1 // Copyright (C) 2008 Ole Laursen
2 // Copyright (C) 2008 Ben Asselstine
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 3 of the License, or
7 // (at your option) any later version.
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 Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include <sigc++/trackable.h>
27 #include <sigc++/signal.h>
29 #include "network-common.h"
30 #include "game-station.h"
40 class GameServer: public GameStation
44 //! Returns the singleton instance. Creates a new one if neccessary.
45 static GameServer * getInstance();
47 //! Deletes the singleton instance.
48 static void deleteInstance();
51 void start(GameScenario *game_scenario, int port, std::string nick);
53 void sit_down (Player *player);
54 void stand_up (Player *player);
55 void chat(std::string message);
57 void sendKillPlayer(Player *player);
58 sigc::signal<void> remote_participant_connected;
59 sigc::signal<void> remote_participant_disconnected;
61 void setGameScenario(GameScenario *scenario) {d_game_scenario = scenario;};
68 GameScenario *d_game_scenario;
69 void onActionDone(NetworkAction *action);
70 void onHistoryDone(NetworkHistory *history);
72 void join(void *conn, std::string payload);
73 void notifyJoin (std::string nickname);
74 void depart(void *conn);
75 void notifyDepart (void *conn, std::string nickname);
76 void sit(void *conn, Player *player, std::string nickname);
77 void notifySit(Player *player, std::string nickname);
78 void stand(void *conn, Player *player, std::string nickname);
79 void notifyStand(Player *player, std::string nickname);
80 void gotRemoteActions(void *conn, const std::string &payload);
81 void gotRemoteHistory(void *conn, const std::string &payload);
82 void notifyChat(std::string message);
84 void sendMap(Participant *part);
85 void sendSeats(void *conn);
86 void sendChatRoster(void *conn);
88 void checkRoundOver();
90 void sendActions(Participant *part);
91 void sendHistories(Participant *part);
93 std::auto_ptr<NetworkServer> network_server;
95 std::list<Participant *> participants;
96 std::list<guint32> players_seated_locally;
98 Participant * play_by_mail_participant;
100 Participant *findParticipantByConn(void *conn);
102 void onGotMessage(void *conn, MessageType type, std::string message);
103 void onConnectionLost(void *conn);
104 void onConnectionMade(void *conn);
105 bool dumpActionsAndHistories(XML_Helper *helper);
106 bool dumpActionsAndHistories(XML_Helper *helper, Player *player);
108 void gotChat(void *conn, std::string message);
109 void gotRoundOver(void *conn);
111 bool player_already_sitting(Player *p);
113 bool add_to_player_list(std::list<guint32> &list, guint32 id);
114 bool remove_from_player_list(std::list<guint32> &list, guint32 id);
115 //! A static pointer for the singleton instance.
116 static GameServer * s_instance;