From 2e37ce01c9dcdc5932cf5fe47a1ade0e0d2b7cf8 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Fri, 7 Jul 2017 21:34:15 +0200 Subject: Implement basic virtual Room support based on enet (#2803) * Added support for network with ENet lib, connecting is possible, but data can't be sent, yet. * fixup! Added support for network with ENet lib, * fixup! CLang * fixup! Added support for network with ENet lib, * fixup! Added support for network with ENet lib, * fixup! Clang format * More fixups! * Moved ENetHost* and ENetPeer* into pimpl classes * fixup! Moved ENetHost* and ENetPeer* into pimpl classes * fixup! Clang again * fixup! Moved ENetHost* and ENetPeer* into pimpl classes * fixup! Moved ENetHost* and ENetPeer* into pimpl classes * fixup! Moved ENetHost* and ENetPeer* into pimpl classes --- src/network/room_member.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/network/room_member.h (limited to 'src/network/room_member.h') diff --git a/src/network/room_member.h b/src/network/room_member.h new file mode 100644 index 000000000..177622b69 --- /dev/null +++ b/src/network/room_member.h @@ -0,0 +1,65 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include "common/common_types.h" +#include "network/room.h" + +namespace Network { + +/** + * This is what a client [person joining a server] would use. + * It also has to be used if you host a game yourself (You'd create both, a Room and a + * RoomMembership for yourself) + */ +class RoomMember final { +public: + enum class State : u8 { + Idle, ///< Default state + Error, ///< Some error [permissions to network device missing or something] + Joining, ///< The client is attempting to join a room. + Joined, ///< The client is connected to the room and is ready to send/receive packets. + LostConnection, ///< Connection closed + + // Reasons why connection was rejected + NameCollision, ///< Somebody is already using this name + MacCollision, ///< Somebody is already using that mac-address + CouldNotConnect ///< The room is not responding to a connection attempt + }; + + RoomMember(); + ~RoomMember(); + + /** + * Returns the status of our connection to the room. + */ + State GetState() const; + + /** + * Returns whether we're connected to a server or not. + */ + bool IsConnected() const; + + /** + * Attempts to join a room at the specified address and port, using the specified nickname. + * This may fail if the username is already taken. + */ + void Join(const std::string& nickname, const char* server_addr = "127.0.0.1", + const u16 serverPort = DefaultRoomPort, const u16 clientPort = 0); + + /** + * Leaves the current room. + */ + void Leave(); + +private: + class RoomMemberImpl; + std::unique_ptr room_member_impl; +}; + +} // namespace Network -- cgit v1.2.3