the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 183 lines 5.1 kB view raw
1#include "stdafx.h" 2#include <iostream> 3#include "InputOutputStream.h" 4#include "net.minecraft.world.entity.player.h" 5#include "PacketListener.h" 6#include "LoginPacket.h" 7#include "LevelType.h" 8 9 10 11LoginPacket::LoginPacket() 12{ 13 this->userName = L""; 14 this->clientVersion = 0; 15 this->seed = 0; 16 this->dimension = 0; 17 this->gameType = 0; 18 this->mapHeight = 0; 19 this->maxPlayers = 0; 20 21 this->difficulty = 1; 22 23 this->m_offlineXuid = INVALID_XUID; 24 this->m_onlineXuid = INVALID_XUID; 25 m_friendsOnlyUGC = false; 26 m_ugcPlayersVersion = 0; 27 m_multiplayerInstanceId = 0; 28 m_playerIndex = 0; 29 m_playerSkinId = 0; 30 m_playerCapeId = 0; 31 m_isGuest = false; 32 m_newSeaLevel = false; 33 m_pLevelType = NULL; 34 m_uiGamePrivileges = 0; 35 m_xzSize = LEVEL_MAX_WIDTH; 36 m_hellScale = HELL_LEVEL_MAX_SCALE; 37} 38 39// Client -> Server 40LoginPacket::LoginPacket(const wstring& userName, int clientVersion, PlayerUID offlineXuid, PlayerUID onlineXuid, bool friendsOnlyUGC, DWORD ugcPlayersVersion, DWORD skinId, DWORD capeId, bool isGuest) 41{ 42 this->userName = userName; 43 this->clientVersion = clientVersion; 44 this->seed = 0; 45 this->dimension = 0; 46 this->gameType = 0; 47 this->mapHeight = 0; 48 this->maxPlayers = 0; 49 50 this->difficulty = 1; 51 52 this->m_offlineXuid = offlineXuid; 53 this->m_onlineXuid = onlineXuid; 54 m_friendsOnlyUGC = friendsOnlyUGC; 55 m_ugcPlayersVersion = ugcPlayersVersion; 56 m_multiplayerInstanceId = 0; 57 m_playerIndex = 0; 58 m_playerSkinId = skinId; 59 m_playerCapeId = capeId; 60 m_isGuest = isGuest; 61 m_newSeaLevel = false; 62 m_pLevelType = NULL; 63 m_uiGamePrivileges = 0; 64 m_xzSize = LEVEL_MAX_WIDTH; 65 m_hellScale = HELL_LEVEL_MAX_SCALE; 66} 67 68// Server -> Client 69LoginPacket::LoginPacket(const wstring& userName, int clientVersion, LevelType *pLevelType, __int64 seed, int gameType, char dimension, BYTE mapHeight, BYTE maxPlayers, char difficulty, INT multiplayerInstanceId, BYTE playerIndex, bool newSeaLevel, unsigned int uiGamePrivileges, int xzSize, int hellScale) 70{ 71 this->userName = userName; 72 this->clientVersion = clientVersion; 73 this->seed = seed; 74 this->dimension = dimension; 75 this->gameType = gameType; 76 this->mapHeight = mapHeight; 77 this->maxPlayers = maxPlayers; 78 79 this->difficulty = difficulty; 80 81 this->m_offlineXuid = INVALID_XUID; 82 this->m_onlineXuid = INVALID_XUID; 83 m_friendsOnlyUGC = false; 84 m_ugcPlayersVersion = 0; 85 m_multiplayerInstanceId = multiplayerInstanceId; 86 this->m_playerIndex = playerIndex; 87 m_playerSkinId = 0; 88 m_playerCapeId = 0; 89 m_isGuest = false; 90 m_newSeaLevel = newSeaLevel; 91 this->m_pLevelType=pLevelType; 92 m_uiGamePrivileges = uiGamePrivileges; 93 m_xzSize = xzSize; 94 m_hellScale = hellScale; 95} 96 97void LoginPacket::read(DataInputStream *dis) //throws IOException 98{ 99 clientVersion = dis->readInt(); 100 userName = readUtf(dis, Player::MAX_NAME_LENGTH); 101 wstring typeName = readUtf(dis, 16); 102 m_pLevelType = LevelType::getLevelType(typeName); 103 if (m_pLevelType == NULL) 104 { 105 m_pLevelType = LevelType::lvl_normal; 106 } 107 seed = dis->readLong(); 108 gameType = dis->readInt(); 109 dimension = dis->readByte(); 110 mapHeight = dis->readByte(); 111 maxPlayers = dis->readByte(); 112 m_offlineXuid = dis->readPlayerUID(); 113 m_onlineXuid = dis->readPlayerUID(); 114 m_friendsOnlyUGC = dis->readBoolean(); 115 m_ugcPlayersVersion = dis->readInt(); 116 difficulty = dis->readByte(); 117 m_multiplayerInstanceId = dis->readInt(); 118 m_playerIndex = dis->readByte(); 119 INT skinId = dis->readInt(); 120 m_playerSkinId = *(DWORD *)&skinId; 121 INT capeId = dis->readInt(); 122 m_playerCapeId = *(DWORD *)&capeId; 123 m_isGuest = dis->readBoolean(); 124 m_newSeaLevel = dis->readBoolean(); 125 m_uiGamePrivileges = dis->readInt(); 126#ifdef _LARGE_WORLDS 127 m_xzSize = dis->readShort(); 128 m_hellScale = dis->read(); 129#endif 130 app.DebugPrintf("LoginPacket::read - Difficulty = %d\n",difficulty); 131 132} 133 134void LoginPacket::write(DataOutputStream *dos) //throws IOException 135{ 136 dos->writeInt(clientVersion); 137 writeUtf(userName, dos); 138 if (m_pLevelType == NULL) 139 { 140 writeUtf(L"", dos); 141 } 142 else 143 { 144 writeUtf(m_pLevelType->getGeneratorName(), dos); 145 } 146 dos->writeLong(seed); 147 dos->writeInt(gameType); 148 dos->writeByte(dimension); 149 dos->writeByte(mapHeight); 150 dos->writeByte(maxPlayers); 151 dos->writePlayerUID(m_offlineXuid); 152 dos->writePlayerUID(m_onlineXuid); 153 dos->writeBoolean(m_friendsOnlyUGC); 154 dos->writeInt(m_ugcPlayersVersion); 155 dos->writeByte(difficulty); 156 dos->writeInt(m_multiplayerInstanceId); 157 dos->writeByte(m_playerIndex); 158 dos->writeInt(m_playerSkinId); 159 dos->writeInt(m_playerCapeId); 160 dos->writeBoolean(m_isGuest); 161 dos->writeBoolean(m_newSeaLevel); 162 dos->writeInt(m_uiGamePrivileges); 163#ifdef _LARGE_WORLDS 164 dos->writeShort(m_xzSize); 165 dos->write(m_hellScale); 166#endif 167} 168 169void LoginPacket::handle(PacketListener *listener) 170{ 171 listener->handleLogin(shared_from_this()); 172} 173 174int LoginPacket::getEstimatedSize() 175{ 176 int length=0; 177 if (m_pLevelType != NULL) 178 { 179 length = (int)m_pLevelType->getGeneratorName().length(); 180 } 181 182 return (int)(sizeof(int) + userName.length() + 4 + 6 + sizeof(__int64) + sizeof(char) + sizeof(int) + (2*sizeof(PlayerUID)) +1 + sizeof(char) + sizeof(BYTE) + sizeof(bool) + sizeof(bool) + length + sizeof(unsigned int)); 183}