Robot Devastation
NetworkManager.hpp
1 // Authors: see AUTHORS.md at project root.
2 // CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
3 // URL: https://github.com/asrob-uc3m/robotDevastation
4 
5 #ifndef __RD_NETWORK_MANAGER_HPP__
6 #define __RD_NETWORK_MANAGER_HPP__
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 
12 #include "Player.hpp"
13 #include "Target.hpp"
14 #include "Weapon.hpp"
15 #include "NetworkEventListener.hpp"
16 #include "NetworkManager.hpp"
17 #include "MentalMapEventListener.hpp"
18 
19 namespace rd{
20 
38 {
39  public:
40  //------------------------------ Construction & destruction ---------------------------------------------------//
47 
53  static NetworkManager *getNetworkManager(const std::string & id);
54 
56  static bool destroyNetworkManager();
57 
58  virtual ~NetworkManager();
59 
60 
61  //------------------------------ Manager Startup & Halting ----------------------------------------------------//
67  virtual bool start() = 0;
68 
70  virtual bool stop() = 0;
71 
73  virtual bool isStopped() const = 0;
74 
75 
76  //------------------------------ Configuration & Listeners ----------------------------------------------------//
79 
82 
84  virtual bool configure(const std::string & parameter, const Player & value);
85 
86 
87 
88  //-- Network API
89  //--------------------------------------------------------------------------------------------
91  virtual bool sendPlayerHit(const Player & player, int damage) = 0;
92 
94  virtual bool login() = 0;
95 
97  virtual bool logout() = 0;
98 
100  virtual bool keepAlive() = 0;
101 
102  //-- MentalMap listener API
103  //-------------------------------------------------------------------------------------------
105  bool onTargetHit(const Target & target, const Player & player, const Weapon & weapon);
106 
108  bool onRespawn(const Player & player);
109 
110 
111 protected:
116  static bool Register(NetworkManager *manager, const std::string & id);
117 
119  std::vector<NetworkEventListener *> listeners;
120 
121 
122  private:
125 
127  static std::string currentId;
128 
130  static std::map< std::string, NetworkManager * > networkManagerRegistry;
131 
132 
133 };
134 
135 }
136 
137 #endif //-- __RD_NETWORK_MANAGER_HPP__
rd::NetworkManager::start
virtual bool start()=0
Start the network manager.
rd::NetworkManager::keepAlive
virtual bool keepAlive()=0
Keeps the user connected to the server (requires to be called periodically)
rd::NetworkManager::Register
static bool Register(NetworkManager *manager, const std::string &id)
This function allows subclasses to install their unique instances in the singleton register to be sel...
Definition: NetworkManager.cpp:120
rd::Player
Class that represents a player of this game, with a 'unique' id, name, health, team id and score.
Definition: Player.hpp:21
rd
The main, catch-all namespace for Robot Devastation.
Definition: groups.dox:4
rd::NetworkManager::onTargetHit
bool onTargetHit(const Target &target, const Player &player, const Weapon &weapon)
Implementation of MentalMapEventListener interface.
Definition: NetworkManager.cpp:110
rd::NetworkManager::onRespawn
bool onRespawn(const Player &player)
Implementation of MentalMapEventListener interface.
Definition: NetworkManager.cpp:115
rd::NetworkManager::networkManagerInstance
static NetworkManager * networkManagerInstance
Stores the unique instance of the NetworkManager.
Definition: NetworkManager.hpp:124
rd::NetworkManager::addNetworkEventListener
bool addNetworkEventListener(NetworkEventListener *listener)
Adds a NetworkEventListener to the list of observers to be notified of events.
Definition: NetworkManager.cpp:93
rd::NetworkManager::isStopped
virtual bool isStopped() const =0
Returns true if manager is stopped (obviously)
rd::NetworkManager::sendPlayerHit
virtual bool sendPlayerHit(const Player &player, int damage)=0
Communicate to the network that a player has been hit by the user.
rd::NetworkManager::configure
virtual bool configure(const std::string &parameter, const Player &value)
Configures a parameter with a value.
Definition: NetworkManager.cpp:105
rd::Weapon
Class that represents a weapon.
Definition: Weapon.hpp:22
rd::NetworkManager::networkManagerRegistry
static std::map< std::string, NetworkManager * > networkManagerRegistry
Stores all the NetworkManager that have been registered.
Definition: NetworkManager.hpp:130
rd::NetworkManager::destroyNetworkManager
static bool destroyNetworkManager()
Deallocate all the registered NetworkManager.
Definition: NetworkManager.cpp:53
rd::NetworkManager::removeNetworkEventListeners
bool removeNetworkEventListeners()
Unregisters all the NetworkEventListener stored.
Definition: NetworkManager.cpp:99
rd::NetworkManager::logout
virtual bool logout()=0
Log the user out of the network.
rd::NetworkManager::stop
virtual bool stop()=0
Stop the network manager.
rd::NetworkManager::currentId
static std::string currentId
Stores the id of the current unique instance used.
Definition: NetworkManager.hpp:127
rd::Target
Class that represents a target detected. This target is (or should be) associated to a player.
Definition: Target.hpp:18
rd::NetworkManager::getNetworkManager
static NetworkManager * getNetworkManager()
Get a reference to the NetworkManager.
Definition: NetworkManager.cpp:16
rd::NetworkManager::listeners
std::vector< NetworkEventListener * > listeners
Observers registered to be notified of network events.
Definition: NetworkManager.hpp:119
rd::NetworkEventListener
Interface for objects that can be notified of input events by the NetworkManager.
Definition: NetworkEventListener.hpp:18
rd::NetworkManager
Manages the communications between the user and the RobotDevastation network.
Definition: NetworkManager.hpp:37
rd::MentalMapEventListener
Interface for objects that can be notified of events related to changes on the data stored.
Definition: MentalMapEventListener.hpp:21
rd::NetworkManager::login
virtual bool login()=0
Log the user into the network.