2011-07-02 14:38:06 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
2012-12-25 15:06:23 +01:00
|
|
|
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
|
2011-07-02 14:38:06 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2012-12-25 15:06:23 +01:00
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* Additional permission under GNU AGPL version 3 section 7 *
|
|
|
|
|
* *
|
|
|
|
|
* If you modify this program, or any covered work, by linking or *
|
|
|
|
|
* combining it with the OpenSSL project's OpenSSL library (or a *
|
|
|
|
|
* modified version of that library), containing parts covered by the *
|
|
|
|
|
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
|
|
|
|
|
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
|
|
|
|
|
* permission to convey the resulting work. *
|
|
|
|
|
* Corresponding Source for a non-source form of such a combination *
|
|
|
|
|
* shall include the source code for the parts of OpenSSL used as well *
|
|
|
|
|
* as that of the covered work. *
|
2011-07-02 14:38:06 +00:00
|
|
|
*****************************************************************************/
|
2009-05-31 20:14:46 +00:00
|
|
|
/* Network server game. */
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-05-31 20:14:46 +00:00
|
|
|
#ifndef _SERVERGAME_H_
|
|
|
|
|
#define _SERVERGAME_H_
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-12 15:48:34 +00:00
|
|
|
#include <boost/enable_shared_from_this.hpp>
|
2014-03-29 16:13:53 +01:00
|
|
|
#include <boost/asio/steady_timer.hpp>
|
2009-05-07 22:36:51 +00:00
|
|
|
#include <third_party/boost/timers.hpp>
|
2010-08-08 10:23:40 +00:00
|
|
|
#include <map>
|
2009-05-07 22:36:51 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/sessionmanager.h>
|
2014-07-27 18:09:19 +02:00
|
|
|
#include <net/serverdelaytime.h>
|
2009-10-03 20:19:51 +00:00
|
|
|
#include <db/serverdbcallback.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <gui/guiinterface.h>
|
|
|
|
|
#include <gamedata.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ServerLobbyThread;
|
|
|
|
|
class ServerGameState;
|
2010-08-07 23:06:59 +00:00
|
|
|
class ServerDBInterface;
|
2011-08-28 17:14:03 +00:00
|
|
|
class PlayerInterface;
|
2007-11-16 15:24:25 +00:00
|
|
|
class ConfigFile;
|
|
|
|
|
struct GameData;
|
|
|
|
|
class Game;
|
|
|
|
|
|
2009-06-12 15:48:34 +00:00
|
|
|
class ServerGame : public boost::enable_shared_from_this<ServerGame>
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame(
|
2012-04-08 14:36:14 +00:00
|
|
|
boost::shared_ptr<ServerLobbyThread> lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, const GameData &gameData,
|
2014-07-27 18:09:19 +02:00
|
|
|
unsigned adminPlayerId, unsigned creatorPlayerDBId, GuiInterface &gui, ConfigFile &playerConfig, const ServerMode mode);
|
2009-05-31 20:14:46 +00:00
|
|
|
virtual ~ServerGame();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-07 23:25:13 +00:00
|
|
|
void Init();
|
|
|
|
|
void Exit();
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
u_int32_t GetId() const;
|
|
|
|
|
const std::string &GetName() const;
|
2012-04-08 14:36:14 +00:00
|
|
|
unsigned GetCreatorDBId() const;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2013-06-16 10:43:13 +02:00
|
|
|
void AddSession(boost::shared_ptr<SessionData> session, bool spectateOnly);
|
2008-03-06 15:27:31 +00:00
|
|
|
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
2012-01-08 13:02:29 +00:00
|
|
|
void MutePlayer(unsigned playerId, bool mute);
|
2011-12-11 19:37:51 +00:00
|
|
|
void MarkPlayerAsInactive(unsigned playerId);
|
|
|
|
|
void MarkPlayerAsKicked(unsigned playerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
void HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
2009-05-30 22:20:40 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
ServerCallback &GetCallback();
|
|
|
|
|
GameState GetCurRound() const;
|
|
|
|
|
|
2013-06-29 16:23:10 +02:00
|
|
|
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet, int state);
|
|
|
|
|
void SendToAllButOnePlayers(boost::shared_ptr<NetPacket> packet, SessionId except, int state);
|
2010-08-28 14:34:02 +00:00
|
|
|
void RemoveAllSessions();
|
2013-10-05 12:49:21 +02:00
|
|
|
void MoveSpectatorsToLobby();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
bool IsPasswordProtected() const;
|
|
|
|
|
bool CheckPassword(const std::string &password) const;
|
2011-02-06 10:37:40 +00:00
|
|
|
static bool CheckSettings(const GameData &data, const std::string &password, ServerMode mode);
|
2007-11-16 15:24:25 +00:00
|
|
|
const GameData &GetGameData() const;
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned playerId) const;
|
|
|
|
|
PlayerIdList GetPlayerIdList() const;
|
2013-06-29 16:23:10 +02:00
|
|
|
PlayerIdList GetSpectatorIdList() const;
|
2007-11-16 15:24:25 +00:00
|
|
|
bool IsPlayerConnected(const std::string &name) const;
|
2010-03-30 18:03:08 +00:00
|
|
|
bool IsPlayerConnected(unsigned playerId) const;
|
2010-10-02 19:50:49 +00:00
|
|
|
bool IsClientAddressConnected(const std::string &clientAddress) const;
|
2011-08-28 17:14:03 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> GetPlayerInterfaceFromGame(const std::string &playerName);
|
2012-01-08 13:02:29 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> GetPlayerInterfaceFromGame(unsigned playerId);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
bool IsRunning() const;
|
|
|
|
|
|
|
|
|
|
unsigned GetAdminPlayerId() const;
|
|
|
|
|
void SetAdminPlayerId(unsigned playerId);
|
|
|
|
|
|
2010-03-30 17:10:37 +00:00
|
|
|
void AddPlayerInvitation(unsigned playerId);
|
|
|
|
|
void RemovePlayerInvitation(unsigned playerId);
|
|
|
|
|
bool IsPlayerInvited(unsigned playerId) const;
|
|
|
|
|
|
2011-02-06 13:17:07 +00:00
|
|
|
void SetPlayerAutoLeaveOnFinish(unsigned playerId);
|
2010-12-25 21:54:26 +00:00
|
|
|
|
2011-09-11 20:38:18 +00:00
|
|
|
void AddRejoinPlayer(unsigned playerId);
|
|
|
|
|
PlayerIdList GetAndResetRejoinPlayers();
|
|
|
|
|
|
2011-12-21 20:56:41 +00:00
|
|
|
void AddReactivatePlayer(unsigned playerId);
|
|
|
|
|
PlayerIdList GetAndResetReactivatePlayers();
|
|
|
|
|
|
2013-06-29 16:23:10 +02:00
|
|
|
void AddNewSpectator(unsigned playerId);
|
|
|
|
|
PlayerIdList GetAndResetNewSpectators();
|
|
|
|
|
|
2012-04-09 10:22:24 +00:00
|
|
|
void SetNameReported();
|
|
|
|
|
bool IsNameReported() const;
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
// should be protected, but is needed in function.
|
|
|
|
|
const Game &GetGame() const;
|
|
|
|
|
Game &GetGame();
|
|
|
|
|
|
2011-12-16 22:39:24 +00:00
|
|
|
void KickPlayer(unsigned playerId);
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
protected:
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
struct RankingData {
|
2010-08-08 10:23:40 +00:00
|
|
|
RankingData() : dbid(DB_ID_INVALID), place(0) {}
|
|
|
|
|
RankingData(DB_id i, int p = 0) : dbid(i), place(p) {}
|
|
|
|
|
DB_id dbid;
|
|
|
|
|
int place;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::map<unsigned, RankingData> RankingMap;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-06-12 15:48:34 +00:00
|
|
|
void TimerVoteKick(const boost::system::error_code &ec);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2010-10-22 19:42:48 +00:00
|
|
|
PlayerDataList InternalStartGame();
|
2010-08-08 10:23:40 +00:00
|
|
|
void InitRankingMap(const PlayerDataList &playerDataList);
|
2010-08-28 14:34:02 +00:00
|
|
|
void UpdateRankingMap();
|
2010-08-08 10:23:40 +00:00
|
|
|
void SetPlayerPlace(unsigned playerId, int place);
|
2011-12-27 20:44:16 +00:00
|
|
|
void ReplaceRankingPlayer(unsigned oldPlayerId, unsigned newPlayerId);
|
2011-02-06 13:17:07 +00:00
|
|
|
void StoreAndResetRanking();
|
|
|
|
|
void RemoveAutoLeavePlayers();
|
2010-08-08 10:23:40 +00:00
|
|
|
void InternalEndGame();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
void InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, unsigned timeoutSec);
|
|
|
|
|
void InternalDenyAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, DenyKickPlayerReason reason);
|
|
|
|
|
void InternalVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, KickVote vote);
|
|
|
|
|
void InternalDenyVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, DenyVoteReason reason);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
PlayerDataList GetFullPlayerDataList() const;
|
|
|
|
|
|
|
|
|
|
void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
|
2008-12-08 23:06:11 +00:00
|
|
|
boost::shared_ptr<PlayerData> RemoveComputerPlayer(unsigned playerId);
|
|
|
|
|
bool IsComputerPlayerActive(unsigned playerId) const;
|
2007-11-16 15:24:25 +00:00
|
|
|
void ResetComputerPlayerList();
|
|
|
|
|
|
2011-12-11 14:54:17 +00:00
|
|
|
void RemoveSession(boost::shared_ptr<SessionData> session, int reason);
|
2013-08-11 13:25:26 +02:00
|
|
|
void RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason, bool spectateOnly);
|
2011-03-10 20:55:46 +00:00
|
|
|
void SessionError(boost::shared_ptr<SessionData> session, int errorCode);
|
|
|
|
|
void MoveSessionToLobby(boost::shared_ptr<SessionData> session, int reason);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
void RemoveDisconnectedPlayers();
|
2011-04-10 10:04:42 +00:00
|
|
|
int GetCurNumberOfPlayers() const;
|
2010-10-22 19:42:48 +00:00
|
|
|
void AssignPlayerNumbers(PlayerDataList &playerList);
|
2008-12-12 22:38:35 +00:00
|
|
|
bool IsValidPlayer(unsigned playerId) const;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-02-06 13:17:07 +00:00
|
|
|
void AddReportedAvatar(unsigned playerId);
|
|
|
|
|
bool IsAvatarReported(unsigned playerId) const;
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
ServerLobbyThread &GetLobbyThread();
|
|
|
|
|
|
|
|
|
|
ServerGameState &GetState();
|
2009-05-31 13:17:02 +00:00
|
|
|
void SetState(ServerGameState &newState);
|
|
|
|
|
|
2014-03-29 16:13:53 +01:00
|
|
|
boost::asio::steady_timer &GetStateTimer1();
|
|
|
|
|
boost::asio::steady_timer &GetStateTimer2();
|
2007-11-21 23:34:25 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
const StartData &GetStartData() const;
|
|
|
|
|
void SetStartData(const StartData &startData);
|
|
|
|
|
|
|
|
|
|
GuiInterface &GetGui();
|
|
|
|
|
|
|
|
|
|
unsigned GetNextGameNum();
|
|
|
|
|
|
|
|
|
|
const SessionManager &GetSessionManager() const;
|
|
|
|
|
SessionManager &GetSessionManager();
|
2010-08-07 23:06:59 +00:00
|
|
|
ServerDBInterface &GetDatabase();
|
2014-07-27 18:09:19 +02:00
|
|
|
const ServerDelayTime GetServerDelayTime() const;
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
private:
|
2009-05-31 20:14:46 +00:00
|
|
|
ServerGame(const ServerGame &other);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionManager m_sessionManager;
|
|
|
|
|
PlayerDataList m_computerPlayerList;
|
|
|
|
|
mutable boost::mutex m_computerPlayerListMutex;
|
|
|
|
|
|
2010-03-30 17:10:37 +00:00
|
|
|
PlayerIdList m_playerInvitationList;
|
|
|
|
|
mutable boost::mutex m_playerInvitationListMutex;
|
|
|
|
|
|
2011-02-06 13:17:07 +00:00
|
|
|
PlayerIdList m_autoLeavePlayerList;
|
|
|
|
|
mutable boost::mutex m_autoLeavePlayerListMutex;
|
|
|
|
|
|
2011-09-11 20:38:18 +00:00
|
|
|
PlayerIdList m_rejoinPlayerList;
|
|
|
|
|
mutable boost::mutex m_rejoinPlayerListMutex;
|
|
|
|
|
|
2011-12-21 20:56:41 +00:00
|
|
|
PlayerIdList m_reactivatePlayerList;
|
|
|
|
|
mutable boost::mutex m_reactivatePlayerListMutex;
|
|
|
|
|
|
2013-06-29 16:23:10 +02:00
|
|
|
PlayerIdList m_newSpectatorList;
|
|
|
|
|
mutable boost::mutex m_newSpectatorListMutex;
|
|
|
|
|
|
2010-12-25 21:54:26 +00:00
|
|
|
PlayerIdList m_reportedAvatarList;
|
|
|
|
|
|
2010-08-08 10:23:40 +00:00
|
|
|
RankingMap m_rankingMap;
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
unsigned m_adminPlayerId;
|
|
|
|
|
|
2008-12-06 21:10:46 +00:00
|
|
|
boost::shared_ptr<VoteKickData> m_voteKickData;
|
2008-11-16 22:57:11 +00:00
|
|
|
|
2009-06-12 15:48:34 +00:00
|
|
|
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
2010-08-07 23:06:59 +00:00
|
|
|
boost::shared_ptr<ServerDBInterface> m_database;
|
2007-11-16 15:24:25 +00:00
|
|
|
GuiInterface &m_gui;
|
|
|
|
|
|
2014-07-27 18:09:19 +02:00
|
|
|
ServerDelayTime m_serverDelayTime;
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
const GameData m_gameData;
|
|
|
|
|
StartData m_startData;
|
2009-05-31 13:17:02 +00:00
|
|
|
boost::shared_ptr<Game> m_game;
|
|
|
|
|
ServerGameState *m_curState;
|
2009-05-30 22:20:40 +00:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
const u_int32_t m_id;
|
|
|
|
|
const std::string m_name;
|
|
|
|
|
const std::string m_password;
|
2012-04-08 14:36:14 +00:00
|
|
|
const unsigned m_creatorPlayerDBId;
|
2011-01-03 18:41:28 +00:00
|
|
|
ConfigFile &m_playerConfig;
|
2007-11-16 15:24:25 +00:00
|
|
|
unsigned m_gameNum;
|
2008-11-16 22:57:11 +00:00
|
|
|
unsigned m_curPetitionId;
|
2014-03-29 16:13:53 +01:00
|
|
|
boost::asio::steady_timer m_voteKickTimer;
|
|
|
|
|
boost::asio::steady_timer m_stateTimer1;
|
|
|
|
|
boost::asio::steady_timer m_stateTimer2;
|
2012-04-09 10:22:24 +00:00
|
|
|
bool m_isNameReported;
|
2008-12-06 21:10:46 +00:00
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
friend class ServerLobbyThread;
|
|
|
|
|
friend class AbstractServerGameStateReceiving;
|
2011-09-11 17:41:56 +00:00
|
|
|
friend class AbstractServerGameStateRunning;
|
2011-02-11 20:02:08 +00:00
|
|
|
friend class ServerGameStateInit;
|
|
|
|
|
friend class ServerGameStateWaitAck;
|
|
|
|
|
friend class ServerGameStateStartGame;
|
|
|
|
|
friend class ServerGameStateHand;
|
|
|
|
|
friend class ServerGameStateWaitPlayerAction;
|
|
|
|
|
friend class ServerGameStateWaitNextHand;
|
2014-07-11 18:15:40 +02:00
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|