Files
pokerth/src/net/serverlobbythread.h
T

135 lines
4.5 KiB
C++
Raw Normal View History

/***************************************************************************
* Copyright (C) 2007 by Lothar May *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
2007-03-13 23:27:17 +00:00
/* Network server receive thread. */
2007-03-13 23:27:17 +00:00
#ifndef _SERVERRECVTHREAD_H_
#define _SERVERRECVTHREAD_H_
2007-03-13 23:27:17 +00:00
#include <net/connectdata.h>
#include <net/sessionmanager.h>
#include <net/netpacket.h>
#include <gui/guiinterface.h>
#include <gamedata.h>
#include <deque>
#include <list>
#include <core/boost/timer.hpp>
#define LOBBY_THREAD_TERMINATE_TIMEOUT 200
2007-03-13 23:27:17 +00:00
class SenderThread;
class ReceiverHelper;
class ServerSenderCallback;
2007-08-20 20:37:54 +00:00
class ServerGameThread;
class ConfigFile;
struct GameData;
class Game;
2007-03-13 23:27:17 +00:00
class ServerLobbyThread : public Thread
{
public:
ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig);
virtual ~ServerLobbyThread();
void Init(const std::string &pwd);
2007-03-13 23:27:17 +00:00
void AddConnection(boost::shared_ptr<ConnectData> data);
void CloseSessionDelayed(SessionWrapper session);
2007-03-13 23:27:17 +00:00
void RemoveGame(unsigned id);
u_int32_t GetNextUniquePlayerId();
2007-08-20 20:37:54 +00:00
u_int32_t GetNextGameId();
ServerCallback &GetCallback();
2007-03-13 23:27:17 +00:00
protected:
typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue;
typedef std::list<SessionWrapper> SessionList;
typedef std::list<std::pair<boost::microsec_timer, boost::shared_ptr<SessionData> > > CloseSessionList;
2007-08-20 20:37:54 +00:00
typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap;
typedef std::list<unsigned> RemoveGameList;
2007-03-13 23:27:17 +00:00
// Main function of the thread.
virtual void Main();
void ProcessLoop();
void HandleNetPacketInit(SessionWrapper session, const NetPacketInit &tmpPacket);
void HandleNetPacketCreateGame(SessionWrapper session, const NetPacketCreateGame &tmpPacket);
void HandleNetPacketJoinGame(SessionWrapper session, const NetPacketJoinGame &tmpPacket);
void CloseSessionLoop();
void RemoveGameLoop();
2007-08-21 19:50:13 +00:00
void InternalAddGame(boost::shared_ptr<ServerGameThread> game);
void InternalRemoveGame(boost::shared_ptr<ServerGameThread> game);
void TerminateGames();
void HandleNewConnection(boost::shared_ptr<ConnectData> connData);
SOCKET Select();
void CleanupConnectQueue();
void CleanupSessionMap();
void SessionError(SessionWrapper session, int errorCode);
void SendError(SOCKET s, int errorCode);
2007-03-13 23:27:17 +00:00
SenderThread &GetSender();
ReceiverHelper &GetReceiver();
bool CheckPassword(const std::string &password) const;
2007-03-13 23:27:17 +00:00
ServerSenderCallback &GetSenderCallback();
GuiInterface &GetGui();
2007-03-13 23:27:17 +00:00
bool IsPlayerConnected(const std::string &name);
static boost::shared_ptr<NetPacket> CreateNetPacketGameListNew(const ServerGameThread &game);
2007-08-21 19:50:13 +00:00
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode);
2007-03-13 23:27:17 +00:00
private:
ConnectQueue m_connectQueue;
2007-03-13 23:27:17 +00:00
mutable boost::mutex m_connectQueueMutex;
SessionManager m_sessionManager;
CloseSessionList m_closeSessionList;
mutable boost::mutex m_closeSessionListMutex;
RemoveGameList m_removeGameList;
mutable boost::mutex m_removeGameListMutex;
2007-08-20 20:37:54 +00:00
GameMap m_gameMap;
2007-03-13 23:27:17 +00:00
std::auto_ptr<ReceiverHelper> m_receiver;
std::auto_ptr<SenderThread> m_sender;
std::auto_ptr<ServerSenderCallback> m_senderCallback;
GuiInterface &m_gui;
std::string m_password;
ConfigFile *m_playerConfig;
u_int32_t m_curUniquePlayerId;
2007-08-20 20:37:54 +00:00
u_int32_t m_curGameId;
};
#endif