Initial handshake and network game start. Works with multiple clients. Not yet stable, because it is not thread-safe. GUI callbacks not complete yet (server dialog not updated).

This commit is contained in:
lotodore
2007-03-20 02:20:50 +00:00
parent 5f7ff8ca54
commit ef10602d5c
33 changed files with 731 additions and 113 deletions
+21 -5
View File
@@ -29,7 +29,8 @@
#define NET_SERVER_LISTEN_BACKLOG 5
ServerThread::ServerThread()
ServerThread::ServerThread(ServerCallback &cb)
: m_callback(cb)
{
m_context.reset(new ServerContext);
}
@@ -51,6 +52,22 @@ ServerThread::Init(unsigned serverPort, bool ipv6, const std::string &pwd)
context.SetPassword(pwd);
}
void
ServerThread::StartGame()
{
if (!IsRunning())
return; // TODO: throw exception
// TODO: possible race condition
GetRecvThread().StartGame();
}
ServerCallback &
ServerThread::GetCallback()
{
return m_callback;
}
void
ServerThread::Main()
{
@@ -65,9 +82,9 @@ ServerThread::Main()
// The main server thread is simple. It only accepts connections.
AcceptLoop();
}
} catch (const NetException &)
} catch (const NetException &e)
{
// TODO: callback.
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
}
}
@@ -141,8 +158,7 @@ ServerThread::AcceptLoop()
if (selectResult > 0) // accept is possible
{
boost::shared_ptr<ConnectData> tmpData(new ConnectData);
socklen_t addrSize = sizeof(*tmpData->GetSockaddr());
tmpData->SetSocket(accept(context.GetSocket(), (struct sockaddr *)tmpData->GetSockaddr(), &addrSize));
tmpData->SetSocket(accept(context.GetSocket(), NULL, NULL));
if (!IS_VALID_SOCKET(tmpData->GetSocket()))
{