2023-08-11 14:44:54 +03:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Net;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
using System.Net.Sockets;
|
2023-08-01 22:11:52 +03:00
|
|
|
|
using System.Numerics;
|
|
|
|
|
using System.Text;
|
2023-07-30 19:31:06 +03:00
|
|
|
|
using BattleBitAPI.Common;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
using BattleBitAPI.Common.Extentions;
|
|
|
|
|
using BattleBitAPI.Networking;
|
|
|
|
|
using CommunityServerAPI.BattleBitAPI;
|
|
|
|
|
|
|
|
|
|
namespace BattleBitAPI.Server
|
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public class GameServer<TPlayer> : System.IDisposable where TPlayer : Player<TPlayer>
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
|
|
|
|
// ---- Public Variables ----
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public ulong ServerHash => mInternal.ServerHash;
|
|
|
|
|
public bool IsConnected => mInternal.IsConnected;
|
|
|
|
|
public IPAddress GameIP => mInternal.GameIP;
|
|
|
|
|
public int GamePort => mInternal.GamePort;
|
|
|
|
|
|
|
|
|
|
public TcpClient Socket => mInternal.Socket;
|
|
|
|
|
public bool IsPasswordProtected => mInternal.IsPasswordProtected;
|
|
|
|
|
public string ServerName => mInternal.ServerName;
|
|
|
|
|
public string Gamemode => mInternal.Gamemode;
|
|
|
|
|
public string Map => mInternal.Map;
|
|
|
|
|
public MapSize MapSize => mInternal.MapSize;
|
|
|
|
|
public MapDayNight DayNight => mInternal.DayNight;
|
|
|
|
|
public int CurrentPlayers => mInternal.CurrentPlayers;
|
|
|
|
|
public int InQueuePlayers => mInternal.InQueuePlayers;
|
|
|
|
|
public int MaxPlayers => mInternal.MaxPlayers;
|
|
|
|
|
public string LoadingScreenText => mInternal.LoadingScreenText;
|
|
|
|
|
public string ServerRulesText => mInternal.ServerRulesText;
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public ServerSettings<TPlayer> ServerSettings => mInternal.ServerSettings;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public MapRotation<TPlayer> MapRotation => mInternal.MapRotation;
|
|
|
|
|
public GamemodeRotation<TPlayer> GamemodeRotation => mInternal.GamemodeRotation;
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public RoundSettings<TPlayer> RoundSettings => mInternal.RoundSettings;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public string TerminationReason => mInternal.TerminationReason;
|
|
|
|
|
public bool ReconnectFlag => mInternal.ReconnectFlag;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
|
|
|
|
// ---- Private Variables ----
|
2023-08-11 11:04:47 +03:00
|
|
|
|
private Internal mInternal;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
|
|
|
|
// ---- Tick ----
|
|
|
|
|
public async Task Tick()
|
|
|
|
|
{
|
|
|
|
|
if (!this.IsConnected)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-08-11 14:44:54 +03:00
|
|
|
|
if (this.mInternal.IsDirtyRoomSettings)
|
2023-08-01 22:11:52 +03:00
|
|
|
|
{
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.mInternal.IsDirtyRoomSettings = false;
|
2023-08-01 22:11:52 +03:00
|
|
|
|
|
|
|
|
|
//Send new settings
|
|
|
|
|
using (var pck = Common.Serialization.Stream.Get())
|
|
|
|
|
{
|
|
|
|
|
pck.Write((byte)NetworkCommuncation.SetNewRoomSettings);
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.mInternal._RoomSettings.Write(pck);
|
2023-08-01 22:11:52 +03:00
|
|
|
|
WriteToSocket(pck);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-11 14:44:54 +03:00
|
|
|
|
if (this.mInternal.IsDirtyMapRotation)
|
2023-08-01 22:11:52 +03:00
|
|
|
|
{
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.mInternal.IsDirtyMapRotation = false;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mBuilder.Clear();
|
2023-08-01 22:11:52 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mBuilder.Append("setmaprotation ");
|
|
|
|
|
lock (this.mInternal._MapRotation)
|
|
|
|
|
foreach (var map in this.mInternal._MapRotation)
|
2023-08-01 22:11:52 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mBuilder.Append(map);
|
|
|
|
|
this.mInternal.mBuilder.Append(',');
|
2023-08-01 22:11:52 +03:00
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.ExecuteCommand(this.mInternal.mBuilder.ToString());
|
2023-08-01 22:11:52 +03:00
|
|
|
|
}
|
2023-08-11 14:44:54 +03:00
|
|
|
|
if (this.mInternal.IsDirtyGamemodeRotation)
|
2023-08-01 22:11:52 +03:00
|
|
|
|
{
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.mInternal.IsDirtyGamemodeRotation = false;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mBuilder.Clear();
|
2023-08-01 22:11:52 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mBuilder.Append("setgamemoderotation ");
|
|
|
|
|
lock (this.mInternal._GamemodeRotation)
|
|
|
|
|
{
|
|
|
|
|
foreach (var gamemode in this.mInternal._GamemodeRotation)
|
2023-08-01 22:11:52 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mBuilder.Append(gamemode);
|
|
|
|
|
this.mInternal.mBuilder.Append(',');
|
2023-08-01 22:11:52 +03:00
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
}
|
|
|
|
|
this.ExecuteCommand(this.mInternal.mBuilder.ToString());
|
2023-08-01 22:11:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 15:15:17 +03:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//Are we still connected on socket level?
|
|
|
|
|
if (!Socket.Connected)
|
|
|
|
|
{
|
|
|
|
|
mClose("Connection was terminated.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 01:38:29 +03:00
|
|
|
|
//Did user requested to close connection?
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.mWantsToCloseConnection)
|
2023-08-11 01:38:29 +03:00
|
|
|
|
{
|
|
|
|
|
mClose(this.TerminationReason);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 15:15:17 +03:00
|
|
|
|
var networkStream = Socket.GetStream();
|
|
|
|
|
|
|
|
|
|
//Read network packages.
|
|
|
|
|
while (Socket.Available > 0)
|
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mLastPackageReceived = Extentions.TickCount;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
|
|
|
|
//Do we know the package size?
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.mReadPackageSize == 0)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
|
|
|
|
const int sizeToRead = 4;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
int leftSizeToRead = sizeToRead - this.mInternal.mReadStream.WritePosition;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
int read = await networkStream.ReadAsync(this.mInternal.mReadStream.Buffer, this.mInternal.mReadStream.WritePosition, leftSizeToRead);
|
2023-03-03 15:15:17 +03:00
|
|
|
|
if (read <= 0)
|
|
|
|
|
throw new Exception("Connection was terminated.");
|
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mReadStream.WritePosition += read;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
|
|
|
|
//Did we receive the package?
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.mReadStream.WritePosition >= 4)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
|
|
|
|
//Read the package size
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mReadPackageSize = this.mInternal.mReadStream.ReadUInt32();
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.mReadPackageSize > Const.MaxNetworkPackageSize)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
throw new Exception("Incoming package was larger than 'Conts.MaxNetworkPackageSize'");
|
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mReadStream.Reset();
|
2023-03-03 15:15:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
int sizeToRead = (int)this.mInternal.mReadPackageSize;
|
|
|
|
|
int leftSizeToRead = sizeToRead - this.mInternal.mReadStream.WritePosition;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
int read = await networkStream.ReadAsync(this.mInternal.mReadStream.Buffer, this.mInternal.mReadStream.WritePosition, leftSizeToRead);
|
2023-03-03 15:15:17 +03:00
|
|
|
|
if (read <= 0)
|
|
|
|
|
throw new Exception("Connection was terminated.");
|
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mReadStream.WritePosition += read;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
|
|
|
|
//Do we have the package?
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.mReadStream.WritePosition >= this.mInternal.mReadPackageSize)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mReadPackageSize = 0;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
await this.mInternal.mExecutionFunc(this, this.mInternal, this.mInternal.mReadStream);
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
|
|
|
|
//Reset
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mReadStream.Reset();
|
2023-03-03 15:15:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Send the network packages.
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.mWriteStream.WritePosition > 0)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
lock (this.mInternal.mWriteStream)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.mWriteStream.WritePosition > 0)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
networkStream.WriteAsync(this.mInternal.mWriteStream.Buffer, 0, this.mInternal.mWriteStream.WritePosition);
|
|
|
|
|
this.mInternal.mWriteStream.WritePosition = 0;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mLastPackageSent = Extentions.TickCount;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Are we timed out?
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if ((Extentions.TickCount - this.mInternal.mLastPackageReceived) > Const.NetworkTimeout)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
throw new Exception("Timedout.");
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
|
|
|
|
//Send keep alive if needed
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if ((Extentions.TickCount - this.mInternal.mLastPackageSent) > Const.NetworkKeepAlive)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
|
|
|
|
//Send keep alive.
|
2023-08-11 11:04:47 +03:00
|
|
|
|
await networkStream.WriteAsync(this.mInternal.mKeepAliveBuffer, 0, 4);
|
2023-07-28 03:24:00 +03:00
|
|
|
|
await networkStream.FlushAsync();
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mLastPackageSent = Extentions.TickCount;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
mClose(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-30 19:31:06 +03:00
|
|
|
|
// ---- Team ----
|
2023-08-11 13:49:51 +03:00
|
|
|
|
public IEnumerable<TPlayer> AllPlayers
|
2023-07-30 19:31:06 +03:00
|
|
|
|
{
|
2023-08-11 13:49:51 +03:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var list = new List<TPlayer>(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;
|
2023-07-30 19:31:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
// ---- Virtual ----
|
|
|
|
|
public virtual async Task OnConnected()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnTick()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnReconnected()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnDisconnected()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerConnected(TPlayer player)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerDisconnected(TPlayer player)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task<bool> OnPlayerTypedMessage(TPlayer player, ChatChannel channel, string msg)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task<PlayerStats> OnGetPlayerStats(ulong steamID, PlayerStats officialStats)
|
|
|
|
|
{
|
|
|
|
|
return officialStats;
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnSavePlayerStats(ulong steamID, PlayerStats stats)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task<bool> OnPlayerRequestingToChangeRole(TPlayer player, GameRole role)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerChangedRole(TPlayer player, GameRole role)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerJoinedSquad(TPlayer player, Squads squad)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerLeftSquad(TPlayer player, Squads squad)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerChangeTeam(TPlayer player, Team team)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2023-08-11 12:34:11 +03:00
|
|
|
|
public virtual async Task<OnPlayerSpawnArguments> OnPlayerSpawning(TPlayer player, OnPlayerSpawnArguments request)
|
2023-08-11 11:04:47 +03:00
|
|
|
|
{
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerSpawned(TPlayer player)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerDied(TPlayer player)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnAPlayerKilledAnotherPlayer(OnPlayerKillArguments<TPlayer> args)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public virtual async Task OnPlayerReported(TPlayer from, TPlayer to, ReportReason reason, string additional)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 03:24:00 +03:00
|
|
|
|
// ---- Functions ----
|
|
|
|
|
public void WriteToSocket(Common.Serialization.Stream pck)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
lock (this.mInternal.mWriteStream)
|
2023-03-03 15:15:17 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mWriteStream.Write((uint)pck.WritePosition);
|
|
|
|
|
this.mInternal.mWriteStream.Write(pck.Buffer, 0, pck.WritePosition);
|
2023-07-28 03:24:00 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void ExecuteCommand(string cmd)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(cmd))
|
|
|
|
|
return;
|
2023-03-03 15:15:17 +03:00
|
|
|
|
|
2023-07-28 03:24:00 +03:00
|
|
|
|
int bytesLong = System.Text.Encoding.UTF8.GetByteCount(cmd);
|
2023-08-11 11:04:47 +03:00
|
|
|
|
lock (this.mInternal.mWriteStream)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.mWriteStream.Write((uint)(1 + 2 + bytesLong));
|
|
|
|
|
this.mInternal.mWriteStream.Write((byte)NetworkCommuncation.ExecuteCommand);
|
|
|
|
|
this.mInternal.mWriteStream.Write(cmd);
|
2023-03-03 15:15:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 03:24:00 +03:00
|
|
|
|
public void SetNewPassword(string newPassword)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("setpass " + newPassword);
|
|
|
|
|
}
|
|
|
|
|
public void SetPingLimit(int newPing)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("setmaxping " + newPing);
|
|
|
|
|
}
|
|
|
|
|
public void AnnounceShort(string msg)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("an " + msg);
|
|
|
|
|
}
|
|
|
|
|
public void AnnounceLong(string msg)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("ann " + msg);
|
|
|
|
|
}
|
|
|
|
|
public void UILogOnServer(string msg, float messageLifetime)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("serverlog " + msg + " " + messageLifetime);
|
|
|
|
|
}
|
|
|
|
|
public void ForceStartGame()
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("forcestart");
|
|
|
|
|
}
|
|
|
|
|
public void ForceEndGame()
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("endgame");
|
|
|
|
|
}
|
|
|
|
|
public void SayToChat(string msg)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("say " + msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopServer()
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("stop");
|
|
|
|
|
}
|
|
|
|
|
public void CloseServer()
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("notifyend");
|
|
|
|
|
}
|
|
|
|
|
public void KickAllPlayers()
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("kick all");
|
|
|
|
|
}
|
|
|
|
|
public void Kick(ulong steamID, string reason)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("kick " + steamID + " " + reason);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void Kick(Player<TPlayer> player, string reason)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
Kick(player.SteamID, reason);
|
|
|
|
|
}
|
|
|
|
|
public void Kill(ulong steamID)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("kill " + steamID);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void Kill(Player<TPlayer> player)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
Kill(player.SteamID);
|
|
|
|
|
}
|
|
|
|
|
public void ChangeTeam(ulong steamID)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("changeteam " + steamID);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void ChangeTeam(Player<TPlayer> player)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
ChangeTeam(player.SteamID);
|
|
|
|
|
}
|
|
|
|
|
public void KickFromSquad(ulong steamID)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("squadkick " + steamID);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void KickFromSquad(Player<TPlayer> player)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
KickFromSquad(player.SteamID);
|
|
|
|
|
}
|
|
|
|
|
public void DisbandPlayerSSquad(ulong steamID)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("squaddisband " + steamID);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void DisbandPlayerCurrentSquad(Player<TPlayer> player)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
DisbandPlayerSSquad(player.SteamID);
|
|
|
|
|
}
|
|
|
|
|
public void PromoteSquadLeader(ulong steamID)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("squadpromote " + steamID);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void PromoteSquadLeader(Player<TPlayer> player)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
PromoteSquadLeader(player.SteamID);
|
|
|
|
|
}
|
|
|
|
|
public void WarnPlayer(ulong steamID, string msg)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("warn " + steamID + " " + msg);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void WarnPlayer(Player<TPlayer> player, string msg)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
WarnPlayer(player.SteamID, msg);
|
|
|
|
|
}
|
|
|
|
|
public void MessageToPlayer(ulong steamID, string msg)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("msg " + steamID + " " + msg);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void MessageToPlayer(Player<TPlayer> player, string msg)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
MessageToPlayer(player.SteamID, msg);
|
|
|
|
|
}
|
2023-07-30 19:31:06 +03:00
|
|
|
|
public void SetRoleTo(ulong steamID, GameRole role)
|
|
|
|
|
{
|
|
|
|
|
ExecuteCommand("setrole " + steamID + " " + role);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void SetRoleTo(Player<TPlayer> player, GameRole role)
|
2023-07-30 19:31:06 +03:00
|
|
|
|
{
|
|
|
|
|
SetRoleTo(player.SteamID, role);
|
|
|
|
|
}
|
2023-08-01 22:11:52 +03:00
|
|
|
|
public void SpawnPlayer(ulong steamID, PlayerLoadout loadout, PlayerWearings wearings, Vector3 position, Vector3 lookDirection, PlayerStand stand, float spawnProtection)
|
|
|
|
|
{
|
2023-08-11 12:34:11 +03:00
|
|
|
|
var request = new OnPlayerSpawnArguments()
|
2023-08-01 22:11:52 +03:00
|
|
|
|
{
|
|
|
|
|
Loadout = loadout,
|
|
|
|
|
Wearings = wearings,
|
|
|
|
|
RequestedPoint = PlayerSpawningPosition.Null,
|
|
|
|
|
SpawnPosition = position,
|
|
|
|
|
LookDirection = lookDirection,
|
|
|
|
|
SpawnStand = stand,
|
|
|
|
|
SpawnProtection = spawnProtection
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Respond back.
|
|
|
|
|
using (var response = Common.Serialization.Stream.Get())
|
|
|
|
|
{
|
|
|
|
|
response.Write((byte)NetworkCommuncation.SpawnPlayer);
|
|
|
|
|
response.Write(steamID);
|
|
|
|
|
request.Write(response);
|
|
|
|
|
response.Write((ushort)0);
|
|
|
|
|
|
|
|
|
|
WriteToSocket(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void SpawnPlayer(Player<TPlayer> player, PlayerLoadout loadout, PlayerWearings wearings, Vector3 position, Vector3 lookDirection, PlayerStand stand, float spawnProtection)
|
2023-08-01 22:11:52 +03:00
|
|
|
|
{
|
|
|
|
|
SpawnPlayer(player.SteamID, loadout, wearings, position, lookDirection, stand, spawnProtection);
|
|
|
|
|
}
|
2023-07-28 03:24:00 +03:00
|
|
|
|
|
|
|
|
|
// ---- Closing ----
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void CloseConnection(string additionInfo = "")
|
2023-08-11 01:38:29 +03:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(additionInfo))
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.TerminationReason = additionInfo;
|
2023-08-11 01:38:29 +03:00
|
|
|
|
else
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.TerminationReason = "User requested to terminate the connection";
|
|
|
|
|
this.mInternal.mWantsToCloseConnection = true;
|
2023-08-11 01:38:29 +03:00
|
|
|
|
}
|
2023-03-03 15:15:17 +03:00
|
|
|
|
private void mClose(string reason)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsConnected)
|
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.TerminationReason = reason;
|
|
|
|
|
this.mInternal.IsConnected = false;
|
2023-07-28 03:24:00 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Disposing ----
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
if (this.mInternal.Socket != null)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.mInternal.Socket.SafeClose();
|
|
|
|
|
this.mInternal.Socket = null;
|
2023-07-28 03:24:00 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Overrides ----
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
this.GameIP + ":" + this.GamePort + " - " +
|
|
|
|
|
this.ServerName;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
// ---- Static ----
|
|
|
|
|
public static TGameServer CreateInstance<TGameServer>(Internal @internal) where TGameServer : GameServer<TPlayer>
|
|
|
|
|
{
|
|
|
|
|
TGameServer gameServer = (TGameServer)Activator.CreateInstance(typeof(TGameServer));
|
|
|
|
|
gameServer.mInternal = @internal;
|
|
|
|
|
return gameServer;
|
|
|
|
|
}
|
2023-08-11 01:38:29 +03:00
|
|
|
|
|
2023-07-28 03:24:00 +03:00
|
|
|
|
// ---- Internal ----
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public class Internal
|
|
|
|
|
{
|
|
|
|
|
// ---- Variables ----
|
|
|
|
|
public ulong ServerHash;
|
|
|
|
|
public bool IsConnected;
|
|
|
|
|
public IPAddress GameIP;
|
|
|
|
|
public int GamePort;
|
|
|
|
|
public TcpClient Socket;
|
|
|
|
|
public Func<GameServer<TPlayer>, Internal, Common.Serialization.Stream, Task> mExecutionFunc;
|
|
|
|
|
public bool IsPasswordProtected;
|
|
|
|
|
public string ServerName;
|
|
|
|
|
public string Gamemode;
|
|
|
|
|
public string Map;
|
|
|
|
|
public MapSize MapSize;
|
|
|
|
|
public MapDayNight DayNight;
|
|
|
|
|
public int CurrentPlayers;
|
|
|
|
|
public int InQueuePlayers;
|
|
|
|
|
public int MaxPlayers;
|
|
|
|
|
public string LoadingScreenText;
|
|
|
|
|
public string ServerRulesText;
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public ServerSettings<TPlayer> ServerSettings;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public MapRotation<TPlayer> MapRotation;
|
|
|
|
|
public GamemodeRotation<TPlayer> GamemodeRotation;
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public RoundSettings<TPlayer> RoundSettings;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public string TerminationReason;
|
|
|
|
|
public bool ReconnectFlag;
|
|
|
|
|
|
|
|
|
|
// ---- Private Variables ----
|
|
|
|
|
public byte[] mKeepAliveBuffer;
|
|
|
|
|
public Common.Serialization.Stream mWriteStream;
|
|
|
|
|
public Common.Serialization.Stream mReadStream;
|
|
|
|
|
public uint mReadPackageSize;
|
|
|
|
|
public long mLastPackageReceived;
|
|
|
|
|
public long mLastPackageSent;
|
|
|
|
|
public bool mWantsToCloseConnection;
|
|
|
|
|
public StringBuilder mBuilder;
|
|
|
|
|
|
|
|
|
|
public Internal()
|
|
|
|
|
{
|
|
|
|
|
this.TerminationReason = string.Empty;
|
|
|
|
|
this.mWriteStream = new Common.Serialization.Stream()
|
|
|
|
|
{
|
|
|
|
|
Buffer = new byte[Const.MaxNetworkPackageSize],
|
|
|
|
|
InPool = false,
|
|
|
|
|
ReadPosition = 0,
|
|
|
|
|
WritePosition = 0,
|
|
|
|
|
};
|
|
|
|
|
this.mReadStream = new Common.Serialization.Stream()
|
|
|
|
|
{
|
|
|
|
|
Buffer = new byte[Const.MaxNetworkPackageSize],
|
|
|
|
|
InPool = false,
|
|
|
|
|
ReadPosition = 0,
|
|
|
|
|
WritePosition = 0,
|
|
|
|
|
};
|
|
|
|
|
this.mKeepAliveBuffer = new byte[4]
|
|
|
|
|
{
|
|
|
|
|
0,0,0,0,
|
|
|
|
|
};
|
|
|
|
|
this.mLastPackageReceived = Extentions.TickCount;
|
|
|
|
|
this.mLastPackageSent = Extentions.TickCount;
|
|
|
|
|
this.mBuilder = new StringBuilder(4096);
|
|
|
|
|
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.ServerSettings = new ServerSettings<TPlayer>(this);
|
2023-08-11 11:04:47 +03:00
|
|
|
|
this.MapRotation = new MapRotation<TPlayer>(this);
|
|
|
|
|
this.GamemodeRotation = new GamemodeRotation<TPlayer>(this);
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.RoundSettings = new RoundSettings<TPlayer>(this);
|
2023-08-11 11:04:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Players In Room ----
|
|
|
|
|
public Dictionary<ulong, Player<TPlayer>> Players = new Dictionary<ulong, Player<TPlayer>>(254);
|
2023-07-28 03:24:00 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
// ---- Room Settings ----
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public mRoomSettings _RoomSettings = new mRoomSettings();
|
|
|
|
|
public bool IsDirtyRoomSettings;
|
|
|
|
|
|
|
|
|
|
// ---- Round Settings ----
|
|
|
|
|
public mRoundSettings _RoundSettings = new mRoundSettings();
|
|
|
|
|
public bool IsDirtyRoundSettings;
|
2023-08-01 22:11:52 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
// ---- Map Rotation ----
|
|
|
|
|
public HashSet<string> _MapRotation = new HashSet<string>(8);
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public bool IsDirtyMapRotation = false;
|
2023-08-01 22:11:52 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
// ---- Gamemode Rotation ----
|
|
|
|
|
public HashSet<string> _GamemodeRotation = new HashSet<string>(8);
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public bool IsDirtyGamemodeRotation = false;
|
2023-08-01 22:11:52 +03:00
|
|
|
|
|
2023-08-11 11:04:47 +03:00
|
|
|
|
// ---- Public Functions ----
|
|
|
|
|
public void Set(Func<GameServer<TPlayer>, Internal, Common.Serialization.Stream, Task> func, TcpClient socket, IPAddress iP, int port, bool isPasswordProtected, string serverName, string gamemode, string map, MapSize mapSize, MapDayNight dayNight, int currentPlayers, int inQueuePlayers, int maxPlayers, string loadingScreenText, string serverRulesText)
|
|
|
|
|
{
|
|
|
|
|
this.ServerHash = ((ulong)port << 32) | (ulong)iP.ToUInt();
|
|
|
|
|
this.IsConnected = true;
|
|
|
|
|
this.GameIP = iP;
|
|
|
|
|
this.GamePort = port;
|
|
|
|
|
this.Socket = socket;
|
|
|
|
|
this.mExecutionFunc = func;
|
|
|
|
|
this.IsPasswordProtected = isPasswordProtected;
|
|
|
|
|
this.ServerName = serverName;
|
|
|
|
|
this.Gamemode = gamemode;
|
|
|
|
|
this.Map = map;
|
|
|
|
|
this.MapSize = mapSize;
|
|
|
|
|
this.DayNight = dayNight;
|
|
|
|
|
this.CurrentPlayers = currentPlayers;
|
|
|
|
|
this.InQueuePlayers = inQueuePlayers;
|
|
|
|
|
this.MaxPlayers = maxPlayers;
|
|
|
|
|
this.LoadingScreenText = loadingScreenText;
|
|
|
|
|
this.ServerRulesText = serverRulesText;
|
|
|
|
|
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.ServerSettings.Reset();
|
|
|
|
|
this._RoomSettings.Reset();
|
|
|
|
|
this.IsDirtyRoomSettings = false;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
|
|
|
|
|
this.MapRotation.Reset();
|
|
|
|
|
this._MapRotation.Clear();
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.IsDirtyMapRotation = false;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
|
|
|
|
|
this.GamemodeRotation.Reset();
|
|
|
|
|
this._GamemodeRotation.Clear();
|
2023-08-11 14:44:54 +03:00
|
|
|
|
this.IsDirtyGamemodeRotation = false;
|
|
|
|
|
|
|
|
|
|
this.RoundSettings.Reset();
|
|
|
|
|
this._RoundSettings.Reset();
|
|
|
|
|
this.IsDirtyRoundSettings = false;
|
2023-08-11 11:04:47 +03:00
|
|
|
|
|
|
|
|
|
this.TerminationReason = string.Empty;
|
|
|
|
|
this.ReconnectFlag = false;
|
|
|
|
|
|
|
|
|
|
this.mWriteStream.Reset();
|
|
|
|
|
this.mReadStream.Reset();
|
|
|
|
|
this.mReadPackageSize = 0;
|
|
|
|
|
this.mLastPackageReceived = Extentions.TickCount;
|
|
|
|
|
this.mLastPackageSent = Extentions.TickCount;
|
|
|
|
|
this.mWantsToCloseConnection = false;
|
|
|
|
|
this.mBuilder.Clear();
|
|
|
|
|
}
|
|
|
|
|
public void AddPlayer(Player<TPlayer> player)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
lock (Players)
|
|
|
|
|
{
|
|
|
|
|
Players.Remove(player.SteamID);
|
|
|
|
|
Players.Add(player.SteamID, player);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void RemovePlayer<TPlayer>(TPlayer player) where TPlayer : Player<TPlayer>
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
lock (Players)
|
|
|
|
|
Players.Remove(player.SteamID);
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public bool TryGetPlayer(ulong steamID, out Player<TPlayer> result)
|
2023-07-28 03:24:00 +03:00
|
|
|
|
{
|
|
|
|
|
lock (Players)
|
|
|
|
|
return Players.TryGetValue(steamID, out result);
|
|
|
|
|
}
|
2023-03-03 15:15:17 +03:00
|
|
|
|
}
|
2023-08-01 22:11:52 +03:00
|
|
|
|
public class mRoomSettings
|
|
|
|
|
{
|
|
|
|
|
public float DamageMultiplier = 1.0f;
|
|
|
|
|
public bool BleedingEnabled = true;
|
|
|
|
|
public bool StamineEnabled = false;
|
|
|
|
|
public bool FriendlyFireEnabled = false;
|
|
|
|
|
public bool HideMapVotes = true;
|
|
|
|
|
public bool OnlyWinnerTeamCanVote = false;
|
|
|
|
|
public bool HitMarkersEnabled = true;
|
|
|
|
|
public bool PointLogEnabled = true;
|
|
|
|
|
public bool SpectatorEnabled = true;
|
|
|
|
|
|
|
|
|
|
public byte MedicLimitPerSquad = 8;
|
|
|
|
|
public byte EngineerLimitPerSquad = 8;
|
|
|
|
|
public byte SupportLimitPerSquad = 8;
|
|
|
|
|
public byte ReconLimitPerSquad = 8;
|
|
|
|
|
|
|
|
|
|
public void Write(Common.Serialization.Stream ser)
|
|
|
|
|
{
|
|
|
|
|
ser.Write(this.DamageMultiplier);
|
|
|
|
|
ser.Write(this.BleedingEnabled);
|
|
|
|
|
ser.Write(this.StamineEnabled);
|
|
|
|
|
ser.Write(this.FriendlyFireEnabled);
|
|
|
|
|
ser.Write(this.HideMapVotes);
|
|
|
|
|
ser.Write(this.OnlyWinnerTeamCanVote);
|
|
|
|
|
ser.Write(this.HitMarkersEnabled);
|
|
|
|
|
ser.Write(this.PointLogEnabled);
|
|
|
|
|
ser.Write(this.SpectatorEnabled);
|
|
|
|
|
ser.Write(this.MedicLimitPerSquad);
|
|
|
|
|
ser.Write(this.EngineerLimitPerSquad);
|
|
|
|
|
ser.Write(this.SupportLimitPerSquad);
|
|
|
|
|
ser.Write(this.ReconLimitPerSquad);
|
|
|
|
|
}
|
|
|
|
|
public void Read(Common.Serialization.Stream ser)
|
|
|
|
|
{
|
|
|
|
|
this.DamageMultiplier = ser.ReadFloat();
|
|
|
|
|
this.BleedingEnabled = ser.ReadBool();
|
|
|
|
|
this.StamineEnabled = ser.ReadBool();
|
|
|
|
|
this.FriendlyFireEnabled = ser.ReadBool();
|
|
|
|
|
this.HideMapVotes = ser.ReadBool();
|
|
|
|
|
this.OnlyWinnerTeamCanVote = ser.ReadBool();
|
|
|
|
|
this.HitMarkersEnabled = ser.ReadBool();
|
|
|
|
|
this.PointLogEnabled = ser.ReadBool();
|
|
|
|
|
this.SpectatorEnabled = ser.ReadBool();
|
|
|
|
|
|
|
|
|
|
this.MedicLimitPerSquad = ser.ReadInt8();
|
|
|
|
|
this.EngineerLimitPerSquad = ser.ReadInt8();
|
|
|
|
|
this.SupportLimitPerSquad = ser.ReadInt8();
|
|
|
|
|
this.ReconLimitPerSquad = ser.ReadInt8();
|
|
|
|
|
}
|
2023-08-11 11:04:47 +03:00
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
this.DamageMultiplier = 1.0f;
|
|
|
|
|
this.BleedingEnabled = true;
|
|
|
|
|
this.StamineEnabled = false;
|
|
|
|
|
this.FriendlyFireEnabled = false;
|
|
|
|
|
this.HideMapVotes = true;
|
|
|
|
|
this.OnlyWinnerTeamCanVote = false;
|
|
|
|
|
this.HitMarkersEnabled = true;
|
|
|
|
|
this.PointLogEnabled = true;
|
|
|
|
|
this.SpectatorEnabled = true;
|
|
|
|
|
|
|
|
|
|
this.MedicLimitPerSquad = 8;
|
|
|
|
|
this.EngineerLimitPerSquad = 8;
|
|
|
|
|
this.SupportLimitPerSquad = 8;
|
|
|
|
|
this.ReconLimitPerSquad = 8;
|
|
|
|
|
}
|
2023-08-01 22:11:52 +03:00
|
|
|
|
}
|
2023-08-11 14:44:54 +03:00
|
|
|
|
public class mRoundSettings
|
|
|
|
|
{
|
|
|
|
|
public GameState State = GameState.WaitingForPlayers;
|
|
|
|
|
public int TeamATickets = 0;
|
|
|
|
|
public int TeamAMaxTickets = 1;
|
|
|
|
|
public int TeamBTickets = 0;
|
|
|
|
|
public int TeamBMaxTickets = 1;
|
|
|
|
|
public int PlayersToStart = 16;
|
|
|
|
|
public int SecondsLeftToEndOfRound = 60;
|
|
|
|
|
|
|
|
|
|
public void Write(Common.Serialization.Stream ser)
|
|
|
|
|
{
|
|
|
|
|
ser.Write((byte)this.State);
|
|
|
|
|
ser.Write(this.TeamATickets);
|
|
|
|
|
ser.Write(this.TeamAMaxTickets);
|
|
|
|
|
ser.Write(this.TeamBTickets);
|
|
|
|
|
ser.Write(this.TeamBMaxTickets);
|
|
|
|
|
ser.Write(this.PlayersToStart);
|
|
|
|
|
ser.Write(this.SecondsLeftToEndOfRound);
|
|
|
|
|
}
|
|
|
|
|
public void Read(Common.Serialization.Stream ser)
|
|
|
|
|
{
|
|
|
|
|
this.State = (GameState)ser.ReadInt8();
|
|
|
|
|
this.TeamATickets = ser.ReadInt32();
|
|
|
|
|
this.TeamAMaxTickets = ser.ReadInt32();
|
|
|
|
|
this.TeamBTickets = ser.ReadInt32();
|
|
|
|
|
this.TeamBMaxTickets = ser.ReadInt32();
|
|
|
|
|
this.PlayersToStart = ser.ReadInt32();
|
|
|
|
|
this.SecondsLeftToEndOfRound = ser.ReadInt32();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
this.State = GameState.WaitingForPlayers;
|
|
|
|
|
this.TeamATickets = 0;
|
|
|
|
|
this.TeamAMaxTickets = 1;
|
|
|
|
|
this.TeamBTickets = 0;
|
|
|
|
|
this.TeamBMaxTickets = 1;
|
|
|
|
|
this.PlayersToStart = 16;
|
|
|
|
|
this.SecondsLeftToEndOfRound = 60;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-03 15:15:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|