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(sWorld.getConfig(CONFIG_ALWAYS_MAXSKILL)) // Max weapon skill when logging in |
---|
736 | pCurrChar->UpdateSkillsToMaxSkillsForLevel(); |
---|
737 | |
---|
738 | //ImpConfig - Check if player has logged in before |
---|
739 | QueryResult *result = CharacterDatabase.PQuery("SELECT guid FROM has_logged_in_before WHERE guid = %u",pCurrChar->GetGUIDLow()); |
---|
740 | if(!result) |
---|
741 | { |
---|
742 | sLog.outBasic("Character '%s' logging in for first time, applying skills and stuff",pCurrChar->GetName()); |
---|
743 | CharacterDatabase.PExecute("INSERT INTO has_logged_in_before VALUES (%u)",pCurrChar->GetGUIDLow()); |
---|
744 | |
---|
745 | //Reputations if "StartAllReputation" is enabled, -- TODO: Fix this in a better way |
---|
746 | if(sWorld.getConfig(CONFIG_START_ALL_REP)) |
---|
747 | { |
---|
748 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(942),42999); |
---|
749 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(935),42999); |
---|
750 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(936),42999); |
---|
751 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(1011),42999); |
---|
752 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(970),42999); |
---|
753 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(967),42999); |
---|
754 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(989),42999); |
---|
755 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(932),42999); |
---|
756 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(934),42999); |
---|
757 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(1038),42999); |
---|
758 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(1077),42999); |
---|
759 | |
---|
760 | // Factions depending on team, like cities and some more stuff |
---|
761 | switch(pCurrChar->GetTeam()) |
---|
762 | { |
---|
763 | case ALLIANCE: |
---|
764 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(72),42999); |
---|
765 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(47),42999); |
---|
766 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(69),42999); |
---|
767 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(930),42999); |
---|
768 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(730),42999); |
---|
769 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(978),42999); |
---|
770 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(54),42999); |
---|
771 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(946),42999); |
---|
772 | break; |
---|
773 | case HORDE: |
---|
774 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(76),42999); |
---|
775 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(68),42999); |
---|
776 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(81),42999); |
---|
777 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(911),42999); |
---|
778 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(729),42999); |
---|
779 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(941),42999); |
---|
780 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(530),42999); |
---|
781 | pCurrChar->SetFactionReputation(sFactionStore.LookupEntry(947),42999); |
---|
782 | break; |
---|
783 | } |
---|
784 | } |
---|
785 | } |
---|
786 | else |
---|
787 | sLog.outBasic("Character '%s' has logged in before",pCurrChar->GetName()); |
---|
788 | |
---|
789 | if(sWorld.getConfig(CONFIG_START_ALL_TAXI)) |
---|
790 | pCurrChar->SetTaxiCheater(true); |
---|
791 | |
---|
792 | |
---|
793 | if(pCurrChar->isGameMaster()) |
---|
794 | SendNotification(LANG_GM_ON); |
---|
795 | |
---|
796 | std::string IP_str = GetRemoteAddress(); |
---|
797 | sLog.outChar("Account: %d (IP: %s) Login Character:[%s] (guid:%u)",GetAccountId(),IP_str.c_str(),pCurrChar->GetName() ,pCurrChar->GetGUID()); |
---|
798 | |
---|
799 | m_playerLoading = false; |
---|
800 | delete holder; |
---|
801 | } |
---|
802 | |
---|
803 | void WorldSession::HandleSetFactionAtWar( WorldPacket & recv_data ) |
---|
804 | { |
---|
805 | CHECK_PACKET_SIZE(recv_data,4+1); |
---|
806 | |
---|
807 | DEBUG_LOG( "WORLD: Received CMSG_SET_FACTION_ATWAR" ); |
---|
808 | |
---|
809 | uint32 repListID; |
---|
810 | uint8 flag; |
---|
811 | |
---|
812 | recv_data >> repListID; |
---|
813 | recv_data >> flag; |
---|
814 | |
---|
815 | FactionStateList::iterator itr = GetPlayer()->m_factions.find(repListID); |
---|
816 | if (itr == GetPlayer()->m_factions.end()) |
---|
817 | return; |
---|
818 | |
---|
819 | // always invisible or hidden faction can't change war state |
---|
820 | if(itr->second.Flags & (FACTION_FLAG_INVISIBLE_FORCED|FACTION_FLAG_HIDDEN) ) |
---|
821 | return; |
---|
822 | |
---|
823 | GetPlayer()->SetFactionAtWar(&itr->second,flag); |
---|
824 | } |
---|
825 | |
---|
826 | //I think this function is never used :/ I dunno, but i guess this opcode not exists |
---|
827 | void WorldSession::HandleSetFactionCheat( WorldPacket & /*recv_data*/ ) |
---|
828 | { |
---|
829 | //CHECK_PACKET_SIZE(recv_data,4+4); |
---|
830 | |
---|
831 | //sLog.outDebug("WORLD SESSION: HandleSetFactionCheat"); |
---|
832 | /* |
---|
833 | uint32 FactionID; |
---|
834 | uint32 Standing; |
---|
835 | |
---|
836 | recv_data >> FactionID; |
---|
837 | recv_data >> Standing; |
---|
838 | |
---|
839 | std::list<struct Factions>::iterator itr; |
---|
840 | |
---|
841 | for(itr = GetPlayer()->factions.begin(); itr != GetPlayer()->factions.end(); ++itr) |
---|
842 | { |
---|
843 | if(itr->ReputationListID == FactionID) |
---|
844 | { |
---|
845 | itr->Standing += Standing; |
---|
846 | itr->Flags = (itr->Flags | 1); |
---|
847 | break; |
---|
848 | } |
---|
849 | } |
---|
850 | */ |
---|
851 | GetPlayer()->UpdateReputation(); |
---|
852 | } |
---|
853 | |
---|
854 | void WorldSession::HandleMeetingStoneInfo( WorldPacket & /*recv_data*/ ) |
---|
855 | { |
---|
856 | DEBUG_LOG( "WORLD: Received CMSG_MEETING_STONE_INFO" ); |
---|
857 | |
---|
858 | WorldPacket data(SMSG_MEETINGSTONE_SETQUEUE, 5); |
---|
859 | data << uint32(0) << uint8(6); |
---|
860 | SendPacket(&data); |
---|
861 | } |
---|
862 | |
---|
863 | void WorldSession::HandleTutorialFlag( WorldPacket & recv_data ) |
---|
864 | { |
---|
865 | CHECK_PACKET_SIZE(recv_data,4); |
---|
866 | |
---|
867 | uint32 iFlag; |
---|
868 | recv_data >> iFlag; |
---|
869 | |
---|
870 | uint32 wInt = (iFlag / 32); |
---|
871 | if (wInt >= 8) |
---|
872 | { |
---|
873 | //sLog.outError("CHEATER? Account:[%d] Guid[%u] tried to send wrong CMSG_TUTORIAL_FLAG", GetAccountId(),GetGUID()); |
---|
874 | return; |
---|
875 | } |
---|
876 | uint32 rInt = (iFlag % 32); |
---|
877 | |
---|
878 | uint32 tutflag = GetPlayer()->GetTutorialInt( wInt ); |
---|
879 | tutflag |= (1 << rInt); |
---|
880 | GetPlayer()->SetTutorialInt( wInt, tutflag ); |
---|
881 | |
---|
882 | //sLog.outDebug("Received Tutorial Flag Set {%u}.", iFlag); |
---|
883 | } |
---|
884 | |
---|
885 | void WorldSession::HandleTutorialClear( WorldPacket & /*recv_data*/ ) |
---|
886 | { |
---|
887 | for ( uint32 iI = 0; iI < 8; iI++) |
---|
888 | GetPlayer()->SetTutorialInt( iI, 0xFFFFFFFF ); |
---|
889 | } |
---|
890 | |
---|
891 | void WorldSession::HandleTutorialReset( WorldPacket & /*recv_data*/ ) |
---|
892 | { |
---|
893 | for ( uint32 iI = 0; iI < 8; iI++) |
---|
894 | GetPlayer()->SetTutorialInt( iI, 0x00000000 ); |
---|
895 | } |
---|
896 | |
---|
897 | void WorldSession::HandleSetWatchedFactionIndexOpcode(WorldPacket & recv_data) |
---|
898 | { |
---|
899 | CHECK_PACKET_SIZE(recv_data,4); |
---|
900 | |
---|
901 | DEBUG_LOG("WORLD: Received CMSG_SET_WATCHED_FACTION"); |
---|
902 | uint32 fact; |
---|
903 | recv_data >> fact; |
---|
904 | GetPlayer()->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, fact); |
---|
905 | } |
---|
906 | |
---|
907 | void WorldSession::HandleSetWatchedFactionInactiveOpcode(WorldPacket & recv_data) |
---|
908 | { |
---|
909 | CHECK_PACKET_SIZE(recv_data,4+1); |
---|
910 | |
---|
911 | DEBUG_LOG("WORLD: Received CMSG_SET_FACTION_INACTIVE"); |
---|
912 | uint32 replistid; |
---|
913 | uint8 inactive; |
---|
914 | recv_data >> replistid >> inactive; |
---|
915 | |
---|
916 | FactionStateList::iterator itr = _player->m_factions.find(replistid); |
---|
917 | if (itr == _player->m_factions.end()) |
---|
918 | return; |
---|
919 | |
---|
920 | _player->SetFactionInactive(&itr->second, inactive); |
---|
921 | } |
---|
922 | |
---|
923 | void WorldSession::HandleToggleHelmOpcode( WorldPacket & /*recv_data*/ ) |
---|
924 | { |
---|
925 | DEBUG_LOG("CMSG_TOGGLE_HELM for %s", _player->GetName()); |
---|
926 | _player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_HELM); |
---|
927 | } |
---|
928 | |
---|
929 | void WorldSession::HandleToggleCloakOpcode( WorldPacket & /*recv_data*/ ) |
---|
930 | { |
---|
931 | DEBUG_LOG("CMSG_TOGGLE_CLOAK for %s", _player->GetName()); |
---|
932 | _player->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_CLOAK); |
---|
933 | } |
---|
934 | |
---|
935 | void WorldSession::HandleChangePlayerNameOpcode(WorldPacket& recv_data) |
---|
936 | { |
---|
937 | CHECK_PACKET_SIZE(recv_data,8+1); |
---|
938 | |
---|
939 | uint64 guid; |
---|
940 | std::string newname; |
---|
941 | std::string oldname; |
---|
942 | |
---|
943 | CHECK_PACKET_SIZE(recv_data, 8+1); |
---|
944 | |
---|
945 | recv_data >> guid; |
---|
946 | recv_data >> newname; |
---|
947 | |
---|
948 | QueryResult *result = CharacterDatabase.PQuery("SELECT at_login FROM characters WHERE guid ='%u'", GUID_LOPART(guid)); |
---|
949 | if (result) |
---|
950 | { |
---|
951 | uint32 at_loginFlags; |
---|
952 | Field *fields = result->Fetch(); |
---|
953 | at_loginFlags = fields[0].GetUInt32(); |
---|
954 | delete result; |
---|
955 | |
---|
956 | if (!(at_loginFlags & AT_LOGIN_RENAME)) |
---|
957 | { |
---|
958 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
959 | data << (uint8)CHAR_CREATE_ERROR; |
---|
960 | SendPacket( &data ); |
---|
961 | return; |
---|
962 | } |
---|
963 | } |
---|
964 | else |
---|
965 | { |
---|
966 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
967 | data << (uint8)CHAR_CREATE_ERROR; |
---|
968 | SendPacket( &data ); |
---|
969 | return; |
---|
970 | } |
---|
971 | |
---|
972 | if(!objmgr.GetPlayerNameByGUID(guid, oldname)) // character not exist, because we have no name for this guid |
---|
973 | { |
---|
974 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
975 | data << (uint8)CHAR_LOGIN_NO_CHARACTER; |
---|
976 | SendPacket( &data ); |
---|
977 | return; |
---|
978 | } |
---|
979 | |
---|
980 | // prevent character rename to invalid name |
---|
981 | if(!normalizePlayerName(newname)) |
---|
982 | { |
---|
983 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
984 | data << (uint8)CHAR_NAME_NO_NAME; |
---|
985 | SendPacket( &data ); |
---|
986 | return; |
---|
987 | } |
---|
988 | |
---|
989 | if(!ObjectMgr::IsValidName(newname,true)) |
---|
990 | { |
---|
991 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
992 | data << (uint8)CHAR_NAME_INVALID_CHARACTER; |
---|
993 | SendPacket( &data ); |
---|
994 | return; |
---|
995 | } |
---|
996 | |
---|
997 | // check name limitations |
---|
998 | if(GetSecurity() == SEC_PLAYER && objmgr.IsReservedName(newname)) |
---|
999 | { |
---|
1000 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
1001 | data << (uint8)CHAR_NAME_RESERVED; |
---|
1002 | SendPacket( &data ); |
---|
1003 | return; |
---|
1004 | } |
---|
1005 | |
---|
1006 | if(objmgr.GetPlayerGUIDByName(newname)) // character with this name already exist |
---|
1007 | { |
---|
1008 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
1009 | data << (uint8)CHAR_CREATE_ERROR; |
---|
1010 | SendPacket( &data ); |
---|
1011 | return; |
---|
1012 | } |
---|
1013 | |
---|
1014 | if(newname == oldname) // checked by client |
---|
1015 | { |
---|
1016 | WorldPacket data(SMSG_CHAR_RENAME, 1); |
---|
1017 | data << (uint8)CHAR_NAME_FAILURE; |
---|
1018 | SendPacket( &data ); |
---|
1019 | return; |
---|
1020 | } |
---|
1021 | |
---|
1022 | // we have to check character at_login_flag & AT_LOGIN_RENAME also (fake packets hehe) |
---|
1023 | |
---|
1024 | CharacterDatabase.escape_string(newname); |
---|
1025 | 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)); |
---|
1026 | CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid ='%u'", GUID_LOPART(guid)); |
---|
1027 | |
---|
1028 | std::string IP_str = GetRemoteAddress(); |
---|
1029 | 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()); |
---|
1030 | |
---|
1031 | WorldPacket data(SMSG_CHAR_RENAME,1+8+(newname.size()+1)); |
---|
1032 | data << (uint8)RESPONSE_SUCCESS; |
---|
1033 | data << guid; |
---|
1034 | data << newname; |
---|
1035 | SendPacket(&data); |
---|
1036 | } |
---|
1037 | |
---|
1038 | void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data) |
---|
1039 | { |
---|
1040 | uint64 guid; |
---|
1041 | |
---|
1042 | CHECK_PACKET_SIZE(recv_data, 8+6); |
---|
1043 | recv_data >> guid; |
---|
1044 | |
---|
1045 | // not accept declined names for unsupported languages |
---|
1046 | std::string name; |
---|
1047 | if(!objmgr.GetPlayerNameByGUID(guid,name)) |
---|
1048 | { |
---|
1049 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
1050 | data << (uint32)1; |
---|
1051 | data << guid; |
---|
1052 | SendPacket(&data); |
---|
1053 | return; |
---|
1054 | } |
---|
1055 | |
---|
1056 | std::wstring wname; |
---|
1057 | if(!Utf8toWStr(name,wname)) |
---|
1058 | { |
---|
1059 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
1060 | data << (uint32)1; |
---|
1061 | data << guid; |
---|
1062 | SendPacket(&data); |
---|
1063 | return; |
---|
1064 | } |
---|
1065 | |
---|
1066 | if(!isCyrillicCharacter(wname[0])) // name already stored as only single alphabet using |
---|
1067 | { |
---|
1068 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
1069 | data << (uint32)1; |
---|
1070 | data << guid; |
---|
1071 | SendPacket(&data); |
---|
1072 | return; |
---|
1073 | } |
---|
1074 | |
---|
1075 | std::string name2; |
---|
1076 | DeclinedName declinedname; |
---|
1077 | |
---|
1078 | recv_data >> name2; |
---|
1079 | |
---|
1080 | if(name2!=name) // character have different name |
---|
1081 | { |
---|
1082 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
1083 | data << (uint32)1; |
---|
1084 | data << guid; |
---|
1085 | SendPacket(&data); |
---|
1086 | return; |
---|
1087 | } |
---|
1088 | |
---|
1089 | for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) |
---|
1090 | { |
---|
1091 | recv_data >> declinedname.name[i]; |
---|
1092 | if(!normalizePlayerName(declinedname.name[i])) |
---|
1093 | { |
---|
1094 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
1095 | data << (uint32)1; |
---|
1096 | data << guid; |
---|
1097 | SendPacket(&data); |
---|
1098 | return; |
---|
1099 | } |
---|
1100 | } |
---|
1101 | |
---|
1102 | if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname,0),declinedname)) |
---|
1103 | { |
---|
1104 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
1105 | data << (uint32)1; |
---|
1106 | data << guid; |
---|
1107 | SendPacket(&data); |
---|
1108 | return; |
---|
1109 | } |
---|
1110 | |
---|
1111 | for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) |
---|
1112 | CharacterDatabase.escape_string(declinedname.name[i]); |
---|
1113 | |
---|
1114 | CharacterDatabase.BeginTransaction(); |
---|
1115 | CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid)); |
---|
1116 | CharacterDatabase.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')", |
---|
1117 | 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()); |
---|
1118 | CharacterDatabase.CommitTransaction(); |
---|
1119 | |
---|
1120 | WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); |
---|
1121 | data << (uint32)0; // OK |
---|
1122 | data << guid; |
---|
1123 | SendPacket(&data); |
---|
1124 | } |
---|