cClientHandle: gotten rid of the obnoxious m_pState, now using direct members instead

git-svn-id: http://mc-server.googlecode.com/svn/trunk@228 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2012-02-02 21:13:24 +00:00
parent dca87cd214
commit f86d796295
4 changed files with 406 additions and 352 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,32 @@
#pragma once
class cSocket; // cClientHandle.h
class cSemaphore;
class cEvent; // Interfaces to the cClientHandle class representing a client connected to this server. The client need not be a player yet
class Game;
class cPacket;
#pragma once
#ifndef CCLIENTHANDLE_H_INCLUDED
#define CCLIENTHANDLE_H_INCLUDED
#include "Packets/cPacket.h"
#include "Vector3d.h"
// class Game;
class cChunk; class cChunk;
class cPlayer; class cPlayer;
class cRedstone; class cRedstone;
class cClientHandle // tolua_export class cClientHandle // tolua_export
{ // tolua_export { // tolua_export
public: public:
@ -22,7 +41,7 @@ public:
cClientHandle(const cSocket & a_Socket); cClientHandle(const cSocket & a_Socket);
~cClientHandle(); ~cClientHandle();
static const int VIEWDISTANCE = 15; // MUST be odd number or CRASH! static const int VIEWDISTANCE = 17; // MUST be odd number or CRASH!
static const int GENERATEDISTANCE = 2; // Server generates this many chunks AHEAD of player sight. static const int GENERATEDISTANCE = 2; // Server generates this many chunks AHEAD of player sight.
const cSocket & GetSocket(); const cSocket & GetSocket();
@ -62,12 +81,31 @@ private:
void SendLoginResponse(); void SendLoginResponse();
struct sClientHandleState; int mProtocolVersion;
sClientHandleState* m_pState; AString mUsername;
AString mPassword;
bool m_bDestroyed; PacketList mPendingParsePackets;
cPlayer* m_Player; PacketList mPendingNrmSendPackets;
bool m_bKicking; PacketList mPendingLowSendPackets;
cThread* pReceiveThread;
cThread* pSendThread;
cSocket mSocket;
cCriticalSection mCriticalSection;
cCriticalSection mSendCriticalSection;
cCriticalSection mSocketCriticalSection;
cSemaphore mSemaphore;
Vector3d mConfirmPosition;
cPacket * mPacketMap[256];
bool m_bDestroyed;
cPlayer * m_Player;
bool m_bKicking;
float m_TimeLastPacket; float m_TimeLastPacket;
@ -83,3 +121,12 @@ private:
bool m_bKeepThreadGoing; bool m_bKeepThreadGoing;
}; // tolua_export }; // tolua_export
#endif // CCLIENTHANDLE_H_INCLUDED

View File

@ -158,16 +158,17 @@ void cPlayer::SpawnOn( cClientHandle* a_Target )
void cPlayer::Tick(float a_Dt) void cPlayer::Tick(float a_Dt)
{ {
cChunk* InChunk = GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ ); cChunk* InChunk = GetWorld()->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
if( !InChunk ) return; if ( !InChunk ) return;
cPawn::Tick(a_Dt); cPawn::Tick(a_Dt);
if(m_bDirtyOrientation && !m_bDirtyPosition) if (m_bDirtyOrientation && !m_bDirtyPosition)
{ {
cPacket_EntityLook EntityLook( this ); cPacket_EntityLook EntityLook( this );
InChunk->Broadcast( EntityLook, m_ClientHandle ); InChunk->Broadcast( EntityLook, m_ClientHandle );
m_bDirtyOrientation = false; m_bDirtyOrientation = false;
} else if(m_bDirtyPosition ) }
else if(m_bDirtyPosition )
{ {
cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_PLAYER_MOVE, 1, this ); cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_PLAYER_MOVE, 1, this );
@ -242,12 +243,14 @@ void cPlayer::Tick(float a_Dt)
cTimer t1; cTimer t1;
// Send Player List (Once per m_LastPlayerListTime/1000 ms) // Send Player List (Once per m_LastPlayerListTime/1000 ms)
if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime()) { if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime())
{
cWorld::PlayerList PlayerList = cRoot::Get()->GetWorld()->GetAllPlayers(); cWorld::PlayerList PlayerList = cRoot::Get()->GetWorld()->GetAllPlayers();
for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr ) for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr)
{ {
if ((*itr) && (*itr)->GetClientHandle() && !((*itr)->GetClientHandle()->IsDestroyed())) { if ((*itr) && (*itr)->GetClientHandle() && !((*itr)->GetClientHandle()->IsDestroyed()))
cPacket_PlayerListItem PlayerListItem(GetColor() + GetName(), true, GetClientHandle()->GetPing()); {
cPacket_PlayerListItem PlayerListItem(GetColor() + m_pState->PlayerName, true, GetClientHandle()->GetPing());
(*itr)->GetClientHandle()->Send( PlayerListItem ); (*itr)->GetClientHandle()->Send( PlayerListItem );
} }
} }

View File

@ -1,3 +1,4 @@
#pragma once #pragma once
#include "../cSocket.h" #include "../cSocket.h"
@ -7,7 +8,6 @@
class cSocket;
class cPacket class cPacket
{ {
public: public:
@ -53,6 +53,9 @@ public:
static int RecvAll( cSocket & a_Socket, char* a_Data, unsigned int a_Size, int a_Options ); static int RecvAll( cSocket & a_Socket, char* a_Data, unsigned int a_Size, int a_Options );
}; };
typedef std::list <cPacket*> PacketList;
typedef std::deque<cPacket *> PacketQueue;