ChatHandler.cpp
上传用户:jxpjxmjjw
上传日期:2009-12-07
资源大小:5877k
文件大小:37k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. // Copyright (C) 2004 Team Python // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "ChatHandler.h" #include "NetworkInterface.h" #include "GameClient.h" #include "Opcodes.h" #include "Log.h" #include "WorldServer.h" #include "Character.h" #include "UpdateMask.h" #include "Database.h" #define world WorldServer::getSingleton()
  2. ChatCommand * ChatHandler::LoadHelp(bool load)
  3. {
  4. static bool first_call = true;
  5. static ChatCommand adminCommandTable[8];
  6. static ChatCommand npcCommandTable[20];
  7. static ChatCommand moveCommandTable[9];
  8. static ChatCommand gmCommandTable[7];
  9. static ChatCommand usrCommandTable[12];
  10. static ChatCommand commandTable[16];
  11. if(first_call)
  12. {
  13. first_call = false;
  14. //ADMIN
  15. adminCommandTable[0].setValues("ban",         3, &ChatHandler::HandleBanCommand,           "",   NULL);//LINA FEATURE
  16. adminCommandTable[1].setValues("unban",       3, &ChatHandler::HandleUnBanCommand,         "",   NULL);//LINA FEATURE
  17. adminCommandTable[2].setValues("lvl",         3, &ChatHandler::HandleSecurityCommand,      "",   NULL);//LINA FEATUR
  18. adminCommandTable[3].setValues("addspirit",   3, &ChatHandler::HandleAddSpiritCommand,     "",   NULL);
  19. adminCommandTable[4].setValues("die",         3, &ChatHandler::HandleDieCommand,           "",   NULL);
  20. adminCommandTable[5].setValues("revive",      3, &ChatHandler::HandleReviveCommand,        "",   NULL);
  21. adminCommandTable[6].setValues("update",      3, &ChatHandler::HandleUpdateCommand,        "",   NULL);
  22. adminCommandTable[7].setValues(NULL,          0, NULL,                                     "",   NULL);
  23. /* //CREATOR
  24. npcCommandTable[0].setValues("info",        2, &ChatHandler::HandleGUIDCommand,          "",   NULL);
  25. npcCommandTable[1].setValues("mobs",        2, &ChatHandler::HandleSpawnCommand,         "",   NULL);
  26. npcCommandTable[2].setValues("taxi",        2, &ChatHandler::HandleSpawnTaxiCommand,     "",   NULL);
  27. npcCommandTable[3].setValues("spell",       2, &ChatHandler::HandleSpellCommand,         "",   NULL);
  28. npcCommandTable[4].setValues("rmvspell",    2, &ChatHandler::HandleRemoveSpellCommand,   "",   NULL);
  29. npcCommandTable[5].setValues("item",        2, &ChatHandler::HandleItemCommand,          "",   NULL);
  30. npcCommandTable[6].setValues("rmvitem",     2, &ChatHandler::HandleRemoveItemCommand,    "",   NULL);
  31. npcCommandTable[7].setValues("itemmove",    2, &ChatHandler::HandleItemMoveCommand,      "",   NULL);
  32. npcCommandTable[8].setValues("delete",      2, &ChatHandler::HandleDeleteCommand,        "",   NULL);
  33. npcCommandTable[9].setValues("level",       2, &ChatHandler::HandleChangeLevelCommand,   "",   NULL);//LINA FEATURE
  34. npcCommandTable[10].setValues("skin",       2, &ChatHandler::HandleDisplayIdCommand,     "",   NULL);
  35. npcCommandTable[11].setValues("faction",     2, &ChatHandler::HandleFactionIdCommand,     "",   NULL);
  36. npcCommandTable[12].setValues("name",        2, &ChatHandler::HandleNameCommand,          "",   NULL);//LINA FEATURE
  37. npcCommandTable[13].setValues("flag",        2, &ChatHandler::HandleNPCFlagCommand,       "",   NULL);
  38. npcCommandTable[14].setValues("animfreq",    3, &ChatHandler::HandleAnimFreqCommand,      "",   NULL);
  39. npcCommandTable[15].setValues("random",      2, &ChatHandler::HandleRandomCommand,        "",   NULL);
  40. npcCommandTable[16].setValues("addmove",     2, &ChatHandler::HandleAddMoveCommand,       "",   NULL);
  41. npcCommandTable[17].setValues("run",         2, &ChatHandler::HandleRunCommand,           "",   NULL);
  42. npcCommandTable[18].setValues("state",       2, &ChatHandler::HandleAggressiveCommand,    "",   NULL);
  43. npcCommandTable[19].setValues(NULL,          0, NULL,                                     "",   NULL); */
  44. //CREATOR 
  45.        npcCommandTable[0].setValues("info",        2, &ChatHandler::HandleGUIDCommand,          "",   NULL); 
  46.        npcCommandTable[1].setValues("mobs",        2, &ChatHandler::HandleSpawnCommand,         "",   NULL); 
  47.        npcCommandTable[2].setValues("taxi",        2, &ChatHandler::HandleSpawnTaxiCommand,     "",   NULL); 
  48.        npcCommandTable[3].setValues("spell",       2, &ChatHandler::HandleSpellCommand,         "",   NULL); 
  49.        npcCommandTable[4].setValues("rmvspell",    2, &ChatHandler::HandleRemoveSpellCommand,   "",   NULL); 
  50.        npcCommandTable[5].setValues("item",        2, &ChatHandler::HandleItemCommand,          "",   NULL); 
  51.        npcCommandTable[6].setValues("rmvitem",     2, &ChatHandler::HandleRemoveItemCommand,    "",   NULL); 
  52.        npcCommandTable[7].setValues("itemmove",    2, &ChatHandler::HandleItemMoveCommand,      "",   NULL); 
  53.        npcCommandTable[8].setValues("delete",      2, &ChatHandler::HandleDeleteCommand,        "",   NULL); 
  54.        npcCommandTable[9].setValues("level",       2, &ChatHandler::HandleChangeLevelCommand,   "",   NULL);//LINA FEATURE 
  55.        npcCommandTable[10].setValues("skin",       2, &ChatHandler::HandleDisplayIdCommand,     "",   NULL); 
  56.        npcCommandTable[11].setValues("faction",     2, &ChatHandler::HandleFactionIdCommand,     "",   NULL); 
  57.        npcCommandTable[12].setValues("name",        2, &ChatHandler::HandleNameCommand,          "",   NULL);//LINA FEATURE 
  58.        npcCommandTable[13].setValues("flag",        2, &ChatHandler::HandleNPCFlagCommand,       "",   NULL); 
  59.        npcCommandTable[14].setValues("animfreq",    3, &ChatHandler::HandleAnimFreqCommand,      "",   NULL); 
  60.        npcCommandTable[15].setValues("random",      2, &ChatHandler::HandleRandomCommand,        "",   NULL); 
  61.        npcCommandTable[16].setValues("addmove",     2, &ChatHandler::HandleAddMoveCommand,       "",   NULL); 
  62.        npcCommandTable[17].setValues("run",         2, &ChatHandler::HandleRunCommand,           "",   NULL); 
  63.        npcCommandTable[18].setValues("state",       2, &ChatHandler::HandleAggressiveCommand,    "",   NULL); 
  64.        npcCommandTable[19].setValues("scale",      2, &ChatHandler::HandleNPCScaleCommand,       "",   NULL);//THE_WIZARD 
  65.        npcCommandTable[20].setValues("hpmin",      2, &ChatHandler::HandleNPChpminCommand,       "",   NULL);//THE_WIZARD 
  66.        npcCommandTable[21].setValues("hpmax",      2, &ChatHandler::HandleNPChpmaxCommand,       "",   NULL);//THE_WIZARD       
  67.        npcCommandTable[22].setValues(NULL,          0, NULL,                                     "",   NULL);
  68. //MOVE
  69. moveCommandTable[0].setValues("where",       1, &ChatHandler::HandleGPSCommand,           "",   NULL);
  70. moveCommandTable[1].setValues("there",       1, &ChatHandler::HandleAppearCommand,        "",   NULL);
  71. moveCommandTable[2].setValues("here",        1, &ChatHandler::HandleSummonCommand,        "",   NULL);
  72. moveCommandTable[3].setValues("fast",        2, &ChatHandler::HandleMoveCommand,          "",   NULL);
  73. moveCommandTable[4].setValues("world",       3, &ChatHandler::HandleWorldPortCommand,     "",   NULL);
  74. moveCommandTable[5].setValues("town",        1, &ChatHandler::HandleRecallCommand,        "",   NULL);
  75. moveCommandTable[6].setValues("prog",        2, &ChatHandler::HandleProgCommand,          "",   NULL);
  76. moveCommandTable[7].setValues("isle",        1, &ChatHandler::HandleIsleCommand,          "",   NULL);
  77. moveCommandTable[8].setValues(NULL,          0, NULL,                                     "",   NULL);
  78.     
  79. //GM
  80. gmCommandTable[0].setValues("pass",        1, &ChatHandler::HandleGMPassCommand,        "",   NULL);//LINA FEATURE
  81. gmCommandTable[1].setValues("off",         1, &ChatHandler::HandleGMOffCommand,         "",   NULL);
  82. gmCommandTable[2].setValues("on",          1, &ChatHandler::HandleGMOnCommand,          "",   NULL);
  83. gmCommandTable[3].setValues("kick",        1, &ChatHandler::HandleKickCommand,          "",   NULL);//LINA FEATURE
  84. gmCommandTable[4].setValues("save",        1, &ChatHandler::HandleSaveAllCommand,       "",   NULL);//LINA FEATURE
  85. gmCommandTable[5].setValues("announce",    1, &ChatHandler::HandleAnnounceCommand,      "",   NULL);
  86. gmCommandTable[6].setValues(NULL,          0, NULL,                                     "",   NULL);
  87. //CHANGE
  88. usrCommandTable[0].setValues("hp",          1, &ChatHandler::HandleModifyHPCommand, "",   NULL);
  89. usrCommandTable[1].setValues("mana",        1, &ChatHandler::HandleModifyManaCommand, "",   NULL);
  90. usrCommandTable[2].setValues("gold",        1, &ChatHandler::HandleModifyGoldCommand, "",   NULL);
  91. usrCommandTable[3].setValues("lvl",         1, &ChatHandler::HandleModifyLevelCommand, "",   NULL);
  92. usrCommandTable[4].setValues("speed",       1, &ChatHandler::HandleModifySpeedCommand, "",   NULL);
  93. usrCommandTable[5].setValues("wspeed",      1, &ChatHandler::HandleModifyWaterSpeedCommand, "",   NULL);//LINA FEATURE
  94. usrCommandTable[6].setValues("scale",       1, &ChatHandler::HandleModifyScaleCommand, "",   NULL);//LINA FEATURE
  95. usrCommandTable[7].setValues("mount",       1, &ChatHandler::HandleModifyMountCommand, "",   NULL);
  96. usrCommandTable[8].setValues("aura",        3, &ChatHandler::HandleAuraCommand, "",   NULL);
  97. usrCommandTable[9].setValues("spell",       3, &ChatHandler::HandleLearnCommand, "",   NULL);
  98. usrCommandTable[10].setValues("skin",       3, &ChatHandler::HandleMorphCommand, "",   NULL);
  99. usrCommandTable[11].setValues(NULL,         0, NULL, "",   NULL);
  100. usrCommandTable[12].setValues("talentxp",   2, &ChatHandler::HandleTalantPointsCommand,     "",   NULL);//THE_WIZARD 
  101. //MAIN
  102. // commandTable[0].setValues("help",        0, &ChatHandler::HandleHelpCommand,          "",   NULL);
  103. commandTable[0].setValues("help",        0, &ChatHandler::HandleCommandsCommand,      "",   NULL);
  104. commandTable[1].setValues("commands",    0, &ChatHandler::HandleCommandsCommand,      "",   NULL);
  105. commandTable[2].setValues("info",        0, &ChatHandler::HandleInfoCommand,          "",   NULL);
  106. commandTable[3].setValues("dismount",    0, &ChatHandler::HandleDismountCommand,      "",   NULL);
  107. commandTable[4].setValues("mount",       0, &ChatHandler::HandleMountCommand,         "",   NULL);
  108. commandTable[5].setValues("save",        0, &ChatHandler::HandleSaveCommand,          "",   NULL);//LINA FEATURE
  109. commandTable[6].setValues("start",       0, &ChatHandler::HandleStartCommand,         "",   NULL);
  110. commandTable[7].setValues("list",        0, &ChatHandler::HandleGMListCommand,        "",   NULL);
  111. commandTable[8].setValues("acct",        0, &ChatHandler::HandleAcctCommand,          "",   NULL);
  112. commandTable[9].setValues("login",       0, &ChatHandler::HandleGMLoginCommand,       "",   NULL);
  113. commandTable[10].setValues("usr",        1, NULL,                                     "",   usrCommandTable);
  114. commandTable[11].setValues("gm",         1, NULL,                                     "",   gmCommandTable);
  115. commandTable[12].setValues("move",  1, NULL,                                     "",   moveCommandTable);
  116. commandTable[13].setValues("npc",        2, NULL,                                     "",   npcCommandTable);
  117. commandTable[14].setValues("admin",      3, NULL,                                     "",   adminCommandTable);
  118. commandTable[15].setValues(NULL,         0, NULL,                                     "",   NULL);
  119. }
  120. if(load)
  121. {
  122. DatabaseInterface *dbi = Database::getSingleton().createDatabaseInterface( );
  123. for(uint32 i = 0; commandTable[i].Name != NULL; i++)
  124. {
  125. dbi->loadChatCommand(commandTable[i].Name, &commandTable[i]);
  126. if(commandTable[i].ChildCommands != NULL)
  127. {
  128. ChatCommand *ptable = commandTable[i].ChildCommands;
  129. for(uint32 j = 0; ptable[j].Name != NULL; j++)
  130. {
  131. std::string str = commandTable[i].Name;
  132. str += " ";
  133. str += ptable[j].Name;
  134. dbi->loadChatCommand(str.c_str(), &ptable[j]);
  135. }
  136. }
  137. }
  138. Database::getSingleton( ).removeDatabaseInterface(dbi);
  139. }
  140. return commandTable;
  141. }
  142. bool ChatHandler::hasStringAbbr(const char* s1, const char* s2) {     for(;;)     {         if( !*s2 )             return true;         else if( !*s1 )             return false;         else if( tolower( *s1 ) != tolower( *s2 ) )             return false;         s1++; s2++;     } } void ChatHandler::SendMultilineMessage(const char *str) {     char buf[256];     wowWData data;     const char* line = str;     const char* pos = line;     while((pos = strchr(line, 'n')) != NULL)     {         strncpy(buf, line, pos-line);         buf[pos-line]=0;         FillMessageData(&data, 0x09, m_pClient, (uint8*)buf);         m_pClient->SendMsg(&data);         line = pos+1;     }     FillMessageData(&data, 0x09, m_pClient, (uint8*)line);     m_pClient->SendMsg(&data); } bool ChatHandler::ExecuteCommandInTable(ChatCommand *table, uint8* text) {     char *cmd = (char*)text;
  143. uint32 AcctLvl = m_pClient->getAccountLvl();     while (*text != ' ' && *text != '') text++; // skip command     if(*text != '')     {         *text = '';         text++;     }     while (*text == ' ') text++; // skip whitespace     if(*cmd == '')         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)
  144.         {
  145.             if(!ExecuteCommandInTable(table[i].ChildCommands, text))
  146.             {
  147.                 if(table[i].Help != "")
  148.                     SendMultilineMessage(table[i].Help.c_str());
  149.                 else
  150.                 {
  151.                     wowWData data;
  152.                     FillMessageData(&data, 0x09, m_pClient, (uint8*)"There is no such subcommand.");
  153.                     m_pClient->SendMsg(&data);
  154.                 }
  155.             }
  156.             return true;
  157.         }
  158. if(!(this->*(table[i].Handler))(text))
  159.         {
  160.             if(table[i].Help != "")
  161.                 SendMultilineMessage(table[i].Help.c_str());
  162.             else
  163.             {
  164.                 wowWData data;
  165.                 FillMessageData(&data, 0x09, m_pClient, (uint8*)"Incorrect syntax.");
  166.                 m_pClient->SendMsg(&data);
  167.             }
  168.         }         return true;     }     return false; } int ChatHandler::ParseCommands(uint8* text, uint16 text_length) {     assert(text);    // assert(*text); fixed by ScreaM     if(text[0] != '!' && text[0] != '.') // let's not confuse users         return 0;     text++;     if(!ExecuteCommandInTable(LoadHelp(false), text))     {         wowWData data;         FillMessageData(&data, 0x09, m_pClient, (uint8*)"There is no such command.");         m_pClient->SendMsg(&data);     }     return 1; } void ChatHandler::HandleMsg( wowWData & recv_data, GameClient *pClient ) {     wowWData data;     char f[256];     sprintf(f, "WORLD: Chat Opcode 0x%.4X", recv_data.opcode);     Log::getSingleton( ).outString( f );     switch (recv_data.opcode)     { case CHAT_MSG_YELL: case CHAT_MSG_PARTY: case CHAT_MSG_GUILD: case CHAT_MSG_OFFICER:     case CMSG_MESSAGECHAT: {             uint16 text_length = strlen((char*)recv_data.data+8)+1; m_pClient = pClient;             if (ParseCommands(recv_data.data+8, text_length) > 0)                 return; uint8 text_mode = recv_data.data[0];             FillMessageData( &data, text_mode, pClient, recv_data.data+8 ); if (text_mode == CHAT_MSG_PARTY) { if (((Character*)pClient->getCurrentChar())->IsInGroup()) { Group *pGroup = world.GetGroupByLeader(((Character*)pClient->getCurrentChar())->GetGroupLeader());                 for (uint32 c=0; c < pGroup->count; c++){ Character *pGroupGuy = world.mCharacters[pGroup->members[c].guid]; world.SendMessageToPlayer(&data, pGroupGuy->getGUID()); } } } else if (text_mode == CHAT_MSG_YELL) { world.SendZoneMessage(&data, pClient, 1); } else if (text_mode == CHAT_MSG_GUILD) return; else if (text_mode == CHAT_MSG_OFFICER) return;             else if (text_mode != CHAT_MSG_WHISPER) { // whisper message send in FillMessageData world.SendAreaMessage(&data, pClient, 1);             }         } break;     case CMSG_TEXT_EMOTE:         { if (pClient->getCurrentChar()->isDead()) return;             uint32 text_emote, guid1, guid2;             recv_data.readData(text_emote);             recv_data >> guid1 >> guid2;             char *nam=0; uint16 namlen=0;             WorldServer::CharacterMap::iterator chariter;             WorldServer::CreatureMap::iterator npciter;             if( (( npciter = world.mCreatures.find( guid1 ) ) != world.mCreatures.end( ) ) && (guid2==0xF0001000) ) {                 nam = npciter->second->getCreatureName( );                 namlen = strlen( nam ) + 1;             } else if( ( chariter = world.mCharacters.find( guid1 ) ) != world.mCharacters.end( ) ) {                 nam = chariter->second->getName( );                 namlen = strlen( nam ) + 1;             }             data.clear();             data.Initialise(12, SMSG_EMOTE);             uint8 emote_anim = world.mEmotes[uint8(text_emote&0xff)];             data << (uint8)emote_anim;             data << (uint8)0x00;             data << (uint8)0x00;             data << (uint8)0x00;             uint32 guid = pClient->getCurrentChar()->getGUID();             data << (uint32)guid << (uint8)0x00 << (uint8)0x00 << (uint8)0x00 << (uint8)0x00; //            world.SendGlobalMessage(&data); world.SendAreaMessage(&data, pClient, 1);             data.clear();             data.setLength(12 + namlen);             data.opcode = SMSG_TEXT_EMOTE;             memcpy(data.data, &guid, 4);             data.data[4] = 0x00;             data.data[5] = 0x00;             data.data[6] = 0x00;             data.data[7] = 0x00;             memcpy(data.data+8,recv_data.data,4);             if( namlen > 0 )                 memcpy( data.data + 12, nam, namlen ); //            pClient->SendMsg( &data ); //            world.SendGlobalMessage(&data, pClient); world.SendAreaMessage(&data, pClient, 1);         } break;     } } void ChatHandler::FillMessageData( wowWData *data, uint8 type, GameClient* pClient, uint8 *text ) {     // !!!! Be careful using strlen to determine the size of the chat message.     // A CHAT_MSG_WHISPER sends TWO null terminated  strings(first the name of     // the whisper target, then the message) and doing strlen only finds the     // length of the first string.  -- DeathCheese     const uint8 msgchat_header_size=13;     uint8 msgchat_header[msgchat_header_size] = {type,         0x00, 0x00, 0x00, 0x00}; //no idea what are those bytes for     // add guid to message header     uint32 guid=0;     if(pClient)         guid = pClient->getCurrentChar()->getGUID();     memcpy(msgchat_header+5, &guid, 4);     msgchat_header[9] = 0x00;     msgchat_header[10] = 0x00;     msgchat_header[11] = 0x00;     msgchat_header[12] = 0x00;     data->clear();     std::string logoutput = "CHAT: ";     if( pClient ) {         logoutput += pClient->getCurrentChar( )->getName( );         logoutput += ": ";     }     uint16 length = strlen((char*)text) + 1;     if (type == CHAT_MSG_WHISPER){         // Whisper Chat:  Server receives two strings.  First is the target of whisper, second is the message.         uint16 msg_length = strlen((char*)text+length) + 1;         data->setLength(msgchat_header_size + msg_length + 1);         data->opcode = SMSG_MESSAGECHAT;         memcpy(data->data, msgchat_header, msgchat_header_size);         memcpy(data->data+msgchat_header_size, text+length, msg_length);         data->data[msgchat_header_size+msg_length] = 0; //NULL terminated string         logoutput += "->";         logoutput += (char *)text;         logoutput += "<- ";         logoutput += (char *)(text + length);     }     else{         data->setLength(msgchat_header_size + length + 1);         data->opcode = SMSG_MESSAGECHAT;         memcpy(data->data,msgchat_header,msgchat_header_size);         memcpy(data->data+msgchat_header_size, text, length);         data->data[msgchat_header_size+length] = 0; //NULL terminated string         logoutput += (char *)text;     }     Log::getSingleton( ).outChat( logoutput.c_str( ) );     // The last byte is most likely a flag, 0 or 1, denoting on or off     uint8 byte = 0x00;     if(type == CHAT_MSG_AFK && pClient!=0) { // toggle AFK         byte = pClient->getCurrentChar()->ToggleAFK();     }     data->data[data->length-1] = byte;     if (type == CHAT_MSG_WHISPER){         char name[22];         memcpy(name, text, length); if (world.GetClientByName((char*)name)) { world.SendMessageToPlayer(data, (char*)name); data->clear(); uint8 buf[256]; sprintf((char*)buf,"To %s: %s", (char*)name, (char *)(text + length)); FillMessageData(data, 0x09, pClient, buf); pClient->SendMsg( data ); } else { data->clear(); uint8 buf[256]; sprintf((char*)buf,"No player named '%s' is currently playing", (char*)name); FillMessageData(data, 0x09, pClient, buf); pClient->SendMsg( data ); }     } } void ChatHandler::SpawnCreature(GameClient *pClient, char* pName, uint32 display_id, uint32 npcFlags, uint32 faction_id, uint32 level) {     wowWData data;     // Create the requested monster     Character *chr = pClient->getCurrentChar();     float x = chr->getPositionX();     float y = chr->getPositionY();     float z = chr->getPositionZ();     float o = chr->getOrientation();     Unit* pUnit = new Unit();     UpdateMask unitMask;     WorldServer::getSingletonPtr()->mObjectMgr.SetCreateUnitBits(unitMask);     pUnit->Create(world.m_hiCreatureGuid++, (uint8*)pName, x, y, z, o);     pUnit->setMapId(chr->getMapId());     pUnit->setZone(chr->getZone());     data.clear();     pUnit->setUpdateValue(OBJECT_FIELD_ENTRY, world.addCreatureName((uint8*)pUnit->getCreatureName()));     pUnit->setUpdateFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);     pUnit->setUpdateValue(UNIT_FIELD_DISPLAYID, display_id);     pUnit->setUpdateValue(UNIT_NPC_FLAGS , npcFlags);     pUnit->setUpdateValue(UNIT_FIELD_FACTIONTEMPLATE , faction_id);     pUnit->setUpdateValue(UNIT_FIELD_HEALTH, 100 + 30*level);     pUnit->setUpdateValue(UNIT_FIELD_MAXHEALTH, 100 + 30*level);     pUnit->setUpdateValue(UNIT_FIELD_LEVEL , level);     pUnit->setUpdateFloatValue(UNIT_FIELD_COMBATREACH , 1.5f);     pUnit->setUpdateFloatValue(UNIT_FIELD_MAXDAMAGE ,  5.0f);     pUnit->setUpdateFloatValue(UNIT_FIELD_MINDAMAGE , 8.0f);     pUnit->setUpdateValue(UNIT_FIELD_BASEATTACKTIME, 1900);     pUnit->setUpdateValue(UNIT_FIELD_BASEATTACKTIME+1, 2000);     pUnit->setUpdateFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 2.0f);     pUnit->CreateObject(&unitMask, &data, 0);     // add to the world list of creatures     WPAssert( pUnit->getGUID() != 0 );     world.mCreatures[pUnit->getGUID()] = pUnit;     // send create message to everyone //    world.SendGlobalMessage(&data); world.SendUnitAreaMessage(&data, pUnit);     DatabaseInterface *dbi = Database::getSingleton( ).createDatabaseInterface( );     dbi->saveCreature(pUnit);     Database::getSingleton( ).removeDatabaseInterface(dbi); } void ChatHandler::smsg_NewWorld(GameClient *pClient, uint16 c, float x, float y, float z) { pClient->getCurrentChar()->setWorldPort(true);     wowWData data;     WorldServer::CreatureMap creatures = world.getCreatureMap();     WorldServer::CharacterMap characters = world.getCharacterMap();     data.Initialise(4, SMSG_TRANSFER_PENDING);     data << uint32(0);     pClient->SendMsg(&data);     // Build a NEW WORLD packet     data.Initialise(20, SMSG_NEW_WORLD);     data << (uint32)c << (float)x << (float)y << (float)z << (float)0.0f;     pClient->SendMsg( &data );     /*     // Destroy this client's player from all clients (including self)     uint32 guid = pClient->getCurrentChar()->getGUID();     data.Initialise(SMSG_DESTROY_OBJECT);     data << (uint32)guid << (uint8)0x00 << (uint8)0x00 << (uint8)0x00 << (uint8)0x00;     WPAssert(data.getLength() == 8);     pClient->SendMsg(&data);     for( WorldServer::CreatureMap::iterator i = creatures.begin( ); i != creatures.end( ); ++ i )     {         uint32 guid = i->second->getGUID();         data.Initialise(SMSG_DESTROY_OBJECT);         data << (uint32)guid << i->second->getGUIDHigh();         WPAssert(data.getLength() == 8);         pClient->SendMsg(&data);     }     */     // Destroy ourselves from other clients     uint32 guid = pClient->getCurrentChar()->getGUID();     data.Initialise(8, SMSG_DESTROY_OBJECT );     data << (uint32)guid << (uint8)0x00 << (uint8)0x00 << (uint8)0x00 << (uint8)0x00; //    pClient->getCurrentChar()->SendMessageToSet(&data, true); world.SendAreaMessage(&data, pClient, 1);     // Remove ourselves from inrange lists     for( WorldServer::CharacterMap::iterator iter = characters.begin( ); iter != characters.end( ); ++ iter )         iter->second->RemoveInRangeObject( pClient->getCurrentChar() );     for( WorldServer::CreatureMap::iterator iter = creatures.begin( ); iter != creatures.end( ); ++ iter )         iter->second->RemoveInRangeObject( pClient->getCurrentChar() );     pClient->getCurrentChar()->ClearInRangeSet();     pClient->getCurrentChar()->setMapId(c);     pClient->getCurrentChar()->setNewPosition(x,y,z); //    pClient->getCurrentChar()->setPosition(8000,8000,0,0,true);     pClient->getCurrentChar()->setPosition(x,y,z,0,true);     //wowWData movedata; // pClient->getCurrentChar( )->TeleportAck(&data, x, y, z); // world.SendAreaMessage(&data, pClient, 1); } void ChatHandler::MovePlayer(GameClient *pClient, float x, float y, float z) {     wowWData data;     //Output new position to the console     uint8 txtBuffer[512];     sprintf((char*)txtBuffer,"WORLD: Moved player to (%f, %f, %f)",x,y,z );     Log::getSingleton( ).outString( (char*)txtBuffer );     sprintf((char*)txtBuffer,"You have been moved to (%f, %f, %f)",x,y,z );     FillMessageData(&data, 0x09, pClient, txtBuffer);     pClient->SendMsg( &data );     ////////////////////////////////////////     //Set the new position of the character     Character *chr = pClient->getCurrentChar();     //Send new position to client via MSG_MOVE_TELEPORT_ACK     chr->TeleportAck(&data, x,y,z);     //pClient->SendMsg(&data);     //////////////////////////////////     //Now send new position of this player to all clients using MSG_MOVE_HEARTBEAT     chr->BuildHeartBeat(&data); //    world.SendGlobalMessage(&data, pClient); world.SendAreaMessage(&data, pClient, 1); } //START OF LINA COMMAND BY NAME FONCTION PATCH
  169. Character * ChatHandler::getCurrentCharByName(uint8 * pName)
  170. {
  171. WorldServer::ClientSet::iterator itr;
  172. for (itr = world.mClients.begin(); itr != world.mClients.end(); itr++)
  173. {
  174. if( strcmp(((GameClient*)(*itr))->getCharacterName(), (char*)pName) == 0 )
  175. {
  176. return ((GameClient*)(*itr))->getCurrentChar();
  177. }
  178. }
  179. wowWData data;
  180. uint8 buf[256];
  181. sprintf((char*)buf,"Character (%s) does not exist or is not logged in.", (char*)pName);
  182. FillMessageData(&data, 0x09, m_pClient, buf);
  183. m_pClient->SendMsg( &data );
  184. return NULL;
  185. }
  186. //END OF LINA COMMAND BY NAME FONCTION PATCH
  187. //START OF LINA COMMAND BY PTR FONCTION PATCH 1.3
  188. Character * ChatHandler::getSelectedChar()
  189. {
  190. const uint32 *guid;
  191. wowWData data;
  192. Character *chr=NULL;
  193. guid = m_pClient->getCurrentChar()->getSelectionPtr();
  194. if (guid[0] != 0)
  195. {
  196. if(guid[1]==0) chr= WorldServer::getSingleton().GetCharacter(guid[0]);
  197. else
  198. {
  199. FillMessageData(&data, 0x09, m_pClient,(uint8*) "Please select a User.");
  200. m_pClient->SendMsg( &data );
  201. }
  202. }
  203. else
  204. {
  205. chr=m_pClient->getCurrentChar();
  206. // FillMessageData(&data, 0x09, m_pClient,(uint8*) "AutoSelection.");
  207. // m_pClient->SendMsg( &data );
  208. }
  209. return chr;
  210. }
  211. //UINT32
  212. int32 ChatHandler::TestValue(const float Value, const float max, const float min)
  213. {
  214. if(Value<min || Value>max)
  215. {
  216. wowWData data;
  217. FillMessageData(&data, 0x09, m_pClient,(uint8*)"Invalid Value.");
  218. m_pClient->SendMsg( &data );
  219. return 0;
  220. }
  221. return 1;
  222. }
  223. //FLOAT
  224. int32 ChatHandler::TestValue(const uint32 Value, const uint32 max, const uint32 min)
  225. {
  226. if(Value<min || Value>max)
  227. {
  228. wowWData data;
  229. FillMessageData(&data, 0x09, m_pClient,(uint8*)"Invalid Value.");
  230. m_pClient->SendMsg( &data );
  231. return 0;
  232. }
  233. return 1;
  234. }
  235. //FLOAT
  236. void ChatHandler::ChangeSelectedCharMsg(const uint16 &index, const float Value, const float max, const float min, char * nom)
  237. {
  238. wowWData data;
  239. if(!TestValue(Value, max, min)) return;
  240. Character * pChar = getSelectedChar();
  241. if(pChar!=NULL)
  242. {
  243. data.Initialise( 12, index );
  244. data << pChar->getUpdateValue( OBJECT_FIELD_GUID );
  245. data << pChar->getUpdateValue( OBJECT_FIELD_GUID + 1 );
  246. data << Value;
  247. pChar->SendMessageToSet( &data, true );
  248. Message(pChar, nom, Value);
  249. }
  250. return;
  251. }
  252. //UINT32
  253. void ChatHandler::ChangeSelectedCharMsg(const uint16 &index, const uint32 Value, const uint32 max, const uint32 min, char * nom)
  254. {
  255. wowWData data;
  256. if(!TestValue(Value, max, min)) return;
  257. Character * pChar = getSelectedChar();
  258. if(pChar!=NULL)
  259. {
  260. data.Initialise( 12, index );
  261. data << pChar->getUpdateValue( OBJECT_FIELD_GUID );
  262. data << pChar->getUpdateValue( OBJECT_FIELD_GUID + 1 );
  263. data << Value;
  264. pChar->SendMessageToSet( &data, true );
  265. Message(pChar, nom, Value);
  266. }
  267. return;
  268. }
  269. //FLOAT
  270. void ChatHandler::ChangeSelectedChar(const uint16 &index, const float Value, const float max, const float min, char * nom)
  271. {
  272. if(!TestValue(Value, max, min)) return;
  273. Character * pChar = getSelectedChar();
  274. if(pChar!=NULL)
  275. {
  276. pChar->setUpdateFloatValue(index , Value);
  277. Message(pChar, nom, Value);
  278. }
  279. return;
  280. }
  281. //UINT32
  282. void ChatHandler::ChangeSelectedChar(const uint16 &index, const uint32 Value, const uint32 max, const uint32 min, char * nom)
  283. {
  284. if(!TestValue(Value, max, min)) return;
  285. Character * pChar = getSelectedChar();
  286. if(pChar!=NULL)
  287. {
  288. pChar->setUpdateValue(index , Value);
  289. Message(pChar, nom, Value);
  290. }
  291. return;
  292. }
  293. //FLOAT
  294. void ChatHandler::Message(Character * pChar, char * nom, const float Value)
  295. {
  296. wowWData data;
  297. uint8 buf[256];
  298. if(strcmp(pChar->getName(),m_pClient->getCurrentChar()->getName())!=0)
  299. {
  300. // send message to user
  301. sprintf((char*)buf,"You change the %s to %2.2f of %s.", nom, Value, pChar->getName());
  302. FillMessageData(&data, 0x09, m_pClient, buf);
  303. m_pClient->SendMsg( &data );
  304. // send message to player
  305. sprintf((char*)buf,"%s changed your %s to %2.2f.", m_pClient->getCurrentChar()->getName(), nom, Value);
  306. FillMessageData(&data, 0x09, pChar->pClient, buf);
  307. pChar->pClient->SendMsg( &data );
  308. // log gm command
  309. FILE *pFile; pFile = fopen("gmcommands.log", "a"); fprintf(pFile, "%s change %s %s to %2.2f.n", m_pClient->getCurrentChar()->getName(), pChar->getName(), nom, Value); fclose(pFile); }
  310. else
  311. {
  312. // send message to user
  313. sprintf((char*)buf,"You change your %s to %2.2f.", nom, Value, pChar->getName());
  314. FillMessageData(&data, 0x09, m_pClient, buf);
  315. m_pClient->SendMsg( &data );
  316. }
  317. }
  318. //UINT32
  319. void ChatHandler::Message(Character * pChar, char * nom, const uint32 Value)
  320. {
  321. wowWData data;
  322. uint8 buf[256];
  323. if(strcmp(pChar->getName(),m_pClient->getCurrentChar()->getName())!=0)
  324. {
  325. // send message to user
  326. sprintf((char*)buf,"You change the %s to %i of %s.", nom, Value, pChar->getName());
  327. FillMessageData(&data, 0x09, m_pClient, buf);
  328. m_pClient->SendMsg( &data );
  329. // send message to player
  330. sprintf((char*)buf,"%s changed your %s to %i.", m_pClient->getCurrentChar()->getName(), nom, Value);
  331. FillMessageData(&data, 0x09, pChar->pClient, buf);
  332. pChar->pClient->SendMsg( &data );
  333. // log gm command
  334. FILE *pFile; pFile = fopen("gmcommands.log", "a"); fprintf(pFile, "%s change %s %s to %i.n", m_pClient->getCurrentChar()->getName(), pChar->getName(), nom, Value); fclose(pFile); }
  335. else
  336. {
  337. // send message to user
  338. sprintf((char*)buf,"You change your %s to %i.", nom, Value, pChar->getName());
  339. FillMessageData(&data, 0x09, m_pClient, buf);
  340. m_pClient->SendMsg( &data );
  341. }
  342. }
  343. void ChatHandler::Message(Character * pChar, char * nom)
  344. {
  345. wowWData data;
  346. uint8 buf[256];
  347. if(strcmp(pChar->getName(),m_pClient->getCurrentChar()->getName())!=0)
  348. {
  349. // send message to user
  350. sprintf((char*)buf,"You %s %s.", nom, pChar->getName());
  351. FillMessageData(&data, 0x09, m_pClient, buf);
  352. m_pClient->SendMsg( &data );
  353. // send message to player
  354. sprintf((char*)buf,"%s %s you.", m_pClient->getCurrentChar()->getName(), nom);
  355. FillMessageData(&data, 0x09, pChar->pClient, buf);
  356. pChar->pClient->SendMsg( &data );
  357. }
  358. else
  359. {
  360. // send message to user
  361. sprintf((char*)buf,"You %s to you.", nom);
  362. FillMessageData(&data, 0x09, m_pClient, buf);
  363. m_pClient->SendMsg( &data );
  364. }
  365. }
  366. Unit * ChatHandler::getSelectedNPC()
  367. {
  368. const uint32 *guid;
  369. guid = m_pClient->getCurrentChar()->getSelectionPtr();
  370. if (guid[0] != 0)
  371. {
  372. if(guid[1]==0xF0001000) return WorldServer::getSingleton().GetCreature(guid[0]);
  373. }
  374. wowWData data;
  375. FillMessageData(&data, 0x09, m_pClient,(uint8*) "Please select a NPC");
  376. m_pClient->SendMsg( &data );
  377. return NULL;
  378. }
  379. void ChatHandler::ChangeSelectedNPC(const uint16 &index, const uint32 Value, const uint32 max, const uint32 min)
  380. {
  381. wowWData data;
  382. if(!TestValue(Value, max, min)) return;
  383. Unit * pUnit = getSelectedNPC();
  384. if(pUnit!=NULL)
  385. {
  386. pUnit->setUpdateValue(index , Value);
  387. DatabaseInterface *dbi = Database::getSingleton().createDatabaseInterface( );
  388. /*
  389. sprintf((char*)buf, "DELETE FROM creatures WHERE id=%u", pUnit->getGUID());
  390. dbi->doQuery((char*)buf);
  391. dbi->saveCreature(pUnit);
  392. */
  393. dbi->updateCreature(pUnit);
  394. Database::getSingleton( ).removeDatabaseInterface(dbi);
  395. pUnit->UpdateObject();
  396. FillMessageData(&data, 0x09, m_pClient,(uint8*)"NPC updated.");
  397. m_pClient->SendMsg( &data );
  398. }
  399. return;
  400. }
  401. //END OF LINA COMMAND BY PTR FONCTION PATCH 1.3 // ELECTRIX ADD START { void ChatHandler::GenCreature(GameClient *pClient, uint32 StartId, uint32 EndId ,uint32 StepId ) {     char* pName= "Def Name ";     uint32 CurrentId=1;     uint16 ModuloId=0;     uint32 npcFlags=0;     uint32 faction_id=0;     uint32 level=10;     wowWData data;     // Create the requested monster     Character *chr = pClient->getCurrentChar();     float x = chr->getPositionX();     float y = chr->getPositionY();     float z = chr->getPositionZ();     float o = chr->getOrientation();     for (CurrentId=StartId;CurrentId<=EndId;CurrentId++)     {         x+= (float) 5.0f;         ModuloId++;         if ( ModuloId>=StepId)         {             x-= (float) 5.0f *(float) ModuloId;             ModuloId=0;             y+= (float) 10.0f;         }         sprintf(pName,"Id:%i",CurrentId);         Unit* pUnit = new Unit();         UpdateMask unitMask;         WorldServer::getSingletonPtr()->mObjectMgr.SetCreateUnitBits(unitMask);         pUnit->Create(world.m_hiCreatureGuid++, (uint8*)pName, x, y, z, o);         pUnit->setMapId(chr->getMapId());         pUnit->setZone(chr->getZone());         data.clear();         pUnit->setUpdateValue(OBJECT_FIELD_ENTRY, world.addCreatureName((uint8*)pUnit->getCreatureName()));         pUnit->setUpdateFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);         pUnit->setUpdateValue(UNIT_FIELD_DISPLAYID, CurrentId);         pUnit->setUpdateValue(UNIT_NPC_FLAGS , npcFlags);         pUnit->setUpdateValue(UNIT_FIELD_FACTIONTEMPLATE , faction_id);         pUnit->setUpdateValue(UNIT_FIELD_HEALTH, 100 + 30*level);         pUnit->setUpdateValue(UNIT_FIELD_MAXHEALTH, 100 + 30*level);         pUnit->setUpdateValue(UNIT_FIELD_LEVEL , level);         pUnit->setUpdateFloatValue(UNIT_FIELD_COMBATREACH , 1.5f);         pUnit->setUpdateFloatValue(UNIT_FIELD_MAXDAMAGE ,  5.0f);         pUnit->setUpdateFloatValue(UNIT_FIELD_MINDAMAGE , 8.0f);         pUnit->setUpdateValue(UNIT_FIELD_BASEATTACKTIME, 1900);         pUnit->setUpdateValue(UNIT_FIELD_BASEATTACKTIME+1, 2000);         pUnit->setUpdateFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 2.0f);         pUnit->CreateObject(&unitMask, &data, 0);         //  add to the world list of creatures         WPAssert( pUnit->getGUID() != 0 );         world.mCreatures[pUnit->getGUID()] = pUnit;         // send create message to everyone //        world.SendGlobalMessage(&data); world.SendUnitAreaMessage(&data, pUnit);         DatabaseInterface *dbi = Database::getSingleton( ).createDatabaseInterface( );         char sql[512];         sprintf(sql, "insert into skin set id_skin='%i',name='%s',type='0',race='0', gender='0'", CurrentId,pName);         dbi->doQuery(sql);         //dbi->saveCreature(pUnit);         Database::getSingleton( ).removeDatabaseInterface(dbi);     } } // }ELECTRIX ADD END