2017-07-08 01:04:15 +05:30
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-07-08 20:17:24 +05:30
|
|
|
#include <array>
|
2017-07-08 01:04:15 +05:30
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2017-08-19 22:44:33 +05:30
|
|
|
#include <vector>
|
2017-07-08 01:04:15 +05:30
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Network {
|
|
|
|
|
2018-10-01 07:23:20 +05:30
|
|
|
constexpr u32 network_version = 4; ///< The version of this Room and RoomMember
|
2017-07-14 12:50:39 +05:30
|
|
|
|
2017-11-20 00:22:37 +05:30
|
|
|
constexpr u16 DefaultRoomPort = 24872;
|
|
|
|
|
|
|
|
constexpr u32 MaxMessageSize = 500;
|
|
|
|
|
|
|
|
/// Maximum number of concurrent connections allowed to this room.
|
|
|
|
static constexpr u32 MaxConcurrentConnections = 254;
|
|
|
|
|
2018-09-07 01:33:28 +05:30
|
|
|
constexpr std::size_t NumChannels = 1; // Number of channels used for the connection
|
2017-07-08 01:04:15 +05:30
|
|
|
|
|
|
|
struct RoomInformation {
|
2017-11-20 00:22:37 +05:30
|
|
|
std::string name; ///< Name of the server
|
|
|
|
u32 member_slots; ///< Maximum number of members in this room
|
|
|
|
std::string uid; ///< The unique ID of the 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
|
2017-07-08 01:04:15 +05:30
|
|
|
};
|
|
|
|
|
2017-08-19 22:44:33 +05:30
|
|
|
struct GameInfo {
|
|
|
|
std::string name{""};
|
|
|
|
u64 id{0};
|
|
|
|
};
|
|
|
|
|
2017-07-09 18:36:02 +05:30
|
|
|
using MacAddress = std::array<u8, 6>;
|
2017-07-08 20:17:24 +05:30
|
|
|
/// A special MAC address that tells the room we're joining to assign us a MAC address
|
|
|
|
/// automatically.
|
2017-07-27 00:36:40 +05:30
|
|
|
constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
2017-07-08 20:17:24 +05:30
|
|
|
|
2017-07-09 18:36:02 +05:30
|
|
|
// 802.11 broadcast MAC address
|
|
|
|
constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
|
|
|
2017-07-08 18:54:47 +05:30
|
|
|
// The different types of messages that can be sent. The first byte of each packet defines the type
|
2017-07-16 00:54:11 +05:30
|
|
|
enum RoomMessageTypes : u8 {
|
2017-07-08 18:54:47 +05:30
|
|
|
IdJoinRequest = 1,
|
|
|
|
IdJoinSuccess,
|
|
|
|
IdRoomInformation,
|
2017-08-19 22:44:33 +05:30
|
|
|
IdSetGameInfo,
|
2017-07-08 18:54:47 +05:30
|
|
|
IdWifiPacket,
|
|
|
|
IdChatMessage,
|
|
|
|
IdNameCollision,
|
2017-07-14 12:50:39 +05:30
|
|
|
IdMacCollision,
|
|
|
|
IdVersionMismatch,
|
2017-11-20 00:22:37 +05:30
|
|
|
IdWrongPassword,
|
2017-07-14 12:50:39 +05:30
|
|
|
IdCloseRoom
|
2017-07-08 18:54:47 +05:30
|
|
|
};
|
|
|
|
|
2017-07-08 01:04:15 +05:30
|
|
|
/// 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 22:44:33 +05:30
|
|
|
struct Member {
|
|
|
|
std::string nickname; ///< The nickname of the member.
|
|
|
|
GameInfo game_info; ///< The current game of the member
|
|
|
|
MacAddress mac_address; ///< The assigned mac address of the member.
|
|
|
|
};
|
|
|
|
|
2017-07-08 01:04:15 +05:30
|
|
|
Room();
|
|
|
|
~Room();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current state of the room.
|
|
|
|
*/
|
|
|
|
State GetState() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the room information of the room.
|
|
|
|
*/
|
|
|
|
const RoomInformation& GetRoomInformation() const;
|
|
|
|
|
2017-08-19 22:44:33 +05:30
|
|
|
/**
|
|
|
|
* Gets a list of the mbmers connected to the room.
|
|
|
|
*/
|
|
|
|
std::vector<Member> GetRoomMemberList() const;
|
|
|
|
|
2017-11-20 00:22:37 +05:30
|
|
|
/**
|
|
|
|
* Checks if the room is password protected
|
|
|
|
*/
|
|
|
|
bool HasPassword() const;
|
|
|
|
|
2017-07-08 01:04:15 +05:30
|
|
|
/**
|
|
|
|
* Creates the socket for this room. Will bind to default address if
|
|
|
|
* server is empty string.
|
|
|
|
*/
|
2017-11-20 00:22:37 +05:30
|
|
|
bool Create(const std::string& name, const std::string& server = "",
|
|
|
|
u16 server_port = DefaultRoomPort, const std::string& password = "",
|
|
|
|
const u32 max_connections = MaxConcurrentConnections,
|
|
|
|
const std::string& preferred_game = "", u64 preferred_game_id = 0);
|
2017-07-08 01:04:15 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the socket
|
|
|
|
*/
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
private:
|
|
|
|
class RoomImpl;
|
|
|
|
std::unique_ptr<RoomImpl> room_impl;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Network
|