2f107db...5202af9
This commit is contained in:
@@ -5,30 +5,12 @@ using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
class Client
|
||||
partial class Client : IDisposable
|
||||
{
|
||||
public string Name;
|
||||
public byte ID;
|
||||
public ulong SteamID;
|
||||
|
||||
private float karma = 1.0f;
|
||||
public float Karma
|
||||
{
|
||||
get
|
||||
{
|
||||
if (GameMain.Server == null) return 1.0f;
|
||||
if (!GameMain.Server.KarmaEnabled) return 1.0f;
|
||||
return karma;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (GameMain.Server == null) return;
|
||||
if (!GameMain.Server.KarmaEnabled) return;
|
||||
karma = Math.Min(Math.Max(value,0.0f),1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public byte TeamID = 0;
|
||||
|
||||
public Character.TeamType TeamID;
|
||||
|
||||
private Character character;
|
||||
public Character Character
|
||||
@@ -36,58 +18,59 @@ namespace Barotrauma.Networking
|
||||
get { return character; }
|
||||
set
|
||||
{
|
||||
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
|
||||
{
|
||||
GameMain.NetworkMember.LastClientListUpdateID++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value!=null)
|
||||
{
|
||||
DebugConsole.NewMessage(value.Name, Microsoft.Xna.Framework.Color.Yellow);
|
||||
}
|
||||
}
|
||||
character = value;
|
||||
if (character != null) HasSpawned = true;
|
||||
if (character != null)
|
||||
{
|
||||
HasSpawned = true;
|
||||
#if CLIENT
|
||||
GameMain.GameSession?.CrewManager?.SetPlayerVoiceIconState(this, muted, mutedLocally);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
public CharacterInfo CharacterInfo;
|
||||
public NetConnection Connection { get; set; }
|
||||
public bool InGame;
|
||||
|
||||
private bool muted;
|
||||
public bool Muted
|
||||
{
|
||||
get { return muted; }
|
||||
set
|
||||
{
|
||||
if (muted == value) { return; }
|
||||
muted = value;
|
||||
#if CLIENT
|
||||
GameMain.NetLobbyScreen.SetPlayerVoiceIconState(this, muted, mutedLocally);
|
||||
GameMain.GameSession?.CrewManager?.SetPlayerVoiceIconState(this, muted, mutedLocally);
|
||||
#endif
|
||||
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
|
||||
{
|
||||
GameMain.NetworkMember.LastClientListUpdateID++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public VoipQueue VoipQueue
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool InGame;
|
||||
public bool HasSpawned; //has the client spawned as a character during the current round
|
||||
|
||||
public UInt16 LastRecvGeneralUpdate = 0;
|
||||
|
||||
public UInt16 LastSentChatMsgID = 0; //last msg this client said
|
||||
public UInt16 LastRecvChatMsgID = 0; //last msg this client knows about
|
||||
|
||||
public UInt16 LastSentEntityEventID = 0;
|
||||
public UInt16 LastRecvEntityEventID = 0;
|
||||
|
||||
public UInt16 LastRecvCampaignUpdate = 0;
|
||||
public UInt16 LastRecvCampaignSave = 0;
|
||||
|
||||
public readonly List<ChatMessage> ChatMsgQueue = new List<ChatMessage>();
|
||||
public UInt16 LastChatMsgQueueID;
|
||||
|
||||
//latest chat messages sent by this client
|
||||
public readonly List<string> LastSentChatMessages = new List<string>();
|
||||
public float ChatSpamSpeed;
|
||||
public float ChatSpamTimer;
|
||||
public int ChatSpamCount;
|
||||
|
||||
public float KickAFKTimer;
|
||||
|
||||
public double MidRoundSyncTimeOut;
|
||||
|
||||
public bool NeedsMidRoundSync;
|
||||
//how many unique events the client missed before joining the server
|
||||
public UInt16 UnreceivedEntityEventCount;
|
||||
public UInt16 FirstNewEventID;
|
||||
|
||||
private List<Client> kickVoters;
|
||||
|
||||
//when was a specific entity event last sent to the client
|
||||
// key = event id, value = NetTime.Now when sending
|
||||
public readonly Dictionary<UInt16, float> EntityEventLastSent = new Dictionary<UInt16, float>();
|
||||
|
||||
public readonly Queue<Entity> PendingPositionUpdates = new Queue<Entity>();
|
||||
|
||||
public bool ReadyToStart;
|
||||
|
||||
public List<JobPrefab> JobPreferences;
|
||||
public JobPrefab AssignedJob;
|
||||
|
||||
public float DeleteDisconnectedTimer;
|
||||
public HashSet<string> GivenAchievements = new HashSet<string>();
|
||||
|
||||
public HashSet<string> GivenAchievements = new HashSet<string>();
|
||||
|
||||
@@ -98,34 +81,21 @@ namespace Barotrauma.Networking
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool SpectateOnly;
|
||||
|
||||
private object[] votes;
|
||||
|
||||
public void InitClientSync()
|
||||
{
|
||||
LastSentChatMsgID = 0;
|
||||
LastRecvChatMsgID = ChatMessage.LastID;
|
||||
|
||||
LastRecvGeneralUpdate = 0;
|
||||
|
||||
LastRecvEntityEventID = 0;
|
||||
|
||||
UnreceivedEntityEventCount = 0;
|
||||
NeedsMidRoundSync = false;
|
||||
}
|
||||
|
||||
public int KickVoteCount
|
||||
{
|
||||
get { return kickVoters.Count; }
|
||||
}
|
||||
|
||||
public Client(NetPeer server, string name, byte ID)
|
||||
/*public Client(NetPeer server, string name, byte ID)
|
||||
: this(name, ID)
|
||||
{
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
partial void InitProjSpecific();
|
||||
partial void DisposeProjSpecific();
|
||||
public Client(string name, byte ID)
|
||||
{
|
||||
this.Name = name;
|
||||
@@ -136,56 +106,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
votes = new object[Enum.GetNames(typeof(VoteType)).Length];
|
||||
|
||||
JobPreferences = new List<JobPrefab>(JobPrefab.List.GetRange(0, Math.Min(JobPrefab.List.Count, 3)));
|
||||
}
|
||||
|
||||
public static bool IsValidName(string name, GameServer server)
|
||||
{
|
||||
char[] disallowedChars = new char[] { ';', ',', '<', '>', '/', '\\', '[', ']', '"', '?' };
|
||||
if (name.Any(c => disallowedChars.Contains(c))) return false;
|
||||
|
||||
foreach (char character in name)
|
||||
{
|
||||
if (!server.AllowedClientNameChars.Any(charRange => (int)character >= charRange.First && (int)character <= charRange.Second)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string SanitizeName(string name)
|
||||
{
|
||||
name = name.Trim();
|
||||
if (name.Length > 20)
|
||||
{
|
||||
name = name.Substring(0, 20);
|
||||
}
|
||||
string rName = "";
|
||||
for (int i = 0; i < name.Length; i++)
|
||||
{
|
||||
rName += name[i] < 32 ? '?' : name[i];
|
||||
}
|
||||
return rName;
|
||||
}
|
||||
|
||||
public void SetPermissions(ClientPermissions permissions, List<DebugConsole.Command> permittedConsoleCommands)
|
||||
{
|
||||
this.Permissions = permissions;
|
||||
this.PermittedConsoleCommands = new List<DebugConsole.Command>(permittedConsoleCommands);
|
||||
}
|
||||
|
||||
public void GivePermission(ClientPermissions permission)
|
||||
{
|
||||
if (!this.Permissions.HasFlag(permission)) this.Permissions |= permission;
|
||||
}
|
||||
|
||||
public void RemovePermission(ClientPermissions permission)
|
||||
{
|
||||
if (this.Permissions.HasFlag(permission)) this.Permissions &= ~permission;
|
||||
}
|
||||
|
||||
public bool HasPermission(ClientPermissions permission)
|
||||
{
|
||||
return this.Permissions.HasFlag(permission);
|
||||
InitProjSpecific();
|
||||
}
|
||||
|
||||
public T GetVote<T>(VoteType voteType)
|
||||
@@ -235,6 +156,60 @@ namespace Barotrauma.Networking
|
||||
client.kickVoters.RemoveAll(voter => !connectedClients.Contains(voter));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void WritePermissions(NetBuffer msg)
|
||||
{
|
||||
msg.Write(ID);
|
||||
msg.Write((UInt16)Permissions);
|
||||
if (HasPermission(ClientPermissions.ConsoleCommands))
|
||||
{
|
||||
msg.Write((UInt16)PermittedConsoleCommands.Count);
|
||||
foreach (DebugConsole.Command command in PermittedConsoleCommands)
|
||||
{
|
||||
msg.Write(command.names[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void ReadPermissions(NetBuffer inc, out ClientPermissions permissions, out List<DebugConsole.Command> permittedCommands)
|
||||
{
|
||||
UInt16 permissionsInt = inc.ReadUInt16();
|
||||
|
||||
permissions = ClientPermissions.None;
|
||||
permittedCommands = new List<DebugConsole.Command>();
|
||||
try
|
||||
{
|
||||
permissions = (ClientPermissions)permissionsInt;
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (permissions.HasFlag(ClientPermissions.ConsoleCommands))
|
||||
{
|
||||
UInt16 commandCount = inc.ReadUInt16();
|
||||
for (int i = 0; i < commandCount; i++)
|
||||
{
|
||||
string commandName = inc.ReadString();
|
||||
var consoleCommand = DebugConsole.Commands.Find(c => c.names.Contains(commandName));
|
||||
if (consoleCommand != null)
|
||||
{
|
||||
permittedCommands.Add(consoleCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadPermissions(NetIncomingMessage inc)
|
||||
{
|
||||
ClientPermissions permissions = ClientPermissions.None;
|
||||
List<DebugConsole.Command> permittedCommands = new List<DebugConsole.Command>();
|
||||
ReadPermissions(inc, out permissions, out permittedCommands);
|
||||
SetPermissions(permissions, permittedCommands);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeProjSpecific();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user