2012-02-02 16:13:24 -05:00
|
|
|
|
|
|
|
// cClientHandle.h
|
|
|
|
|
|
|
|
// Interfaces to the cClientHandle class representing a client connected to this server. The client need not be a player yet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#pragma once
|
2012-02-02 16:13:24 -05:00
|
|
|
#ifndef CCLIENTHANDLE_H_INCLUDED
|
|
|
|
#define CCLIENTHANDLE_H_INCLUDED
|
|
|
|
|
2012-02-04 14:40:48 -05:00
|
|
|
#include "packets/cPacket.h"
|
2012-02-02 16:13:24 -05:00
|
|
|
#include "Vector3d.h"
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
#include "packets/cPacket_KeepAlive.h"
|
|
|
|
#include "packets/cPacket_PlayerPosition.h"
|
|
|
|
#include "packets/cPacket_Respawn.h"
|
|
|
|
#include "packets/cPacket_RelativeEntityMoveLook.h"
|
|
|
|
#include "packets/cPacket_Chat.h"
|
|
|
|
#include "packets/cPacket_Login.h"
|
|
|
|
#include "packets/cPacket_WindowClick.h"
|
|
|
|
#include "packets/cPacket_PlayerMoveLook.h"
|
|
|
|
#include "packets/cPacket_TimeUpdate.h"
|
|
|
|
#include "packets/cPacket_BlockDig.h"
|
|
|
|
#include "packets/cPacket_Handshake.h"
|
|
|
|
#include "packets/cPacket_PlayerLook.h"
|
|
|
|
#include "packets/cPacket_ArmAnim.h"
|
|
|
|
#include "packets/cPacket_BlockPlace.h"
|
|
|
|
#include "packets/cPacket_Flying.h"
|
|
|
|
#include "packets/cPacket_Disconnect.h"
|
|
|
|
#include "packets/cPacket_PickupSpawn.h"
|
|
|
|
#include "packets/cPacket_ItemSwitch.h"
|
|
|
|
#include "packets/cPacket_EntityEquipment.h"
|
|
|
|
#include "packets/cPacket_CreativeInventoryAction.h"
|
|
|
|
#include "packets/cPacket_NewInvalidState.h"
|
|
|
|
#include "packets/cPacket_UseEntity.h"
|
|
|
|
#include "packets/cPacket_WindowClose.h"
|
|
|
|
#include "packets/cPacket_UpdateSign.h"
|
|
|
|
#include "packets/cPacket_Ping.h"
|
|
|
|
#include "packets/cPacket_PlayerListItem.h"
|
|
|
|
|
2012-02-02 16:13:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// class Game;
|
2011-10-03 14:41:19 -04:00
|
|
|
class cChunk;
|
|
|
|
class cPlayer;
|
2011-11-04 01:01:55 -04:00
|
|
|
class cRedstone;
|
2012-02-02 16:13:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
class cClientHandle // tolua_export
|
|
|
|
{ // tolua_export
|
|
|
|
public:
|
|
|
|
enum ENUM_PRIORITY
|
|
|
|
{
|
|
|
|
E_PRIORITY_LOW,
|
|
|
|
E_PRIORITY_NORMAL
|
|
|
|
};
|
|
|
|
|
2011-12-28 06:27:36 -05:00
|
|
|
static const int MAXBLOCKCHANGEINTERACTIONS = 10; // 5 didn't help, 10 seems to have done the trick
|
2011-12-27 11:27:22 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cClientHandle(const cSocket & a_Socket);
|
|
|
|
~cClientHandle();
|
|
|
|
|
2012-02-02 16:13:24 -05:00
|
|
|
static const int VIEWDISTANCE = 17; // MUST be odd number or CRASH!
|
2011-12-24 18:34:30 -05:00
|
|
|
static const int GENERATEDISTANCE = 2; // Server generates this many chunks AHEAD of player sight.
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
const cSocket & GetSocket();
|
|
|
|
cPlayer* GetPlayer() { return m_Player; } // tolua_export
|
|
|
|
|
2012-02-01 17:38:03 -05:00
|
|
|
void Kick(const AString & a_Reason); //tolua_export
|
|
|
|
void Authenticate(void); // Called by cAuthenticator when the user passes authentication
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
void AddPacket( cPacket * a_Packet );
|
|
|
|
void HandlePendingPackets();
|
|
|
|
|
|
|
|
void StreamChunks();
|
|
|
|
void StreamChunksSmart( cChunk** a_Chunks, unsigned int a_NumChunks );
|
2011-12-26 16:54:08 -05:00
|
|
|
void RemoveFromAllChunks();
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2012-02-01 17:38:03 -05:00
|
|
|
const AString & GetUsername(void) const;
|
2011-12-27 13:39:06 -05:00
|
|
|
|
2011-12-25 21:35:49 -05:00
|
|
|
inline short GetPing() { return m_Ping; }
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
private:
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
int m_ProtocolVersion;
|
|
|
|
AString m_Username;
|
|
|
|
AString m_Password;
|
2012-02-02 16:13:24 -05:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
PacketList m_PendingParsePackets;
|
|
|
|
PacketList m_PendingNrmSendPackets;
|
|
|
|
PacketList m_PendingLowSendPackets;
|
2012-02-02 16:13:24 -05:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
cThread * m_pReceiveThread;
|
|
|
|
cThread * m_pSendThread;
|
2012-02-02 16:13:24 -05:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
cSocket m_Socket;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
cCriticalSection m_CriticalSection;
|
|
|
|
cCriticalSection m_SendCriticalSection;
|
|
|
|
cCriticalSection m_SocketCriticalSection;
|
|
|
|
cSemaphore m_Semaphore;
|
2012-02-02 16:13:24 -05:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
Vector3d m_ConfirmPosition;
|
2012-02-02 16:13:24 -05:00
|
|
|
|
2012-02-03 09:33:40 -05:00
|
|
|
cPacket * m_PacketMap[256];
|
2012-02-02 16:13:24 -05:00
|
|
|
|
|
|
|
bool m_bDestroyed;
|
|
|
|
cPlayer * m_Player;
|
|
|
|
bool m_bKicking;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
float m_TimeLastPacket;
|
|
|
|
|
2011-12-25 21:35:49 -05:00
|
|
|
short m_Ping;
|
2012-02-03 09:33:40 -05:00
|
|
|
int m_PingID;
|
2011-12-27 13:39:06 -05:00
|
|
|
long long m_PingStartTime;
|
|
|
|
long long m_LastPingTime;
|
|
|
|
static const unsigned short PING_TIME_MS = 1000; //minecraft sends 1 per 20 ticks (1 second or every 1000 ms)
|
2011-12-25 21:35:49 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
bool m_bLoggedIn;
|
2012-01-19 13:12:39 -05:00
|
|
|
bool m_bPositionConfirmed;
|
2011-11-01 17:57:08 -04:00
|
|
|
bool m_bSendLoginResponse;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
bool m_bKeepThreadGoing;
|
2012-02-03 09:33:40 -05:00
|
|
|
|
|
|
|
void HandlePacket(cPacket * a_Packet);
|
|
|
|
|
|
|
|
// Packets handled while !m_bLoggedIn:
|
|
|
|
void HandlePing (void);
|
|
|
|
void HandleHandshake (cPacket_Handshake * a_Packet);
|
|
|
|
void HandleLogin (cPacket_Login * a_Packet);
|
|
|
|
void HandleMoveLookLogin(cPacket_PlayerMoveLook * a_Packet); // While !m_bLoggedIn
|
|
|
|
void HandleDefaultLogin (cPacket * a_Packet); // the default case
|
|
|
|
|
|
|
|
// Packets handled while !m_bPositionConfirmed:
|
|
|
|
void HandleMoveLookConfirm(cPacket_PlayerMoveLook * a_Packet); // While !m_bPositionConfirmed
|
|
|
|
|
|
|
|
// Packets handled while m_bPositionConfirmed (normal gameplay):
|
|
|
|
void HandleCreativeInventory(cPacket_CreativeInventoryAction * a_Packet);
|
|
|
|
void HandlePlayerPos (cPacket_PlayerPosition * a_Packet);
|
|
|
|
void HandleBlockDig (cPacket_BlockDig * a_Packet);
|
|
|
|
void HandleBlockPlace (cPacket_BlockPlace * a_Packet);
|
|
|
|
void HandlePickupSpawn (cPacket_PickupSpawn * a_Packet);
|
|
|
|
void HandleChat (cPacket_Chat * a_Packet);
|
|
|
|
void HandlePlayerLook (cPacket_PlayerLook * a_Packet);
|
|
|
|
void HandlePlayerMoveLook (cPacket_PlayerMoveLook * a_Packet); // While m_bPositionConfirmed (normal gameplay)
|
|
|
|
void HandleAnimation (cPacket_ArmAnim * a_Packet);
|
|
|
|
void HandleItemSwitch (cPacket_ItemSwitch * a_Packet);
|
|
|
|
void HandleWindowClose (cPacket_WindowClose * a_Packet);
|
|
|
|
void HandleWindowClick (cPacket_WindowClick * a_Packet);
|
|
|
|
void HandleUpdateSign (cPacket_UpdateSign * a_Packet);
|
|
|
|
void HandleUseEntity (cPacket_UseEntity * a_Packet);
|
|
|
|
void HandleRespawn (void);
|
|
|
|
void HandleDisconnect (cPacket_Disconnect * a_Packet);
|
|
|
|
void HandleKeepAlive (cPacket_KeepAlive * a_Packet);
|
|
|
|
|
|
|
|
/// Returns true if the rate block interactions is within a reasonable limit (bot protection)
|
|
|
|
bool CheckBlockInteractionsRate(void);
|
|
|
|
|
|
|
|
void SendLoginResponse();
|
2011-10-03 14:41:19 -04:00
|
|
|
}; // tolua_export
|
2012-02-02 16:13:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CCLIENTHANDLE_H_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|