126 lines
4.8 KiB
Diff
126 lines
4.8 KiB
Diff
# UNDF: UNDF-2026-000001121
|
|
# UNDF: UNDF-2026-XXXXXXXXX
|
|
--- a/src/network/room.cpp
|
|
+++ b/src/network/room.cpp
|
|
@@ -1,8 +1,8 @@
|
|
// Copyright Citra Emulator Project / Azahar Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
-#include <algorithm>
|
|
#include <atomic>
|
|
#include <mutex>
|
|
#include <random>
|
|
#include <regex>
|
|
#include <sstream>
|
|
#include <thread>
|
|
+#include <unordered_set>
|
|
#include "common/logging/log.h"
|
|
#include "enet/enet.h"
|
|
#include "network/packet.h"
|
|
@@ -48,8 +48,8 @@ class Room::RoomImpl {
|
|
public:
|
|
// ...
|
|
- UsernameBanList username_ban_list; ///< List of banned usernames
|
|
- IPBanList ip_ban_list; ///< List of banned IP addresses
|
|
+ std::unordered_set<std::string> username_ban_list; ///< Set of banned usernames (O(1) lookup)
|
|
+ std::unordered_set<std::string> ip_ban_list; ///< Set of banned IP addresses (O(1) lookup)
|
|
mutable std::mutex ban_list_mutex; ///< Mutex for the ban lists
|
|
|
|
@@ -383,14 +383,10 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) {
|
|
{
|
|
std::lock_guard lock(ban_list_mutex);
|
|
|
|
// Check username ban
|
|
if (!member.user_data.username.empty() &&
|
|
- std::find(username_ban_list.begin(), username_ban_list.end(),
|
|
- member.user_data.username) != username_ban_list.end()) {
|
|
+ username_ban_list.count(member.user_data.username) != 0) {
|
|
SendUserBanned(event->peer);
|
|
return;
|
|
}
|
|
|
|
// Check IP ban
|
|
char ip_raw[256];
|
|
enet_address_get_host_ip(&event->peer->address, ip_raw, sizeof(ip_raw) - 1);
|
|
ip = ip_raw;
|
|
|
|
- if (std::find(ip_ban_list.begin(), ip_ban_list.end(), ip) != ip_ban_list.end()) {
|
|
+ if (ip_ban_list.count(ip) != 0) {
|
|
SendUserBanned(event->peer);
|
|
return;
|
|
}
|
|
}
|
|
|
|
@@ -503,15 +499,10 @@ void Room::RoomImpl::HandleModBanPacket(const ENetEvent* event) {
|
|
if (!username.empty()) {
|
|
// Ban the forum username
|
|
- if (std::find(username_ban_list.begin(), username_ban_list.end(), username) ==
|
|
- username_ban_list.end()) {
|
|
- username_ban_list.emplace_back(username);
|
|
- }
|
|
+ username_ban_list.insert(username);
|
|
}
|
|
|
|
// Ban the member's IP as well
|
|
- if (std::find(ip_ban_list.begin(), ip_ban_list.end(), ip) == ip_ban_list.end()) {
|
|
- ip_ban_list.emplace_back(ip);
|
|
- }
|
|
+ ip_ban_list.insert(ip);
|
|
}
|
|
|
|
@@ -535,14 +526,10 @@ void Room::RoomImpl::HandleModUnbanPacket(const ENetEvent* event) {
|
|
bool unbanned = false;
|
|
{
|
|
std::lock_guard lock(ban_list_mutex);
|
|
|
|
- auto it = std::find(username_ban_list.begin(), username_ban_list.end(), address);
|
|
- if (it != username_ban_list.end()) {
|
|
+ if (username_ban_list.erase(address) > 0) {
|
|
unbanned = true;
|
|
- username_ban_list.erase(it);
|
|
}
|
|
|
|
- it = std::find(ip_ban_list.begin(), ip_ban_list.end(), address);
|
|
- if (it != ip_ban_list.end()) {
|
|
+ if (ip_ban_list.erase(address) > 0) {
|
|
unbanned = true;
|
|
- ip_ban_list.erase(it);
|
|
}
|
|
}
|
|
|
|
@@ -739,8 +726,10 @@ void Room::RoomImpl::SendModBanListResponse(ENetPeer* client) {
|
|
Packet packet;
|
|
packet << static_cast<u8>(IdModBanListResponse);
|
|
{
|
|
std::lock_guard lock(ban_list_mutex);
|
|
- packet << username_ban_list;
|
|
- packet << ip_ban_list;
|
|
+ std::vector<std::string> unames(username_ban_list.begin(), username_ban_list.end());
|
|
+ std::vector<std::string> ips(ip_ban_list.begin(), ip_ban_list.end());
|
|
+ packet << unames;
|
|
+ packet << ips;
|
|
}
|
|
ENetPacket* enet_packet =
|
|
enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE);
|
|
|
|
@@ -1043,8 +1032,10 @@ bool Room::Create(const std::string& name, const std::string& description,
|
|
room_impl->password = password;
|
|
room_impl->verify_backend = std::move(verify_backend);
|
|
- room_impl->username_ban_list = ban_list.first;
|
|
- room_impl->ip_ban_list = ban_list.second;
|
|
+ room_impl->username_ban_list =
|
|
+ std::unordered_set<std::string>(ban_list.first.begin(), ban_list.first.end());
|
|
+ room_impl->ip_ban_list =
|
|
+ std::unordered_set<std::string>(ban_list.second.begin(), ban_list.second.end());
|
|
room_impl->StartLoop();
|
|
return true;
|
|
|
|
@@ -1065,7 +1056,9 @@ Room::BanList Room::GetBanList() const {
|
|
std::lock_guard lock(room_impl->ban_list_mutex);
|
|
- return {room_impl->username_ban_list, room_impl->ip_ban_list};
|
|
+ return {
|
|
+ UsernameBanList(room_impl->username_ban_list.begin(), room_impl->username_ban_list.end()),
|
|
+ IPBanList(room_impl->ip_ban_list.begin(), room_impl->ip_ban_list.end()),
|
|
+ };
|
|
}
|