diff --git a/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 b/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 index 892e7c0..07eb104 100644 Binary files a/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 and b/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/03c9a4fe-4c3d-479f-9b83-b08774de5a7c.vsidx b/.vs/CommunityServerAPI/FileContentIndex/103e471d-505e-4363-97da-38f54bd5ec5c.vsidx similarity index 75% rename from .vs/CommunityServerAPI/FileContentIndex/03c9a4fe-4c3d-479f-9b83-b08774de5a7c.vsidx rename to .vs/CommunityServerAPI/FileContentIndex/103e471d-505e-4363-97da-38f54bd5ec5c.vsidx index d809245..34e5b24 100644 Binary files a/.vs/CommunityServerAPI/FileContentIndex/03c9a4fe-4c3d-479f-9b83-b08774de5a7c.vsidx and b/.vs/CommunityServerAPI/FileContentIndex/103e471d-505e-4363-97da-38f54bd5ec5c.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/2fef31c7-9222-4014-bf16-10c1aa16f748.vsidx b/.vs/CommunityServerAPI/FileContentIndex/2fef31c7-9222-4014-bf16-10c1aa16f748.vsidx new file mode 100644 index 0000000..a99b1fb Binary files /dev/null and b/.vs/CommunityServerAPI/FileContentIndex/2fef31c7-9222-4014-bf16-10c1aa16f748.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/4fde6a0c-cacf-49c4-a174-e6359477eec0.vsidx b/.vs/CommunityServerAPI/FileContentIndex/4fde6a0c-cacf-49c4-a174-e6359477eec0.vsidx deleted file mode 100644 index c0f71a1..0000000 Binary files a/.vs/CommunityServerAPI/FileContentIndex/4fde6a0c-cacf-49c4-a174-e6359477eec0.vsidx and /dev/null differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/645746a3-f0c2-4099-ab77-e40542763961.vsidx b/.vs/CommunityServerAPI/FileContentIndex/57c85625-9283-421b-9e46-1d3412b7cbd6.vsidx similarity index 76% rename from .vs/CommunityServerAPI/FileContentIndex/645746a3-f0c2-4099-ab77-e40542763961.vsidx rename to .vs/CommunityServerAPI/FileContentIndex/57c85625-9283-421b-9e46-1d3412b7cbd6.vsidx index b397a7f..814a709 100644 Binary files a/.vs/CommunityServerAPI/FileContentIndex/645746a3-f0c2-4099-ab77-e40542763961.vsidx and b/.vs/CommunityServerAPI/FileContentIndex/57c85625-9283-421b-9e46-1d3412b7cbd6.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/d109a60a-2e74-4ac5-a384-fa3278b71228.vsidx b/.vs/CommunityServerAPI/FileContentIndex/77437816-41c0-4b3b-8563-4072e8d70b92.vsidx similarity index 70% rename from .vs/CommunityServerAPI/FileContentIndex/d109a60a-2e74-4ac5-a384-fa3278b71228.vsidx rename to .vs/CommunityServerAPI/FileContentIndex/77437816-41c0-4b3b-8563-4072e8d70b92.vsidx index a92a0c3..43ecea8 100644 Binary files a/.vs/CommunityServerAPI/FileContentIndex/d109a60a-2e74-4ac5-a384-fa3278b71228.vsidx and b/.vs/CommunityServerAPI/FileContentIndex/77437816-41c0-4b3b-8563-4072e8d70b92.vsidx differ diff --git a/.vs/CommunityServerAPI/v17/.futdcache.v2 b/.vs/CommunityServerAPI/v17/.futdcache.v2 index 202d555..10dc513 100644 Binary files a/.vs/CommunityServerAPI/v17/.futdcache.v2 and b/.vs/CommunityServerAPI/v17/.futdcache.v2 differ diff --git a/.vs/ProjectEvaluation/communityserverapi.metadata.v6.1 b/.vs/ProjectEvaluation/communityserverapi.metadata.v6.1 index e663d1b..8fe8b0a 100644 Binary files a/.vs/ProjectEvaluation/communityserverapi.metadata.v6.1 and b/.vs/ProjectEvaluation/communityserverapi.metadata.v6.1 differ diff --git a/.vs/ProjectEvaluation/communityserverapi.projects.v6.1 b/.vs/ProjectEvaluation/communityserverapi.projects.v6.1 index d3b90ad..35e9396 100644 Binary files a/.vs/ProjectEvaluation/communityserverapi.projects.v6.1 and b/.vs/ProjectEvaluation/communityserverapi.projects.v6.1 differ diff --git a/BattleBitAPI/Server/GameServer.cs b/BattleBitAPI/Server/GameServer.cs index abe6f3a..e71e67e 100644 --- a/BattleBitAPI/Server/GameServer.cs +++ b/BattleBitAPI/Server/GameServer.cs @@ -193,12 +193,32 @@ namespace BattleBitAPI.Server } // ---- Team ---- - public IEnumerable GetAllPlayers() + public IEnumerable AllPlayers { - var list = new List(this.mInternal.Players.Values.Count); - foreach (var item in this.mInternal.Players.Values) - list.Add((TPlayer)item); - return list; + get + { + var list = new List(this.mInternal.Players.Values.Count); + lock (this.mInternal.Players) + { + foreach (var item in this.mInternal.Players.Values) + list.Add((TPlayer)item); + } + return list; + } + } + public bool TryGetPlayer(ulong steamID, out TPlayer player) + { + lock (this.mInternal.Players) + { + if (this.mInternal.Players.TryGetValue(steamID, out var _player)) + { + player = (TPlayer)_player; + return true; + } + } + + player = default; + return false; } // ---- Virtual ---- diff --git a/BattleBitAPI/Server/ServerListener.cs b/BattleBitAPI/Server/ServerListener.cs index e59392e..8154a0c 100644 --- a/BattleBitAPI/Server/ServerListener.cs +++ b/BattleBitAPI/Server/ServerListener.cs @@ -571,11 +571,21 @@ namespace BattleBitAPI.Server } private async Task mHandleGameServer(TGameServer server) { + bool isTicking = false; + using (server) { + async Task mTickAsync() + { + isTicking = true; + await server.OnTick(); + isTicking = false; + } + while (server.IsConnected) { - server.OnTick(); + if (!isTicking) + mTickAsync(); await server.Tick(); await Task.Delay(10); @@ -585,7 +595,7 @@ namespace BattleBitAPI.Server { server.OnDisconnected(); - if (this.OnGameServerDisconnected!= null) + if (this.OnGameServerDisconnected != null) this.OnGameServerDisconnected(server); } } @@ -972,6 +982,36 @@ namespace BattleBitAPI.Server } } + // --- Public --- + public IEnumerable ConnectedGameServers + { + get + { + var list = new List(mActiveConnections.Count); + lock (mActiveConnections) + { + foreach (var item in mActiveConnections.Values) + list.Add(item.server); + } + return list; + } + } + public bool TryGetGameServer(IPAddress ip, ushort port, out TGameServer server) + { + var hash = ((ulong)port << 32) | (ulong)ip.ToUInt(); + lock (mActiveConnections) + { + if (mActiveConnections.TryGetValue(hash, out var _server)) + { + server = (TGameServer)_server.server; + return true; + } + } + + server = default; + return false; + } + // --- Disposing --- public void Dispose() { diff --git a/Program.cs b/Program.cs index d26d295..d25442d 100644 --- a/Program.cs +++ b/Program.cs @@ -1,14 +1,12 @@ using BattleBitAPI; using BattleBitAPI.Common; using BattleBitAPI.Server; -using System.Net; class Program { static void Main(string[] args) { var listener = new ServerListener(); - listener.Start(29294); Thread.Sleep(-1); } @@ -23,4 +21,8 @@ class MyGameServer : GameServer { return true; } + public override async Task OnTick() + { + await Task.Delay(3000); + } } diff --git a/bin/Debug/net6.0/CommunityServerAPI.dll b/bin/Debug/net6.0/CommunityServerAPI.dll index df6ba45..1eee1c3 100644 Binary files a/bin/Debug/net6.0/CommunityServerAPI.dll and b/bin/Debug/net6.0/CommunityServerAPI.dll differ diff --git a/bin/Debug/net6.0/CommunityServerAPI.pdb b/bin/Debug/net6.0/CommunityServerAPI.pdb index 0b9cfe1..e1b3a5b 100644 Binary files a/bin/Debug/net6.0/CommunityServerAPI.pdb and b/bin/Debug/net6.0/CommunityServerAPI.pdb differ diff --git a/obj/Debug/net6.0/CommunityServerAPI.dll b/obj/Debug/net6.0/CommunityServerAPI.dll index df6ba45..1eee1c3 100644 Binary files a/obj/Debug/net6.0/CommunityServerAPI.dll and b/obj/Debug/net6.0/CommunityServerAPI.dll differ diff --git a/obj/Debug/net6.0/CommunityServerAPI.pdb b/obj/Debug/net6.0/CommunityServerAPI.pdb index 0b9cfe1..e1b3a5b 100644 Binary files a/obj/Debug/net6.0/CommunityServerAPI.pdb and b/obj/Debug/net6.0/CommunityServerAPI.pdb differ diff --git a/obj/Debug/net6.0/ref/CommunityServerAPI.dll b/obj/Debug/net6.0/ref/CommunityServerAPI.dll index 234ca09..d0d1c67 100644 Binary files a/obj/Debug/net6.0/ref/CommunityServerAPI.dll and b/obj/Debug/net6.0/ref/CommunityServerAPI.dll differ diff --git a/obj/Debug/net6.0/refint/CommunityServerAPI.dll b/obj/Debug/net6.0/refint/CommunityServerAPI.dll index 234ca09..d0d1c67 100644 Binary files a/obj/Debug/net6.0/refint/CommunityServerAPI.dll and b/obj/Debug/net6.0/refint/CommunityServerAPI.dll differ