[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 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 |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 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 |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
| 21 | #include "Common.h" |
---|
| 22 | #include "Database/DatabaseEnv.h" |
---|
| 23 | #include "Opcodes.h" |
---|
| 24 | #include "Log.h" |
---|
| 25 | #include "WorldPacket.h" |
---|
| 26 | #include "WorldSession.h" |
---|
| 27 | #include "World.h" |
---|
| 28 | #include "ObjectMgr.h" |
---|
| 29 | #include "Player.h" |
---|
| 30 | #include "Group.h" |
---|
| 31 | #include "ObjectAccessor.h" |
---|
| 32 | #include "MapManager.h" |
---|
| 33 | #include "SocialMgr.h" |
---|
| 34 | #include "Util.h" |
---|
| 35 | |
---|
| 36 | /* differeces from off: |
---|
| 37 | -you can uninvite yourself - is is useful |
---|
| 38 | -you can accept invitation even if leader went offline |
---|
| 39 | */ |
---|
| 40 | /* todo: |
---|
| 41 | -group_destroyed msg is sent but not shown |
---|
| 42 | -reduce xp gaining when in raid group |
---|
| 43 | -quest sharing has to be corrected |
---|
| 44 | -FIX sending PartyMemberStats |
---|
| 45 | */ |
---|
| 46 | |
---|
| 47 | void WorldSession::SendPartyResult(PartyOperation operation, std::string member, PartyResult res) |
---|
| 48 | { |
---|
| 49 | WorldPacket data(SMSG_PARTY_COMMAND_RESULT, (8+member.size()+1)); |
---|
| 50 | data << (uint32)operation; |
---|
| 51 | data << member; |
---|
| 52 | data << (uint32)res; |
---|
| 53 | |
---|
| 54 | SendPacket( &data ); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | void WorldSession::HandleGroupInviteOpcode( WorldPacket & recv_data ) |
---|
| 58 | { |
---|
| 59 | std::string membername; |
---|
| 60 | recv_data >> membername; |
---|
| 61 | |
---|
| 62 | if(_player->InBattleGround()) |
---|
| 63 | { |
---|
| 64 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_INVITE_RESTRICTED); |
---|
| 65 | return; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | // attempt add selected player |
---|
| 69 | |
---|
| 70 | // cheating |
---|
| 71 | if(!normalizePlayerName(membername)) |
---|
| 72 | { |
---|
| 73 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_CANT_FIND_TARGET); |
---|
| 74 | return; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | Player *player = objmgr.GetPlayer(membername.c_str()); |
---|
| 78 | |
---|
| 79 | // no player |
---|
| 80 | if(!player) |
---|
| 81 | { |
---|
| 82 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_CANT_FIND_TARGET); |
---|
| 83 | return; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | // can't group with |
---|
| 87 | if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP) && GetPlayer()->GetTeam() != player->GetTeam()) |
---|
| 88 | { |
---|
| 89 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_TARGET_UNFRIENDLY); |
---|
| 90 | return; |
---|
| 91 | } |
---|
| 92 | if(GetPlayer()->GetInstanceId() != 0 && player->GetInstanceId() != 0 && GetPlayer()->GetInstanceId() != player->GetInstanceId() && GetPlayer()->GetMapId() == player->GetMapId()) |
---|
| 93 | { |
---|
| 94 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_NOT_IN_YOUR_INSTANCE); |
---|
| 95 | return; |
---|
| 96 | } |
---|
| 97 | // just ignore us |
---|
| 98 | if(player->GetInstanceId() != 0 && player->GetDifficulty() != GetPlayer()->GetDifficulty()) |
---|
| 99 | { |
---|
| 100 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_TARGET_IGNORE_YOU); |
---|
| 101 | return; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | if(player->GetSocial()->HasIgnore(GetPlayer()->GetGUIDLow())) |
---|
| 105 | { |
---|
| 106 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_TARGET_IGNORE_YOU); |
---|
| 107 | return; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | // player already in another group or invited |
---|
| 111 | if(player->GetGroup() || player->GetGroupInvite() ) |
---|
| 112 | { |
---|
| 113 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_ALREADY_IN_GROUP); |
---|
| 114 | return; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | Group *group = GetPlayer()->GetGroup(); |
---|
| 118 | |
---|
| 119 | if(group) |
---|
| 120 | { |
---|
| 121 | // not have permissions for invite |
---|
| 122 | if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID())) |
---|
| 123 | { |
---|
| 124 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_YOU_NOT_LEADER); |
---|
| 125 | return; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | // not have place |
---|
| 129 | if(group->IsFull()) |
---|
| 130 | { |
---|
| 131 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_PARTY_FULL); |
---|
| 132 | return; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // ok, but group not exist, start a new group |
---|
| 137 | // but don't create and save the group to the DB until |
---|
| 138 | // at least one person joins |
---|
| 139 | if(!group) |
---|
| 140 | { |
---|
| 141 | group = new Group; |
---|
| 142 | // new group: if can't add then delete |
---|
| 143 | if(!group->AddLeaderInvite(GetPlayer())) |
---|
| 144 | { |
---|
| 145 | delete group; |
---|
| 146 | return; |
---|
| 147 | } |
---|
| 148 | if(!group->AddInvite(player)) |
---|
| 149 | { |
---|
| 150 | delete group; |
---|
| 151 | return; |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | // already existed group: if can't add then just leave |
---|
| 157 | if(!group->AddInvite(player)) |
---|
| 158 | { |
---|
| 159 | return; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // ok, we do it |
---|
| 164 | WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size |
---|
| 165 | data << GetPlayer()->GetName(); |
---|
| 166 | player->GetSession()->SendPacket(&data); |
---|
| 167 | |
---|
| 168 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_OK); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | void WorldSession::HandleGroupAcceptOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 172 | { |
---|
| 173 | Group *group = GetPlayer()->GetGroupInvite(); |
---|
| 174 | if (!group) return; |
---|
| 175 | |
---|
| 176 | if(group->GetLeaderGUID() == GetPlayer()->GetGUID()) |
---|
| 177 | { |
---|
| 178 | sLog.outError("HandleGroupAcceptOpcode: player %s(%d) tried to accept an invite to his own group", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); |
---|
| 179 | return; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | // remove in from ivites in any case |
---|
| 183 | group->RemoveInvite(GetPlayer()); |
---|
| 184 | |
---|
| 185 | /** error handling **/ |
---|
| 186 | /********************/ |
---|
| 187 | |
---|
| 188 | // not have place |
---|
| 189 | if(group->IsFull()) |
---|
| 190 | { |
---|
| 191 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_PARTY_FULL); |
---|
| 192 | return; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | Player* leader = objmgr.GetPlayer(group->GetLeaderGUID()); |
---|
| 196 | |
---|
| 197 | if(leader && leader->InBattleGround()) |
---|
| 198 | { |
---|
| 199 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED); |
---|
| 200 | return; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | // forming a new group, create it |
---|
| 204 | if(!group->IsCreated()) |
---|
| 205 | { |
---|
| 206 | if(leader) group->RemoveInvite(leader); |
---|
| 207 | group->Create(group->GetLeaderGUID(), group->GetLeaderName()); |
---|
| 208 | objmgr.AddGroup(group); |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | // everything's fine, do it |
---|
| 212 | if(!group->AddMember(GetPlayer()->GetGUID(), GetPlayer()->GetName())) |
---|
| 213 | return; |
---|
| 214 | |
---|
| 215 | uint8 subgroup = group->GetMemberGroup(GetPlayer()->GetGUID()); |
---|
| 216 | |
---|
| 217 | GetPlayer()->SetGroup(group, subgroup); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | void WorldSession::HandleGroupDeclineOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 221 | { |
---|
| 222 | Group *group = GetPlayer()->GetGroupInvite(); |
---|
| 223 | if (!group) return; |
---|
| 224 | |
---|
| 225 | Player *leader = objmgr.GetPlayer(group->GetLeaderGUID()); |
---|
| 226 | |
---|
| 227 | /** error handling **/ |
---|
| 228 | if(!leader || !leader->GetSession()) |
---|
| 229 | return; |
---|
| 230 | /********************/ |
---|
| 231 | |
---|
| 232 | // everything's fine, do it |
---|
| 233 | if(!group->IsCreated()) |
---|
| 234 | { |
---|
| 235 | // note: this means that if you invite more than one person |
---|
| 236 | // and one of them declines before the first one accepts |
---|
| 237 | // all invites will be cleared |
---|
| 238 | // fixme: is that ok ? |
---|
| 239 | group->RemoveAllInvites(); |
---|
| 240 | delete group; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | GetPlayer()->SetGroupInvite(NULL); |
---|
| 244 | |
---|
| 245 | WorldPacket data( SMSG_GROUP_DECLINE, 10 ); // guess size |
---|
| 246 | data << GetPlayer()->GetName(); |
---|
| 247 | leader->GetSession()->SendPacket( &data ); |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | void WorldSession::HandleGroupUninviteGuidOpcode(WorldPacket & recv_data) |
---|
| 251 | { |
---|
| 252 | CHECK_PACKET_SIZE(recv_data,8); |
---|
| 253 | |
---|
| 254 | uint64 guid; |
---|
| 255 | recv_data >> guid; |
---|
| 256 | |
---|
| 257 | if(_player->InBattleGround()) |
---|
| 258 | { |
---|
| 259 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED); |
---|
| 260 | return; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | std::string membername; |
---|
| 264 | if(!objmgr.GetPlayerNameByGUID(guid, membername)) |
---|
| 265 | return; // not found |
---|
| 266 | |
---|
| 267 | HandleGroupUninvite(guid, membername); |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | void WorldSession::HandleGroupUninviteNameOpcode(WorldPacket & recv_data) |
---|
| 271 | { |
---|
| 272 | CHECK_PACKET_SIZE(recv_data,1); |
---|
| 273 | |
---|
| 274 | std::string membername; |
---|
| 275 | recv_data >> membername; |
---|
| 276 | |
---|
| 277 | if(_player->InBattleGround()) |
---|
| 278 | { |
---|
| 279 | SendPartyResult(PARTY_OP_INVITE, membername, PARTY_RESULT_INVITE_RESTRICTED); |
---|
| 280 | return; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | // player not found |
---|
| 284 | if(!normalizePlayerName(membername)) |
---|
| 285 | return; |
---|
| 286 | |
---|
| 287 | uint64 guid = objmgr.GetPlayerGUIDByName(membername); |
---|
| 288 | |
---|
| 289 | // player not found |
---|
| 290 | if(!guid) |
---|
| 291 | return; |
---|
| 292 | |
---|
| 293 | HandleGroupUninvite(guid, membername); |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | void WorldSession::HandleGroupUninvite(uint64 guid, std::string name) |
---|
| 297 | { |
---|
| 298 | Group *group = GetPlayer()->GetGroup(); |
---|
| 299 | if(!group) |
---|
| 300 | return; |
---|
| 301 | |
---|
| 302 | if(_player->InBattleGround()) |
---|
| 303 | { |
---|
| 304 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED); |
---|
| 305 | return; |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | Player *player = objmgr.GetPlayer(guid); |
---|
| 309 | |
---|
| 310 | /** error handling **/ |
---|
| 311 | if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID())) |
---|
| 312 | { |
---|
| 313 | SendPartyResult(PARTY_OP_LEAVE, "", PARTY_RESULT_YOU_NOT_LEADER); |
---|
| 314 | return; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | if(!group->IsMember(guid) && (player && player->GetGroupInvite() != group)) |
---|
| 318 | { |
---|
| 319 | SendPartyResult(PARTY_OP_LEAVE, name, PARTY_RESULT_NOT_IN_YOUR_PARTY); |
---|
| 320 | return; |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | if(guid == GetPlayer()->GetGUID()) |
---|
| 324 | { |
---|
| 325 | sLog.outError("WorldSession::HandleGroupUninvite: leader %s(%d) tried to uninvite himself from the group.", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); |
---|
| 326 | return; |
---|
| 327 | } |
---|
| 328 | /********************/ |
---|
| 329 | |
---|
| 330 | // everything's fine, do it |
---|
| 331 | |
---|
| 332 | if(player && player->GetGroupInvite()) // uninvite invitee |
---|
| 333 | player->UninviteFromGroup(); |
---|
| 334 | else // uninvite member |
---|
| 335 | Player::RemoveFromGroup(group,guid); |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | void WorldSession::HandleGroupSetLeaderOpcode( WorldPacket & recv_data ) |
---|
| 339 | { |
---|
| 340 | CHECK_PACKET_SIZE(recv_data,8); |
---|
| 341 | |
---|
| 342 | Group *group = GetPlayer()->GetGroup(); |
---|
| 343 | if(!group) |
---|
| 344 | return; |
---|
| 345 | |
---|
| 346 | uint64 guid; |
---|
| 347 | recv_data >> guid; |
---|
| 348 | |
---|
| 349 | Player *player = objmgr.GetPlayer(guid); |
---|
| 350 | |
---|
| 351 | /** error handling **/ |
---|
| 352 | if (!player || !group->IsLeader(GetPlayer()->GetGUID()) || player->GetGroup() != group) |
---|
| 353 | return; |
---|
| 354 | /********************/ |
---|
| 355 | |
---|
| 356 | // everything's fine, do it |
---|
| 357 | group->ChangeLeader(guid); |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | void WorldSession::HandleGroupLeaveOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 361 | { |
---|
| 362 | if(!GetPlayer()->GetGroup()) |
---|
| 363 | return; |
---|
| 364 | |
---|
| 365 | if(_player->InBattleGround()) |
---|
| 366 | { |
---|
| 367 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_INVITE_RESTRICTED); |
---|
| 368 | return; |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | /** error handling **/ |
---|
| 372 | /********************/ |
---|
| 373 | |
---|
| 374 | // everything's fine, do it |
---|
| 375 | SendPartyResult(PARTY_OP_LEAVE, GetPlayer()->GetName(), PARTY_RESULT_OK); |
---|
| 376 | |
---|
| 377 | GetPlayer()->RemoveFromGroup(); |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | void WorldSession::HandleLootMethodOpcode( WorldPacket & recv_data ) |
---|
| 381 | { |
---|
| 382 | CHECK_PACKET_SIZE(recv_data,4+8+4); |
---|
| 383 | |
---|
| 384 | Group *group = GetPlayer()->GetGroup(); |
---|
| 385 | if(!group) |
---|
| 386 | return; |
---|
| 387 | |
---|
| 388 | uint32 lootMethod; |
---|
| 389 | uint64 lootMaster; |
---|
| 390 | uint32 lootThreshold; |
---|
| 391 | recv_data >> lootMethod >> lootMaster >> lootThreshold; |
---|
| 392 | |
---|
| 393 | /** error handling **/ |
---|
| 394 | if(!group->IsLeader(GetPlayer()->GetGUID())) |
---|
| 395 | return; |
---|
| 396 | /********************/ |
---|
| 397 | |
---|
| 398 | // everything's fine, do it |
---|
| 399 | group->SetLootMethod((LootMethod)lootMethod); |
---|
| 400 | group->SetLooterGuid(lootMaster); |
---|
| 401 | group->SetLootThreshold((ItemQualities)lootThreshold); |
---|
| 402 | group->SendUpdate(); |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | void WorldSession::HandleLootRoll( WorldPacket &recv_data ) |
---|
| 406 | { |
---|
| 407 | CHECK_PACKET_SIZE(recv_data,8+4+1); |
---|
| 408 | |
---|
| 409 | if(!GetPlayer()->GetGroup()) |
---|
| 410 | return; |
---|
| 411 | |
---|
| 412 | uint64 Guid; |
---|
| 413 | uint32 NumberOfPlayers; |
---|
| 414 | uint8 Choise; |
---|
| 415 | recv_data >> Guid; //guid of the item rolled |
---|
| 416 | recv_data >> NumberOfPlayers; |
---|
| 417 | recv_data >> Choise; //0: pass, 1: need, 2: greed |
---|
| 418 | |
---|
| 419 | //sLog.outDebug("WORLD RECIEVE CMSG_LOOT_ROLL, From:%u, Numberofplayers:%u, Choise:%u", (uint32)Guid, NumberOfPlayers, Choise); |
---|
| 420 | |
---|
| 421 | Group* group = GetPlayer()->GetGroup(); |
---|
| 422 | if(!group) |
---|
| 423 | return; |
---|
| 424 | |
---|
| 425 | // everything's fine, do it |
---|
| 426 | group->CountRollVote(GetPlayer()->GetGUID(), Guid, NumberOfPlayers, Choise); |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | void WorldSession::HandleMinimapPingOpcode(WorldPacket& recv_data) |
---|
| 430 | { |
---|
| 431 | CHECK_PACKET_SIZE(recv_data,4+4); |
---|
| 432 | |
---|
| 433 | if(!GetPlayer()->GetGroup()) |
---|
| 434 | return; |
---|
| 435 | |
---|
| 436 | float x, y; |
---|
| 437 | recv_data >> x; |
---|
| 438 | recv_data >> y; |
---|
| 439 | |
---|
| 440 | //sLog.outDebug("Received opcode MSG_MINIMAP_PING X: %f, Y: %f", x, y); |
---|
| 441 | |
---|
| 442 | /** error handling **/ |
---|
| 443 | /********************/ |
---|
| 444 | |
---|
| 445 | // everything's fine, do it |
---|
| 446 | WorldPacket data(MSG_MINIMAP_PING, (8+4+4)); |
---|
| 447 | data << GetPlayer()->GetGUID(); |
---|
| 448 | data << x; |
---|
| 449 | data << y; |
---|
| 450 | GetPlayer()->GetGroup()->BroadcastPacket(&data, -1, GetPlayer()->GetGUID()); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | void WorldSession::HandleRandomRollOpcode(WorldPacket& recv_data) |
---|
| 454 | { |
---|
| 455 | CHECK_PACKET_SIZE(recv_data,4+4); |
---|
| 456 | |
---|
| 457 | uint32 minimum, maximum, roll; |
---|
| 458 | recv_data >> minimum; |
---|
| 459 | recv_data >> maximum; |
---|
| 460 | |
---|
| 461 | /** error handling **/ |
---|
| 462 | if(minimum > maximum || maximum > 10000) // < 32768 for urand call |
---|
| 463 | return; |
---|
| 464 | /********************/ |
---|
| 465 | |
---|
| 466 | // everything's fine, do it |
---|
| 467 | roll = urand(minimum, maximum); |
---|
| 468 | |
---|
| 469 | //sLog.outDebug("ROLL: MIN: %u, MAX: %u, ROLL: %u", minimum, maximum, roll); |
---|
| 470 | |
---|
| 471 | WorldPacket data(MSG_RANDOM_ROLL, 4+4+4+8); |
---|
| 472 | data << minimum; |
---|
| 473 | data << maximum; |
---|
| 474 | data << roll; |
---|
| 475 | data << GetPlayer()->GetGUID(); |
---|
| 476 | if(GetPlayer()->GetGroup()) |
---|
| 477 | GetPlayer()->GetGroup()->BroadcastPacket(&data); |
---|
| 478 | else |
---|
| 479 | SendPacket(&data); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | void WorldSession::HandleRaidIconTargetOpcode( WorldPacket & recv_data ) |
---|
| 483 | { |
---|
| 484 | CHECK_PACKET_SIZE(recv_data,1); |
---|
| 485 | |
---|
| 486 | Group *group = GetPlayer()->GetGroup(); |
---|
| 487 | if(!group) |
---|
| 488 | return; |
---|
| 489 | |
---|
| 490 | uint8 x; |
---|
| 491 | recv_data >> x; |
---|
| 492 | |
---|
| 493 | /** error handling **/ |
---|
| 494 | /********************/ |
---|
| 495 | |
---|
| 496 | // everything's fine, do it |
---|
| 497 | if(x == 0xFF) // target icon request |
---|
| 498 | { |
---|
| 499 | group->SendTargetIconList(this); |
---|
| 500 | } |
---|
| 501 | else // target icon update |
---|
| 502 | { |
---|
| 503 | // recheck |
---|
| 504 | CHECK_PACKET_SIZE(recv_data,1+8); |
---|
| 505 | |
---|
| 506 | if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID())) |
---|
| 507 | return; |
---|
| 508 | |
---|
| 509 | uint64 guid; |
---|
| 510 | recv_data >> guid; |
---|
| 511 | group->SetTargetIcon(x, guid); |
---|
| 512 | } |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | void WorldSession::HandleRaidConvertOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 516 | { |
---|
| 517 | Group *group = GetPlayer()->GetGroup(); |
---|
| 518 | if(!group) |
---|
| 519 | return; |
---|
| 520 | |
---|
| 521 | if(_player->InBattleGround()) |
---|
| 522 | return; |
---|
| 523 | |
---|
| 524 | /** error handling **/ |
---|
| 525 | if(!group->IsLeader(GetPlayer()->GetGUID()) || group->GetMembersCount() < 2) |
---|
| 526 | return; |
---|
| 527 | /********************/ |
---|
| 528 | |
---|
| 529 | // everything's fine, do it (is it 0 (PARTY_OP_INVITE) correct code) |
---|
| 530 | SendPartyResult(PARTY_OP_INVITE, "", PARTY_RESULT_OK); |
---|
| 531 | group->ConvertToRaid(); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | void WorldSession::HandleGroupChangeSubGroupOpcode( WorldPacket & recv_data ) |
---|
| 535 | { |
---|
| 536 | CHECK_PACKET_SIZE(recv_data,1+1); |
---|
| 537 | |
---|
| 538 | Group *group = GetPlayer()->GetGroup(); |
---|
| 539 | if(!group) |
---|
| 540 | return; |
---|
| 541 | |
---|
| 542 | std::string name; |
---|
| 543 | uint8 groupNr; |
---|
| 544 | recv_data >> name; |
---|
| 545 | |
---|
| 546 | // recheck |
---|
| 547 | CHECK_PACKET_SIZE(recv_data,(name.size()+1)+1); |
---|
| 548 | |
---|
| 549 | recv_data >> groupNr; |
---|
| 550 | |
---|
| 551 | /** error handling **/ |
---|
| 552 | if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID())) |
---|
| 553 | return; |
---|
| 554 | /********************/ |
---|
| 555 | |
---|
| 556 | // everything's fine, do it |
---|
| 557 | group->ChangeMembersGroup(objmgr.GetPlayer(name.c_str()), groupNr); |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | void WorldSession::HandleGroupAssistantOpcode( WorldPacket & recv_data ) |
---|
| 561 | { |
---|
| 562 | CHECK_PACKET_SIZE(recv_data,8+1); |
---|
| 563 | |
---|
| 564 | Group *group = GetPlayer()->GetGroup(); |
---|
| 565 | if(!group) |
---|
| 566 | return; |
---|
| 567 | |
---|
| 568 | uint64 guid; |
---|
| 569 | uint8 flag; |
---|
| 570 | recv_data >> guid; |
---|
| 571 | recv_data >> flag; |
---|
| 572 | |
---|
| 573 | /** error handling **/ |
---|
| 574 | if(!group->IsLeader(GetPlayer()->GetGUID())) |
---|
| 575 | return; |
---|
| 576 | /********************/ |
---|
| 577 | |
---|
| 578 | // everything's fine, do it |
---|
| 579 | group->SetAssistant(guid, (flag==0?false:true)); |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | void WorldSession::HandleGroupPromoteOpcode( WorldPacket & recv_data ) |
---|
| 583 | { |
---|
| 584 | CHECK_PACKET_SIZE(recv_data, 1+1+8); |
---|
| 585 | |
---|
| 586 | Group *group = GetPlayer()->GetGroup(); |
---|
| 587 | if(!group) |
---|
| 588 | return; |
---|
| 589 | |
---|
| 590 | uint8 flag1, flag2; |
---|
| 591 | uint64 guid; |
---|
| 592 | recv_data >> flag1 >> flag2; |
---|
| 593 | recv_data >> guid; |
---|
| 594 | // if(flag1) Main Assist |
---|
| 595 | // 0x4 |
---|
| 596 | // if(flag2) Main Tank |
---|
| 597 | // 0x2 |
---|
| 598 | |
---|
| 599 | /** error handling **/ |
---|
| 600 | if(!group->IsLeader(GetPlayer()->GetGUID())) |
---|
| 601 | return; |
---|
| 602 | /********************/ |
---|
| 603 | |
---|
| 604 | // everything's fine, do it |
---|
| 605 | if(flag1 == 1) |
---|
| 606 | group->SetMainAssistant(guid); |
---|
| 607 | if(flag2 == 1) |
---|
| 608 | group->SetMainTank(guid); |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | void WorldSession::HandleRaidReadyCheckOpcode( WorldPacket & recv_data ) |
---|
| 612 | { |
---|
| 613 | Group *group = GetPlayer()->GetGroup(); |
---|
| 614 | if(!group) |
---|
| 615 | return; |
---|
| 616 | |
---|
| 617 | if(recv_data.empty()) // request |
---|
| 618 | { |
---|
| 619 | /** error handling **/ |
---|
| 620 | if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID())) |
---|
| 621 | return; |
---|
| 622 | /********************/ |
---|
| 623 | |
---|
| 624 | // everything's fine, do it |
---|
| 625 | WorldPacket data(MSG_RAID_READY_CHECK, 8); |
---|
| 626 | data << GetPlayer()->GetGUID(); |
---|
| 627 | group->BroadcastPacket(&data, -1); |
---|
| 628 | |
---|
| 629 | group->OfflineReadyCheck(); |
---|
| 630 | } |
---|
| 631 | else // answer |
---|
| 632 | { |
---|
| 633 | uint8 state; |
---|
| 634 | recv_data >> state; |
---|
| 635 | |
---|
| 636 | // everything's fine, do it |
---|
| 637 | WorldPacket data(MSG_RAID_READY_CHECK_CONFIRM, 9); |
---|
| 638 | data << GetPlayer()->GetGUID(); |
---|
| 639 | data << state; |
---|
| 640 | group->BroadcastReadyCheck(&data); |
---|
| 641 | } |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | void WorldSession::HandleRaidReadyCheckFinishOpcode( WorldPacket & recv_data ) |
---|
| 645 | { |
---|
| 646 | //Group* group = GetPlayer()->GetGroup(); |
---|
| 647 | //if(!group) |
---|
| 648 | // return; |
---|
| 649 | |
---|
| 650 | //if(!group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID())) |
---|
| 651 | // return; |
---|
| 652 | |
---|
| 653 | // Is any reaction need? |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | void WorldSession::BuildPartyMemberStatsChangedPacket(Player *player, WorldPacket *data) |
---|
| 657 | { |
---|
| 658 | uint32 mask = player->GetGroupUpdateFlag(); |
---|
| 659 | |
---|
| 660 | if (mask == GROUP_UPDATE_FLAG_NONE) |
---|
| 661 | return; |
---|
| 662 | |
---|
| 663 | if (mask & GROUP_UPDATE_FLAG_POWER_TYPE) // if update power type, update current/max power also |
---|
| 664 | mask |= (GROUP_UPDATE_FLAG_CUR_POWER | GROUP_UPDATE_FLAG_MAX_POWER); |
---|
| 665 | |
---|
| 666 | if (mask & GROUP_UPDATE_FLAG_PET_POWER_TYPE) // same for pets |
---|
| 667 | mask |= (GROUP_UPDATE_FLAG_PET_CUR_POWER | GROUP_UPDATE_FLAG_PET_MAX_POWER); |
---|
| 668 | |
---|
| 669 | uint32 byteCount = 0; |
---|
| 670 | for (int i = 1; i < GROUP_UPDATE_FLAGS_COUNT; ++i) |
---|
| 671 | if (mask & (1 << i)) |
---|
| 672 | byteCount += GroupUpdateLength[i]; |
---|
| 673 | |
---|
| 674 | data->Initialize(SMSG_PARTY_MEMBER_STATS, 8 + 4 + byteCount); |
---|
| 675 | data->append(player->GetPackGUID()); |
---|
| 676 | *data << (uint32) mask; |
---|
| 677 | |
---|
| 678 | if (mask & GROUP_UPDATE_FLAG_STATUS) |
---|
| 679 | { |
---|
| 680 | if (player) |
---|
| 681 | { |
---|
| 682 | if (player->IsPvP()) |
---|
| 683 | *data << (uint16) (MEMBER_STATUS_ONLINE | MEMBER_STATUS_PVP); |
---|
| 684 | else |
---|
| 685 | *data << (uint16) MEMBER_STATUS_ONLINE; |
---|
| 686 | } |
---|
| 687 | else |
---|
| 688 | *data << (uint16) MEMBER_STATUS_OFFLINE; |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | if (mask & GROUP_UPDATE_FLAG_CUR_HP) |
---|
| 692 | *data << (uint16) player->GetHealth(); |
---|
| 693 | |
---|
| 694 | if (mask & GROUP_UPDATE_FLAG_MAX_HP) |
---|
| 695 | *data << (uint16) player->GetMaxHealth(); |
---|
| 696 | |
---|
| 697 | Powers powerType = player->getPowerType(); |
---|
| 698 | if (mask & GROUP_UPDATE_FLAG_POWER_TYPE) |
---|
| 699 | *data << (uint8) powerType; |
---|
| 700 | |
---|
| 701 | if (mask & GROUP_UPDATE_FLAG_CUR_POWER) |
---|
| 702 | *data << (uint16) player->GetPower(powerType); |
---|
| 703 | |
---|
| 704 | if (mask & GROUP_UPDATE_FLAG_MAX_POWER) |
---|
| 705 | *data << (uint16) player->GetMaxPower(powerType); |
---|
| 706 | |
---|
| 707 | if (mask & GROUP_UPDATE_FLAG_LEVEL) |
---|
| 708 | *data << (uint16) player->getLevel(); |
---|
| 709 | |
---|
| 710 | if (mask & GROUP_UPDATE_FLAG_ZONE) |
---|
| 711 | *data << (uint16) player->GetZoneId(); |
---|
| 712 | |
---|
| 713 | if (mask & GROUP_UPDATE_FLAG_POSITION) |
---|
| 714 | *data << (uint16) player->GetPositionX() << (uint16) player->GetPositionY(); |
---|
| 715 | |
---|
| 716 | if (mask & GROUP_UPDATE_FLAG_AURAS) |
---|
| 717 | { |
---|
| 718 | uint64 auramask = player->GetAuraUpdateMask(); |
---|
| 719 | *data << uint64(auramask); |
---|
| 720 | for(uint32 i = 0; i < MAX_AURAS; ++i) |
---|
| 721 | { |
---|
| 722 | if(auramask & (uint64(1) << i)) |
---|
| 723 | { |
---|
| 724 | *data << uint16(player->GetUInt32Value(UNIT_FIELD_AURA + i)); |
---|
| 725 | *data << uint8(1); |
---|
| 726 | } |
---|
| 727 | } |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | Pet *pet = player->GetPet(); |
---|
| 731 | if (mask & GROUP_UPDATE_FLAG_PET_GUID) |
---|
| 732 | { |
---|
| 733 | if(pet) |
---|
| 734 | *data << (uint64) pet->GetGUID(); |
---|
| 735 | else |
---|
| 736 | *data << (uint64) 0; |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | if (mask & GROUP_UPDATE_FLAG_PET_NAME) |
---|
| 740 | { |
---|
| 741 | if(pet) |
---|
| 742 | *data << pet->GetName(); |
---|
| 743 | else |
---|
| 744 | *data << (uint8) 0; |
---|
| 745 | } |
---|
| 746 | |
---|
| 747 | if (mask & GROUP_UPDATE_FLAG_PET_MODEL_ID) |
---|
| 748 | { |
---|
| 749 | if(pet) |
---|
| 750 | *data << (uint16) pet->GetDisplayId(); |
---|
| 751 | else |
---|
| 752 | *data << (uint16) 0; |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | if (mask & GROUP_UPDATE_FLAG_PET_CUR_HP) |
---|
| 756 | { |
---|
| 757 | if(pet) |
---|
| 758 | *data << (uint16) pet->GetHealth(); |
---|
| 759 | else |
---|
| 760 | *data << (uint16) 0; |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | if (mask & GROUP_UPDATE_FLAG_PET_MAX_HP) |
---|
| 764 | { |
---|
| 765 | if(pet) |
---|
| 766 | *data << (uint16) pet->GetMaxHealth(); |
---|
| 767 | else |
---|
| 768 | *data << (uint16) 0; |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | if (mask & GROUP_UPDATE_FLAG_PET_POWER_TYPE) |
---|
| 772 | { |
---|
| 773 | if(pet) |
---|
| 774 | *data << (uint8) pet->getPowerType(); |
---|
| 775 | else |
---|
| 776 | *data << (uint8) 0; |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | if (mask & GROUP_UPDATE_FLAG_PET_CUR_POWER) |
---|
| 780 | { |
---|
| 781 | if(pet) |
---|
| 782 | *data << (uint16) pet->GetPower(pet->getPowerType()); |
---|
| 783 | else |
---|
| 784 | *data << (uint16) 0; |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | if (mask & GROUP_UPDATE_FLAG_PET_MAX_POWER) |
---|
| 788 | { |
---|
| 789 | if(pet) |
---|
| 790 | *data << (uint16) pet->GetMaxPower(pet->getPowerType()); |
---|
| 791 | else |
---|
| 792 | *data << (uint16) 0; |
---|
| 793 | } |
---|
| 794 | |
---|
| 795 | if (mask & GROUP_UPDATE_FLAG_PET_AURAS) |
---|
| 796 | { |
---|
| 797 | if(pet) |
---|
| 798 | { |
---|
| 799 | uint64 auramask = pet->GetAuraUpdateMask(); |
---|
| 800 | *data << uint64(auramask); |
---|
| 801 | for(uint32 i = 0; i < MAX_AURAS; ++i) |
---|
| 802 | { |
---|
| 803 | if(auramask & (uint64(1) << i)) |
---|
| 804 | { |
---|
| 805 | *data << uint16(pet->GetUInt32Value(UNIT_FIELD_AURA + i)); |
---|
| 806 | *data << uint8(1); |
---|
| 807 | } |
---|
| 808 | } |
---|
| 809 | } |
---|
| 810 | else |
---|
| 811 | *data << (uint64) 0; |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | /*this procedure handles clients CMSG_REQUEST_PARTY_MEMBER_STATS request*/ |
---|
| 816 | void WorldSession::HandleRequestPartyMemberStatsOpcode( WorldPacket &recv_data ) |
---|
| 817 | { |
---|
| 818 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
| 819 | |
---|
| 820 | sLog.outDebug("WORLD: Received CMSG_REQUEST_PARTY_MEMBER_STATS"); |
---|
| 821 | uint64 Guid; |
---|
| 822 | recv_data >> Guid; |
---|
| 823 | |
---|
| 824 | Player *player = objmgr.GetPlayer(Guid); |
---|
| 825 | if(!player) |
---|
| 826 | { |
---|
| 827 | WorldPacket data(SMSG_PARTY_MEMBER_STATS_FULL, 3+4+2); |
---|
| 828 | data.appendPackGUID(Guid); |
---|
| 829 | data << (uint32) GROUP_UPDATE_FLAG_STATUS; |
---|
| 830 | data << (uint16) MEMBER_STATUS_OFFLINE; |
---|
| 831 | SendPacket(&data); |
---|
| 832 | return; |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | Pet *pet = player->GetPet(); |
---|
| 836 | |
---|
| 837 | WorldPacket data(SMSG_PARTY_MEMBER_STATS_FULL, 4+2+2+2+1+2*6+8+1+8); |
---|
| 838 | data.append(player->GetPackGUID()); |
---|
| 839 | |
---|
| 840 | uint32 mask1 = 0x00040BFF; // common mask, real flags used 0x000040BFF |
---|
| 841 | if(pet) |
---|
| 842 | mask1 = 0x7FFFFFFF; // for hunters and other classes with pets |
---|
| 843 | |
---|
| 844 | Powers powerType = player->getPowerType(); |
---|
| 845 | data << (uint32) mask1; // group update mask |
---|
| 846 | data << (uint16) MEMBER_STATUS_ONLINE; // member's online status |
---|
| 847 | data << (uint16) player->GetHealth(); // GROUP_UPDATE_FLAG_CUR_HP |
---|
| 848 | data << (uint16) player->GetMaxHealth(); // GROUP_UPDATE_FLAG_MAX_HP |
---|
| 849 | data << (uint8) powerType; // GROUP_UPDATE_FLAG_POWER_TYPE |
---|
| 850 | data << (uint16) player->GetPower(powerType); // GROUP_UPDATE_FLAG_CUR_POWER |
---|
| 851 | data << (uint16) player->GetMaxPower(powerType); // GROUP_UPDATE_FLAG_MAX_POWER |
---|
| 852 | data << (uint16) player->getLevel(); // GROUP_UPDATE_FLAG_LEVEL |
---|
| 853 | data << (uint16) player->GetZoneId(); // GROUP_UPDATE_FLAG_ZONE |
---|
| 854 | data << (uint16) player->GetPositionX(); // GROUP_UPDATE_FLAG_POSITION |
---|
| 855 | data << (uint16) player->GetPositionY(); // GROUP_UPDATE_FLAG_POSITION |
---|
| 856 | |
---|
| 857 | uint64 auramask = 0; |
---|
| 858 | size_t maskPos = data.wpos(); |
---|
| 859 | data << (uint64) auramask; // placeholder |
---|
| 860 | for(uint8 i = 0; i < MAX_AURAS; ++i) |
---|
| 861 | { |
---|
| 862 | if(uint32 aura = player->GetUInt32Value(UNIT_FIELD_AURA + i)) |
---|
| 863 | { |
---|
| 864 | auramask |= (uint64(1) << i); |
---|
| 865 | data << uint16(aura); |
---|
| 866 | data << uint8(1); |
---|
| 867 | } |
---|
| 868 | } |
---|
| 869 | data.put<uint64>(maskPos,auramask); // GROUP_UPDATE_FLAG_AURAS |
---|
| 870 | |
---|
| 871 | if(pet) |
---|
| 872 | { |
---|
| 873 | Powers petpowertype = pet->getPowerType(); |
---|
| 874 | data << (uint64) pet->GetGUID(); // GROUP_UPDATE_FLAG_PET_GUID |
---|
| 875 | data << pet->GetName(); // GROUP_UPDATE_FLAG_PET_NAME |
---|
| 876 | data << (uint16) pet->GetDisplayId(); // GROUP_UPDATE_FLAG_PET_MODEL_ID |
---|
| 877 | data << (uint16) pet->GetHealth(); // GROUP_UPDATE_FLAG_PET_CUR_HP |
---|
| 878 | data << (uint16) pet->GetMaxHealth(); // GROUP_UPDATE_FLAG_PET_MAX_HP |
---|
| 879 | data << (uint8) petpowertype; // GROUP_UPDATE_FLAG_PET_POWER_TYPE |
---|
| 880 | data << (uint16) pet->GetPower(petpowertype); // GROUP_UPDATE_FLAG_PET_CUR_POWER |
---|
| 881 | data << (uint16) pet->GetMaxPower(petpowertype); // GROUP_UPDATE_FLAG_PET_MAX_POWER |
---|
| 882 | |
---|
| 883 | uint64 petauramask = 0; |
---|
| 884 | size_t petMaskPos = data.wpos(); |
---|
| 885 | data << (uint64) petauramask; // placeholder |
---|
| 886 | for(uint8 i = 0; i < MAX_AURAS; ++i) |
---|
| 887 | { |
---|
| 888 | if(uint32 petaura = pet->GetUInt32Value(UNIT_FIELD_AURA + i)) |
---|
| 889 | { |
---|
| 890 | petauramask |= (uint64(1) << i); |
---|
| 891 | data << (uint16) petaura; |
---|
| 892 | data << (uint8) 1; |
---|
| 893 | } |
---|
| 894 | } |
---|
| 895 | data.put<uint64>(petMaskPos,petauramask); // GROUP_UPDATE_FLAG_PET_AURAS |
---|
| 896 | } |
---|
| 897 | else |
---|
| 898 | { |
---|
| 899 | data << (uint8) 0; // GROUP_UPDATE_FLAG_PET_NAME |
---|
| 900 | data << (uint64) 0; // GROUP_UPDATE_FLAG_PET_AURAS |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | SendPacket(&data); |
---|
| 904 | } |
---|
| 905 | |
---|
| 906 | /*!*/void WorldSession::HandleRequestRaidInfoOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 907 | { |
---|
| 908 | // every time the player checks the character screen |
---|
| 909 | _player->SendRaidInfo(); |
---|
| 910 | } |
---|
| 911 | |
---|
| 912 | /*void WorldSession::HandleGroupCancelOpcode( WorldPacket & recv_data ) |
---|
| 913 | { |
---|
| 914 | sLog.outDebug( "WORLD: got CMSG_GROUP_CANCEL." ); |
---|
| 915 | }*/ |
---|
| 916 | |
---|
| 917 | void WorldSession::HandleGroupPassOnLootOpcode( WorldPacket & recv_data ) |
---|
| 918 | { |
---|
| 919 | CHECK_PACKET_SIZE(recv_data, 4); |
---|
| 920 | |
---|
| 921 | sLog.outDebug("WORLD: Received CMSG_GROUP_PASS_ON_LOOT"); |
---|
| 922 | |
---|
| 923 | uint32 unkn; |
---|
| 924 | recv_data >> unkn; |
---|
| 925 | |
---|
| 926 | // ignore if player not loaded |
---|
| 927 | if(!GetPlayer()) // needed because STATUS_AUTHED |
---|
| 928 | { |
---|
| 929 | if(unkn!=0) |
---|
| 930 | sLog.outError("CMSG_GROUP_PASS_ON_LOOT value<>0 for not-loaded character!"); |
---|
| 931 | return; |
---|
| 932 | } |
---|
| 933 | |
---|
| 934 | if(unkn!=0) |
---|
| 935 | sLog.outError("CMSG_GROUP_PASS_ON_LOOT: activation not implemented!"); |
---|
| 936 | } |
---|