summaryrefslogtreecommitdiffstats
path: root/source/Protocol132.h
blob: d1f1ccbd3c1a4de5e493c40ea0bc787de4064b62 (plain) (blame)
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

// Protocol132.h

// Interfaces to the cProtocol132 class representing the release 1.3.2 protocol (#39)





#pragma once

#include "Protocol125.h"
#include "CryptoPP/modes.h"
#include "CryptoPP/aes.h"





class cProtocol132 :
	public cProtocol125
{
	typedef cProtocol125 super;
public:

	cProtocol132(cClientHandle * a_Client);
	
	// DEBUG:
	virtual ~cProtocol132();

	/// Called when client sends some data:
	virtual void DataReceived(const char * a_Data, int a_Size) override;
	
	// Sending commands:
	virtual void SendBlockAction  (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override;
	virtual void SendBlockChange  (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
	virtual void SendChunkData    (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
	virtual void SendDestroyEntity(const cEntity & a_Entity) override;
	virtual void SendLogin        (const cPlayer & a_Player, const cWorld & a_World) override;
	virtual void SendPlayerSpawn  (const cPlayer & a_Player) override;
	virtual void SendSpawnMob     (const cMonster & a_Mob) override;
	virtual void SendUnloadChunk  (int a_ChunkX, int a_ChunkZ) override;

	// DEBUG:
	virtual void SendKeepAlive  (int a_PingID) override;

	/// Handling of the additional packets:
	virtual int ParsePacket(unsigned char a_PacketType) override;
	
	// Modified packets:
	virtual int ParseBlockPlace     (void) override;
	virtual int ParseHandshake      (void) override;
	virtual int ParseLogin          (void) override;
	virtual int ParsePlayerAbilities(void) override;
	
	// New packets:
	virtual int ParseClientStatuses       (void);
	virtual int ParseEncryptionKeyResponse(void);
	virtual int ParseLocaleViewDistance   (void);
	
protected:
	bool m_IsEncrypted;
	CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption m_Decryptor;
	CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption m_Encryptor;
	
	// DEBUG:
	CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption m_Decryptor2;
	AString m_DataToSend;
	int m_CurrentIn, m_CurrentOut;
	int m_EncIn, m_EncOut;
	
	virtual void SendData(const char * a_Data, int a_Size) override;
	
	// DEBUG:
	virtual void Flush(void) override;
	
	// Items in slots are sent differently
	virtual void WriteItem(const cItem & a_Item) override;
	virtual int  ParseItem(cItem & a_Item) override;
	
	virtual void SendCompass(const cWorld & a_World);
	virtual void SendEncryptionKeyRequest(const AString & a_Key);
	
	/// Decrypts the key and nonce, checks nonce, starts the symmetric encryption
	void HandleEncryptionKeyResponse(const AString & a_EncKey, const AString & a_EncNonce);
	
	/// Starts the symmetric encryption with the specified key
	void StartEncryption(const byte * a_Key);
} ;