~ubuntu-branches/ubuntu/precise/pokerth/precise-proposed

« back to all changes in this revision

Viewing changes to src/net/servergamethread.h

  • Committer: Bazaar Package Importer
  • Author(s): Evgeni Golov
  • Date: 2009-06-26 00:23:56 UTC
  • mfrom: (1.1.7 upstream) (5.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090626002356-p3nrzdhhqwk5gpf0
Tags: 0.7.1-1
* New upstream release.
* debian/control:
  + Build-Depend on unversioned boost packages again.
    Closes: #531119, #534086
  + Improve pokerth-server description, one does not need the package
    for one-table games.
  + Standards-Version: 3.8.2, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2007 by Lothar May                                      *
3
 
 *                                                                         *
4
 
 *   This program is free software; you can redistribute it and/or modify  *
5
 
 *   it under the terms of the GNU General Public License as published by  *
6
 
 *   the Free Software Foundation; either version 2 of the License, or     *
7
 
 *   (at your option) any later version.                                   *
8
 
 *                                                                         *
9
 
 *   This program is distributed in the hope that it will be useful,       *
10
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 
 *   GNU General Public License for more details.                          *
13
 
 *                                                                         *
14
 
 *   You should have received a copy of the GNU General Public License     *
15
 
 *   along with this program; if not, write to the                         *
16
 
 *   Free Software Foundation, Inc.,                                       *
17
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 
 ***************************************************************************/
19
 
/* Network server game thread. */
20
 
 
21
 
#ifndef _SERVERGAMETHREAD_H_
22
 
#define _SERVERGAMETHREAD_H_
23
 
 
24
 
#include <net/sessionmanager.h>
25
 
#include <gui/guiinterface.h>
26
 
#include <gamedata.h>
27
 
#include <third_party/boost/timers.hpp>
28
 
 
29
 
#include <deque>
30
 
 
31
 
#define GAME_THREAD_TERMINATE_TIMEOUT   THREAD_WAIT_INFINITE
32
 
 
33
 
 
34
 
class ReceiverHelper;
35
 
class ServerLobbyThread;
36
 
class ServerGameState;
37
 
class ConfigFile;
38
 
struct GameData;
39
 
class Game;
40
 
 
41
 
class ServerGameThread : public Thread
42
 
{
43
 
public:
44
 
        ServerGameThread(
45
 
                ServerLobbyThread &lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig);
46
 
        virtual ~ServerGameThread();
47
 
 
48
 
        u_int32_t GetId() const;
49
 
        const std::string &GetName() const;
50
 
 
51
 
        void AddSession(SessionWrapper session);
52
 
        void RemovePlayer(unsigned playerId, unsigned errorCode);
53
 
 
54
 
        ServerCallback &GetCallback();
55
 
        GameState GetCurRound() const;
56
 
 
57
 
        void SendToAllPlayers(boost::shared_ptr<NetPacket> packet, SessionData::State state);
58
 
        void RemoveAllSessions();
59
 
 
60
 
        bool IsPasswordProtected() const;
61
 
        bool CheckPassword(const std::string &password) const;
62
 
        const GameData &GetGameData() const;
63
 
 
64
 
        boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned playerId) const;
65
 
        PlayerIdList GetPlayerIdList() const;
66
 
        bool IsPlayerConnected(const std::string &name) const;
67
 
 
68
 
        bool IsRunning() const;
69
 
 
70
 
        unsigned GetAdminPlayerId() const;
71
 
        void SetAdminPlayerId(unsigned playerId);
72
 
 
73
 
        // should be protected, but is needed in function.
74
 
        const Game &GetGame() const;
75
 
        Game &GetGame();
76
 
 
77
 
protected:
78
 
 
79
 
        typedef std::deque<SessionWrapper> SessionQueue;
80
 
 
81
 
        // Main function of the thread.
82
 
        virtual void Main();
83
 
        void RemovePlayerLoop();
84
 
        void VoteKickLoop();
85
 
        void VoteKickAction();
86
 
 
87
 
        void InternalStartGame();
88
 
        void ResetGame();
89
 
 
90
 
        void InternalKickPlayer(unsigned playerId);
91
 
        void InternalAskVoteKick(SessionWrapper byWhom, unsigned playerIdWho, unsigned timeoutSec);
92
 
        void InternalDenyAskVoteKick(SessionWrapper byWhom, unsigned playerIdWho, DenyKickPlayerReason reason);
93
 
        void InternalVoteKick(SessionWrapper byWhom, unsigned petitionId, KickVote vote);
94
 
        void InternalDenyVoteKick(SessionWrapper byWhom, unsigned petitionId, DenyVoteReason reason);
95
 
 
96
 
        PlayerDataList GetFullPlayerDataList() const;
97
 
 
98
 
        void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
99
 
        boost::shared_ptr<PlayerData> RemoveComputerPlayer(unsigned playerId);
100
 
        bool IsComputerPlayerActive(unsigned playerId) const;
101
 
        void ResetComputerPlayerList();
102
 
 
103
 
        void GracefulRemoveSession(SessionWrapper session, int reason);
104
 
        void RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason);
