diff --git a/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 b/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 index 99eb4c3..4d6cb8d 100644 Binary files a/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 and b/.vs/CommunityServerAPI/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/83982491-356f-49c4-86ee-5a4bc319c732.vsidx b/.vs/CommunityServerAPI/FileContentIndex/03c9a4fe-4c3d-479f-9b83-b08774de5a7c.vsidx similarity index 73% rename from .vs/CommunityServerAPI/FileContentIndex/83982491-356f-49c4-86ee-5a4bc319c732.vsidx rename to .vs/CommunityServerAPI/FileContentIndex/03c9a4fe-4c3d-479f-9b83-b08774de5a7c.vsidx index a95f852..d809245 100644 Binary files a/.vs/CommunityServerAPI/FileContentIndex/83982491-356f-49c4-86ee-5a4bc319c732.vsidx and b/.vs/CommunityServerAPI/FileContentIndex/03c9a4fe-4c3d-479f-9b83-b08774de5a7c.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/4adb6c8c-c638-44a6-8fc5-9df83031ed7f.vsidx b/.vs/CommunityServerAPI/FileContentIndex/4adb6c8c-c638-44a6-8fc5-9df83031ed7f.vsidx deleted file mode 100644 index db33a14..0000000 Binary files a/.vs/CommunityServerAPI/FileContentIndex/4adb6c8c-c638-44a6-8fc5-9df83031ed7f.vsidx and /dev/null differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/645746a3-f0c2-4099-ab77-e40542763961.vsidx b/.vs/CommunityServerAPI/FileContentIndex/645746a3-f0c2-4099-ab77-e40542763961.vsidx new file mode 100644 index 0000000..b397a7f Binary files /dev/null and b/.vs/CommunityServerAPI/FileContentIndex/645746a3-f0c2-4099-ab77-e40542763961.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/8fc81313-1aa8-4e87-a229-236870ed2692.vsidx b/.vs/CommunityServerAPI/FileContentIndex/8fc81313-1aa8-4e87-a229-236870ed2692.vsidx new file mode 100644 index 0000000..d25a9bc Binary files /dev/null and b/.vs/CommunityServerAPI/FileContentIndex/8fc81313-1aa8-4e87-a229-236870ed2692.vsidx differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/c9b50050-20cf-49b7-9014-cfb1229ddcdb.vsidx b/.vs/CommunityServerAPI/FileContentIndex/c9b50050-20cf-49b7-9014-cfb1229ddcdb.vsidx deleted file mode 100644 index 421211c..0000000 Binary files a/.vs/CommunityServerAPI/FileContentIndex/c9b50050-20cf-49b7-9014-cfb1229ddcdb.vsidx and /dev/null differ diff --git a/.vs/CommunityServerAPI/FileContentIndex/325c9c79-6da6-4205-9559-db8e61bd6029.vsidx b/.vs/CommunityServerAPI/FileContentIndex/d109a60a-2e74-4ac5-a384-fa3278b71228.vsidx similarity index 76% rename from .vs/CommunityServerAPI/FileContentIndex/325c9c79-6da6-4205-9559-db8e61bd6029.vsidx rename to .vs/CommunityServerAPI/FileContentIndex/d109a60a-2e74-4ac5-a384-fa3278b71228.vsidx index 77d506c..a92a0c3 100644 Binary files a/.vs/CommunityServerAPI/FileContentIndex/325c9c79-6da6-4205-9559-db8e61bd6029.vsidx and b/.vs/CommunityServerAPI/FileContentIndex/d109a60a-2e74-4ac5-a384-fa3278b71228.vsidx differ diff --git a/BattleBitAPI/Common/Arguments/OnPlayerSpawnArguments.cs b/BattleBitAPI/Common/Arguments/OnPlayerSpawnArguments.cs new file mode 100644 index 0000000..bb2f6a8 --- /dev/null +++ b/BattleBitAPI/Common/Arguments/OnPlayerSpawnArguments.cs @@ -0,0 +1,50 @@ +using System.Numerics; + +namespace BattleBitAPI.Common +{ + public struct OnPlayerSpawnArguments + { + public PlayerSpawningPosition RequestedPoint; + public PlayerLoadout Loadout; + public PlayerWearings Wearings; + public Vector3 SpawnPosition; + public Vector3 LookDirection; + public PlayerStand SpawnStand; + public float SpawnProtection; + + public void Write(Common.Serialization.Stream ser) + { + ser.Write((byte)RequestedPoint); + Loadout.Write(ser); + Wearings.Write(ser); + ser.Write(SpawnPosition.X); + ser.Write(SpawnPosition.Y); + ser.Write(SpawnPosition.Z); + ser.Write(LookDirection.X); + ser.Write(LookDirection.Y); + ser.Write(LookDirection.Z); + ser.Write((byte)SpawnStand); + ser.Write(SpawnProtection); + } + public void Read(Common.Serialization.Stream ser) + { + RequestedPoint = (PlayerSpawningPosition)ser.ReadInt8(); + Loadout.Read(ser); + Wearings.Read(ser); + SpawnPosition = new Vector3() + { + X = ser.ReadFloat(), + Y = ser.ReadFloat(), + Z = ser.ReadFloat() + }; + LookDirection = new Vector3() + { + X = ser.ReadFloat(), + Y = ser.ReadFloat(), + Z = ser.ReadFloat() + }; + SpawnStand = (PlayerStand)ser.ReadInt8(); + SpawnProtection = ser.ReadFloat(); + } + } +} diff --git a/BattleBitAPI/Common/Datasets/Gadgets.cs b/BattleBitAPI/Common/Data/Gadgets.cs similarity index 100% rename from BattleBitAPI/Common/Datasets/Gadgets.cs rename to BattleBitAPI/Common/Data/Gadgets.cs diff --git a/BattleBitAPI/Common/Data/PlayerSpawnRequest.cs b/BattleBitAPI/Common/Data/PlayerSpawnRequest.cs deleted file mode 100644 index cb2dfb9..0000000 --- a/BattleBitAPI/Common/Data/PlayerSpawnRequest.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Numerics; - -namespace BattleBitAPI.Common -{ - public struct PlayerSpawnRequest - { - public PlayerSpawningPosition RequestedPoint; - public PlayerLoadout Loadout; - public PlayerWearings Wearings; - public Vector3 SpawnPosition; - public Vector3 LookDirection; - public PlayerStand SpawnStand; - public float SpawnProtection; - - public void Write(Common.Serialization.Stream ser) - { - ser.Write((byte)this.RequestedPoint); - this.Loadout.Write(ser); - this.Wearings.Write(ser); - ser.Write(this.SpawnPosition.X); - ser.Write(this.SpawnPosition.Y); - ser.Write(this.SpawnPosition.Z); - ser.Write(this.LookDirection.X); - ser.Write(this.LookDirection.Y); - ser.Write(this.LookDirection.Z); - ser.Write((byte)this.SpawnStand); - ser.Write(this.SpawnProtection); - } - public void Read(Common.Serialization.Stream ser) - { - this.RequestedPoint = (PlayerSpawningPosition)ser.ReadInt8(); - this.Loadout.Read(ser); - this.Wearings.Read(ser); - this.SpawnPosition = new Vector3() - { - X = ser.ReadFloat(), - Y = ser.ReadFloat(), - Z = ser.ReadFloat() - }; - this.LookDirection = new Vector3() - { - X = ser.ReadFloat(), - Y = ser.ReadFloat(), - Z = ser.ReadFloat() - }; - this.SpawnStand = (PlayerStand)ser.ReadInt8(); - this.SpawnProtection = ser.ReadFloat(); - } - } -} diff --git a/BattleBitAPI/Server/GameServer.cs b/BattleBitAPI/Server/GameServer.cs index 1e41522..abe6f3a 100644 --- a/BattleBitAPI/Server/GameServer.cs +++ b/BattleBitAPI/Server/GameServer.cs @@ -1,7 +1,6 @@ using System.Net; using System.Net.Sockets; using System.Numerics; -using System.Resources; using System.Text; using BattleBitAPI.Common; using BattleBitAPI.Common.Extentions; @@ -259,7 +258,7 @@ namespace BattleBitAPI.Server { } - public virtual async Task OnPlayerSpawning(TPlayer player, PlayerSpawnRequest request) + public virtual async Task OnPlayerSpawning(TPlayer player, OnPlayerSpawnArguments request) { return request; } @@ -423,7 +422,7 @@ namespace BattleBitAPI.Server } public void SpawnPlayer(ulong steamID, PlayerLoadout loadout, PlayerWearings wearings, Vector3 position, Vector3 lookDirection, PlayerStand stand, float spawnProtection) { - var request = new PlayerSpawnRequest() + var request = new OnPlayerSpawnArguments() { Loadout = loadout, Wearings = wearings, diff --git a/BattleBitAPI/Server/ServerListener.cs b/BattleBitAPI/Server/ServerListener.cs index 19ed369..07c9afa 100644 --- a/BattleBitAPI/Server/ServerListener.cs +++ b/BattleBitAPI/Server/ServerListener.cs @@ -34,14 +34,16 @@ namespace BattleBitAPI.Server // --- Private --- private TcpListener mSocket; + private bool mIsBlocking; private Dictionary.Internal resources)> mActiveConnections; private mInstances mInstanceDatabase; // --- Construction --- - public ServerListener() + public ServerListener(bool isBlocking = true) { this.mActiveConnections = new Dictionary.Internal)>(16); this.mInstanceDatabase = new mInstances(); + this.mIsBlocking = isBlocking; } // --- Starting --- @@ -544,7 +546,11 @@ namespace BattleBitAPI.Server { while (server.IsConnected) { - await server.OnTick(); + if (this.mIsBlocking) + await server.OnTick(); + else + server.OnTick(); + await server.Tick(); await Task.Delay(10); } @@ -588,8 +594,16 @@ namespace BattleBitAPI.Server player.Role = role; resources.AddPlayer(player); - await server.OnPlayerConnected(player); - await player.OnConnected(); + if (this.mIsBlocking) + { + await server.OnPlayerConnected(player); + await player.OnConnected(); + } + else + { + server.OnPlayerConnected(player); + player.OnConnected(); + } } } break; @@ -606,8 +620,16 @@ namespace BattleBitAPI.Server if (exist) { - await server.OnPlayerDisconnected((TPlayer)player); - await player.OnDisconnected(); + if (this.mIsBlocking) + { + await server.OnPlayerDisconnected((TPlayer)player); + await player.OnDisconnected(); + } + else + { + server.OnPlayerDisconnected((TPlayer)player); + player.OnDisconnected(); + } } } break; @@ -668,7 +690,11 @@ namespace BattleBitAPI.Server SourceOfDamage = source, KillerTool = tool, }; - await server.OnAPlayerKilledAnotherPlayer(args); + + if (this.mIsBlocking) + await server.OnAPlayerKilledAnotherPlayer(args); + else + server.OnAPlayerKilledAnotherPlayer(args); } } } @@ -681,18 +707,25 @@ namespace BattleBitAPI.Server if (stream.CanRead(8 + 2)) { ulong steamID = stream.ReadUInt64(); - var stats = new PlayerStats(); stats.Read(stream); - stats = await server.OnGetPlayerStats(steamID, stats); - using (var response = Common.Serialization.Stream.Get()) + async Task mHandle() { - response.Write((byte)NetworkCommuncation.SendPlayerStats); - response.Write(steamID); - stats.Write(response); - server.WriteToSocket(response); + stats = await server.OnGetPlayerStats(steamID, stats); + using (var response = Common.Serialization.Stream.Get()) + { + response.Write((byte)NetworkCommuncation.SendPlayerStats); + response.Write(steamID); + stats.Write(response); + server.WriteToSocket(response); + } } + + if (mIsBlocking) + await mHandle(); + else + mHandle(); } break; } @@ -704,7 +737,10 @@ namespace BattleBitAPI.Server PlayerStats stats = new PlayerStats(); stats.Read(stream); - await server.OnSavePlayerStats(steamID, stats); + if (mIsBlocking) + await server.OnSavePlayerStats(steamID, stats); + else + server.OnSavePlayerStats(steamID, stats); } break; } @@ -717,12 +753,17 @@ namespace BattleBitAPI.Server if (resources.TryGetPlayer(steamID, out var client)) { - bool accepted = true; + async Task mHandle() + { + bool accepted = await server.OnPlayerRequestingToChangeRole((TPlayer)client, role); + if (accepted) + server.SetRoleTo(steamID, role); + } - accepted = await server.OnPlayerRequestingToChangeRole((TPlayer)client, role); - - if (accepted) - server.SetRoleTo(steamID, role); + if (mIsBlocking) + await mHandle(); + else + mHandle(); } } break; @@ -737,7 +778,10 @@ namespace BattleBitAPI.Server if (resources.TryGetPlayer(steamID, out var client)) { client.Role = role; - await server.OnPlayerChangedRole((TPlayer)client, role); + if (mIsBlocking) + await server.OnPlayerChangedRole((TPlayer)client, role); + else + server.OnPlayerChangedRole((TPlayer)client, role); } } break; @@ -752,7 +796,10 @@ namespace BattleBitAPI.Server if (resources.TryGetPlayer(steamID, out var client)) { client.Squad = squad; - await server.OnPlayerJoinedSquad((TPlayer)client, squad); + if (mIsBlocking) + await server.OnPlayerJoinedSquad((TPlayer)client, squad); + else + server.OnPlayerJoinedSquad((TPlayer)client, squad); } } break; @@ -770,10 +817,18 @@ namespace BattleBitAPI.Server client.Squad = Squads.NoSquad; client.Role = GameRole.Assault; - await server.OnPlayerLeftSquad((TPlayer)client, oldSquad); - - if (oldRole != GameRole.Assault) - await server.OnPlayerChangedRole((TPlayer)client, GameRole.Assault); + if (mIsBlocking) + { + await server.OnPlayerLeftSquad((TPlayer)client, oldSquad); + if (oldRole != GameRole.Assault) + await server.OnPlayerChangedRole((TPlayer)client, GameRole.Assault); + } + else + { + server.OnPlayerLeftSquad((TPlayer)client, oldSquad); + if (oldRole != GameRole.Assault) + server.OnPlayerChangedRole((TPlayer)client, GameRole.Assault); + } } } break; @@ -788,7 +843,10 @@ namespace BattleBitAPI.Server if (resources.TryGetPlayer(steamID, out var client)) { client.Team = team; - await server.OnPlayerChangeTeam((TPlayer)client, team); + if (mIsBlocking) + await server.OnPlayerChangeTeam((TPlayer)client, team); + else + server.OnPlayerChangeTeam((TPlayer)client, team); } } break; @@ -799,21 +857,31 @@ namespace BattleBitAPI.Server { ulong steamID = stream.ReadUInt64(); - var request = new PlayerSpawnRequest(); + var request = new OnPlayerSpawnArguments(); request.Read(stream); ushort vehicleID = stream.ReadUInt16(); if (resources.TryGetPlayer(steamID, out var client)) - request = await server.OnPlayerSpawning((TPlayer)client, request); - - //Respond back. - using (var response = Common.Serialization.Stream.Get()) { - response.Write((byte)NetworkCommuncation.SpawnPlayer); - response.Write(steamID); - request.Write(response); - response.Write(vehicleID); - server.WriteToSocket(response); + async Task mHandle() + { + request = await server.OnPlayerSpawning((TPlayer)client, request); + + //Respond back. + using (var response = Common.Serialization.Stream.Get()) + { + response.Write((byte)NetworkCommuncation.SpawnPlayer); + response.Write(steamID); + request.Write(response); + response.Write(vehicleID); + server.WriteToSocket(response); + } + } + + if (mIsBlocking) + await mHandle(); + else + mHandle(); } } break; @@ -831,7 +899,10 @@ namespace BattleBitAPI.Server { if (resources.TryGetPlayer(reported, out var reportedClient)) { - await server.OnPlayerReported((TPlayer)reporterClient, (TPlayer)reportedClient, reason, additionalInfo); + if (mIsBlocking) + await server.OnPlayerReported((TPlayer)reporterClient, (TPlayer)reportedClient, reason, additionalInfo); + else + server.OnPlayerReported((TPlayer)reporterClient, (TPlayer)reportedClient, reason, additionalInfo); } } } @@ -854,8 +925,16 @@ namespace BattleBitAPI.Server client.IsAlive = true; - await client.OnSpawned(); - await server.OnPlayerSpawned((TPlayer)client); + if (mIsBlocking) + { + await client.OnSpawned(); + await server.OnPlayerSpawned((TPlayer)client); + } + else + { + client.OnSpawned(); + server.OnPlayerSpawned((TPlayer)client); + } } } break; @@ -871,9 +950,16 @@ namespace BattleBitAPI.Server client.CurrentWearings = new PlayerWearings(); client.IsAlive = false; - await client.OnDied(); - - await server.OnPlayerDied((TPlayer)client); + if (mIsBlocking) + { + await client.OnDied(); + await server.OnPlayerDied((TPlayer)client); + } + else + { + client.OnDied(); + server.OnPlayerDied((TPlayer)client); + } } } break; @@ -964,7 +1050,7 @@ namespace BattleBitAPI.Server { if (this.mPlayerInstances.TryGetValue(steamID, out var player)) return player; - + player = Activator.CreateInstance(); player.OnCreated(); mPlayerInstances.Add(steamID, player); diff --git a/Program.cs b/Program.cs index 99ceb52..92bcd27 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,5 @@ using BattleBitAPI; +using BattleBitAPI.Common; using BattleBitAPI.Server; using System.Net; @@ -7,8 +8,8 @@ class Program static void Main(string[] args) { var listener = new ServerListener(); - listener.Start(29294); listener.OnGameServerConnecting += OnGameServerConnecting; + listener.Start(29294); Thread.Sleep(-1); } @@ -18,22 +19,27 @@ class Program return true; } } -class MyPlayer : Player +class MyPlayer : Player { - public int NumberOfSpawns = 0; - public override async Task OnSpawned() { - this.NumberOfSpawns++; - base.GameServer.CloseConnection(); - - await Console.Out.WriteLineAsync("Spawn: " + this.NumberOfSpawns); } } + + class MyGameServer : GameServer { public override async Task OnConnected() { Console.WriteLine(base.GameIP + " connected"); } + + public override async Task OnTick() + { + } + + public override async Task OnPlayerTypedMessage(MyPlayer player, ChatChannel channel, string msg) + { + } + } diff --git a/bin/Debug/net6.0/CommunityServerAPI.dll b/bin/Debug/net6.0/CommunityServerAPI.dll index b9b191d..abd73b7 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 bcd3e7e..0eb5e84 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 b9b191d..abd73b7 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 bcd3e7e..0eb5e84 100644 Binary files a/obj/Debug/net6.0/CommunityServerAPI.pdb and b/obj/Debug/net6.0/CommunityServerAPI.pdb differ