From 59e740035e767b28b37cd7d4fdd8698b8f1f0376 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 31 Jan 2012 18:06:24 +0000 Subject: Slight code cleanup, no big changes git-svn-id: http://mc-server.googlecode.com/svn/trunk@202 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 166 +++++++++++++++++++++++++++++++++++------------ source/cMonster.cpp | 6 +- source/cTCPLink.cpp | 2 - 3 files changed, 129 insertions(+), 45 deletions(-) (limited to 'source') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index d5fd0d5c0..1f7045d2b 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -77,18 +77,19 @@ typedef std::list PacketList; + + + + +// fwd: cServer.cpp: +extern std::string GetWSAError(); + + + + + struct cClientHandle::sClientHandleState { - sClientHandleState() - : ProtocolVersion( 23 ) - , pReceiveThread( 0 ) - , pSendThread( 0 ) - , pAuthenticateThread( 0 ) - , pSemaphore( 0 ) - { - for( int i = 0; i < 256; ++i ) - PacketMap[i] = 0; - } int ProtocolVersion; std::string Username; std::string Password; @@ -111,7 +112,25 @@ struct cClientHandle::sClientHandleState Vector3d ConfirmPosition; cPacket* PacketMap[256]; -}; + + sClientHandleState(void) + : ProtocolVersion( 23 ) + , pReceiveThread( 0 ) + , pSendThread( 0 ) + , pAuthenticateThread( 0 ) + , pSemaphore( 0 ) + { + for( int i = 0; i < 256; ++i ) + PacketMap[i] = 0; + } +} ; + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cClientHandle: cClientHandle::cClientHandle(const cSocket & a_Socket) : m_bDestroyed( false ) @@ -135,30 +154,30 @@ cClientHandle::cClientHandle(const cSocket & a_Socket) m_pState->pSemaphore = new cSemaphore( MAX_SEMAPHORES, 0 ); // All the packets that can be received from the client - m_pState->PacketMap[E_KEEP_ALIVE] = new cPacket_KeepAlive; - m_pState->PacketMap[E_HANDSHAKE] = new cPacket_Handshake; - m_pState->PacketMap[E_LOGIN] = new cPacket_Login; - m_pState->PacketMap[E_PLAYERPOS] = new cPacket_PlayerPosition; - m_pState->PacketMap[E_PLAYERLOOK] = new cPacket_PlayerLook; - m_pState->PacketMap[E_PLAYERMOVELOOK] = new cPacket_PlayerMoveLook; - m_pState->PacketMap[E_CHAT] = new cPacket_Chat; - m_pState->PacketMap[E_ANIMATION] = new cPacket_ArmAnim; - m_pState->PacketMap[E_FLYING] = new cPacket_Flying; - m_pState->PacketMap[E_BLOCK_DIG] = new cPacket_BlockDig; - m_pState->PacketMap[E_BLOCK_PLACE] = new cPacket_BlockPlace; - m_pState->PacketMap[E_DISCONNECT] = new cPacket_Disconnect; - m_pState->PacketMap[E_ITEM_SWITCH] = new cPacket_ItemSwitch; - m_pState->PacketMap[E_ENTITY_EQUIPMENT] = new cPacket_EntityEquipment; - m_pState->PacketMap[E_CREATIVE_INVENTORY_ACTION] = new cPacket_CreativeInventoryAction; - m_pState->PacketMap[E_NEW_INVALID_STATE] = new cPacket_NewInvalidState; - m_pState->PacketMap[E_PICKUP_SPAWN] = new cPacket_PickupSpawn; - m_pState->PacketMap[E_USE_ENTITY] = new cPacket_UseEntity; - m_pState->PacketMap[E_WINDOW_CLOSE] = new cPacket_WindowClose; - m_pState->PacketMap[E_WINDOW_CLICK] = new cPacket_WindowClick; - m_pState->PacketMap[E_PACKET_13] = new cPacket_13; - m_pState->PacketMap[E_UPDATE_SIGN] = new cPacket_UpdateSign; - m_pState->PacketMap[E_RESPAWN] = new cPacket_Respawn; - m_pState->PacketMap[E_PING] = new cPacket_Ping; + m_pState->PacketMap[E_KEEP_ALIVE] = new cPacket_KeepAlive; + m_pState->PacketMap[E_HANDSHAKE] = new cPacket_Handshake; + m_pState->PacketMap[E_LOGIN] = new cPacket_Login; + m_pState->PacketMap[E_PLAYERPOS] = new cPacket_PlayerPosition; + m_pState->PacketMap[E_PLAYERLOOK] = new cPacket_PlayerLook; + m_pState->PacketMap[E_PLAYERMOVELOOK] = new cPacket_PlayerMoveLook; + m_pState->PacketMap[E_CHAT] = new cPacket_Chat; + m_pState->PacketMap[E_ANIMATION] = new cPacket_ArmAnim; + m_pState->PacketMap[E_FLYING] = new cPacket_Flying; + m_pState->PacketMap[E_BLOCK_DIG] = new cPacket_BlockDig; + m_pState->PacketMap[E_BLOCK_PLACE] = new cPacket_BlockPlace; + m_pState->PacketMap[E_DISCONNECT] = new cPacket_Disconnect; + m_pState->PacketMap[E_ITEM_SWITCH] = new cPacket_ItemSwitch; + m_pState->PacketMap[E_ENTITY_EQUIPMENT] = new cPacket_EntityEquipment; + m_pState->PacketMap[E_CREATIVE_INVENTORY_ACTION] = new cPacket_CreativeInventoryAction; + m_pState->PacketMap[E_NEW_INVALID_STATE] = new cPacket_NewInvalidState; + m_pState->PacketMap[E_PICKUP_SPAWN] = new cPacket_PickupSpawn; + m_pState->PacketMap[E_USE_ENTITY] = new cPacket_UseEntity; + m_pState->PacketMap[E_WINDOW_CLOSE] = new cPacket_WindowClose; + m_pState->PacketMap[E_WINDOW_CLICK] = new cPacket_WindowClick; + m_pState->PacketMap[E_PACKET_13] = new cPacket_13; + m_pState->PacketMap[E_UPDATE_SIGN] = new cPacket_UpdateSign; + m_pState->PacketMap[E_RESPAWN] = new cPacket_Respawn; + m_pState->PacketMap[E_PING] = new cPacket_Ping; memset( m_LoadedChunks, 0x00, sizeof(cChunk*)*VIEWDISTANCE*VIEWDISTANCE ); @@ -172,6 +191,10 @@ cClientHandle::cClientHandle(const cSocket & a_Socket) LOG("New ClientHandle" ); } + + + + cClientHandle::~cClientHandle() { LOG("Deleting client %s", GetUsername() ); @@ -251,6 +274,10 @@ cClientHandle::~cClientHandle() delete m_pState; } + + + + void cClientHandle::Destroy() { m_bDestroyed = true; @@ -263,12 +290,20 @@ void cClientHandle::Destroy() m_pState->SocketCriticalSection.Unlock(); } + + + + void cClientHandle::Kick( const char* a_Reason ) { Send( cPacket_Disconnect( a_Reason ) ); m_bKicking = true; } + + + + void cClientHandle::StreamChunks() { if( !m_bLoggedIn ) @@ -347,6 +382,10 @@ void cClientHandle::StreamChunks() } } + + + + // Sends chunks to the player from the player position outward void cClientHandle::StreamChunksSmart( cChunk** a_Chunks, unsigned int a_NumChunks ) { @@ -386,6 +425,10 @@ void cClientHandle::StreamChunksSmart( cChunk** a_Chunks, unsigned int a_NumChun } } + + + + // This removes the client from all chunks. Used when switching worlds void cClientHandle::RemoveFromAllChunks() { @@ -400,6 +443,10 @@ void cClientHandle::RemoveFromAllChunks() } } + + + + void cClientHandle::AddPacket(cPacket * a_Packet) { m_pState->CriticalSection.Lock(); @@ -407,12 +454,20 @@ void cClientHandle::AddPacket(cPacket * a_Packet) m_pState->CriticalSection.Unlock(); } + + + + void cClientHandle::RemovePacket( cPacket * a_Packet ) { delete a_Packet; m_pState->PendingParsePackets.remove( a_Packet ); } + + + + void cClientHandle::HandlePendingPackets() { m_pState->CriticalSection.Lock(); @@ -424,12 +479,16 @@ void cClientHandle::HandlePendingPackets() m_pState->CriticalSection.Unlock(); } + + + + void cClientHandle::HandlePacket( cPacket* a_Packet ) { m_TimeLastPacket = cWorld::GetTime(); -// cPacket* CopiedPacket = a_Packet->Clone(); -// a_Packet = CopiedPacket; + // cPacket* CopiedPacket = a_Packet->Clone(); + // a_Packet = CopiedPacket; //LOG("Packet: 0x%02x", a_Packet->m_PacketID ); @@ -1325,6 +1384,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet ) } } + + + + void cClientHandle::AuthenticateThread( void* a_Param ) { cClientHandle* self = (cClientHandle*)a_Param; @@ -1339,6 +1402,9 @@ void cClientHandle::AuthenticateThread( void* a_Param ) } + + + void cClientHandle::Tick(float a_Dt) { (void)a_Dt; @@ -1414,6 +1480,10 @@ void cClientHandle::Tick(float a_Dt) } } + + + + void cClientHandle::Send( const cPacket & a_Packet, ENUM_PRIORITY a_Priority /* = E_PRIORITY_NORMAL */ ) { if( m_bKicking ) return; // Don't add more packets if player is getting kicked anyway @@ -1460,6 +1530,10 @@ void cClientHandle::Send( const cPacket & a_Packet, ENUM_PRIORITY a_Priority /* m_pState->pSemaphore->Signal(); } + + + + void cClientHandle::SendThread( void *lpParam ) { cClientHandle* self = (cClientHandle*)lpParam; @@ -1539,7 +1613,8 @@ void cClientHandle::SendThread( void *lpParam ) } -extern std::string GetWSAError(); + + void cClientHandle::ReceiveThread( void *lpParam ) { @@ -1581,11 +1656,11 @@ void cClientHandle::ReceiveThread( void *lpParam ) } else { - LOG("Unknown packet: 0x%2x %c %i", (unsigned char)temp, (unsigned char)temp, (unsigned char)temp ); + LOG("Unknown packet: 0x%02x \'%c\' %i", (unsigned char)temp, (unsigned char)temp, (unsigned char)temp ); char c_Str[128]; - sprintf_s( c_Str, 128, "[C->S] Unknown PacketID: 0x%2x", (unsigned char)temp ); + sprintf_s( c_Str, 128, "[C->S] Unknown PacketID: 0x%02x", (unsigned char)temp ); cPacket_Disconnect DC(c_Str); DC.Send( socket ); @@ -1602,12 +1677,23 @@ void cClientHandle::ReceiveThread( void *lpParam ) } + + + const char* cClientHandle::GetUsername() { return m_pState->Username.c_str(); } + + + + const cSocket & cClientHandle::GetSocket() { return m_pState->Socket; } + + + + diff --git a/source/cMonster.cpp b/source/cMonster.cpp index e5f970122..fac25df5d 100644 --- a/source/cMonster.cpp +++ b/source/cMonster.cpp @@ -44,7 +44,7 @@ cMonster::cMonster() , m_bMovingToDestination(false) , m_Speed( new Vector3f() ) , m_DestinationTime( 0 ) - , m_Gravity( -9.81 ) + , m_Gravity( -9.81f) , m_bOnGround( false ) , m_DestroyTimer( 0 ) , m_Jump(0) @@ -53,8 +53,8 @@ cMonster::cMonster() , m_SightDistance(25) , m_SeePlayerInterval (0) , m_EMPersonality(AGGRESSIVE) - , m_AttackDamage(1.0) - , m_AttackRange(5.0) + , m_AttackDamage(1.0f) + , m_AttackRange(5.0f) , m_AttackInterval(0) , m_AttackRate(3) , idle_interval(0) diff --git a/source/cTCPLink.cpp b/source/cTCPLink.cpp index 4170da710..65cb0c028 100644 --- a/source/cTCPLink.cpp +++ b/source/cTCPLink.cpp @@ -5,8 +5,6 @@ #include "cSocket.h" #include "MCSocket.h" -#include "cMCLogger.h" - #ifndef _WIN32 #include #endif -- cgit v1.2.3