room.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2017 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <memory>
  7. #include <string>
  8. #include "common/common_types.h"
  9. namespace Network {
  10. constexpr u32 network_version = 1; ///< The version of this Room and RoomMember
  11. constexpr u16 DefaultRoomPort = 1234;
  12. constexpr size_t NumChannels = 1; // Number of channels used for the connection
  13. struct RoomInformation {
  14. std::string name; ///< Name of the server
  15. u32 member_slots; ///< Maximum number of members in this room
  16. };
  17. using MacAddress = std::array<u8, 6>;
  18. /// A special MAC address that tells the room we're joining to assign us a MAC address
  19. /// automatically.
  20. const MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  21. // 802.11 broadcast MAC address
  22. constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  23. // The different types of messages that can be sent. The first byte of each packet defines the type
  24. enum RoomMessageTypes : u8 {
  25. IdJoinRequest = 1,
  26. IdJoinSuccess,
  27. IdRoomInformation,
  28. IdSetGameName,
  29. IdWifiPacket,
  30. IdChatMessage,
  31. IdNameCollision,
  32. IdMacCollision,
  33. IdVersionMismatch,
  34. IdCloseRoom
  35. };
  36. /// This is what a server [person creating a server] would use.
  37. class Room final {
  38. public:
  39. enum class State : u8 {
  40. Open, ///< The room is open and ready to accept connections.
  41. Closed, ///< The room is not opened and can not accept connections.
  42. };
  43. Room();
  44. ~Room();
  45. /**
  46. * Gets the current state of the room.
  47. */
  48. State GetState() const;
  49. /**
  50. * Gets the room information of the room.
  51. */
  52. const RoomInformation& GetRoomInformation() const;
  53. /**
  54. * Creates the socket for this room. Will bind to default address if
  55. * server is empty string.
  56. */
  57. void Create(const std::string& name, const std::string& server = "",
  58. u16 server_port = DefaultRoomPort);
  59. /**
  60. * Destroys the socket
  61. */
  62. void Destroy();
  63. private:
  64. class RoomImpl;
  65. std::unique_ptr<RoomImpl> room_impl;
  66. };
  67. } // namespace Network