159[[nodiscard]] std::optional<std::vector<RoomRecord>>
165[[nodiscard]] std::optional<CreateRoomRequest>
read_create_room(std::span<const std::byte> message);
171[[nodiscard]] std::optional<std::uint8_t>
178[[nodiscard]] std::optional<std::uint8_t>
190[[nodiscard]] std::optional<std::uint8_t>
197[[nodiscard]] std::optional<std::pair<std::uint8_t, std::uint8_t>>
204[[nodiscard]] std::optional<std::uint8_t>
216[[nodiscard]] std::optional<bool>
read_set_ready(std::span<const std::byte> message)
noexcept;
238[[nodiscard]] std::vector<std::byte>
write_room_list(std::span<const RoomRecord> rooms);
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
@ BadName
The name is empty, too long, not UTF-8 or has control characters.
std::vector< std::byte > write_join_room(std::uint8_t room)
Encodes a JoinRoom.
std::vector< std::byte > write_room_players(const RoomPlayers &players)
Encodes a RoomPlayers.
std::optional< std::uint8_t > read_join_rejected(std::span< const std::byte > message) noexcept
Reads a JoinRejected.
JoinRejection
Why a room is not joined, the reason of JoinRejected.
Definition rooms.hpp:77
@ NoSuchRoom
No room in use has this number.
@ RoomFull
The room has as many players as it takes.
@ InGame
The player is in game: it plays in its room until its session ends.
std::optional< std::uint8_t > read_room_created(std::span< const std::byte > message) noexcept
Reads a RoomCreated.
std::vector< std::byte > write_room_rejected(RoomRejection reason)
Encodes a RoomRejected.
std::vector< std::byte > write_game_start()
Encodes a GameStart.
bool read_list_rooms(std::span< const std::byte > message) noexcept
Tells whether a message is a well-formed ListRooms: its kind alone.
std::optional< std::pair< std::uint8_t, std::uint8_t > > read_room_joined(std::span< const std::byte > message) noexcept
Reads a RoomJoined.
std::vector< std::byte > write_create_room(const CreateRoomRequest &request)
Encodes a CreateRoom.
Difficulty
How hard the enemies of a room are: how often they come and how much they take.
Definition rooms.hpp:49
@ Hard
More enemies, harder to destroy.
@ Easy
Fewer enemies, easier to destroy.
@ Normal
The game as tuned.
std::vector< std::byte > write_room_list(std::span< const RoomRecord > rooms)
Encodes a RoomList.
constexpr std::size_t max_listed_rooms
Most rooms a server may have, and a RoomList may hold.
Definition rooms.hpp:17
constexpr std::uint8_t max_room_lives
Most lives a room may give its players.
Definition rooms.hpp:46
bool read_leave_room(std::span< const std::byte > message) noexcept
Tells whether a message is a well-formed LeaveRoom: its kind alone.
RoomRejection
Why a room is not created, the reason of RoomRejected.
Definition rooms.hpp:28
@ UnknownWaves
The server has no waves file of this name.
@ BadSize
The number of players is not 1 to 4.
@ BadDifficulty
The difficulty is not a Difficulty.
@ BadLives
The lives are not 1 to max_room_lives.
@ NoRoomLeft
Every room of the server is in use.
@ BadFriendlyFire
The friendly fire is not 0 or 1.
std::optional< std::vector< RoomRecord > > read_room_list(std::span< const std::byte > message)
Reads a RoomList.
std::vector< std::byte > write_set_ready(bool ready)
Encodes a SetReady.
std::vector< std::byte > write_room_joined(std::uint8_t room, std::uint8_t player)
Encodes a RoomJoined.
std::vector< std::byte > write_list_rooms()
Encodes a ListRooms.
std::string_view to_string(ChatRejection reason) noexcept
Short name of a rejection, for logs.
std::optional< CreateRoomRequest > read_create_room(std::span< const std::byte > message)
Reads a CreateRoom.
RoomState
What a room is doing, the state of a RoomList record.
Definition rooms.hpp:20
@ Waiting
None of its players is in game yet.
@ Playing
Its game is running.
std::optional< RoomPlayers > read_room_players(std::span< const std::byte > message)
Reads a RoomPlayers.
std::optional< std::uint8_t > read_join_room(std::span< const std::byte > message) noexcept
Reads a JoinRoom.
std::vector< std::byte > write_join_rejected(JoinRejection reason)
Encodes a JoinRejected.
std::vector< std::byte > write_room_created(std::uint8_t room)
Encodes a RoomCreated.
bool read_game_start(std::span< const std::byte > message) noexcept
Tells whether a message is a well-formed GameStart: its kind alone.
std::optional< std::uint8_t > read_room_rejected(std::span< const std::byte > message) noexcept
Reads a RoomRejected.
std::vector< std::byte > write_leave_room()
Encodes a LeaveRoom.
std::optional< bool > read_set_ready(std::span< const std::byte > message) noexcept
Reads a SetReady.
Content of a CreateRoom.
Definition rooms.hpp:131
RoomRules rules
How the room plays, not checked yet.
Definition rooms.hpp:137
std::string name
Name of the room, not checked yet: see valid_player_name(), whose rules apply.
Definition rooms.hpp:133
bool operator==(const CreateRoomRequest &) const =default
Field-by-field equality.
std::uint8_t max_players
Most players the room takes, not checked yet: 1 to 4 are valid.
Definition rooms.hpp:135
A player of a room, as a RoomPlayers describes it.
Definition rooms.hpp:87
bool operator==(const RoomPlayer &) const =default
Field-by-field equality.
std::uint8_t player
Number in the room, 0 to 3.
Definition rooms.hpp:89
std::string name
Name given at login.
Definition rooms.hpp:91
bool ready
Whether it is ready to start.
Definition rooms.hpp:93
Content of a RoomPlayers.
Definition rooms.hpp:101
std::uint8_t room
Number of the room.
Definition rooms.hpp:103
std::vector< RoomPlayer > players
Its players, at most 4, by number.
Definition rooms.hpp:105
bool operator==(const RoomPlayers &) const =default
Field-by-field equality.
A room, as a RoomList describes it.
Definition rooms.hpp:113
std::uint8_t room
Number of the room, 0 to max_listed_rooms - 1.
Definition rooms.hpp:115
bool operator==(const RoomRecord &) const =default
Field-by-field equality.
std::string name
Name of the room.
Definition rooms.hpp:117
std::uint8_t max_players
Most players the room takes, 1 to 4.
Definition rooms.hpp:121
std::uint8_t players
Players in the room.
Definition rooms.hpp:119
std::uint8_t state
State as sent: a RoomState value, or an unknown one.
Definition rooms.hpp:123
How a room plays, chosen at its creation (CreateRoom, RFC section 3.6).
Definition rooms.hpp:60
std::uint8_t lives
Lives of each player, 1 to max_room_lives.
Definition rooms.hpp:62
std::uint8_t difficulty
A Difficulty value.
Definition rooms.hpp:64
bool operator==(const RoomRules &) const =default
Field-by-field equality.
std::uint8_t friendly_fire
1 if the players' missiles hit the other players, 0 if not.
Definition rooms.hpp:69
std::string waves
Name of the waves file to play, among those the server offers, without its .json; empty for the serve...
Definition rooms.hpp:67