summaryrefslogtreecommitdiffstats
path: root/source/cServer.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-08 11:02:46 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-08 11:02:46 +0100
commitc82c636d8c9ac24c1e73740c35b3a93525783a3d (patch)
tree45c6bd08dc95ac8509834c35096ced5732db3d7a /source/cServer.cpp
parentcSocket: final localhost fix - made it a function (forgotten file) (diff)
downloadcuberite-c82c636d8c9ac24c1e73740c35b3a93525783a3d.tar
cuberite-c82c636d8c9ac24c1e73740c35b3a93525783a3d.tar.gz
cuberite-c82c636d8c9ac24c1e73740c35b3a93525783a3d.tar.bz2
cuberite-c82c636d8c9ac24c1e73740c35b3a93525783a3d.tar.lz
cuberite-c82c636d8c9ac24c1e73740c35b3a93525783a3d.tar.xz
cuberite-c82c636d8c9ac24c1e73740c35b3a93525783a3d.tar.zst
cuberite-c82c636d8c9ac24c1e73740c35b3a93525783a3d.zip
Diffstat (limited to 'source/cServer.cpp')
-rw-r--r--source/cServer.cpp65
1 files changed, 16 insertions, 49 deletions
diff --git a/source/cServer.cpp b/source/cServer.cpp
index 36fb71875..e3fdb2f86 100644
--- a/source/cServer.cpp
+++ b/source/cServer.cpp
@@ -100,46 +100,9 @@ void cServer::ServerListenThread( void *a_Args )
-std::string GetWSAError()
+void cServer::ClientDestroying(const cClientHandle * a_Client)
{
-#ifdef _WIN32
- switch( WSAGetLastError() )
- {
- case WSANOTINITIALISED:
- return "WSANOTINITIALISED";
- case WSAENETDOWN:
- return "WSAENETDOWN";
- case WSAEFAULT:
- return "WSAEFAULT";
- case WSAENOTCONN:
- return "WSAENOTCONN";
- case WSAEINTR:
- return "WSAEINTR";
- case WSAEINPROGRESS:
- return "WSAEINPROGRESS";
- case WSAENETRESET:
- return "WSAENETRESET";
- case WSAENOTSOCK:
- return "WSAENOTSOCK";
- case WSAEOPNOTSUPP:
- return "WSAEOPNOTSUPP";
- case WSAESHUTDOWN:
- return "WSAESHUTDOWN";
- case WSAEWOULDBLOCK:
- return "WSAEWOULDBLOCK";
- case WSAEMSGSIZE:
- return "WSAEMSGSIZE";
- case WSAEINVAL:
- return "WSAEINVAL";
- case WSAECONNABORTED:
- return "WSAECONNABORTED";
- case WSAETIMEDOUT:
- return "WSAETIMEDOUT";
- case WSAECONNRESET:
- return "WSAECONNRESET";
- }
-#endif
- return "No Error";
+ m_SocketThreads.RemoveClient(a_Client);
}
@@ -183,11 +146,11 @@ bool cServer::InitServer( int a_Port )
return false;
}
- if( m_pState->SListenClient.SetReuseAddress() == -1 )
+ if( m_pState->SListenClient.SetReuseAddress() == -1 )
{
- LOGERROR("setsockopt == -1");
- return false;
- }
+ LOGERROR("setsockopt == -1");
+ return false;
+ }
cSocket::SockAddr_In local;
local.Family = cSocket::ADDRESS_FAMILY_INTERNET;
@@ -308,9 +271,16 @@ void cServer::StartListenClient()
return;
}
- LOG("%s connected!", ClientIP.c_str());
+ LOG("Client \"%s\" connected!", ClientIP.c_str());
- cClientHandle *NewHandle = new cClientHandle( SClient );
+ cClientHandle *NewHandle = new cClientHandle(SClient);
+ if (!m_SocketThreads.AddClient(&(NewHandle->GetSocket()), NewHandle))
+ {
+ // For some reason SocketThreads have rejected the handle, clean it up
+ SClient.CloseSocket();
+ delete NewHandle;
+ return;
+ }
m_pState->Clients.push_back( NewHandle ); // TODO - lock list
}
@@ -335,11 +305,8 @@ bool cServer::Tick(float a_Dt)
//World->LockClientHandle(); // TODO - Lock client list
for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end();)
{
- (*itr)->HandlePendingPackets();
-
if( (*itr)->IsDestroyed() )
{
-
cClientHandle* RemoveMe = *itr;
++itr;
m_pState->Clients.remove( RemoveMe );
@@ -464,7 +431,7 @@ void cServer::ServerCommand( const char* a_Cmd )
{
if( split[0].compare( "help" ) == 0 )
{
- printf("===================ALL COMMANDS====================\n");
+ printf("================== ALL COMMANDS ===================\n");
printf("help - Shows this message\n");
printf("save-all - Saves all loaded chunks to disk\n");
printf("list - Lists all players currently in server\n");