Beispiel #1
0
        protected override void SendClientRconCommands()
        {
            if (SendRconCommandsClients.Count == 0)
            {
                return;
            }


            var clientId = SendRconCommandsClients.Peek();

            void Reset()
            {
                if (Clients[clientId].SendCommandsEnumerator != null)
                {
                    Clients[clientId].SendCommandsEnumerator.Dispose();
                    Clients[clientId].SendCommandsEnumerator = null;
                }

                SendRconCommandsClients.Dequeue();
            }

            if (Clients[clientId].State == ServerClientState.Empty ||
                Clients[clientId].SendCommandsEnumerator == null)
            {
                Reset();
                return;
            }

            var sended = 0;

            while (sended < 16 && Clients[clientId].SendCommandsEnumerator.MoveNext())
            {
                var command = Clients[clientId].SendCommandsEnumerator.Current.Value;
                SendRconCommandAdd(command, clientId);
                sended++;
            }

            if (sended == 0)
            {
                Reset();
            }
        }
Beispiel #2
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);
            }
        }