initial commit, lordsawar source, slightly modified
[lordsawar] / src / pbm-game-server.h
1 // Copyright (C) 2008 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #ifndef PBM_GAME_SERVER_H
19 #define PBM_GAME_SERVER_H
20
21 #include "config.h"
22
23 #include <memory>
24 #include <list>
25 #include <sigc++/trackable.h>
26
27 class NetworkAction;
28 class NetworkHistory;
29 class XML_Helper;
30 class Player;
31
32 class PbmGameServer: public sigc::trackable
33 {
34 public:
35         
36   //! Returns the singleton instance.  Creates a new one if neccessary.
37   static PbmGameServer * getInstance();
38
39   //! Deletes the singleton instance.
40   static void deleteInstance();
41
42   void start();
43
44   bool endTurn(std::string turnfile, bool &broken);
45   
46 protected:
47   PbmGameServer();
48   ~PbmGameServer();
49 private:
50   std::list<NetworkAction*> d_actions;
51   std::list<NetworkHistory*> d_histories;
52   void listenForActions();
53   void listenForHistories();
54   void onActionDone(NetworkAction *action);
55   void onHistoryDone(NetworkHistory *history);
56
57   void clearNetworkActionlist();
58   void clearNetworkHistorylist();
59   bool dumpActionsAndHistories(XML_Helper *helper);
60
61   //! A static pointer for the singleton instance.
62   static PbmGameServer * s_instance;
63 };
64
65 #endif