summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-25 10:23:19 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-25 10:23:19 +0200
commit7a43f6be09cfe74dc4a757e949ba88ce033ac419 (patch)
tree5273b2363de5c1ac5201cc443d8682733db598c4 /source
parentProtoProxy: fixed after file renaming (diff)
downloadcuberite-7a43f6be09cfe74dc4a757e949ba88ce033ac419.tar
cuberite-7a43f6be09cfe74dc4a757e949ba88ce033ac419.tar.gz
cuberite-7a43f6be09cfe74dc4a757e949ba88ce033ac419.tar.bz2
cuberite-7a43f6be09cfe74dc4a757e949ba88ce033ac419.tar.lz
cuberite-7a43f6be09cfe74dc4a757e949ba88ce033ac419.tar.xz
cuberite-7a43f6be09cfe74dc4a757e949ba88ce033ac419.tar.zst
cuberite-7a43f6be09cfe74dc4a757e949ba88ce033ac419.zip
Diffstat (limited to 'source')
-rw-r--r--source/ClientHandle.cpp39
-rw-r--r--source/ClientHandle.h10
-rw-r--r--source/OSSupport/File.h6
-rw-r--r--source/OSSupport/SocketThreads.cpp99
-rw-r--r--source/OSSupport/SocketThreads.h26
-rw-r--r--source/Protocol/Protocol.h1
-rw-r--r--source/Protocol/Protocol132.cpp2
-rw-r--r--source/Protocol/Protocol132.h2
-rw-r--r--source/Protocol/ProtocolRecognizer.cpp8
-rw-r--r--source/Protocol/ProtocolRecognizer.h1
-rw-r--r--source/Server.cpp16
-rw-r--r--source/Server.h6
-rw-r--r--source/UI/SlotArea.h1
13 files changed, 103 insertions, 114 deletions
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index a080b4ed6..2296ae23e 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -75,9 +75,9 @@ int cClientHandle::s_ClientCount = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cClientHandle:
-cClientHandle::cClientHandle(const cSocket & a_Socket, int a_ViewDistance)
+cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance)
: m_ViewDistance(a_ViewDistance)
- , m_Socket(a_Socket)
+ , m_IPString(a_Socket->GetIPString())
, m_OutgoingData(64 KiB)
, m_bDestroyed(false)
, m_Player(NULL)
@@ -138,12 +138,9 @@ cClientHandle::~cClientHandle()
}
}
- if (m_Socket.IsValid())
+ if (!m_bKicking)
{
- if (!m_bKicking)
- {
- SendDisconnect("Server shut down? Kthnxbai");
- }
+ SendDisconnect("Server shut down? Kthnxbai");
}
if (m_Player != NULL)
@@ -158,15 +155,12 @@ cClientHandle::~cClientHandle()
AString Data;
m_OutgoingData.ReadAll(Data);
m_OutgoingData.CommitRead();
- cRoot::Get()->GetServer()->WriteToClient(&m_Socket, Data);
+ cRoot::Get()->GetServer()->WriteToClient(this, Data);
}
// Queue the socket to close as soon as it sends all outgoing data:
- cRoot::Get()->GetServer()->QueueClientClose(&m_Socket);
-
- // We need to remove the socket from SocketThreads because we own it and it gets destroyed after this destructor finishes
- // TODO: The socket needs to stay alive, someone else has to own it
- cRoot::Get()->GetServer()->RemoveClient(&m_Socket);
+ cRoot::Get()->GetServer()->QueueClientClose(this);
+ cRoot::Get()->GetServer()->RemoveClient(this);
delete m_Protocol;
m_Protocol = NULL;
@@ -234,7 +228,7 @@ void cClientHandle::Authenticate(void)
m_Player->LoginSetGameMode(World->GetGameMode());
}
- m_Player->SetIP (m_Socket.GetIPString());
+ m_Player->SetIP (m_IPString);
cRoot::Get()->GetPluginManager()->CallHook(cPluginManager::HOOK_PLAYER_SPAWN, 1, m_Player);
@@ -1560,10 +1554,8 @@ void cClientHandle::AddWantedChunk(int a_ChunkX, int a_ChunkZ)
void cClientHandle::PacketBufferFull(void)
{
// Too much data in the incoming queue, the server is probably too busy, kick the client:
- LOGERROR("Too much data in queue for client \"%s\" @ %s, kicking them.", m_Username.c_str(), m_Socket.GetIPString().c_str());
+ LOGERROR("Too much data in queue for client \"%s\" @ %s, kicking them.", m_Username.c_str(), m_IPString.c_str());
SendDisconnect("Server busy");
- // TODO: QueueDestroy();
- cSleep::MilliSleep(1000); // Give packet some time to be received
Destroy();
}
@@ -1573,13 +1565,11 @@ void cClientHandle::PacketBufferFull(void)
void cClientHandle::PacketUnknown(unsigned char a_PacketType)
{
- LOGERROR("Unknown packet type 0x%02x from client \"%s\" @ %s", a_PacketType, m_Username.c_str(), m_Socket.GetIPString().c_str());
+ LOGERROR("Unknown packet type 0x%02x from client \"%s\" @ %s", a_PacketType, m_Username.c_str(), m_IPString.c_str());
AString Reason;
Printf(Reason, "[C->S] Unknown PacketID: 0x%02x", a_PacketType);
SendDisconnect(Reason);
- // TODO: QueueDestroy();
- cSleep::MilliSleep(1000); // Give packet some time to be received
Destroy();
}
@@ -1591,8 +1581,6 @@ void cClientHandle::PacketError(unsigned char a_PacketType)
{
LOGERROR("Protocol error while parsing packet type 0x%02x; disconnecting client \"%s\"", a_PacketType, m_Username.c_str());
SendDisconnect("Protocol error");
- // TODO: QueueDestroy();
- cSleep::MilliSleep(1000); // Give packet some time to be received
Destroy();
}
@@ -1637,11 +1625,8 @@ void cClientHandle::SocketClosed(void)
{
// The socket has been closed for any reason
- // TODO
- /*
- self->Destroy();
- LOG("Client \"%s\" disconnected", GetLogName().c_str());
- */
+ LOG("Client \"%s\" @ %s disconnected", m_Username.c_str(), m_IPString.c_str());
+ Destroy();
}
diff --git a/source/ClientHandle.h b/source/ClientHandle.h
index 83d0fd9c0..8beecd7e4 100644
--- a/source/ClientHandle.h
+++ b/source/ClientHandle.h
@@ -50,11 +50,10 @@ public:
static const int MAX_VIEW_DISTANCE = 10;
static const int MIN_VIEW_DISTANCE = 4;
- cClientHandle(const cSocket & a_Socket, int a_ViewDistance);
- ~cClientHandle();
+ cClientHandle(const cSocket * a_Socket, int a_ViewDistance);
+ virtual ~cClientHandle();
- cSocket & GetSocket (void) { return m_Socket; }
- const AString & GetIPString(void) const { return m_Socket.GetIPString(); }
+ const AString & GetIPString(void) const { return m_IPString; }
cPlayer* GetPlayer() { return m_Player; } // tolua_export
@@ -169,6 +168,8 @@ private:
int m_ViewDistance; // Number of chunks the player can see in each direction; 4 is the minimum ( http://wiki.vg/Protocol_FAQ#.E2.80.A6all_connecting_clients_spasm_and_jerk_uncontrollably.21 )
static const int GENERATEDISTANCE = 2; // Server generates this many chunks AHEAD of player sight. 2 is the minimum, since foliage is generated 1 step behind chunk terrain generation
+
+ AString m_IPString;
int m_ProtocolVersion;
AString m_Username;
@@ -178,7 +179,6 @@ private:
cChunkCoordsList m_LoadedChunks; // Chunks that the player belongs to
cChunkCoordsList m_ChunksToSend; // Chunks that need to be sent to the player (queued because they weren't generated yet or there's not enough time to send them)
- cSocket m_Socket;
cProtocol * m_Protocol;
cCriticalSection m_CSOutgoingData;
diff --git a/source/OSSupport/File.h b/source/OSSupport/File.h
index d16784236..f3d21d450 100644
--- a/source/OSSupport/File.h
+++ b/source/OSSupport/File.h
@@ -46,6 +46,12 @@ Usage:
class cFile
{
public:
+ #ifdef _WIN32
+ static const char PathSeparator = '\\';
+ #else
+ static const char PathSeparator = '/';
+ #endif
+
/// The mode in which to open the file
enum EMode
{
diff --git a/source/OSSupport/SocketThreads.cpp b/source/OSSupport/SocketThreads.cpp
index ae23b4496..dd961770d 100644
--- a/source/OSSupport/SocketThreads.cpp
+++ b/source/OSSupport/SocketThreads.cpp
@@ -37,7 +37,7 @@ cSocketThreads::~cSocketThreads()
-bool cSocketThreads::AddClient(cSocket * a_Socket, cCallback * a_Client)
+bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client)
{
// Add a (socket, client) pair for processing, data from a_Socket is to be sent to a_Client
@@ -71,6 +71,7 @@ bool cSocketThreads::AddClient(cSocket * a_Socket, cCallback * a_Client)
+/*
void cSocketThreads::RemoveClient(const cSocket * a_Socket)
{
// Remove the socket (and associated client) from processing
@@ -87,6 +88,7 @@ void cSocketThreads::RemoveClient(const cSocket * a_Socket)
// Cannot assert here, this may actually happen legally, since cClientHandle has to clean up the socket and it may have already closed in the meantime
// ASSERT(!"Removing an unknown socket");
}
+*/
@@ -133,20 +135,13 @@ void cSocketThreads::NotifyWrite(const cCallback * a_Client)
-void cSocketThreads::Write(const cSocket * a_Socket, const AString & a_Data)
+void cSocketThreads::Write(const cCallback * a_Client, const AString & a_Data)
{
- // Puts a_Data into outgoing data queue for a_Socket
-
- if (!a_Socket->IsValid())
- {
- // Socket already closed, ignore the request
- return;
- }
-
+ // Puts a_Data into outgoing data queue for a_Client
cCSLock Lock(m_CS);
for (cSocketThreadList::iterator itr = m_Threads.begin(); itr != m_Threads.end(); ++itr)
{
- if ((*itr)->Write(a_Socket, a_Data))
+ if ((*itr)->Write(a_Client, a_Data))
{
return;
}
@@ -181,24 +176,20 @@ void cSocketThreads::StopReading(const cCallback * a_Client)
/// Queues the socket for closing, as soon as its outgoing data is sent
-void cSocketThreads::QueueClose(const cSocket * a_Socket)
+void cSocketThreads::QueueClose(const cCallback * a_Client)
{
- if (!a_Socket->IsValid())
- {
- // Already closed, ignore the request
- return;
- }
+ LOGD("QueueClose(client %p)", a_Client);
cCSLock Lock(m_CS);
for (cSocketThreadList::iterator itr = m_Threads.begin(); itr != m_Threads.end(); ++itr)
{
- if ((*itr)->QueueClose(a_Socket))
+ if ((*itr)->QueueClose(a_Client))
{
return;
}
} // for itr - m_Threads[]
- ASSERT(!"Queueing close of an unknown socket");
+ ASSERT(!"Queueing close of an unknown client");
}
@@ -240,13 +231,15 @@ cSocketThreads::cSocketThread::~cSocketThread()
-void cSocketThreads::cSocketThread::AddClient(cSocket * a_Socket, cCallback * a_Client)
+void cSocketThreads::cSocketThread::AddClient(const cSocket & a_Socket, cCallback * a_Client)
{
ASSERT(m_NumSlots < MAX_SLOTS); // Use HasEmptySlot() to check before adding
m_Slots[m_NumSlots].m_Client = a_Client;
m_Slots[m_NumSlots].m_Socket = a_Socket;
m_Slots[m_NumSlots].m_Outgoing.clear();
+ m_Slots[m_NumSlots].m_ShouldClose = false;
+ m_Slots[m_NumSlots].m_ShouldCallClient = true;
m_NumSlots++;
// Notify the thread of the change:
@@ -297,7 +290,7 @@ bool cSocketThreads::cSocketThread::RemoveSocket(const cSocket * a_Socket)
for (int i = m_NumSlots - 1; i >= 0 ; --i)
{
- if (m_Slots[i].m_Socket != a_Socket)
+ if (m_Slots[i].m_Socket != *a_Socket)
{
continue;
}
@@ -339,7 +332,7 @@ bool cSocketThreads::cSocketThread::HasSocket(const cSocket * a_Socket) const
{
for (int i = m_NumSlots - 1; i >= 0; --i)
{
- if (m_Slots[i].m_Socket->GetSocket() == a_Socket->GetSocket())
+ if (m_Slots[i].m_Socket == *a_Socket)
{
return true;
}
@@ -367,12 +360,12 @@ bool cSocketThreads::cSocketThread::NotifyWrite(const cCallback * a_Client)
-bool cSocketThreads::cSocketThread::Write(const cSocket * a_Socket, const AString & a_Data)
+bool cSocketThreads::cSocketThread::Write(const cCallback * a_Client, const AString & a_Data)
{
// Returns true if socket handled by this thread
for (int i = m_NumSlots - 1; i >= 0; --i)
{
- if (m_Slots[i].m_Socket == a_Socket)
+ if (m_Slots[i].m_Client == a_Client)
{
m_Slots[i].m_Outgoing.append(a_Data);
@@ -397,13 +390,7 @@ bool cSocketThreads::cSocketThread::StopReading (const cCallback * a_Client)
{
if (m_Slots[i].m_Client == a_Client)
{
- m_Slots[i].m_Client = NULL;
- m_Slots[i].m_ShouldClose = false;
-
- // Notify the thread that there's a stop reading request:
- ASSERT(m_ControlSocket2.IsValid());
- m_ControlSocket2.Send("s", 1);
-
+ m_Slots[i].m_ShouldCallClient = false;
return true;
}
} // for i - m_Slots[]
@@ -414,14 +401,13 @@ bool cSocketThreads::cSocketThread::StopReading (const cCallback * a_Client)
-bool cSocketThreads::cSocketThread::QueueClose(const cSocket * a_Socket)
+bool cSocketThreads::cSocketThread::QueueClose(const cCallback * a_Client)
{
// Returns true if socket handled by this thread
for (int i = m_NumSlots - 1; i >= 0; --i)
{
- if (m_Slots[i].m_Socket == a_Socket)
+ if (m_Slots[i].m_Client == a_Client)
{
- ASSERT(m_Slots[i].m_Client == NULL); // Should have stopped reading first
m_Slots[i].m_ShouldClose = true;
// Notify the thread that there's a close queued (in case its conditions are already met):
@@ -561,11 +547,11 @@ void cSocketThreads::cSocketThread::PrepareSet(fd_set * a_Set, cSocket::xSocket
cCSLock Lock(m_Parent->m_CS);
for (int i = m_NumSlots - 1; i >= 0; --i)
{
- if (!m_Slots[i].m_Socket->IsValid())
+ if (!m_Slots[i].m_Socket.IsValid())
{
continue;
}
- cSocket::xSocket s = m_Slots[i].m_Socket->GetSocket();
+ cSocket::xSocket s = m_Slots[i].m_Socket.GetSocket();
FD_SET(s, a_Set);
if (s > a_Highest)
{
@@ -593,24 +579,24 @@ void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read)
cCSLock Lock(m_Parent->m_CS);
for (int i = m_NumSlots - 1; i >= 0; --i)
{
- if (!FD_ISSET(m_Slots[i].m_Socket->GetSocket(), a_Read))
+ if (!FD_ISSET(m_Slots[i].m_Socket.GetSocket(), a_Read))
{
continue;
}
char Buffer[1024];
- int Received = m_Slots[i].m_Socket->Receive(Buffer, ARRAYCOUNT(Buffer), 0);
+ int Received = m_Slots[i].m_Socket.Receive(Buffer, ARRAYCOUNT(Buffer), 0);
if (Received == 0)
{
// The socket has been closed by the remote party, close our socket and let it be removed after we process all reading
- m_Slots[i].m_Socket->CloseSocket();
- if (m_Slots[i].m_Client != NULL)
+ m_Slots[i].m_Socket.CloseSocket();
+ if (m_Slots[i].m_ShouldCallClient)
{
m_Slots[i].m_Client->SocketClosed();
}
}
else if (Received > 0)
{
- if (m_Slots[i].m_Client != NULL)
+ if (m_Slots[i].m_ShouldCallClient)
{
m_Slots[i].m_Client->DataReceived(Buffer, Received);
}
@@ -618,8 +604,8 @@ void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read)
else
{
// The socket has encountered an error, close it and let it be removed after we process all reading
- m_Slots[i].m_Socket->CloseSocket();
- if (m_Slots[i].m_Client != NULL)
+ m_Slots[i].m_Socket.CloseSocket();
+ if (m_Slots[i].m_ShouldCallClient)
{
m_Slots[i].m_Client->SocketClosed();
}
@@ -637,38 +623,41 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write)
cCSLock Lock(m_Parent->m_CS);
for (int i = m_NumSlots - 1; i >= 0; --i)
{
- cSocket Socket(*(m_Slots[i].m_Socket));
- if (!Socket.IsValid() || !FD_ISSET(Socket.GetSocket(), a_Write))
+ if (!m_Slots[i].m_Socket.IsValid() || !FD_ISSET(m_Slots[i].m_Socket.GetSocket(), a_Write))
{
continue;
}
if (m_Slots[i].m_Outgoing.empty())
{
// Request another chunk of outgoing data:
- if (m_Slots[i].m_Client != NULL)
+ if (m_Slots[i].m_ShouldCallClient)
{
m_Slots[i].m_Client->GetOutgoingData(m_Slots[i].m_Outgoing);
}
if (m_Slots[i].m_Outgoing.empty())
{
// Nothing ready
- if ((m_Slots[i].m_Client == NULL) && m_Slots[i].m_ShouldClose)
+ if (m_Slots[i].m_ShouldClose)
{
// Socket was queued for closing and there's no more data to send, close it now:
- m_Slots[i].m_Socket->CloseSocket();
- m_Slots[i] = m_Slots[--m_NumSlots];
+
+ // DEBUG
+ LOGD("Socket was queued for closing, closing now. Slot %d, client %p, socket %d", i, m_Slots[i].m_Client, m_Slots[i].m_Socket.GetSocket());
+
+ m_Slots[i].m_Socket.CloseSocket();
+ // The slot must be freed actively by the client, using RemoveClient()
}
continue;
}
} // if (outgoing data is empty)
- int Sent = m_Slots[i].m_Socket->Send(m_Slots[i].m_Outgoing.data(), m_Slots[i].m_Outgoing.size());
+ int Sent = m_Slots[i].m_Socket.Send(m_Slots[i].m_Outgoing.data(), m_Slots[i].m_Outgoing.size());
if (Sent < 0)
{
int Err = cSocket::GetLastError();
- LOGWARNING("Error %d while writing to client \"%s\", disconnecting. \"%s\"", Err, m_Slots[i].m_Socket->GetIPString().c_str(), cSocket::GetErrorString(Err).c_str());
- m_Slots[i].m_Socket->CloseSocket();
- if (m_Slots[i].m_Client != NULL)
+ LOGWARNING("Error %d while writing to client \"%s\", disconnecting. \"%s\"", Err, m_Slots[i].m_Socket.GetIPString().c_str(), cSocket::GetErrorString(Err).c_str());
+ m_Slots[i].m_Socket.CloseSocket();
+ if (m_Slots[i].m_ShouldCallClient)
{
m_Slots[i].m_Client->SocketClosed();
}
@@ -695,12 +684,12 @@ void cSocketThreads::cSocketThread::WriteToSockets(fd_set * a_Write)
void cSocketThreads::cSocketThread::RemoveClosedSockets(void)
{
- // Removes sockets that have closed from m_Slots[]
+ // Removes sockets that have been queued for closing from m_Slots[]
cCSLock Lock(m_Parent->m_CS);
for (int i = m_NumSlots - 1; i >= 0; --i)
{
- if (m_Slots[i].m_Socket->IsValid())
+ if (!m_Slots[i].m_ShouldClose || !m_Slots[i].m_Outgoing.empty())
{
continue;
}
diff --git a/source/OSSupport/SocketThreads.h b/source/OSSupport/SocketThreads.h
index 4683e0e4d..974270a11 100644
--- a/source/OSSupport/SocketThreads.h
+++ b/source/OSSupport/SocketThreads.h
@@ -76,25 +76,22 @@ public:
~cSocketThreads();
/// Add a (socket, client) pair for processing, data from a_Socket is to be sent to a_Client; returns true if successful
- bool AddClient(cSocket * a_Socket, cCallback * a_Client);
+ bool AddClient(const cSocket & a_Socket, cCallback * a_Client);
- /// Remove the socket (and associated client) from processing
- void RemoveClient(const cSocket * a_Socket);
-
- /// Remove the associated socket and the client from processing
+ /// Remove the associated socket and the client from processing. The socket is left to send its data and is removed only after all its m_OutgoingData is sent
void RemoveClient(const cCallback * a_Client);
/// Notify the thread responsible for a_Client that the client has something to write
void NotifyWrite(const cCallback * a_Client);
- /// Puts a_Data into outgoing data queue for a_Socket
- void Write(const cSocket * a_Socket, const AString & a_Data);
+ /// Puts a_Data into outgoing data queue for a_Client
+ void Write(const cCallback * a_Client, const AString & a_Data);
- /// Stops reading from the socket - when this call returns, no more calls to the callbacks are made
+ /// Stops reading from the client - when this call returns, no more calls to the callbacks are made
void StopReading(const cCallback * a_Client);
- /// Queues the socket for closing, as soon as its outgoing data is sent
- void QueueClose(const cSocket * a_Socket);
+ /// Queues the client for closing, as soon as its outgoing data is sent
+ void QueueClose(const cCallback * a_Client);
private:
@@ -112,15 +109,15 @@ private:
bool HasEmptySlot(void) const {return m_NumSlots < MAX_SLOTS; }
bool IsEmpty (void) const {return m_NumSlots == 0; }
- void AddClient (cSocket * a_Socket, cCallback * a_Client);
+ void AddClient (const cSocket & a_Socket, cCallback * a_Client); // Takes ownership of the socket
bool RemoveClient(const cCallback * a_Client); // Returns true if removed, false if not found
bool RemoveSocket(const cSocket * a_Socket); // Returns true if removed, false if not found
bool HasClient (const cCallback * a_Client) const;
bool HasSocket (const cSocket * a_Socket) const;
bool NotifyWrite (const cCallback * a_Client); // Returns true if client handled by this thread
- bool Write (const cSocket * a_Socket, const AString & a_Data); // Returns true if socket handled by this thread
+ bool Write (const cCallback * a_Client, const AString & a_Data); // Returns true if client handled by this thread
bool StopReading (const cCallback * a_Client); // Returns true if client handled by this thread
- bool QueueClose (const cSocket * a_Socket); // Returns true if socket handled by this thread
+ bool QueueClose (const cCallback * a_Client); // Returns true if client handled by this thread
bool Start(void); // Hide the cIsThread's Start method, we need to provide our own startup to create the control socket
@@ -138,10 +135,11 @@ private:
// Manipulation with these assumes that the parent's m_CS is locked
struct sSlot
{
- cSocket * m_Socket;
+ cSocket m_Socket; // The socket is primarily owned by this
cCallback * m_Client;
AString m_Outgoing; // If sending writes only partial data, the rest is stored here for another send
bool m_ShouldClose; // If true, the socket is to be closed after sending all outgoing data
+ bool m_ShouldCallClient; // If true, the client callbacks are called. Set to false in StopReading()
} ;
sSlot m_Slots[MAX_SLOTS];
int m_NumSlots; // Number of slots actually used
diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h
index af915a2bb..e871e958a 100644
--- a/source/Protocol/Protocol.h
+++ b/source/Protocol/Protocol.h
@@ -37,6 +37,7 @@ public:
m_Client(a_Client)
{
}
+ virtual ~cProtocol() {}
/// Called when client sends some data
virtual void DataReceived(const char * a_Data, int a_Size) = 0;
diff --git a/source/Protocol/Protocol132.cpp b/source/Protocol/Protocol132.cpp
index 32b55e280..a39697526 100644
--- a/source/Protocol/Protocol132.cpp
+++ b/source/Protocol/Protocol132.cpp
@@ -150,6 +150,7 @@ cProtocol132::cProtocol132(cClientHandle * a_Client) :
super(a_Client),
m_IsEncrypted(false)
{
+ LOGD("Created cProtocol132 at %p", this);
}
@@ -162,6 +163,7 @@ cProtocol132::~cProtocol132()
{
LOGD("There are %d unsent bytes while deleting cProtocol132", m_DataToSend.size());
}
+ LOGD("Deleted cProtocol132 at %p", this);
}
diff --git a/source/Protocol/Protocol132.h b/source/Protocol/Protocol132.h
index dde34ca30..5fb82148d 100644
--- a/source/Protocol/Protocol132.h
+++ b/source/Protocol/Protocol132.h
@@ -24,8 +24,6 @@ class cProtocol132 :
public:
cProtocol132(cClientHandle * a_Client);
-
- // DEBUG:
virtual ~cProtocol132();
/// Called when client sends some data:
diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp
index 095d63f8f..96a831063 100644
--- a/source/Protocol/ProtocolRecognizer.cpp
+++ b/source/Protocol/ProtocolRecognizer.cpp
@@ -29,6 +29,14 @@ cProtocolRecognizer::cProtocolRecognizer(cClientHandle * a_Client) :
+cProtocolRecognizer::~cProtocolRecognizer()
+{
+}
+
+
+
+
+
void cProtocolRecognizer::DataReceived(const char * a_Data, int a_Size)
{
if (m_Protocol == NULL)
diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h
index 3eff8d2ab..0a42c279f 100644
--- a/source/Protocol/ProtocolRecognizer.h
+++ b/source/Protocol/ProtocolRecognizer.h
@@ -32,6 +32,7 @@ class cProtocolRecognizer :
public:
cProtocolRecognizer(cClientHandle * a_Client);
+ virtual ~cProtocolRecognizer();
/// Called when client sends some data:
virtual void DataReceived(const char * a_Data, int a_Size) override;
diff --git a/source/Server.cpp b/source/Server.cpp
index c77892076..8cf923882 100644
--- a/source/Server.cpp
+++ b/source/Server.cpp
@@ -113,27 +113,27 @@ void cServer::NotifyClientWrite(const cClientHandle * a_Client)
-void cServer::WriteToClient(const cSocket * a_Socket, const AString & a_Data)
+void cServer::WriteToClient(const cClientHandle * a_Client, const AString & a_Data)
{
- m_SocketThreads.Write(a_Socket, a_Data);
+ m_SocketThreads.Write(a_Client, a_Data);
}
-void cServer::QueueClientClose(const cSocket * a_Socket)
+void cServer::QueueClientClose(const cClientHandle * a_Client)
{
- m_SocketThreads.QueueClose(a_Socket);
+ m_SocketThreads.QueueClose(a_Client);
}
-void cServer::RemoveClient(const cSocket * a_Socket)
+void cServer::RemoveClient(const cClientHandle * a_Client)
{
- m_SocketThreads.RemoveClient(a_Socket);
+ m_SocketThreads.RemoveClient(a_Client);
}
@@ -340,8 +340,8 @@ void cServer::StartListenClient()
LOG("Client \"%s\" connected!", ClientIP.c_str());
- cClientHandle *NewHandle = new cClientHandle(SClient, m_ClientViewDistance);
- if (!m_SocketThreads.AddClient(&(NewHandle->GetSocket()), NewHandle))
+ cClientHandle * NewHandle = new cClientHandle(&SClient, m_ClientViewDistance);
+ if (!m_SocketThreads.AddClient(SClient, NewHandle))
{
// For some reason SocketThreads have rejected the handle, clean it up
LOGERROR("Client \"%s\" cannot be handled, server probably unstable", SClient.GetIPString().c_str());
diff --git a/source/Server.h b/source/Server.h
index b3599aa1e..8d21e7834 100644
--- a/source/Server.h
+++ b/source/Server.h
@@ -62,11 +62,11 @@ public: //tolua_export
void NotifyClientWrite(const cClientHandle * a_Client); // Notifies m_SocketThreads that client has something to be written
- void WriteToClient(const cSocket * a_Socket, const AString & a_Data); // Queues outgoing data for the socket through m_SocketThreads
+ void WriteToClient(const cClientHandle * a_Client, const AString & a_Data); // Queues outgoing data for the client through m_SocketThreads
- void QueueClientClose(const cSocket * a_Socket); // Queues the socket to close when all its outgoing data is sent
+ void QueueClientClose(const cClientHandle * a_Client); // Queues the clienthandle to close when all its outgoing data is sent
- void RemoveClient(const cSocket * a_Socket); // Removes the socket from m_SocketThreads
+ void RemoveClient(const cClientHandle * a_Client); // Removes the clienthandle from m_SocketThreads
CryptoPP::RSA::PrivateKey & GetPrivateKey(void) { return m_PrivateKey; }
CryptoPP::RSA::PublicKey & GetPublicKey (void) { return m_PublicKey; }
diff --git a/source/UI/SlotArea.h b/source/UI/SlotArea.h
index e356fbdd8..ffb8ed553 100644
--- a/source/UI/SlotArea.h
+++ b/source/UI/SlotArea.h
@@ -26,6 +26,7 @@ class cSlotArea
{
public:
cSlotArea(int a_NumSlots, cWindow & a_ParentWindow);
+ virtual ~cSlotArea() {} // force a virtual destructor in all subclasses
int GetNumSlots(void) const { return m_NumSlots; }