summaryrefslogtreecommitdiffstats
path: root/source/cClientHandle.h
blob: a704ffc0e6b386cf853550660f3b0a1796cd6447 (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
#pragma once

class cSocket;
class cSemaphore;
class cEvent;
class Game;
class cPacket;
class cChunk;
class cPlayer;
class cClientHandle							// tolua_export
{											// tolua_export
public:
	enum ENUM_PRIORITY
	{
		E_PRIORITY_LOW,
		E_PRIORITY_NORMAL
	};

	cClientHandle(const cSocket & a_Socket);
	~cClientHandle();

	static const int VIEWDISTANCE = 13;
        static const int GAMEMODE = 1; //0 = Survival, 1 = Creative;

	const cSocket & GetSocket();
	cPlayer* GetPlayer() { return m_Player; }	// tolua_export

	void Kick( const char* a_Reason ); //tolua_export

	void AddPacket( cPacket * a_Packet );
	void HandlePendingPackets();

	void StreamChunks();
	void StreamChunksSmart( cChunk** a_Chunks, unsigned int a_NumChunks );

	inline void SetLoggedIn( bool a_bLoggedIn ) { m_bLoggedIn = a_bLoggedIn; }
	inline bool IsLoggedIn() { return m_bLoggedIn; }

	void Tick(float a_Dt);

	bool IsDestroyed() { return m_bDestroyed; }
	void Destroy();

	cChunk* m_LoadedChunks[VIEWDISTANCE*VIEWDISTANCE];

	void Send( const cPacket & a_Packet, ENUM_PRIORITY a_Priority = E_PRIORITY_NORMAL );

	static void SendThread( void *lpParam );
	static void ReceiveThread( void *lpParam );
	static void AuthenticateThread( void* a_Param );

	const char* GetUsername();
private:
	void HandlePacket( cPacket* a_Packet );
	void RemovePacket( cPacket * a_Packet );

	void SendLoginResponse();

	struct sClientHandleState;
	sClientHandleState* m_pState;

	bool m_bDestroyed;
	cPlayer* m_Player;
	bool m_bKicking;

	float m_TimeLastPacket;

	bool m_bLoggedIn;

	bool m_bKeepThreadGoing;
};										// tolua_export