From 119bff351450ea16ffda550b6e0f67379b29f708 Mon Sep 17 00:00:00 2001 From: void_17 Date: Mon, 2 Mar 2026 17:37:16 +0700 Subject: Revert "shared_ptr -> std::shared_ptr" This reverts commit 7074f35e4ba831e358117842b99ee35b87f85ae5. --- Minecraft.Client/PlayerConnection.cpp | 244 +++++++++++++++++----------------- 1 file changed, 122 insertions(+), 122 deletions(-) (limited to 'Minecraft.Client/PlayerConnection.cpp') diff --git a/Minecraft.Client/PlayerConnection.cpp b/Minecraft.Client/PlayerConnection.cpp index 393ae105..f0e538a8 100644 --- a/Minecraft.Client/PlayerConnection.cpp +++ b/Minecraft.Client/PlayerConnection.cpp @@ -34,7 +34,7 @@ Random PlayerConnection::random; -PlayerConnection::PlayerConnection(MinecraftServer *server, Connection *connection, std::shared_ptr player) +PlayerConnection::PlayerConnection(MinecraftServer *server, Connection *connection, shared_ptr player) { // 4J - added initialisers done = false; @@ -93,12 +93,12 @@ void PlayerConnection::tick() lastKeepAliveTick = tickCount; lastKeepAliveTime = System::nanoTime() / 1000000; lastKeepAliveId = random.nextInt(); - send( std::shared_ptr( new KeepAlivePacket(lastKeepAliveId) ) ); + send( shared_ptr( new KeepAlivePacket(lastKeepAliveId) ) ); } // if (!didTick) { // player->doTick(false); // } - + if (chatSpamTickCount > 0) { chatSpamTickCount--; @@ -123,30 +123,30 @@ void PlayerConnection::disconnect(DisconnectPacket::eDisconnectReason reason) // 4J Stu - Need to remove the player from the receiving list before their socket is NULLed so that we can find another player on their system server->getPlayers()->removePlayerFromReceiving( player ); - send( std::shared_ptr( new DisconnectPacket(reason) )); + send( shared_ptr( new DisconnectPacket(reason) )); connection->sendAndQuit(); // 4J-PB - removed, since it needs to be localised in the language the client is in - //server->players->broadcastAll( std::shared_ptr( new ChatPacket(L"�e" + player->name + L" left the game.") ) ); + //server->players->broadcastAll( shared_ptr( new ChatPacket(L"§e" + player->name + L" left the game.") ) ); if(getWasKicked()) { - server->getPlayers()->broadcastAll( std::shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) ); + server->getPlayers()->broadcastAll( shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) ); } else { - server->getPlayers()->broadcastAll( std::shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerLeftGame) ) ); + server->getPlayers()->broadcastAll( shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerLeftGame) ) ); } - + server->getPlayers()->remove(player); done = true; LeaveCriticalSection(&done_cs); } -void PlayerConnection::handlePlayerInput(std::shared_ptr packet) +void PlayerConnection::handlePlayerInput(shared_ptr packet) { player->setPlayerInput(packet->getXa(), packet->getYa(), packet->isJumping(), packet->isSneaking(), packet->getXRot(), packet->getYRot()); } -void PlayerConnection::handleMovePlayer(std::shared_ptr packet) +void PlayerConnection::handleMovePlayer(shared_ptr packet) { ServerLevel *level = server->getLevel(player->dimension); @@ -391,10 +391,10 @@ void PlayerConnection::teleport(double x, double y, double z, float yRot, float player->absMoveTo(x, y, z, yRot, xRot); // 4J - note that 1.62 is added to the height here as the client connection that receives this will presume it represents y + heightOffset at that end // This is different to the way that height is sent back to the server, where it represents the bottom of the player bounding volume - if(sendPacket) player->connection->send( std::shared_ptr( new MovePlayerPacket::PosRot(x, y + 1.62f, y, z, yRot, xRot, false, false) ) ); + if(sendPacket) player->connection->send( shared_ptr( new MovePlayerPacket::PosRot(x, y + 1.62f, y, z, yRot, xRot, false, false) ) ); } -void PlayerConnection::handlePlayerAction(std::shared_ptr packet) +void PlayerConnection::handlePlayerAction(shared_ptr packet) { ServerLevel *level = server->getLevel(player->dimension); @@ -442,19 +442,19 @@ void PlayerConnection::handlePlayerAction(std::shared_ptr pa if (packet->action == PlayerActionPacket::START_DESTROY_BLOCK) { if (zd > 16 || canEditSpawn) player->gameMode->startDestroyBlock(x, y, z, packet->face); - else player->connection->send( std::shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); + else player->connection->send( shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); } else if (packet->action == PlayerActionPacket::STOP_DESTROY_BLOCK) { player->gameMode->stopDestroyBlock(x, y, z); server->getPlayers()->prioritiseTileChanges(x, y, z, level->dimension->id); // 4J added - make sure that the update packets for this get prioritised over other general world updates - if (level->getTile(x, y, z) != 0) player->connection->send( std::shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); + if (level->getTile(x, y, z) != 0) player->connection->send( shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); } else if (packet->action == PlayerActionPacket::ABORT_DESTROY_BLOCK) { player->gameMode->abortDestroyBlock(x, y, z); - if (level->getTile(x, y, z) != 0) player->connection->send(std::shared_ptr( new TileUpdatePacket(x, y, z, level))); + if (level->getTile(x, y, z) != 0) player->connection->send(shared_ptr( new TileUpdatePacket(x, y, z, level))); } else if (packet->action == PlayerActionPacket::GET_UPDATED_BLOCK) { @@ -464,7 +464,7 @@ void PlayerConnection::handlePlayerAction(std::shared_ptr pa double dist = xDist * xDist + yDist * yDist + zDist * zDist; if (dist < 16 * 16) { - player->connection->send( std::shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); + player->connection->send( shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); } } @@ -473,16 +473,16 @@ void PlayerConnection::handlePlayerAction(std::shared_ptr pa } -void PlayerConnection::handleUseItem(std::shared_ptr packet) +void PlayerConnection::handleUseItem(shared_ptr packet) { ServerLevel *level = server->getLevel(player->dimension); - std::shared_ptr item = player->inventory->getSelected(); + shared_ptr item = player->inventory->getSelected(); bool informClient = false; int x = packet->getX(); int y = packet->getY(); int z = packet->getZ(); int face = packet->getFace(); - + // 4J Stu - We don't have ops, so just use the levels setting bool canEditSpawn = level->canEditSpawn; // = level->dimension->id != 0 || server->players->isOp(player->name); if (packet->getFace() == 255) @@ -509,14 +509,14 @@ void PlayerConnection::handleUseItem(std::shared_ptr packet) } else { - //player->connection->send(std::shared_ptr(new ChatPacket("\u00A77Height limit for building is " + server->maxBuildHeight))); + //player->connection->send(shared_ptr(new ChatPacket("\u00A77Height limit for building is " + server->maxBuildHeight))); informClient = true; } if (informClient) { - player->connection->send( std::shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); + player->connection->send( shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); if (face == 0) y--; if (face == 1) y++; @@ -524,7 +524,7 @@ void PlayerConnection::handleUseItem(std::shared_ptr packet) if (face == 3) z++; if (face == 4) x--; if (face == 5) x++; - + // 4J - Fixes an issue where pistons briefly disappear when retracting. The pistons themselves shouldn't have their change from being pistonBase_Id to pistonMovingPiece_Id // directly sent to the client, as this will happen on the client as a result of it actioning (via a tile event) the retraction of the piston locally. However, by putting a switch // beside a piston and then performing an action on the side of it facing a piston, the following line of code will send a TileUpdatePacket containing the change to pistonMovingPiece_Id @@ -532,7 +532,7 @@ void PlayerConnection::handleUseItem(std::shared_ptr packet) // isn't what it is expecting. if( level->getTile(x,y,z) != Tile::pistonMovingPiece_Id ) { - player->connection->send( std::shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); + player->connection->send( shared_ptr( new TileUpdatePacket(x, y, z, level) ) ); } } @@ -554,7 +554,7 @@ void PlayerConnection::handleUseItem(std::shared_ptr packet) if (!ItemInstance::matches(player->inventory->getSelected(), packet->getItem())) { - send( std::shared_ptr( new ContainerSetSlotPacket(player->containerMenu->containerId, s->index, player->inventory->getSelected()) ) ); + send( shared_ptr( new ContainerSetSlotPacket(player->containerMenu->containerId, s->index, player->inventory->getSelected()) ) ); } } @@ -569,27 +569,27 @@ void PlayerConnection::onDisconnect(DisconnectPacket::eDisconnectReason reason, if( done ) return; // logger.info(player.name + " lost connection: " + reason); // 4J-PB - removed, since it needs to be localised in the language the client is in - //server->players->broadcastAll( std::shared_ptr( new ChatPacket(L"�e" + player->name + L" left the game.") ) ); + //server->players->broadcastAll( shared_ptr( new ChatPacket(L"§e" + player->name + L" left the game.") ) ); if(getWasKicked()) { - server->getPlayers()->broadcastAll( std::shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) ); + server->getPlayers()->broadcastAll( shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerKickedFromGame) ) ); } else { - server->getPlayers()->broadcastAll( std::shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerLeftGame) ) ); + server->getPlayers()->broadcastAll( shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerLeftGame) ) ); } server->getPlayers()->remove(player); done = true; LeaveCriticalSection(&done_cs); } -void PlayerConnection::onUnhandledPacket(std::shared_ptr packet) +void PlayerConnection::onUnhandledPacket(shared_ptr packet) { // logger.warning(getClass() + " wasn't prepared to deal with a " + packet.getClass()); disconnect(DisconnectPacket::eDisconnect_UnexpectedPacket); } -void PlayerConnection::send(std::shared_ptr packet) +void PlayerConnection::send(shared_ptr packet) { if( connection->getSocket() != NULL ) { @@ -607,7 +607,7 @@ void PlayerConnection::send(std::shared_ptr packet) } // 4J Added -void PlayerConnection::queueSend(std::shared_ptr packet) +void PlayerConnection::queueSend(shared_ptr packet) { if( connection->getSocket() != NULL ) { @@ -624,7 +624,7 @@ void PlayerConnection::queueSend(std::shared_ptr packet) } } -void PlayerConnection::handleSetCarriedItem(std::shared_ptr packet) +void PlayerConnection::handleSetCarriedItem(shared_ptr packet) { if (packet->slot < 0 || packet->slot >= Inventory::getSelectionSize()) { @@ -634,7 +634,7 @@ void PlayerConnection::handleSetCarriedItem(std::shared_ptrinventory->selected = packet->slot; } -void PlayerConnection::handleChat(std::shared_ptr packet) +void PlayerConnection::handleChat(shared_ptr packet) { // 4J - TODO #if 0 @@ -678,7 +678,7 @@ void PlayerConnection::handleCommand(const wstring& message) #endif } -void PlayerConnection::handleAnimate(std::shared_ptr packet) +void PlayerConnection::handleAnimate(shared_ptr packet) { if (packet->action == AnimatePacket::SWING) { @@ -686,7 +686,7 @@ void PlayerConnection::handleAnimate(std::shared_ptr packet) } } -void PlayerConnection::handlePlayerCommand(std::shared_ptr packet) +void PlayerConnection::handlePlayerCommand(shared_ptr packet) { if (packet->action == PlayerCommandPacket::START_SNEAKING) { @@ -725,7 +725,7 @@ void PlayerConnection::setShowOnMaps(bool bVal) player->setShowOnMaps(bVal); } -void PlayerConnection::handleDisconnect(std::shared_ptr packet) +void PlayerConnection::handleDisconnect(shared_ptr packet) { // 4J Stu - Need to remove the player from the receiving list before their socket is NULLed so that we can find another player on their system server->getPlayers()->removePlayerFromReceiving( player ); @@ -740,13 +740,13 @@ int PlayerConnection::countDelayedPackets() void PlayerConnection::info(const wstring& string) { // 4J-PB - removed, since it needs to be localised in the language the client is in - //send( std::shared_ptr( new ChatPacket(L"�7" + string) ) ); + //send( shared_ptr( new ChatPacket(L"§7" + string) ) ); } void PlayerConnection::warn(const wstring& string) { // 4J-PB - removed, since it needs to be localised in the language the client is in - //send( std::shared_ptr( new ChatPacket(L"�9" + string) ) ); + //send( shared_ptr( new ChatPacket(L"§9" + string) ) ); } wstring PlayerConnection::getConsoleName() @@ -754,10 +754,10 @@ wstring PlayerConnection::getConsoleName() return player->name; } -void PlayerConnection::handleInteract(std::shared_ptr packet) +void PlayerConnection::handleInteract(shared_ptr packet) { ServerLevel *level = server->getLevel(player->dimension); - std::shared_ptr target = level->getEntity(packet->target); + shared_ptr target = level->getEntity(packet->target); // Fix for #8218 - Gameplay: Attacking zombies from a different level often results in no hits being registered // 4J Stu - If the client says that we hit something, then agree with it. The canSee can fail here as it checks @@ -792,7 +792,7 @@ bool PlayerConnection::canHandleAsyncPackets() return true; } -void PlayerConnection::handleTexture(std::shared_ptr packet) +void PlayerConnection::handleTexture(shared_ptr packet) { // Both PlayerConnection and ClientConnection should handle this mostly the same way @@ -803,12 +803,12 @@ void PlayerConnection::handleTexture(std::shared_ptr packet) wprintf(L"Server received request for custom texture %ls\n",packet->textureName.c_str()); #endif PBYTE pbData=NULL; - DWORD dwBytes=0; + DWORD dwBytes=0; app.GetMemFileDetails(packet->textureName,&pbData,&dwBytes); if(dwBytes!=0) { - send( std::shared_ptr( new TexturePacket(packet->textureName,pbData,dwBytes) ) ); + send( shared_ptr( new TexturePacket(packet->textureName,pbData,dwBytes) ) ); } else { @@ -826,7 +826,7 @@ void PlayerConnection::handleTexture(std::shared_ptr packet) } } -void PlayerConnection::handleTextureAndGeometry(std::shared_ptr packet) +void PlayerConnection::handleTextureAndGeometry(shared_ptr packet) { // Both PlayerConnection and ClientConnection should handle this mostly the same way @@ -837,7 +837,7 @@ void PlayerConnection::handleTextureAndGeometry(std::shared_ptrtextureName.c_str()); #endif PBYTE pbData=NULL; - DWORD dwTextureBytes=0; + DWORD dwTextureBytes=0; app.GetMemFileDetails(packet->textureName,&pbData,&dwTextureBytes); DLCSkinFile *pDLCSkinFile = app.m_dlcManager.getSkinFile(packet->textureName); @@ -848,11 +848,11 @@ void PlayerConnection::handleTextureAndGeometry(std::shared_ptrgetAdditionalBoxesCount()!=0) { - send( std::shared_ptr( new TextureAndGeometryPacket(packet->textureName,pbData,dwTextureBytes,pDLCSkinFile) ) ); + send( shared_ptr( new TextureAndGeometryPacket(packet->textureName,pbData,dwTextureBytes,pDLCSkinFile) ) ); } else { - send( std::shared_ptr( new TextureAndGeometryPacket(packet->textureName,pbData,dwTextureBytes) ) ); + send( shared_ptr( new TextureAndGeometryPacket(packet->textureName,pbData,dwTextureBytes) ) ); } } else @@ -861,7 +861,7 @@ void PlayerConnection::handleTextureAndGeometry(std::shared_ptr *pvSkinBoxes = app.GetAdditionalSkinBoxes(packet->dwSkinID); unsigned int uiAnimOverrideBitmask= app.GetAnimOverrideBitmask(packet->dwSkinID); - send( std::shared_ptr( new TextureAndGeometryPacket(packet->textureName,pbData,dwTextureBytes,pvSkinBoxes,uiAnimOverrideBitmask) ) ); + send( shared_ptr( new TextureAndGeometryPacket(packet->textureName,pbData,dwTextureBytes,pvSkinBoxes,uiAnimOverrideBitmask) ) ); } } else @@ -901,12 +901,12 @@ void PlayerConnection::handleTextureReceived(const wstring &textureName) if( it != m_texturesRequested.end() ) { PBYTE pbData=NULL; - DWORD dwBytes=0; + DWORD dwBytes=0; app.GetMemFileDetails(textureName,&pbData,&dwBytes); if(dwBytes!=0) { - send( std::shared_ptr( new TexturePacket(textureName,pbData,dwBytes) ) ); + send( shared_ptr( new TexturePacket(textureName,pbData,dwBytes) ) ); m_texturesRequested.erase(it); } } @@ -919,7 +919,7 @@ void PlayerConnection::handleTextureAndGeometryReceived(const wstring &textureNa if( it != m_texturesRequested.end() ) { PBYTE pbData=NULL; - DWORD dwTextureBytes=0; + DWORD dwTextureBytes=0; app.GetMemFileDetails(textureName,&pbData,&dwTextureBytes); DLCSkinFile *pDLCSkinFile=app.m_dlcManager.getSkinFile(textureName); @@ -927,7 +927,7 @@ void PlayerConnection::handleTextureAndGeometryReceived(const wstring &textureNa { if(pDLCSkinFile && (pDLCSkinFile->getAdditionalBoxesCount()!=0)) { - send( std::shared_ptr( new TextureAndGeometryPacket(textureName,pbData,dwTextureBytes,pDLCSkinFile) ) ); + send( shared_ptr( new TextureAndGeometryPacket(textureName,pbData,dwTextureBytes,pDLCSkinFile) ) ); } else { @@ -936,14 +936,14 @@ void PlayerConnection::handleTextureAndGeometryReceived(const wstring &textureNa vector *pvSkinBoxes = app.GetAdditionalSkinBoxes(dwSkinID); unsigned int uiAnimOverrideBitmask= app.GetAnimOverrideBitmask(dwSkinID); - send( std::shared_ptr( new TextureAndGeometryPacket(textureName,pbData,dwTextureBytes, pvSkinBoxes, uiAnimOverrideBitmask) ) ); + send( shared_ptr( new TextureAndGeometryPacket(textureName,pbData,dwTextureBytes, pvSkinBoxes, uiAnimOverrideBitmask) ) ); } - m_texturesRequested.erase(it); + m_texturesRequested.erase(it); } } } -void PlayerConnection::handleTextureChange(std::shared_ptr packet) +void PlayerConnection::handleTextureChange(shared_ptr packet) { switch(packet->action) { @@ -968,26 +968,26 @@ void PlayerConnection::handleTextureChange(std::shared_ptr #ifndef _CONTENT_PACKAGE wprintf(L"Sending texture packet to get custom skin %ls from player %ls\n",packet->path.c_str(), player->name.c_str()); #endif - send(std::shared_ptr( new TexturePacket(packet->path,NULL,0) ) ); + send(shared_ptr( new TexturePacket(packet->path,NULL,0) ) ); } } else if(!packet->path.empty() && app.IsFileInMemoryTextures(packet->path)) - { + { // Update the ref count on the memory texture data app.AddMemoryTextureFile(packet->path,NULL,0); } - server->getPlayers()->broadcastAll( std::shared_ptr( new TextureChangePacket(player,packet->action,packet->path) ), player->dimension ); + server->getPlayers()->broadcastAll( shared_ptr( new TextureChangePacket(player,packet->action,packet->path) ), player->dimension ); } -void PlayerConnection::handleTextureAndGeometryChange(std::shared_ptr packet) +void PlayerConnection::handleTextureAndGeometryChange(shared_ptr packet) { player->setCustomSkin( app.getSkinIdFromPath( packet->path ) ); #ifndef _CONTENT_PACKAGE wprintf(L"PlayerConnection::handleTextureAndGeometryChange - Skin for server player %ls has changed to %ls (%d)\n", player->name.c_str(), player->customTextureUrl.c_str(), player->getPlayerDefaultSkin() ); #endif - - + + if(!packet->path.empty() && packet->path.substr(0,3).compare(L"def") != 0 && !app.IsFileInMemoryTextures(packet->path)) { if( server->connection->addPendingTextureRequest(packet->path)) @@ -995,11 +995,11 @@ void PlayerConnection::handleTextureAndGeometryChange(std::shared_ptrpath.c_str(), player->name.c_str()); #endif - send(std::shared_ptr( new TextureAndGeometryPacket(packet->path,NULL,0) ) ); + send(shared_ptr( new TextureAndGeometryPacket(packet->path,NULL,0) ) ); } } else if(!packet->path.empty() && app.IsFileInMemoryTextures(packet->path)) - { + { // Update the ref count on the memory texture data app.AddMemoryTextureFile(packet->path,NULL,0); @@ -1009,10 +1009,10 @@ void PlayerConnection::handleTextureAndGeometryChange(std::shared_ptrdwSkinID,) //DebugBreak(); } - server->getPlayers()->broadcastAll( std::shared_ptr( new TextureAndGeometryChangePacket(player,packet->path) ), player->dimension ); + server->getPlayers()->broadcastAll( shared_ptr( new TextureAndGeometryChangePacket(player,packet->path) ), player->dimension ); } -void PlayerConnection::handleServerSettingsChanged(std::shared_ptr packet) +void PlayerConnection::handleServerSettingsChanged(shared_ptr packet) { if(packet->action==ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS) { @@ -1024,7 +1024,7 @@ void PlayerConnection::handleServerSettingsChanged(std::shared_ptrdata,eGameHostOption_FireSpreads)); app.SetGameHostOption(eGameHostOption_TNT, app.GetGameHostOption(packet->data,eGameHostOption_TNT)); - server->getPlayers()->broadcastAll( std::shared_ptr( new ServerSettingsChangedPacket( ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS,app.GetGameHostOption(eGameHostOption_All) ) ) ); + server->getPlayers()->broadcastAll( shared_ptr( new ServerSettingsChangedPacket( ServerSettingsChangedPacket::HOST_IN_GAME_SETTINGS,app.GetGameHostOption(eGameHostOption_All) ) ) ); // Update the QoS data g_NetworkManager.UpdateAndSetGameSessionData(); @@ -1032,21 +1032,21 @@ void PlayerConnection::handleServerSettingsChanged(std::shared_ptr packet) +void PlayerConnection::handleKickPlayer(shared_ptr packet) { INetworkPlayer *networkPlayer = getNetworkPlayer(); if( (networkPlayer != NULL && networkPlayer->IsHost()) || player->isModerator()) - { + { server->getPlayers()->kickPlayerByShortId(packet->m_networkSmallId); } } -void PlayerConnection::handleGameCommand(std::shared_ptr packet) +void PlayerConnection::handleGameCommand(shared_ptr packet) { MinecraftServer::getInstance()->getCommandDispatcher()->performCommand(player, packet->command, packet->data); } -void PlayerConnection::handleClientCommand(std::shared_ptr packet) +void PlayerConnection::handleClientCommand(shared_ptr packet) { if (packet->action == ClientCommandPacket::PERFORM_RESPAWN) { @@ -1078,17 +1078,17 @@ void PlayerConnection::handleClientCommand(std::shared_ptr } } -void PlayerConnection::handleRespawn(std::shared_ptr packet) +void PlayerConnection::handleRespawn(shared_ptr packet) { } -void PlayerConnection::handleContainerClose(std::shared_ptr packet) +void PlayerConnection::handleContainerClose(shared_ptr packet) { player->doCloseContainer(); } -#ifndef _CONTENT_PACKAGE -void PlayerConnection::handleContainerSetSlot(std::shared_ptr packet) +#ifndef _CONTENT_PACKAGE +void PlayerConnection::handleContainerSetSlot(shared_ptr packet) { if (packet->containerId == AbstractContainerMenu::CONTAINER_ID_CARRIED ) { @@ -1098,7 +1098,7 @@ void PlayerConnection::handleContainerSetSlot(std::shared_ptrcontainerId == AbstractContainerMenu::CONTAINER_ID_INVENTORY && packet->slot >= 36 && packet->slot < 36 + 9) { - std::shared_ptr lastItem = player->inventoryMenu->getSlot(packet->slot)->getItem(); + shared_ptr lastItem = player->inventoryMenu->getSlot(packet->slot)->getItem(); if (packet->item != NULL) { if (lastItem == NULL || lastItem->count < packet->item->count) @@ -1124,16 +1124,16 @@ void PlayerConnection::handleContainerSetSlot(std::shared_ptr packet) +void PlayerConnection::handleContainerClick(shared_ptr packet) { if (player->containerMenu->containerId == packet->containerId && player->containerMenu->isSynched(player)) { - std::shared_ptr clicked = player->containerMenu->clicked(packet->slotNum, packet->buttonNum, packet->quickKey?AbstractContainerMenu::CLICK_QUICK_MOVE:AbstractContainerMenu::CLICK_PICKUP, player); + shared_ptr clicked = player->containerMenu->clicked(packet->slotNum, packet->buttonNum, packet->quickKey?AbstractContainerMenu::CLICK_QUICK_MOVE:AbstractContainerMenu::CLICK_PICKUP, player); if (ItemInstance::matches(packet->item, clicked)) { // Yep, you sure did click what you claimed to click! - player->connection->send( std::shared_ptr( new ContainerAckPacket(packet->containerId, packet->uid, true) ) ); + player->connection->send( shared_ptr( new ContainerAckPacket(packet->containerId, packet->uid, true) ) ); player->ignoreSlotUpdateHack = true; player->containerMenu->broadcastChanges(); player->broadcastCarriedItem(); @@ -1143,10 +1143,10 @@ void PlayerConnection::handleContainerClick(std::shared_ptrcontainerMenu->containerId] = packet->uid; - player->connection->send( std::shared_ptr( new ContainerAckPacket(packet->containerId, packet->uid, false) ) ); + player->connection->send( shared_ptr( new ContainerAckPacket(packet->containerId, packet->uid, false) ) ); player->containerMenu->setSynched(player, false); - vector > items; + vector > items; for (unsigned int i = 0; i < player->containerMenu->slots->size(); i++) { items.push_back(player->containerMenu->slots->at(i)->getItem()); @@ -1159,7 +1159,7 @@ void PlayerConnection::handleContainerClick(std::shared_ptr packet) +void PlayerConnection::handleContainerButtonClick(shared_ptr packet) { if (player->containerMenu->containerId == packet->containerId && player->containerMenu->isSynched(player)) { @@ -1168,12 +1168,12 @@ void PlayerConnection::handleContainerButtonClick(std::shared_ptr packet) +void PlayerConnection::handleSetCreativeModeSlot(shared_ptr packet) { if (player->gameMode->isCreative()) { bool drop = packet->slotNum < 0; - std::shared_ptr item = packet->item; + shared_ptr item = packet->item; if(item != NULL && item->id == Item::map_Id) { @@ -1187,9 +1187,9 @@ void PlayerConnection::handleSetCreativeModeSlot(std::shared_ptrsetAuxValue( player->level->getAuxValueForMap(player->getXuid(), player->dimension, centreXC, centreZC, mapScale) ); + item->setAuxValue( player->level->getAuxValueForMap(player->getXuid(), player->dimension, centreXC, centreZC, mapScale) ); - std::shared_ptr data = MapItem::getSavedData(item->getAuxValue(), player->level); + shared_ptr data = MapItem::getSavedData(item->getAuxValue(), player->level); // 4J Stu - We only have one map per player per dimension, so don't reset the one that they have // when a new one is created wchar_t buf[64]; @@ -1197,9 +1197,9 @@ void PlayerConnection::handleSetCreativeModeSlot(std::shared_ptr( new MapItemSavedData(id) ); + data = shared_ptr( new MapItemSavedData(id) ); } - player->level->setSavedData(id, (std::shared_ptr ) data); + player->level->setSavedData(id, (shared_ptr ) data); data->scale = mapScale; // 4J-PB - for Xbox maps, we'll centre them on the origin of the world, since we can fit the whole world in our map @@ -1232,7 +1232,7 @@ void PlayerConnection::handleSetCreativeModeSlot(std::shared_ptr dropped = player->drop(item); + shared_ptr dropped = player->drop(item); if (dropped != NULL) { dropped->setShortLifeTime(); @@ -1244,7 +1244,7 @@ void PlayerConnection::handleSetCreativeModeSlot(std::shared_ptr > items; + vector > items; for (unsigned int i = 0; i < player->inventoryMenu->slots->size(); i++) { items.push_back(player->inventoryMenu->slots->at(i)->getItem()); @@ -1254,7 +1254,7 @@ void PlayerConnection::handleSetCreativeModeSlot(std::shared_ptr packet) +void PlayerConnection::handleContainerAck(shared_ptr packet) { AUTO_VAR(it, expectedAcks.find(player->containerMenu->containerId)); @@ -1264,18 +1264,18 @@ void PlayerConnection::handleContainerAck(std::shared_ptr pa } } -void PlayerConnection::handleSignUpdate(std::shared_ptr packet) +void PlayerConnection::handleSignUpdate(shared_ptr packet) { app.DebugPrintf("PlayerConnection::handleSignUpdate\n"); ServerLevel *level = server->getLevel(player->dimension); if (level->hasChunkAt(packet->x, packet->y, packet->z)) { - std::shared_ptr te = level->getTileEntity(packet->x, packet->y, packet->z); + shared_ptr te = level->getTileEntity(packet->x, packet->y, packet->z); if (dynamic_pointer_cast(te) != NULL) { - std::shared_ptr ste = dynamic_pointer_cast(te); + shared_ptr ste = dynamic_pointer_cast(te); if (!ste->isEditable()) { server->warn(L"Player " + player->name + L" just tried to change non-editable sign"); @@ -1289,7 +1289,7 @@ void PlayerConnection::handleSignUpdate(std::shared_ptr packet int x = packet->x; int y = packet->y; int z = packet->z; - std::shared_ptr ste = dynamic_pointer_cast(te); + shared_ptr ste = dynamic_pointer_cast(te); for (int i = 0; i < 4; i++) { wstring lineText = packet->lines[i].substr(0,15); @@ -1303,7 +1303,7 @@ void PlayerConnection::handleSignUpdate(std::shared_ptr packet } -void PlayerConnection::handleKeepAlive(std::shared_ptr packet) +void PlayerConnection::handleKeepAlive(shared_ptr packet) { if (packet->id == lastKeepAliveId) { @@ -1312,18 +1312,18 @@ void PlayerConnection::handleKeepAlive(std::shared_ptr packet) } } -void PlayerConnection::handlePlayerInfo(std::shared_ptr packet) -{ +void PlayerConnection::handlePlayerInfo(shared_ptr packet) +{ // Need to check that this player has permission to change each individual setting? INetworkPlayer *networkPlayer = getNetworkPlayer(); if( (networkPlayer != NULL && networkPlayer->IsHost()) || player->isModerator() ) { - std::shared_ptr serverPlayer; + shared_ptr serverPlayer; // Find the player being edited for(AUTO_VAR(it, server->getPlayers()->players.begin()); it != server->getPlayers()->players.end(); ++it) { - std::shared_ptr checkingPlayer = *it; + shared_ptr checkingPlayer = *it; if(checkingPlayer->connection->getNetworkPlayer() != NULL && checkingPlayer->connection->getNetworkPlayer()->GetSmallId() == packet->m_networkSmallId) { serverPlayer = checkingPlayer; @@ -1348,7 +1348,7 @@ void PlayerConnection::handlePlayerInfo(std::shared_ptr packet #endif serverPlayer->setPlayerGamePrivilege(Player::ePlayerGamePrivilege_CreativeMode,Player::getPlayerGamePrivilege(packet->m_playerPrivileges,Player::ePlayerGamePrivilege_CreativeMode) ); serverPlayer->gameMode->setGameModeForPlayer(gameType); - serverPlayer->connection->send( std::shared_ptr( new GameEventPacket(GameEventPacket::CHANGE_GAME_MODE, gameType->getId()) )); + serverPlayer->connection->send( shared_ptr( new GameEventPacket(GameEventPacket::CHANGE_GAME_MODE, gameType->getId()) )); } else { @@ -1376,7 +1376,7 @@ void PlayerConnection::handlePlayerInfo(std::shared_ptr packet } else { - // Editing someone else + // Editing someone else if(!trustPlayers && !serverPlayer->connection->getNetworkPlayer()->IsHost()) { serverPlayer->setPlayerGamePrivilege(Player::ePlayerGamePrivilege_CannotMine,Player::getPlayerGamePrivilege(packet->m_playerPrivileges,Player::ePlayerGamePrivilege_CannotMine) ); @@ -1400,7 +1400,7 @@ void PlayerConnection::handlePlayerInfo(std::shared_ptr packet } } - server->getPlayers()->broadcastAll( std::shared_ptr( new PlayerInfoPacket( serverPlayer ) ) ); + server->getPlayers()->broadcastAll( shared_ptr( new PlayerInfoPacket( serverPlayer ) ) ); } } } @@ -1410,7 +1410,7 @@ bool PlayerConnection::isServerPacketListener() return true; } -void PlayerConnection::handlePlayerAbilities(std::shared_ptr playerAbilitiesPacket) +void PlayerConnection::handlePlayerAbilities(shared_ptr playerAbilitiesPacket) { player->abilities.flying = playerAbilitiesPacket->isFlying() && player->abilities.mayfly; } @@ -1427,19 +1427,19 @@ void PlayerConnection::handlePlayerAbilities(std::shared_ptr packet) +//void handleClientInformation(shared_ptr packet) //{ // player->updateOptions(packet); //} -void PlayerConnection::handleCustomPayload(std::shared_ptr customPayloadPacket) +void PlayerConnection::handleCustomPayload(shared_ptr customPayloadPacket) { #if 0 if (CustomPayloadPacket.CUSTOM_BOOK_PACKET.equals(customPayloadPacket.identifier)) { ByteArrayInputStream bais(customPayloadPacket->data); DataInputStream input(&bais); - std::shared_ptr sentItem = Packet::readItem(input); + shared_ptr sentItem = Packet::readItem(input); if (!WritingBookItem.makeSureTagIsValid(sentItem.getTag())) { @@ -1510,13 +1510,13 @@ void PlayerConnection::handleCustomPayload(std::shared_ptr // 4J Added -void PlayerConnection::handleDebugOptions(std::shared_ptr packet) +void PlayerConnection::handleDebugOptions(shared_ptr packet) { //Player player = dynamic_pointer_cast( player->shared_from_this() ); player->SetDebugOptions(packet->m_uiVal); } -void PlayerConnection::handleCraftItem(std::shared_ptr packet) +void PlayerConnection::handleCraftItem(shared_ptr packet) { int iRecipe = packet->recipe; @@ -1524,7 +1524,7 @@ void PlayerConnection::handleCraftItem(std::shared_ptr packet) return; Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); - std::shared_ptr pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); + shared_ptr pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); if(app.DebugSettingsOn() && (player->GetDebugOptions()&(1L< packet) else { - + // TODO 4J Stu - Assume at the moment that the client can work this out for us... - //if(pRecipeIngredientsRequired[iRecipe].bCanMake) + //if(pRecipeIngredientsRequired[iRecipe].bCanMake) //{ pTempItemInst->onCraftedBy(player->level, dynamic_pointer_cast( player->shared_from_this() ), pTempItemInst->count ); @@ -1549,7 +1549,7 @@ void PlayerConnection::handleCraftItem(std::shared_ptr packet) { for(int j=0;j ingItemInst = nullptr; + shared_ptr ingItemInst = nullptr; // do we need to remove a specific aux value? if(pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]!=Recipes::ANY_AUX_VALUE) { @@ -1568,13 +1568,13 @@ void PlayerConnection::handleCraftItem(std::shared_ptr packet) if (ingItemInst->getItem()->hasCraftingRemainingItem()) { // replace item with remaining result - player->inventory->add( std::shared_ptr( new ItemInstance(ingItemInst->getItem()->getCraftingRemainingItem()) ) ); + player->inventory->add( shared_ptr( new ItemInstance(ingItemInst->getItem()->getCraftingRemainingItem()) ) ); } } } } - + // 4J Stu - Fix for #13119 - We should add the item after we remove the ingredients if(player->inventory->add(pTempItemInst)==false ) { @@ -1586,7 +1586,7 @@ void PlayerConnection::handleCraftItem(std::shared_ptr packet) { // 4J Stu - Maps need to have their aux value update, so the client should always be assumed to be wrong // This is how the Java works, as the client also incorrectly predicts the auxvalue of the mapItem - vector > items; + vector > items; for (unsigned int i = 0; i < player->containerMenu->slots->size(); i++) { items.push_back(player->containerMenu->slots->at(i)->getItem()); @@ -1625,7 +1625,7 @@ void PlayerConnection::handleCraftItem(std::shared_ptr packet) } -void PlayerConnection::handleTradeItem(std::shared_ptr packet) +void PlayerConnection::handleTradeItem(shared_ptr packet) { if (player->containerMenu->containerId == packet->containerId) { @@ -1642,8 +1642,8 @@ void PlayerConnection::handleTradeItem(std::shared_ptr packet) if(!activeRecipe->isDeprecated()) { // Do we have the ingredients? - std::shared_ptr buyAItem = activeRecipe->getBuyAItem(); - std::shared_ptr buyBItem = activeRecipe->getBuyBItem(); + shared_ptr buyAItem = activeRecipe->getBuyAItem(); + shared_ptr buyBItem = activeRecipe->getBuyBItem(); int buyAMatches = player->inventory->countMatches(buyAItem); int buyBMatches = player->inventory->countMatches(buyBItem); @@ -1656,8 +1656,8 @@ void PlayerConnection::handleTradeItem(std::shared_ptr packet) player->inventory->removeResources(buyBItem); // Add the item we have purchased - std::shared_ptr result = activeRecipe->getSellItem()->copy(); - + shared_ptr result = activeRecipe->getSellItem()->copy(); + // 4J JEV - Award itemsBought stat. player->awardStat( GenericStats::itemsBought(result->getItem()->id), @@ -1667,7 +1667,7 @@ void PlayerConnection::handleTradeItem(std::shared_ptr packet) result->GetCount() ) ); - + if (!player->inventory->add(result)) { player->drop(result); @@ -1687,7 +1687,7 @@ INetworkPlayer *PlayerConnection::getNetworkPlayer() bool PlayerConnection::isLocal() { - if( connection->getSocket() == NULL ) + if( connection->getSocket() == NULL ) { return false; } @@ -1700,7 +1700,7 @@ bool PlayerConnection::isLocal() bool PlayerConnection::isGuest() { - if( connection->getSocket() == NULL ) + if( connection->getSocket() == NULL ) { return false; } -- cgit v1.2.3