2007-02-16 00:03:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
* 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. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
/* Network client thread. */
|
|
|
|
|
|
2007-02-17 23:44:45 +00:00
|
|
|
#ifndef _CLIENTTHREAD_H_
|
|
|
|
|
#define _CLIENTTHREAD_H_
|
|
|
|
|
|
2007-02-16 00:03:30 +00:00
|
|
|
#include <core/thread.h>
|
2007-05-20 00:16:29 +00:00
|
|
|
#include <guiinterface.h>
|
|
|
|
|
#include <playerdata.h>
|
|
|
|
|
#include <gamedata.h>
|
2007-02-16 00:03:30 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2007-03-13 23:27:17 +00:00
|
|
|
class ClientContext;
|
2007-02-17 23:44:45 +00:00
|
|
|
class ClientState;
|
2007-02-25 23:16:26 +00:00
|
|
|
class SenderThread;
|
2007-03-13 02:23:12 +00:00
|
|
|
class ReceiverHelper;
|
2007-03-13 23:27:17 +00:00
|
|
|
class ClientSenderCallback;
|
2007-05-20 00:16:29 +00:00
|
|
|
class Game;
|
2007-02-16 00:03:30 +00:00
|
|
|
|
|
|
|
|
class ClientThread : public Thread
|
|
|
|
|
{
|
|
|
|
|
public:
|
2007-05-20 00:16:29 +00:00
|
|
|
ClientThread(GuiInterface &gui);
|
2007-02-16 00:03:30 +00:00
|
|
|
virtual ~ClientThread();
|
|
|
|
|
|
|
|
|
|
// Set the parameters. Does not do any error checking.
|
|
|
|
|
// Error checking will be done during connect
|
|
|
|
|
// (i.e. after starting the thread).
|
2007-04-08 16:18:20 +00:00
|
|
|
void Init(
|
|
|
|
|
const std::string &serverAddress,
|
|
|
|
|
unsigned serverPort,
|
|
|
|
|
bool ipv6,
|
2007-06-04 16:49:19 +00:00
|
|
|
bool sctp,
|
2007-04-08 16:18:20 +00:00
|
|
|
const std::string &pwd,
|
|
|
|
|
const std::string &playerName);
|
2007-02-16 00:03:30 +00:00
|
|
|
|
2007-05-23 22:31:56 +00:00
|
|
|
void SendPlayerAction();
|
2007-05-25 16:03:12 +00:00
|
|
|
void SendChatMessage(const std::string &msg);
|
2007-05-23 22:31:56 +00:00
|
|
|
|
2007-03-13 23:27:17 +00:00
|
|
|
ClientCallback &GetCallback();
|
2007-05-20 00:16:29 +00:00
|
|
|
GuiInterface &GetGui();
|
2007-03-13 23:27:17 +00:00
|
|
|
|
2007-02-16 00:03:30 +00:00
|
|
|
protected:
|
2007-05-06 23:27:08 +00:00
|
|
|
typedef std::map<unsigned, std::string> PlayerMap;
|
2007-02-16 00:03:30 +00:00
|
|
|
|
|
|
|
|
// Main function of the thread.
|
|
|
|
|
virtual void Main();
|
|
|
|
|
|
2007-03-13 23:27:17 +00:00
|
|
|
const ClientContext &GetContext() const;
|
|
|
|
|
ClientContext &GetContext();
|
2007-02-17 23:44:45 +00:00
|
|
|
|
2007-02-18 00:10:26 +00:00
|
|
|
ClientState &GetState();
|
2007-02-17 23:44:45 +00:00
|
|
|
void SetState(ClientState &newState);
|
|
|
|
|
|
2007-02-25 23:16:26 +00:00
|
|
|
SenderThread &GetSender();
|
2007-03-13 02:23:12 +00:00
|
|
|
ReceiverHelper &GetReceiver();
|
2007-02-25 23:16:26 +00:00
|
|
|
|
2007-04-27 21:35:18 +00:00
|
|
|
const GameData &GetGameData() const;
|
|
|
|
|
void SetGameData(const GameData &gameData);
|
2007-05-20 00:16:29 +00:00
|
|
|
const StartData &GetStartData() const;
|
|
|
|
|
void SetStartData(const StartData &startData);
|
2007-05-21 19:00:06 +00:00
|
|
|
int GetGuiPlayerNum() const;
|
|
|
|
|
void SetGuiPlayerNum(int guiPlayerNum);
|
2007-05-20 00:16:29 +00:00
|
|
|
|
|
|
|
|
boost::shared_ptr<Game> GetGame();
|
2007-04-27 21:35:18 +00:00
|
|
|
|
2007-03-13 23:27:17 +00:00
|
|
|
ClientSenderCallback &GetSenderCallback();
|
|
|
|
|
|
2007-05-20 00:16:29 +00:00
|
|
|
void AddPlayerData(boost::shared_ptr<PlayerData> playerData);
|
|
|
|
|
void RemovePlayerData(unsigned playerId);
|
2007-05-25 16:03:12 +00:00
|
|
|
void MapPlayerDataList();
|
|
|
|
|
const PlayerDataList &GetPlayerDataList() const;
|
|
|
|
|
boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned id);
|
2007-05-20 00:16:29 +00:00
|
|
|
|
2007-06-15 10:38:41 +00:00
|
|
|
void RemoveDisconnectedPlayers();
|
|
|
|
|
|
2007-02-16 00:03:30 +00:00
|
|
|
private:
|
|
|
|
|
|
2007-03-13 23:27:17 +00:00
|
|
|
std::auto_ptr<ClientContext> m_context;
|
|
|
|
|
std::auto_ptr<ClientSenderCallback> m_senderCallback;
|
2007-02-17 23:44:45 +00:00
|
|
|
ClientState *m_curState;
|
2007-05-20 00:16:29 +00:00
|
|
|
GuiInterface &m_gui;
|
2007-04-27 21:35:18 +00:00
|
|
|
|
2007-02-25 23:16:26 +00:00
|
|
|
std::auto_ptr<SenderThread> m_sender;
|
2007-03-13 02:23:12 +00:00
|
|
|
std::auto_ptr<ReceiverHelper> m_receiver;
|
2007-02-17 23:44:45 +00:00
|
|
|
|
2007-05-20 00:16:29 +00:00
|
|
|
GameData m_gameData;
|
|
|
|
|
StartData m_startData;
|
|
|
|
|
PlayerDataList m_playerDataList;
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<Game> m_game;
|
|
|
|
|
|
|
|
|
|
unsigned m_curGameId;
|
2007-05-21 19:00:06 +00:00
|
|
|
int m_guiPlayerNum;
|
2007-04-27 21:35:18 +00:00
|
|
|
|
2007-05-25 16:03:12 +00:00
|
|
|
friend class AbstractClientStateReceiving;
|
2007-02-17 23:44:45 +00:00
|
|
|
friend class ClientStateInit;
|
2007-02-25 17:08:58 +00:00
|
|
|
friend class ClientStateStartResolve;
|
|
|
|
|
friend class ClientStateResolving;
|
2007-02-25 18:22:19 +00:00
|
|
|
friend class ClientStateStartConnect;
|
|
|
|
|
friend class ClientStateConnecting;
|
2007-02-25 23:16:26 +00:00
|
|
|
friend class ClientStateStartSession;
|
|
|
|
|
friend class ClientStateWaitSession;
|
2007-03-20 02:20:50 +00:00
|
|
|
friend class ClientStateWaitGame;
|
2007-05-20 00:16:29 +00:00
|
|
|
friend class ClientStateWaitHand;
|
2007-05-24 20:26:23 +00:00
|
|
|
friend class ClientStateRunHand;
|
2007-05-13 22:25:59 +00:00
|
|
|
friend class ClientStateFinal;
|
2007-02-16 00:03:30 +00:00
|
|
|
};
|
|
|
|
|
|
2007-02-17 23:44:45 +00:00
|
|
|
#endif
|