forked from tiltedphoques/TiltedEvolution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameServer.h
107 lines (82 loc) · 3.41 KB
/
GameServer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include <AdminMessages/Message.h>
#include <Messages/AuthenticationRequest.h>
#include <Messages/Message.h>
#include <World.h>
using TiltedPhoques::ConnectionId_t;
using TiltedPhoques::Server;
using TiltedPhoques::String;
struct AuthenticationRequest;
struct Player;
struct PartyComponent;
namespace Resources
{
class ResourceCollection;
}
namespace Console
{
class ConsoleRegistry;
}
struct GameServer final : Server
{
// TODO: eventually refactor this.
struct Info
{
String name;
String desc;
String icon_url;
String tagList;
uint16_t tick_rate;
};
GameServer(Console::ConsoleRegistry& aConsole) noexcept;
virtual ~GameServer();
TP_NOCOPYMOVE(GameServer);
static GameServer* Get() noexcept;
void Initialize();
void Kill();
bool CheckMoPo();
void BindMessageHandlers();
void BindServerCommands();
void UpdateInfo();
void UpdateTimeScale();
void UpdateSettings();
// Packet dispatching
void Send(ConnectionId_t aConnectionId, const ServerMessage& acServerMessage) const;
void Send(ConnectionId_t aConnectionId, const ServerAdminMessage& acServerMessage) const;
void SendToLoaded(const ServerMessage& acServerMessage) const;
void SendToPlayers(const ServerMessage& acServerMessage, const Player* apExcludeSender = nullptr) const;
void SendToPlayersInRange(const ServerMessage& acServerMessage, const entt::entity acOrigin, const Player* apExcludeSender = nullptr) const;
void SendToParty(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, const Player* apExcludeSender = nullptr) const;
void SendToPartyInRange(const ServerMessage& acServerMessage, const PartyComponent& acPartyComponent, const entt::entity acOrigin, const Player* apExcludeSender = nullptr) const;
const Info& GetInfo() const noexcept { return m_info; }
bool IsRunning() const noexcept { return !m_requestStop; }
bool IsPasswordProtected() const noexcept { return m_isPasswordProtected; }
template <class T> void ForEachAdmin(const T& aFunctor)
{
for (auto id : m_adminSessions)
aFunctor(id);
}
protected:
bool ValidateAuthParams(ConnectionId_t aConnectionId, const UniquePtr<AuthenticationRequest>& acRequest);
void HandleAuthenticationRequest(ConnectionId_t aConnectionId, const UniquePtr<AuthenticationRequest>& acRequest);
// Implement TiltedPhoques::Server
void OnUpdate() override;
void OnConsume(const void* apData, uint32_t aSize, ConnectionId_t aConnectionId) override;
void OnConnection(ConnectionId_t aHandle) override;
void OnDisconnection(ConnectionId_t aConnectionId, EDisconnectReason aReason) override;
private:
void UpdateTitle() const;
private:
std::chrono::high_resolution_clock::time_point m_lastFrameTime;
std::function<void(UniquePtr<ClientMessage>&, ConnectionId_t)> m_messageHandlers[kClientOpcodeMax];
std::function<void(UniquePtr<ClientAdminMessage>&, ConnectionId_t)> m_adminMessageHandlers[kClientAdminOpcodeMax];
bool m_isPasswordProtected{};
Info m_info{};
UniquePtr<World> m_pWorld;
UniquePtr<Resources::ResourceCollection> m_pResources;
Console::ConsoleRegistry& m_commands;
TiltedPhoques::Set<ConnectionId_t> m_adminSessions;
TiltedPhoques::Map<ConnectionId_t, entt::entity> m_connectionToEntity;
bool m_requestStop;
static inline GameServer* s_pInstance = nullptr;
};