diff options
Diffstat (limited to '')
| -rw-r--r-- | src/network/room_member.h | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/src/network/room_member.h b/src/network/room_member.h deleted file mode 100644 index 98770a234..000000000 --- a/src/network/room_member.h +++ /dev/null | |||
| @@ -1,182 +0,0 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <functional> | ||
| 8 | #include <memory> | ||
| 9 | #include <string> | ||
| 10 | #include <vector> | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "network/room.h" | ||
| 13 | |||
| 14 | namespace Network { | ||
| 15 | |||
| 16 | /// Information about the received WiFi packets. | ||
| 17 | /// Acts as our own 802.11 header. | ||
| 18 | struct WifiPacket { | ||
| 19 | enum class PacketType : u8 { Beacon, Data, Authentication, AssociationResponse }; | ||
| 20 | PacketType type; ///< The type of 802.11 frame. | ||
| 21 | std::vector<u8> data; ///< Raw 802.11 frame data, starting at the management frame header | ||
| 22 | /// for management frames. | ||
| 23 | MacAddress transmitter_address; ///< Mac address of the transmitter. | ||
| 24 | MacAddress destination_address; ///< Mac address of the receiver. | ||
| 25 | u8 channel; ///< WiFi channel where this frame was transmitted. | ||
| 26 | }; | ||
| 27 | |||
| 28 | /// Represents a chat message. | ||
| 29 | struct ChatEntry { | ||
| 30 | std::string nickname; ///< Nickname of the client who sent this message. | ||
| 31 | std::string message; ///< Body of the message. | ||
| 32 | }; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * This is what a client [person joining a server] would use. | ||
| 36 | * It also has to be used if you host a game yourself (You'd create both, a Room and a | ||
| 37 | * RoomMembership for yourself) | ||
| 38 | */ | ||
| 39 | class RoomMember final { | ||
| 40 | public: | ||
| 41 | enum class State : u8 { | ||
| 42 | Idle, ///< Default state | ||
| 43 | Error, ///< Some error [permissions to network device missing or something] | ||
| 44 | Joining, ///< The client is attempting to join a room. | ||
| 45 | Joined, ///< The client is connected to the room and is ready to send/receive packets. | ||
| 46 | LostConnection, ///< Connection closed | ||
| 47 | |||
| 48 | // Reasons why connection was rejected | ||
| 49 | NameCollision, ///< Somebody is already using this name | ||
| 50 | MacCollision, ///< Somebody is already using that mac-address | ||
| 51 | WrongVersion, ///< The room version is not the same as for this RoomMember | ||
| 52 | CouldNotConnect ///< The room is not responding to a connection attempt | ||
| 53 | }; | ||
| 54 | |||
| 55 | struct MemberInformation { | ||
| 56 | std::string nickname; ///< Nickname of the member. | ||
| 57 | GameInfo game_info; ///< Name of the game they're currently playing, or empty if they're | ||
| 58 | /// not playing anything. | ||
| 59 | MacAddress mac_address; ///< MAC address associated with this member. | ||
| 60 | }; | ||
| 61 | using MemberList = std::vector<MemberInformation>; | ||
| 62 | |||
| 63 | // The handle for the callback functions | ||
| 64 | template <typename T> | ||
| 65 | using CallbackHandle = std::shared_ptr<std::function<void(const T&)>>; | ||
| 66 | |||
| 67 | /** | ||
| 68 | * Unbinds a callback function from the events. | ||
| 69 | * @param handle The connection handle to disconnect | ||
| 70 | */ | ||
| 71 | template <typename T> | ||
| 72 | void Unbind(CallbackHandle<T> handle); | ||
| 73 | |||
| 74 | RoomMember(); | ||
| 75 | ~RoomMember(); | ||
| 76 | |||
| 77 | /** | ||
| 78 | * Returns the status of our connection to the room. | ||
| 79 | */ | ||
| 80 | State GetState() const; | ||
| 81 | |||
| 82 | /** | ||
| 83 | * Returns information about the members in the room we're currently connected to. | ||
| 84 | */ | ||
| 85 | const MemberList& GetMemberInformation() const; | ||
| 86 | |||
| 87 | /** | ||
| 88 | * Returns the nickname of the RoomMember. | ||
| 89 | */ | ||
| 90 | const std::string& GetNickname() const; | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Returns the MAC address of the RoomMember. | ||
| 94 | */ | ||
| 95 | const MacAddress& GetMacAddress() const; | ||
| 96 | |||
| 97 | /** | ||
| 98 | * Returns information about the room we're currently connected to. | ||
| 99 | */ | ||
| 100 | RoomInformation GetRoomInformation() const; | ||
| 101 | |||
| 102 | /** | ||
| 103 | * Returns whether we're connected to a server or not. | ||
| 104 | */ | ||
| 105 | bool IsConnected() const; | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Attempts to join a room at the specified address and port, using the specified nickname. | ||
| 109 | * This may fail if the username is already taken. | ||
| 110 | */ | ||
| 111 | void Join(const std::string& nickname, const char* server_addr = "127.0.0.1", | ||
| 112 | const u16 serverPort = DefaultRoomPort, const u16 clientPort = 0, | ||
| 113 | const MacAddress& preferred_mac = NoPreferredMac); | ||
| 114 | |||
| 115 | /** | ||
| 116 | * Sends a WiFi packet to the room. | ||
| 117 | * @param packet The WiFi packet to send. | ||
| 118 | */ | ||
| 119 | void SendWifiPacket(const WifiPacket& packet); | ||
| 120 | |||
| 121 | /** | ||
| 122 | * Sends a chat message to the room. | ||
| 123 | * @param message The contents of the message. | ||
| 124 | */ | ||
| 125 | void SendChatMessage(const std::string& message); | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Sends the current game info to the room. | ||
| 129 | * @param game_info The game information. | ||
| 130 | */ | ||
| 131 | void SendGameInfo(const GameInfo& game_info); | ||
| 132 | |||
| 133 | /** | ||
| 134 | * Binds a function to an event that will be triggered every time the State of the member | ||
| 135 | * changed. The function wil be called every time the event is triggered. The callback function | ||
| 136 | * must not bind or unbind a function. Doing so will cause a deadlock | ||
| 137 | * @param callback The function to call | ||
| 138 | * @return A handle used for removing the function from the registered list | ||
| 139 | */ | ||
| 140 | CallbackHandle<State> BindOnStateChanged(std::function<void(const State&)> callback); | ||
| 141 | |||
| 142 | /** | ||
| 143 | * Binds a function to an event that will be triggered every time a WifiPacket is received. | ||
| 144 | * The function wil be called everytime the event is triggered. | ||
| 145 | * The callback function must not bind or unbind a function. Doing so will cause a deadlock | ||
| 146 | * @param callback The function to call | ||
| 147 | * @return A handle used for removing the function from the registered list | ||
| 148 | */ | ||
| 149 | CallbackHandle<WifiPacket> BindOnWifiPacketReceived( | ||
| 150 | std::function<void(const WifiPacket&)> callback); | ||
| 151 | |||
| 152 | /** | ||
| 153 | * Binds a function to an event that will be triggered every time the RoomInformation changes. | ||
| 154 | * The function wil be called every time the event is triggered. | ||
| 155 | * The callback function must not bind or unbind a function. Doing so will cause a deadlock | ||
| 156 | * @param callback The function to call | ||
| 157 | * @return A handle used for removing the function from the registered list | ||
| 158 | */ | ||
| 159 | CallbackHandle<RoomInformation> BindOnRoomInformationChanged( | ||
| 160 | std::function<void(const RoomInformation&)> callback); | ||
| 161 | |||
| 162 | /** | ||
| 163 | * Binds a function to an event that will be triggered every time a ChatMessage is received. | ||
| 164 | * The function wil be called every time the event is triggered. | ||
| 165 | * The callback function must not bind or unbind a function. Doing so will cause a deadlock | ||
| 166 | * @param callback The function to call | ||
| 167 | * @return A handle used for removing the function from the registered list | ||
| 168 | */ | ||
| 169 | CallbackHandle<ChatEntry> BindOnChatMessageRecieved( | ||
| 170 | std::function<void(const ChatEntry&)> callback); | ||
| 171 | |||
| 172 | /** | ||
| 173 | * Leaves the current room. | ||
| 174 | */ | ||
| 175 | void Leave(); | ||
| 176 | |||
| 177 | private: | ||
| 178 | class RoomMemberImpl; | ||
| 179 | std::unique_ptr<RoomMemberImpl> room_member_impl; | ||
| 180 | }; | ||
| 181 | |||
| 182 | } // namespace Network | ||