105
 
        void ErrorRemoveSession(SessionWrapper session);
106
 
        void SessionError(SessionWrapper session, int errorCode);
107
 
        void MoveSessionToLobby(SessionWrapper session, int reason);
108
 
 
109
 
        void RemoveDisconnectedPlayers();
110
 
        size_t GetCurNumberOfPlayers() const;
111
 
        void AssignPlayerNumbers();
112
 
        bool IsValidPlayer(unsigned playerId) const;
113
 
 
114
 
        ServerLobbyThread &GetLobbyThread();
115
 
 
116
 
        ServerGameState &GetState();
117
 
        void SetState(ServerGameState &newState);
118
 
 
119
 
        const boost::timers::portable::microsec_timer &GetStateTimer() const;
120
 
        boost::timers::portable::microsec_timer &GetStateTimer();
121
 
        unsigned GetStateTimerFlag() const;
122
 
        void SetStateTimerFlag(unsigned flag);
123
 
 
124
 
        ReceiverHelper &GetReceiver();
125
 
 
126
 
        const StartData &GetStartData() const;
127
 
        void SetStartData(const StartData &startData);
128
 
 
129
 
        GuiInterface &GetGui();
130
 
 
131
 
        unsigned GetNextGameNum();
132
 
 
133
 
        const SessionManager &GetSessionManager() const;
134
 
        SessionManager &GetSessionManager();
135
 
 
136
 
private:
137
 
 
138
 
        SessionQueue m_sessionQueue;
139
 
        mutable boost::mutex m_sessionQueueMutex;
140
 
 
141
 
        SessionManager m_sessionManager;
142
 
        PlayerDataList m_computerPlayerList;
143
 
        mutable boost::mutex m_computerPlayerListMutex;
144
 
 
145
 
        RemovePlayerList m_removePlayerList;
146
 
        mutable boost::mutex m_removePlayerListMutex;
147
 
 
148
 
        unsigned m_adminPlayerId;
149
 
        mutable boost::mutex m_adminPlayerIdMutex;
150
 
 
151
 
        boost::shared_ptr<VoteKickData> m_voteKickData;
152
 
        mutable boost::mutex m_voteKickDataMutex;
153
 
 
154
 
        ServerLobbyThread &m_lobbyThread;
155
 
        boost::shared_ptr<ReceiverHelper> m_receiver;
156
 
        GuiInterface &m_gui;
157
 
 
158
 
        const GameData          m_gameData;
159
 
        StartData                       m_startData;
160
 
        boost::shared_ptr<Game> m_game;
161
 
        const u_int32_t         m_id;
162
 
        const std::string       m_name;
163
 
        const std::string       m_password;
164
 
        ConfigFile                 *m_playerConfig;
165
 
        ServerGameState    *m_curState;
166
 
        unsigned                        m_gameNum;
167
 
        unsigned                        m_curPetitionId;
168
 
 
169
 
        boost::timers::portable::microsec_timer m_stateTimer;
170
 
        unsigned                                                                m_stateTimerFlag;
171
 
 
172
 
        boost::timers::portable::microsec_timer m_voteKickActionTimer;
173
 
 
174
 
friend class AbstractServerGameStateReceiving;
175
 
friend class AbstractServerGameStateRunning;
176
 
friend class AbstractServerGameStateTimer;
177
 
friend class ServerGameStateInit;
178
 
friend class ServerGameStateWaitAck;
179
 
friend class ServerGameStateStartGame;
180
 
friend class ServerGameStateStartHand;
181
 
friend class ServerGameStateStartRound;
182
 
friend class ServerGameStateWaitPlayerAction;
183
 
friend class ServerGameStateComputerAction;
184
 
friend class ServerGameStateDealCardsDelay;
185
 
friend class ServerGameStateShowCardsDelay;
186
 
friend class ServerGameStateNextHandDelay;
187
 
friend class ServerGameStateNextGameDelay;
188
 
};
189
 
 
190
 
#endif