diff options
Diffstat (limited to 'src/network/room_member.h')
-rw-r--r-- | src/network/room_member.h | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/src/network/room_member.h b/src/network/room_member.h index 177622b69..bc1af3a7e 100644 --- a/src/network/room_member.h +++ b/src/network/room_member.h @@ -4,14 +4,32 @@ #pragma once -#include <atomic> #include <memory> #include <string> +#include <vector> #include "common/common_types.h" #include "network/room.h" namespace Network { +/// Information about the received WiFi packets. +/// Acts as our own 802.11 header. +struct WifiPacket { + enum class PacketType : u8 { Beacon, Data, Authentication, AssociationResponse }; + PacketType type; ///< The type of 802.11 frame. + std::vector<u8> data; ///< Raw 802.11 frame data, starting at the management frame header + /// for management frames. + MacAddress transmitter_address; ///< Mac address of the transmitter. + MacAddress destination_address; ///< Mac address of the receiver. + u8 channel; ///< WiFi channel where this frame was transmitted. +}; + +/// Represents a chat message. +struct ChatEntry { + std::string nickname; ///< Nickname of the client who sent this message. + std::string message; ///< Body of the message. +}; + /** * This is what a client [person joining a server] would use. * It also has to be used if you host a game yourself (You'd create both, a Room and a @@ -29,9 +47,18 @@ public: // Reasons why connection was rejected NameCollision, ///< Somebody is already using this name MacCollision, ///< Somebody is already using that mac-address + WrongVersion, ///< The room version is not the same as for this RoomMember CouldNotConnect ///< The room is not responding to a connection attempt }; + 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 + /// not playing anything. + MacAddress mac_address; ///< MAC address associated with this member. + }; + using MemberList = std::vector<MemberInformation>; + RoomMember(); ~RoomMember(); @@ -41,6 +68,26 @@ public: State GetState() const; /** + * Returns information about the members in the room we're currently connected to. + */ + const MemberList& GetMemberInformation() const; + + /** + * Returns the nickname of the RoomMember. + */ + const std::string& GetNickname() const; + + /** + * Returns the MAC address of the RoomMember. + */ + const MacAddress& GetMacAddress() const; + + /** + * Returns information about the room we're currently connected to. + */ + RoomInformation GetRoomInformation() const; + + /** * Returns whether we're connected to a server or not. */ bool IsConnected() const; @@ -50,7 +97,26 @@ public: * This may fail if the username is already taken. */ void Join(const std::string& nickname, const char* server_addr = "127.0.0.1", - const u16 serverPort = DefaultRoomPort, const u16 clientPort = 0); + const u16 serverPort = DefaultRoomPort, const u16 clientPort = 0, + const MacAddress& preferred_mac = NoPreferredMac); + + /** + * Sends a WiFi packet to the room. + * @param packet The WiFi packet to send. + */ + void SendWifiPacket(const WifiPacket& packet); + + /** + * Sends a chat message to the room. + * @param message The contents of the message. + */ + void SendChatMessage(const std::string& message); + + /** + * Sends the current game name to the room. + * @param game_name The game name. + */ + void SendGameName(const std::string& game_name); /** * Leaves the current room. |