From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.Client/ClientConnection.h | 140 ++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Minecraft.Client/ClientConnection.h (limited to 'Minecraft.Client/ClientConnection.h') diff --git a/Minecraft.Client/ClientConnection.h b/Minecraft.Client/ClientConnection.h new file mode 100644 index 00000000..2ce46ce0 --- /dev/null +++ b/Minecraft.Client/ClientConnection.h @@ -0,0 +1,140 @@ +#pragma once +#include "..\Minecraft.World\net.minecraft.network.h" +class Minecraft; +class MultiPlayerLevel; +class SavedDataStorage; +class Socket; +class MultiplayerLocalPlayer; + +class ClientConnection : public PacketListener +{ +private: + enum eClientConnectionConnectingState + { + eCCPreLoginSent = 0, + eCCPreLoginReceived, + eCCLoginSent, + eCCLoginReceived, + eCCConnected + }; +private: + bool done; + Connection *connection; +public: + wstring message; + bool createdOk; // 4J added +private: + Minecraft *minecraft; + MultiPlayerLevel *level; + bool started; + + // 4J Stu - I don't think we are interested in the PlayerInfo data, so I'm not going to use it at the moment + //Map playerInfoMap = new HashMap(); +public: + //List playerInfos = new ArrayList(); + + int maxPlayers; + +public: + bool isStarted() { return started; } // 4J Added + bool isClosed() { return done; } // 4J Added + Socket *getSocket() { return connection->getSocket(); } // 4J Added + +private: + DWORD m_userIndex; // 4J Added +public: + SavedDataStorage *savedDataStorage; + ClientConnection(Minecraft *minecraft, const wstring& ip, int port); + ClientConnection(Minecraft *minecraft, Socket *socket, int iUserIndex = -1); + ~ClientConnection(); + void tick(); + INetworkPlayer *getNetworkPlayer(); + virtual void handleLogin(shared_ptr packet); + virtual void handleAddEntity(shared_ptr packet); + virtual void handleAddExperienceOrb(shared_ptr packet); + virtual void handleAddGlobalEntity(shared_ptr packet); + virtual void handleAddPainting(shared_ptr packet); + virtual void handleSetEntityMotion(shared_ptr packet); + virtual void handleSetEntityData(shared_ptr packet); + virtual void handleAddPlayer(shared_ptr packet); + virtual void handleTeleportEntity(shared_ptr packet); + virtual void handleMoveEntity(shared_ptr packet); + virtual void handleRotateMob(shared_ptr packet); + virtual void handleMoveEntitySmall(shared_ptr packet); + virtual void handleRemoveEntity(shared_ptr packet); + virtual void handleMovePlayer(shared_ptr packet); + + Random *random; + + // 4J Added + virtual void handleChunkVisibilityArea(shared_ptr packet); + + virtual void handleChunkVisibility(shared_ptr packet); + virtual void handleChunkTilesUpdate(shared_ptr packet); + virtual void handleBlockRegionUpdate(shared_ptr packet); + virtual void handleTileUpdate(shared_ptr packet); + virtual void handleDisconnect(shared_ptr packet); + virtual void onDisconnect(DisconnectPacket::eDisconnectReason reason, void *reasonObjects); + void sendAndDisconnect(shared_ptr packet); + void send(shared_ptr packet); + virtual void handleTakeItemEntity(shared_ptr packet); + virtual void handleChat(shared_ptr packet); + virtual void handleAnimate(shared_ptr packet); + virtual void handleEntityActionAtPosition(shared_ptr packet); + virtual void handlePreLogin(shared_ptr packet); + void close(); + virtual void handleAddMob(shared_ptr packet); + virtual void handleSetTime(shared_ptr packet); + virtual void handleSetSpawn(shared_ptr packet); + virtual void handleRidePacket(shared_ptr packet); + virtual void handleEntityEvent(shared_ptr packet); +private: + shared_ptr getEntity(int entityId); + wstring GetDisplayNameByGamertag(wstring gamertag); +public: + virtual void handleSetHealth(shared_ptr packet); + virtual void handleSetExperience(shared_ptr packet); + virtual void handleRespawn(shared_ptr packet); + virtual void handleExplosion(shared_ptr packet); + virtual void handleContainerOpen(shared_ptr packet); + virtual void handleContainerSetSlot(shared_ptr packet); + virtual void handleContainerAck(shared_ptr packet); + virtual void handleContainerContent(shared_ptr packet); + virtual void handleSignUpdate(shared_ptr packet); + virtual void handleTileEntityData(shared_ptr packet); + virtual void handleContainerSetData(shared_ptr packet); + virtual void handleSetEquippedItem(shared_ptr packet); + virtual void handleContainerClose(shared_ptr packet); + virtual void handleTileEvent(shared_ptr packet); + virtual void handleTileDestruction(shared_ptr packet); + virtual bool canHandleAsyncPackets(); + virtual void handleGameEvent(shared_ptr gameEventPacket); + virtual void handleComplexItemData(shared_ptr packet); + virtual void handleLevelEvent(shared_ptr packet); + virtual void handleAwardStat(shared_ptr packet); + virtual void handleUpdateMobEffect(shared_ptr packet); + virtual void handleRemoveMobEffect(shared_ptr packet); + virtual bool isServerPacketListener(); + virtual void handlePlayerInfo(shared_ptr packet); + virtual void handleKeepAlive(shared_ptr packet); + virtual void handlePlayerAbilities(shared_ptr playerAbilitiesPacket); + virtual void handleSoundEvent(shared_ptr packet); + virtual void handleCustomPayload(shared_ptr customPayloadPacket); + virtual Connection *getConnection(); + + // 4J Added + virtual void handleServerSettingsChanged(shared_ptr packet); + virtual void handleTexture(shared_ptr packet); + virtual void handleTextureAndGeometry(shared_ptr packet); + virtual void handleUpdateProgress(shared_ptr packet); + + // 4J Added + static int HostDisconnectReturned(void *pParam,int iPad,C4JStorage::EMessageResult result); + static int ExitGameAndSaveReturned(void *pParam,int iPad,C4JStorage::EMessageResult result); + virtual void handleTextureChange(shared_ptr packet); + virtual void handleTextureAndGeometryChange(shared_ptr packet); + virtual void handleUpdateGameRuleProgressPacket(shared_ptr packet); + virtual void handleXZ(shared_ptr packet); + + void displayPrivilegeChanges(shared_ptr player, unsigned int oldPrivileges); +}; \ No newline at end of file -- cgit v1.2.3