1 // Copyright (C) 2008, 2011, 2014 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 #pragma once
19 #ifndef GAME_STATION_H
20 #define GAME_STATION_H
21 
22 #include <config.h>
23 
24 #include <memory>
25 #include <list>
26 #include <map>
27 #include <sigc++/trackable.h>
28 #include <sigc++/signal.h>
29 #include <sigc++/connection.h>
30 
31 #include "game-client-decoder.h"
32 
33 //! A helper class for GameServer and GameClient objects.
34 class GameStation: public GameClientDecoder
35 {
36 public:
37 
38   sigc::signal<void, Glib::ustring> remote_participant_joins;
39   sigc::signal<void, Player*, Glib::ustring> player_sits;
40   sigc::signal<void, Player*, Glib::ustring> player_stands;
41   sigc::signal<void, Glib::ustring> remote_participant_departs;
42   sigc::signal<void> playerlist_reorder_received;
43   sigc::signal<void, Player*> local_player_moved;
44   sigc::signal<void, Player*> local_player_died;
45   sigc::signal<void, Player*> local_player_starts_move;
46   sigc::signal<void, Player*, int> player_changes_type;
47   sigc::signal<void, Player*, Glib::ustring> player_changes_name;
48   sigc::signal<void, Glib::ustring, Glib::ustring> nickname_changed;
49   sigc::signal<void, Player*> player_gets_turned_off;
50   sigc::signal<void> round_begins;
51   sigc::signal<void> round_ends;
52   sigc::signal<void> game_may_begin;
53   sigc::signal<void, Player *> start_player_turn;
54 
55   void listenForLocalEvents(Player *p);
getProfileId()56   Glib::ustring getProfileId() const {return d_profile_id;};
57 protected:
58   GameStation();
~GameStation()59   virtual ~GameStation() {};
60 
61   virtual void onActionDone(Action *action, guint32 id) = 0;
62   virtual void onHistoryDone(History *history, guint32 id) = 0;
63 
64   void clearNetworkActionlist(std::list<NetworkAction*> &actions);
65   void clearNetworkHistorylist(std::list<NetworkHistory*> &histories);
66 
67   void stopListeningForLocalEvents(Player *p);
68   void stopListeningForLocalEvents();
69 
70   static bool get_message_lobby_activity (Glib::ustring payload,
71                                           guint32 &player_id,
72                                           gint32 &action, bool &reported,
73                                           Glib::ustring &nickname);
74 
setProfileId(Glib::ustring id)75   void setProfileId(Glib::ustring id) {d_profile_id = id;};
76 
77 private:
78   std::map<guint32, sigc::connection> action_listeners;
79   std::map<guint32, sigc::connection> history_listeners;
80   Glib::ustring d_profile_id;
81 };
82 
83 #endif
84