network/room_member: Add moderation functions
To allow for passing moderation errors around without impacting the State, this commit also separates the previous State enum into two enums: State, and Error. The State enum now only contains generic states like disconnected or connected, and the Error enum describes the specific error happened. citra_qt/multiplayer/{state, message} is changed accordingly.
This commit is contained in:
parent
38f86cce94
commit
7acd2664dd
6 changed files with 251 additions and 56 deletions
|
@ -57,20 +57,30 @@ class RoomMember final {
|
|||
public:
|
||||
enum class State : u8 {
|
||||
Uninitialized, ///< Not initialized
|
||||
Idle, ///< Default state
|
||||
Error, ///< Some error [permissions to network device missing or something]
|
||||
Idle, ///< Default state (i.e. not connected)
|
||||
Joining, ///< The client is attempting to join a room.
|
||||
Joined, ///< The client is connected to the room and is ready to send/receive packets.
|
||||
};
|
||||
|
||||
enum class Error : u8 {
|
||||
// Reasons why connection was closed
|
||||
LostConnection, ///< Connection closed
|
||||
HostKicked, ///< Kicked by the host
|
||||
|
||||
// Reasons why connection was rejected
|
||||
UnknownError, ///< Some error [permissions to network device missing or something]
|
||||
NameCollision, ///< Somebody is already using this name
|
||||
MacCollision, ///< Somebody is already using that mac-address
|
||||
ConsoleIdCollision, ///< Somebody in the room has the same Console ID
|
||||
WrongVersion, ///< The room version is not the same as for this RoomMember
|
||||
WrongPassword, ///< The password doesn't match the one from the Room
|
||||
CouldNotConnect, ///< The room is not responding to a connection attempt
|
||||
RoomIsFull ///< Room is already at the maximum number of players
|
||||
RoomIsFull, ///< Room is already at the maximum number of players
|
||||
HostBanned, ///< The user is banned by the host
|
||||
|
||||
// Reasons why moderation request failed
|
||||
PermissionDenied, ///< The user does not have mod permissions
|
||||
NoSuchUser, ///< The nickname the user attempts to kick/ban does not exist
|
||||
};
|
||||
|
||||
struct MemberInformation {
|
||||
|
@ -161,6 +171,19 @@ public:
|
|||
*/
|
||||
void SendGameInfo(const GameInfo& game_info);
|
||||
|
||||
/**
|
||||
* Sends a moderation request to the room.
|
||||
* @param type Moderation request type.
|
||||
* @param nickname The subject of the request. (i.e. the user you want to kick/ban)
|
||||
*/
|
||||
void SendModerationRequest(RoomMessageTypes type, const std::string& nickname);
|
||||
|
||||
/**
|
||||
* Attempts to retrieve ban list from the room.
|
||||
* If success, the ban list callback would be called. Otherwise an error would be emitted.
|
||||
*/
|
||||
void RequestBanList();
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -170,6 +193,15 @@ public:
|
|||
*/
|
||||
CallbackHandle<State> BindOnStateChanged(std::function<void(const State&)> callback);
|
||||
|
||||
/**
|
||||
* Binds a function to an event that will be triggered every time an error happened. 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<Error> BindOnError(std::function<void(const Error&)> 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.
|
||||
|
@ -210,6 +242,16 @@ public:
|
|||
CallbackHandle<StatusMessageEntry> BindOnStatusMessageReceived(
|
||||
std::function<void(const StatusMessageEntry&)> callback);
|
||||
|
||||
/**
|
||||
* Binds a function to an event that will be triggered every time a requested ban list
|
||||
* received. The function will 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<Room::BanList> BindOnBanListReceived(
|
||||
std::function<void(const Room::BanList&)> callback);
|
||||
|
||||
/**
|
||||
* Leaves the current room.
|
||||
*/
|
||||
|
@ -224,24 +266,42 @@ static const char* GetStateStr(const RoomMember::State& s) {
|
|||
switch (s) {
|
||||
case RoomMember::State::Idle:
|
||||
return "Idle";
|
||||
case RoomMember::State::Error:
|
||||
return "Error";
|
||||
case RoomMember::State::Joining:
|
||||
return "Joining";
|
||||
case RoomMember::State::Joined:
|
||||
return "Joined";
|
||||
case RoomMember::State::LostConnection:
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
static const char* GetErrorStr(const RoomMember::Error& e) {
|
||||
switch (e) {
|
||||
case RoomMember::Error::LostConnection:
|
||||
return "LostConnection";
|
||||
case RoomMember::State::NameCollision:
|
||||
case RoomMember::Error::HostKicked:
|
||||
return "HostKicked";
|
||||
case RoomMember::Error::UnknownError:
|
||||
return "UnknownError";
|
||||
case RoomMember::Error::NameCollision:
|
||||
return "NameCollision";
|
||||
case RoomMember::State::MacCollision:
|
||||
return "MacCollision";
|
||||
case RoomMember::State::WrongVersion:
|
||||
case RoomMember::Error::MacCollision:
|
||||
return "MaxCollision";
|
||||
case RoomMember::Error::ConsoleIdCollision:
|
||||
return "ConsoleIdCollision";
|
||||
case RoomMember::Error::WrongVersion:
|
||||
return "WrongVersion";
|
||||
case RoomMember::State::WrongPassword:
|
||||
case RoomMember::Error::WrongPassword:
|
||||
return "WrongPassword";
|
||||
case RoomMember::State::CouldNotConnect:
|
||||
case RoomMember::Error::CouldNotConnect:
|
||||
return "CouldNotConnect";
|
||||
case RoomMember::Error::RoomIsFull:
|
||||
return "RoomIsFull";
|
||||
case RoomMember::Error::HostBanned:
|
||||
return "HostBanned";
|
||||
case RoomMember::Error::PermissionDenied:
|
||||
return "PermissionDenied";
|
||||
case RoomMember::Error::NoSuchUser:
|
||||
return "NoSuchUser";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue