2017-07-07 19:34:15 +00:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-07-08 14:47:24 +00:00
|
|
|
#include <array>
|
2017-07-07 19:34:15 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2017-08-19 17:14:33 +00:00
|
|
|
#include <vector>
|
2017-07-07 19:34:15 +00:00
|
|
|
#include "common/common_types.h"
|
2018-10-27 07:35:01 +00:00
|
|
|
#include "network/verify_user.h"
|
2017-07-07 19:34:15 +00:00
|
|
|
|
|
|
|
namespace Network {
|
|
|
|
|
2018-10-01 01:53:20 +00:00
|
|
|
constexpr u32 network_version = 4; ///< The version of this Room and RoomMember
|
2017-07-14 07:20:39 +00:00
|
|
|
|
2017-11-19 18:52:37 +00:00
|
|
|
constexpr u16 DefaultRoomPort = 24872;
|
|
|
|
|
|
|
|
constexpr u32 MaxMessageSize = 500;
|
|
|
|
|
|
|
|
/// Maximum number of concurrent connections allowed to this room.
|
|
|
|
static constexpr u32 MaxConcurrentConnections = 254;
|
|
|
|
|
2018-09-06 20:03:28 +00:00
|
|
|
constexpr std::size_t NumChannels = 1; // Number of channels used for the connection
|
2017-07-07 19:34:15 +00:00
|
|
|
|
|
|
|
struct RoomInformation {
|
2017-11-19 18:52:37 +00:00
|
|
|
std::string name; ///< Name of the server
|
2018-04-30 07:40:51 +00:00
|
|
|
std::string description; ///< Server description
|
2017-11-19 18:52:37 +00:00
|
|
|
u32 member_slots; ///< Maximum number of members in this room
|
|
|
|
u16 port; ///< The port of this room
|
|
|
|
std::string preferred_game; ///< Game to advertise that you want to play
|
|
|
|
u64 preferred_game_id; ///< Title ID for the advertised game
|
2018-11-24 08:08:32 +00:00
|
|
|
std::string host_username; ///< Forum username of the host
|
2017-07-07 19:34:15 +00:00
|
|
|
};
|
|
|
|
|
2017-08-19 17:14:33 +00:00
|
|
|
struct GameInfo {
|
|
|
|
std::string name{""};
|
|
|
|
u64 id{0};
|
|
|
|
};
|
|
|
|
|
2017-07-09 13:06:02 +00:00
|
|
|
using MacAddress = std::array<u8, 6>;
|
2017-07-08 14:47:24 +00:00
|
|
|
/// A special MAC address that tells the room we're joining to assign us a MAC address
|
|
|
|
/// automatically.
|
2017-07-26 19:06:40 +00:00
|
|
|
constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
2017-07-08 14:47:24 +00:00
|
|
|
|
2017-07-09 13:06:02 +00:00
|
|
|
// 802.11 broadcast MAC address
|
|
|
|
constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
|
|
|
2017-07-08 13:24:47 +00:00
|
|
|
// The different types of messages that can be sent. The first byte of each packet defines the type
|
2017-07-15 19:24:11 +00:00
|
|
|
enum RoomMessageTypes : u8 {
|
2017-07-08 13:24:47 +00:00
|
|
|
IdJoinRequest = 1,
|
|
|
|
IdJoinSuccess,
|
|
|
|
IdRoomInformation,
|
2017-08-19 17:14:33 +00:00
|
|
|
IdSetGameInfo,
|
2017-07-08 13:24:47 +00:00
|
|
|
IdWifiPacket,
|
|
|
|
IdChatMessage,
|
|
|
|
IdNameCollision,
|
2017-07-14 07:20:39 +00:00
|
|
|
IdMacCollision,
|
|
|
|
IdVersionMismatch,
|
2017-11-19 18:52:37 +00:00
|
|
|
IdWrongPassword,
|
2018-04-20 07:34:37 +00:00
|
|
|
IdCloseRoom,
|
|
|
|
IdRoomIsFull,
|
2018-10-31 15:07:03 +00:00
|
|
|
IdConsoleIdCollision,
|
2018-11-09 13:55:57 +00:00
|
|
|
IdStatusMessage,
|
2018-11-24 08:08:32 +00:00
|
|
|
IdHostKicked,
|
|
|
|
IdHostBanned,
|
|
|
|
/// Moderation requests
|
|
|
|
IdModKick,
|
|
|
|
IdModBan,
|
|
|
|
IdModUnban,
|
|
|
|
IdModGetBanList,
|
|
|
|
// Moderation responses
|
|
|
|
IdModBanListResponse,
|
|
|
|
IdModPermissionDenied,
|
|
|
|
IdModNoSuchUser,
|
2018-11-09 13:55:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Types of system status messages
|
|
|
|
enum StatusMessageTypes : u8 {
|
2018-11-24 08:08:32 +00:00
|
|
|
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
|
2017-07-08 13:24:47 +00:00
|
|
|
};
|
|
|
|
|
2017-07-07 19:34:15 +00:00
|
|
|
/// 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.
|
|
|
|
};
|
|
|
|
|
2017-08-19 17:14:33 +00:00
|
|
|
struct Member {
|
2018-10-27 07:35:01 +00:00
|
|
|
std::string nickname; ///< The nickname of the member.
|
|
|
|
std::string username; ///< The web services username of the member. Can be empty.
|
|
|
|
std::string display_name; ///< The web services display name of the member. Can be empty.
|
|
|
|
std::string avatar_url; ///< Url to the member's avatar. Can be empty.
|
|
|
|
GameInfo game_info; ///< The current game of the member
|
|
|
|
MacAddress mac_address; ///< The assigned mac address of the member.
|
2017-08-19 17:14:33 +00:00
|
|
|
};
|
|
|
|
|
2017-07-07 19:34:15 +00:00
|
|
|
Room();
|
|
|
|
~Room();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current state of the room.
|
|
|
|
*/
|
|
|
|
State GetState() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the room information of the room.
|
|
|
|
*/
|
|
|
|
const RoomInformation& GetRoomInformation() const;
|
|
|
|
|
2018-10-27 07:35:01 +00:00
|
|
|
/**
|
|
|
|
* Gets the verify UID of this room.
|
|
|
|
*/
|
|
|
|
std::string GetVerifyUID() const;
|
|
|
|
|
2017-08-19 17:14:33 +00:00
|
|
|
/**
|
|
|
|
* Gets a list of the mbmers connected to the room.
|
|
|
|
*/
|
|
|
|
std::vector<Member> GetRoomMemberList() const;
|
|
|
|
|
2017-11-19 18:52:37 +00:00
|
|
|
/**
|
|
|
|
* Checks if the room is password protected
|
|
|
|
*/
|
|
|
|
bool HasPassword() const;
|
|
|
|
|
2018-11-24 08:08:32 +00:00
|
|
|
using UsernameBanList = std::vector<std::string>;
|
|
|
|
using IPBanList = std::vector<std::string>;
|
|
|
|
|
|
|
|
using BanList = std::pair<UsernameBanList, IPBanList>;
|
|
|
|
|
2017-07-07 19:34:15 +00:00
|
|
|
/**
|
|
|
|
* Creates the socket for this room. Will bind to default address if
|
|
|
|
* server is empty string.
|
|
|
|
*/
|
2018-04-30 07:40:51 +00:00
|
|
|
bool Create(const std::string& name, const std::string& description = "",
|
|
|
|
const std::string& server = "", u16 server_port = DefaultRoomPort,
|
|
|
|
const std::string& password = "",
|
2017-11-19 18:52:37 +00:00
|
|
|
const u32 max_connections = MaxConcurrentConnections,
|
2018-11-24 08:08:32 +00:00
|
|
|
const std::string& host_username = "", const std::string& preferred_game = "",
|
|
|
|
u64 preferred_game_id = 0,
|
|
|
|
std::unique_ptr<VerifyUser::Backend> verify_backend = nullptr,
|
|
|
|
const BanList& ban_list = {});
|
2018-10-27 07:35:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the verification GUID of the room.
|
|
|
|
*/
|
|
|
|
void SetVerifyUID(const std::string& uid);
|
2017-07-07 19:34:15 +00:00
|
|
|
|
2018-11-24 08:08:32 +00:00
|
|
|
/**
|
|
|
|
* Gets the ban list (including banned forum usernames and IPs) of the room.
|
|
|
|
*/
|
|
|
|
BanList GetBanList() const;
|
|
|
|
|
2017-07-07 19:34:15 +00:00
|
|
|
/**
|
|
|
|
* Destroys the socket
|
|
|
|
*/
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
private:
|
|
|
|
class RoomImpl;
|
|
|
|
std::unique_ptr<RoomImpl> room_impl;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Network
|