2022-07-25 16:18:30 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-07-06 01:20:39 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2022-07-15 20:11:09 +01:00
|
|
|
#include "common/announce_multiplayer_room.h"
|
2022-07-06 01:20:39 +01:00
|
|
|
#include "common/common_types.h"
|
2022-07-30 04:58:23 +01:00
|
|
|
#include "common/socket_types.h"
|
2022-07-06 01:20:39 +01:00
|
|
|
#include "network/verify_user.h"
|
|
|
|
|
|
|
|
namespace Network {
|
|
|
|
|
2022-07-15 20:11:09 +01:00
|
|
|
using AnnounceMultiplayerRoom::GameInfo;
|
|
|
|
using AnnounceMultiplayerRoom::Member;
|
|
|
|
using AnnounceMultiplayerRoom::RoomInformation;
|
|
|
|
|
2022-07-15 18:45:35 +01:00
|
|
|
constexpr u32 network_version = 1; ///< The version of this Room and RoomMember
|
2022-07-06 01:20:39 +01:00
|
|
|
|
|
|
|
constexpr u16 DefaultRoomPort = 24872;
|
|
|
|
|
|
|
|
constexpr u32 MaxMessageSize = 500;
|
|
|
|
|
|
|
|
/// Maximum number of concurrent connections allowed to this room.
|
|
|
|
static constexpr u32 MaxConcurrentConnections = 254;
|
|
|
|
|
|
|
|
constexpr std::size_t NumChannels = 1; // Number of channels used for the connection
|
|
|
|
|
2022-07-30 04:58:23 +01:00
|
|
|
/// A special IP address that tells the room we're joining to assign us a IP address
|
2022-07-06 01:20:39 +01:00
|
|
|
/// automatically.
|
2022-07-30 04:58:23 +01:00
|
|
|
constexpr IPv4Address NoPreferredIP = {0xFF, 0xFF, 0xFF, 0xFF};
|
2022-07-06 01:20:39 +01:00
|
|
|
|
|
|
|
// The different types of messages that can be sent. The first byte of each packet defines the type
|
|
|
|
enum RoomMessageTypes : u8 {
|
|
|
|
IdJoinRequest = 1,
|
|
|
|
IdJoinSuccess,
|
|
|
|
IdRoomInformation,
|
|
|
|
IdSetGameInfo,
|
2022-07-30 04:58:23 +01:00
|
|
|
IdProxyPacket,
|
2022-07-31 03:46:26 +01:00
|
|
|
IdLdnPacket,
|
2022-07-06 01:20:39 +01:00
|
|
|
IdChatMessage,
|
|
|
|
IdNameCollision,
|
2022-07-30 04:58:23 +01:00
|
|
|
IdIpCollision,
|
2022-07-06 01:20:39 +01:00
|
|
|
IdVersionMismatch,
|
|
|
|
IdWrongPassword,
|
|
|
|
IdCloseRoom,
|
|
|
|
IdRoomIsFull,
|
|
|
|
IdStatusMessage,
|
|
|
|
IdHostKicked,
|
|
|
|
IdHostBanned,
|
|
|
|
/// Moderation requests
|
|
|
|
IdModKick,
|
|
|
|
IdModBan,
|
|
|
|
IdModUnban,
|
|
|
|
IdModGetBanList,
|
|
|
|
// Moderation responses
|
|
|
|
IdModBanListResponse,
|
|
|
|
IdModPermissionDenied,
|
|
|
|
IdModNoSuchUser,
|
|
|
|
IdJoinSuccessAsMod,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Types of system status messages
|
|
|
|
enum StatusMessageTypes : u8 {
|
|
|
|
IdMemberJoin = 1, ///< Member joining
|
|
|
|
IdMemberLeave, ///< Member leaving
|
|
|
|
IdMemberKicked, ///< A member is kicked from the room
|
|
|
|
IdMemberBanned, ///< A member is banned from the room
|
|
|
|
IdAddressUnbanned, ///< A username / ip address is unbanned from the room
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This is what a server [person creating a server] would use.
|
|
|
|
class Room final {
|
|
|
|
public:
|
|
|
|
enum class State : u8 {
|
|
|
|
Open, ///< The room is open and ready to accept connections.
|
|
|
|
Closed, ///< The room is not opened and can not accept connections.
|
|
|
|
};
|
|
|
|
|
|
|
|
Room();
|
|
|
|
~Room();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current state of the room.
|
|
|
|
*/
|
|
|
|
State GetState() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the room information of the room.
|
|
|
|
*/
|
|
|
|
const RoomInformation& GetRoomInformation() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the verify UID of this room.
|
|
|
|
*/
|
|
|
|
std::string GetVerifyUID() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a list of the mbmers connected to the room.
|
|
|
|
*/
|
|
|
|
std::vector<Member> GetRoomMemberList() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the room is password protected
|
|
|
|
*/
|
|
|
|
bool HasPassword() const;
|
|
|
|
|
|
|
|
using UsernameBanList = std::vector<std::string>;
|
|
|
|
using IPBanList = std::vector<std::string>;
|
|
|
|
|
|
|
|
using BanList = std::pair<UsernameBanList, IPBanList>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the socket for this room. Will bind to default address if
|
|
|
|
* server is empty string.
|
|
|
|
*/
|
|
|
|
bool Create(const std::string& name, const std::string& description = "",
|
|
|
|
const std::string& server = "", u16 server_port = DefaultRoomPort,
|
|
|
|
const std::string& password = "",
|
|
|
|
const u32 max_connections = MaxConcurrentConnections,
|
2022-07-18 04:53:44 +01:00
|
|
|
const std::string& host_username = "", const GameInfo = {},
|
2022-07-06 01:20:39 +01:00
|
|
|
std::unique_ptr<VerifyUser::Backend> verify_backend = nullptr,
|
2021-12-25 19:27:52 +00:00
|
|
|
const BanList& ban_list = {}, bool enable_yuzu_mods = false);
|
2022-07-06 01:20:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the verification GUID of the room.
|
|
|
|
*/
|
|
|
|
void SetVerifyUID(const std::string& uid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the ban list (including banned forum usernames and IPs) of the room.
|
|
|
|
*/
|
|
|
|
BanList GetBanList() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the socket
|
|
|
|
*/
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
private:
|
|
|
|
class RoomImpl;
|
|
|
|
std::unique_ptr<RoomImpl> room_impl;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Network
|