Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
server.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/asio/ip/udp.hpp>
4#include <boost/asio/io_context.hpp>
5
6#include <thread>
7#include <atomic>
8#include <unordered_map>
9#include <memory>
10#include <chrono>
11
18
19using boost::asio::ip::tcp;
20
22using EventList = std::vector<std::pair<EntityID, Event>>;
23
24class Server {
25public:
26 Server(boost::asio::io_context& io_context, GameConfig config);
27
28 static EntityID genNewEID();
29
35 std::chrono::milliseconds doTick();
36
38
39 void updateGameState(const EventList& events);
40
41 void sendUpdateToAllClients(Event event);
42
43 void sendLightSourceUpdates(EntityID playerID);
44
45 void sendSoundCommands();
46
47private:
49 EntityID world_eid;
50
52 LobbyBroadcaster lobby_broadcaster;
53
54 void _doAccept();
55
56 tcp::acceptor acceptor;
57 tcp::socket socket;
58
72 std::shared_ptr<Session> _handleNewSession(boost::asio::ip::address addr);
73
75 Sessions sessions;
76
78 ServerGameState state;
79
81 GameConfig config;
82
84 IntroCutscene intro_cutscene;
85};
Definition: introcutscene.hpp:16
Definition: lobbybroadcaster.hpp:18
The ServerGameState class contains all abstract game state data and logic for a single game state ins...
Definition: servergamestate.hpp:43
Definition: server.hpp:24
void sendUpdateToAllClients(Event event)
Definition: server.cpp:100
EventList getAllClientEvents()
Definition: server.cpp:79
std::chrono::milliseconds doTick()
Definition: server.cpp:212
static EntityID genNewEID()
Definition: server.cpp:67
void sendLightSourceUpdates(EntityID playerID)
Definition: server.cpp:109
void updateGameState(const EventList &events)
Definition: server.cpp:72
void sendSoundCommands()
Definition: server.cpp:535
std::vector< std::pair< EntityID, Event > > EventList
Represents a list of events from a certain client with a specified ID.
Definition: server.hpp:22
std::vector< std::pair< EntityID, Event > > EventList
Represents a list of events from a certain client with a specified ID.
Definition: servergamestate.hpp:25
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: config.hpp:12
uint32_t EntityID
Global Object ID (when the server or client references an object with a particular EntityID,...
Definition: typedefs.hpp:9