80 std::function<
void()> beforeServerStartup, std::function<
void(int64_t)> beforeClientConnected,
81 std::function<
void(int64_t)> afterClientDisconnected)
82 : _registry(registry),
83 _beforeFrame(std::move(beforeFrame)),
84 _beforeServerStartup(std::move(beforeServerStartup)),
85 _beforeClientConnected(std::move(beforeClientConnected)),
86 _afterClientDisconnected(std::move(afterClientDisconnected))
89 g_pCVar = engine.
Cvar;
90 ConVar_Register(FCVAR_RELEASE | FCVAR_CLIENT_CAN_EXECUTE | FCVAR_SERVER_CAN_EXECUTE | FCVAR_GAMEDLL);
92 auto add = [
this](
Subscription hook) { _hooks.Add(std::move(hook)); };
94 const auto onFrame = [
this](IServerGameDLL&, bool, bool, bool) {
96 _registry.RaiseFrame();
98 const auto onStartupServer = [
this](INetworkServerService&,
const GameSessionConfiguration_t&,
99 ISource2WorldSession*,
const char* mapName) {
100 const std::string_view map =
Text(mapName);
101 Log::Info(
"Server startup: map '{}'.", map.empty() ?
"<none>" : map);
102 _beforeServerStartup();
103 _registry.RaiseServerStartup(map);
104 DisconnectEveryone();
106 const auto onClientConnect = [
this](IServerGameClients&, CPlayerSlot slot,
const char* name, uint64 xuid,
107 const char*, bool, CBufferString* rejectReason) {
108 return AdmitClient(_registry, slot.Get(), xuid,
Text(name), rejectReason);
110 const auto onClientConnected = [
this](IServerGameClients&, CPlayerSlot slot,
const char* name, uint64 xuid,
111 const char*,
const char* address, bool) {
113 ConnectClient(slot.Get(), xuid,
Text(name),
Text(address));
115 const auto onClientPutInServer = [
this, server = engine.
Engine](IServerGameClients&, CPlayerSlot slot,
116 const char* name, ClientPutInServerType_t,
118 if (
IsValidSlot(slot.Get()) && !_registry.IsConnected(slot.Get()))
123 const auto onClientDisconnect = [
this](IServerGameClients&, CPlayerSlot slot, ENetworkDisconnectionReason,
124 const char*, uint64 xuid,
const char*) {
125 _registry.RaiseClientDisconnected(slot.Get());
126 _afterClientDisconnected(
static_cast<int64_t
>(xuid));
128 const auto onClientFullyConnect = [
this](IServerGameClients&, CPlayerSlot slot) {
129 _registry.RaiseClientFullyConnected(slot.Get());
131 const auto onClientSettingsChanged = [
this](IServerGameClients&, CPlayerSlot slot) {
132 _registry.RaiseClientSettingsChanged(slot.Get());
134 const auto onConCommand = [
this](ICvar&, ConCommandRef command,
const CCommandContext& context,
135 const CCommand& arguments) {
136 return RunCommand(_registry,
Text(command.GetName()), arguments, context.GetPlayerSlot().Get());
138 const auto onClientCommand = [
this](IServerGameClients&, CPlayerSlot slot,
const CCommand& arguments) {
139 return RunCommand(_registry,
Text(arguments.Arg(0)), arguments, slot.Get());
141 const auto onCheckTransmit = [
this](ISource2GameEntities&, CCheckTransmitInfo** infoList,
int infoCount,
142 CBitVec<MAX_EDICTS>&, CBitVec<MAX_EDICTS>&,
const Entity2Networkable_t**,
143 const uint16*, int) { _registry.RaiseCheckTransmit(infoList, infoCount); };
155 onClientFullyConnect));
157 onClientSettingsChanged));
166 add(std::move(*manifest));
170 Log::Error(
"Precache is off: {}", manifest.error().Detail);