aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/LoginPacket.cpp
blob: 79cdfbae1ded586c6d494bb619d5a8d071b7f0a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "stdafx.h"
#include <iostream>
#include "InputOutputStream.h"
#include "net.minecraft.world.entity.player.h"
#include "PacketListener.h"
#include "LoginPacket.h"
#include "LevelType.h"



LoginPacket::LoginPacket()
{
	this->userName = L"";
	this->clientVersion = 0;
	this->seed = 0;
	this->dimension = 0;
	this->gameType = 0;
	this->mapHeight = 0;
	this->maxPlayers = 0;

	this->difficulty = 1;

	this->m_offlineXuid = INVALID_XUID;
	this->m_onlineXuid = INVALID_XUID;
	m_friendsOnlyUGC = false;
	m_ugcPlayersVersion = 0;
	m_multiplayerInstanceId = 0;
	m_playerIndex = 0;
	m_playerSkinId = 0;
	m_playerCapeId = 0;
	m_isGuest = false;
	m_newSeaLevel = false;
	m_pLevelType = nullptr;
	m_uiGamePrivileges = 0;
	m_xzSize = LEVEL_MAX_WIDTH;
	m_hellScale = HELL_LEVEL_MAX_SCALE;
}

// Client -> Server
LoginPacket::LoginPacket(const wstring& userName, int clientVersion, PlayerUID offlineXuid, PlayerUID onlineXuid,  bool friendsOnlyUGC, DWORD ugcPlayersVersion, DWORD skinId, DWORD capeId, bool isGuest)
{
	this->userName = userName;
	this->clientVersion = clientVersion;
	this->seed = 0;
	this->dimension = 0;
	this->gameType = 0;
	this->mapHeight = 0;
	this->maxPlayers = 0;

	this->difficulty = 1;

	this->m_offlineXuid = offlineXuid;
	this->m_onlineXuid = onlineXuid;
	m_friendsOnlyUGC = friendsOnlyUGC;
	m_ugcPlayersVersion = ugcPlayersVersion;
	m_multiplayerInstanceId = 0;
	m_playerIndex = 0;
	m_playerSkinId = skinId;
	m_playerCapeId = capeId;
	m_isGuest = isGuest;
	m_newSeaLevel = false;
	m_pLevelType = nullptr;
	m_uiGamePrivileges = 0;
	m_xzSize = LEVEL_MAX_WIDTH;
	m_hellScale = HELL_LEVEL_MAX_SCALE;
}

// Server -> Client
LoginPacket::LoginPacket(const wstring& userName, int clientVersion, LevelType *pLevelType, int64_t seed, int gameType, char dimension, BYTE mapHeight, BYTE maxPlayers, char difficulty, INT multiplayerInstanceId, BYTE playerIndex, bool newSeaLevel, unsigned int uiGamePrivileges, int xzSize, int hellScale)
{
	this->userName = userName;
	this->clientVersion = clientVersion;
	this->seed = seed;
	this->dimension = dimension;
	this->gameType = gameType;
	this->mapHeight = mapHeight;
	this->maxPlayers = maxPlayers;

	this->difficulty = difficulty;

	this->m_offlineXuid = INVALID_XUID;
	this->m_onlineXuid = INVALID_XUID;
	m_friendsOnlyUGC = false;
	m_ugcPlayersVersion = 0;
	m_multiplayerInstanceId = multiplayerInstanceId;
	this->m_playerIndex = playerIndex;
	m_playerSkinId = 0;
	m_playerCapeId = 0;
	m_isGuest = false;
	m_newSeaLevel = newSeaLevel;
	this->m_pLevelType=pLevelType;
	m_uiGamePrivileges = uiGamePrivileges;
	m_xzSize = xzSize;
	m_hellScale = hellScale;
}

void LoginPacket::read(DataInputStream *dis) //throws IOException
{
	clientVersion = dis->readInt();
	userName = readUtf(dis, Player::MAX_NAME_LENGTH);
	wstring typeName = readUtf(dis, 16);
	m_pLevelType = LevelType::getLevelType(typeName);
	if (m_pLevelType == nullptr)
	{
		m_pLevelType = LevelType::lvl_normal;
	}
	seed = dis->readLong();
	gameType = dis->readInt();
	dimension = dis->readByte();
	mapHeight = dis->readByte();
	maxPlayers = dis->readByte();
	m_offlineXuid = dis->readPlayerUID();
	m_onlineXuid = dis->readPlayerUID();
	m_friendsOnlyUGC = dis->readBoolean();
	m_ugcPlayersVersion = dis->readInt();
	difficulty = dis->readByte();
	m_multiplayerInstanceId = dis->readInt();
	m_playerIndex = dis->readByte();
	INT skinId = dis->readInt();
	m_playerSkinId = *(DWORD *)&skinId;
	INT capeId = dis->readInt();
	m_playerCapeId = *(DWORD *)&capeId;
	m_isGuest = dis->readBoolean();
	m_newSeaLevel = dis->readBoolean();
	m_uiGamePrivileges = dis->readInt();
#ifdef _LARGE_WORLDS
	m_xzSize = dis->readShort();
	m_hellScale = dis->read();
#endif
	app.DebugPrintf("LoginPacket::read - Difficulty = %d\n",difficulty);

}

void LoginPacket::write(DataOutputStream *dos) //throws IOException
{
	dos->writeInt(clientVersion);
	writeUtf(userName, dos);
	if (m_pLevelType == nullptr)
	{
		writeUtf(L"", dos);
	}
	else
	{
		writeUtf(m_pLevelType->getGeneratorName(), dos);
	}
	dos->writeLong(seed);
	dos->writeInt(gameType);
	dos->writeByte(dimension);
	dos->writeByte(mapHeight);
	dos->writeByte(maxPlayers);
	dos->writePlayerUID(m_offlineXuid);
	dos->writePlayerUID(m_onlineXuid);
	dos->writeBoolean(m_friendsOnlyUGC);
	dos->writeInt(m_ugcPlayersVersion);
	dos->writeByte(difficulty);
	dos->writeInt(m_multiplayerInstanceId);
	dos->writeByte(m_playerIndex);
	dos->writeInt(m_playerSkinId);
	dos->writeInt(m_playerCapeId);
	dos->writeBoolean(m_isGuest);
	dos->writeBoolean(m_newSeaLevel);
	dos->writeInt(m_uiGamePrivileges);
#ifdef _LARGE_WORLDS
	dos->writeShort(m_xzSize);
	dos->write(m_hellScale);
#endif
}

void LoginPacket::handle(PacketListener *listener)
{
	listener->handleLogin(shared_from_this());
}

int LoginPacket::getEstimatedSize()
{
	int length=0;
	if (m_pLevelType != nullptr)
	{
		length = static_cast<int>(m_pLevelType->getGeneratorName().length());
	}

	return static_cast<int>(sizeof(int) + userName.length() + 4 + 6 + sizeof(int64_t) + sizeof(char) + sizeof(int) + (2 * sizeof(PlayerUID)) + 1 + sizeof(char) + sizeof(BYTE) + sizeof(bool) + sizeof(bool) + length + sizeof(unsigned int));
}