3#include <boost/multi_index_container.hpp>
4#include <boost/multi_index/hashed_index.hpp>
5#include <boost/multi_index/member.hpp>
8#include <boost/asio.hpp>
21using namespace boost::asio::ip;
63class Session :
public std::enable_shared_from_this<Session> {
93 [[nodiscard(
"You should check if the connection was successful")]]
94 bool connectTo(basic_resolver_results<class boost::asio::ip::tcp> endpoints);
101 void sendPacket(std::shared_ptr<PackagedPacket> packet);
116 void setDM(
bool is_dm);
122 std::optional<PacketHeader> prev_hdr;
126 std::vector<std::shared_ptr<PackagedPacket>> packets_to_send;
128 std::array<char, NETWORK_BUFFER_SIZE>
buffer;
150 SocketError _classifySocketError(boost::system::error_code ec,
const char* where);
156 bool socketHasEnoughBytes(std::size_t bytes);
165 boost::asio::ip::address
ip,
166 std::shared_ptr<Session>
session)
171 boost::asio::ip::address
ip;
183 return v.to_v4().to_ulong();
185 auto const&
range =
v.to_v6().to_bytes();
186 return boost::hash_range(
range.begin(),
range.end());
188 if (
v.is_unspecified()) {
190 return static_cast<size_t>(0x4751301174351161ul);
192 return boost::hash_value(
v.to_string());
210 boost::multi_index::indexed_by<
211 boost::multi_index::hashed_unique<
212 boost::multi_index::tag<IndexByID>,
213 boost::multi_index::member<SessionEntry, EntityID, &SessionEntry::id>
215 boost::multi_index::hashed_unique<
216 boost::multi_index::tag<IndexByIP>,
217 boost::multi_index::member<SessionEntry, boost::asio::ip::address, &SessionEntry::ip>,
Definition: session.hpp:63
bool connectTo(basic_resolver_results< class boost::asio::ip::tcp > endpoints)
Definition: session.cpp:89
bool isOkay() const
Definition: session.cpp:24
~Session()
Definition: session.cpp:21
void setDM(bool is_dm)
Definition: session.cpp:170
void sendEvent(Event evt)
Definition: session.cpp:136
void sendPacket(std::shared_ptr< PackagedPacket > packet)
Definition: session.cpp:119
const SessionInfo & getInfo() const
Definition: session.cpp:28
std::vector< Event > handleAllReceivedPackets()
Definition: session.cpp:32
const GLdouble * v
Definition: glad.h:1999
GLuint id
Definition: glad.h:1776
GLboolean * data
Definition: glad.h:1600
GLuint buffer
Definition: glad.h:1791
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glad.h:1531
GLenum GLint * range
Definition: glad.h:2816
PacketType
Definition: packet.hpp:30
SocketError
Definition: session.hpp:29
@ FATAL
We cannot recover from this error, so the socket is probably dead.
Definition: session.hpp:33
@ RETRY
There was an error, but it doesn't compromise the socket connection.
Definition: session.hpp:35
@ NONE
No error, everything is good.
Definition: session.hpp:31
boost::multi_index_container< SessionEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag< IndexByID >, boost::multi_index::member< SessionEntry, EntityID, &SessionEntry::id > >, boost::multi_index::hashed_unique< boost::multi_index::tag< IndexByIP >, boost::multi_index::member< SessionEntry, boost::asio::ip::address, &SessionEntry::ip >, ip_address_hash > > > Sessions
Definition: session.hpp:221
Definition: event.hpp:348
Definition: session.hpp:197
Definition: session.hpp:199
Definition: session.hpp:162
EntityID id
Definition: session.hpp:169
SessionEntry(EntityID id, bool is_dungeon_master, boost::asio::ip::address ip, std::shared_ptr< Session > session)
Definition: session.hpp:163
boost::asio::ip::address ip
Definition: session.hpp:171
bool is_dungeon_master
Definition: session.hpp:170
std::shared_ptr< Session > session
Definition: session.hpp:172
Definition: session.hpp:46
SessionInfo(std::optional< std::string > client_name, std::optional< EntityID > client_eid, std::optional< bool > is_dungeon_master)
Definition: session.hpp:47
std::optional< EntityID > client_eid
Definition: session.hpp:52
std::optional< std::string > client_name
Definition: session.hpp:51
std::optional< bool > is_dungeon_master
Definition: session.hpp:53
Definition: session.hpp:180
size_t operator()(const boost::asio::ip::address &v) const
Definition: session.hpp:181
uint32_t EntityID
Global Object ID (when the server or client references an object with a particular EntityID,...
Definition: typedefs.hpp:9