示例#1
0
        protected override void NetMsgInfo(Chunk packet, UnPacker unPacker, int clientId)
        {
            if (!packet.Flags.HasFlag(SendFlags.Vital))
            {
                return;
            }

            if (Clients[clientId].State != ServerClientState.Auth)
            {
                return;
            }

            var version = unPacker.GetString(SanitizeType.SanitizeCC);

            if (string.IsNullOrEmpty(version) || !version.StartsWith(GameContext.NetVersion))
            {
                Kick(clientId, $"Wrong version. Server is running '{GameContext.NetVersion}' and client '{version}'");
                return;
            }

            var password = unPacker.GetString(SanitizeType.SanitizeCC);

            if (!string.IsNullOrEmpty(Config["Password"]) && password != Config["Password"])
            {
                Kick(clientId, "Wrong password");
                return;
            }

            Clients[clientId].Version = unPacker.GetInt();
            Clients[clientId].State   = ServerClientState.Connecting;
            SendMap(clientId);
        }
示例#2
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Name     = unpacker.GetString(Sanitize);
            ClientId = unpacker.GetInt();
            Reason   = unpacker.GetString(Sanitize);

            return(unpacker.Error);
        }
示例#3
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            VoteType = unpacker.GetString(Sanitize);
            Value    = unpacker.GetString(Sanitize);
            Reason   = unpacker.GetString(Sanitize);
            Force    = unpacker.GetBool();

            return(unpacker.Error);
        }
示例#4
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Name    = unpacker.GetString(Sanitize);
            Clan    = unpacker.GetString(Sanitize);
            Country = unpacker.GetInt();
            unpacker.GetString(SkinPartNames, Sanitize);
            unpacker.GetBool(UseCustomColors);
            unpacker.GetInt(SkinPartColors);

            return(unpacker.Error);
        }
示例#5
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ClientID    = unpacker.GetInt();
            VoteType    = (Vote)unpacker.GetInt();
            Timeout     = unpacker.GetInt();
            Description = unpacker.GetString(Sanitize);
            Reason      = unpacker.GetString(Sanitize);

            if (VoteType < 0 || VoteType >= Vote.NumTypes)
            {
                failedOn = nameof(VoteType);
            }
            if (Timeout < 0 || Timeout > 60)
            {
                failedOn = nameof(Timeout);
            }

            return(unpacker.Error);
        }
示例#6
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ChatMode = (ChatMode)unpacker.GetInt();
            TargetId = unpacker.GetInt();
            Message  = unpacker.GetString(Sanitize);

            if (ChatMode < 0 || ChatMode >= ChatMode.NumModes)
            {
                failedOn = nameof(ChatMode);
            }

            return(unpacker.Error);
        }
示例#7
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            Name     = unpacker.GetString(Sanitize);
            ClientId = unpacker.GetInt();
            Team     = (Team)unpacker.GetInt();

            if (Team < Team.Spectators || Team > Team.Blue)
            {
                failedOn = nameof(Team);
            }

            return(unpacker.Error);
        }
示例#8
0
        public override bool UnPackError(UnPacker unpacker, ref string failedOn)
        {
            ClientID = unpacker.GetInt();
            Local    = unpacker.GetBool();
            Team     = (Team)unpacker.GetInt();
            Name     = unpacker.GetString(Sanitize);
            Clan     = unpacker.GetString(Sanitize);
            Country  = unpacker.GetInt();

            unpacker.GetString(SkinPartNames, Sanitize);
            unpacker.GetBool(UseCustomColors);
            unpacker.GetInt(SkinPartColors);

            Silent = unpacker.GetBool();


            if (Team < Team.Spectators || Team > Team.Blue)
            {
                failedOn = nameof(Team);
            }

            return(unpacker.Error);
        }
示例#9
0
        protected override void NetMsgRconCmd(Chunk packet, UnPacker unPacker, int clientId)
        {
            if (!packet.Flags.HasFlag(SendFlags.Vital) || unPacker.Error)
            {
                return;
            }

            if (!IsAuthed(clientId))
            {
                return;
            }

            var command = unPacker.GetString(SanitizeType.SanitizeCC);

            if (string.IsNullOrEmpty(command))
            {
                return;
            }

            Console.Print(OutputLevel.AddInfo, "server", $"ClientId={clientId} execute rcon command: '{command}'");
            Console.ExecuteLine(command, Clients[clientId].AccessLevel, clientId);
        }
示例#10
0
        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);
            }
        }
示例#11
0
 public override bool UnPackError(UnPacker unpacker, ref string failedOn)
 {
     Description = unpacker.GetString(Sanitize);
     return(unpacker.Error);
 }