network, citra_qt: Give moderation permission to community mods
Based on the `roles` payload in the JWT, the rooms will now give mod permission to Citra Community Moderators. To notify the client of its permissions, a new response, IdJoinSuccessAsMod is added, and there's now a new RoomMember::State called Moderator.
This commit is contained in:
parent
94be4050bc
commit
9d062d63da
15 changed files with 73 additions and 27 deletions
|
@ -155,6 +155,12 @@ public:
|
|||
*/
|
||||
void SendJoinSuccess(ENetPeer* client, MacAddress mac_address);
|
||||
|
||||
/**
|
||||
* Notifies the member that its connection attempt was successful,
|
||||
* and it is now part of the room, and it has been granted mod permissions.
|
||||
*/
|
||||
void SendJoinSuccessAsMod(ENetPeer* client, MacAddress mac_address);
|
||||
|
||||
/**
|
||||
* Sends a IdHostKicked message telling the client that they have been kicked.
|
||||
*/
|
||||
|
@ -401,7 +407,11 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
|
|||
|
||||
// Notify everyone that the room information has changed.
|
||||
BroadcastRoomInformation();
|
||||
SendJoinSuccess(event->peer, preferred_mac);
|
||||
if (HasModPermission(event->peer)) {
|
||||
SendJoinSuccessAsMod(event->peer, preferred_mac);
|
||||
} else {
|
||||
SendJoinSuccess(event->peer, preferred_mac);
|
||||
}
|
||||
}
|
||||
|
||||
void Room::RoomImpl::HandleModKickPacket(const ENetEvent* event) {
|
||||
|
@ -588,10 +598,11 @@ bool Room::RoomImpl::HasModPermission(const ENetPeer* client) const {
|
|||
if (sending_member == members.end()) {
|
||||
return false;
|
||||
}
|
||||
if (sending_member->user_data.username != room_information.host_username) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (sending_member->user_data.moderator) // Community moderator
|
||||
return true;
|
||||
if (sending_member->user_data.username == room_information.host_username) // Room host
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Room::RoomImpl::SendNameCollision(ENetPeer* client) {
|
||||
|
@ -665,6 +676,16 @@ void Room::RoomImpl::SendJoinSuccess(ENetPeer* client, MacAddress mac_address) {
|
|||
enet_host_flush(server);
|
||||
}
|
||||
|
||||
void Room::RoomImpl::SendJoinSuccessAsMod(ENetPeer* client, MacAddress mac_address) {
|
||||
Packet packet;
|
||||
packet << static_cast<u8>(IdJoinSuccessAsMod);
|
||||
packet << mac_address;
|
||||
ENetPacket* enet_packet =
|
||||
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(client, 0, enet_packet);
|
||||
enet_host_flush(server);
|
||||
}
|
||||
|
||||
void Room::RoomImpl::SendUserKicked(ENetPeer* client) {
|
||||
Packet packet;
|
||||
packet << static_cast<u8>(IdHostKicked);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue