Beispiel #1
0
        public virtual bool Handle(string parameters, WorldSession _session = null)
        {
            SetSentErrorMessage(false);
            session = _session;
            // check if the user has enough privileges to access command group.
            // check if the user has enough privileges to invoke the command.
            if (session != null && this.Attributes.MinUserLevel > session.GetSecurity())
            {
                return(SendErrorMessage(CypherStrings.NoCmd));
            }

            string[] @params = null;

            if (parameters == string.Empty)
            {
                command = this.GetDefaultSubcommand();
            }
            else
            {
                @params = parameters.Split(' ');

                var          blah  = this.GetSubGroupCommand(@params[0]);
                CommandGroup group = null;
                if (blah.Key != null)
                {
                    group = blah.Value;
                    return(group.Handle(string.Join(" ", @params.Skip(1)), session));
                }
                else
                {
                    command = this.GetSubcommand(@params[0]) ?? this.GetDefaultSubcommand();
                }

                if (command != this.GetDefaultSubcommand())
                {
                    @params = @params.Skip(1).ToArray();
                }
            }

            // check if the user has enough privileges to invoke the command.
            if (session != null && command.MinUserLevel > session.GetSecurity())
            {
                return(SendErrorMessage(CypherStrings.NoCmd));
            }

            var success = (bool)this._commands[command].Invoke(this, new object[] { @params, this });

            if (!SentErrorMessage && !success)
            {
                return(SendErrorMessage(command.Help));
            }

            return(true);
        }
Beispiel #2
0
        public bool HasLowerSecurityAccount(WorldSession target, uint target_account, bool strong = false)
        {
            AccountTypes target_ac_sec;

            // allow everything from console and RA console
            if (_session == null)
                return false;

            // ignore only for non-players for non strong checks (when allow apply command at least to same sec level)
            if (!Global.AccountMgr.IsPlayerAccount(_session.GetSecurity()) && !strong && !WorldConfig.GetBoolValue(WorldCfg.GmLowerSecurity))
                return false;

            if (target != null)
                target_ac_sec = target.GetSecurity();
            else if (target_account != 0)
                target_ac_sec = Global.AccountMgr.GetSecurity(target_account);
            else
                return true;                                        // caller must report error for (target == NULL && target_account == 0)

            if (_session.GetSecurity() < target_ac_sec || (strong && _session.GetSecurity() <= target_ac_sec))
            {
                SendSysMessage(CypherStrings.YoursSecurityIsLow);
                _sentErrorMessage = true;
                return true;
            }
            return false;
        }
