[6922] Whitespace and newline fixes
[getmangos.git] / src / game / CharacterHandler.cpp
blobb338c48af32e7a899422a99f1542827398302421
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
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.
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.
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
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 "ArenaTeam.h"
40 #include "Language.h"
42 class LoginQueryHolder : public SqlQueryHolder
44 private:
45 uint32 m_accountId;
46 uint64 m_guid;
47 public:
48 LoginQueryHolder(uint32 accountId, uint64 guid)
49 : m_accountId(accountId), m_guid(guid) { }
50 uint64 GetGuid() const { return m_guid; }
51 uint32 GetAccountId() const { return m_accountId; }
52 bool Initialize();
55 bool LoginQueryHolder::Initialize()
57 SetSize(MAX_PLAYER_LOGIN_QUERY);
59 bool res = true;
61 // NOTE: all fields in `characters` must be read to prevent lost character data at next save in case wrong DB structure.
62 // !!! NOTE: including unused `zone`,`online`
63 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, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty, arena_pending_points FROM characters WHERE guid = '%u'", GUID_LOPART(m_guid));
64 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADGROUP, "SELECT leaderGuid FROM group_member WHERE memberGuid ='%u'", GUID_LOPART(m_guid));
65 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));
66 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS, "SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid));
67 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS, "SELECT spell,slot,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid));
68 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));
69 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid));
70 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);
71 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid));
72 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));
73 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS, "SELECT button,action,type,misc FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid));
74 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));
75 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid));
76 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid));
77 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));
78 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS, "SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'", GUID_LOPART(m_guid));
79 if(sWorld.getConfig(CONFIG_DECLINED_NAMES_USED))
80 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES, "SELECT genitive, dative, accusative, instrumental, prepositional FROM character_declinedname WHERE guid = '%u'",GUID_LOPART(m_guid));
81 // in other case still be dummy query
82 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADGUILD, "SELECT guildid,rank FROM guild_member WHERE guid = '%u'", GUID_LOPART(m_guid));
83 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADARENAINFO, "SELECT arenateamid, played_week, played_season, personal_rating FROM arena_team_member WHERE guid='%u'", GUID_LOPART(m_guid));
84 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS, "SELECT achievement, date FROM character_achievement WHERE guid = '%u'", GUID_LOPART(m_guid));
85 res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS,"SELECT criteria, counter, date FROM character_achievement_progress WHERE guid = '%u'", GUID_LOPART(m_guid));
87 return res;
90 // don't call WorldSession directly
91 // it may get deleted before the query callbacks get executed
92 // instead pass an account id to this handler
93 class CharacterHandler
95 public:
96 void HandleCharEnumCallback(QueryResult * result, uint32 account)
98 WorldSession * session = sWorld.FindSession(account);
99 if(!session)
101 delete result;
102 return;
104 session->HandleCharEnum(result);
106 void HandlePlayerLoginCallback(QueryResult * /*dummy*/, SqlQueryHolder * holder)
108 if (!holder) return;
109 WorldSession *session = sWorld.FindSession(((LoginQueryHolder*)holder)->GetAccountId());
110 if(!session)
112 delete holder;
113 return;
115 session->HandlePlayerLogin((LoginQueryHolder*)holder);
117 } chrHandler;
119 void WorldSession::HandleCharEnum(QueryResult * result)
121 // keys can be non cleared if player open realm list and close it by 'cancel'
122 loginDatabase.PExecute("UPDATE account SET v = '0', s = '0' WHERE id = '%u'", GetAccountId());
124 WorldPacket data(SMSG_CHAR_ENUM, 100); // we guess size
126 uint8 num = 0;
128 data << num;
130 if( result )
132 Player *plr = new Player(this);
135 uint32 guidlow = (*result)[0].GetUInt32();
136 sLog.outDetail("Loading char guid %u from account %u.",guidlow,GetAccountId());
138 if(plr->MinimalLoadFromDB( result, guidlow ))
140 plr->BuildEnumData( result, &data );
141 ++num;
144 while( result->NextRow() );
146 delete plr;
147 delete result;
150 data.put<uint8>(0, num);
152 SendPacket( &data );
155 void WorldSession::HandleCharEnumOpcode( WorldPacket & /*recv_data*/ )
157 /// get all the data necessary for loading all characters (along with their pets) on the account
158 CharacterDatabase.AsyncPQuery(&chrHandler, &CharacterHandler::HandleCharEnumCallback, GetAccountId(),
159 !sWorld.getConfig(CONFIG_DECLINED_NAMES_USED) ?
160 // ------- Query Without Declined Names --------
161 // 0 1 2 3 4 5 6 7 8
162 "SELECT characters.guid, characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, "
163 // 9 10 11 12 13
164 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, guild_member.guildid "
165 "FROM characters LEFT JOIN character_pet ON characters.guid=character_pet.owner AND character_pet.slot='0' "
166 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
167 "WHERE characters.account = '%u' ORDER BY characters.guid"
169 // --------- Query With Declined Names ---------
170 // 0 1 2 3 4 5 6 7 8
171 "SELECT characters.guid, characters.data, characters.name, characters.position_x, characters.position_y, characters.position_z, characters.map, characters.totaltime, characters.leveltime, "
172 // 9 10 11 12 13 14
173 "characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, guild_member.guildid, genitive "
174 "FROM characters LEFT JOIN character_pet ON characters.guid = character_pet.owner AND character_pet.slot='0' "
175 "LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid "
176 "LEFT JOIN guild_member ON characters.guid = guild_member.guid "
177 "WHERE characters.account = '%u' ORDER BY characters.guid",
178 GetAccountId());
181 void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data )
183 CHECK_PACKET_SIZE(recv_data,1+1+1+1+1+1+1+1+1+1);
185 std::string name;
186 uint8 race_,class_;
188 recv_data >> name;
190 // recheck with known string size
191 CHECK_PACKET_SIZE(recv_data,(name.size()+1)+1+1+1+1+1+1+1+1+1);
193 recv_data >> race_;
194 recv_data >> class_;
196 WorldPacket data(SMSG_CHAR_CREATE, 1); // returned with diff.values in all cases
198 if(GetSecurity() == SEC_PLAYER)
200 if(uint32 mask = sWorld.getConfig(CONFIG_CHARACTERS_CREATING_DISABLED))
202 bool disabled = false;
204 uint32 team = Player::TeamForRace(race_);
205 switch(team)
207 case ALLIANCE: disabled = mask & (1<<0); break;
208 case HORDE: disabled = mask & (1<<1); break;
211 if(disabled)
213 data << (uint8)CHAR_CREATE_DISABLED;
214 SendPacket( &data );
215 return;
220 ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(class_);
221 ChrRacesEntry const* raceEntry = sChrRacesStore.LookupEntry(race_);
223 if( !classEntry || !raceEntry )
225 data << (uint8)CHAR_CREATE_FAILED;
226 SendPacket( &data );
227 sLog.outError("Class: %u or Race %u not found in DBC (Wrong DBC files?) or Cheater?", class_, race_);
228 return;
231 // prevent character creating Expansion race without Expansion account
232 if (raceEntry->addon > Expansion())
234 data << (uint8)CHAR_CREATE_EXPANSION;
235 sLog.outError("Expansion %u account:[%d] tried to Create character with expansion %u race (%u)",Expansion(),GetAccountId(),raceEntry->addon,race_);
236 SendPacket( &data );
237 return;
240 // prevent character creating Expansion class without Expansion account
241 if (classEntry->addon > Expansion())
243 data << (uint8)CHAR_CREATE_EXPANSION_CLASS;
244 sLog.outError("Expansion %u account:[%d] tried to Create character with expansion %u class (%u)",Expansion(),GetAccountId(),classEntry->addon,class_);
245 SendPacket( &data );
246 return;
249 // prevent character creating with invalid name
250 if(!normalizePlayerName(name))
252 data << (uint8)CHAR_NAME_INVALID_CHARACTER;
253 SendPacket( &data );
254 sLog.outError("Account:[%d] but tried to Create character with empty [name] ",GetAccountId());
255 return;
258 // check name limitations
259 if(!ObjectMgr::IsValidName(name,true))
261 data << (uint8)CHAR_NAME_INVALID_CHARACTER;
262 SendPacket( &data );
263 return;
266 if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(name))
268 data << (uint8)CHAR_NAME_RESERVED;
269 SendPacket( &data );
270 return;
273 if(objmgr.GetPlayerGUIDByName(name))
275 data << (uint8)CHAR_CREATE_NAME_IN_USE;
276 SendPacket( &data );
277 return;
280 QueryResult *resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
281 if ( resultacct )
283 Field *fields=resultacct->Fetch();
284 uint32 acctcharcount = fields[0].GetUInt32();
285 delete resultacct;
287 if (acctcharcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_ACCOUNT))
289 data << (uint8)CHAR_CREATE_ACCOUNT_LIMIT;
290 SendPacket( &data );
291 return;
295 QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(guid) FROM characters WHERE account = '%d'", GetAccountId());
296 uint8 charcount = 0;
297 if ( result )
299 Field *fields=result->Fetch();
300 charcount = fields[0].GetUInt8();
301 delete result;
303 if (charcount >= sWorld.getConfig(CONFIG_CHARACTERS_PER_REALM))
305 data << (uint8)CHAR_CREATE_SERVER_LIMIT;
306 SendPacket( &data );
307 return;
311 // speedup check for heroic class disabled case
312 uint32 heroic_free_slots = sWorld.getConfig(CONFIG_HEROIC_CHARACTERS_PER_REALM);
313 if(heroic_free_slots==0 && GetSecurity()==SEC_PLAYER && class_ == CLASS_DEATH_KNIGHT)
315 data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT;
316 SendPacket( &data );
317 return;
320 bool AllowTwoSideAccounts = !sWorld.IsPvPRealm() || sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_ACCOUNTS) || GetSecurity() > SEC_PLAYER;
321 uint32 skipCinematics = sWorld.getConfig(CONFIG_SKIP_CINEMATICS);
323 bool have_same_race = false;
324 if(!AllowTwoSideAccounts || skipCinematics == 1 || class_ == CLASS_DEATH_KNIGHT)
326 QueryResult *result2 = CharacterDatabase.PQuery("SELECT race,class FROM characters WHERE account = '%u' %s",
327 GetAccountId(), (skipCinematics == 1 || class_ == CLASS_DEATH_KNIGHT) ? "" : "LIMIT 1");
328 if(result2)
330 uint32 team_= Player::TeamForRace(race_);
332 Field* field = result2->Fetch();
333 uint8 acc_race = field[0].GetUInt32();
335 if(GetSecurity()==SEC_PLAYER && class_ == CLASS_DEATH_KNIGHT)
337 uint8 acc_class = field[1].GetUInt32();
338 if(acc_class == CLASS_DEATH_KNIGHT)
340 if(heroic_free_slots > 0)
341 --heroic_free_slots;
343 if(heroic_free_slots==0)
345 data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT;
346 SendPacket( &data );
347 return;
352 // need to check team only for first character
353 // TODO: what to if account already has characters of both races?
354 if (!AllowTwoSideAccounts)
356 uint32 acc_team=0;
357 if(acc_race > 0)
358 acc_team = Player::TeamForRace(acc_race);
360 if(acc_team != team_)
362 data << (uint8)CHAR_CREATE_PVP_TEAMS_VIOLATION;
363 SendPacket( &data );
364 delete result2;
365 return;
369 // search same race for cinematic or same class if need
370 // TODO: check if cinematic already shown? (already logged in?; cinematic field)
371 while ((skipCinematics == 1 && !have_same_race) || class_ == CLASS_DEATH_KNIGHT)
373 if(!result2->NextRow())
374 break;
376 field = result2->Fetch();
377 acc_race = field[0].GetUInt32();
379 if(!have_same_race)
380 have_same_race = race_ == acc_race;
382 if(GetSecurity()==SEC_PLAYER && class_ == CLASS_DEATH_KNIGHT)
384 uint8 acc_class = field[1].GetUInt32();
385 if(acc_class == CLASS_DEATH_KNIGHT)
387 if(heroic_free_slots > 0)
388 --heroic_free_slots;
390 if(heroic_free_slots==0)
392 data << (uint8)CHAR_CREATE_UNIQUE_CLASS_LIMIT;
393 SendPacket( &data );
394 return;
399 delete result2;
403 // extract other data required for player creating
404 uint8 gender, skin, face, hairStyle, hairColor, facialHair, outfitId;
405 recv_data >> gender >> skin >> face;
406 recv_data >> hairStyle >> hairColor >> facialHair >> outfitId;
408 Player * pNewChar = new Player(this);
409 if(!pNewChar->Create( objmgr.GenerateLowGuid(HIGHGUID_PLAYER), name, race_, class_, gender, skin, face, hairStyle, hairColor, facialHair, outfitId ))
411 // Player not create (race/class problem?)
412 delete pNewChar;
414 data << (uint8)CHAR_CREATE_ERROR;
415 SendPacket( &data );
417 return;
420 if(have_same_race && skipCinematics == 1 || skipCinematics == 2)
421 pNewChar->setCinematic(1); // not show intro
423 // Player created, save it now
424 pNewChar->SaveToDB();
425 charcount+=1;
427 loginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID);
428 loginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount, GetAccountId(), realmID);
430 delete pNewChar; // created only to call SaveToDB()
432 data << (uint8)CHAR_CREATE_SUCCESS;
433 SendPacket( &data );
435 std::string IP_str = GetRemoteAddress();
436 sLog.outBasic("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str());
437 sLog.outChar("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str());
440 void WorldSession::HandleCharDeleteOpcode( WorldPacket & recv_data )
442 CHECK_PACKET_SIZE(recv_data,8);
444 uint64 guid;
445 recv_data >> guid;
447 // can't delete loaded character
448 if(objmgr.GetPlayer(guid))
449 return;
451 uint32 accountId = 0;
452 std::string name;
454 // is guild leader
455 if(objmgr.GetGuildByLeader(guid))
457 WorldPacket data(SMSG_CHAR_DELETE, 1);
458 data << (uint8)CHAR_DELETE_FAILED_GUILD_LEADER;
459 SendPacket( &data );
460 return;
463 // is arena team captain
464 if(objmgr.GetArenaTeamByCaptain(guid))
466 WorldPacket data(SMSG_CHAR_DELETE, 1);
467 data << (uint8)CHAR_DELETE_FAILED_ARENA_CAPTAIN;
468 SendPacket( &data );
469 return;
472 QueryResult *result = CharacterDatabase.PQuery("SELECT account,name FROM characters WHERE guid='%u'", GUID_LOPART(guid));
473 if(result)
475 Field *fields = result->Fetch();
476 accountId = fields[0].GetUInt32();
477 name = fields[1].GetCppString();
478 delete result;
481 // prevent deleting other players' characters using cheating tools
482 if(accountId != GetAccountId())
483 return;
485 std::string IP_str = GetRemoteAddress();
486 sLog.outBasic("Account: %d (IP: %s) Delete Character:[%s] (guid:%u)",GetAccountId(),IP_str.c_str(),name.c_str(),GUID_LOPART(guid));
487 sLog.outChar("Account: %d (IP: %s) Delete Character:[%s] (guid: %u)",GetAccountId(),IP_str.c_str(),name.c_str(),GUID_LOPART(guid));
489 if(sLog.IsOutCharDump()) // optimize GetPlayerDump call
491 std::string dump = PlayerDumpWriter().GetDump(GUID_LOPART(guid));
492 sLog.outCharDump(dump.c_str(),GetAccountId(),GUID_LOPART(guid),name.c_str());
495 Player::DeleteFromDB(guid, GetAccountId());
497 WorldPacket data(SMSG_CHAR_DELETE, 1);
498 data << (uint8)CHAR_DELETE_SUCCESS;
499 SendPacket( &data );
502 void WorldSession::HandlePlayerLoginOpcode( WorldPacket & recv_data )
504 CHECK_PACKET_SIZE(recv_data,8);
506 if(PlayerLoading() || GetPlayer() != NULL)
508 sLog.outError("Player tryes to login again, AccountId = %d",GetAccountId());
509 return;
512 m_playerLoading = true;
513 uint64 playerGuid = 0;
515 DEBUG_LOG( "WORLD: Recvd Player Logon Message" );
517 recv_data >> playerGuid;
519 LoginQueryHolder *holder = new LoginQueryHolder(GetAccountId(), playerGuid);
520 if(!holder->Initialize())
522 delete holder; // delete all unprocessed queries
523 m_playerLoading = false;
524 return;
527 CharacterDatabase.DelayQueryHolder(&chrHandler, &CharacterHandler::HandlePlayerLoginCallback, holder);
530 void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder)
532 uint64 playerGuid = holder->GetGuid();
534 Player* pCurrChar = new Player(this);
535 pCurrChar->GetMotionMaster()->Initialize();
537 // "GetAccountId()==db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools)
538 if(!pCurrChar->LoadFromDB(GUID_LOPART(playerGuid), holder))
540 KickPlayer(); // disconnect client, player no set to session and it will not deleted or saved at kick
541 delete pCurrChar; // delete it manually
542 delete holder; // delete all unprocessed queries
543 m_playerLoading = false;
544 return;
547 SetPlayer(pCurrChar);
549 pCurrChar->SendDungeonDifficulty(false);
551 WorldPacket data( SMSG_LOGIN_VERIFY_WORLD, 20 );
552 data << pCurrChar->GetMapId();
553 data << pCurrChar->GetPositionX();
554 data << pCurrChar->GetPositionY();
555 data << pCurrChar->GetPositionZ();
556 data << pCurrChar->GetOrientation();
557 SendPacket(&data);
559 data.Initialize( SMSG_ACCOUNT_DATA_TIMES, 4+1+8*4 ); // changed in WotLK
560 data << uint32(time(NULL)); // unix time of something
561 data << uint8(1);
562 for(int i = 0; i < NUM_ACCOUNT_DATA_TYPES; i++)
563 data << uint32(GetAccountData(i)->Time); // also unix time
564 SendPacket(&data);
566 data.Initialize(SMSG_FEATURE_SYSTEM_STATUS, 2); // added in 2.2.0
567 data << uint8(2); // unknown value
568 data << uint8(0); // enable(1)/disable(0) voice chat interface in client
569 SendPacket(&data);
571 // Send MOTD
573 data.Initialize(SMSG_MOTD, 50); // new in 2.0.1
574 data << (uint32)0;
576 uint32 linecount=0;
577 std::string str_motd = sWorld.GetMotd();
578 std::string::size_type pos, nextpos;
580 pos = 0;
581 while ( (nextpos= str_motd.find('@',pos)) != std::string::npos )
583 if (nextpos != pos)
585 data << str_motd.substr(pos,nextpos-pos);
586 ++linecount;
588 pos = nextpos+1;
591 if (pos<str_motd.length())
593 data << str_motd.substr(pos);
594 ++linecount;
597 data.put(0, linecount);
599 SendPacket( &data );
600 DEBUG_LOG( "WORLD: Sent motd (SMSG_MOTD)" );
603 //QueryResult *result = CharacterDatabase.PQuery("SELECT guildid,rank FROM guild_member WHERE guid = '%u'",pCurrChar->GetGUIDLow());
604 QueryResult *resultGuild = holder->GetResult(PLAYER_LOGIN_QUERY_LOADGUILD);
606 if(resultGuild)
608 Field *fields = resultGuild->Fetch();
609 pCurrChar->SetInGuild(fields[0].GetUInt32());
610 pCurrChar->SetRank(fields[1].GetUInt32());
611 delete resultGuild;
613 else if(pCurrChar->GetGuildId()) // clear guild related fields in case wrong data about non existed membership
615 pCurrChar->SetInGuild(0);
616 pCurrChar->SetRank(0);
619 if(pCurrChar->GetGuildId() != 0)
621 Guild* guild = objmgr.GetGuildById(pCurrChar->GetGuildId());
622 if(guild)
624 data.Initialize(SMSG_GUILD_EVENT, (2+guild->GetMOTD().size()+1));
625 data << (uint8)GE_MOTD;
626 data << (uint8)1;
627 data << guild->GetMOTD();
628 SendPacket(&data);
629 DEBUG_LOG( "WORLD: Sent guild-motd (SMSG_GUILD_EVENT)" );
631 data.Initialize(SMSG_GUILD_EVENT, (5+10)); // we guess size
632 data<<(uint8)GE_SIGNED_ON;
633 data<<(uint8)1;
634 data<<pCurrChar->GetName();
635 data<<pCurrChar->GetGUID();
636 guild->BroadcastPacket(&data);
637 DEBUG_LOG( "WORLD: Sent guild-signed-on (SMSG_GUILD_EVENT)" );
639 // Increment online members of the guild
640 guild->IncOnlineMemberCount();
642 else
644 // remove wrong guild data
645 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());
646 pCurrChar->SetInGuild(0);
650 if(!pCurrChar->isAlive())
651 pCurrChar->SendCorpseReclaimDelay(true);
653 pCurrChar->SendInitialPacketsBeforeAddToMap();
655 //Show cinematic at the first time that player login
656 if( !pCurrChar->getCinematic() )
658 pCurrChar->setCinematic(1);
660 if(ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(pCurrChar->getClass()))
662 if(cEntry->CinematicSequence)
664 data.Initialize(SMSG_TRIGGER_CINEMATIC, 4);
665 data << uint32(cEntry->CinematicSequence);
666 SendPacket( &data );
668 else if(ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(pCurrChar->getRace()))
670 data.Initialize(SMSG_TRIGGER_CINEMATIC, 4);
671 data << uint32(rEntry->CinematicSequence);
672 SendPacket( &data );
677 if (!pCurrChar->GetMap()->Add(pCurrChar))
679 AreaTrigger const* at = objmgr.GetGoBackTrigger(pCurrChar->GetMapId());
680 if(at)
681 pCurrChar->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, pCurrChar->GetOrientation());
682 else
683 pCurrChar->TeleportTo(pCurrChar->m_homebindMapId, pCurrChar->m_homebindX, pCurrChar->m_homebindY, pCurrChar->m_homebindZ, pCurrChar->GetOrientation());
686 ObjectAccessor::Instance().AddObject(pCurrChar);
687 //sLog.outDebug("Player %s added to Map.",pCurrChar->GetName());
688 pCurrChar->GetSocial()->SendSocialList();
690 pCurrChar->SendInitialPacketsAfterAddToMap();
692 CharacterDatabase.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar->GetGUIDLow());
693 loginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId());
694 pCurrChar->SetInGameTime( getMSTime() );
696 // announce group about member online (must be after add to player list to receive announce to self)
697 if(Group *group = pCurrChar->GetGroup())
699 //pCurrChar->groupInfo.group->SendInit(this); // useless
700 group->SendUpdate();
703 // friend status
704 sSocialMgr.SendFriendStatus(pCurrChar, FRIEND_ONLINE, pCurrChar->GetGUIDLow(), true);
706 // Place character in world (and load zone) before some object loading
707 pCurrChar->LoadCorpse();
709 // setting Ghost+speed if dead
710 if (pCurrChar->m_deathState != ALIVE)
712 // not blizz like, we must correctly save and load player instead...
713 if(pCurrChar->getRace() == RACE_NIGHTELF)
714 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)
715 pCurrChar->CastSpell(pCurrChar, 8326, true, 0); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)
717 pCurrChar->SetMovement(MOVE_WATER_WALK);
720 if(uint32 sourceNode = pCurrChar->m_taxi.GetTaxiSource())
723 sLog.outDebug( "WORLD: Restart character %u taxi flight", pCurrChar->GetGUIDLow() );
725 uint32 MountId = objmgr.GetTaxiMount(sourceNode, pCurrChar->GetTeam());
726 uint32 path = pCurrChar->m_taxi.GetCurrentTaxiPath();
728 // search appropriate start path node
729 uint32 startNode = 0;
731 TaxiPathNodeList const& nodeList = sTaxiPathNodesByPath[path];
733 float distPrev = MAP_SIZE*MAP_SIZE;
734 float distNext =
735 (nodeList[0].x-pCurrChar->GetPositionX())*(nodeList[0].x-pCurrChar->GetPositionX())+
736 (nodeList[0].y-pCurrChar->GetPositionY())*(nodeList[0].y-pCurrChar->GetPositionY())+
737 (nodeList[0].z-pCurrChar->GetPositionZ())*(nodeList[0].z-pCurrChar->GetPositionZ());
739 for(uint32 i = 1; i < nodeList.size(); ++i)
741 TaxiPathNode const& node = nodeList[i];
742 TaxiPathNode const& prevNode = nodeList[i-1];
744 // skip nodes at another map
745 if(node.mapid != pCurrChar->GetMapId())
746 continue;
748 distPrev = distNext;
750 distNext =
751 (node.x-pCurrChar->GetPositionX())*(node.x-pCurrChar->GetPositionX())+
752 (node.y-pCurrChar->GetPositionY())*(node.y-pCurrChar->GetPositionY())+
753 (node.z-pCurrChar->GetPositionZ())*(node.z-pCurrChar->GetPositionZ());
755 float distNodes =
756 (node.x-prevNode.x)*(node.x-prevNode.x)+
757 (node.y-prevNode.y)*(node.y-prevNode.y)+
758 (node.z-prevNode.z)*(node.z-prevNode.z);
760 if(distNext + distPrev < distNodes)
762 startNode = i;
763 break;
767 SendDoFlight( MountId, path, startNode );
770 // Load pet if any and player is alive and not in taxi flight
771 if(pCurrChar->isAlive() && pCurrChar->m_taxi.GetTaxiSource()==0)
772 pCurrChar->LoadPet();
774 // Set FFA PvP for non GM in non-rest mode
775 if(sWorld.IsFFAPvPRealm() && !pCurrChar->isGameMaster() && !pCurrChar->HasFlag(PLAYER_FLAGS,PLAYER_FLAGS_RESTING) )
776 pCurrChar->SetFlag(PLAYER_FLAGS,PLAYER_FLAGS_FFA_PVP);
778 if(pCurrChar->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP))
779 pCurrChar->SetContestedPvP();
781 // Apply at_login requests
782 if(pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS))
784 pCurrChar->resetSpells();
785 SendNotification(LANG_RESET_SPELLS);
788 if(pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS))
790 pCurrChar->resetTalents(true);
791 SendNotification(LANG_RESET_TALENTS);
794 // show time before shutdown if shutdown planned.
795 if(sWorld.IsShutdowning())
796 sWorld.ShutdownMsg(true,pCurrChar);
798 if(sWorld.getConfig(CONFIG_ALL_TAXI_PATHS))
799 pCurrChar->SetTaxiCheater(true);
801 if(pCurrChar->isGameMaster())
802 SendNotification(LANG_GM_ON);
804 std::string IP_str = GetRemoteAddress();
805 sLog.outChar("Account: %d (IP: %s) Login Character:[%s] (guid:%u)",
806 GetAccountId(),IP_str.c_str(),pCurrChar->GetName() ,pCurrChar->GetGUIDLow());
808 m_playerLoading = false;
809 delete holder;
812 void WorldSession::HandleSetFactionAtWar( WorldPacket & recv_data )
814 CHECK_PACKET_SIZE(recv_data,4+1);
816 DEBUG_LOG( "WORLD: Received CMSG_SET_FACTION_ATWAR" );
818 uint32 repListID;
819 uint8 flag;
821 recv_data >> repListID;
822 recv_data >> flag;
824 FactionStateList::iterator itr = GetPlayer()->m_factions.find(repListID);
825 if (itr == GetPlayer()->m_factions.end())
826 return;
828 // always invisible or hidden faction can't change war state
829 if(itr->second.Flags & (FACTION_FLAG_INVISIBLE_FORCED|FACTION_FLAG_HIDDEN) )
830 return;
832 GetPlayer()->SetFactionAtWar(&itr->second,flag);
835 //I think this function is never used :/ I dunno, but i guess this opcode not exists
836 void WorldSession::HandleSetFactionCheat( WorldPacket & /*recv_data*/ )
838 //CHECK_PACKET_SIZE(recv_data,4+4);
840 //sLog.outDebug("WORLD SESSION: HandleSetFactionCheat");
842 uint32 FactionID;
843 uint32 Standing;
845 recv_data >> FactionID;
846 recv_data >> Standing;
848 std::list<struct Factions>::iterator itr;
850 for(itr = GetPlayer()->factions.begin(); itr != GetPlayer()->factions.end(); ++itr)
852 if(itr->ReputationListID == FactionID)
854 itr->Standing += Standing;
855 itr->Flags = (itr->Flags | 1);
856 break;
860 GetPlayer()->UpdateReputation();
863 void WorldSession::HandleMeetingStoneInfo( WorldPacket & /*recv_data*/ )
865 DEBUG_LOG( "WORLD: Received CMSG_MEETING_STONE_INFO" );
867 WorldPacket data(SMSG_MEETINGSTONE_SETQUEUE, 5);
868 data << uint32(0) << uint8(6);
869 SendPacket(&data);
872 void WorldSession::HandleTutorialFlag( WorldPacket & recv_data )
874 CHECK_PACKET_SIZE(recv_data,4);
876 uint32 iFlag;
877 recv_data >> iFlag;
879 uint32 wInt = (iFlag / 32);
880 if (wInt >= 8)
882 //sLog.outError("CHEATER? Account:[%d] Guid[%u] tried to send wrong CMSG_TUTORIAL_FLAG", GetAccountId(),GetGUID());
883 return;
885 uint32 rInt = (iFlag % 32);
887 uint32 tutflag = GetPlayer()->GetTutorialInt( wInt );
888 tutflag |= (1 << rInt);
889 GetPlayer()->SetTutorialInt( wInt, tutflag );
891 //sLog.outDebug("Received Tutorial Flag Set {%u}.", iFlag);
894 void WorldSession::HandleTutorialClear( WorldPacket & /*recv_data*/ )
896 for ( uint32 iI = 0; iI < 8; iI++)
897 GetPlayer()->SetTutorialInt( iI, 0xFFFFFFFF );
900 void WorldSession::HandleTutorialReset( WorldPacket & /*recv_data*/ )
902 for ( uint32 iI = 0; iI < 8; iI++)
903 GetPlayer()->SetTutorialInt( iI, 0x00000000 );
906 void WorldSession::HandleSetWatchedFactionIndexOpcode(WorldPacket & recv_data)
908 CHECK_PACKET_SIZE(recv_data,4);
910 DEBUG_LOG("WORLD: Received CMSG_SET_WATCHED_FACTION");
911 uint32 fact;
912 recv_data >> fact;
913 GetPlayer()->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, fact);
916 void WorldSession::HandleSetWatchedFactionInactiveOpcode(WorldPacket & recv_data)
918 CHECK_PACKET_SIZE(recv_data,4+1);
920 DEBUG_LOG("WORLD: Received CMSG_SET_FACTION_INACTIVE");
921 uint32 replistid;
922 uint8 inactive;
923 recv_data >> replistid >> inactive;
925 FactionStateList::iterator itr = _player->m_factions.find(replistid);
926 if (itr == _player->m_factions.end())
927 return;
929 _player->SetFactionInactive(&itr->second, inactive);
932 void WorldSession::HandleToggleHelmOpcode( WorldPacket & /*recv_data*/ )
934 DEBUG_LOG("CMSG_TOGGLE_HELM for %s", _player->GetName());
935 _player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_HELM);
938 void WorldSession::HandleToggleCloakOpcode( WorldPacket & /*recv_data*/ )
940 DEBUG_LOG("CMSG_TOGGLE_CLOAK for %s", _player->GetName());
941 _player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_CLOAK);
944 void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data)
946 CHECK_PACKET_SIZE(recv_data, 8+1);
948 uint64 guid;
949 std::string newname;
951 recv_data >> guid;
952 recv_data >> newname;
954 // prevent character rename to invalid name
955 if(!normalizePlayerName(newname))
957 WorldPacket data(SMSG_CHAR_RENAME, 1);
958 data << uint8(CHAR_NAME_NO_NAME);
959 SendPacket( &data );
960 return;
963 if(!ObjectMgr::IsValidName(newname, true))
965 WorldPacket data(SMSG_CHAR_RENAME, 1);
966 data << uint8(CHAR_NAME_INVALID_CHARACTER);
967 SendPacket( &data );
968 return;
971 // check name limitations
972 if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname))
974 WorldPacket data(SMSG_CHAR_RENAME, 1);
975 data << uint8(CHAR_NAME_RESERVED);
976 SendPacket( &data );
977 return;
980 std::string escaped_newname = newname;
981 CharacterDatabase.escape_string(escaped_newname);
983 // make sure that the character belongs to the current account, that rename at login is enabled
984 // and that there is no character with the desired new name
985 CharacterDatabase.AsyncPQuery(&WorldSession::HandleChangePlayerNameOpcodeCallBack,
986 GetAccountId(), newname,
987 "SELECT guid, name FROM characters WHERE guid = %d AND account = %d AND (at_login & %d) = %d AND NOT EXISTS (SELECT NULL FROM characters WHERE name = '%s')",
988 GUID_LOPART(guid), GetAccountId(), AT_LOGIN_RENAME, AT_LOGIN_RENAME, escaped_newname.c_str()
992 void WorldSession::HandleChangePlayerNameOpcodeCallBack(QueryResult *result, uint32 accountId, std::string newname)
994 WorldSession * session = sWorld.FindSession(accountId);
995 if(!session)
997 if(result) delete result;
998 return;
1001 if (!result)
1003 WorldPacket data(SMSG_CHAR_RENAME, 1);
1004 data << uint8(CHAR_CREATE_ERROR);
1005 session->SendPacket( &data );
1006 return;
1009 uint32 guidLow = result->Fetch()[0].GetUInt32();
1010 uint64 guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
1011 std::string oldname = result->Fetch()[1].GetCppString();
1013 delete result;
1015 CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_RENAME), guidLow);
1016 CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", guidLow);
1018 sLog.outChar("Account: %d (IP: %s) Character:[%s] (guid:%u) Changed name to: %s", session->GetAccountId(), session->GetRemoteAddress().c_str(), oldname.c_str(), guidLow, newname.c_str());
1020 WorldPacket data(SMSG_CHAR_RENAME, 1+8+(newname.size()+1));
1021 data << uint8(RESPONSE_SUCCESS);
1022 data << uint64(guid);
1023 data << newname;
1024 session->SendPacket(&data);
1027 void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data)
1029 uint64 guid;
1031 CHECK_PACKET_SIZE(recv_data, 8);
1032 recv_data >> guid;
1034 // not accept declined names for unsupported languages
1035 std::string name;
1036 if(!objmgr.GetPlayerNameByGUID(guid, name))
1038 WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
1039 data << uint32(1);
1040 data << uint64(guid);
1041 SendPacket(&data);
1042 return;
1045 std::wstring wname;
1046 if(!Utf8toWStr(name, wname))
1048 WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
1049 data << uint32(1);
1050 data << uint64(guid);
1051 SendPacket(&data);
1052 return;
1055 if(!isCyrillicCharacter(wname[0])) // name already stored as only single alphabet using
1057 WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
1058 data << uint32(1);
1059 data << uint64(guid);
1060 SendPacket(&data);
1061 return;
1064 std::string name2;
1065 DeclinedName declinedname;
1067 CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1);
1068 recv_data >> name2;
1070 if(name2 != name) // character have different name
1072 WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
1073 data << uint32(1);
1074 data << uint64(guid);
1075 SendPacket(&data);
1076 return;
1079 for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
1081 CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1);
1082 recv_data >> declinedname.name[i];
1083 if(!normalizePlayerName(declinedname.name[i]))
1085 WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
1086 data << uint32(1);
1087 data << uint64(guid);
1088 SendPacket(&data);
1089 return;
1093 if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname, 0), declinedname))
1095 WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
1096 data << uint32(1);
1097 data << uint64(guid);
1098 SendPacket(&data);
1099 return;
1102 for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
1103 CharacterDatabase.escape_string(declinedname.name[i]);
1105 CharacterDatabase.BeginTransaction();
1106 CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid));
1107 CharacterDatabase.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')",
1108 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());
1109 CharacterDatabase.CommitTransaction();
1111 WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8);
1112 data << uint32(0); // OK
1113 data << uint64(guid);
1114 SendPacket(&data);
1117 void WorldSession::HandleAlterAppearance( WorldPacket & recv_data )
1119 sLog.outDebug("CMSG_ALTER_APPEARANCE");
1121 CHECK_PACKET_SIZE(recv_data, 4+4+4);
1123 uint32 Hair, Color, FacialHair;
1124 recv_data >> Hair >> Color >> FacialHair;
1126 BarberShopStyleEntry const* bs_hair = sBarberShopStyleStore.LookupEntry(Hair);
1128 if(!bs_hair || bs_hair->type != 0 || bs_hair->race != _player->getRace() || bs_hair->gender != _player->getGender())
1129 return;
1131 BarberShopStyleEntry const* bs_facialHair = sBarberShopStyleStore.LookupEntry(FacialHair);
1133 if(!bs_facialHair || bs_facialHair->type != 2 || bs_facialHair->race != _player->getRace() || bs_facialHair->gender != _player->getGender())
1134 return;
1136 uint32 Cost = _player->GetBarberShopCost(bs_hair->hair_id, Color, bs_facialHair->hair_id);
1138 // 0 - ok
1139 // 1,3 - not enough money
1140 // 2 - you have to seat on barber chair
1141 if(_player->GetMoney() < Cost)
1143 WorldPacket data(SMSG_BARBER_SHOP_RESULT, 4);
1144 data << uint32(1); // no money
1145 SendPacket(&data);
1146 return;
1148 else
1150 WorldPacket data(SMSG_BARBER_SHOP_RESULT, 4);
1151 data << uint32(0); // ok
1152 SendPacket(&data);
1155 _player->SetMoney(_player->GetMoney() - Cost); // it isn't free
1157 _player->SetByteValue(PLAYER_BYTES, 2, uint8(bs_hair->hair_id));
1158 _player->SetByteValue(PLAYER_BYTES, 3, uint8(Color));
1159 _player->SetByteValue(PLAYER_BYTES_2, 0, uint8(bs_facialHair->hair_id));
1161 _player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_VISIT_BARBER_SHOP, 1);
1163 _player->SetStandState(0); // stand up
1166 void WorldSession::HandleRemoveGlyph( WorldPacket & recv_data )
1168 CHECK_PACKET_SIZE(recv_data, 4);
1170 uint32 slot;
1171 recv_data >> slot;
1173 if(slot > 5)
1175 sLog.outDebug("Client sent wrong glyph slot number in opcode CMSG_REMOVE_GLYPH %u", slot);
1176 return;
1179 if(uint32 glyph = _player->GetGlyph(slot))
1181 if(GlyphPropertiesEntry const *gp = sGlyphPropertiesStore.LookupEntry(glyph))
1183 _player->RemoveAurasDueToSpell(gp->SpellId);
1184 _player->SetGlyph(slot, 0);
1189 void WorldSession::HandleCharCustomize(WorldPacket& recv_data)
1191 CHECK_PACKET_SIZE(recv_data, 8+1);
1193 uint64 guid;
1194 std::string newname;
1196 recv_data >> guid;
1197 recv_data >> newname;
1199 CHECK_PACKET_SIZE(recv_data, recv_data.rpos()+1+1+1+1+1+1);
1201 uint8 gender, skin, face, hairStyle, hairColor, facialHair;
1202 recv_data >> gender >> skin >> face >> hairStyle >> hairColor >> facialHair;
1204 QueryResult *result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid));
1205 if (!result)
1207 WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
1208 data << uint8(CHAR_CREATE_ERROR);
1209 SendPacket( &data );
1210 return;
1213 Field *fields = result->Fetch();
1214 uint32 at_loginFlags = fields[0].GetUInt32();
1215 delete result;
1217 if (!(at_loginFlags & AT_LOGIN_CUSTOMIZE))
1219 WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
1220 data << uint8(CHAR_CREATE_ERROR);
1221 SendPacket( &data );
1222 return;
1225 // prevent character rename to invalid name
1226 if(!normalizePlayerName(newname))
1228 WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
1229 data << uint8(CHAR_NAME_NO_NAME);
1230 SendPacket( &data );
1231 return;
1234 if(!ObjectMgr::IsValidName(newname,true))
1236 WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
1237 data << uint8(CHAR_NAME_INVALID_CHARACTER);
1238 SendPacket( &data );
1239 return;
1242 // check name limitations
1243 if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname))
1245 WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
1246 data << uint8(CHAR_NAME_RESERVED);
1247 SendPacket( &data );
1248 return;
1251 if(objmgr.GetPlayerGUIDByName(newname)) // character with this name already exist
1253 WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1);
1254 data << uint8(CHAR_CREATE_NAME_IN_USE);
1255 SendPacket( &data );
1256 return;
1259 CharacterDatabase.escape_string(newname);
1260 Player::Customize(guid, gender, skin, face, hairStyle, hairColor, facialHair);
1261 CharacterDatabase.PExecute("UPDATE characters set name = '%s', at_login = at_login & ~ %u WHERE guid ='%u'", newname.c_str(), uint32(AT_LOGIN_CUSTOMIZE), GUID_LOPART(guid));
1262 CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid));
1264 std::string IP_str = GetRemoteAddress();
1265 sLog.outChar("Account: %d (IP: %s), Character guid: %u Customized to: %s", GetAccountId(), IP_str.c_str(), GUID_LOPART(guid), newname.c_str());
1267 WorldPacket data(SMSG_CHAR_CUSTOMIZE, 1+8+(newname.size()+1)+6);
1268 data << uint8(RESPONSE_SUCCESS);
1269 data << uint64(guid);
1270 data << newname;
1271 data << uint8(gender);
1272 data << uint8(skin);
1273 data << uint8(face);
1274 data << uint8(hairStyle);
1275 data << uint8(hairColor);
1276 data << uint8(facialHair);
1277 SendPacket(&data);