[28] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 4 | * This program is free software; you can redistribute it and/or modify |
---|
| 5 | * it under the terms of the GNU General Public License as published by |
---|
| 6 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | * (at your option) any later version. |
---|
| 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program; if not, write to the Free Software |
---|
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include "Common.h" |
---|
| 20 | #include "WorldPacket.h" |
---|
| 21 | #include "Opcodes.h" |
---|
| 22 | #include "Log.h" |
---|
| 23 | #include "Player.h" |
---|
| 24 | #include "ObjectMgr.h" |
---|
| 25 | #include "WorldSession.h" |
---|
| 26 | #include "MapManager.h" |
---|
| 27 | #include "ObjectAccessor.h" |
---|
| 28 | #include "Object.h" |
---|
| 29 | #include "Chat.h" |
---|
| 30 | #include "Language.h" |
---|
| 31 | #include "BattleGroundMgr.h" |
---|
| 32 | #include "BattleGroundWS.h" |
---|
| 33 | #include "BattleGround.h" |
---|
| 34 | #include "ArenaTeam.h" |
---|
| 35 | |
---|
| 36 | void WorldSession::HandleBattleGroundHelloOpcode( WorldPacket & recv_data ) |
---|
| 37 | { |
---|
| 38 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
| 39 | |
---|
| 40 | uint64 guid; |
---|
| 41 | recv_data >> guid; |
---|
| 42 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_HELLO Message from: " I64FMT, guid); |
---|
| 43 | |
---|
| 44 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
| 45 | if(!unit) |
---|
| 46 | return; |
---|
| 47 | |
---|
| 48 | if(!unit->isBattleMaster()) // it's not battlemaster |
---|
| 49 | return; |
---|
| 50 | |
---|
| 51 | // Stop the npc if moving |
---|
| 52 | unit->StopMoving(); |
---|
| 53 | |
---|
| 54 | uint32 bgTypeId = objmgr.GetBattleMasterBG(unit->GetEntry()); |
---|
| 55 | |
---|
| 56 | if(!_player->GetBGAccessByLevel(bgTypeId)) |
---|
| 57 | { |
---|
| 58 | // temp, must be gossip message... |
---|
| 59 | SendNotification(LANG_YOUR_BG_LEVEL_REQ_ERROR); |
---|
| 60 | return; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | SendBattlegGroundList(guid, bgTypeId); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | void WorldSession::SendBattlegGroundList( uint64 guid, uint32 bgTypeId ) |
---|
| 67 | { |
---|
| 68 | WorldPacket data; |
---|
| 69 | sBattleGroundMgr.BuildBattleGroundListPacket(&data, guid, _player, bgTypeId); |
---|
| 70 | SendPacket( &data ); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void WorldSession::HandleBattleGroundJoinOpcode( WorldPacket & recv_data ) |
---|
| 74 | { |
---|
| 75 | CHECK_PACKET_SIZE(recv_data, 8+4+4+1); |
---|
| 76 | |
---|
| 77 | uint64 guid; |
---|
| 78 | uint32 bgTypeId; |
---|
| 79 | uint32 instanceId; |
---|
| 80 | uint8 joinAsGroup; |
---|
| 81 | Group * grp; |
---|
| 82 | |
---|
| 83 | recv_data >> guid; // battlemaster guid |
---|
| 84 | recv_data >> bgTypeId; // battleground type id (DBC id) |
---|
| 85 | recv_data >> instanceId; // instance id, 0 if First Available selected |
---|
| 86 | recv_data >> joinAsGroup; // join as group |
---|
| 87 | |
---|
| 88 | if(bgTypeId >= MAX_BATTLEGROUND_TYPES) |
---|
| 89 | { |
---|
| 90 | sLog.outError("Battleground: invalid bgtype received. possible cheater? player guid %u",_player->GetGUIDLow()); |
---|
| 91 | return; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_JOIN Message from: " I64FMT, guid); |
---|
| 95 | |
---|
| 96 | // can do this, since it's battleground, not arena |
---|
| 97 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId, 0); |
---|
| 98 | |
---|
| 99 | // ignore if we already in BG or BG queue |
---|
| 100 | if(_player->InBattleGround()) |
---|
| 101 | return; |
---|
| 102 | |
---|
| 103 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
| 104 | if(!unit) |
---|
| 105 | return; |
---|
| 106 | |
---|
| 107 | if(!unit->isBattleMaster()) // it's not battlemaster |
---|
| 108 | return; |
---|
| 109 | |
---|
| 110 | // get bg instance or bg template if instance not found |
---|
| 111 | BattleGround * bg = 0; |
---|
| 112 | if(instanceId) |
---|
| 113 | BattleGround *bg = sBattleGroundMgr.GetBattleGround(instanceId); |
---|
| 114 | |
---|
| 115 | if(!bg && !(bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId))) |
---|
| 116 | { |
---|
| 117 | sLog.outError("Battleground: no available bg / template found"); |
---|
| 118 | return; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // check queueing conditions |
---|
| 122 | if(!joinAsGroup) |
---|
| 123 | { |
---|
| 124 | // check Deserter debuff |
---|
| 125 | if( !_player->CanJoinToBattleground() ) |
---|
| 126 | { |
---|
| 127 | WorldPacket data(SMSG_GROUP_JOINED_BATTLEGROUND, 4); |
---|
| 128 | data << (uint32) 0xFFFFFFFE; |
---|
| 129 | _player->GetSession()->SendPacket(&data); |
---|
| 130 | return; |
---|
| 131 | } |
---|
| 132 | // check if already in queue |
---|
| 133 | if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES) |
---|
| 134 | //player is already in this queue |
---|
| 135 | return; |
---|
| 136 | // check if has free queue slots |
---|
| 137 | if(!_player->HasFreeBattleGroundQueueId()) |
---|
| 138 | return; |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | { |
---|
| 142 | grp = _player->GetGroup(); |
---|
| 143 | // no group found, error |
---|
| 144 | if(!grp) |
---|
| 145 | return; |
---|
| 146 | uint32 err = grp->CanJoinBattleGroundQueue(bgTypeId, bgQueueTypeId, 0, bg->GetMaxPlayersPerTeam(), false, 0); |
---|
| 147 | switch(err) |
---|
| 148 | { |
---|
| 149 | // TODO: add error-based feedback to players in all cases |
---|
| 150 | case BG_JOIN_ERR_GROUP_TOO_MANY: |
---|
| 151 | { |
---|
| 152 | WorldPacket data; |
---|
| 153 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_TOO_LARGE), NULL); |
---|
| 154 | SendPacket(&data); |
---|
| 155 | } |
---|
| 156 | return; |
---|
| 157 | break; |
---|
| 158 | case BG_JOIN_ERR_OFFLINE_MEMBER: |
---|
| 159 | { |
---|
| 160 | WorldPacket data; |
---|
| 161 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_OFFLINE_MEMBER), NULL); |
---|
| 162 | SendPacket(&data); |
---|
| 163 | } |
---|
| 164 | return; |
---|
| 165 | break; |
---|
| 166 | case BG_JOIN_ERR_MIXED_FACTION: |
---|
| 167 | { |
---|
| 168 | WorldPacket data; |
---|
| 169 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_FACTION), NULL); |
---|
| 170 | SendPacket(&data); |
---|
| 171 | } |
---|
| 172 | return; |
---|
| 173 | break; |
---|
| 174 | case BG_JOIN_ERR_MIXED_LEVELS: |
---|
| 175 | { |
---|
| 176 | WorldPacket data; |
---|
| 177 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_LEVELS), NULL); |
---|
| 178 | SendPacket(&data); |
---|
| 179 | } |
---|
| 180 | return; |
---|
| 181 | break; |
---|
| 182 | case BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE: |
---|
| 183 | { |
---|
| 184 | WorldPacket data; |
---|
| 185 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_ALREADY_IN_QUEUE), NULL); |
---|
| 186 | SendPacket(&data); |
---|
| 187 | } |
---|
| 188 | return; |
---|
| 189 | break; |
---|
| 190 | case BG_JOIN_ERR_GROUP_DESERTER: |
---|
| 191 | { |
---|
| 192 | WorldPacket data; |
---|
| 193 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_DESERTER), NULL); |
---|
| 194 | SendPacket(&data); |
---|
| 195 | } |
---|
| 196 | return; |
---|
| 197 | break; |
---|
| 198 | case BG_JOIN_ERR_ALL_QUEUES_USED: |
---|
| 199 | { |
---|
| 200 | WorldPacket data; |
---|
| 201 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_NO_FREE_QUEUE_SLOTS), NULL); |
---|
| 202 | SendPacket(&data); |
---|
| 203 | } |
---|
| 204 | return; |
---|
| 205 | break; |
---|
| 206 | // all ok, can join |
---|
| 207 | case BG_JOIN_ERR_OK: |
---|
| 208 | break; |
---|
| 209 | // these aren't possible outcomes in bgs |
---|
| 210 | case BG_JOIN_ERR_GROUP_NOT_ENOUGH: |
---|
| 211 | case BG_JOIN_ERR_MIXED_ARENATEAM: |
---|
| 212 | return; |
---|
| 213 | break; |
---|
| 214 | // not the above? shouldn't happen, don't let join |
---|
| 215 | default: |
---|
| 216 | return; |
---|
| 217 | break; |
---|
| 218 | }; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | // if we're here, then the conditions to join a bg are met. We can proceed in joining. |
---|
| 222 | |
---|
| 223 | // _player->GetGroup() was already checked, grp is already initialized |
---|
| 224 | if(joinAsGroup /* && _player->GetGroup()*/) |
---|
| 225 | { |
---|
| 226 | sLog.outDebug("Battleground: the following players are joining as group:"); |
---|
| 227 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, 0, false, 0); |
---|
| 228 | for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
| 229 | { |
---|
| 230 | Player *member = itr->getSource(); |
---|
| 231 | if(!member) continue; // this should never happen |
---|
| 232 | |
---|
| 233 | uint32 queueSlot = member->AddBattleGroundQueueId(bgQueueTypeId); // add to queue |
---|
| 234 | |
---|
| 235 | // store entry point coords (same as leader entry point) |
---|
| 236 | member->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
| 237 | |
---|
| 238 | WorldPacket data; |
---|
| 239 | // send status packet (in queue) |
---|
| 240 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, member->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0); |
---|
| 241 | member->GetSession()->SendPacket(&data); |
---|
| 242 | sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, bgTypeId); |
---|
| 243 | member->GetSession()->SendPacket(&data); |
---|
| 244 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(member, ginfo); |
---|
| 245 | sLog.outDebug("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,member->GetGUIDLow(), member->GetName()); |
---|
| 246 | } |
---|
| 247 | sLog.outDebug("Battleground: group end"); |
---|
| 248 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel()); |
---|
| 249 | } |
---|
| 250 | else |
---|
| 251 | { |
---|
| 252 | // already checked if queueSlot is valid, now just get it |
---|
| 253 | uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId); |
---|
| 254 | // store entry point coords |
---|
| 255 | _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
| 256 | |
---|
| 257 | WorldPacket data; |
---|
| 258 | // send status packet (in queue) |
---|
| 259 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0); |
---|
| 260 | SendPacket(&data); |
---|
| 261 | |
---|
| 262 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, 0, false, 0); |
---|
| 263 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(_player, ginfo); |
---|
| 264 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel()); |
---|
| 265 | sLog.outDebug("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName()); |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | void WorldSession::HandleBattleGroundPlayerPositionsOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 270 | { |
---|
| 271 | // empty opcode |
---|
| 272 | sLog.outDebug("WORLD: Recvd MSG_BATTLEGROUND_PLAYER_POSITIONS Message"); |
---|
| 273 | |
---|
| 274 | BattleGround *bg = _player->GetBattleGround(); |
---|
| 275 | if(!bg) // can't be received if player not in battleground |
---|
| 276 | return; |
---|
| 277 | |
---|
| 278 | if(bg->GetTypeID() == BATTLEGROUND_WS) |
---|
| 279 | { |
---|
| 280 | uint32 count1 = 0; |
---|
| 281 | uint32 count2 = 0; |
---|
| 282 | |
---|
| 283 | Player *ap = objmgr.GetPlayer(((BattleGroundWS*)bg)->GetAllianceFlagPickerGUID()); |
---|
| 284 | if(ap) ++count2; |
---|
| 285 | |
---|
| 286 | Player *hp = objmgr.GetPlayer(((BattleGroundWS*)bg)->GetHordeFlagPickerGUID()); |
---|
| 287 | if(hp) ++count2; |
---|
| 288 | |
---|
| 289 | WorldPacket data(MSG_BATTLEGROUND_PLAYER_POSITIONS, (4+4+16*count1+16*count2)); |
---|
| 290 | data << count1; // alliance flag holders count |
---|
| 291 | /*for(uint8 i = 0; i < count1; i++) |
---|
| 292 | { |
---|
| 293 | data << uint64(0); // guid |
---|
| 294 | data << (float)0; // x |
---|
| 295 | data << (float)0; // y |
---|
| 296 | }*/ |
---|
| 297 | data << count2; // horde flag holders count |
---|
| 298 | if(ap) |
---|
| 299 | { |
---|
| 300 | data << (uint64)ap->GetGUID(); |
---|
| 301 | data << (float)ap->GetPositionX(); |
---|
| 302 | data << (float)ap->GetPositionY(); |
---|
| 303 | } |
---|
| 304 | if(hp) |
---|
| 305 | { |
---|
| 306 | data << (uint64)hp->GetGUID(); |
---|
| 307 | data << (float)hp->GetPositionX(); |
---|
| 308 | data << (float)hp->GetPositionY(); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | SendPacket(&data); |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | void WorldSession::HandleBattleGroundPVPlogdataOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 316 | { |
---|
| 317 | sLog.outDebug( "WORLD: Recvd MSG_PVP_LOG_DATA Message"); |
---|
| 318 | |
---|
| 319 | BattleGround *bg = _player->GetBattleGround(); |
---|
| 320 | if(!bg) |
---|
| 321 | return; |
---|
| 322 | |
---|
| 323 | WorldPacket data; |
---|
| 324 | sBattleGroundMgr.BuildPvpLogDataPacket(&data, bg); |
---|
| 325 | SendPacket(&data); |
---|
| 326 | |
---|
| 327 | sLog.outDebug( "WORLD: Sent MSG_PVP_LOG_DATA Message"); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | void WorldSession::HandleBattleGroundListOpcode( WorldPacket &recv_data ) |
---|
| 331 | { |
---|
| 332 | CHECK_PACKET_SIZE(recv_data, 4); |
---|
| 333 | |
---|
| 334 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEFIELD_LIST Message"); |
---|
| 335 | |
---|
| 336 | uint32 bgTypeId; |
---|
| 337 | recv_data >> bgTypeId; // id from DBC |
---|
| 338 | |
---|
| 339 | if(bgTypeId >= MAX_BATTLEGROUND_TYPES) |
---|
| 340 | { |
---|
| 341 | sLog.outError("Battleground: invalid bgtype received."); |
---|
| 342 | return; |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId); |
---|
| 346 | |
---|
| 347 | if(!bl) |
---|
| 348 | return; |
---|
| 349 | |
---|
| 350 | WorldPacket data; |
---|
| 351 | sBattleGroundMgr.BuildBattleGroundListPacket(&data, _player->GetGUID(), _player, bgTypeId); |
---|
| 352 | SendPacket( &data ); |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | void WorldSession::HandleBattleGroundPlayerPortOpcode( WorldPacket &recv_data ) |
---|
| 356 | { |
---|
| 357 | CHECK_PACKET_SIZE(recv_data, 1+1+4+2+1); |
---|
| 358 | |
---|
| 359 | sLog.outDebug( "WORLD: Recvd CMSG_BATTLEFIELD_PORT Message"); |
---|
| 360 | |
---|
| 361 | uint8 type; // arenatype if arena |
---|
| 362 | uint8 unk2; // unk, can be 0x0 (may be if was invited?) and 0x1 |
---|
| 363 | uint32 instanceId; |
---|
| 364 | uint32 bgTypeId; // type id from dbc |
---|
| 365 | uint16 unk; // 0x1F90 constant? |
---|
| 366 | uint8 action; // enter battle 0x1, leave queue 0x0 |
---|
| 367 | |
---|
| 368 | recv_data >> type >> unk2 >> bgTypeId >> unk >> action; |
---|
| 369 | |
---|
| 370 | if(bgTypeId >= MAX_BATTLEGROUND_TYPES) |
---|
| 371 | { |
---|
| 372 | sLog.outError("Battleground: invalid bgtype received."); |
---|
| 373 | // update battleground slots for the player to fix his UI and sent data. |
---|
| 374 | // this is a HACK, I don't know why the client starts sending invalid packets in the first place. |
---|
| 375 | // it usually happens with extremely high latency (if debugging / stepping in the code for example) |
---|
| 376 | if(_player->InBattleGroundQueue()) |
---|
| 377 | { |
---|
| 378 | // update all queues, send invitation info if player is invited, queue info if queued |
---|
| 379 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
| 380 | { |
---|
| 381 | uint32 queue_id = _player->GetBattleGroundQueueId(i); |
---|
| 382 | if(!queue_id) |
---|
| 383 | continue; |
---|
| 384 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
| 385 | // if the player is not in queue, contine |
---|
| 386 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
| 387 | continue; |
---|
| 388 | |
---|
| 389 | // no group information, this should never happen |
---|
| 390 | if(!itrPlayerStatus->second.GroupInfo) |
---|
| 391 | continue; |
---|
| 392 | |
---|
| 393 | BattleGround * bg = NULL; |
---|
| 394 | |
---|
| 395 | // get possibly needed data from groupinfo |
---|
| 396 | bgTypeId = itrPlayerStatus->second.GroupInfo->BgTypeId; |
---|
| 397 | uint8 arenatype = itrPlayerStatus->second.GroupInfo->ArenaType; |
---|
| 398 | uint8 israted = itrPlayerStatus->second.GroupInfo->IsRated; |
---|
| 399 | uint8 status = 0; |
---|
| 400 | |
---|
| 401 | |
---|
| 402 | if(!itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID) |
---|
| 403 | { |
---|
| 404 | // not invited to bg, get template |
---|
| 405 | bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId); |
---|
| 406 | status = STATUS_WAIT_QUEUE; |
---|
| 407 | } |
---|
| 408 | else |
---|
| 409 | { |
---|
| 410 | // get the bg we're invited to |
---|
| 411 | BattleGround * bg = sBattleGroundMgr.GetBattleGround(itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID); |
---|
| 412 | status = STATUS_WAIT_JOIN; |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | // if bg not found, then continue |
---|
| 416 | if(!bg) |
---|
| 417 | continue; |
---|
| 418 | |
---|
| 419 | // don't invite if already in the instance |
---|
| 420 | if(_player->InBattleGround() && _player->GetBattleGround() && _player->GetBattleGround()->GetInstanceID() == bg->GetInstanceID()) |
---|
| 421 | continue; |
---|
| 422 | |
---|
| 423 | // re - invite player with proper data |
---|
| 424 | WorldPacket data; |
---|
| 425 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, itrPlayerStatus->second.GroupInfo->Team?itrPlayerStatus->second.GroupInfo->Team:_player->GetTeam(), i, status, INVITE_ACCEPT_WAIT_TIME, 0, arenatype, israted); |
---|
| 426 | SendPacket(&data); |
---|
| 427 | } |
---|
| 428 | } |
---|
| 429 | return; |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | uint32 bgQueueTypeId = 0; |
---|
| 433 | // get the bg what we were invited to |
---|
| 434 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus; |
---|
| 435 | bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId,type); |
---|
| 436 | itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
| 437 | |
---|
| 438 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
| 439 | { |
---|
| 440 | sLog.outError("Battleground: itrplayerstatus not found."); |
---|
| 441 | return; |
---|
| 442 | } |
---|
| 443 | instanceId = itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID; |
---|
| 444 | |
---|
| 445 | // if action == 1, then instanceId is _required_ |
---|
| 446 | if(!instanceId && action == 1) |
---|
| 447 | { |
---|
| 448 | sLog.outError("Battleground: instance not found."); |
---|
| 449 | return; |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | BattleGround *bg = sBattleGroundMgr.GetBattleGround(instanceId); |
---|
| 453 | |
---|
| 454 | // bg template might and must be used in case of leaving queue, when instance is not created yet |
---|
| 455 | if(!bg && action == 0) |
---|
| 456 | bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId); |
---|
| 457 | |
---|
| 458 | if(!bg) |
---|
| 459 | { |
---|
| 460 | sLog.outError("Battleground: bg not found."); |
---|
| 461 | return; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | bgTypeId = bg->GetTypeID(); |
---|
| 465 | |
---|
| 466 | if(_player->InBattleGroundQueue()) |
---|
| 467 | { |
---|
| 468 | uint32 queueSlot = 0; |
---|
| 469 | uint32 team = 0; |
---|
| 470 | uint32 arenatype = 0; |
---|
| 471 | uint32 israted = 0; |
---|
| 472 | uint32 rating = 0; |
---|
| 473 | // get the team info from the queue |
---|
| 474 | BattleGroundQueue::QueuedPlayersMap::iterator pitr = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
| 475 | if(pitr !=sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end() |
---|
| 476 | && pitr->second.GroupInfo ) |
---|
| 477 | { |
---|
| 478 | team = pitr->second.GroupInfo->Team; |
---|
| 479 | arenatype = pitr->second.GroupInfo->ArenaType; |
---|
| 480 | israted = pitr->second.GroupInfo->IsRated; |
---|
| 481 | rating = pitr->second.GroupInfo->ArenaTeamRating; |
---|
| 482 | } |
---|
| 483 | else |
---|
| 484 | { |
---|
| 485 | sLog.outError("Battleground: Invalid player queue info!"); |
---|
| 486 | return; |
---|
| 487 | } |
---|
| 488 | WorldPacket data; |
---|
| 489 | switch(action) |
---|
| 490 | { |
---|
| 491 | case 1: // port to battleground |
---|
| 492 | if(!_player->IsInvitedForBattleGroundQueueType(bgQueueTypeId)) |
---|
| 493 | return; // cheating? |
---|
| 494 | // resurrect the player |
---|
| 495 | if(!_player->isAlive()) |
---|
| 496 | { |
---|
| 497 | _player->ResurrectPlayer(1.0f,false); |
---|
| 498 | _player->SpawnCorpseBones(); |
---|
| 499 | } |
---|
| 500 | // stop taxi flight at port |
---|
| 501 | if(_player->isInFlight()) |
---|
| 502 | { |
---|
| 503 | _player->GetMotionMaster()->MovementExpired(); |
---|
| 504 | _player->m_taxi.ClearTaxiDestinations(); |
---|
| 505 | } |
---|
| 506 | _player->RemoveFromGroup(); |
---|
| 507 | queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId); |
---|
| 508 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime()); |
---|
| 509 | _player->GetSession()->SendPacket(&data); |
---|
| 510 | // remove battleground queue status from BGmgr |
---|
| 511 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].RemovePlayer(_player->GetGUID(), false); |
---|
| 512 | // this is still needed here if battleground "jumping" shouldn't add deserter debuff |
---|
| 513 | // also this required to prevent stuck at old battleground after SetBattleGroundId set to new |
---|
| 514 | if( BattleGround *currentBg = _player->GetBattleGround() ) |
---|
| 515 | currentBg->RemovePlayerAtLeave(_player->GetGUID(), false, true); |
---|
| 516 | |
---|
| 517 | // set the destination instance id |
---|
| 518 | _player->SetBattleGroundId(bg->GetInstanceID()); |
---|
| 519 | // set the destination team |
---|
| 520 | _player->SetBGTeam(team); |
---|
| 521 | // bg->HandleBeforeTeleportToBattleGround(_player); |
---|
| 522 | sBattleGroundMgr.SendToBattleGround(_player, instanceId); |
---|
| 523 | // add only in HandleMoveWorldPortAck() |
---|
| 524 | // bg->AddPlayer(_player,team); |
---|
| 525 | sLog.outDebug("Battleground: player %s (%u) joined battle for bg %u, bgtype %u, queue type %u.",_player->GetName(),_player->GetGUIDLow(),bg->GetInstanceID(),bg->GetTypeID(),bgQueueTypeId); |
---|
| 526 | break; |
---|
| 527 | case 0: // leave queue |
---|
| 528 | queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId); |
---|
| 529 | _player->RemoveBattleGroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs |
---|
| 530 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_NONE, 0, 0); |
---|
| 531 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].RemovePlayer(_player->GetGUID(), true); |
---|
| 532 | // player left queue, we should update it, maybe now his group fits in |
---|
| 533 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId,_player->GetBattleGroundQueueIdFromLevel(),arenatype,israted,rating); |
---|
| 534 | SendPacket(&data); |
---|
| 535 | sLog.outDebug("Battleground: player %s (%u) left queue for bgtype %u, queue type %u.",_player->GetName(),_player->GetGUIDLow(),bg->GetTypeID(),bgQueueTypeId); |
---|
| 536 | break; |
---|
| 537 | default: |
---|
| 538 | sLog.outError("Battleground port: unknown action %u", action); |
---|
| 539 | break; |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | } |
---|
| 543 | |
---|
| 544 | void WorldSession::HandleBattleGroundLeaveOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 545 | { |
---|
| 546 | //CHECK_PACKET_SIZE(recv_data, 1+1+4+2); |
---|
| 547 | |
---|
| 548 | sLog.outDebug( "WORLD: Recvd CMSG_LEAVE_BATTLEFIELD Message"); |
---|
| 549 | |
---|
| 550 | //uint8 unk1, unk2; |
---|
| 551 | //uint32 bgTypeId; // id from DBC |
---|
| 552 | //uint16 unk3; |
---|
| 553 | |
---|
| 554 | //recv_data >> unk1 >> unk2 >> bgTypeId >> unk3; - no used currently |
---|
| 555 | |
---|
| 556 | //if(bgTypeId >= MAX_BATTLEGROUND_TYPES) // cheating? but not important in this case |
---|
| 557 | // return; |
---|
| 558 | |
---|
| 559 | // not allow leave battleground in combat |
---|
| 560 | if(_player->isInCombat()) |
---|
| 561 | if(BattleGround* bg = _player->GetBattleGround()) |
---|
| 562 | if(bg->GetStatus() != STATUS_WAIT_LEAVE) |
---|
| 563 | return; |
---|
| 564 | |
---|
| 565 | _player->LeaveBattleground(); |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | void WorldSession::HandleBattlefieldStatusOpcode( WorldPacket & /*recv_data*/ ) |
---|
| 569 | { |
---|
| 570 | // empty opcode |
---|
| 571 | sLog.outDebug( "WORLD: Battleground status" ); |
---|
| 572 | |
---|
| 573 | WorldPacket data; |
---|
| 574 | |
---|
| 575 | // TODO: we must put player back to battleground in case disconnect (< 5 minutes offline time) or teleport player on login(!) from battleground map to entry point |
---|
| 576 | if(_player->InBattleGround()) |
---|
| 577 | { |
---|
| 578 | BattleGround *bg = _player->GetBattleGround(); |
---|
| 579 | if(bg) |
---|
| 580 | { |
---|
| 581 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bg->GetTypeID(), bg->GetArenaType()); |
---|
| 582 | uint32 queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId); |
---|
| 583 | if((bg->GetStatus() <= STATUS_IN_PROGRESS)) |
---|
| 584 | { |
---|
| 585 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime()); |
---|
| 586 | SendPacket(&data); |
---|
| 587 | } |
---|
| 588 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
| 589 | { |
---|
| 590 | uint32 queue_id = _player->GetBattleGroundQueueId(i); // battlegroundqueueid stores the type id, not the instance id, so this is definitely wrong |
---|
| 591 | uint8 arenatype = sBattleGroundMgr.BGArenaType(queue_id); |
---|
| 592 | uint8 isRated = 0; |
---|
| 593 | if (i == queueSlot || !queue_id) // we need to get the instance ids |
---|
| 594 | continue; |
---|
| 595 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
| 596 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
| 597 | continue; |
---|
| 598 | if(itrPlayerStatus->second.GroupInfo) |
---|
| 599 | { |
---|
| 600 | arenatype = itrPlayerStatus->second.GroupInfo->ArenaType; |
---|
| 601 | isRated = itrPlayerStatus->second.GroupInfo->IsRated; |
---|
| 602 | } |
---|
| 603 | BattleGround *bg2 = sBattleGroundMgr.GetBattleGroundTemplate(sBattleGroundMgr.BGTemplateId(queue_id)); // try this |
---|
| 604 | if(bg2) |
---|
| 605 | { |
---|
| 606 | //in this call is small bug, this call should be filled by player's waiting time in queue |
---|
| 607 | //this call nulls all timers for client : |
---|
| 608 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg2, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0,arenatype,isRated); |
---|
| 609 | SendPacket(&data); |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | else |
---|
| 615 | { |
---|
| 616 | // we should update all queues? .. i'm not sure if this code is correct |
---|
| 617 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
| 618 | { |
---|
| 619 | uint32 queue_id = _player->GetBattleGroundQueueId(i); |
---|
| 620 | if(!queue_id) |
---|
| 621 | continue; |
---|
| 622 | uint32 bgTypeId = sBattleGroundMgr.BGTemplateId(queue_id); |
---|
| 623 | uint8 arenatype = sBattleGroundMgr.BGArenaType(queue_id); |
---|
| 624 | uint8 isRated = 0; |
---|
| 625 | BattleGround *bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId); |
---|
| 626 | BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID()); |
---|
| 627 | if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()) |
---|
| 628 | continue; |
---|
| 629 | if(itrPlayerStatus->second.GroupInfo) |
---|
| 630 | { |
---|
| 631 | arenatype = itrPlayerStatus->second.GroupInfo->ArenaType; |
---|
| 632 | isRated = itrPlayerStatus->second.GroupInfo->IsRated; |
---|
| 633 | } |
---|
| 634 | if(bg && queue_id) |
---|
| 635 | { |
---|
| 636 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated); |
---|
| 637 | SendPacket(&data); |
---|
| 638 | } |
---|
| 639 | } |
---|
| 640 | } |
---|
| 641 | /* else // not sure if it needed... |
---|
| 642 | { |
---|
| 643 | for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++) |
---|
| 644 | { |
---|
| 645 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, NULL, _player->GetTeam(),i , STATUS_NONE, 0, 0); |
---|
| 646 | SendPacket(&data); |
---|
| 647 | } |
---|
| 648 | }*/ |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | void WorldSession::HandleAreaSpiritHealerQueryOpcode( WorldPacket & recv_data ) |
---|
| 652 | { |
---|
| 653 | sLog.outDebug("WORLD: CMSG_AREA_SPIRIT_HEALER_QUERY"); |
---|
| 654 | |
---|
| 655 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
| 656 | |
---|
| 657 | BattleGround *bg = _player->GetBattleGround(); |
---|
| 658 | if(!bg) |
---|
| 659 | return; |
---|
| 660 | |
---|
| 661 | uint64 guid; |
---|
| 662 | recv_data >> guid; |
---|
| 663 | |
---|
| 664 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
| 665 | if(!unit) |
---|
| 666 | return; |
---|
| 667 | |
---|
| 668 | if(!unit->isSpiritService()) // it's not spirit service |
---|
| 669 | return; |
---|
| 670 | |
---|
| 671 | sBattleGroundMgr.SendAreaSpiritHealerQueryOpcode(_player, bg, guid); |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | void WorldSession::HandleAreaSpiritHealerQueueOpcode( WorldPacket & recv_data ) |
---|
| 675 | { |
---|
| 676 | sLog.outDebug("WORLD: CMSG_AREA_SPIRIT_HEALER_QUEUE"); |
---|
| 677 | |
---|
| 678 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
| 679 | |
---|
| 680 | BattleGround *bg = _player->GetBattleGround(); |
---|
| 681 | if(!bg) |
---|
| 682 | return; |
---|
| 683 | |
---|
| 684 | uint64 guid; |
---|
| 685 | recv_data >> guid; |
---|
| 686 | |
---|
| 687 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
| 688 | if(!unit) |
---|
| 689 | return; |
---|
| 690 | |
---|
| 691 | if(!unit->isSpiritService()) // it's not spirit service |
---|
| 692 | return; |
---|
| 693 | |
---|
| 694 | bg->AddPlayerToResurrectQueue(guid, _player->GetGUID()); |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | void WorldSession::HandleBattleGroundArenaJoin( WorldPacket & recv_data ) |
---|
| 698 | { |
---|
| 699 | CHECK_PACKET_SIZE(recv_data, 8+1+1+1); |
---|
| 700 | |
---|
| 701 | sLog.outDebug("WORLD: CMSG_BATTLEMASTER_JOIN_ARENA"); |
---|
| 702 | recv_data.hexlike(); |
---|
| 703 | |
---|
| 704 | // ignore if we already in BG or BG queue |
---|
| 705 | if(_player->InBattleGround()) |
---|
| 706 | return; |
---|
| 707 | |
---|
| 708 | uint64 guid; // arena Battlemaster guid |
---|
| 709 | uint8 type; // 2v2, 3v3 or 5v5 |
---|
| 710 | uint8 asGroup; // asGroup |
---|
| 711 | uint8 isRated; // isRated |
---|
| 712 | Group * grp; |
---|
| 713 | |
---|
| 714 | recv_data >> guid >> type >> asGroup >> isRated; |
---|
| 715 | |
---|
| 716 | Creature *unit = ObjectAccessor::GetCreature(*_player, guid); |
---|
| 717 | if(!unit) |
---|
| 718 | return; |
---|
| 719 | |
---|
| 720 | if(!unit->isBattleMaster()) // it's not battle master |
---|
| 721 | return; |
---|
| 722 | |
---|
| 723 | uint8 arenatype = 0; |
---|
| 724 | uint32 arenaRating = 0; |
---|
| 725 | |
---|
| 726 | switch(type) |
---|
| 727 | { |
---|
| 728 | case 0: |
---|
| 729 | arenatype = ARENA_TYPE_2v2; |
---|
| 730 | break; |
---|
| 731 | case 1: |
---|
| 732 | arenatype = ARENA_TYPE_3v3; |
---|
| 733 | break; |
---|
| 734 | case 2: |
---|
| 735 | arenatype = ARENA_TYPE_5v5; |
---|
| 736 | break; |
---|
| 737 | default: |
---|
| 738 | sLog.outError("Unknown arena type %u at HandleBattleGroundArenaJoin()", type); |
---|
| 739 | return; |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | //check existance |
---|
| 743 | BattleGround* bg = NULL; |
---|
| 744 | if( !(bg = sBattleGroundMgr.GetBattleGroundTemplate(BATTLEGROUND_AA)) ) |
---|
| 745 | { |
---|
| 746 | sLog.outError("Battleground: template bg (all arenas) not found"); |
---|
| 747 | return; |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | uint8 bgTypeId = bg->GetTypeID(); |
---|
| 751 | uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId, arenatype); |
---|
| 752 | |
---|
| 753 | // check queueing conditions |
---|
| 754 | if(!asGroup) |
---|
| 755 | { |
---|
| 756 | // check if already in queue |
---|
| 757 | if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES) |
---|
| 758 | //player is already in this queue |
---|
| 759 | return; |
---|
| 760 | // check if has free queue slots |
---|
| 761 | if(!_player->HasFreeBattleGroundQueueId()) |
---|
| 762 | return; |
---|
| 763 | } |
---|
| 764 | else |
---|
| 765 | { |
---|
| 766 | grp = _player->GetGroup(); |
---|
| 767 | // no group found, error |
---|
| 768 | if(!grp) |
---|
| 769 | return; |
---|
| 770 | uint32 err = grp->CanJoinBattleGroundQueue(bgTypeId, bgQueueTypeId, arenatype, arenatype, (bool)isRated, type); |
---|
| 771 | switch(err) |
---|
| 772 | { |
---|
| 773 | // TODO: add error-based feedback to players in all cases |
---|
| 774 | case BG_JOIN_ERR_GROUP_TOO_MANY: |
---|
| 775 | { |
---|
| 776 | WorldPacket data; |
---|
| 777 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_ARENA_GROUP_TOO_LARGE), NULL); |
---|
| 778 | SendPacket(&data); |
---|
| 779 | } |
---|
| 780 | return; |
---|
| 781 | break; |
---|
| 782 | case BG_JOIN_ERR_GROUP_NOT_ENOUGH: |
---|
| 783 | { |
---|
| 784 | WorldPacket data; |
---|
| 785 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_ARENA_NOT_ENOUGH_PLAYERS), NULL); |
---|
| 786 | SendPacket(&data); |
---|
| 787 | } |
---|
| 788 | return; |
---|
| 789 | break; |
---|
| 790 | case BG_JOIN_ERR_MIXED_ARENATEAM: |
---|
| 791 | { |
---|
| 792 | WorldPacket data; |
---|
| 793 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_ARENA_YOUR_TEAM_ONLY), NULL); |
---|
| 794 | SendPacket(&data); |
---|
| 795 | } |
---|
| 796 | return; |
---|
| 797 | break; |
---|
| 798 | case BG_JOIN_ERR_OFFLINE_MEMBER: |
---|
| 799 | { |
---|
| 800 | WorldPacket data; |
---|
| 801 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_OFFLINE_MEMBER), NULL); |
---|
| 802 | SendPacket(&data); |
---|
| 803 | } |
---|
| 804 | return; |
---|
| 805 | break; |
---|
| 806 | case BG_JOIN_ERR_MIXED_FACTION: |
---|
| 807 | { |
---|
| 808 | WorldPacket data; |
---|
| 809 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_FACTION), NULL); |
---|
| 810 | SendPacket(&data); |
---|
| 811 | } |
---|
| 812 | return; |
---|
| 813 | break; |
---|
| 814 | case BG_JOIN_ERR_MIXED_LEVELS: |
---|
| 815 | { |
---|
| 816 | WorldPacket data; |
---|
| 817 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_LEVELS), NULL); |
---|
| 818 | SendPacket(&data); |
---|
| 819 | } |
---|
| 820 | return; |
---|
| 821 | break; |
---|
| 822 | case BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE: |
---|
| 823 | { |
---|
| 824 | WorldPacket data; |
---|
| 825 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_ALREADY_IN_QUEUE), NULL); |
---|
| 826 | SendPacket(&data); |
---|
| 827 | } |
---|
| 828 | return; |
---|
| 829 | break; |
---|
| 830 | case BG_JOIN_ERR_GROUP_DESERTER: |
---|
| 831 | { |
---|
| 832 | WorldPacket data; |
---|
| 833 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_DESERTER), NULL); |
---|
| 834 | SendPacket(&data); |
---|
| 835 | } |
---|
| 836 | return; |
---|
| 837 | break; |
---|
| 838 | case BG_JOIN_ERR_ALL_QUEUES_USED: |
---|
| 839 | { |
---|
| 840 | WorldPacket data; |
---|
| 841 | ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_NO_FREE_QUEUE_SLOTS), NULL); |
---|
| 842 | SendPacket(&data); |
---|
| 843 | } |
---|
| 844 | return; |
---|
| 845 | break; |
---|
| 846 | // all ok, can join |
---|
| 847 | case BG_JOIN_ERR_OK: |
---|
| 848 | break; |
---|
| 849 | // not the above? shouldn't happen, don't let join |
---|
| 850 | default: |
---|
| 851 | return; |
---|
| 852 | break; |
---|
| 853 | }; |
---|
| 854 | } |
---|
| 855 | |
---|
| 856 | uint32 ateamId = 0; |
---|
| 857 | |
---|
| 858 | if(isRated) |
---|
| 859 | { |
---|
| 860 | ateamId = _player->GetArenaTeamId(type); |
---|
| 861 | // check real arenateam existence only here (if it was moved to group->CanJoin .. () then we would ahve to get it twice) |
---|
| 862 | ArenaTeam * at = objmgr.GetArenaTeamById(ateamId); |
---|
| 863 | if(!at) |
---|
| 864 | { |
---|
| 865 | _player->GetSession()->SendNotInArenaTeamPacket(arenatype); |
---|
| 866 | return; |
---|
| 867 | } |
---|
| 868 | // get the team rating for queueing |
---|
| 869 | arenaRating = at->GetRating(); |
---|
| 870 | // the arenateam id must match for everyone in the group |
---|
| 871 | // get the personal ratings for queueing |
---|
| 872 | uint32 avg_pers_rating = 0; |
---|
| 873 | for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
| 874 | { |
---|
| 875 | Player *member = itr->getSource(); |
---|
| 876 | |
---|
| 877 | // calc avg personal rating |
---|
| 878 | avg_pers_rating += member->GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (type*6) + 5); |
---|
| 879 | } |
---|
| 880 | |
---|
| 881 | if( arenatype ) |
---|
| 882 | avg_pers_rating /= arenatype; |
---|
| 883 | |
---|
| 884 | // if avg personal rating is more than 150 points below the teams rating, the team will be queued against an opponent matching or similar to the average personal rating |
---|
| 885 | if(avg_pers_rating + 150 < arenaRating) |
---|
| 886 | arenaRating = avg_pers_rating; |
---|
| 887 | } |
---|
| 888 | |
---|
| 889 | if(asGroup) |
---|
| 890 | { |
---|
| 891 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, arenatype, isRated, arenaRating, ateamId); |
---|
| 892 | sLog.outDebug("Battleground: arena join as group start"); |
---|
| 893 | if(isRated) |
---|
| 894 | sLog.outDebug("Battleground: arena team id %u, leader %s queued with rating %u for type %u",_player->GetArenaTeamId(type),_player->GetName(),arenaRating,arenatype); |
---|
| 895 | for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
| 896 | { |
---|
| 897 | Player *member = itr->getSource(); |
---|
| 898 | if(!member) continue; |
---|
| 899 | |
---|
| 900 | uint32 queueSlot = member->AddBattleGroundQueueId(bgQueueTypeId);// add to queue |
---|
| 901 | |
---|
| 902 | // store entry point coords (same as leader entry point) |
---|
| 903 | member->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
| 904 | |
---|
| 905 | WorldPacket data; |
---|
| 906 | // send status packet (in queue) |
---|
| 907 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, member->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated); |
---|
| 908 | member->GetSession()->SendPacket(&data); |
---|
| 909 | sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, bgTypeId); |
---|
| 910 | member->GetSession()->SendPacket(&data); |
---|
| 911 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(member, ginfo); |
---|
| 912 | sLog.outDebug("Battleground: player joined queue for arena as group bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,member->GetGUIDLow(), member->GetName()); |
---|
| 913 | } |
---|
| 914 | sLog.outDebug("Battleground: arena join as group end"); |
---|
| 915 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel(), arenatype, isRated, arenaRating); |
---|
| 916 | } |
---|
| 917 | else |
---|
| 918 | { |
---|
| 919 | uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId); |
---|
| 920 | |
---|
| 921 | // store entry point coords |
---|
| 922 | _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); |
---|
| 923 | |
---|
| 924 | WorldPacket data; |
---|
| 925 | // send status packet (in queue) |
---|
| 926 | sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated); |
---|
| 927 | SendPacket(&data); |
---|
| 928 | GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, arenatype, isRated, arenaRating); |
---|
| 929 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(_player, ginfo); |
---|
| 930 | sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel(), arenatype, isRated, arenaRating); |
---|
| 931 | sLog.outDebug("Battleground: player joined queue for arena, skirmish, bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName()); |
---|
| 932 | } |
---|
| 933 | } |
---|
| 934 | |
---|
| 935 | void WorldSession::HandleBattleGroundReportAFK( WorldPacket & recv_data ) |
---|
| 936 | { |
---|
| 937 | CHECK_PACKET_SIZE(recv_data, 8); |
---|
| 938 | |
---|
| 939 | uint64 playerGuid; |
---|
| 940 | recv_data >> playerGuid; |
---|
| 941 | Player *reportedPlayer = objmgr.GetPlayer(playerGuid); |
---|
| 942 | |
---|
| 943 | if(!reportedPlayer) |
---|
| 944 | { |
---|
| 945 | sLog.outDebug("WorldSession::HandleBattleGroundReportAFK: player not found"); |
---|
| 946 | return; |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | sLog.outDebug("WorldSession::HandleBattleGroundReportAFK: %s reported %s", _player->GetName(), reportedPlayer->GetName()); |
---|
| 950 | |
---|
| 951 | reportedPlayer->ReportedAfkBy(_player); |
---|
| 952 | } |
---|