2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-28 06:28:06 +03:00

HLTV: Refactoring and fixes (#469)

This commit is contained in:
Dmitry Novikov 2017-05-11 23:11:16 +03:00 committed by GitHub
parent 96a8033de9
commit 49483d3b05
33 changed files with 261 additions and 179 deletions

View File

@ -412,7 +412,7 @@ bool BSPModel::InPVS(vec_t *point)
void BSPModel::Clear()
{
#define FREE_FIELD(field) if (field) { free(field); }
#define FREE_FIELD(field) if (field) { Mem_Free(field); }
FREE_FIELD(m_model.leafs);
FREE_FIELD(m_model.nodes);
FREE_FIELD(m_model.planes);
@ -833,28 +833,25 @@ void BSPModel::LoadEntities(lump_t *l)
m_model.entities = (char *)Mem_ZeroMalloc(l->filelen);
memcpy(m_model.entities, (const void *)(m_base + l->fileofs), l->filelen);
if (m_model.entities)
char *pszInputStream = COM_Parse(m_model.entities);
if (*pszInputStream)
{
char *pszInputStream = COM_Parse(m_model.entities);
if (*pszInputStream)
while (com_token[0] != '}')
{
while (com_token[0] != '}')
if (!strcmp(com_token, "wad"))
{
if (!strcmp(com_token, "wad"))
{
COM_Parse(pszInputStream);
if (m_wadpath) {
free(m_wadpath);
}
m_wadpath = _strdup(com_token);
return;
COM_Parse(pszInputStream);
if (m_wadpath) {
Mem_Free(m_wadpath);
}
pszInputStream = COM_Parse(pszInputStream);
if (!*pszInputStream)
return;
m_wadpath = _strdup(com_token);
return;
}
pszInputStream = COM_Parse(pszInputStream);
if (!*pszInputStream)
return;
}
}
}

View File

@ -1013,8 +1013,8 @@ void Delta::ClearEncoders()
while (p)
{
n = p->next;
free(p->name);
free(p);
Mem_Free(p->name);
Mem_Free(p);
p = n;
}
@ -1070,7 +1070,7 @@ void Delta::ClearLinks(delta_link_t **plinks)
while (p)
{
n = p->next;
free(p);
Mem_Free(p);
p = n;
}
*plinks = 0;
@ -1097,13 +1097,13 @@ delta_t *Delta::BuildFromLinks(delta_link_t **pplinks)
for (p = *pplinks, pcur = pdesc; p; p = p->next, pcur++)
{
memcpy(pcur, p->delta, sizeof(delta_description_t));
free(p->delta);
Mem_Free(p->delta);
p->delta = 0;
}
ClearLinks(pplinks);
pdelta->dynamic = 1;
pdelta->dynamic = TRUE;
pdelta->fieldCount = count;
pdelta->pdd = pdesc;
@ -1238,10 +1238,10 @@ void Delta::FreeDescription(delta_t **ppdesc)
if (ppdesc && *ppdesc)
{
if ((*ppdesc)->dynamic) {
free((*ppdesc)->pdd);
Mem_Free((*ppdesc)->pdd);
}
free(*ppdesc);
Mem_Free(*ppdesc);
*ppdesc = nullptr;
}
}
@ -1276,8 +1276,8 @@ void Delta::ClearDefinitions()
while (p)
{
n = p->next;
free(p->ptypename);
free(p);
Mem_Free(p->ptypename);
Mem_Free(p);
p = n;
}
@ -1456,7 +1456,7 @@ bool Delta::Load(char *name, delta_t **ppdesc, char *pszFile)
}
bool res = ParseDescription(name, ppdesc, pbuf);
free(pbuf);
Mem_Free(pbuf);
return res;
}
@ -1475,13 +1475,13 @@ void Delta::ClearRegistrations()
while (p)
{
n = p->next;
free(p->name);
Mem_Free(p->name);
if (p->pdesc) {
FreeDescription(&p->pdesc);
}
free(p);
Mem_Free(p);
p = n;
}

View File

