[28] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 4 | * This program is free software; you can redistribute it and/or modify |
---|
| 5 | * it under the terms of the GNU General Public License as published by |
---|
| 6 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | * (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include "Common.h" |
---|
| 20 | #include "Database/DatabaseEnv.h" |
---|
| 21 | #include "WorldPacket.h" |
---|
| 22 | #include "SharedDefines.h" |
---|
| 23 | #include "WorldSession.h" |
---|
| 24 | #include "Opcodes.h" |
---|
| 25 | #include "Log.h" |
---|
| 26 | #include "World.h" |
---|
| 27 | #include "ObjectMgr.h" |
---|
| 28 | #include "Player.h" |
---|
| 29 | #include "Guild.h" |
---|
| 30 | #include "UpdateMask.h" |
---|
| 31 | #include "Auth/md5.h" |
---|
| 32 | #include "MapManager.h" |
---|
| 33 | #include "ObjectAccessor.h" |
---|
| 34 | #include "Group.h" |
---|
| 35 | #include "Database/DatabaseImpl.h" |
---|
| 36 | #include "PlayerDump.h" |
---|
| 37 | #include "SocialMgr.h" |
---|
| 38 | #include "Util.h" |
---|
| 39 | #include "Language.h" |
---|
| 40 | |
---|
| 41 | class LoginQueryHolder : public SqlQueryHolder |
---|
| 42 | { |
---|
| 43 | private: |
---|
| 44 | uint32 m_accountId; |
---|
| 45 | uint64 m_guid; |
---|
| 46 | public: |
---|
| 47 | LoginQueryHolder(uint32 accountId, uint64 guid) |
---|
| 48 | : m_accountId(accountId), m_guid(guid) { } |
---|
| 49 | uint64 GetGuid() const { return m_guid; } |
---|
| 50 | uint32 GetAccountId() const { return m_accountId; } |
---|
| 51 | bool Initialize(); |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | bool LoginQueryHolder::Initialize() |
---|
| 55 | { |
---|
| 56 | SetSize(MAX_PLAYER_LOGIN_QUERY); |
---|
| 57 | |
---|
| 58 | bool res = true; |
---|
| 59 | |
---|
| 60 | // NOTE: all fields in `characters` must be read to prevent lost character data at next save in case wrong DB structure. |
---|
| 61 | // !!! NOTE: including unused `zone`,`online` |
---|
| 62 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADFROM, "SELECT guid, account, data, name, race, class, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, gmstate, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty FROM characters WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 63 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADGROUP, "SELECT leaderGuid FROM group_member WHERE memberGuid ='%u'", GUID_LOPART(m_guid)); |
---|
| 64 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES, "SELECT id, permanent, map, difficulty, resettime FROM character_instance LEFT JOIN instance ON instance = id WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 65 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS, "SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 66 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS, "SELECT spell,slot,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 67 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS, "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 68 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 69 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADTUTORIALS, "SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u' AND realmid = '%u'", GetAccountId(), realmID); |
---|
| 70 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 71 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GUID_LOPART(m_guid)); |
---|
| 72 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS, "SELECT button,action,type,misc FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid)); |
---|
| 73 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILCOUNT, "SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" I64FMTD "'", GUID_LOPART(m_guid),(uint64)time(NULL)); |
---|
| 74 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid)); |
---|
| 75 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid)); |
---|
| 76 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADHOMEBIND, "SELECT map,zone,position_x,position_y,position_z FROM character_homebind WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 77 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS, "SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 78 | if(sWorld.getConfig(CONFIG_DECLINED_NAMES_USED)) |
---|
| 79 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = '%u'",GUID_LOPART(m_guid)); |
---|
| 80 | // in other case still be dummy query |
---|
| 81 | res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADGUILD, "SELECT guildid,rank FROM guild_member WHERE guid = '%u'", GUID_LOPART(m_guid)); |
---|
| 82 | |
---|
| 83 | return res; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | // don't call WorldSession directly |
---|
| 87 | // it may get deleted before the query callbacks get executed |
---|
| 88 | // instead pass an account id to this handler |
---|
| 89 | class CharacterHandler |
---|
| 90 | { |
---|
| 91 | public: |
---|
| 92 | void HandleCharEnumCallback(QueryResult * result, uint32 account) |
---|
| 93 | { |
---|
| 94 | WorldSession * session = sWorld.FindSession(account); |
---|
| 95 | if(!session) |
---|
| 96 | { |
---|
| 97 | delete result; |
---|
| 98 | return; |
---|
| 99 | } |
---|
| 100 | session->HandleCharEnum(result); |
---|
| 101 | } |
---|
| 102 | void HandlePlayerLoginCallback(QueryResult * /*dummy*/, SqlQueryHolder * holder) |
---|
| 103 | { |
---|
| 104 | if (!holder) return; |
---|
| 105 | WorldSession *session = sWorld.FindSession(((LoginQueryHolder*)holder)->GetAccountId()); |
---|
| 106 | if(!session) |
---|
| 107 | { |
---|
| 108 | delete holder; |
---|
| 109 | return; |
---|
| 110 | } |
---|
| 111 | session->HandlePlayerLogin((LoginQueryHolder*)holder); |
---|
| 112 | } |
---|
| 113 | } chrHandler; |
---|
| 114 | |
---|
| 115 | void WorldSession::HandleCharEnum(QueryResult * result) |
---|
| 116 | { |
---|
| 117 | // keys can be non cleared if player open realm list and close it by 'cancel' |
---|
| 118 | loginDatabase.PExecute("UPDATE account SET v = '0', s = '0' WHERE id = '%u'", GetAccountId()); |
---|
| 119 | |
---|
| 120 | WorldPacket data(SMSG_CHAR_ENUM, 100); // we guess size |
---|
| 121 | |
---|
| 122 | uint8 num = 0; |
---|
| 123 | |
---|
| 124 | data << num; |
---|
| 125 | |
---|
| 126 | if( result ) |
---|
| 127 | { |
---|
| 128 | Player *plr = new Player(this); |
---|
| 129 | do |
---|
| 130 | { |
---|
| 131 | sLog.outDetail("Loading char guid %u from account %u.",(*result)[0].GetUInt32(),GetAccountId()); |
---|
| 132 | |
---|
| 133 | if(plr->MinimalLoadFromDB( result, (*result)[0].GetUInt32() )) |
---|
| 134 | { |
---|
| 135 | plr->BuildEnumData( result, &data ); |
---|
| 136 | ++num; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | while( result->NextRow() ); |
---|
| 140 | |
---|
| 141 | delete plr; |
---|
| 142 | delete result; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | data.put<uint8>(0, num); |
---|
| 146 | |
---|
| 147 | SendPacket( &data ); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void WorldSession::HandleCharEnumOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 151 | { |
---|
| 152 | /// get all the data necessary for loading all characters (along with their pets) on the account |
---|
| 153 | CharacterDatabase.AsyncPQuery(&chrHandler, &CharacterHandler::HandleCharEnumCallback, GetAccountId(), |
---|
| 154 | !sWorld.getConfig(CONFIG_DECLINED_NAMES_USED) ? |
---|
| 155 | // ------- Query Without Declined Names -------- |
---|
| 156 | // 0 1 2 3 4 5 6 7 8 |
---|
| 157 | "SELECT characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, characters.at_login, " |
---|
| 158 | // 9 10 11 |
---|
| 159 | "character_pet.entry, character_pet.modelid, character_pet.level " |
---|
| 160 | "FROM characters LEFT JOIN character_pet ON characters.guid=character_pet.owner AND character_pet.slot='0' " |
---|
| 161 | "WHERE characters.account = '%u' ORDER BY characters.guid" |
---|
| 162 | : |
---|
| 163 | // --------- Query With Declined Names --------- |
---|
| 164 | // 0 1 2 3 4 5 6 7 8 |
---|
| 165 | "SELECT characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, characters.at_login, " |
---|
| 166 | // 9 10 11 12 |
---|
| 167 | "character_pet.entry, character_pet.modelid, character_pet.level, genitive " |
---|
| 168 | "FROM characters LEFT JOIN character_pet ON characters.guid = character_pet.owner AND character_pet.slot='0' " |
---|
| 169 | "LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid " |
---|
| 170 | "WHERE characters.account = '%u' ORDER BY characters.guid", |
---|
| 171 | GetAccountId()); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) |
---|
| 175 | { |
---|
| 176 | CHECK_PACKET_SIZE(recv_data,1+1+1+1+1+1+1+1+1+1); |
---|
| 177 | |
---|
| 178 | std::string name; |
---|
| 179 | uint8 race_,class_; |
---|
| 180 | bool pTbc = this->IsTBC() && sWorld.getConfig(CONFIG_EXPANSION) > 0; |
---|
| 181 | recv_data >> name; |
---|
| 182 | |
---|
| 183 | // recheck with known string size |
---|
| 184 | CHECK_PACKET_SIZE(recv_data,(name.size()+1)+1+1+1+1+1+1+1+1+1); |
---|
| 185 | |
---|
| 186 | recv_data >> race_; |
---|
| 187 | recv_data >> class_; |
---|
| 188 | |
---|
| 189 | WorldPacket data(SMSG_CHAR_CREATE, 1); // returned with diff.values in all cases |
---|
| 190 | |
---|
| 191 | if(GetSecurity() == SEC_PLAYER) |
---|
| 192 | { |
---|
| 193 | if(uint32 mask = sWorld.getConfig(CONFIG_CHARACTERS_CREATING_DISABLED)) |
---|
| 194 | { |
---|
| 195 | bool disabled = false; |
---|
| 196 | |
---|
| 197 | uint32 team = Player::TeamForRace(race_); |
---|
| 198 | switch(team) |
---|
| 199 | { |
---|
| 200 | case ALLIANCE: disabled = mask & (1<<0); break; |
---|
| 201 | case HORDE: disabled = mask & (1<<1); break; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | if(disabled) |
---|
| 205 | { |
---|
| 206 | data << (uint8)CHAR_CREATE_DISABLED; |
---|
| 207 | SendPacket( &data ); |
---|
| 208 | return; |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | if (!sChrClassesStore.LookupEntry(class_)|| |
---|
| 214 | !sChrRacesStore.LookupEntry(race_)) |
---|
| 215 | { |
---|
| 216 | data << (uint8)CHAR_CREATE_FAILED; |
---|
| 217 | SendPacket( &data ); |
---|
| 218 | sLog.outError("Class: %u or Race %u not found in DBC (Wrong DBC files?) or Cheater?", class_, race_); |
---|
| 219 | return; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | // prevent character creating Expansion race without Expansion account |
---|
| 223 | if (!pTbc&&(race_>RACE_TROLL)) |
---|
| 224 | { |
---|
| 225 | data << (uint8)CHAR_CREATE_EXPANSION; |
---|
| 226 | sLog.outError("No Expansion Account:[%d] but tried to Create TBC character",GetAccountId()); |
---|
| 227 | SendPacket( &data ); |
---|
| 228 | return; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | // prevent character creating with invalid name |
---|
| 232 | if(!normalizePlayerName(name)) |
---|
| 233 | { |
---|
| 234 | data << (uint8)CHAR_NAME_INVALID_CHARACTER; |
---|
| 235 | SendPacket( &data ); |
---|
| 236 | sLog.outError("Account:[%d] but tried to Create character with empty [name] ",GetAccountId()); |
---|
| 237 | return; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | // check name limitations |
---|
| 241 | if(!ObjectMgr::IsValidName(name,true)) |
---|
| 242 | { |
---|
| 243 | data << (uint8)CHAR_NAME_INVALID_CHARACTER; |
---|
| 244 | SendPacket( &data ); |
---|
| 245 | return; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(name)) |
---|
| 249 | { |
---|
| 250 | data << (uint8)CHAR_NAME_RESERVED; |
---|
| 251 | SendPacket( &data ); |
---|
| 252 | return; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | if(objmgr.GetPlayerGUIDByName(name)) |
---|
| 256 | { |
---|
| 257 | data << (uint8)CHAR_CREATE_NAME_IN_USE; |
---|
| 258 | SendPacket( &data ); |
---|
| 259 | return; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | QueryResult *resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId()); |
---|
| 263 | if ( resultacct ) |
---|
| 264 | { |
---|
| 265 | Field *fields=resultacct->Fetch(); |
---|
| 266 | uint32 acctcharcount = fields[0].GetUInt32(); |
---|
| 267 | delete resultacct; |
---|
| 268 | |
---|
| 269 | if (acctcharcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_ACCOUNT)) |
---|
| 270 | { |
---|
| 271 | data << (uint8)CHAR_CREATE_ACCOUNT_LIMIT; |
---|
| 272 | SendPacket( &data ); |
---|
| 273 | return; |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId()); |
---|
| 278 | uint8 charcount = 0; |
---|
| 279 | if ( result ) |
---|
| 280 | { |
---|
| 281 | Field *fields=result->Fetch(); |
---|
| 282 | charcount = fields[0].GetUInt8(); |
---|
| 283 | delete result; |
---|
| 284 | |
---|
| 285 | if (charcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_REALM)) |
---|
| 286 | { |
---|
| 287 | data << (uint8)CHAR_CREATE_SERVER_LIMIT; |
---|
| 288 | SendPacket( &data ); |
---|
| 289 | return; |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | bool AllowTwoSideAccounts = !sWorld.IsPvPRealm() || sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS) || GetSecurity() > SEC_PLAYER; |
---|
| 294 | uint32 skipCinematics = sWorld.getConfig(CONFIG_SKIP_CINEMATICS); |
---|
| 295 | |
---|
| 296 | bool have_same_race = false; |
---|
| 297 | if(!AllowTwoSideAccounts || skipCinematics == 1) |
---|
| 298 | { |
---|
| 299 | QueryResult *result2 = CharacterDatabase.PQuery("SELECT DISTINCT race FROM characters WHERE account = '%u' %s", GetAccountId(),skipCinematics == 1 ? "" : "LIMIT 1"); |
---|
| 300 | if(result2) |
---|
| 301 | { |
---|
| 302 | uint32 team_= Player::TeamForRace(race_); |
---|
| 303 | |
---|
| 304 | Field* field = result2->Fetch(); |
---|
| 305 | uint8 race = field[0].GetUInt32(); |
---|
| 306 | |
---|
| 307 | // need to check team only for first character |
---|
| 308 | // TODO: what to if account already has characters of both races? |
---|
| 309 | if (!AllowTwoSideAccounts) |
---|
| 310 | { |
---|
| 311 | uint32 team=0; |
---|
| 312 | if(race > 0) |
---|
| 313 | team = Player::TeamForRace(race); |
---|
| 314 | |
---|
| 315 | if(team != team_) |
---|
| 316 | { |
---|
| 317 | data << (uint8)CHAR_CREATE_PVP_TEAMS_VIOLATION; |
---|
| 318 | SendPacket( &data ); |
---|
| 319 | delete result2; |
---|
| 320 | return; |
---|
| 321 | } |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | if (skipCinematics == 1) |
---|
| 325 | { |
---|
| 326 | // TODO: check if cinematic already shown? (already logged in?; cinematic field) |
---|
| 327 | while (race_ != race && result2->NextRow()) |
---|
| 328 | { |
---|
| 329 | field = result2->Fetch(); |
---|
| 330 | race = field[0].GetUInt32(); |
---|
| 331 | } |
---|
| 332 | have_same_race = race_ == race; |
---|
| 333 | } |
---|
| 334 | delete result2; |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | // extract other data required for player creating |
---|
| 339 | uint8 gender, skin, face, hairStyle, hairColor, facialHair, outfitId; |
---|
| 340 | recv_data >> gender >> skin >> face; |
---|
| 341 | recv_data >> hairStyle >> hairColor >> facialHair >> outfitId; |
---|
| 342 | |
---|
| 343 | Player * pNewChar = new Player(this); |
---|
| 344 | if(!pNewChar->Create( objmgr.GenerateLowGuid(HIGHGUID_PLAYER), name, race_, class_, gender, skin, face, hairStyle, hairColor, facialHair, outfitId )) |
---|
| 345 | { |
---|
| 346 | // Player not create (race/class problem?) |
---|
| 347 | delete pNewChar; |
---|
| 348 | |
---|
| 349 | data << (uint8)CHAR_CREATE_ERROR; |
---|
| 350 | SendPacket( &data ); |
---|
| 351 | |
---|
| 352 | return; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | if(have_same_race && skipCinematics == 1 || skipCinematics == 2) |
---|
| 356 | pNewChar->setCinematic(1); // not show intro |
---|
| 357 | |
---|
| 358 | // Player created, save it now |
---|
| 359 | pNewChar->SaveToDB(); |
---|
| 360 | charcount+=1; |
---|
| 361 | |
---|
| 362 | loginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID); |
---|
| 363 | loginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount, GetAccountId(), realmID); |
---|
| 364 | |
---|
| 365 | delete pNewChar; // created only to call SaveToDB() |
---|
| 366 | |
---|
| 367 | data << (uint8)CHAR_CREATE_SUCCESS; |
---|
| 368 | SendPacket( &data ); |
---|
| 369 | |
---|
| 370 | std::string IP_str = GetRemoteAddress().c_str(); |
---|
| 371 | sLog.outBasic("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str()); |
---|
| 372 | sLog.outChar("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str()); |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | void WorldSession::HandleCharDeleteOpcode( WorldPacket & recv_data ) |
---|
| 376 | { |
---|
| 377 | CHECK_PACKET_SIZE(recv_data,8); |
---|
| 378 | |
---|
| 379 | uint64 guid; |
---|
| 380 | recv_data >> guid; |
---|
| 381 | |
---|
| 382 | // can't delete loaded character |
---|
| 383 | if(objmgr.GetPlayer(guid)) |
---|
| 384 | return; |
---|
| 385 | |
---|
| 386 | uint32 accountId = 0; |
---|
| 387 | std::string name; |
---|
| 388 | |
---|
| 389 | // is guild leader |
---|
| 390 | if(objmgr.GetGuildByLeader(guid)) |
---|
| 391 | { |
---|
| 392 | WorldPacket data(SMSG_CHAR_DELETE, 1); |
---|
| 393 | data << (uint8)CHAR_DELETE_FAILED_GUILD_LEADER; |
---|
| 394 | SendPacket( &data ); |
---|
| 395 | return; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | // is arena team captain |
---|
| 399 | if(objmgr.GetArenaTeamByCapitan(guid)) |
---|
| 400 | { |
---|
| 401 | WorldPacket data(SMSG_CHAR_DELETE, 1); |
---|
| 402 | data << (uint8)CHAR_DELETE_FAILED_ARENA_CAPTAIN; |
---|
| 403 | SendPacket( &data ); |
---|
| 404 | return; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | QueryResult *result = CharacterDatabase.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid)); |
---|
| 408 | if(result) |
---|
| 409 | { |
---|
| 410 | Field *fields = result->Fetch(); |
---|
| 411 | accountId = fields[0].GetUInt32(); |
---|
| 412 | name = fields[1].GetCppString(); |
---|
| 413 | delete result; |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | // prevent deleting other players' characters using cheating tools |
---|
| 417 | if(accountId != GetAccountId()) |
---|
| 418 | return; |
---|
| 419 | |
---|
| 420 | std::string IP_str = GetRemoteAddress(); |
---|
| 421 | sLog.outBasic("Account: %d (IP: %s) Delete Character:[%s] (guid:%u)",GetAccountId(),IP_str.c_str(),name.c_str(),GUID_LOPART(guid)); |
---|
| 422 | sLog.outChar("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)",GetAccountId(),IP_str.c_str(),name.c_str(),GUID_LOPART(guid)); |
---|
| 423 | |
---|
| 424 | if(sLog.IsOutCharDump()) // optimize GetPlayerDump call |
---|
| 425 | { |
---|
| 426 | std::string dump = PlayerDumpWriter().GetDump(GUID_LOPART(guid)); |
---|
| 427 | sLog.outCharDump(dump.c_str(),GetAccountId(),GUID_LOPART(guid),name.c_str()); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | Player::DeleteFromDB(guid, GetAccountId()); |
---|
| 431 | |
---|
| 432 | WorldPacket data(SMSG_CHAR_DELETE, 1); |
---|
| 433 | data << (uint8)CHAR_DELETE_SUCCESS; |
---|
| 434 | SendPacket( &data ); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | void WorldSession::HandlePlayerLoginOpcode( WorldPacket & recv_data ) |
---|
| 438 | { |
---|
| 439 | CHECK_PACKET_SIZE(recv_data,8); |
---|
| 440 | |
---|
| 441 | m_playerLoading = true; |
---|
| 442 | uint64 playerGuid = 0; |
---|
| 443 | |
---|
| 444 | DEBUG_LOG( "WORLD: Recvd Player Logon Message" ); |
---|
| 445 | |
---|
| 446 | recv_data >> playerGuid; |
---|
| 447 | |
---|
| 448 | LoginQueryHolder *holder = new LoginQueryHolder(GetAccountId(), playerGuid); |
---|
| 449 | if(!holder->Initialize()) |
---|
| 450 | { |
---|
| 451 | delete holder; // delete all unprocessed queries |
---|
| 452 | m_playerLoading = false; |
---|
| 453 | return; |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | CharacterDatabase.DelayQueryHolder(&chrHandler, &CharacterHandler::HandlePlayerLoginCallback, holder); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder) |
---|
| 460 | { |
---|
| 461 | uint64 playerGuid = holder->GetGuid(); |
---|
| 462 | |
---|
| 463 | Player* pCurrChar = new Player(this); |
---|
| 464 | pCurrChar->GetMotionMaster()->Initialize(); |
---|
| 465 | |
---|
| 466 | // "GetAccountId()==db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools) |
---|
| 467 | if(!pCurrChar->LoadFromDB(GUID_LOPART(playerGuid), holder)) |
---|
| 468 | { |
---|
| 469 | KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick |
---|
| 470 | delete pCurrChar; // delete it manually |
---|
| 471 | delete holder; // delete all unprocessed queries |
---|
| 472 | m_playerLoading = false; |
---|
| 473 | return; |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | SetPlayer(pCurrChar); |
---|
| 477 | |
---|
| 478 | pCurrChar->SendDungeonDifficulty(false); |
---|
| 479 | |
---|
| 480 | WorldPacket data( SMSG_LOGIN_VERIFY_WORLD, 20 ); |
---|
| 481 | data << pCurrChar->GetMapId(); |
---|
| 482 | data << pCurrChar->GetPositionX(); |
---|
| 483 | data << pCurrChar->GetPositionY(); |
---|
| 484 | data << pCurrChar->GetPositionZ(); |
---|
| 485 | data << pCurrChar->GetOrientation(); |
---|
| 486 | SendPacket(&data); |
---|
| 487 | |
---|
| 488 | data.Initialize( SMSG_ACCOUNT_DATA_TIMES, 128 ); |
---|
| 489 | for(int i = 0; i < 32; i++) |
---|
| 490 | data << uint32(0); |
---|
| 491 | SendPacket(&data); |
---|
| 492 | |
---|
| 493 | data.Initialize(SMSG_FEATURE_SYSTEM_STATUS, 2); // added in 2.2.0 |
---|
| 494 | data << uint8(2); // unknown value |
---|
| 495 | data << uint8(0); // enable(1)/disable(0) voice chat interface in client |
---|
| 496 | SendPacket(&data); |
---|
| 497 | |
---|
| 498 | // Send MOTD |
---|
| 499 | { |
---|
| 500 | data.Initialize(SMSG_MOTD, 50); // new in 2.0.1 |
---|
| 501 | data << (uint32)0; |
---|
| 502 | |
---|
| 503 | uint32 linecount=0; |
---|
| 504 | std::string str_motd = sWorld.GetMotd(); |
---|
| 505 | std::string::size_type pos, nextpos; |
---|
| 506 | |
---|
| 507 | pos = 0; |
---|
| 508 | while ( (nextpos= str_motd.find('@',pos)) != std::string::npos ) |
---|
| 509 | { |
---|
| 510 | if (nextpos != pos) |
---|
| 511 | { |
---|
| 512 | data << str_motd.substr(pos,nextpos-pos); |
---|
| 513 | ++linecount; |
---|
| 514 | } |
---|
| 515 | pos = nextpos+1; |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | if (pos<str_motd.length()) |
---|
| 519 | { |
---|
| 520 | data << str_motd.substr(pos); |
---|
| 521 | ++linecount; |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | data.put(0, linecount); |
---|
| 525 | |
---|
| 526 | SendPacket( &data ); |
---|
| 527 | DEBUG_LOG( "WORLD: Sent motd (SMSG_MOTD)" ); |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | if(pCurrChar->GetGuildId() != 0) |
---|
| 531 | { |
---|
| 532 | Guild* guild = objmgr.GetGuildById(pCurrChar->GetGuildId()); |
---|
| 533 | if(guild) |
---|
| 534 | { |
---|
| 535 | data.Initialize(SMSG_GUILD_EVENT, (2+guild->GetMOTD().size()+1)); |
---|
| 536 | data << (uint8)GE_MOTD; |
---|
| 537 | data << (uint8)1; |
---|
| 538 | data << guild->GetMOTD(); |
---|
| 539 | SendPacket(&data); |
---|
| 540 | DEBUG_LOG( "WORLD: Sent guild-motd (SMSG_GUILD_EVENT)" ); |
---|
| 541 | |
---|
| 542 | data.Initialize(SMSG_GUILD_EVENT, (5+10)); // we guess size |
---|
| 543 | data<<(uint8)GE_SIGNED_ON; |
---|
| 544 | data<<(uint8)1; |
---|
| 545 | data<<pCurrChar->GetName(); |
---|
| 546 | data<<pCurrChar->GetGUID(); |
---|
| 547 | guild->BroadcastPacket(&data); |
---|
| 548 | DEBUG_LOG( "WORLD: Sent guild-signed-on (SMSG_GUILD_EVENT)" ); |
---|
| 549 | |
---|
| 550 | // Increment online members of the guild |
---|
| 551 | guild->IncOnlineMemberCount(); |
---|
| 552 | } |
---|
| 553 | else |
---|
| 554 | { |
---|
| 555 | // remove wrong guild data |
---|
| 556 | sLog.outError("Player %s (GUID: %u) marked as member not existed guild (id: %u), removing guild membership for player.",pCurrChar->GetName(),pCurrChar->GetGUIDLow(),pCurrChar->GetGuildId()); |
---|
| 557 | pCurrChar->SetUInt32Value(PLAYER_GUILDID,0); |
---|
| 558 | pCurrChar->SetUInt32ValueInDB(PLAYER_GUILDID,0,pCurrChar->GetGUID()); |
---|
| 559 | } |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | if(!pCurrChar->isAlive()) |
---|
| 563 | pCurrChar->SendCorpseReclaimDelay(true); |
---|
| 564 | |
---|
| 565 | pCurrChar->SendInitialPacketsBeforeAddToMap(); |
---|
| 566 | |
---|
| 567 | //Show cinematic at the first time that player login |
---|
| 568 | if( !pCurrChar->getCinematic() ) |
---|
| 569 | { |
---|
| 570 | pCurrChar->setCinematic(1); |
---|
| 571 | |
---|
| 572 | ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(pCurrChar->getRace()); |
---|
| 573 | if(rEntry) |
---|
| 574 | { |
---|
| 575 | data.Initialize( SMSG_TRIGGER_CINEMATIC,4 ); |
---|
| 576 | data << uint32(rEntry->startmovie); |
---|
| 577 | SendPacket( &data ); |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | //QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow()); |
---|
| 582 | QueryResult *resultGuild = holder->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD); |
---|
| 583 | |
---|
| 584 | if(resultGuild) |
---|
| 585 | { |
---|
| 586 | Field *fields = resultGuild->Fetch(); |
---|
| 587 | pCurrChar->SetInGuild(fields[0].GetUInt32()); |
---|
| 588 | pCurrChar->SetRank(fields[1].GetUInt32()); |
---|
| 589 | delete resultGuild; |
---|
| 590 | } |
---|
| 591 | else if(pCurrChar->GetGuildId()) // clear guild related fields in case wrong data about non existed membership |
---|
| 592 | { |
---|
| 593 | pCurrChar->SetInGuild(0); |
---|
| 594 | pCurrChar->SetRank(0); |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | if (!MapManager::Instance().GetMap(pCurrChar->GetMapId(), pCurrChar)->Add(pCurrChar)) |
---|
| 598 | { |
---|
| 599 | AreaTrigger const* at = objmgr.GetGoBackTrigger(pCurrChar->GetMapId()); |
---|
| 600 | if(at) |
---|
| 601 | pCurrChar->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, pCurrChar->GetOrientation()); |
---|
| 602 | else |
---|
| 603 | pCurrChar->TeleportTo(pCurrChar->m_homebindMapId, pCurrChar->m_homebindX, pCurrChar->m_homebindY, pCurrChar->m_homebindZ, pCurrChar->GetOrientation()); |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | ObjectAccessor::Instance().AddObject(pCurrChar); |
---|
| 607 | //sLog.outDebug("Player %s added to Map.",pCurrChar->GetName()); |
---|
| 608 | pCurrChar->GetSocial()->SendSocialList(); |
---|
| 609 | |
---|
| 610 | pCurrChar->SendInitialPacketsAfterAddToMap(); |
---|
| 611 | |
---|
| 612 | CharacterDatabase.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar->GetGUIDLow()); |
---|
| 613 | loginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId()); |
---|
| 614 | pCurrChar->SetInGameTime( getMSTime() ); |
---|
| 615 | |
---|
| 616 | // announce group about member online (must be after add to player list to receive announce to self) |
---|
| 617 | if(Group *group = pCurrChar->GetGroup()) |
---|
| 618 | { |
---|
| 619 | //pCurrChar->groupInfo.group->SendInit(this); // useless |
---|
| 620 | group->SendUpdate(); |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | // friend status |
---|
| 624 | sSocialMgr.SendFriendStatus(pCurrChar, FRIEND_ONLINE, pCurrChar->GetGUIDLow(), "", true); |
---|
| 625 | |
---|
| 626 | // Place character in world (and load zone) before some object loading |
---|
| 627 | pCurrChar->LoadCorpse(); |
---|
| 628 | |
---|
| 629 | // setting Ghost+speed if dead |
---|
| 630 | //if ( pCurrChar->m_deathState == DEAD ) |
---|
| 631 | if (pCurrChar->m_deathState != ALIVE) |
---|
| 632 | { |
---|
| 633 | // not blizz like, we must correctly save and load player instead... |
---|
| 634 | if(pCurrChar->getRace() == RACE_NIGHTELF) |
---|
| 635 | pCurrChar->CastSpell(pCurrChar, 20584, true, 0);// auras SPELL_AURA_INCREASE_SPEED(+speed in wisp form), SPELL_AURA_INCREASE_SWIM_SPEED(+swim speed in wisp form), SPELL_AURA_TRANSFORM (to wisp form) |
---|
| 636 | pCurrChar->CastSpell(pCurrChar, 8326, true, 0); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?) |
---|
| 637 | |
---|
| 638 | //pCurrChar->SetUInt32Value(UNIT_FIELD_AURA+41, 8326); |
---|
| 639 | //pCurrChar->SetUInt32Value(UNIT_FIELD_AURA+42, 20584); |
---|
| 640 | //pCurrChar->SetUInt32Value(UNIT_FIELD_AURAFLAGS+6, 238); |
---|
| 641 | //pCurrChar->SetUInt32Value(UNIT_FIELD_AURALEVELS+11, 514); |
---|
| 642 | //pCurrChar->SetUInt32Value(UNIT_FIELD_AURAAPPLICATIONS+11, 65535); |
---|
| 643 | //pCurrChar->SetUInt32Value(UNIT_FIELD_DISPLAYID, 1825); |
---|
| 644 | //if (pCurrChar->getRace() == RACE_NIGHTELF) |
---|
| 645 | //{ |
---|
| 646 | // pCurrChar->SetSpeed(MOVE_RUN, 1.5f*1.2f, true); |
---|
| 647 | // pCurrChar->SetSpeed(MOVE_SWIM, 1.5f*1.2f, true); |
---|
| 648 | //} |
---|
| 649 | //else |
---|
| 650 | //{ |
---|
| 651 | // pCurrChar->SetSpeed(MOVE_RUN, 1.5f, true); |
---|
| 652 | // pCurrChar->SetSpeed(MOVE_SWIM, 1.5f, true); |
---|
| 653 | //} |
---|
| 654 | pCurrChar->SetMovement(MOVE_WATER_WALK); |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | if(uint32 sourceNode = pCurrChar->m_taxi.GetTaxiSource()) |
---|
| 658 | { |
---|
| 659 | |
---|
| 660 | sLog.outDebug( "WORLD: Restart character %u taxi flight", pCurrChar->GetGUIDLow() ); |
---|
| 661 | |
---|
| 662 | uint32 MountId = objmgr.GetTaxiMount(sourceNode, pCurrChar->GetTeam()); |
---|
| 663 | uint32 path = pCurrChar->m_taxi.GetCurrentTaxiPath(); |
---|
| 664 | |
---|
| 665 | // search appropriate start path node |
---|
| 666 | uint32 startNode = 0; |
---|
| 667 | |
---|
| 668 | TaxiPathNodeList const& nodeList = sTaxiPathNodesByPath[path]; |
---|
| 669 | |
---|
| 670 | float distPrev = MAP_SIZE*MAP_SIZE; |
---|
| 671 | float distNext = |
---|
| 672 | (nodeList[0].x-pCurrChar->GetPositionX())*(nodeList[0].x-pCurrChar->GetPositionX())+ |
---|
| 673 | (nodeList[0].y-pCurrChar->GetPositionY())*(nodeList[0].y-pCurrChar->GetPositionY())+ |
---|
| 674 | (nodeList[0].z-pCurrChar->GetPositionZ())*(nodeList[0].z-pCurrChar->GetPositionZ()); |
---|
| 675 | |
---|
| 676 | for(uint32 i = 1; i < nodeList.size(); ++i) |
---|
| 677 | { |
---|
| 678 | TaxiPathNode const& node = nodeList[i]; |
---|
| 679 | TaxiPathNode const& prevNode = nodeList[i-1]; |
---|
| 680 | |
---|
| 681 | // skip nodes at another map |
---|
| 682 | if(node.mapid != pCurrChar->GetMapId()) |
---|
| 683 | continue; |
---|
| 684 | |
---|
| 685 | distPrev = distNext; |
---|
| 686 | |
---|
| 687 | distNext = |
---|
| 688 | (node.x-pCurrChar->GetPositionX())*(node.x-pCurrChar->GetPositionX())+ |
---|
| 689 | (node.y-pCurrChar->GetPositionY())*(node.y-pCurrChar->GetPositionY())+ |
---|
| 690 | (node.z-pCurrChar->GetPositionZ())*(node.z-pCurrChar->GetPositionZ()); |
---|
| 691 | |
---|
| 692 | float distNodes = |
---|
| 693 | (node.x-prevNode.x)*(node.x-prevNode.x)+ |
---|
| 694 | (node.y-prevNode.y)*(node.y-prevNode.y)+ |
---|
| 695 | (node.z-prevNode.z)*(node.z-prevNode.z); |
---|
| 696 | |
---|
| 697 | if(distNext + distPrev < distNodes) |
---|
| 698 | { |
---|
| 699 | startNode = i; |
---|
| 700 | break; |
---|
| 701 | } |
---|
| 702 | } |
---|
| 703 | |
---|
| 704 | SendDoFlight( MountId, path, startNode ); |
---|
| 705 | } |
---|
| 706 | |
---|
| 707 | // Load pet if any and player is alive and not in taxi flight |
---|
| 708 | if(pCurrChar->isAlive() && pCurrChar->m_taxi.GetTaxiSource()==0) |
---|
| 709 | pCurrChar->LoadPet(); |
---|
| 710 | |
---|
| 711 | // Set FFA PvP for non GM in non-rest mode |
---|
| 712 | if(sWorld.IsFFAPvPRealm() && !pCurrChar->isGameMaster() && !pCurrChar->HasFlag(PLAYER_FLAGS,PLAYER_FLAGS_RESTING) ) |
---|
| 713 | pCurrChar->SetFlag(PLAYER_FLAGS,PLAYER_FLAGS_FFA_PVP); |
---|
| 714 | |
---|
| 715 | if(pCurrChar->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP)) |
---|
| 716 | pCurrChar->SetContestedPvP(); |
---|
| 717 | |
---|
| 718 | // Apply at_login requests |
---|
| 719 | if(pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS)) |
---|
| 720 | { |
---|
| 721 | pCurrChar->resetSpells(); |
---|
| 722 | SendNotification(LANG_RESET_SPELLS); |
---|
| 723 | } |
---|
| 724 | |
---|
| 725 | if(pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS)) |
---|
| 726 | { |
---|
| 727 | pCurrChar->resetTalents(true); |
---|
| 728 | SendNotification(LANG_RESET_TALENTS); |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | // show time before shutdown if shutdown planned. |
---|
| 732 | if(sWorld.IsShutdowning()) |
---|
| 733 | sWorld.ShutdownMsg(true,pCurrChar); |
---|
| 734 | |
---|
| 735 | if(pCurrChar->isGameMaster()) |
---|
| 736 | SendNotification(LANG_GM_ON); |
---|
| 737 | |
---|
| 738 | std::string IP_str = GetRemoteAddress(); |
---|
| 739 | sLog.outChar("Account: %d (IP: %s) Login Character:[%s] (guid:%u)",GetAccountId(),IP_str.c_str(),pCurrChar->GetName() ,pCurrChar->GetGUID()); |
---|
| 740 | |
---|
| 741 | m_playerLoading = false; |
---|
| 742 | delete holder; |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | void WorldSession::HandleSetFactionAtWar( WorldPacket & recv_data ) |
---|
| 746 | { |
---|
| 747 | CHECK_PACKET_SIZE(recv_data,4+1); |
---|
| 748 | |
---|
| 749 | DEBUG_LOG( "WORLD: Received CMSG_SET_FACTION_ATWAR" ); |
---|
| 750 | |
---|
| 751 | uint32 repListID; |
---|
| 752 | uint8 flag; |
---|
| 753 | |
---|
| 754 | recv_data >> repListID; |
---|
| 755 | recv_data >> flag; |
---|
| 756 | |
---|
| 757 | FactionStateList::iterator itr = GetPlayer()->m_factions.find(repListID); |
---|
| 758 | if (itr == GetPlayer()->m_factions.end()) |
---|
| 759 | return; |
---|
| 760 | |
---|
| 761 | // always invisible or hidden faction can't change war state |
---|
| 762 | if(itr->second.Flags & (FACTION_FLAG_INVISIBLE_FORCED|FACTION_FLAG_HIDDEN) ) |
---|
| 763 | return; |
---|
| 764 | |
---|
| 765 | GetPlayer()->SetFactionAtWar(&itr->second,flag); |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | //I think this function is never used :/ I dunno, but i guess this opcode not exists |
---|
| 769 | void WorldSession::HandleSetFactionCheat( WorldPacket & /*recv_data*/ ) |
---|
| 770 | { |
---|
| 771 | //CHECK_PACKET_SIZE(recv_data,4+4); |
---|
| 772 | |
---|
| 773 | //sLog.outDebug("WORLD SESSION: HandleSetFactionCheat"); |
---|
| 774 | /* |
---|
| 775 | uint32 FactionID; |
---|
| 776 | uint32 Standing; |
---|
| 777 | |
---|
| 778 | recv_data >> FactionID; |
---|
| 779 | recv_data >> Standing; |
---|
| 780 | |
---|
| 781 | std::list<struct Factions>::iterator itr; |
---|
| 782 | |
---|
| 783 | for(itr = GetPlayer()->factions.begin(); itr != GetPlayer()->factions.end(); ++itr) |
---|
| 784 | { |
---|
| 785 | if(itr->ReputationListID == FactionID) |
---|
| 786 | { |
---|
| 787 | itr->Standing += Standing; |
---|
| 788 | itr->Flags = (itr->Flags | 1); |
---|
| 789 | break; |
---|
| 790 | } |
---|
| 791 | } |
---|
| 792 | */ |
---|
| 793 | GetPlayer()->UpdateReputation(); |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | void WorldSession::HandleMeetingStoneInfo( WorldPacket & /*recv_data*/ ) |
---|
| 797 | { |
---|
| 798 | DEBUG_LOG( "WORLD: Received CMSG_MEETING_STONE_INFO" ); |
---|
| 799 | |
---|
| 800 | WorldPacket data(SMSG_MEETINGSTONE_SETQUEUE, 5); |
---|
| 801 | data << uint32(0) << uint8(6); |
---|
| 802 | SendPacket(&data); |
---|
| 803 | } |
---|
| 804 | |
---|
| 805 | void WorldSession::HandleTutorialFlag( WorldPacket & recv_data ) |
---|
| 806 | { |
---|
| 807 | CHECK_PACKET_SIZE(recv_data,4); |
---|
| 808 | |
---|
| 809 | uint32 iFlag; |
---|
| 810 | recv_data >> iFlag; |
---|
| 811 | |
---|
| 812 | uint32 wInt = (iFlag / 32); |
---|
| 813 | if (wInt >= 8) |
---|
| 814 | { |
---|
| 815 | //sLog.outError("CHEATER? Account:[%d] Guid[%u] tried to send wrong CMSG_TUTORIAL_FLAG", GetAccountId(),GetGUID()); |
---|
| 816 | return; |
---|
| 817 | } |
---|
| 818 | uint32 rInt = (iFlag % 32); |
---|
| 819 | |
---|
| 820 | uint32 tutflag = GetPlayer()->GetTutorialInt( wInt ); |
---|
| 821 | tutflag |= (1 << rInt); |
---|
| 822 | GetPlayer()->SetTutorialInt( wInt, tutflag ); |
---|
| 823 | |
---|
| 824 | //sLog.outDebug("Received Tutorial Flag Set {%u}.", iFlag); |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | void WorldSession::HandleTutorialClear( WorldPacket & /*recv_data*/ ) |
---|
| 828 | { |
---|
| 829 | for ( uint32 iI = 0; iI < 8; iI++) |
---|
| 830 | GetPlayer()->SetTutorialInt( iI, 0xFFFFFFFF ); |
---|
| 831 | } |
---|
| 832 | |
---|
| 833 | void WorldSession::HandleTutorialReset( WorldPacket & /*recv_data*/ ) |
---|
| 834 | { |
---|
| 835 | for ( uint32 iI = 0; iI < 8; iI++) |
---|
| 836 | GetPlayer()->SetTutorialInt( iI, 0x00000000 ); |
---|
| 837 | } |
---|
| 838 | |
---|
| 839 | void WorldSession::HandleSetWatchedFactionIndexOpcode(WorldPacket & recv_data) |
---|
| 840 | { |
---|
| 841 | CHECK_PACKET_SIZE(recv_data,4); |
---|
| 842 | |
---|
| 843 | DEBUG_LOG("WORLD: Received CMSG_SET_WATCHED_FACTION"); |
---|
| 844 | uint32 fact; |
---|
| 845 | recv_data >> fact; |
---|
| 846 | GetPlayer()->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, fact); |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | void WorldSession::HandleSetWatchedFactionInactiveOpcode(WorldPacket & recv_data) |
---|
| 850 | { |
---|
| 851 | CHECK_PACKET_SIZE(recv_data,4+1); |
---|
| 852 | |
---|
| 853 | DEBUG_LOG("WORLD: Received CMSG_SET_FACTION_INACTIVE"); |
---|
| 854 | uint32 replistid; |
---|
| 855 | uint8 inactive; |
---|
| 856 | recv_data >> replistid >> inactive; |
---|
| 857 | |
---|
| 858 | FactionStateList::iterator itr = _player->m_factions.find(replistid); |
---|
| 859 | if (itr == _player->m_factions.end()) |
---|
| 860 | return; |
---|
| 861 | |
---|
| 862 | _player->SetFactionInactive(&itr->second, inactive); |
---|
| 863 | } |
---|
| 864 | |
---|
| 865 | void WorldSession::HandleToggleHelmOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 866 | { |
---|
| 867 | DEBUG_LOG("CMSG_TOGGLE_HELM for %s", _player->GetName()); |
---|
| 868 | _player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_HELM); |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | void WorldSession::HandleToggleCloakOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 872 | { |
---|
| 873 | DEBUG_LOG("CMSG_TOGGLE_CLOAK for %s", _player->GetName()); |
---|
| 874 | _player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_CLOAK); |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data) |
---|
| 878 | { |
---|
| 879 | CHECK_PACKET_SIZE(recv_data,8+1); |
---|
| 880 | |
---|
| 881 | uint64 guid; |
---|
| 882 | std::string newname; |
---|
| 883 | std::string oldname; |
---|
| 884 | |
---|
| 885 | CHECK_PACKET_SIZE(recv_data, 8+1); |
---|
| 886 | |
---|
| 887 | recv_data >> guid; |
---|
| 888 | recv_data >> newname; |
---|
| 889 | |
---|
| 890 | QueryResult *result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid)); |
---|
| 891 | if (result) |
---|
| 892 | { |
---|
| 893 | uint32 at_loginFlags; |
---|
| 894 | Field *fields = result->Fetch(); |
---|
| 895 | at_loginFlags = fields[0].GetUInt32(); |
---|
| 896 | delete result; |
---|
| 897 | |
---|
| 898 | if (!(at_loginFlags & AT_LOGIN_RENAME)) |
---|
| 899 | { |
---|
| 900 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 901 | data << (uint8)CHAR_CREATE_ERROR; |
---|
| 902 | SendPacket( &data ); |
---|
| 903 | return; |
---|
| 904 | } |
---|
| 905 | } |
---|
| 906 | else |
---|
| 907 | { |
---|
| 908 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 909 | data << (uint8)CHAR_CREATE_ERROR; |
---|
| 910 | SendPacket( &data ); |
---|
| 911 | return; |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | if(!objmgr.GetPlayerNameByGUID(guid, oldname)) // character not exist, because we have no name for this guid |
---|
| 915 | { |
---|
| 916 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 917 | data << (uint8)CHAR_LOGIN_NO_CHARACTER; |
---|
| 918 | SendPacket( &data ); |
---|
| 919 | return; |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | // prevent character rename to invalid name |
---|
| 923 | if(!normalizePlayerName(newname)) |
---|
| 924 | { |
---|
| 925 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 926 | data << (uint8)CHAR_NAME_NO_NAME; |
---|
| 927 | SendPacket( &data ); |
---|
| 928 | return; |
---|
| 929 | } |
---|
| 930 | |
---|
| 931 | if(!ObjectMgr::IsValidName(newname,true)) |
---|
| 932 | { |
---|
| 933 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 934 | data << (uint8)CHAR_NAME_INVALID_CHARACTER; |
---|
| 935 | SendPacket( &data ); |
---|
| 936 | return; |
---|
| 937 | } |
---|
| 938 | |
---|
| 939 | // check name limitations |
---|
| 940 | if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname)) |
---|
| 941 | { |
---|
| 942 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 943 | data << (uint8)CHAR_NAME_RESERVED; |
---|
| 944 | SendPacket( &data ); |
---|
| 945 | return; |
---|
| 946 | } |
---|
| 947 | |
---|
| 948 | if(objmgr.GetPlayerGUIDByName(newname)) // character with this name already exist |
---|
| 949 | { |
---|
| 950 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 951 | data << (uint8)CHAR_CREATE_ERROR; |
---|
| 952 | SendPacket( &data ); |
---|
| 953 | return; |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | if(newname == oldname) // checked by client |
---|
| 957 | { |
---|
| 958 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
| 959 | data << (uint8)CHAR_NAME_FAILURE; |
---|
| 960 | SendPacket( &data ); |
---|
| 961 | return; |
---|
| 962 | } |
---|
| 963 | |
---|
| 964 | // we have to check character at_login_flag & AT_LOGIN_RENAME also (fake packets hehe) |
---|
| 965 | |
---|
| 966 | CharacterDatabase.escape_string(newname); |
---|
| 967 | CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_RENAME),GUID_LOPART(guid)); |
---|
| 968 | CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid)); |
---|
| 969 | |
---|
| 970 | std::string IP_str = GetRemoteAddress(); |
---|
| 971 | sLog.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s",GetAccountId(),IP_str.c_str(),oldname.c_str(),GUID_LOPART(guid),newname.c_str()); |
---|
| 972 | |
---|
| 973 | WorldPacket data(SMSG_CHAR_RENAME,1+8+(newname.size()+1)); |
---|
| 974 | data << (uint8)RESPONSE_SUCCESS; |
---|
| 975 | data << guid; |
---|
| 976 | data << newname; |
---|
| 977 | SendPacket(&data); |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data) |
---|
| 981 | { |
---|
| 982 | uint64 guid; |
---|
| 983 | |
---|
| 984 | CHECK_PACKET_SIZE(recv_data, 8+6); |
---|
| 985 | recv_data >> guid; |
---|
| 986 | |
---|
| 987 | // not accept declined names for unsupported languages |
---|
| 988 | std::string name; |
---|
| 989 | if(!objmgr.GetPlayerNameByGUID(guid,name)) |
---|
| 990 | { |
---|
| 991 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
| 992 | data << (uint32)1; |
---|
| 993 | data << guid; |
---|
| 994 | SendPacket(&data); |
---|
| 995 | return; |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | std::wstring wname; |
---|
| 999 | if(!Utf8toWStr(name,wname)) |
---|
| 1000 | { |
---|
| 1001 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
| 1002 | data << (uint32)1; |
---|
| 1003 | data << guid; |
---|
| 1004 | SendPacket(&data); |
---|
| 1005 | return; |
---|
| 1006 | } |
---|
| 1007 | |
---|
| 1008 | if(!isCyrillicCharacter(wname[0])) // name already stored as only single alphabet using |
---|
| 1009 | { |
---|
| 1010 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
| 1011 | data << (uint32)1; |
---|
| 1012 | data << guid; |
---|
| 1013 | SendPacket(&data); |
---|
| 1014 | return; |
---|
| 1015 | } |
---|
| 1016 | |
---|
| 1017 | std::string name2; |
---|
| 1018 | DeclinedName declinedname; |
---|
| 1019 | |
---|
| 1020 | recv_data >> name2; |
---|
| 1021 | |
---|
| 1022 | if(name2!=name) // character have different name |
---|
| 1023 | { |
---|
| 1024 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
| 1025 | data << (uint32)1; |
---|
| 1026 | data << guid; |
---|
| 1027 | SendPacket(&data); |
---|
| 1028 | return; |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) |
---|
| 1032 | { |
---|
| 1033 | recv_data >> declinedname.name[i]; |
---|
| 1034 | if(!normalizePlayerName(declinedname.name[i])) |
---|
| 1035 | { |
---|
| 1036 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
| 1037 | data << (uint32)1; |
---|
| 1038 | data << guid; |
---|
| 1039 | SendPacket(&data); |
---|
| 1040 | return; |
---|
| 1041 | } |
---|
| 1042 | } |
---|
| 1043 | |
---|
| 1044 | if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname,0),declinedname)) |
---|
| 1045 | { |
---|
| 1046 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
| 1047 | data << (uint32)1; |
---|
| 1048 | data << guid; |
---|
| 1049 | SendPacket(&data); |
---|
| 1050 | return; |
---|
| 1051 | } |
---|
| 1052 | |
---|
| 1053 | for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) |
---|
| 1054 | CharacterDatabase.escape_string(declinedname.name[i]); |
---|
| 1055 | |
---|
| 1056 | CharacterDatabase.BeginTransaction(); |
---|
| 1057 | CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid)); |
---|
| 1058 | CharacterDatabase.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')", |
---|
| 1059 | GUID_LOPART(guid), declinedname.name[0].c_str(),declinedname.name[1].c_str(),declinedname.name[2].c_str(),declinedname.name[3].c_str(),declinedname.name[4].c_str()); |
---|
| 1060 | CharacterDatabase.CommitTransaction(); |
---|
| 1061 | |
---|
| 1062 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
| 1063 | data << (uint32)0; // OK |
---|
| 1064 | data << guid; |
---|
| 1065 | SendPacket(&data); |
---|
| 1066 | } |
---|