示例#1
0
 static public void Handle_CS_ModCommand(CS_ModCommand <Zone> pkt, Zone zone)
 {
     using (Data.InfantryDataContext db = zone._server.getContext())
     {
         Data.DB.history hist = new Data.DB.history();
         hist.sender    = pkt.sender;
         hist.recipient = pkt.recipient;
         hist.zone      = pkt.zone;
         hist.arena     = pkt.arena;
         hist.command   = pkt.command;
         hist.date      = DateTime.Now;
         db.histories.InsertOnSubmit(hist);
         db.SubmitChanges();
     }
 }
示例#2
0
        /// <summary>
        /// Creates a new packet based on the typeID and the received content
        /// inside the buffer. The user has to create an own implementation
        /// of this interface.
        /// </summary>
        public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size)
        {               //Ready our packet base
            PacketBase packet = null;

            size--;

            //Was it a system packet?
            if (buffer[offset++] == 0)
            {
                //Yes, find the appropriate type
                return(createSystemPacket(typeID, buffer, offset, size));
            }

            //So what was the typeid?
            switch (typeID)
            {
            case CS_Auth <T> .TypeID:
                packet = new CS_Auth <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerLogin <T> .TypeID:
                packet = new CS_PlayerLogin <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerUpdate <T> .TypeID:
                packet = new CS_PlayerUpdate <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerLeave <T> .TypeID:
                packet = new CS_PlayerLeave <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerBanner <T> .TypeID:
                packet = new CS_PlayerBanner <T>(typeID, buffer, offset, size);
                break;

            case CS_PlayerStatsRequest <T> .TypeID:
                packet = new CS_PlayerStatsRequest <T>(typeID, buffer, offset, size);
                break;

            case CS_Whisper <T> .TypeID:
                packet = new CS_Whisper <T>(typeID, buffer, offset, size);
                break;

            case CS_JoinChat <T> .TypeID:
                packet = new CS_JoinChat <T>(typeID, buffer, offset, size);
                break;

            case CS_LeaveChat <T> .TypeID:
                packet = new CS_LeaveChat <T>(typeID, buffer, offset, size);
                break;

            case CS_PrivateChat <T> .TypeID:
                packet = new CS_PrivateChat <T>(typeID, buffer, offset, size);
                break;

            case CS_ModCommand <T> .TypeID:
                packet = new CS_ModCommand <T>(typeID, buffer, offset, size);
                break;

            case CS_Squads <T> .TypeID:
                packet = new CS_Squads <T>(typeID, buffer, offset, size);
                break;

            case CS_ChatQuery <T> .TypeID:
                packet = new CS_ChatQuery <T>(typeID, buffer, offset, size);
                break;

            case Disconnect <T> .TypeID:
                packet = new Disconnect <T>(typeID, buffer, offset, size);
                break;

            case CS_Ban <T> .TypeID:
                packet = new CS_Ban <T>(typeID, buffer, offset, size);
                break;

            case CS_SquadMatch <T> .TypeID:
                packet = new CS_SquadMatch <T>(typeID, buffer, offset, size);
                break;

            case CS_ModQuery <T> .TypeID:
                packet = new CS_ModQuery <T>(typeID, buffer, offset, size);
                break;

            case CS_ChatCommand <T> .TypeID:
                packet = new CS_ChatCommand <T>(typeID, buffer, offset, size);
                break;

            case CS_StatsUpdate <T> .TypeID:
                packet = new CS_StatsUpdate <T>(typeID, buffer, offset, size);
                break;

            case CS_ArenaUpdate <T> .TypeID:
                packet = new CS_ArenaUpdate <T>(typeID, buffer, offset, size);
                break;

            default:
                //An undefined packet.
                packet = new PacketDummy(typeID, buffer, offset, size);
                break;
            }

            return(packet);
        }
        /// <summary>
        /// Handles a moderator command received from a player
        /// </summary>
        public void playerModCommand(Player from, Player recipient, string command, string payload, int bong)
        {       //Attempt to find the appropriate handler
            HandlerDescriptor handler;

            if (!_commandRegistrar._modCommands.TryGetValue(command.ToLower(), out handler))
            {
                if (String.IsNullOrEmpty(command) && !String.IsNullOrWhiteSpace(payload) &&
                    from.PermissionLevelLocal > Data.PlayerPermission.Normal)
                {
                    //Mod chat
                    if (_server.IsStandalone)
                    {
                        foreach (Player p in Players)
                        {
                            if (p != from && p.PermissionLevelLocal >= Data.PlayerPermission.ArenaMod)
                            {
                                p.sendMessage(0, String.Format("&[ModChat] [{0}]> {1}",
                                                               from._alias, payload));
                            }
                        }
                    }
                    else
                    {
                        //For arena owners only
                        foreach (Player p in Players)
                        {
                            if (p != from && p._permissionTemp >= Data.PlayerPermission.ArenaMod)
                            {
                                p.sendMessage(0, String.Format("&[ModChat] [{0}]> {1}", from._alias, payload));
                            }
                        }

                        //For all other mods
                        CS_ChatQuery <Data.Database> pkt = new CS_ChatQuery <Data.Database>();
                        pkt.queryType = CS_ChatQuery <Data.Database> .QueryType.modChat;
                        pkt.sender    = from._alias;
                        pkt.payload   = String.Format("&[ModChat] [{0}]> {1}", from._alias, payload);
                        //Send it!
                        _server._db.send(pkt);
                    }
                }
                else
                {
                    //Possibly a scripted mod command, lets pass it
                    from._arena.handlePlayerModCommand(from, recipient, command, payload);
                }
                return;
            }

            //Are they a developer?
            if (!from._developer)
            {   //No
                //Check the permission levels
                if ((int)from.PermissionLevelLocal < (int)handler.permissionLevel)
                {       //Not going to happen.
                    return;
                }
            }
            else
            {
                //They are, is this a dev command?
                if (!handler.isDevCommand)
                {
                    return;
                }
                //Do they have the power?
                if ((int)from.PermissionLevelLocal < (int)handler.permissionLevel)
                {
                    //Nope
                    return;
                }
            }

            //Command logging (ignore normal player permission commands like *help, etc)
            if (from.PermissionLevelLocal != Data.PlayerPermission.Normal)
            {   //Notify his superiors in the arena
                string sRecipient;
                foreach (Player p in Players)
                {
                    if (p != from && !p._watchMod)
                    {
                        //We have watchmod commands off, bypass this player
                        continue;
                    }
                    if (p != from && (int)from.PermissionLevelLocal <= (int)p.PermissionLevelLocal)
                    {
                        p.sendMessage(0, String.Format("&[Arena: {0}] {1}>{2} *{3} {4}",
                                                       from._arena._name,
                                                       from._alias,
                                                       sRecipient = (recipient != null)
                                ? " :" + recipient._alias + ":"
                                : String.Empty,
                                                       command,
                                                       payload));
                    }
                    //Developer?
                    else if (from._developer)
                    {
                        if (p.PermissionLevelLocal >= Data.PlayerPermission.Mod && p != from)
                        {
                            p.sendMessage(0, String.Format("&[Arena: {0}] {1}>{2} *{3} {4}",
                                                           from._arena._name,
                                                           from._alias,
                                                           sRecipient = (recipient != null)
                                ? " :" + recipient._alias + ":"
                                : String.Empty,
                                                           command,
                                                           payload));
                        }
                    }
                }

                //Log it in the history database
                if (!_server.IsStandalone)
                {
                    CS_ModCommand <Data.Database> pkt = new CS_ModCommand <Data.Database>();
                    pkt.sender    = from._alias;
                    pkt.recipient = (recipient != null) ? recipient._alias : "none";
                    pkt.zone      = from._server.Name;
                    pkt.arena     = from._arena._name;
                    pkt.command   = command + " " + payload;

                    //Send it!
                    from._server._db.send(pkt);
                }
            }

            try
            {
                //Security hole fix
                //Lets check their level and their arena
                if (from.PermissionLevel < Data.PlayerPermission.SMod)
                {
                    if (recipient != null && !recipient._arena._name.Equals(from._arena._name, StringComparison.OrdinalIgnoreCase))
                    {
                        from.sendMessage(-1, "You cannot use commands from one arena to another.");
                        return;
                    }
                }

                //Handle it!
                handler.handler(from, recipient, payload, bong);
            }
            catch (Exception ex)
            {
                if (recipient != null)
                {
                    Log.write(TLog.Exception, "Exception while executing mod command '{0}' from '{1}' to '{2}'.\r\nPayload: {3}\r\n{4}",
                              command, from, recipient, payload, ex);
                }
                else
                {
                    Log.write(TLog.Exception, "Exception while executing mod command '{0}' from '{1}'.\r\nPayload: {2}\r\n{3}",
                              command, from, payload, ex);
                }
            }
        }