forked from alterware/s1-mod
maint: update
This commit is contained in:
181
src/client/game/engine/sv_game.cpp
Normal file
181
src/client/game/engine/sv_game.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
#include <std_include.hpp>
|
||||
#include <game/game.hpp>
|
||||
|
||||
#include "sv_game.hpp"
|
||||
|
||||
#include <component/console.hpp>
|
||||
|
||||
#include <utils/string.hpp>
|
||||
|
||||
namespace game::engine
|
||||
{
|
||||
char* SV_ExpandNewlines(char* in)
|
||||
{
|
||||
static char string[1024];
|
||||
|
||||
unsigned int l = 0;
|
||||
while (*in && l < sizeof(string) - 3)
|
||||
{
|
||||
if (*in == '\n')
|
||||
{
|
||||
string[l++] = '\\';
|
||||
string[l++] = 'n';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*in != '\x14' && *in != '\x15')
|
||||
{
|
||||
string[l++] = *in;
|
||||
}
|
||||
}
|
||||
|
||||
++in;
|
||||
}
|
||||
|
||||
string[l] = '\0';
|
||||
return string;
|
||||
}
|
||||
|
||||
void SV_CullIgnorableServerCommands(mp::client_t* client)
|
||||
{
|
||||
int to = client->reliableSent + 1;
|
||||
for (int from = to; from <= client->reliableSequence; ++from)
|
||||
{
|
||||
int from_index = from & 0x7F;
|
||||
assert(client->netBuf.reliableCommandInfo[from_index].time >= 0);
|
||||
if (client->netBuf.reliableCommandInfo[from_index].type)
|
||||
{
|
||||
int to_index = to & 0x7F;
|
||||
if (to_index != from_index)
|
||||
{
|
||||
client->netBuf.reliableCommandInfo[to_index] = client->netBuf.reliableCommandInfo[from_index];
|
||||
}
|
||||
|
||||
++to;
|
||||
}
|
||||
}
|
||||
|
||||
client->reliableSequence = to - 1;
|
||||
}
|
||||
|
||||
void SV_DelayDropClient(mp::client_t* drop, const char* reason)
|
||||
{
|
||||
assert(drop);
|
||||
assert(reason);
|
||||
assert(drop->header.state != mp::CS_FREE);
|
||||
if (drop->header.state == mp::CS_ZOMBIE)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
console::info("(drop->dropReason) = %s", drop->dropReason);
|
||||
#endif
|
||||
}
|
||||
else if (!drop->dropReason)
|
||||
{
|
||||
drop->dropReason = reason;
|
||||
}
|
||||
}
|
||||
|
||||
void SV_AddServerCommand(mp::client_t* client, svscmd_type type, const char* cmd)
|
||||
{
|
||||
static_assert(offsetof(mp::client_t, netBuf.reliableCommandInfo[0].cmd) == 0xC44);
|
||||
|
||||
if (client->testClient == TC_BOT)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (client->reliableSequence - client->reliableAcknowledge < 64 && client->header.state == mp::CS_ACTIVE || (SV_CullIgnorableServerCommands(client), type))
|
||||
{
|
||||
int len = static_cast<int>(std::strlen(cmd)) + 1;
|
||||
int to = SV_CanReplaceServerCommand(client, reinterpret_cast<const unsigned char*>(cmd), len);
|
||||
if (to < 0)
|
||||
{
|
||||
++client->reliableSequence;
|
||||
}
|
||||
else
|
||||
{
|
||||
int from = to + 1;
|
||||
while (from <= client->reliableSequence)
|
||||
{
|
||||
client->netBuf.reliableCommandInfo[to & 0x7F] = client->netBuf.reliableCommandInfo[from & 0x7F];
|
||||
++from;
|
||||
++to;
|
||||
}
|
||||
}
|
||||
|
||||
if (client->reliableSequence - client->reliableAcknowledge == 129)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
console::info("===== pending server commands =====\n");
|
||||
int i = 0;
|
||||
for (i = client->reliableAcknowledge + 1; i <= client->reliableSequence; ++i)
|
||||
{
|
||||
console::info("cmd %5d: %8d: %s\n", i, client->netBuf.reliableCommandInfo[i & 0x7F].time, client->netBuf.reliableCommandInfo[i & 0x7F].cmd);
|
||||
}
|
||||
console::info("cmd %5d: %8d: %s\n", i, *game::mp::serverTime, cmd);
|
||||
#endif
|
||||
NET_OutOfBandPrint(NS_SERVER, &client->header.netchan.remoteAddress, "disconnect");
|
||||
SV_DelayDropClient(client, "EXE_SERVERCOMMANDOVERFLOW");
|
||||
type = SV_CMD_RELIABLE;
|
||||
cmd = utils::string::va("%c \"EXE_SERVERCOMMANDOVERFLOW\"", 'r');
|
||||
}
|
||||
|
||||
int index = client->reliableSequence & 0x7F;
|
||||
MSG_WriteReliableCommandToBuffer(cmd, client->netBuf.reliableCommandInfo[index].cmd, sizeof(client->netBuf.reliableCommandInfo[index].cmd));
|
||||
client->netBuf.reliableCommandInfo[index].time = *game::mp::serverTime;
|
||||
client->netBuf.reliableCommandInfo[index].type = type;
|
||||
}
|
||||
}
|
||||
|
||||
void SV_SendServerCommand(mp::client_t* cl, svscmd_type type, const char* fmt, ...)
|
||||
{
|
||||
mp::client_t* client;
|
||||
int j, len;
|
||||
va_list va;
|
||||
|
||||
const auto server_command_buf_large = std::make_unique<char[]>(0x20000);
|
||||
|
||||
va_start(va, fmt);
|
||||
len = vsnprintf_s(server_command_buf_large.get(), 0x20000, _TRUNCATE, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
assert(len >= 0);
|
||||
|
||||
if (cl)
|
||||
{
|
||||
SV_AddServerCommand(cl, type, server_command_buf_large.get());
|
||||
return;
|
||||
}
|
||||
|
||||
if (environment::is_dedi() && !std::strncmp(server_command_buf_large.get(), "print", 5))
|
||||
{
|
||||
console::info("broadcast: %s\n", SV_ExpandNewlines(server_command_buf_large.get()));
|
||||
}
|
||||
|
||||
const auto* sv_maxclients = Dvar_FindVar("sv_maxclients");
|
||||
for (j = 0, client = mp::svs_clients; j < sv_maxclients->current.integer; j++, client++)
|
||||
{
|
||||
if (client->header.state < mp::CS_CLIENTLOADING)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SV_AddServerCommand(client, type, server_command_buf_large.get());
|
||||
}
|
||||
}
|
||||
|
||||
void SV_GameSendServerCommand(char clientNum, svscmd_type type, const char* text)
|
||||
{
|
||||
[[maybe_unused]] const auto* sv_maxclients = Dvar_FindVar("sv_maxclients");
|
||||
|
||||
if (clientNum == -1)
|
||||
{
|
||||
SV_SendServerCommand(nullptr, type, "%s", text);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(sv_maxclients->current.integer >= 1 && sv_maxclients->current.integer <= 18);
|
||||
assert(static_cast<unsigned>(clientNum) < sv_maxclients->current.unsignedInt);
|
||||
SV_SendServerCommand(&mp::svs_clients[clientNum], type, "%s", text);
|
||||
}
|
||||
}
|
7
src/client/game/engine/sv_game.hpp
Normal file
7
src/client/game/engine/sv_game.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace game::engine
|
||||
{
|
||||
void SV_SendServerCommand(mp::client_t* cl, svscmd_type type, const char* fmt, ...);
|
||||
void SV_GameSendServerCommand(char clientNum, svscmd_type type, const char* text);
|
||||
}
|
@ -855,10 +855,11 @@ namespace game
|
||||
int readcount;
|
||||
int bit;
|
||||
int lastEntityRef;
|
||||
netsrc_t targetLocalNetID;
|
||||
int useZlib;
|
||||
};
|
||||
|
||||
static_assert(sizeof(msg_t) == 0x38);
|
||||
|
||||
enum errorParm
|
||||
{
|
||||
ERR_FATAL = 0,
|
||||
@ -1416,8 +1417,44 @@ namespace game
|
||||
|
||||
static_assert(sizeof(pml_t) == 0x130);
|
||||
|
||||
struct netProfilePacket_t
|
||||
{
|
||||
int iTime;
|
||||
int iSize;
|
||||
int bFragment;
|
||||
};
|
||||
|
||||
struct netProfileStream_t
|
||||
{
|
||||
netProfilePacket_t packets[60];
|
||||
int iCurrPacket;
|
||||
int iBytesPerSecond;
|
||||
int iLastBPSCalcTime;
|
||||
int iCountedPackets;
|
||||
int iCountedFragments;
|
||||
int iFragmentPercentage;
|
||||
int iLargestPacket;
|
||||
int iSmallestPacket;
|
||||
};
|
||||
|
||||
struct netProfileInfo_t
|
||||
{
|
||||
netProfileStream_t send;
|
||||
netProfileStream_t recieve;
|
||||
};
|
||||
|
||||
namespace mp
|
||||
{
|
||||
enum
|
||||
{
|
||||
CS_FREE = 0x0,
|
||||
CS_ZOMBIE = 0x1,
|
||||
CS_RECONNECTING = 0x2,
|
||||
CS_CONNECTED = 0x3,
|
||||
CS_CLIENTLOADING = 0x4,
|
||||
CS_ACTIVE = 0x5,
|
||||
};
|
||||
|
||||
struct cachedSnapshot_t
|
||||
{
|
||||
int archivedFrame;
|
||||
@ -1470,33 +1507,141 @@ namespace game
|
||||
{
|
||||
};
|
||||
|
||||
struct netchan_t
|
||||
{
|
||||
int outgoingSequence;
|
||||
netsrc_t sock;
|
||||
int dropped;
|
||||
int incomingSequence;
|
||||
netadr_s remoteAddress;
|
||||
int fragmentSequence;
|
||||
int fragmentLength;
|
||||
char* fragmentBuffer;
|
||||
int fragmentBufferSize;
|
||||
int unsentFragments;
|
||||
int unsentFragmentStart;
|
||||
int unsentLength;
|
||||
char* unsentBuffer;
|
||||
int unsentBufferSize;
|
||||
netProfileInfo_t prof;
|
||||
};
|
||||
|
||||
struct clientHeader_t
|
||||
{
|
||||
int state;
|
||||
char __pad0[36];
|
||||
netadr_s remoteAddress;
|
||||
}; // size = ?
|
||||
int sendAsActive;
|
||||
int deltaMessage;
|
||||
int rateDelayed;
|
||||
int hasAckedBaselineData;
|
||||
int hugeSnapshotSent;
|
||||
netchan_t netchan;
|
||||
float predictedOrigin[3];
|
||||
int predictedOriginServerTime;
|
||||
int migrationState;
|
||||
unsigned int predictedVehicleSplineId;
|
||||
int predictedVehicleTargetEntity;
|
||||
float predictedVehicleOrigin[3];
|
||||
int predictedVehicleServerTime;
|
||||
int ackedMessage[32];
|
||||
unsigned int ackedMessageCount;
|
||||
int sentMessage[32];
|
||||
int wasKillcam[32];
|
||||
unsigned int sendMessageCount;
|
||||
bool overrideDeltaMessage;
|
||||
int overrideSequenceNumber;
|
||||
int sequenceResume;
|
||||
int isInKillcam;
|
||||
};
|
||||
|
||||
struct svscmd_info_t
|
||||
{
|
||||
int time;
|
||||
int type;
|
||||
char cmd[1024];
|
||||
};
|
||||
|
||||
static_assert(sizeof(svscmd_info_t) == 0x408);
|
||||
|
||||
struct client_net_buffers_t
|
||||
{
|
||||
svscmd_info_t reliableCommandInfo[128];
|
||||
char netchanOutgoingBuffer[131072];
|
||||
char netchanIncomingBuffer[2048];
|
||||
};
|
||||
|
||||
struct usercmd_s
|
||||
{
|
||||
int serverTime;
|
||||
unsigned int buttons;
|
||||
int angles[3];
|
||||
Weapon weapon;
|
||||
Weapon offHand;
|
||||
char forwardmove;
|
||||
char rightmove;
|
||||
unsigned __int16 airburstMarkDistance;
|
||||
__int16 meleeChargeEnt;
|
||||
unsigned __int8 meleeChargeDist;
|
||||
char selectedLoc[2];
|
||||
unsigned __int8 selectedLocAngle;
|
||||
char remoteControlAngles[2];
|
||||
char remoteControlMove[3];
|
||||
unsigned int sightedClientsMask;
|
||||
unsigned __int16 spawnTraceEntIndex;
|
||||
unsigned int sightedSpawnsMask[2];
|
||||
unsigned int partialSightedSpawnsMask[2];
|
||||
};
|
||||
|
||||
static_assert(sizeof(usercmd_s) == 0x44);
|
||||
|
||||
struct client_t
|
||||
{
|
||||
clientHeader_t header;
|
||||
char __pad0[3044];
|
||||
const char* dropReason;
|
||||
char userinfo[0x400];
|
||||
int reliableSequence;
|
||||
int reliableAcknowledge;
|
||||
char __pad1[265864];
|
||||
int reliableSent;
|
||||
int messageAcknowledge;
|
||||
int largeCommandSequence;
|
||||
int gamestateMessageNum;
|
||||
int challenge;
|
||||
client_net_buffers_t netBuf;
|
||||
int cumulThinkTime;
|
||||
int beginCmdIndex;
|
||||
int currCmdIndex;
|
||||
usercmd_s lastUsercmd;
|
||||
usercmd_s cmds[8];
|
||||
int lastClientCommand;
|
||||
gentity_s* gentity; // 268976
|
||||
char name[32]; // 268984
|
||||
char __pad2[8];
|
||||
char name[32];
|
||||
int lastPacketTime;
|
||||
int lastConnectTime;
|
||||
int nextSnapshotTime; // 269024
|
||||
char __pad3[544];
|
||||
char __pad3[532];
|
||||
int pureAuthentic;
|
||||
unsigned int streamSyncWaitBits;
|
||||
unsigned int streamSyncWaitTimeout;
|
||||
LiveClientDropType liveDropRequest; // 269572
|
||||
char __pad4[24];
|
||||
TestClientType testClient; // 269600
|
||||
char __pad5[391700];
|
||||
}; // size = 661304
|
||||
|
||||
static_assert(offsetof(client_t, header.netchan.unsentFragments) == 0x54);
|
||||
static_assert(offsetof(client_t, header.migrationState) == 0x660);
|
||||
static_assert(offsetof(client_t, userinfo) == 0x820);
|
||||
static_assert(offsetof(client_t, reliableSequence) == 0xC20);
|
||||
static_assert(offsetof(client_t, reliableAcknowledge) == 0xC24);
|
||||
static_assert(offsetof(client_t, reliableSent) == 0xC28);
|
||||
static_assert(offsetof(client_t, messageAcknowledge) == 0xC2C);
|
||||
static_assert(offsetof(client_t, largeCommandSequence) == 0xC30);
|
||||
static_assert(offsetof(client_t, lastUsercmd) == 0x41848);
|
||||
static_assert(offsetof(client_t, lastClientCommand) == 0x41AAC);
|
||||
static_assert(offsetof(client_t, gentity) == 0x41AB0);
|
||||
static_assert(offsetof(client_t, name) == 0x41AB8);
|
||||
static_assert(offsetof(client_t, lastPacketTime) == 0x41AD8);
|
||||
static_assert(offsetof(client_t, nextSnapshotTime) == 0x41AE0);
|
||||
static_assert(offsetof(client_t, pureAuthentic) == 0x41CF8);
|
||||
static_assert(offsetof(client_t, liveDropRequest) == 0x41D04);
|
||||
static_assert(offsetof(client_t, testClient) == 0x41D20);
|
||||
static_assert(sizeof(client_t) == 0xA1738);
|
||||
@ -1508,7 +1653,9 @@ namespace game
|
||||
{
|
||||
char __pad[56135];
|
||||
int flags; // 56136
|
||||
};
|
||||
}; // Incomplete
|
||||
|
||||
static_assert(offsetof(gclient_s, flags) == 56136);
|
||||
|
||||
struct gentity_s
|
||||
{
|
||||
|
@ -184,7 +184,7 @@ namespace game
|
||||
WEAK symbol<void(mp::client_t* client)> SV_DropClient{0, 0x140438A30};
|
||||
WEAK symbol<void(mp::client_t*, const char*, int)> SV_ExecuteClientCommand{0, 0x15121D8E6};
|
||||
WEAK symbol<void(int localClientNum)> SV_FastRestart{0, 0x1404374E0};
|
||||
WEAK symbol<void(int clientNum, svscmd_type type, const char* text)> SV_GameSendServerCommand{0x1403F3A70, 0x14043E120};
|
||||
WEAK symbol<int(mp::client_t* client, const unsigned char* cmd, int cmdSize)> SV_CanReplaceServerCommand{0x0, 0x140441A00};
|
||||
WEAK symbol<const char*(int clientNum)> SV_GetGuid{0, 0x14043E1E0};
|
||||
WEAK symbol<int(int clientNum)> SV_GetClientPing{0, 0x14043E1C0};
|
||||
WEAK symbol<playerState_s*(int num)> SV_GetPlayerstateForClientNum{0x1403F3AB0, 0x14043E260};
|
||||
@ -221,6 +221,8 @@ namespace game
|
||||
|
||||
WEAK symbol<void(char* dest, const char* src, int destsize)> I_strncpyz{0x1403793B0, 0x1404C9E60};
|
||||
|
||||
WEAK symbol<void(const char* pszCommand, char* pszBuffer, int iBufferSize)> MSG_WriteReliableCommandToBuffer{0x0, 0x1403E1090};
|
||||
|
||||
WEAK symbol<void*(jmp_buf* Buf, int Value)> longjmp{0x14059C5C0, 0x1406FD930};
|
||||
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x14059CD00, 0x1406FE070};
|
||||
|
||||
|
Reference in New Issue
Block a user