bool ChatHandler::ShowHelpForCommand(WorldSession *m_session, ChatCommand *table, const char* cmd) { for(uint32 i = 0; table[i].Name != NULL; i++) { if(!hasStringAbbr(table[i].Name, cmd)) continue; if(m_session->CanUseCommand(table[i].CommandGroup)) continue; if(table[i].ChildCommands != NULL) { cmd = strtok(NULL, " "); if(cmd && ShowHelpForCommand(m_session, table[i].ChildCommands, cmd)) return true; } if(table[i].Help == "") { SystemMessage(m_session, "There is no help for that command"); return true; } SendMultilineMessage(m_session, table[i].Help.c_str()); return true; } return false; }
bool ChatHandler::ShowHelpForCommand(ChatCommand *table, const char* cmd) { for(uint32 i = 0; table[i].Name != NULL; i++) { if(!hasStringAbbr(table[i].Name, cmd)) continue; if(m_session->GetSecurity() < table[i].SecurityLevel) continue; if(table[i].ChildCommands != NULL) { cmd = strtok(NULL, " "); if(cmd && ShowHelpForCommand(table[i].ChildCommands, cmd)) return true; } if(table[i].Help == "") { WorldPacket data; FillSystemMessageData(&data, m_session, "There is no help for that command"); m_session->SendPacket(&data); return true; } SendMultilineMessage(table[i].Help.c_str()); return true; } return false; }
bool ChatHandler::ShowHelpForCommand(ChatCommand *table, const char* cmd) { for(uint32 i = 0; table[i].Name != NULL; i++) { if(!hasStringAbbr(table[i].Name, cmd)) continue; if(m_session->GetSecurity() < table[i].SecurityLevel) continue; if(table[i].ChildCommands != NULL) { cmd = strtok(NULL, " "); if(cmd && ShowHelpForCommand(table[i].ChildCommands, cmd)) return true; } if(table[i].Help == "") { SendSysMessage(LANG_NO_HELP_CMD); return true; } SendSysMultilineMessage(table[i].Help.c_str()); return true; } return false; }
bool ChatHandler::HandleCommandsCommand(const char* args, WorldSession* m_session) { ChatCommand* table = CommandTableStorage::getSingleton().Get(); std::string output; uint32 count = 0; output = "Available commands: \n\n"; for (uint32 i = 0; table[i].Name != NULL; i++) { if (*args && !hasStringAbbr(table[i].Name, (char*)args)) continue; if (table[i].CommandGroup != '0' && !m_session->CanUseCommand(table[i].CommandGroup)) continue; switch (table[i].CommandGroup) { case 'z': { output += "|cffff6060"; output += table[i].Name; output += "|r, "; }break; case 'm': { output += "|cff00ffff"; output += table[i].Name; output += ", "; }break; case 'c': { output += "|cff00ff00"; output += table[i].Name; output += "|r, "; }break; default: { output += "|cff00ccff"; output += table[i].Name; output += "|r, "; }break; } ++count; if (count == 5) // 5 per line { output += "\n"; count = 0; } } if (count) output += "\n"; SendMultilineMessage(m_session, output.c_str()); return true; }
bool ChatHandler::Command_Commands (const char* args) { ChatCommand *table = getCommandTable(); m_session->SystemMessage (LANG_CMD_AVAIL); std::string msg; for(uint32 i = 0; table[i].Name != NULL; ++i) { if(*args && !hasStringAbbr(table[i].Name, (char*)args)) continue; if(m_session->GetSecurity() < table[i].SecurityLevel) continue; // Format command help msg += "|cffcccccc"; msg += table[i].Name; ChatCommand * child = table[i].ChildCommands; if (child != NULL) { msg += " (|cffccccff"; for (uint32 q = 0; child[q].Name != NULL; q++) { msg += child[q].Name; if (child[q+1].Name != NULL) msg += ", "; // Flush too long lines if (msg.size() > 200) { m_session->SystemMessage ((char *)msg.c_str()); msg = "|cffccccff"; } } msg += "|cffcccccc)"; } if (table[i+1].Name != NULL) msg += ", "; // Flush too long lines if (msg.size() > 254) { m_session->SystemMessage ((char *)msg.c_str()); msg = "|cffcccccc"; } } // Flush the rest if (msg.size()) { msg += "."; m_session->SystemMessage ((char *)msg.c_str()); } m_session->SystemMessage (LANG_CMD_MHELP); return true; }
bool ChatHandler::ShowHelpForCommand(std::vector<ChatCommand> const& table, const char* cmd) { if (*cmd) { for (uint32 i = 0; i < table.size(); ++i) { // must be available (ignore handler existence for show command with possible available subcommands) if (!isAvailable(table[i])) continue; if (!hasStringAbbr(table[i].Name, cmd)) continue; // have subcommand char const* subcmd = (*cmd) ? strtok(NULL, " ") : ""; if (!table[i].ChildCommands.empty() && subcmd && *subcmd) { if (ShowHelpForCommand(table[i].ChildCommands, subcmd)) return true; } if (!table[i].Help.empty()) SendSysMessage(table[i].Help.c_str()); if (!table[i].ChildCommands.empty()) if (ShowHelpForSubCommands(table[i].ChildCommands, table[i].Name, subcmd ? subcmd : "")) return true; return !table[i].Help.empty(); } } else { for (uint32 i = 0; i < table.size(); ++i) { // must be available (ignore handler existence for show command with possible available subcommands) if (!isAvailable(table[i])) continue; if (strlen(table[i].Name)) continue; if (!table[i].Help.empty()) SendSysMessage(table[i].Help.c_str()); if (!table[i].ChildCommands.empty()) if (ShowHelpForSubCommands(table[i].ChildCommands, "", "")) return true; return !table[i].Help.empty(); } } return ShowHelpForSubCommands(table, "", cmd); }
bool ChatHandler::ExecuteCommandInTable(ChatCommand *table, uint8* text) { char *cmd = (char*)text; uint32 AcctLvl = m_pClient->getAccountLvl(); while (*text != ' ' && *text != '\0') text++; // skip command if(*text != '\0') { *text = '\0'; text++; } while (*text == ' ') text++; // skip whitespace if(*cmd == '\0') return false; for(uint32 i = 0; table[i].Name != NULL; i++) { if(!hasStringAbbr(table[i].Name, cmd)) continue; if(AcctLvl < table[i].SecurityLevel) continue; if(table[i].ChildCommands != NULL) { if(!ExecuteCommandInTable(table[i].ChildCommands, text)) { if(table[i].Help != "") SendMultilineMessage(table[i].Help.c_str()); else { wowWData data; FillMessageData(&data, 0x09, m_pClient, (uint8*)"There is no such subcommand."); m_pClient->SendMsg(&data); } } return true; } if(!(this->*(table[i].Handler))(text)) { if(table[i].Help != "") SendMultilineMessage(table[i].Help.c_str()); else { wowWData data; FillMessageData(&data, 0x09, m_pClient, (uint8*)"Incorrect syntax."); m_pClient->SendMsg(&data); } } return true; } return false; }
bool ChatHandler::HandleCommandsCommand(const char* args) { ChatCommand *table = getCommandTable(); SendSysMessage(LANG_AVIABLE_CMD); for(uint32 i = 0; table[i].Name != NULL; i++) { if(*args && !hasStringAbbr(table[i].Name, (char*)args)) continue; if(m_session->GetSecurity() < table[i].SecurityLevel) continue; SendSysMessage(table[i].Name); } return true; }
bool ChatHandler::HandleCommandsCommand(const char* args) { ChatCommand *table = getCommandTable(); WorldPacket data; FillSystemMessageData(&data, m_session, "Commands aviable to you:"); m_session->SendPacket(&data); for(uint32 i = 0; table[i].Name != NULL; i++) { if(*args && !hasStringAbbr(table[i].Name, (char*)args)) continue; if(m_session->GetSecurity() < table[i].SecurityLevel) continue; FillSystemMessageData(&data, m_session, table[i].Name); m_session->SendPacket(&data); } return true; }
bool ChatHandler::ShowHelpForSubCommands(std::vector<ChatCommand> const& table, char const* cmd, char const* subcmd) { std::string list; for (uint32 i = 0; i < table.size(); ++i) { // must be available (ignore handler existence for show command with possible available subcommands) if (!isAvailable(table[i])) continue; // for empty subcmd show all available if (*subcmd && !hasStringAbbr(table[i].Name, subcmd)) continue; if (m_session) list += "\n "; else list += "\n\r "; list += table[i].Name; if (!table[i].ChildCommands.empty()) list += " ..."; } if (list.empty()) return false; if (&table == &getCommandTable()) { SendSysMessage(LANG_AVIABLE_CMD); PSendSysMessage("%s", list.c_str()); } else PSendSysMessage(LANG_SUBCMDS_LIST, cmd, list.c_str()); return true; }
bool ChatHandler::ExecuteCommandInTable(std::vector<ChatCommand> const& table, const char* text, std::string const& fullcmd) { char const* oldtext = text; std::string cmd = ""; while (*text != ' ' && *text != '\0') { cmd += *text; ++text; } while (*text == ' ') ++text; for (uint32 i = 0; i < table.size(); ++i) { if (!hasStringAbbr(table[i].Name, cmd.c_str())) continue; bool match = false; if (strlen(table[i].Name) > cmd.length()) { for (uint32 j = 0; j < table.size(); ++j) { if (!hasStringAbbr(table[j].Name, cmd.c_str())) continue; if (strcmp(table[j].Name, cmd.c_str()) == 0) { match = true; break; } } } if (match) continue; // select subcommand from child commands list if (!table[i].ChildCommands.empty()) { if (!ExecuteCommandInTable(table[i].ChildCommands, text, fullcmd)) { #ifdef ELUNA if (!sEluna->OnCommand(GetSession() ? GetSession()->GetPlayer() : NULL, oldtext)) return true; #endif if (text[0] != '\0') SendSysMessage(LANG_NO_SUBCMD); else SendSysMessage(LANG_CMD_SYNTAX); ShowHelpForCommand(table[i].ChildCommands, text); } return true; } // must be available and have handler if (!table[i].Handler || !isAvailable(table[i])) continue; SetSentErrorMessage(false); // table[i].Name == "" is special case: send original command to handler if ((table[i].Handler)(this, table[i].Name[0] != '\0' ? text : oldtext)) { if (!m_session) // ignore console return true; Player* player = m_session->GetPlayer(); if (!AccountMgr::IsPlayerAccount(m_session->GetSecurity())) { ObjectGuid guid = player->GetTarget(); uint32 areaId = player->GetAreaId(); std::string areaName = "Unknown"; std::string zoneName = "Unknown"; if (AreaTableEntry const* area = GetAreaEntryByAreaID(areaId)) { int locale = GetSessionDbcLocale(); areaName = area->area_name[locale]; if (AreaTableEntry const* zone = GetAreaEntryByAreaID(area->zone)) zoneName = zone->area_name[locale]; } sLog->outCommand(m_session->GetAccountId(), "Command: %s [Player: %s (%s) (Account: %u) X: %f Y: %f Z: %f Map: %u (%s) Area: %u (%s) Zone: %s Selected: %s (%s)]", fullcmd.c_str(), player->GetName().c_str(), player->GetGUID().ToString().c_str(), m_session->GetAccountId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), player->FindMap() ? player->FindMap()->GetMapName() : "Unknown", areaId, areaName.c_str(), zoneName.c_str(), (player->GetSelectedUnit()) ? player->GetSelectedUnit()->GetName().c_str() : "", guid.ToString().c_str()); } } // some commands have custom error messages. Don't send the default one in these cases. else if (!HasSentErrorMessage()) { if (!table[i].Help.empty()) SendSysMessage(table[i].Help.c_str()); else SendSysMessage(LANG_CMD_SYNTAX); } return true; } return false; }
bool ChatHandler::ExecuteCommandInTable(ChatCommand* table, const char* text, const std::string& fullcmd) { char const* oldtext = text; std::string cmd = ""; while (*text != ' ' && *text != '\0') { cmd += *text; ++text; } while (*text == ' ') ++text; for (uint32 i = 0; table[i].Name != NULL; ++i) { if (!hasStringAbbr(table[i].Name, cmd.c_str())) continue; bool match = false; if (strlen(table[i].Name) > cmd.length()) { for (uint32 j = 0; table[j].Name != NULL; ++j) { if (!hasStringAbbr(table[j].Name, cmd.c_str())) continue; if (strcmp(table[j].Name, cmd.c_str()) != 0) continue; else { match = true; break; } } } if (match) continue; // select subcommand from child commands list if (table[i].ChildCommands != NULL) { if (!ExecuteCommandInTable(table[i].ChildCommands, text, fullcmd)) { if (text && text[0] != '\0') SendSysMessage(LANG_NO_SUBCMD); else SendSysMessage(LANG_CMD_SYNTAX); ShowHelpForCommand(table[i].ChildCommands, text); } return true; } // must be available and have handler if (!table[i].Handler || !isAvailable(table[i])) continue; SetSentErrorMessage(false); // table[i].Name == "" is special case: send original command to handler if ((table[i].Handler)(this, table[i].Name[0] != '\0' ? text : oldtext)) { if (!AccountMgr::IsPlayerAccount(table[i].SecurityLevel)) { // chat case if (m_session) { Player* p = m_session->GetPlayer(); uint64 sel_guid = p->GetSelection(); sLog->outCommand(m_session->GetAccountId(), "Command: %s [Player: %s (Account: %u) X: %f Y: %f Z: %f Map: %u Selected %s: %s (GUID: %u)]", fullcmd.c_str(), p->GetName().c_str(), m_session->GetAccountId(), p->GetPositionX(), p->GetPositionY(), p->GetPositionZ(), p->GetMapId(), GetLogNameForGuid(sel_guid), (p->GetSelectedUnit()) ? p->GetSelectedUnit()->GetName().c_str() : "", GUID_LOPART(sel_guid)); } } } // some commands have custom error messages. Don't send the default one in these cases. else if (!HasSentErrorMessage()) { if (!table[i].Help.empty()) SendSysMessage(table[i].Help.c_str()); else SendSysMessage(LANG_CMD_SYNTAX); } return true; } return false; }
bool ChatHandler::HandleCommandsCommand(const char* args, WorldSession *m_session) { ChatCommand *table = sComTableStore.Get(); WorldPacket data; std::string output; uint32 count = 0; output = "Available commands: \n\n"; for(uint32 i = 0; table[i].Name != NULL; i++) { if(*args && !hasStringAbbr(table[i].Name, (char*)args)) continue; if(table[i].CommandGroup != '0' && !m_session->CanUseCommand(table[i].CommandGroup)) continue; switch(table[i].CommandGroup) { case 'z': { output+="|cffff6060"; output+=table[i].Name; output+="|r, "; } break; case 'm': { output+="|cff00ffff"; output+=table[i].Name; output+=", "; } break; case 'c': { output += "|cff00ff00"; output += table[i].Name; output += "|r, "; }break; default: { output+="|cff00ccff"; output+=table[i].Name; output+="|r, "; } break; } count++; if(count == 5) // 5 per line { output += "\n"; count = 0; } } if(count) output += "\n"; //FillSystemMessageData(&data, table[i].Name); //m_session->SendPacket(&data); //} SendMultilineMessage(m_session, output.c_str()); return true; }
bool ChatHandler::ExecuteCommandInTable(ChatCommand *table, const char* text, WorldSession *m_session) { std::string cmd = ""; // get command while (*text != ' ' && *text != '\0') { cmd += *text; text++; } while (*text == ' ') text++; // skip whitespace if(!cmd.length()) return false; for(uint32 i = 0; table[i].Name != NULL; i++) { if(!hasStringAbbr(table[i].Name, cmd.c_str())) continue; if(!m_session->CanUseCommand(table[i].CommandGroup)) continue; if(table[i].ChildCommands != NULL) { if(!ExecuteCommandInTable(table[i].ChildCommands, text, m_session)) { if(table[i].Help != "") SendMultilineMessage(m_session, table[i].Help.c_str()); else { GreenSystemMessage(m_session, "Available Subcommands:"); for(uint32 k=0; table[i].ChildCommands[k].Name;k++) { if(m_session->CanUseCommand(table[i].ChildCommands[k].CommandGroup)) BlueSystemMessage(m_session, " %s - %s", table[i].ChildCommands[k].Name, table[i].ChildCommands[k].Help.size() ? table[i].ChildCommands[k].Help.c_str() : "No Help Available"); } } } return true; } // Check for field-based commands if(table[i].Handler == NULL && (table[i].MaxValueField || table[i].NormalValueField)) { bool result = false; if(strlen(text) == 0) { RedSystemMessage(m_session, "No values specified."); } if(table[i].ValueType == 2) result = CmdSetFloatField(m_session, table[i].NormalValueField, table[i].MaxValueField, table[i].Name, text); else result = CmdSetValueField(m_session, table[i].NormalValueField, table[i].MaxValueField, table[i].Name, text); if(!result) RedSystemMessage(m_session, "Must be in the form of (command) <value>, or, (command) <value> <maxvalue>"); } else { if(!(this->*(table[i].Handler))(text, m_session)) { if(table[i].Help != "") SendMultilineMessage(m_session, table[i].Help.c_str()); else { RedSystemMessage(m_session, "Incorrect syntax specified. Try .help %s for the correct syntax.", table[i].Name); } } } return true; } return false; }
bool ChatHandler::ExecuteCommandInTable(ChatCommand *table, const char* text) { char const* oldtext = text; std::string fullcmd = text; // original `text` can't be used. It content destroyed in command code processing. std::string cmd = ""; while (*text != ' ' && *text != '\0') { cmd += *text; text++; } while (*text == ' ') text++; if(!cmd.length()) return false; for(uint32 i = 0; table[i].Name != NULL; i++) { // allow pass "" command name in table if(strlen(table[i].Name) && !hasStringAbbr(table[i].Name, cmd.c_str())) continue; // select subcommand from child commands list if(table[i].ChildCommands != NULL) { if(!ExecuteCommandInTable(table[i].ChildCommands, text)) { if(table[i].Help != "") SendSysMultilineMessage(table[i].Help.c_str()); else SendSysMessage(LANG_NO_SUBCMD); } return true; } // check security level only for simple command (without child commands) if(m_session->GetSecurity() < table[i].SecurityLevel) continue; // table[i].Name == "" is special case: send original command to handler if((this->*(table[i].Handler))(strlen(table[i].Name)!=0 ? text : oldtext)) { if(table[i].SecurityLevel > 0) { Player* p = m_session->GetPlayer(); uint64 sel_guid = p->GetSelection(); sLog.outCommand("Command: %s [Player: %s (Account: %u) X: %f Y: %f Z: %f Map: %u Selected: %s (GUID: %u)]", fullcmd.c_str(),p->GetName(),m_session->GetAccountId(),p->GetPositionX(),p->GetPositionY(),p->GetPositionZ(),p->GetMapId(), (GUID_HIPART(sel_guid)==HIGHGUID_UNIT ? "creature" : (sel_guid !=0 ? "player" : "none")), GUID_LOPART(sel_guid)); } } else { if(table[i].Help != "") SendSysMultilineMessage(table[i].Help.c_str()); else SendSysMessage(LANG_CMD_SYNTAX); } return true; } return false; }
bool ChatHandler::ExecuteCommandInTable(ChatCommand* table, const char* text, std::string const& fullcmd) { char const* oldtext = text; std::string cmd = ""; while (*text != ' ' && *text != '\0') { cmd += *text; ++text; } while (*text == ' ') ++text; for (uint32 i = 0; table[i].Name != NULL; ++i) { if (!hasStringAbbr(table[i].Name, cmd.c_str())) continue; bool match = false; if (strlen(table[i].Name) > cmd.length()) { for (uint32 j = 0; table[j].Name != NULL; ++j) { if (!hasStringAbbr(table[j].Name, cmd.c_str())) continue; if (strcmp(table[j].Name, cmd.c_str()) == 0) { match = true; break; } } } if (match) continue; // select subcommand from child commands list if (table[i].ChildCommands != NULL) { if (!ExecuteCommandInTable(table[i].ChildCommands, text, fullcmd)) { if (text[0] != '\0') SendSysMessage(LANG_NO_SUBCMD); else SendSysMessage(LANG_CMD_SYNTAX); ShowHelpForCommand(table[i].ChildCommands, text); } return true; } // must be available and have handler if (!table[i].Handler || !isAvailable(table[i])) continue; SetSentErrorMessage(false); // table[i].Name == "" is special case: send original command to handler if ((table[i].Handler)(this, table[i].Name[0] != '\0' ? text : oldtext)) { if (!m_session) // ignore console return true; Player* player = m_session->GetPlayer(); if (!AccountMgr::IsPlayerAccount(m_session->GetSecurity())) { uint64 guid = player->GetTarget(); uint32 areaId = player->GetAreaId(); std::string areaName = "Unknown"; std::string zoneName = "Unknown"; if (AreaTableEntry const* area = GetAreaEntryByAreaID(areaId)) { int locale = GetSessionDbcLocale(); areaName = area->area_name[locale]; if (AreaTableEntry const* zone = GetAreaEntryByAreaID(area->zone)) zoneName = zone->area_name[locale]; } sLog->outCommand(m_session->GetAccountId(), "Command: %s [Player: %s (Guid: %u) (Account: %u) X: %f Y: %f Z: %f Map: %u (%s) Area: %u (%s) Zone: %s Selected %s: %s (GUID: %u)]", fullcmd.c_str(), player->GetName().c_str(), GUID_LOPART(player->GetGUID()), m_session->GetAccountId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), player->GetMap() ? player->GetMap()->GetMapName() : "Unknown", areaId, areaName.c_str(), zoneName.c_str(), GetLogNameForGuid(guid), (player->GetSelectedUnit()) ? player->GetSelectedUnit()->GetName().c_str() : "", GUID_LOPART(guid)); if ((sIRC->logmask & 2) != 0) { std::string logchan = "#"; logchan += sIRC->logchan; std::stringstream ss; ss << sIRC->iLog.GetLogDateTimeStr() << ": [ " << player->GetName() << "(" << GetSession()->GetSecurity() << ") ] Used Command: [ " << fullcmd << " ] Target Guid: [" << GUID_LOPART(guid) << "]"; sIRC->Send_IRC_Channel(logchan,ss.str().c_str(), true, "LOG"); } } } // some commands have custom error messages. Don't send the default one in these cases. else if (!HasSentErrorMessage()) { if (!table[i].Help.empty()) SendSysMessage(table[i].Help.c_str()); else SendSysMessage(LANG_CMD_SYNTAX); } return true; } return false; }