141[[nodiscard]]
bool valid_text(std::string_view text, std::size_t max_size)
noexcept;
153[[nodiscard]] std::optional<TcpKind>
kind_of(std::span<const std::byte> message)
noexcept;
164[[nodiscard]] std::optional<LoginAccepted>
171[[nodiscard]] std::optional<std::uint8_t>
178[[nodiscard]] std::optional<std::uint8_t>
read_logout(std::span<const std::byte> message)
noexcept;
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
@ Left
It quit: Logout, Disconnect, or its TCP connection closed.
@ TimedOut
No valid datagram for too long, or no event acknowledged (RFC section 5.5).
@ Kicked
A protocol error ended its session (RFC section 3.2).
constexpr std::size_t max_name_size
Longest player name, in bytes of UTF-8.
Definition login.hpp:20
LoginRejection
Why a login is refused, the reason of LoginRejected.
Definition login.hpp:70
@ BadName
The name is empty, too long, not UTF-8 or has control characters.
@ ServerFull
Every room of the server is full.
@ GameStarted
The game is running and does not take new players.
@ NameTaken
Another player of the server has this name.
@ BadVersion
The server does not speak the requested version.
@ Banned
The administrator banned the address the client connects from.
std::vector< std::byte > write_logout(LogoutReason reason)
Encodes a Logout.
LogoutReason
Why a session ends, the reason of Logout.
Definition login.hpp:86
@ Shutdown
The server is stopping.
@ RoomClosed
The administrator of the server closed the player's room.
@ ProtocolError
The client sent something invalid over UDP.
std::vector< std::byte > write_login_request(const LoginRequest &request)
Encodes a LoginRequest.
bool valid_player_name(std::string_view name) noexcept
Tells whether a name follows the rules of LoginRequest.
std::vector< std::byte > write_login_accepted(const LoginAccepted &accepted)
Encodes a LoginAccepted.
std::vector< std::byte > write_login_rejected(LoginRejection reason)
Encodes a LoginRejected.
TcpKind
First byte of every TCP message: what it is.
Definition login.hpp:24
@ Logout
Both ways: the sender ends the session and closes.
@ ChatRejected
Server to client: why a ChatSend was not relayed.
@ SetReady
Client to server: ready to start, or not.
@ ListRooms
Client to server, after the login: asks for the rooms.
@ GameStart
Server to client: every player of its room is ready, bind and play.
@ LeaveRoom
Client to server: leaves its room for the lobby.
@ JoinRoom
Client to server: the room to join.
@ RoomList
Server to client: the rooms, answering ListRooms.
@ LoginRejected
Server to client: why the login failed; the server closes afterwards.
@ ScoreList
Server to client: the best scores, best first.
@ ChatSend
Client to server: a text for the players of its room (RFC section 3.8).
@ CreateRoom
Client to server, after the login: name and size of a room to create.
@ RoomCreated
Server to client: the number of the room created, answering CreateRoom.
@ JoinRejected
Server to client: why the room was not joined, answering JoinRoom.
@ ListScores
Client to server: the best scores, please (RFC section 3.9).
@ RoomRejected
Server to client: why the room was not created, answering CreateRoom.
@ RoomJoined
Server to client: the room joined and the player's number there.
std::optional< LoginRequest > read_login_request(std::span< const std::byte > message)
Reads a LoginRequest.
std::optional< TcpKind > kind_of(std::span< const std::byte > message) noexcept
Kind of a TCP message.
std::optional< std::uint8_t > read_logout(std::span< const std::byte > message) noexcept
Reads a Logout.
std::optional< LoginAccepted > read_login_accepted(std::span< const std::byte > message) noexcept
Reads a LoginAccepted.
std::string_view to_string(ChatRejection reason) noexcept
Short name of a rejection, for logs.
constexpr std::uint8_t protocol_version
Protocol version the server speaks, in LoginRequest and in the UDP header.
Definition login.hpp:17
bool valid_text(std::string_view text, std::size_t max_size) noexcept
Tells whether a text is 1 to max_size bytes of valid UTF-8 without control characters,...
std::optional< std::uint8_t > read_login_rejected(std::span< const std::byte > message) noexcept
Reads a LoginRejected.
Content of a ChatMessage.
Definition chat.hpp:38
Content of a LoginAccepted.
Definition login.hpp:116
std::uint8_t player
Player number in its room, 0 to 3.
Definition login.hpp:120
std::uint16_t udp_port
UDP port of the server.
Definition login.hpp:122
std::uint32_t session
Session token, never 0.
Definition login.hpp:118
bool operator==(const LoginAccepted &) const =default
Field-by-field equality.
Content of a LoginRequest.
Definition login.hpp:104
std::uint8_t version
Protocol version of the client.
Definition login.hpp:106
std::string name
Player name, not checked yet: see valid_player_name().
Definition login.hpp:108
bool operator==(const LoginRequest &) const =default
Field-by-field equality.
Content of a RoomPlayers.
Definition rooms.hpp:101