initial commit, lordsawar source, slightly modified
[lordsawar] / src / game-client.h
1 // Copyright (C) 2008 Ole Laursen
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 GAME_CLIENT_H
19 #define GAME_CLIENT_H
20
21 #include "config.h"
22
23 #include <list>
24 #include <memory>
25 #include <sigc++/trackable.h>
26 #include <sigc++/signal.h>
27 class XML_Helper;
28 class NetworkAction;
29 class NetworkHistory;
30
31 #include "network-common.h"
32 #include "game-station.h"
33
34 class NetworkConnection;
35 class GameScenario;
36 class Player;
37
38 class GameClient: public GameStation
39 {
40 public:
41         
42   //! Returns the singleton instance.  Creates a new one if neccessary.
43   static GameClient* getInstance();
44
45   //! Deletes the singleton instance.
46   static void deleteInstance();
47
48   void start(std::string host, guint32 port, std::string nick);
49   void request_seat_manifest();
50
51   sigc::signal<void> client_connected;
52   sigc::signal<void> client_disconnected;
53   sigc::signal<void> client_could_not_connect;
54   
55   void sit_down (Player *player);
56   void stand_up (Player *player);
57   void chat(std::string message);
58
59   std::string getHost() const{return d_host;};
60   guint32 getPort() const{return d_port;};
61
62   void sendRoundOver();
63 protected:
64   GameClient();
65   ~GameClient();
66
67 private:
68   std::auto_ptr<NetworkConnection> network_connection;
69   int player_id;
70
71   void onConnected();
72   void onConnectionLost();
73   void onGotMessage(MessageType type, std::string message);
74
75   void onActionDone(NetworkAction *action);
76   void sendActions();
77
78   void onHistoryDone(NetworkHistory *history);
79   void sendHistories();
80
81   void gotTurnOrder (std::string payload);
82   void gotKillPlayer(Player *player);
83
84   void sat_down(Player *player, std::string nickname);
85   void stood_up(Player *player, std::string nickname);
86
87   std::list<NetworkAction*> actions;
88   std::list<NetworkHistory*> histories;
89   //! A static pointer for the singleton instance.
90   static GameClient * s_instance;
91   bool d_connected;
92   std::string d_host;
93   guint32 d_port;
94 };
95
96 #endif