Skip to content

Commit 96e5273

Browse files
committed
fix(core): ensure ip on game thread
1 parent fd169d0 commit 96e5273

4 files changed

Lines changed: 45 additions & 40 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ csharp_preserve_single_line_statements = true
201201
csharp_preserve_single_line_blocks = true
202202

203203
# License header
204-
file_header_template = Copyright (C) 2025 oscar-wos\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.
204+
file_header_template = Copyright (C) 2026 oscar-wos\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.
205205
csharp_style_namespace_declarations = file_scoped:suggestion
206206
csharp_style_prefer_null_check_over_type_check = true:suggestion
207207
csharp_style_prefer_local_over_anonymous_function = true:suggestion

RSession.sln

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RLogger", "RLogger\src\RLog
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSession", "src\RSession.csproj", "{FF469060-2A5D-EE11-1870-AD6223F812B2}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSession.Shared", "RSession.Shared\RSession.Shared.csproj", "{640B8FD8-CEB4-A213-DA72-D43793BA463E}"
11+
EndProject
1012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSession.Aliases", "RSession.Aliases\RSession.Aliases.csproj", "{0C162EBC-CB9B-CB4B-EA4A-11210F82F2DB}"
1113
EndProject
1214
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSession.Messages", "RSession.Messages\RSession.Messages.csproj", "{F9398443-B30A-9A5E-0981-6949F0799A03}"
1315
EndProject
1416
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSession.Played", "RSession.Played\RSession.Played.csproj", "{FEBFE5AB-678D-FFDE-3B5A-0A8663615737}"
1517
EndProject
16-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSession.Shared", "RSession.Shared\RSession.Shared.csproj", "{640B8FD8-CEB4-A213-DA72-D43793BA463E}"
17-
EndProject
1818
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RSession.Rotation", "RSession.Rotation\RSession.Rotation.csproj", "{04DBEACF-F3CF-5113-AA46-A41709E81BC6}"
1919
EndProject
2020
Global
@@ -41,6 +41,14 @@ Global
4141
{FF469060-2A5D-EE11-1870-AD6223F812B2}.Release|Any CPU.Build.0 = Release|Any CPU
4242
{FF469060-2A5D-EE11-1870-AD6223F812B2}.Release|x64.ActiveCfg = Release|x64
4343
{FF469060-2A5D-EE11-1870-AD6223F812B2}.Release|x64.Build.0 = Release|x64
44+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|x64.ActiveCfg = Debug|x64
47+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|x64.Build.0 = Debug|x64
48+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|x64.ActiveCfg = Release|x64
51+
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|x64.Build.0 = Release|x64
4452
{0C162EBC-CB9B-CB4B-EA4A-11210F82F2DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4553
{0C162EBC-CB9B-CB4B-EA4A-11210F82F2DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
4654
{0C162EBC-CB9B-CB4B-EA4A-11210F82F2DB}.Debug|x64.ActiveCfg = Debug|x64
@@ -65,14 +73,6 @@ Global
6573
{FEBFE5AB-678D-FFDE-3B5A-0A8663615737}.Release|Any CPU.Build.0 = Release|Any CPU
6674
{FEBFE5AB-678D-FFDE-3B5A-0A8663615737}.Release|x64.ActiveCfg = Release|x64
6775
{FEBFE5AB-678D-FFDE-3B5A-0A8663615737}.Release|x64.Build.0 = Release|x64
68-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|Any CPU.Build.0 = Debug|Any CPU
70-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|x64.ActiveCfg = Debug|x64
71-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Debug|x64.Build.0 = Debug|x64
72-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|Any CPU.ActiveCfg = Release|Any CPU
73-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|Any CPU.Build.0 = Release|Any CPU
74-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|x64.ActiveCfg = Release|x64
75-
{640B8FD8-CEB4-A213-DA72-D43793BA463E}.Release|x64.Build.0 = Release|x64
7676
{04DBEACF-F3CF-5113-AA46-A41709E81BC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7777
{04DBEACF-F3CF-5113-AA46-A41709E81BC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
7878
{04DBEACF-F3CF-5113-AA46-A41709E81BC6}.Debug|x64.ActiveCfg = Debug|x64

src/RSession.cs

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

3131
[PluginMetadata(
3232
Id = "RSession",
33-
Version = "1.2.0",
33+
Version = "1.2.1",
3434
Name = "RSession",
3535
Website = "https://github.com/oscar-wos/RSession",
3636
Author = "oscar-wos"
@@ -90,7 +90,6 @@ public override void Load(bool hotReload)
9090
ServiceCollection services = new();
9191

9292
_ = services.AddSwiftly(Core);
93-
9493
_ = services.AddConfigs();
9594
_ = services.AddDatabases();
9695
_ = services.AddEvents();

src/Services/Core/ServerService.cs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2025 oscar-wos
1+
// Copyright (C) 2026 oscar-wos
22
//
33
// This program is free software: you can redistribute it and/or modify
44
// it under the terms of the GNU General Public License as published by
@@ -42,36 +42,42 @@ IMapService mapService
4242
public short? GetServerId() => _id;
4343

4444
public void Initialize() =>
45-
Task.Run(async () =>
46-
{
47-
string ip = _core.Engine.ServerIP ?? "0.0.0.0";
48-
ushort port = (ushort)(_core.ConVar.Find<int>("hostport")?.Value ?? 0);
49-
50-
try
45+
_core.Scheduler.DelayBySeconds(
46+
3.3f,
47+
() =>
5148
{
52-
await _databaseService.CreateTablesAsync().ConfigureAwait(false);
49+
string ip = _core.Engine.ServerIP ?? "0.0.0.0";
50+
ushort port = (ushort)(_core.ConVar.Find<int>("hostport")?.Value ?? 27015);
5351

54-
short serverId = await _databaseService
55-
.GetServerAsync(ip, port)
56-
.ConfigureAwait(false);
52+
_ = Task.Run(async () =>
53+
{
54+
try
55+
{
56+
await _databaseService.CreateTablesAsync().ConfigureAwait(false);
5757

58-
_logService.LogInformation(
59-
$"Server registered - {ip}:{port} | Server ID: {serverId}",
60-
logger: _logger
61-
);
58+
short serverId = await _databaseService
59+
.GetServerAsync(ip, port)
60+
.ConfigureAwait(false);
6261

63-
_id = serverId;
64-
_eventService.InvokeServerRegistered(serverId);
62+
_logService.LogInformation(
63+
$"Server registered - {ip}:{port} | Server ID: {serverId}",
64+
logger: _logger
65+
);
6566

66-
_mapService.HandleMapLoad(_core.Engine.GlobalVars.MapName);
67-
}
68-
catch (Exception ex)
69-
{
70-
_logService.LogError(
71-
$"Unable to register server - {ip}:{port}",
72-
exception: ex,
73-
logger: _logger
74-
);
67+
_id = serverId;
68+
_eventService.InvokeServerRegistered(serverId);
69+
70+
_mapService.HandleMapLoad(_core.Engine.GlobalVars.MapName);
71+
}
72+
catch (Exception ex)
73+
{
74+
_logService.LogError(
75+
$"Unable to register server - {ip}:{port}",
76+
exception: ex,
77+
logger: _logger
78+
);
79+
}
80+
});
7581
}
76-
});
82+
);
7783
}

0 commit comments

Comments
 (0)