Game configuration now placed in a struct. Prepared to send/receive game configuration over tcp.

This commit is contained in:
lotodore
2007-04-26 23:07:08 +00:00
parent e202a83fbc
commit 29b6050ee1
16 changed files with 133 additions and 37 deletions
+3
View File
@@ -81,6 +81,9 @@ ServerRecvStateInit::Process(ServerRecvThread &server)
tmpPacket->GetData(playerData);
server.GetCallback().SignalNetServerPlayerJoined(playerData.playerName);
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
NetPacketJoinGameAck::Data joinGameAckData;
// TODO: set data.
static_cast<NetPacketJoinGameAck *>(answer.get())->SetData(joinGameAckData);
server.GetSender().Send(answer, recvSock);
session->SetState(SessionData::Established);
}
+24
View File
@@ -24,6 +24,9 @@
#include <net/sendercallback.h>
#include <net/receiverhelper.h>
#include <net/socket_msg.h>
#include <gamedata.h>
using namespace std;
class ServerSenderCallback : public SenderCallback
{
@@ -47,6 +50,7 @@ ServerRecvThread::ServerRecvThread(ServerCallback &cb)
m_senderCallback.reset(new ServerSenderCallback(*this));
m_sender.reset(new SenderThread(GetSenderCallback()));
m_receiver.reset(new ReceiverHelper);
m_gameData.reset(new GameData);
}
ServerRecvThread::~ServerRecvThread()
@@ -55,6 +59,13 @@ ServerRecvThread::~ServerRecvThread()
CleanupSessionMap();
}
void
ServerRecvThread::Init(const string &pwd, const GameData &gameData)
{
m_password = pwd;
*m_gameData = gameData;
}
void
ServerRecvThread::SendToAllPlayers(boost::shared_ptr<NetPacket> packet)
{
@@ -297,6 +308,19 @@ ServerRecvThread::GetReceiver()
return *m_receiver;
}
const GameData &
ServerRecvThread::GetGameData()
{
assert(m_gameData.get());
return *m_gameData;
}
bool
ServerRecvThread::CheckPassword(const std::string &password)
{
return (password == m_password);
}
ServerSenderCallback &
ServerRecvThread::GetSenderCallback()
{
+4 -2
View File
@@ -41,7 +41,8 @@ ServerThread::~ServerThread()
}
void
ServerThread::Init(unsigned serverPort, bool ipv6, const std::string &pwd)
ServerThread::Init(unsigned serverPort, bool ipv6, const std::string &pwd,
const GameData &gameData)
{
if (IsRunning())
return; // TODO: throw exception
@@ -50,7 +51,8 @@ ServerThread::Init(unsigned serverPort, bool ipv6, const std::string &pwd)
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
context.SetServerPort(serverPort);
context.SetPassword(pwd);
GetRecvThread().Init(pwd, gameData);
}
void