protected virtual void ConsoleStatus(ConsoleCommandResult result, int clientId, ref object data) { for (var i = 0; i < Clients.Length; i++) { if (Clients[i].State == ServerClientState.Empty) { continue; } string line; var endPoint = NetworkServer.ClientEndPoint(i); if (ClientInGame(i)) { var auth = Clients[i].AccessLevel == BaseServerClient.AuthedAdmin ? "(admin)" : Clients[i].AccessLevel == BaseServerClient.AuthedModerator ? "(moderator)" : string.Empty; line = $"id={i} endpoint={endPoint} client={Clients[i].Version:X} name='{ClientName(i)}' " + $"score={GameContext.GameController.Score(i)} team={GameContext.Players[i].Team} {auth}"; } else { line = $"id={i} endpoint={endPoint} connecting"; } Console.Print(OutputLevel.Standard, "server", line); } }
protected override void ClientDisconnected(int clientId, string reason) { Console.Print(OutputLevel.Standard, "server", $"client disconnected. cid={clientId} addr={NetworkServer.ClientEndPoint(clientId)} reason='{reason}'"); if (Clients[clientId].State >= ServerClientState.Ready) { Clients[clientId].Quitting = true; PlayerDisconnected?.Invoke(clientId, reason); } Clients[clientId].State = ServerClientState.Empty; }
protected override void NetMsgReady(Chunk packet, UnPacker unPacker, int clientId) { if (!packet.Flags.HasFlag(SendFlags.Vital)) { return; } if (Clients[clientId].State != ServerClientState.Connecting) { return; } Console.Print(OutputLevel.AddInfo, "server", $"player is ready. ClientId={clientId} addr={NetworkServer.ClientEndPoint(clientId)}"); Clients[clientId].State = ServerClientState.Ready; PlayerReady?.Invoke(clientId); var msg = new MsgPacker((int)NetworkMessages.ServerConnectionReady, true); SendMsg(msg, MsgFlags.Vital | MsgFlags.Flush, clientId); }
protected override void NetMsgEnterGame(Chunk packet, UnPacker unPacker, int clientId) { if (!packet.Flags.HasFlag(SendFlags.Vital)) { return; } if (Clients[clientId].State != ServerClientState.Ready) { return; } if (!GameContext.IsClientReady(clientId)) { return; } Console.Print(OutputLevel.Standard, "server", $"player has entered the game. ClientId={clientId} addr={NetworkServer.ClientEndPoint(clientId)}"); Clients[clientId].State = ServerClientState.InGame; SendServerInfo(clientId); PlayerEnter?.Invoke(clientId); }
protected override void NetMsgRconAuth(Chunk packet, UnPacker unPacker, int clientId) { if (IsAuthed(clientId)) { return; } var password = unPacker.GetString(SanitizeType.SanitizeCC); if (!packet.Flags.HasFlag(SendFlags.Vital) || unPacker.Error) { return; } // TODO send map list if (string.IsNullOrEmpty(Config["SvRconPassword"]) && string.IsNullOrEmpty(Config["SvRconModPassword"])) { SendRconLine(clientId, "No rcon password set on server. Set sv_rcon_password and/or sv_rcon_mod_password to enable the remote console."); return; } var authed = false; var format = string.Empty; var authLevel = 0; if (!string.IsNullOrEmpty(Config["SvRconPassword"]) && Config["SvRconPassword"] == password) { authed = true; format = $"clientId={clientId} authed 'admin'"; authLevel = BaseServerClient.AuthedAdmin; SendRconLine(clientId, "Admin authentication successful. Full remote console access granted."); } else if (!string.IsNullOrEmpty(Config["SvRconModPassword"]) && Config["SvRconModPassword"] == password) { authed = true; format = $"clientId={clientId} authed 'moderator'"; authLevel = BaseServerClient.AuthedModerator; SendRconLine(clientId, "Moderator authentication successful. Limited remote console access granted."); } else if (Config["SvRconMaxTries"]) { Clients[clientId].AuthTries++; SendRconLine(clientId, $"Wrong password {Clients[clientId].AuthTries}/{Config["SvRconMaxTries"]}."); if (Clients[clientId].AuthTries >= Config["SvRconMaxTries"]) { if (Config["SvRconBantime"]) { NetworkBan.BanAddr(NetworkServer.ClientEndPoint(clientId), Config["SvRconBantime"] * 60, "Too many remote console authentication tries"); } else { Kick(clientId, "Too many remote console authentication tries"); } } } else { SendRconLine(clientId, "Wrong password"); } if (authed) { var msg = new MsgPacker((int)NetworkMessages.ServerRconAuthOn, true); SendMsg(msg, MsgFlags.Vital, clientId); Console.Print(OutputLevel.Standard, "server", format); Clients[clientId].AccessLevel = authLevel; Clients[clientId].SendCommandsEnumerator = Console.GetCommands(authLevel, ConfigFlags.Server).GetEnumerator(); SendRconCommandsClients.Enqueue(clientId); } }
public override IPEndPoint ClientEndPoint(int clientId) { return(Clients[clientId].State == ServerClientState.InGame ? NetworkServer.ClientEndPoint(clientId) : null); }
protected override void NetMsgReady(NetworkChunk packet, Unpacker unpacker, int clientId) { if (Clients[clientId].State != ServerClientState.CONNECTING) { return; } Console.Print(OutputLevel.ADDINFO, "server", $"player is ready. ClientID={clientId} addr={NetworkServer.ClientEndPoint(clientId)}"); Clients[clientId].State = ServerClientState.READY; GameContext.OnClientConnected(clientId); var msg = new MsgPacker((int)NetworkMessages.SV_CON_READY); SendMsgEx(msg, MsgFlags.VITAL | MsgFlags.FLUSH, clientId, true); }
protected override void NetMsgEnterGame(NetworkChunk packet, Unpacker unpacker, int clientId) { if (Clients[clientId].State != ServerClientState.READY || !GameContext.IsClientReady(clientId)) { return; } Console.Print(OutputLevel.STANDARD, "server", $"player has entered the game. ClientID={clientId} addr={NetworkServer.ClientEndPoint(clientId)}"); Clients[clientId].State = ServerClientState.IN_GAME; GameContext.OnClientEnter(clientId); }