2022-02-24 01:51:11 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: Implement things from GameInterface.cpp. Mostly the engine interfaces.
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
#include "core/stdafx.h"
|
2023-01-24 00:53:45 +01:00
|
|
|
#include "tier1/cvar.h"
|
2022-12-03 02:57:11 +01:00
|
|
|
#include "public/server_class.h"
|
2023-01-16 21:09:21 +01:00
|
|
|
#include "public/eiface.h"
|
2023-01-24 00:53:45 +01:00
|
|
|
#include "public/const.h"
|
2023-07-02 21:49:35 +02:00
|
|
|
#include "common/protocol.h"
|
2023-01-24 00:53:45 +01:00
|
|
|
#include "engine/server/sv_main.h"
|
|
|
|
#include "gameinterface.h"
|
|
|
|
#include "entitylist.h"
|
|
|
|
#include "baseanimating.h"
|
2023-07-02 21:49:35 +02:00
|
|
|
#include "game/shared/usercmd.h"
|
2023-07-19 02:27:28 +02:00
|
|
|
#include "game/server/util_server.h"
|
2022-02-24 01:51:11 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This is called when a new game is started. (restart, map)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CServerGameDLL::GameInit(void)
|
|
|
|
{
|
2022-08-31 14:38:49 +02:00
|
|
|
const static int index = 1;
|
2022-02-24 01:51:11 +01:00
|
|
|
CallVFunc<void>(index, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This is called when scripts are getting recompiled. (restart, map, changelevel)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CServerGameDLL::PrecompileScriptsJob(void)
|
|
|
|
{
|
2022-08-31 14:38:49 +02:00
|
|
|
const static int index = 2;
|
2022-02-24 01:51:11 +01:00
|
|
|
CallVFunc<void>(index, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Called when a level is shutdown (including changing levels)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CServerGameDLL::LevelShutdown(void)
|
|
|
|
{
|
2022-08-31 14:38:49 +02:00
|
|
|
const static int index = 8;
|
2022-02-24 01:51:11 +01:00
|
|
|
CallVFunc<void>(index, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This is called when a game ends (server disconnect, death, restart, load)
|
|
|
|
// NOT on level transitions within a game
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CServerGameDLL::GameShutdown(void)
|
|
|
|
{
|
2022-12-03 02:58:05 +01:00
|
|
|
// Game just calls a nullsub for GameShutdown lol.
|
2022-08-31 14:38:49 +02:00
|
|
|
const static int index = 9;
|
2022-02-24 01:51:11 +01:00
|
|
|
CallVFunc<void>(index, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-12-03 02:57:11 +01:00
|
|
|
// Purpose: Gets the simulation tick interval
|
2022-02-24 01:51:11 +01:00
|
|
|
// Output : float
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
float CServerGameDLL::GetTickInterval(void)
|
|
|
|
{
|
2022-08-31 14:38:49 +02:00
|
|
|
const static int index = 11;
|
2022-02-24 01:51:11 +01:00
|
|
|
return CallVFunc<float>(index, this);
|
|
|
|
}
|
|
|
|
|
2022-12-03 02:57:11 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: get all server classes
|
|
|
|
// Output : ServerClass*
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
ServerClass* CServerGameDLL::GetAllServerClasses(void)
|
|
|
|
{
|
|
|
|
const static int index = 12;
|
|
|
|
return CallVFunc<ServerClass*>(index, this);
|
|
|
|
}
|
|
|
|
|
2022-09-18 20:42:16 +01:00
|
|
|
void __fastcall CServerGameDLL::OnReceivedSayTextMessage(void* thisptr, int senderId, const char* text, bool isTeamChat)
|
|
|
|
{
|
|
|
|
#if defined(GAMEDLL_S3)
|
|
|
|
// set isTeamChat to false so that we can let the convar sv_forceChatToTeamOnly decide whether team chat should be enforced
|
|
|
|
// this isn't a great way of doing it but it works so meh
|
|
|
|
CServerGameDLL__OnReceivedSayTextMessage(thisptr, senderId, text, false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-01-24 00:53:45 +01:00
|
|
|
void DrawServerHitboxes(bool bRunOverlays)
|
|
|
|
{
|
|
|
|
int nVal = sv_showhitboxes->GetInt();
|
|
|
|
Assert(nVal < NUM_ENT_ENTRIES);
|
|
|
|
|
|
|
|
if (nVal == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::function<void(int)> fnLookupAndDraw = [&](int iEntity)
|
|
|
|
{
|
|
|
|
IHandleEntity* pEntity = LookupEntityByIndex(iEntity);
|
|
|
|
CBaseAnimating* pAnimating = dynamic_cast<CBaseAnimating*>(pEntity);
|
|
|
|
|
|
|
|
if (pAnimating)
|
|
|
|
{
|
|
|
|
pAnimating->DrawServerHitboxes();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (nVal == 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_ENT_ENTRIES; i++)
|
|
|
|
{
|
|
|
|
fnLookupAndDraw(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Lookup entity manually by index from 'sv_showhitboxes'.
|
|
|
|
{
|
|
|
|
fnLookupAndDraw(nVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-02 21:49:35 +02:00
|
|
|
void CServerGameClients::ProcessUserCmds(CServerGameClients* thisp, edict_t edict,
|
|
|
|
bf_read* buf, int numCmds, int totalCmds, int droppedPackets, bool ignore, bool paused)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CUserCmd* from, * to;
|
|
|
|
|
|
|
|
// We track last three command in case we drop some
|
|
|
|
// packets but get them back.
|
|
|
|
CUserCmd cmds[MAX_BACKUP_COMMANDS_PROCESS];
|
|
|
|
CUserCmd cmdNull; // For delta compression
|
|
|
|
|
|
|
|
Assert(numCmds >= 0);
|
|
|
|
Assert((totalCmds - numCmds) >= 0);
|
|
|
|
|
|
|
|
CPlayer* pPlayer = UTIL_PlayerByIndex(edict);
|
|
|
|
|
|
|
|
// Too many commands?
|
|
|
|
if (totalCmds < 0 || totalCmds >= (MAX_BACKUP_COMMANDS_PROCESS - 1) ||
|
|
|
|
numCmds < 0 || numCmds > totalCmds)
|
|
|
|
{
|
|
|
|
//const char* name = "unknown";
|
|
|
|
//if (pPlayer)
|
|
|
|
//{
|
|
|
|
// name = pPlayer->GetPlayerName();
|
|
|
|
//}
|
|
|
|
|
|
|
|
//Warning(eDLL_T::SERVER, "%s: too many cmds %i sent for player %s\n", __FUNCTION__, totalCmds, name);
|
|
|
|
// !TODO: Drop the client from here.
|
|
|
|
|
|
|
|
buf->SetOverflowFlag();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
from = &cmdNull;
|
|
|
|
for (i = totalCmds - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
to = &cmds[i];
|
|
|
|
ReadUserCmd(buf, to, from);
|
|
|
|
from = to;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client not fully connected or server has gone inactive or is paused, just ignore
|
|
|
|
if (ignore || !pPlayer)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pPlayer->ProcessUserCmds(cmds, numCmds, totalCmds, droppedPackets, paused);
|
|
|
|
}
|
|
|
|
|
2023-01-24 00:53:45 +01:00
|
|
|
void RunFrameServer(double flFrameTime, bool bRunOverlays, bool bUniformUpdate)
|
|
|
|
{
|
|
|
|
DrawServerHitboxes(bRunOverlays);
|
|
|
|
v_RunFrameServer(flFrameTime, bRunOverlays, bUniformUpdate);
|
|
|
|
}
|
|
|
|
|
2023-01-25 02:26:52 +01:00
|
|
|
void VServerGameDLL::Attach() const
|
2022-09-18 20:42:16 +01:00
|
|
|
{
|
|
|
|
#if defined(GAMEDLL_S3)
|
|
|
|
DetourAttach((LPVOID*)&CServerGameDLL__OnReceivedSayTextMessage, &CServerGameDLL::OnReceivedSayTextMessage);
|
2023-07-02 21:49:35 +02:00
|
|
|
DetourAttach(&v_CServerGameClients__ProcessUserCmds, CServerGameClients::ProcessUserCmds);
|
2022-09-18 20:42:16 +01:00
|
|
|
#endif
|
2023-01-24 00:53:45 +01:00
|
|
|
DetourAttach(&v_RunFrameServer, &RunFrameServer);
|
2022-09-18 20:42:16 +01:00
|
|
|
}
|
|
|
|
|
2023-01-25 02:26:52 +01:00
|
|
|
void VServerGameDLL::Detach() const
|
2022-09-18 20:42:16 +01:00
|
|
|
{
|
|
|
|
#if defined(GAMEDLL_S3)
|
|
|
|
DetourDetach((LPVOID*)&CServerGameDLL__OnReceivedSayTextMessage, &CServerGameDLL::OnReceivedSayTextMessage);
|
2023-07-02 21:49:35 +02:00
|
|
|
DetourDetach(&v_CServerGameClients__ProcessUserCmds, CServerGameClients::ProcessUserCmds);
|
2022-09-18 20:42:16 +01:00
|
|
|
#endif
|
2023-01-24 00:53:45 +01:00
|
|
|
DetourDetach(&v_RunFrameServer, &RunFrameServer);
|
2022-09-18 20:42:16 +01:00
|
|
|
}
|
|
|
|
|
2022-04-12 02:48:46 +02:00
|
|
|
CServerGameDLL* g_pServerGameDLL = nullptr;
|
|
|
|
CServerGameClients* g_pServerGameClients = nullptr;
|
2023-01-16 21:09:21 +01:00
|
|
|
CServerGameEnts* g_pServerGameEntities = nullptr;
|
2023-01-17 11:21:10 +01:00
|
|
|
|
|
|
|
// Holds global variables shared between engine and game.
|
2023-01-20 14:07:25 +01:00
|
|
|
CGlobalVars** g_pGlobals = nullptr;
|