Added missing parts in libnetwork (#2838)
* Network: Set and send the game information over enet Added Callbacks for RoomMember and GetMemberList to Room in preparation for web_services.
This commit is contained in:
parent
21204ba488
commit
5d0a1e7efd
9 changed files with 310 additions and 37 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -53,12 +54,23 @@ public:
|
|||
|
||||
struct MemberInformation {
|
||||
std::string nickname; ///< Nickname of the member.
|
||||
std::string game_name; ///< Name of the game they're currently playing, or empty if they're
|
||||
GameInfo game_info; ///< Name of the game they're currently playing, or empty if they're
|
||||
/// not playing anything.
|
||||
MacAddress mac_address; ///< MAC address associated with this member.
|
||||
};
|
||||
using MemberList = std::vector<MemberInformation>;
|
||||
|
||||
// The handle for the callback functions
|
||||
template <typename T>
|
||||
using CallbackHandle = std::shared_ptr<std::function<void(const T&)>>;
|
||||
|
||||
/**
|
||||
* Unbinds a callback function from the events.
|
||||
* @param handle The connection handle to disconnect
|
||||
*/
|
||||
template <typename T>
|
||||
void Unbind(CallbackHandle<T> handle);
|
||||
|
||||
RoomMember();
|
||||
~RoomMember();
|
||||
|
||||
|
@ -113,10 +125,49 @@ public:
|
|||
void SendChatMessage(const std::string& message);
|
||||
|
||||
/**
|
||||
* Sends the current game name to the room.
|
||||
* @param game_name The game name.
|
||||
* Sends the current game info to the room.
|
||||
* @param game_info The game information.
|
||||
*/
|
||||
void SendGameName(const std::string& game_name);
|
||||
void SendGameInfo(const GameInfo& game_info);
|
||||
|
||||
/**
|
||||
* Binds a function to an event that will be triggered every time the State of the member
|
||||
* changed. The function wil be called every time the event is triggered. The callback function
|
||||
* must not bind or unbind a function. Doing so will cause a deadlock
|
||||
* @param callback The function to call
|
||||
* @return A handle used for removing the function from the registered list
|
||||
*/
|
||||
CallbackHandle<State> BindOnStateChanged(std::function<void(const State&)> callback);
|
||||
|
||||
/**
|
||||
* Binds a function to an event that will be triggered every time a WifiPacket is received.
|
||||
* The function wil be called everytime the event is triggered.
|
||||
* The callback function must not bind or unbind a function. Doing so will cause a deadlock
|
||||
* @param callback The function to call
|
||||
* @return A handle used for removing the function from the registered list
|
||||
*/
|
||||
CallbackHandle<WifiPacket> BindOnWifiPacketReceived(
|
||||
std::function<void(const WifiPacket&)> callback);
|
||||
|
||||
/**
|
||||
* Binds a function to an event that will be triggered every time the RoomInformation changes.
|
||||
* The function wil be called every time the event is triggered.
|
||||
* The callback function must not bind or unbind a function. Doing so will cause a deadlock
|
||||
* @param callback The function to call
|
||||
* @return A handle used for removing the function from the registered list
|
||||
*/
|
||||
CallbackHandle<RoomInformation> BindOnRoomInformationChanged(
|
||||
std::function<void(const RoomInformation&)> callback);
|
||||
|
||||
/**
|
||||
* Binds a function to an event that will be triggered every time a ChatMessage is received.
|
||||
* The function wil be called every time the event is triggered.
|
||||
* The callback function must not bind or unbind a function. Doing so will cause a deadlock
|
||||
* @param callback The function to call
|
||||
* @return A handle used for removing the function from the registered list
|
||||
*/
|
||||
CallbackHandle<ChatEntry> BindOnChatMessageRecieved(
|
||||
std::function<void(const ChatEntry&)> callback);
|
||||
|
||||
/**
|
||||
* Leaves the current room.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue