This commit is contained in:
Niko Storni 2023-08-14 17:50:55 +02:00
parent 164cf6b349
commit c39d2446e8
3 changed files with 41 additions and 41 deletions

View File

@ -1,6 +1,6 @@
namespace BattleBitAPI.Networking namespace BattleBitAPI.Networking
{ {
public enum NetworkCommuncation : byte public enum NetworkCommunication : byte
{ {
None = 0, None = 0,
Hail = 1, Hail = 1,

View File

@ -53,7 +53,7 @@ namespace BattleBitAPI.Server
//Send new settings //Send new settings
using (var pck = Common.Serialization.Stream.Get()) using (var pck = Common.Serialization.Stream.Get())
{ {
pck.Write((byte)NetworkCommuncation.SetNewRoomSettings); pck.Write((byte)NetworkCommunication.SetNewRoomSettings);
this.mInternal._RoomSettings.Write(pck); this.mInternal._RoomSettings.Write(pck);
WriteToSocket(pck); WriteToSocket(pck);
} }
@ -95,7 +95,7 @@ namespace BattleBitAPI.Server
//Send new round settings //Send new round settings
using (var pck = Common.Serialization.Stream.Get()) using (var pck = Common.Serialization.Stream.Get())
{ {
pck.Write((byte)NetworkCommuncation.SetNewRoundState); pck.Write((byte)NetworkCommunication.SetNewRoundState);
this.mInternal._RoundSettings.Write(pck); this.mInternal._RoundSettings.Write(pck);
WriteToSocket(pck); WriteToSocket(pck);
} }
@ -354,7 +354,7 @@ namespace BattleBitAPI.Server
lock (this.mInternal.mWriteStream) lock (this.mInternal.mWriteStream)
{ {
this.mInternal.mWriteStream.Write((uint)(1 + 2 + bytesLong)); this.mInternal.mWriteStream.Write((uint)(1 + 2 + bytesLong));
this.mInternal.mWriteStream.Write((byte)NetworkCommuncation.ExecuteCommand); this.mInternal.mWriteStream.Write((byte)NetworkCommunication.ExecuteCommand);
this.mInternal.mWriteStream.Write(cmd); this.mInternal.mWriteStream.Write(cmd);
} }
} }
@ -519,7 +519,7 @@ namespace BattleBitAPI.Server
//Respond back. //Respond back.
using (var response = Common.Serialization.Stream.Get()) using (var response = Common.Serialization.Stream.Get())
{ {
response.Write((byte)NetworkCommuncation.SpawnPlayer); response.Write((byte)NetworkCommunication.SpawnPlayer);
response.Write(steamID); response.Write(steamID);
request.Write(response); request.Write(response);
response.Write((ushort)0); response.Write((ushort)0);
@ -600,7 +600,7 @@ namespace BattleBitAPI.Server
{ {
using (var packet = Common.Serialization.Stream.Get()) using (var packet = Common.Serialization.Stream.Get())
{ {
packet.Write((byte)NetworkCommuncation.SetPlayerWeapon); packet.Write((byte)NetworkCommunication.SetPlayerWeapon);
packet.Write(steamID); packet.Write(steamID);
packet.Write((byte)0);//Primary packet.Write((byte)0);//Primary
item.Write(packet); item.Write(packet);
@ -618,7 +618,7 @@ namespace BattleBitAPI.Server
{ {
using (var packet = Common.Serialization.Stream.Get()) using (var packet = Common.Serialization.Stream.Get())
{ {
packet.Write((byte)NetworkCommuncation.SetPlayerWeapon); packet.Write((byte)NetworkCommunication.SetPlayerWeapon);
packet.Write(steamID); packet.Write(steamID);
packet.Write((byte)1);//Secondary packet.Write((byte)1);//Secondary
item.Write(packet); item.Write(packet);
@ -636,7 +636,7 @@ namespace BattleBitAPI.Server
{ {
using (var packet = Common.Serialization.Stream.Get()) using (var packet = Common.Serialization.Stream.Get())
{ {
packet.Write((byte)NetworkCommuncation.SetPlayerGadget); packet.Write((byte)NetworkCommunication.SetPlayerGadget);
packet.Write(steamID); packet.Write(steamID);
packet.Write((byte)2);//first aid packet.Write((byte)2);//first aid
packet.Write(tool); packet.Write(tool);
@ -654,7 +654,7 @@ namespace BattleBitAPI.Server
{ {
using (var packet = Common.Serialization.Stream.Get()) using (var packet = Common.Serialization.Stream.Get())
{ {
packet.Write((byte)NetworkCommuncation.SetPlayerGadget); packet.Write((byte)NetworkCommunication.SetPlayerGadget);
packet.Write(steamID); packet.Write(steamID);
packet.Write((byte)3);//Tool A packet.Write((byte)3);//Tool A
packet.Write(tool); packet.Write(tool);
@ -672,7 +672,7 @@ namespace BattleBitAPI.Server
{ {
using (var packet = Common.Serialization.Stream.Get()) using (var packet = Common.Serialization.Stream.Get())
{ {
packet.Write((byte)NetworkCommuncation.SetPlayerGadget); packet.Write((byte)NetworkCommunication.SetPlayerGadget);
packet.Write(steamID); packet.Write(steamID);
packet.Write((byte)4);//Tool A packet.Write((byte)4);//Tool A
packet.Write(tool); packet.Write(tool);
@ -690,7 +690,7 @@ namespace BattleBitAPI.Server
{ {
using (var packet = Common.Serialization.Stream.Get()) using (var packet = Common.Serialization.Stream.Get())
{ {
packet.Write((byte)NetworkCommuncation.SetPlayerGadget); packet.Write((byte)NetworkCommunication.SetPlayerGadget);
packet.Write(steamID); packet.Write(steamID);
packet.Write((byte)5);//Tool A packet.Write((byte)5);//Tool A
packet.Write(tool); packet.Write(tool);

View File

@ -173,8 +173,8 @@ namespace BattleBitAPI.Server
readStream.Reset(); readStream.Reset();
if (!await networkStream.TryRead(readStream, 1, source.Token)) if (!await networkStream.TryRead(readStream, 1, source.Token))
throw new Exception("Unable to read the package type"); throw new Exception("Unable to read the package type");
NetworkCommuncation type = (NetworkCommuncation)readStream.ReadInt8(); NetworkCommunication type = (NetworkCommunication)readStream.ReadInt8();
if (type != NetworkCommuncation.Hail) if (type != NetworkCommunication.Hail)
throw new Exception("Incoming package wasn't hail."); throw new Exception("Incoming package wasn't hail.");
} }
@ -542,7 +542,7 @@ namespace BattleBitAPI.Server
} }
//Send accepted notification. //Send accepted notification.
networkStream.WriteByte((byte)NetworkCommuncation.Accepted); networkStream.WriteByte((byte)NetworkCommunication.Accepted);
if (isNew) if (isNew)
{ {
@ -560,7 +560,7 @@ namespace BattleBitAPI.Server
var networkStream = client.GetStream(); var networkStream = client.GetStream();
using (var pck = BattleBitAPI.Common.Serialization.Stream.Get()) using (var pck = BattleBitAPI.Common.Serialization.Stream.Get())
{ {
pck.Write((byte)NetworkCommuncation.Denied); pck.Write((byte)NetworkCommunication.Denied);
pck.Write(e.Message); pck.Write(e.Message);
//Send denied notification. //Send denied notification.
@ -652,10 +652,10 @@ namespace BattleBitAPI.Server
// --- Logic Executing --- // --- Logic Executing ---
private async Task mExecutePackage(GameServer<TPlayer> server, GameServer<TPlayer>.Internal resources, Common.Serialization.Stream stream) private async Task mExecutePackage(GameServer<TPlayer> server, GameServer<TPlayer>.Internal resources, Common.Serialization.Stream stream)
{ {
var communcation = (NetworkCommuncation)stream.ReadInt8(); var communcation = (NetworkCommunication)stream.ReadInt8();
switch (communcation) switch (communcation)
{ {
case NetworkCommuncation.PlayerConnected: case NetworkCommunication.PlayerConnected:
{ {
if (stream.CanRead(8 + 2 + 4 + (1 + 1 + 1))) if (stream.CanRead(8 + 2 + 4 + (1 + 1 + 1)))
{ {
@ -690,7 +690,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.PlayerDisconnected: case NetworkCommunication.PlayerDisconnected:
{ {
if (stream.CanRead(8)) if (stream.CanRead(8))
{ {
@ -717,7 +717,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerTypedMessage: case NetworkCommunication.OnPlayerTypedMessage:
{ {
if (stream.CanRead(2 + 8 + 1 + 2)) if (stream.CanRead(2 + 8 + 1 + 2))
{ {
@ -736,7 +736,7 @@ namespace BattleBitAPI.Server
//Respond back. //Respond back.
using (var response = Common.Serialization.Stream.Get()) using (var response = Common.Serialization.Stream.Get())
{ {
response.Write((byte)NetworkCommuncation.RespondPlayerMessage); response.Write((byte)NetworkCommunication.RespondPlayerMessage);
response.Write(messageID); response.Write(messageID);
response.Write(pass); response.Write(pass);
server.WriteToSocket(response); server.WriteToSocket(response);
@ -750,7 +750,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnAPlayerDownedAnotherPlayer: case NetworkCommunication.OnAPlayerDownedAnotherPlayer:
{ {
if (stream.CanRead(8 + 12 + 8 + 12 + 2 + 1 + 1)) if (stream.CanRead(8 + 12 + 8 + 12 + 2 + 1 + 1))
{ {
@ -789,7 +789,7 @@ namespace BattleBitAPI.Server
break; break;
} }
case NetworkCommuncation.OnPlayerJoining: case NetworkCommunication.OnPlayerJoining:
{ {
if (stream.CanRead(8 + 2)) if (stream.CanRead(8 + 2))
{ {
@ -810,7 +810,7 @@ namespace BattleBitAPI.Server
await server.OnPlayerJoiningToServer(steamID, args); await server.OnPlayerJoiningToServer(steamID, args);
using (var response = Common.Serialization.Stream.Get()) using (var response = Common.Serialization.Stream.Get())
{ {
response.Write((byte)NetworkCommuncation.SendPlayerStats); response.Write((byte)NetworkCommunication.SendPlayerStats);
response.Write(steamID); response.Write(steamID);
args.Write(response); args.Write(response);
server.WriteToSocket(response); server.WriteToSocket(response);
@ -821,7 +821,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.SavePlayerStats: case NetworkCommunication.SavePlayerStats:
{ {
if (stream.CanRead(8 + 4)) if (stream.CanRead(8 + 4))
{ {
@ -833,7 +833,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerAskingToChangeRole: case NetworkCommunication.OnPlayerAskingToChangeRole:
{ {
if (stream.CanRead(8 + 1)) if (stream.CanRead(8 + 1))
{ {
@ -854,7 +854,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerChangedRole: case NetworkCommunication.OnPlayerChangedRole:
{ {
if (stream.CanRead(8 + 1)) if (stream.CanRead(8 + 1))
{ {
@ -872,7 +872,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerJoinedASquad: case NetworkCommunication.OnPlayerJoinedASquad:
{ {
if (stream.CanRead(8 + 1)) if (stream.CanRead(8 + 1))
{ {
@ -890,7 +890,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerLeftSquad: case NetworkCommunication.OnPlayerLeftSquad:
{ {
if (stream.CanRead(8)) if (stream.CanRead(8))
{ {
@ -917,7 +917,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerChangedTeam: case NetworkCommunication.OnPlayerChangedTeam:
{ {
if (stream.CanRead(8 + 1)) if (stream.CanRead(8 + 1))
{ {
@ -936,7 +936,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerRequestingToSpawn: case NetworkCommunication.OnPlayerRequestingToSpawn:
{ {
if (stream.CanRead(2)) if (stream.CanRead(2))
{ {
@ -955,7 +955,7 @@ namespace BattleBitAPI.Server
//Respond back. //Respond back.
using (var response = Common.Serialization.Stream.Get()) using (var response = Common.Serialization.Stream.Get())
{ {
response.Write((byte)NetworkCommuncation.SpawnPlayer); response.Write((byte)NetworkCommunication.SpawnPlayer);
response.Write(steamID); response.Write(steamID);
request.Write(response); request.Write(response);
response.Write(vehicleID); response.Write(vehicleID);
@ -968,7 +968,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerReport: case NetworkCommunication.OnPlayerReport:
{ {
if (stream.CanRead(8 + 8 + 1 + 2)) if (stream.CanRead(8 + 8 + 1 + 2))
{ {
@ -987,7 +987,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerSpawn: case NetworkCommunication.OnPlayerSpawn:
{ {
if (stream.CanRead(8 + 2)) if (stream.CanRead(8 + 2))
{ {
@ -1012,7 +1012,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerDie: case NetworkCommunication.OnPlayerDie:
{ {
if (stream.CanRead(8)) if (stream.CanRead(8))
{ {
@ -1028,7 +1028,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.NotifyNewMapRotation: case NetworkCommunication.NotifyNewMapRotation:
{ {
if (stream.CanRead(4)) if (stream.CanRead(4))
{ {
@ -1046,7 +1046,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.NotifyNewGamemodeRotation: case NetworkCommunication.NotifyNewGamemodeRotation:
{ {
if (stream.CanRead(4)) if (stream.CanRead(4))
{ {
@ -1064,7 +1064,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.NotifyNewRoundState: case NetworkCommunication.NotifyNewRoundState:
{ {
if (stream.CanRead(GameServer<TPlayer>.mRoundSettings.Size)) if (stream.CanRead(GameServer<TPlayer>.mRoundSettings.Size))
{ {
@ -1084,7 +1084,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerAskingToChangeTeam: case NetworkCommunication.OnPlayerAskingToChangeTeam:
{ {
if (stream.CanRead(8 + 1)) if (stream.CanRead(8 + 1))
{ {
@ -1105,7 +1105,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.GameTick: case NetworkCommunication.GameTick:
{ {
if (stream.CanRead(4 + 4 + 4)) if (stream.CanRead(4 + 4 + 4))
{ {
@ -1152,7 +1152,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerGivenUp: case NetworkCommunication.OnPlayerGivenUp:
{ {
if (stream.CanRead(8)) if (stream.CanRead(8))
{ {
@ -1165,7 +1165,7 @@ namespace BattleBitAPI.Server
} }
break; break;
} }
case NetworkCommuncation.OnPlayerRevivedAnother: case NetworkCommunication.OnPlayerRevivedAnother:
{ {
if (stream.CanRead(8 + 8)) if (stream.CanRead(8 + 8))
{ {