Beispiel #3
0
        bool HasLowerSecurityAccount(WorldSession target, uint target_account, bool strong = false)
        {
            uint target_sec;

            // allow everything from console and RA console
            if (session == null)
            {
                return(false);
            }

            // ignore only for non-players for non strong checks (when allow apply command at least to same sec level)
            if (!ObjMgr.IsPlayerAccount(session.GetSecurity()) && !strong)// && !sWorld->getBoolConfig(CONFIG_GM_LOWER_SECURITY))
            {
                return(false);
            }

            if (target != null)
            {
                target_sec = (uint)target.GetSecurity();
            }
            else if (target_account != 0)
            {
                target_sec = AcctMgr.GetSecurity(target_account);
            }
            else
            {
                return(true);                                        // caller must report error for (target == NULL && target_account == 0)
            }
            AccountTypes target_ac_sec = (AccountTypes)target_sec;

            if (session.GetSecurity() < target_ac_sec || (strong && session.GetSecurity() <= target_ac_sec))
            {
                SendSysMessage(CypherStrings.YoursSecurityIsLow);
                SetSentErrorMessage(true);
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        public static void HandleChatMessage(ref PacketReader packet, ref WorldSession session)
        {
            ChatMsg type;

            switch (packet.Opcode)
            {
            case Opcodes.CMSG_MessageChatGuild:
                type = ChatMsg.Guild;
                break;

            case Opcodes.CMSG_MessageChatOfficer:
                type = ChatMsg.Officer;
                break;

            case Opcodes.CMSG_MessageChatParty:
                type = ChatMsg.Party;
                break;

            case Opcodes.CMSG_MessageChatWhisper:
                type = ChatMsg.Whisper;
                break;

            case Opcodes.CMSG_MessageChatYell:
                type = ChatMsg.Yell;
                break;

            case Opcodes.CMSG_MessageChatSay:
            default:
                type = ChatMsg.Say;
                break;
            }

            if (type >= ChatMsg.Max)
            {
                Log.outError("CHAT: Wrong message type received: {0}", type);
                return;
            }
            Player sender = session.GetPlayer();

            Language lang;

            if (type != ChatMsg.Emote && type != ChatMsg.Afk && type != ChatMsg.Dnd)
            {
                lang = (Language)packet.ReadUInt32();

                /*
                 * // prevent talking at unknown language (cheating)
                 * LanguageDesc const* langDesc = GetLanguageDescByID(lang);
                 * if (!langDesc)
                 * {
                 *  SendNotification(LANG_UNKNOWN_LANGUAGE);
                 *  recvData.rfinish();
                 *  return;
                 * }
                 *
                 * if (langDesc->skill_id != 0 && !sender->HasSkill(langDesc->skill_id))
                 * {
                 *  // also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language)
                 *  Unit::AuraEffectList const& langAuras = sender->GetAuraEffectsByType(SPELL_AURA_COMPREHEND_LANGUAGE);
                 *  bool foundAura = false;
                 *  for (Unit::AuraEffectList::const_iterator i = langAuras.begin(); i != langAuras.end(); ++i)
                 *  {
                 *      if ((*i)->GetMiscValue() == int32(lang))
                 *      {
                 *          foundAura = true;
                 *          break;
                 *      }
                 *  }
                 *  if (!foundAura)
                 *  {
                 *      SendNotification(LANG_NOT_LEARNED_LANGUAGE);
                 *      recvData.rfinish();
                 *      return;
                 *  }
                 * }
                 */
                if (lang == Language.Addon)
                {
                    //if (sWorld->getBoolConfig(CONFIG_CHATLOG_ADDON))
                    {
                        //std::string msg = "";
                        //recvData >> msg;

                        //if (msg.empty())
                        //return;

                        // sScriptMgr->OnPlayerChat(sender, uint32(CHAT_MSG_ADDON), lang, msg);
                    }

                    // Disabled addon channel?
                    //if (!sWorld->getBoolConfig(CONFIG_ADDON_CHANNEL))
                    //return;
                }
                // LANG_ADDON should not be changed nor be affected by flood control
                else
                {
                    // send in universal language if player in .gm on mode (ignore spell effects)
                    if (sender.isGameMaster())
                    {
                        lang = Language.Universal;
                    }

                    /*
                     * else
                     * {
                     * // send in universal language in two side iteration allowed mode
                     * //if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT))
                     * //lang = LANG_UNIVERSAL;
                     * //else
                     * //{
                     * switch (type)
                     * {
                     *  case CHAT_MSG_PARTY:
                     *  case CHAT_MSG_PARTY_LEADER:
                     *  case CHAT_MSG_RAID:
                     *  case CHAT_MSG_RAID_LEADER:
                     *  case CHAT_MSG_RAID_WARNING:
                     *  // allow two side chat at group channel if two side group allowed
                     *  if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP))
                     *      lang = LANG_UNIVERSAL;
                     *      break;
                     *  case CHAT_MSG_GUILD:
                     *  case CHAT_MSG_OFFICER:
                     *  // allow two side chat at guild channel if two side guild allowed
                     *  if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD))
                     *      lang = LANG_UNIVERSAL;
                     *  break;
                     * }
                     *
                     *
                     * // but overwrite it by SPELL_AURA_MOD_LANGUAGE auras (only single case used)
                     * Unit::AuraEffectList const& ModLangAuras = sender->GetAuraEffectsByType(SPELL_AURA_MOD_LANGUAGE);
                     * if (!ModLangAuras.empty())
                     * lang = ModLangAuras.front()->GetMiscValue();
                     * }
                     *
                     * //if (!sender->CanSpeak())
                     * {
                     * //std::string timeStr = secsToTimeString(m_muteTime - time(NULL));
                     * //SendNotification(GetCypherString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str());
                     * //recvData.rfinish(); // Prevent warnings
                     * //return;
                     * }
                     */
                }
            }
            else
            {
                lang = Language.Universal;
            }

            //if (sender->HasAura(1852) && type != CHAT_MSG_WHISPER)
            {
                //recvData.rfinish();
                //SendNotification(GetCypherString(LANG_GM_SILENCE), sender->GetName());
                //return;
            }
            uint   textLength     = 0;
            uint   receiverLength = 0;
            string to             = string.Empty;
            string channel        = string.Empty;
            string msg            = string.Empty;
            bool   ignoreChecks   = false;

            switch (type)
            {
            case ChatMsg.Say:
            case ChatMsg.Emote:
            case ChatMsg.Yell:
            case ChatMsg.Party:
            case ChatMsg.Guild:
            case ChatMsg.Officer:
            case ChatMsg.Raid:
            case ChatMsg.Raid_Warning:
            case ChatMsg.Battleground:
                textLength = packet.GetBits <uint>(9);
                msg        = packet.ReadString(textLength);
                break;

            case ChatMsg.Whisper:
                receiverLength = packet.GetBits <uint>(10);
                textLength     = packet.GetBits <uint>(9);
                to             = packet.ReadString(receiverLength);
                msg            = packet.ReadString(textLength);
                break;

            case ChatMsg.Channel:
                receiverLength = packet.GetBits <uint>(10);
                textLength     = packet.GetBits <uint>(9);
                msg            = packet.ReadString(textLength);
                channel        = packet.ReadString(receiverLength);
                break;

            case ChatMsg.Afk:
            case ChatMsg.Dnd:
                textLength   = packet.GetBits <uint>(9);
                msg          = packet.ReadString(textLength);
                ignoreChecks = true;
                break;
            }
            if (!ignoreChecks)
            {
                if (msg == string.Empty)
                {
                    return;
                }

                if (CommandManager.TryParse(msg, session))
                {
                    return;
                }

                if (msg == string.Empty)
                {
                    return;
                }
            }

            switch (type)
            {
            case ChatMsg.Say:
            case ChatMsg.Emote:
            case ChatMsg.Yell:
                //if (sender->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ))
            {
                //SendNotification(GetCypherString(LANG_SAY_REQ), sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ));
                //return;
            }

                if (type == ChatMsg.Say)
                {
                    sender.Say(msg, lang);
                }
                //else if (type == ChatMsg.EMOTE)
                //sender.TextEmote(msg);
                else if (type == ChatMsg.Yell)
                {
                    sender.Yell(msg, lang);
                }
                break;

            case ChatMsg.Whisper:
                //if (sender->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ))
            {
                //SendNotification(GetCypherString(LANG_WHISPER_REQ), sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ));
                //return;
            }

                //if (!normalizePlayerName(to))
                {
                    //SendPlayerNotFoundNotice(to);
                    //break;
                }

                Player receiver         = ObjMgr.FindPlayerByName(to);
                bool   senderIsPlayer   = ObjMgr.IsPlayerAccount(session.GetSecurity());
                bool   receiverIsPlayer = ObjMgr.IsPlayerAccount(receiver != null ? receiver.GetSession().GetSecurity() : AccountTypes.Player);
                if (receiver == null || (senderIsPlayer && !receiverIsPlayer))        // && !receiver.isAcceptWhispers() && !receiver.IsInWhisperWhiteList(sender->GetGUID())))todo fixme
                {
                    SendPlayerNotFoundNotice(session, to);
                    return;
                }

                //if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT) && senderIsPlayer && receiverIsPlayer)
                //if (GetPlayer()->GetTeam() != receiver->GetTeam())
                {
                    //SendWrongFactionNotice();
                    //return;
                }

                //if (GetPlayer()->HasAura(1852) && !receiver->isGameMaster())
                {
                    //SendNotification(GetCypherString(LANG_GM_SILENCE), GetPlayer()->GetName());
                    //return;
                }

                // If player is a Gamemaster and doesn't accept whisper, we auto-whitelist every player that the Gamemaster is talking to
                //if (!senderIsPlayer && !sender->isAcceptWhispers() && !sender->IsInWhisperWhiteList(receiver->GetGUID()))
                //sender->AddWhisperWhiteList(receiver->GetGUID());

                session.GetPlayer().Whisper(msg, lang, receiver.GetGUID());
                break;

            /*
             * case ChatMsg.Party:
             * case ChatMsg.PartyLEADER:
             * {
             *  // if player is in battleground, he cannot say to battleground members by /p
             *  Group* group = GetPlayer()->GetOriginalGroup();
             *  if (!group)
             *  {
             *      group = _player->GetGroup();
             *      if (!group || group->isBGGroup())
             *          return;
             *  }
             *
             *  if (group->IsLeader(GetPlayer()->GetGUID()))
             *      type = CHAT_MSG_PARTY_LEADER;
             *
             *  sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group);
             *
             *  WorldPacket data;
             *  ChatHandler::FillMessageData(&data, this, uint8(type), lang, NULL, 0, msg.c_str(), NULL);
             *  group->BroadcastPacket(&data, false, group->GetMemberGroup(GetPlayer()->GetGUID()));
             * } break;
             * case CHAT_MSG_GUILD:
             * {
             *  if (GetPlayer()->GetGuildId())
             *  {
             *      if (Guild* guild = sGuildMgr->GetGuildById(GetPlayer()->GetGuildId()))
             *      {
             *          sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, guild);
             *
             *          guild->BroadcastToGuild(this, false, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
             *      }
             *  }
             * } break;
             * case CHAT_MSG_OFFICER:
             * {
             *  if (GetPlayer()->GetGuildId())
             *  {
             *      if (Guild* guild = sGuildMgr->GetGuildById(GetPlayer()->GetGuildId()))
             *      {
             *          sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, guild);
             *
             *          guild->BroadcastToGuild(this, true, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL);
             *      }
             *  }
             * } break;
             * case CHAT_MSG_RAID:
             * case CHAT_MSG_RAID_LEADER:
             * {
             *  // if player is in battleground, he cannot say to battleground members by /ra
             *  Group* group = GetPlayer()->GetOriginalGroup();
             *  if (!group)
             *  {
             *      group = GetPlayer()->GetGroup();
             *      if (!group || group->isBGGroup() || !group->isRaidGroup())
             *          return;
             *  }
             *
             *  if (group->IsLeader(GetPlayer()->GetGUID()))
             *      type = CHAT_MSG_RAID_LEADER;
             *
             *  sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group);
             *
             *  WorldPacket data;
             *  ChatHandler::FillMessageData(&data, this, uint8(type), lang, "", 0, msg.c_str(), NULL);
             *  group->BroadcastPacket(&data, false);
             * } break;
             * case CHAT_MSG_RAID_WARNING:
             * {
             *  Group* group = GetPlayer()->GetGroup();
             *  if (!group || !group->isRaidGroup() || !(group->IsLeader(GetPlayer()->GetGUID()) || group->IsAssistant(GetPlayer()->GetGUID())) || group->isBGGroup())
             *      return;
             *
             *  sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group);
             *
             *  WorldPacket data;
             *  //in battleground, raid warning is sent only to players in battleground - code is ok
             *  ChatHandler::FillMessageData(&data, this, CHAT_MSG_RAID_WARNING, lang, "", 0, msg.c_str(), NULL);
             *  group->BroadcastPacket(&data, false);
             * } break;
             * case CHAT_MSG_BATTLEGROUND:
             * case CHAT_MSG_BATTLEGROUND_LEADER:
             * {
             *  // battleground raid is always in Player->GetGroup(), never in GetOriginalGroup()
             *  Group* group = GetPlayer()->GetGroup();
             *  if (!group || !group->isBGGroup())
             *      return;
             *
             *  if (group->IsLeader(GetPlayer()->GetGUID()))
             *      type = CHAT_MSG_BATTLEGROUND_LEADER;
             *
             *  sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group);
             *
             *  WorldPacket data;
             *  ChatHandler::FillMessageData(&data, this, uint8(type), lang, "", 0, msg.c_str(), NULL);
             *  group->BroadcastPacket(&data, false);
             * } break;
             * case CHAT_MSG_CHANNEL:
             * {
             *  if (AccountMgr::IsPlayerAccount(GetSecurity()))
             *  {
             *      if (_player->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ))
             *      {
             *          SendNotification(GetCypherString(LANG_CHANNEL_REQ), sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ));
             *          return;
             *      }
             *  }
             *
             *  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
             *  {
             *
             *      if (Channel* chn = cMgr->GetChannel(channel, _player))
             *      {
             *          sScriptMgr->OnPlayerChat(_player, type, lang, msg, chn);
             *
             *          chn->Say(_player->GetGUID(), msg.c_str(), lang);
             *      }
             *  }
             * } break;
             * case CHAT_MSG_AFK:
             * {
             *  if ((msg.empty() || !_player->isAFK()) && !_player->isInCombat())
             *  {
             *      if (!_player->isAFK())
             *      {
             *          if (msg.empty())
             *              msg  = GetCypherString(LANG_PLAYER_AFK_DEFAULT);
             *          _player->afkMsg = msg;
             *      }
             *
             *      sScriptMgr->OnPlayerChat(_player, type, lang, msg);
             *
             *      _player->ToggleAFK();
             *      if (_player->isAFK() && _player->isDND())
             *          _player->ToggleDND();
             *  }
             * } break;
             * case CHAT_MSG_DND:
             * {
             *  if (msg.empty() || !_player->isDND())
             *  {
             *      if (!_player->isDND())
             *      {
             *          if (msg.empty())
             *              msg = GetCypherString(LANG_PLAYER_DND_DEFAULT);
             *          _player->dndMsg = msg;
             *      }
             *
             *      sScriptMgr->OnPlayerChat(_player, type, lang, msg);
             *
             *      _player->ToggleDND();
             *      if (_player->isDND() && _player->isAFK())
             *          _player->ToggleAFK();
             *  }
             * } break;
             */
            default:
                Log.outError("CHAT: unknown message type {0}, lang: {1}", type, lang);
                break;
            }
        }