Skip to content

Commit fde985f

Browse files
committed
fix(core): ensure database on game thread
1 parent dec2f3c commit fde985f

2 files changed

Lines changed: 28 additions & 25 deletions

File tree

src/RSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace RSession;
3030

3131
[PluginMetadata(
3232
Id = "RSession",
33-
Version = "1.2.2",
33+
Version = "1.2.3",
3434
Name = "RSession",
3535
Website = "https://github.com/oscar-wos/RSession",
3636
Author = "oscar-wos"

src/Services/Core/ServerService.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,38 @@ public void Initialize() =>
5050
string ip = _core.Engine.ServerIP ?? "0.0.0.0";
5151
ushort port = (ushort)(_core.ConVar.Find<int>("hostport")?.Value ?? 27015);
5252

53-
_ = Task.Run(async () =>
53+
try
5454
{
55-
try
56-
{
57-
await _databaseService.CreateTablesAsync().ConfigureAwait(false);
55+
_databaseService
56+
.CreateTablesAsync()
57+
.ConfigureAwait(false)
58+
.GetAwaiter()
59+
.GetResult();
5860

59-
short serverId = await _databaseService
60-
.GetServerAsync(ip, port)
61-
.ConfigureAwait(false);
61+
short serverId = _databaseService
62+
.GetServerAsync(ip, port)
63+
.ConfigureAwait(false)
64+
.GetAwaiter()
65+
.GetResult();
6266

63-
_logService.LogInformation(
64-
$"Server registered - {ip}:{port} | Server ID: {serverId}",
65-
logger: _logger
66-
);
67+
_logService.LogInformation(
68+
$"Server registered - {ip}:{port} | Server ID: {serverId}",
69+
logger: _logger
70+
);
6771

68-
_id = serverId;
69-
_eventService.InvokeServerRegistered(serverId);
72+
_id = serverId;
73+
_eventService.InvokeServerRegistered(serverId);
7074

71-
_mapService.HandleMapLoad(_core.Engine.GlobalVars.MapName);
72-
}
73-
catch (Exception ex)
74-
{
75-
_logService.LogError(
76-
$"Unable to register server - {ip}:{port}",
77-
exception: ex,
78-
logger: _logger
79-
);
80-
}
81-
});
75+
_mapService.HandleMapLoad(_core.Engine.GlobalVars.MapName);
76+
}
77+
catch (Exception ex)
78+
{
79+
_logService.LogError(
80+
$"Unable to register server - {ip}:{port}",
81+
exception: ex,
82+
logger: _logger
83+
);
84+
}
8285
}
8386
)
8487
);

0 commit comments

Comments
 (0)