NetworkManager class
The NetworkManager
class defines the interface required for managing the network system in Robot Devastation. Other classes can then define the implementation of the NetworkManager according to, for instance, the library selected for connecting to the network / server.
Note that configuration of the player data has to be performed before the NetworkManager
is started.
The main methods of a NetworkManager
are:
start()
,stop()
andisStopped()
: control the manager startup and halting.addNetworkEventListener()
: registers aNetworkEventListener
that will be notified when network events are generated by the server.removeNetworkEventListeners()
: unsuscribes all the registered listeners, and they will not be notified until they are registered again.configure()
: configure some network parameters (e.g. the player to be logged in).login()
: login in the game server.logout()
: logout from the game server.keepAlive()
: tells the server that you are still alive. If this signal is not sent every 60 seconds the server automatically logs out the player.sendPlayerhit()
: notify the server that an enemy has been hit.
A NetworkManager
should also implement the required methods of the MentalMapEventListener
interface:
onTargetHit()
: notifies the game server that a player has been hit withsendPlayerhit()
.onRespawn()
: restores the player health after respawn.
YarpNetworkManager class
YarpNetworkManager
is an implementation of the NetworkManager
interface using YARP as communications middleware. It uses a yarp::os::TypedReaderCallback<yarp::os::Bottle>
to receive data from the server and then notifies listeners that new data has arrived. It also owns a yarp::os::RpcClient
to send data for login, logout and to notify the server that a robot has been hit.
A yarp::os::RateThread
is used to send periodically a keepAlive()
signal to the game server to avoid being logged out.
MockNetworkManager class
MockNetworkManager
is an implementation of the NetworkManager
for unit testing purposes.
It allows to emulate connections with The Server without the actual server being executed. It also allows reading / writing data to the emulated game server to check , for instance, if the player is logged in or to set the game players.
isLoggedIn()
: checks if player is currently logged in the server.isStopped()
: checks if the manager is stopped.setPlayerData()
: sets the player data in the emulated server.getPlayerData()
: retrieves the player data from the emulated server.sendPlayerData()
: makes theMockNetworkManager
receive player data from the emulated server, generating aNetworkEvent
that is notified to all registered listeners.setLoggedIn()
: set the logged in status of theMockNetworkManager
.