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