@ -28,6 +28,15 @@
#include "precompiled.h"
Network::Network()
{
m_NoDNS = false;
m_IsMultihomed = false;
m_FakeLoss = 0;
m_LastStatsUpdateTime = 0;
}
bool Network::Init(IBaseSystem *system, int serial, char *name)
{
BaseSystemModule::Init(system, serial, name);

View File

@ -82,7 +82,7 @@
class NetSocket;
class Network: public BaseSystemModule, public INetwork {
public:
Network() {}
Network();
virtual ~Network() {}
bool Init(IBaseSystem *system, int serial, char *name);

View File

@ -108,7 +108,7 @@ bool Server::Init(IBaseSystem *system, int serial, char *name)
m_DelayReconnect = true;
m_Protocol = PROTOCOL_VERSION;
m_UserInfo.SetMaxSize(256);
m_UserInfo.SetMaxSize(MAX_INFO_STRING);
m_UserInfo.SetValueForKey("name", "HLTV Proxy");
m_UserInfo.SetValueForKey("cl_lw", "1");
m_UserInfo.SetValueForKey("cl_lc", "1");
@ -119,6 +119,7 @@ bool Server::Init(IBaseSystem *system, int serial, char *name)
m_IsGameServer = false;
m_IsVoiceBlocking = false;
m_ServerSocket = nullptr;
m_ServerChannel.Create(system);
m_ServerInfo.SetMaxSize(512);
@ -227,6 +228,7 @@ void Server::ShutDown()
Disconnect();
m_ServerChannel.Close();
m_ReliableData.Free();
m_UnreliableData.Free();
m_VoiceData.Free();
@ -367,7 +369,7 @@ void Server::ProcessMessage(unsigned int seqNr)
{
if (m_Instream->IsOverflowed()) {
m_System->Printf("WARNING! Server::ProcessMessage: packet read overflow.\n");
return;
break;
}
int cmd = m_Instream->ReadByte();
@ -883,11 +885,11 @@ void Server::ParseSetView()
{
m_ReliableData.WriteByte(svc_setview);
m_ReliableData.WriteBuf(m_Instream->CurrentByte(), 2);
m_ReliableData.SkipBytes(2);
m_Instream->SkipBytes(2);
}
else
{
m_System->Errorf("Server::ParseAddAngle: unexpected server state.\n");
m_System->Errorf("Server::ParseSetView: unexpected server state.\n");
}
}
@ -938,8 +940,9 @@ void Server::ParseNewUserMsg()
iSize = -1;
}
char name[16];
m_Instream->ReadBuf(sizeof(name), name);
char name[17];
m_Instream->ReadBuf(sizeof(name) - 1, name);
name[sizeof(name) - 1] = '\0';
m_System->DPrintf("Adding user message:%s(%i).\n", name, iMsg);
m_World->AddUserMessage(iMsg, iSize, name);
@ -1323,7 +1326,7 @@ void Server::ParseFileTransferFailed()
return;
}
m_System->Printf("WARNING! Downloading \"%s\" failed.\n", name);
m_System->Printf("WARNING! Server::ParseFileTransferFailed: Downloading \"%s\" failed.\n", name);
}
void Server::ParseSignonNum()
@ -1378,12 +1381,12 @@ void Server::ParseCustomization()
resource->pNext = nullptr;
if (resource->ucFlags & RES_CUSTOM) {
m_Instream->ReadBuf(16, resource->rgucMD5_hash);
m_Instream->ReadBuf(sizeof(resource->rgucMD5_hash), resource->rgucMD5_hash);
}
resource->playernum = index;
m_System->DPrintf("Ignoring player customization (%s).\n", resource->szFileName);
free(resource);
Mem_Free(resource);
}
void Server::ClearFrame(bool completely)
@ -1422,7 +1425,7 @@ bool Server::ParseUserMessage(int cmd)
{
UserMsg *usermsg = m_World->GetUserMsg(cmd);
if (!usermsg) {
m_System->Printf("WARNING! Server::ProcessMessage: unknown user message (%i).\n", cmd);
m_System->Printf("WARNING! Server::ParseUserMessage: unknown user message (%i).\n", cmd);
return false;
}
@ -1539,7 +1542,7 @@ void Server::ParseSound()
m_Instream->StartBitMode();
vec3_t pos;
unsigned char *start = this->m_Instream->m_CurByte;
unsigned char *start = this->m_Instream->CurrentByte();
int field_mask = m_Instream->ReadBits(9);
if (field_mask & SND_FL_VOLUME) {
@ -1564,20 +1567,21 @@ void Server::ParseSound()
m_Instream->EndBitMode();
m_UnreliableData.WriteByte(6);
m_UnreliableData.WriteBuf(start, m_Instream->m_CurByte - start);
m_UnreliableData.WriteByte(svc_sound);
m_UnreliableData.WriteBuf(start, m_Instream->CurrentByte() - start);
}
void Server::ParseEvent()
{
m_Instream->StartBitMode();
m_Frame.events = m_Instream->m_CurByte;
m_Frame.events = m_Instream->CurrentByte();
m_Frame.eventnum = m_Instream->ReadBits(5);
for (unsigned int i = 0; i < m_Frame.eventnum; i++)
{
m_Instream->SkipBits(10);
if (m_Instream->ReadBit())
m_Instream->SkipBits(11);
@ -1594,10 +1598,10 @@ void Server::ParseEvent()
void Server::ParseStopSound()
{
int i = m_Instream->ReadShort();
int entityIndex = m_Instream->ReadShort();
m_UnreliableData.WriteByte(svc_stopsound);
m_UnreliableData.WriteShort(i);
m_UnreliableData.WriteShort(entityIndex);
}
void Server::ParsePings()
@ -2059,7 +2063,11 @@ void Server::ParseCenterPrint()
m_UnreliableData.WriteString(string);
}
else {
m_System->Errorf("Server::ParseStuffText: unexpected state.\n");
m_System->Errorf("Server::ParseCenterPrint: unexpected state.\n");
}
if (string[0]) {
m_System->DPrintf(">>%s\n", string);
}
}
@ -2189,7 +2197,7 @@ void Server::ParseTimeScale()
{
m_System->Printf("Server::ParseTimeScale: invalid during signon.\n");
}
else if (m_ServerState == SERVER_RUNNING && m_ServerState == SERVER_INTERMISSION)
else if (m_ServerState == SERVER_RUNNING || m_ServerState == SERVER_INTERMISSION)
{
m_ReliableData.WriteByte(svc_timescale);
m_ReliableData.WriteFloat(timescale);

View File

@ -39,8 +39,8 @@ bool World::Init(IBaseSystem *system, int serial, char *name)
SetName(WORLD_INTERFACE_VERSION);
}
m_ClientUserMsgs = 0;
m_ResourcesList = 0;
m_ClientUserMsgs = nullptr;
m_ResourcesList = nullptr;
m_ResourcesNum = 0;
m_Protocol = PROTOCOL_VERSION;
@ -99,13 +99,13 @@ void World::ShutDown()
if (m_DeltaCache)
{
free(m_DeltaCache);
Mem_Free(m_DeltaCache);
m_DeltaCache = nullptr;
}
if (m_FrameCache)
{
free(m_FrameCache);
Mem_Free(m_FrameCache);
m_FrameCache = nullptr;
}
@ -161,7 +161,7 @@ void World::ClearUserMessages()
for (pList = m_ClientUserMsgs; pList; pList = pNext)
{
pNext = pList->next;
free(pList);
Mem_Free(pList);
}
m_ClientUserMsgs = nullptr;
@ -193,7 +193,7 @@ bool World::AddUserMessage(int msgNumber, int size, char *name)
if (!bFound)
{
UserMsg *pumsg = (UserMsg *)malloc(sizeof(UserMsg));
UserMsg *pumsg = (UserMsg *)Mem_Malloc(sizeof(UserMsg));
memcpy(pumsg, &umsg, sizeof(*pumsg));
pumsg->next = m_ClientUserMsgs;
m_ClientUserMsgs = pumsg;
@ -258,7 +258,7 @@ void World::ClearResources()
resource_t *res, *next;
for (res = m_ResourcesList; res; res = next) {
next = res->pNext;
free(res);
Mem_Free(res);
}
m_ResourcesList = nullptr;
@ -755,7 +755,7 @@ int World::AddFrame(frame_t *newFrame)
maxFrameSize += sizeof(demo_info_t);
}
pdata = (unsigned char *)malloc(maxFrameSize);
pdata = (unsigned char *)Mem_ZeroMalloc(maxFrameSize);
currentFrame->data = pdata;
currentFrame->delta = -1;
@ -1446,7 +1446,7 @@ bool World::AddSignonData(unsigned char type, unsigned char *data, int size)
m_SignonData.WriteByte(type);
m_SignonData.WriteBuf(data, size);
return m_SignonData.m_Overflowed;
return m_SignonData.IsOverflowed();
}
int World::FindUserMsgByName(char *name)
@ -1742,10 +1742,10 @@ int World::RemoveFrames(unsigned int startSeqNr, unsigned int endSeqNr)
m_FramesByTime.Remove(frame);
if (frame->data) {
free(frame->data);
Mem_Free(frame->data);
}
free(frame);
Mem_Free(frame);
frame = (frame_t *)m_Frames.FindExactKey(++nextseqnr);
}
@ -1787,10 +1787,10 @@ void World::ClearFrames()
while (frame)
{
if (frame->data) {
free(frame->data);
Mem_Free(frame->data);
}
free(frame);
Mem_Free(frame);
frame = (frame_t *)m_Frames.GetNext();
}
@ -1910,7 +1910,6 @@ void World::ParseDeltaDescription(BitBuffer *stream)
char szDesc[256];
strcopy(szDesc, s);
m_System->DPrintf("Reading delta description for: %s.\n", s);
delta_t **ppdelta = m_Delta.LookupRegistration(szDesc);
@ -1924,7 +1923,7 @@ void World::ParseDeltaDescription(BitBuffer *stream)
*ppdelta = (delta_t *)Mem_ZeroMalloc(sizeof(delta_t));
pdesc = (delta_description_t *)Mem_ZeroMalloc(sizeof(delta_description_t) * c);
(*ppdelta)->dynamic = 1;
(*ppdelta)->dynamic = TRUE;
(*ppdelta)->fieldCount = c;
for (int i = 0; i < c; i++) {
@ -2122,8 +2121,8 @@ bool World::SaveAsDemo(char *filename, IDirector *director)
}
m_WorldTime = frame->time;
demoChannel.Create(m_System, 0, 0);
demoFile.Init(this, 0, &demoChannel);
demoChannel.Create(m_System);
demoFile.Init(this, nullptr, &demoChannel);
if (!demoFile.StartRecording(filename)) {
return false;
@ -2171,6 +2170,8 @@ bool World::SaveAsDemo(char *filename, IDirector *director)
}
}
demoFile.CloseFile();
demoChannel.Clear();
return true;
}

