R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
chat.hpp File Reference

TCP messages of the chat (RFC section 3.8): encoding, decoding and text rules. More...

#include <cstddef>
#include <cstdint>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>

Go to the source code of this file.

Classes

struct  rtype::ChatMessage
 Content of a ChatMessage. More...
 

Namespaces

namespace  rtype
 R-Type game code, built on the Aegis2D engine.
 

Enumerations

enum class  rtype::ChatRejection : std::uint8_t { rtype::TooLong = 1 , rtype::BadText = 2 , rtype::TooFast = 3 }
 Why a chat message is not relayed, the reason of ChatRejected. More...
 

Functions

std::string_view rtype::to_string (ChatRejection reason) noexcept
 Short name of a rejection, for logs.
 
std::optional< ChatRejection > rtype::check_chat_text (std::string_view text) noexcept
 Checks a text against the rules of ChatSend, the length first.
 
std::optional< std::string > rtype::read_chat_send (std::span< const std::byte > message)
 Reads a ChatSend.
 
std::optional< ChatMessage > rtype::read_chat_message (std::span< const std::byte > message)
 Reads a ChatMessage.
 
std::optional< std::uint8_t > rtype::read_chat_rejected (std::span< const std::byte > message) noexcept
 Reads a ChatRejected.
 
std::vector< std::byte > rtype::write_chat_send (std::string_view text)
 Encodes a ChatSend.
 
std::vector< std::byte > rtype::write_chat_message (const ChatMessage &message)
 Encodes a ChatMessage.
 
std::vector< std::byte > rtype::write_chat_rejected (ChatRejection reason)
 Encodes a ChatRejected.
 

Variables

constexpr std::size_t rtype::max_chat_size = 200
 Longest chat text, in bytes of UTF-8.
 
constexpr std::uint8_t rtype::lobby_player = 255
 player of a ChatMessage whose sender is in the lobby, with no player number.
 
constexpr std::uint8_t rtype::server_player = 254
 player of a ChatMessage of the server itself, such as its administrator's say: no player has it (RFC section 3.8).
 
constexpr std::string_view rtype::server_name = "server"
 name of a ChatMessage of the server itself.
 

Detailed Description

TCP messages of the chat (RFC section 3.8): encoding, decoding and text rules.