View File

@ -894,7 +894,6 @@ bool DemoPlayer::LoadGame(char *filename)
m_LastClockUpdateTime = 0;
m_LastFrameTime = 0;
m_PlayerState = DEMOPLAYER_INITIALIZING;
m_LastFrameTime = 0;
m_MasterMode = true;
return true;
@ -953,9 +952,9 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
unsigned int cmd;
while ((cmd = stream->ReadByte()) != -1)
{
switch (cmd)
switch ((DemoCmd)cmd)
{
case DEM_STRING:
case DemoCmd::StringCmd:
{
char szCmdName[64];
stream->ReadBuf(sizeof(szCmdName), szCmdName);
@ -963,14 +962,14 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->Cbuf_AddText("\n");
break;
}
case DEM_CLIENTDATA:
case DemoCmd::ClientData:
{
client_data_t cdat;
stream->ReadBuf(sizeof(cdat), &cdat);
m_Engine->DemoUpdateClientData(&cdat);
break;
}
case DEM_EVENT:
case DemoCmd::Event:
{
int flags = _LittleLong(stream->ReadLong());
int idx = _LittleLong(stream->ReadLong());
@ -982,7 +981,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->CL_QueueEvent(flags, idx, delay, &eargs);
break;
}
case DEM_WEAPONANIM:
case DemoCmd::WeaponAnim:
{
int anim = _LittleLong(stream->ReadLong());
int body = _LittleLong(stream->ReadLong());
@ -990,7 +989,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->HudWeaponAnim(anim, body);
break;
}
case DEM_PLAYSOUND:
case DemoCmd::PlaySound:
{
int channel = stream->ReadLong();
int sampleSize = stream->ReadLong();
@ -1007,13 +1006,14 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->CL_DemoPlaySound(channel, sample, attenuation, volume, flags, pitch);
break;
}
case DEM_PAYLOAD:
case DemoCmd::PayLoad:
{
unsigned char data[32768];
memset(data, 0, sizeof(data));
int length = stream->ReadLong();
stream->ReadBuf(length, data);
m_Engine->ClientDLL_ReadDemoBuffer(length, data);
break;
}

View File

@ -28,6 +28,18 @@
#include "precompiled.h"
DemoClient::DemoClient()
{
m_Proxy = nullptr;
m_World = nullptr;
m_ClientDelta = 0;
m_LastFrameSeqNr = 0;
m_IsActive = false;
memset(m_BaseFileName, 0, sizeof(m_BaseFileName));
}
bool DemoClient::Init(IBaseSystem *system, int serial, char *name)
{
BaseSystemModule::Init(system, serial, name);

View File

@ -32,7 +32,7 @@
class DemoClient: public IClient, public BaseSystemModule {
public:
DemoClient() {}
DemoClient();
virtual ~DemoClient() {}
bool Init(IBaseSystem *system, int serial, char *name);

View File

@ -28,6 +28,14 @@
#include "precompiled.h"
FakeClient::FakeClient()
{
m_Network = nullptr;
m_World = nullptr;
m_Server = nullptr;
m_Socket = nullptr;
}
bool FakeClient::Init(IBaseSystem *system, int serial, char *name)
{
BaseSystemModule::Init(system, serial, name);

View File

@ -37,7 +37,7 @@ class INetSocket;
class FakeClient: public BaseSystemModule {
public:
FakeClient() {}
FakeClient();
virtual ~FakeClient() {}
bool Init(IBaseSystem *system, int serial, char *name);

View File

@ -43,10 +43,16 @@ Master::GameToAppIDMapItem_t Master::m_GameToAppIDMap[] =
{ GAME_APPID_CSTRIKE_BETA, "cstrike_beta" }
};
Master::Master() :
m_flMasterUpdateTime(0),
m_bSteamInitialized(false)
Master::Master()
{
m_Proxy = nullptr;
m_MasterSocket = nullptr;
m_NoMaster = false;
m_bMasterLoaded = false;
m_bSteamInitialized = false;
m_flMasterUpdateTime = 0;
}
int Master::GetGameAppID(const char *gamedir) const

View File

@ -198,8 +198,9 @@ bool Proxy::Init(IBaseSystem *system, int serial, char *name)
m_InfoString.Resize(2080);
m_NextInfoMessagesUpdate = 0;
m_RconAddress.Clear();
// Clear buffers
memset(&m_RconAddress, 0, sizeof(m_RconAddress));
memset(m_RconPassword, 0, sizeof(m_RconPassword));
memset(m_AdminPassword, 0, sizeof(m_AdminPassword));
memset(m_ProxyPassword, 0, sizeof(m_ProxyPassword));
@ -389,7 +390,7 @@ void Proxy::CMD_Ping(char *cmdLine)
}
if (!to.m_Port) {
to.SetPort_(atoi("27015"));
to.SetPort(atoi("27015"));
}
m_Socket->OutOfBandPrintf(&to, "ping");
@ -469,7 +470,7 @@ void Proxy::ReplyConnect(NetAddress *to, int protocol, int challenge, char *prot
if (type == TYPE_CLIENT && m_DispatchMode != DISPATCH_OFF)
{
float ratio = m_Status.GetBestRelayProxy(&relayProxy);
float myRatio = m_Clients.CountElements() / m_MaxClients * 1.25f;
float myRatio = (float)(m_Clients.CountElements() / m_MaxClients) * 1.25f;
if (myRatio > 1) {
myRatio = 1;
}
@ -739,7 +740,7 @@ bool Proxy::WriteSignonData(int type, BitBuffer *stream)
stream->WriteString(COM_VarArgs("%s\n", m_SignonCommands));
}
float ex_interp = (1 / GetMaxUpdateRate()) + 0.05f;
float ex_interp = (float)(1 / GetMaxUpdateRate()) + 0.05f;
stream->WriteByte(svc_stufftext);
stream->WriteString(COM_VarArgs("ex_interp %.2f\n", ex_interp));
@ -946,7 +947,7 @@ void Proxy::CMD_Connect(char *cmdLine)
}
if (!address.m_Port) {
address.SetPort_(atoi("27015"));
address.SetPort(atoi("27015"));
}
Reset();
@ -1237,7 +1238,7 @@ void Proxy::CMD_RconAddress(char *cmdLine)
m_Network->ResolveAddress(params.GetToken(1), &m_RconAddress);
if (!m_RconAddress.m_Port) {
m_RconAddress.SetPort_(atoi("27015"));
m_RconAddress.SetPort(atoi("27015"));
}
}
@ -2027,7 +2028,7 @@ resource_t *Proxy::LoadResourceFromFile(char *fileName, resourcetype_t type)
}
m_System->Printf("WARNING! Failed to load resource file %s.\n", fileName);
free(newresource);
Mem_Free(newresource);
return nullptr;
}
@ -2041,7 +2042,7 @@ void Proxy::FreeResource(resource_t *resource)
m_System->FreeFile(resource->data);
}
free(resource);
Mem_Free(resource);
}
void Proxy::ClearResources()
@ -2169,7 +2170,7 @@ bool Proxy::IsBanned(NetAddress *adr)
while (bannedAdr)
{
if (adr->EqualBase(bannedAdr)) {
return bannedAdr != nullptr;
return true;
}
bannedAdr = (NetAddress *)m_BannList.GetNext();
@ -2249,13 +2250,13 @@ void Proxy::CMD_Bann(char *cmdLine)
if (!(m_Network->ResolveAddress(params.GetToken(1), adr)))
{
m_System->Printf("Couldn't resolve IP \x02%s\"\n", params.GetToken(1));
free(adr);
Mem_Free(adr);
return;
}
if (IsBanned(adr)) {
m_System->Printf("IP already banned.\n");
free(adr);
Mem_Free(adr);
return;
}

View File

@ -28,6 +28,16 @@
#include "precompiled.h"
ProxyClient::ProxyClient(IProxy *proxy)
{
m_Proxy = proxy;
m_ChatEnabled = false;
m_LastChatTime = 0;
m_LastCheerTime = 0;
m_NextDecalTime = 0;
}
void ProxyClient::ShutDown()
{
char *clientTypeString[] = { "Spectator", "Relay Proxy", "Director", "Commentator", "Fake Client" };

View File

@ -36,7 +36,7 @@ class IBaseSystem;
class ProxyClient: public BaseClient {
public:
ProxyClient(IProxy *proxy) : m_Proxy(proxy) {}
ProxyClient(IProxy *proxy);
virtual ~ProxyClient() {}
bool Init(IBaseSystem *system, int serial, char *name);

View File

@ -28,6 +28,17 @@
#include "precompiled.h"
Status::Status()
{
m_Proxy = nullptr;
m_NextUpdateTime = 0;
m_NumberOfProxies = 0;
m_NumberOfSlots = 0;
m_NumberOfSpectators = 0;
m_MaxNumberOfSpectators = 0;
}
bool Status::Init(IBaseSystem *system, int serial, char *name)
{
BaseSystemModule::Init(system, serial, name);
@ -259,7 +270,7 @@ void Status::GetLocalStats(int &proxies, int &slots, int &spectators)
if (m_SystemTime > proxy->time + 64)
{
m_Proxies.Remove(proxy);
free(proxy);
Mem_Free(proxy);
}
else
{

View File

@ -44,7 +44,7 @@ typedef struct proxyInfo_s {
class IProxy;
class Status: public BaseSystemModule {
public:
Status() {}
Status();
virtual ~Status() {}
bool Init(IBaseSystem *system, int serial, char *name);

View File

@ -560,7 +560,9 @@ void BaseClient::WriteDatagram(double time, frame_t *frame)
if (m_ClientChannel.m_unreliableStream.IsOverflowed()) {
m_System->DPrintf("Unreliable data stream overflow.\n");
m_ClientChannel.m_unreliableStream.Clear();
m_LastFrameSeqNr = 0;
// FIXME: V519 The 'm_LastFrameSeqNr' variable is assigned values twice successively.
// m_LastFrameSeqNr = 0;
}
m_LastFrameSeqNr = frame->seqnr;
@ -633,12 +635,13 @@ void BaseClient::ParseMove(NetPacket *packet)
void BaseClient::SetName(char *newName)
{
char temp[32];
char temp[1024];
COM_RemoveEvilChars(newName);
COM_TrimSpace(newName, temp);
if (strlen(temp) > sizeof(temp) - 1) {
temp[sizeof(temp) - 1] = '\0';
const int len = sizeof(m_ClientName);
if (strlen(temp) >= len) {
temp[len] = '\0';
}
if (!temp[0] || !_stricmp(temp, "console")) {

View File

@ -151,15 +151,16 @@ protected:
};
static clc_func_s m_ClientFuncs[];
enum { MAX_USER_INFO = 256, MAX_SCOREBOARD_NAME = 32 };
IWorld *m_World;
INetSocket *m_Socket;
NetChannel m_ClientChannel;
int m_ClientType;
int m_ClientState;
char m_ClientName[32];
char m_ClientName[MAX_SCOREBOARD_NAME];
enum { MAX_USER_INFO = 256 };
InfoString m_Userinfo;
unsigned int m_LastFrameSeqNr;
unsigned int m_DeltaFrameSeqNr;

View File

@ -162,7 +162,7 @@ void BitBuffer::Reset()
void BitBuffer::Free()
{
if (m_Data && m_OwnData) {
free(m_Data);
Mem_Free(m_Data);
}
m_Data = nullptr;

View File

@ -106,7 +106,7 @@ void DemoFile::CloseFile()
if (m_Entries)
{
free(m_Entries);
Mem_Free(m_Entries);
m_Entries = nullptr;
}
@ -423,7 +423,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
int msglen; // command length in bytes
unsigned char msgbuf[MAX_POSSIBLE_MSG];
float time;
unsigned char cmd;
DemoCmd cmd;
int frame;
int channel;
int sampleSize;
@ -432,18 +432,18 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
while (readNextCmd)
{
unsigned int curpos = m_FileSystem->Tell(m_FileHandle);
if (m_FileSystem->Read(&cmd, sizeof(unsigned char), m_FileHandle) != sizeof(unsigned char)) {
if (m_FileSystem->Read(&cmd, sizeof(cmd), m_FileHandle) != sizeof(cmd)) {
StopPlayBack();
return;
}
m_FileSystem->Read(&time, sizeof(float), m_FileHandle);
m_FileSystem->Read(&time, sizeof(time), m_FileHandle);
time = _LittleFloat(time);
m_FileSystem->Read(&frame, sizeof(int), m_FileHandle);
m_FileSystem->Read(&frame, sizeof(frame), m_FileHandle);
frame = _LittleLong(frame);
if (cmd && cmd != DEM_READ) {
if (cmd != DemoCmd::Unknown && cmd != DemoCmd::Read) {
m_nextReadTime = m_startTime + time;
}
@ -456,16 +456,16 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
switch (cmd)
{
case DEM_START_TIME:
case DemoCmd::StartTime:
m_startTime = (float)m_System->GetTime();
break;
case DEM_STRING:
case DemoCmd::StringCmd:
msglen = sizeof(char [64]);
break;
case DEM_CLIENTDATA:
case DemoCmd::ClientData:
msglen = sizeof(client_data_t);
break;
case DEM_READ:
case DemoCmd::Read:
{
if (++m_CurrentEntry >= m_EntryNumber) {
StopPlayBack();
@ -477,22 +477,22 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
}
break;
}
case DEM_EVENT:
case DemoCmd::Event:
msglen = sizeof(int) // flags
+ sizeof(int) // idx
+ sizeof(float) // delay
+ sizeof(event_args_t); // eargs
break;
case DEM_WEAPONANIM:
case DemoCmd::WeaponAnim:
msglen = sizeof(int) // anim
+ sizeof(int); // body
break;
case DEM_PLAYSOUND:
case DemoCmd::PlaySound:
{
m_FileSystem->Read(&channel, sizeof(int), m_FileHandle);
m_FileSystem->Read(&channel, sizeof(channel), m_FileHandle);
channel = _LittleLong(channel);
m_FileSystem->Read(&sampleSize, sizeof(int), m_FileHandle);
m_FileSystem->Read(&sampleSize, sizeof(sampleSize), m_FileHandle);
sampleSize = _LittleLong(sampleSize);
msglen = sampleSize
+ sizeof(float) // attenuation
@ -501,9 +501,9 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
+ sizeof(int); // pitch
break;
}
case DEM_PAYLOAD:
case DemoCmd::PayLoad:
{
m_FileSystem->Read(&msglen, sizeof(int), m_FileHandle);
m_FileSystem->Read(&msglen, sizeof(msglen), m_FileHandle);
msglen = _LittleLong(msglen);
break;
}
@ -516,15 +516,15 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
{
m_FileSystem->Read(msgbuf, msglen, m_FileHandle);
demoData->WriteByte(cmd);
demoData->WriteByte((unsigned char)cmd);
switch (cmd)
{
case DEM_PLAYSOUND:
case DemoCmd::PlaySound:
demoData->WriteLong(channel);
demoData->WriteLong(sampleSize);
break;
case DEM_PAYLOAD:
case DemoCmd::PayLoad:
demoData->WriteLong(msglen);
break;
}
@ -537,7 +537,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
ReadSequenceInfo();
int length;
if (m_FileSystem->Read(&length, sizeof(int), m_FileHandle) != sizeof(int)) {
if (m_FileSystem->Read(&length, sizeof(length), m_FileHandle) != sizeof(length)) {
m_System->DPrintf("WARNING! DemoFile::ReadDemoPacket: Bad demo length.\n");
StopPlayBack();
return;

View File

@ -46,21 +46,22 @@ const int DEMO_PROTOCOL = 5;
const int DEMO_STARTUP = 0; // this lump contains startup info needed to spawn into the server
const int DEMO_NORMAL = 1; // this lump contains playback info of messages, etc., needed during playback.
enum DemoCmd {
DEM_UNKNOWN = 0,
DEM_NOREWIND, // startup message
DEM_START_TIME,
DEM_STRING,
DEM_CLIENTDATA,
DEM_READ,
DEM_EVENT,
DEM_WEAPONANIM,
DEM_PLAYSOUND,
DEM_PAYLOAD
#undef PlaySound
enum class DemoCmd : unsigned char {
Unknown = 0,
NoRewind, // startup message
StartTime,
StringCmd,
ClientData,
Read,
Event,
WeaponAnim,
PlaySound,
PayLoad
};
typedef struct demoheader_s {
char szFileStamp[6];
char szFileStamp[8];
int nDemoProtocol; // should be DEMO_PROTOCOL
int nNetProtocolVersion; // should be PROTOCOL_VERSION
char szMapName[260]; // name of map

View File

@ -49,7 +49,8 @@ char *DirectorCmd::m_CMD_Name[] =
"WAYPOINTS"
};
DirectorCmd::DirectorCmd()
DirectorCmd::DirectorCmd() :
m_Size(0), m_Index(0)
{
Clear();
}

View File

@ -66,7 +66,7 @@ InfoString::InfoString(char *string)
InfoString::~InfoString()
{
if (m_String) {
free(m_String);
Mem_Free(m_String);
m_String = nullptr;
}
}
@ -100,7 +100,7 @@ void InfoString::SetMaxSize(unsigned int maxSize)
newBuffer[maxSize - 1] = '\0';
}
free(m_String);
Mem_Free(m_String);
}
m_MaxSize = maxSize;
@ -398,7 +398,7 @@ bool InfoString::SetValueForStarKey(const char *key, const char *value)
// Remove current key/value and return if we doesn't specified to set a value
RemoveKey(key);
if (!value || !strlen(value)) {
if (!strlen(value)) {
return true;
}

View File

@ -28,12 +28,12 @@
#include "precompiled.h"
NetAddress::NetAddress()
NetAddress::NetAddress() :
m_Port(0), m_IP(), m_String()
{
memset(this, 0, sizeof(NetAddress));
}
void NetAddress::SetPort_(int16 port)
void NetAddress::SetPort(int16 port)
{
m_Port = htons(port);
}

View File

@ -31,6 +31,8 @@
#include "netadr.h"
#include "BitBuffer.h"
#undef SetPort
class NetAddress {
public:
NetAddress();
@ -51,7 +53,7 @@ public:
bool Equal(NetAddress *a);
bool FromSockadr(struct sockaddr *s);
void ToSockadr(struct sockaddr *s);
void SetPort_(int16 port);
void SetPort(int16 port);
void ToStream(BitBuffer *stream);
void FromStream(BitBuffer *stream);

View File

@ -62,7 +62,7 @@ void NetChannel::UnlinkFragment(fragbuf_t *buf, int stream)
if (*list == buf)
{
*list = buf->next;
free(buf);
Mem_Free(buf);
return;
}
@ -72,7 +72,7 @@ void NetChannel::UnlinkFragment(fragbuf_t *buf, int stream)
if (search->next == buf)
{
search->next = buf->next;
free(buf);
Mem_Free(buf);
return;
}
@ -115,7 +115,7 @@ void NetChannel::ClearFragbufs(fragbuf_t **ppbuf)
while (buf)
{
n = buf->next;
free(buf);
Mem_Free(buf);
buf = n;
}
@ -132,7 +132,7 @@ void NetChannel::ClearFragments()
{
next = wait->next;
ClearFragbufs(&wait->fragbufs);
free(wait);
Mem_Free(wait);
wait = next;
}
m_waitlist[i] = nullptr;
@ -155,7 +155,7 @@ void NetChannel::FlushIncoming(int stream)
while (p)
{
n = p->next;
free(p);
Mem_Free(p);
p = n;
}
@ -203,7 +203,7 @@ void NetChannel::Clear()
if (m_tempBuffer)
{
free(m_tempBuffer);
Mem_Free(m_tempBuffer);
m_tempBuffer = nullptr;
}
@ -664,7 +664,7 @@ void NetChannel::ProcessIncoming(unsigned char *data, int size)
bool frag_message[MAX_STREAMS] = { false, false };
int frag_offset[MAX_STREAMS] = { 0, 0 };
int m_frag_length[MAX_STREAMS] = { 0, 0 };
int frag_length[MAX_STREAMS] = { 0, 0 };
bool message_contains_fragments;
int net_drop;
@ -718,7 +718,7 @@ void NetChannel::ProcessIncoming(unsigned char *data, int size)
frag_message[i] = true;
fragid[i] = message.ReadLong();
frag_offset[i] = message.ReadShort();
m_frag_length[i] = message.ReadShort();
frag_length[i] = message.ReadShort();
}
}
}
@ -801,8 +801,8 @@ void NetChannel::ProcessIncoming(unsigned char *data, int size)
pbuf = FindBufferById(&m_incomingbufs[i], fragid[i], true);
if (pbuf)
{
memcpy(pbuf->data, message.GetData() + message.CurrentSize() + frag_offset[i], m_frag_length[i]);
pbuf->size = m_frag_length[i];
memcpy(pbuf->data, message.GetData() + message.CurrentSize() + frag_offset[i], frag_length[i]);
pbuf->size = frag_length[i];
}
else
{
@ -815,15 +815,15 @@ void NetChannel::ProcessIncoming(unsigned char *data, int size)
// Rearrange incoming data to not have the frag stuff in the middle of it
int wpos = message.CurrentSize() + frag_offset[i];
int rpos = wpos + m_frag_length[i];
int rpos = wpos + frag_length[i];
memmove(message.GetData() + wpos, message.GetData() + rpos, message.GetMaxSize() - rpos);
message.m_MaxSize -= m_frag_length[i];
message.m_MaxSize -= frag_length[i];
for (j = i + 1; j < MAX_STREAMS; j++)
{
// fragments order already validated
frag_offset[j] -= m_frag_length[i];
frag_offset[j] -= frag_length[i];
}
}
}
@ -871,7 +871,7 @@ void NetChannel::FragSend()
m_fragbufcount[i] = wait->fragbufcount;
// Throw away wait list
free(wait);
Mem_Free(wait);
}
}
@ -974,7 +974,7 @@ bool NetChannel::CreateFragmentsFromBuffer(void *buffer, int size, int streamtyp
if (!buf)
{
m_System->Printf("NetChannel::CreateFragmentsFromBuffer:Couldn't allocate fragbuf_t\n");
free(wait);
Mem_Free(wait);
return false;
}
@ -1100,7 +1100,7 @@ void NetChannel::CopyNormalFragments()
n = p->next;
packet->data.WriteBuf(p->data, p->size);
free(p);
Mem_Free(p);
p = n;
}
@ -1257,7 +1257,7 @@ bool NetChannel::CopyFileFragments()
{
n = p->next;
filecontent.WriteBuf(p->data, p->size);
free(p);
Mem_Free(p);
p = n;
}

View File

@ -28,6 +28,17 @@
#include "precompiled.h"
BaseSystemModule::BaseSystemModule()
{
m_System = nullptr;
m_Serial = 0;
m_SystemTime = 0;
m_State = MODULE_UNDEFINED;
memset(m_Name, 0, sizeof(m_Name));
}
char *BaseSystemModule::GetName()
{
return m_Name;

View File

@ -36,7 +36,7 @@
class BaseSystemModule: virtual public ISystemModule {
public:
BaseSystemModule() : m_State(MODULE_UNDEFINED) {}
BaseSystemModule();
virtual ~BaseSystemModule() {}
virtual bool Init(IBaseSystem *system, int serial, char *name);

View File

@ -44,7 +44,7 @@ ObjectDictionary::ObjectDictionary()
ObjectDictionary::~ObjectDictionary()
{
if (m_entries) {
free(m_entries);
Mem_Free(m_entries);
}
}
@ -56,7 +56,7 @@ void ObjectDictionary::Clear(bool freeObjectssMemory)
{
void *obj = m_entries[i].object;
if (obj) {
free(obj);
Mem_Free(obj);
}
}
}
@ -177,7 +177,7 @@ bool ObjectDictionary::RemoveIndex(int index, bool freeObjectMemory)
entry_t *e2 = &m_entries[index + 1];
if (freeObjectMemory && e1->object)
free(e1->object);
Mem_Free(e1->object);
while (p != e1)
{
@ -281,7 +281,7 @@ bool ObjectDictionary::CheckSize()
if (newSize != m_maxSize)
{
entry_t *newEntries = (entry_t *)malloc(sizeof(entry_t) * newSize);
entry_t *newEntries = (entry_t *)Mem_Malloc(sizeof(entry_t) * newSize);
if (!newEntries)
return false;
@ -290,7 +290,7 @@ bool ObjectDictionary::CheckSize()
if (m_entries && m_size)
{
memcpy(newEntries, m_entries, sizeof(entry_t) * m_size);
free(m_entries);
Mem_Free(m_entries);
}
m_entries = newEntries;

View File

@ -84,7 +84,7 @@ void *ObjectList::RemoveHead()
if (m_tail == m_head)
m_tail = nullptr;
free(m_head);
Mem_Free(m_head);
m_head = newHead;
m_number--;
@ -140,7 +140,7 @@ void *ObjectList::RemoveTail()
if (m_head == m_tail)
m_head = nullptr;
free(m_tail);
Mem_Free(m_tail);
m_tail = newTail;
m_number--;
@ -189,9 +189,9 @@ void ObjectList::Clear(bool freeElementsMemory)
ne = e->next;
if (freeElementsMemory && e->object)
free(e->object);
Mem_Free(e->object);
free(e);
Mem_Free(e);
e = ne;
}
@ -214,7 +214,7 @@ bool ObjectList::Remove(void *object)
if (m_tail == e) m_tail = e->prev;
if (m_current == e) m_current= e->next;
free(e);
Mem_Free(e);
m_number--;
}

View File

@ -115,7 +115,7 @@ int StartVGUI()
// make sure we get the right version
adminFactory = Sys_GetFactory(g_hAdminServerModule);
g_pAdminServer = (IAdminServer *)adminFactory(ADMINSERVER_INTERFACE_VERSION, nullptr);
g_pAdminVGuiModule = (IVGuiModule *)adminFactory("VGuiModuleAdminServer001", nullptr);
g_pAdminVGuiModule = (IVGuiModule *)adminFactory(VGUIMODULE_INTERFACE_VERSION, nullptr);
Assert(g_pAdminServer != nullptr);
Assert(g_pAdminVGuiModule != nullptr);
if (!g_pAdminServer || !g_pAdminVGuiModule)

View File

@ -959,8 +959,8 @@ void DELTA_ClearEncoders()
while (p)
{
n = p->next;
free(p->name);
free(p);
Mem_Free(p->name);
Mem_Free(p);
p = n;
}
@ -1016,7 +1016,7 @@ void DELTA_ClearLinks(delta_link_t **plinks)
while (p)
{
n = p->next;
free(p);
Mem_Free(p);
p = n;
}
*plinks = 0;
@ -1042,7 +1042,7 @@ delta_t *DELTA_BuildFromLinks(delta_link_t **pplinks)
for (p = *pplinks, pcur = pdesc; p; p = p->next, pcur++)
{
memcpy(pcur, p->delta, sizeof(delta_description_t));
free(p->delta);
Mem_Free(p->delta);
p->delta = nullptr;
}
@ -1178,10 +1178,10 @@ void DELTA_FreeDescription(delta_t **ppdesc)
if (ppdesc && *ppdesc)
{
if ((*ppdesc)->dynamic) {
free((*ppdesc)->pdd);
Mem_Free((*ppdesc)->pdd);
}
free(*ppdesc);
Mem_Free(*ppdesc);
*ppdesc = nullptr;
}
}
@ -1216,8 +1216,8 @@ void DELTA_ClearDefinitions()
while (p)
{
n = p->next;
free(p->ptypename);
free(p);
Mem_Free(p->ptypename);
Mem_Free(p);
p = n;
}
@ -1402,13 +1402,13 @@ void DELTA_ClearRegistrations()
while (p)
{
n = p->next;
free(p->name);
Mem_Free(p->name);
if (p->pdesc) {
DELTA_FreeDescription(&p->pdesc);
}
free(p);
Mem_Free(p);
p = n;
}