2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-01-16 08:38:10 +03:00

HLTV: Some fixes and small refactoring. (#466)

* HLTV: Some fixes and small refactoring.
Update README.md
This commit is contained in:
Dmitry Novikov 2017-05-09 16:43:15 +03:00 committed by GitHub
parent 3c05dad7a7
commit 7432df957c
7 changed files with 78 additions and 59 deletions

View File

@ -35,6 +35,7 @@ void BSPModel::Init(IBaseSystem *system)
m_currentLeaf = nullptr; m_currentLeaf = nullptr;
m_base = nullptr; m_base = nullptr;
m_wadpath = nullptr; m_wadpath = nullptr;
m_IsMinimal = false;
memset(&m_model, 0, sizeof(m_model)); memset(&m_model, 0, sizeof(m_model));
memset(m_novis, 0xFF, sizeof(m_novis)); memset(m_novis, 0xFF, sizeof(m_novis));
@ -48,6 +49,7 @@ bool BSPModel::Load(const char *name, bool minimal)
return false; return false;
} }
m_IsMinimal = minimal;
return LoadFromBuffer(buffer, length, COM_SkipPath((char *)name)); return LoadFromBuffer(buffer, length, COM_SkipPath((char *)name));
} }
@ -411,7 +413,6 @@ bool BSPModel::InPVS(vec_t *point)
void BSPModel::Clear() void BSPModel::Clear()
{ {
#define FREE_FIELD(field) if (field) { free(field); } #define FREE_FIELD(field) if (field) { free(field); }
FREE_FIELD(m_model.leafs); FREE_FIELD(m_model.leafs);
FREE_FIELD(m_model.nodes); FREE_FIELD(m_model.nodes);
FREE_FIELD(m_model.planes); FREE_FIELD(m_model.planes);
@ -437,6 +438,7 @@ void BSPModel::Clear()
} }
FREE_FIELD(m_wadpath); FREE_FIELD(m_wadpath);
#undef FREE_FIELD
memset(&m_model, 0, sizeof(m_model)); memset(&m_model, 0, sizeof(m_model));

View File

@ -175,13 +175,13 @@ void Server::SetGameDirectory(const char *defaultDir, const char *gameDir)
if (gameDir && _stricmp(gameDir, defaultDir) != 0) if (gameDir && _stricmp(gameDir, defaultDir) != 0)
{ {
sprintf(temp, "%s/%s", GetBaseDir(), gameDir); sprintf(temp, "%s/%s", m_System->GetBaseDir(), gameDir);
m_FileSystem->AddSearchPath(temp, "GAME"); m_FileSystem->AddSearchPath(temp, "GAME");
} }
sprintf(temp, "%s/%s", GetBaseDir(), defaultDir); sprintf(temp, "%s/%s", m_System->GetBaseDir(), defaultDir);
m_FileSystem->AddSearchPath(temp, "DEFAULTGAME"); m_FileSystem->AddSearchPath(temp, "DEFAULTGAME");
m_FileSystem->AddSearchPath(GetBaseDir(), "ROOT"); m_FileSystem->AddSearchPath(m_System->GetBaseDir(), "ROOT");
} }
void Server::ExecuteCommand(int commandID, char *commandLine) void Server::ExecuteCommand(int commandID, char *commandLine)

View File

@ -955,7 +955,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
{ {
switch (cmd) switch (cmd)
{ {
case DEMO_STRINCMD: case DEM_STRING:
{ {
char szCmdName[64]; char szCmdName[64];
stream->ReadBuf(sizeof(szCmdName), szCmdName); stream->ReadBuf(sizeof(szCmdName), szCmdName);
@ -963,14 +963,14 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->Cbuf_AddText("\n"); m_Engine->Cbuf_AddText("\n");
break; break;
} }
case DEMO_CLIENTDATA: case DEM_CLIENTDATA:
{ {
client_data_t cdat; client_data_t cdat;
stream->ReadBuf(sizeof(cdat), &cdat); stream->ReadBuf(sizeof(cdat), &cdat);
m_Engine->DemoUpdateClientData(&cdat); m_Engine->DemoUpdateClientData(&cdat);
break; break;
} }
case DEMO_EVENT: case DEM_EVENT:
{ {
int flags = _LittleLong(stream->ReadLong()); int flags = _LittleLong(stream->ReadLong());
int idx = _LittleLong(stream->ReadLong()); int idx = _LittleLong(stream->ReadLong());
@ -982,7 +982,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->CL_QueueEvent(flags, idx, delay, &eargs); m_Engine->CL_QueueEvent(flags, idx, delay, &eargs);
break; break;
} }
case DEMO_WEAPONANIM: case DEM_WEAPONANIM:
{ {
int anim = _LittleLong(stream->ReadLong()); int anim = _LittleLong(stream->ReadLong());
int body = _LittleLong(stream->ReadLong()); int body = _LittleLong(stream->ReadLong());
@ -990,7 +990,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->HudWeaponAnim(anim, body); m_Engine->HudWeaponAnim(anim, body);
break; break;
} }
case DEMO_PLAYSOUND: case DEM_PLAYSOUND:
{ {
int channel = stream->ReadLong(); int channel = stream->ReadLong();
int sampleSize = stream->ReadLong(); int sampleSize = stream->ReadLong();
@ -1007,7 +1007,7 @@ void DemoPlayer::ExecuteDemoFileCommands(BitBuffer *stream)
m_Engine->CL_DemoPlaySound(channel, sample, attenuation, volume, flags, pitch); m_Engine->CL_DemoPlaySound(channel, sample, attenuation, volume, flags, pitch);
break; break;
} }
case DEMO_DATA: case DEM_PAYLOAD:
{ {
unsigned char data[32768]; unsigned char data[32768];
memset(data, 0, sizeof(data)); memset(data, 0, sizeof(data));

View File

@ -133,16 +133,6 @@ protected:
void WriteSpawn(BitBuffer *stream); void WriteSpawn(BitBuffer *stream);
void ReindexCommands(); void ReindexCommands();
void WriteCameraPath(DirectorCmd *, BitBuffer *stream); void WriteCameraPath(DirectorCmd *, BitBuffer *stream);
enum DemoCmds {
DEMO_STRINCMD = 3,
DEMO_CLIENTDATA = 4,
DEMO_EVENT = 6,
DEMO_WEAPONANIM = 7,
DEMO_PLAYSOUND = 8,
DEMO_DATA = 9
};
void ExecuteDemoFileCommands(BitBuffer *stream); void ExecuteDemoFileCommands(BitBuffer *stream);
private: private:

View File

@ -308,7 +308,7 @@ Lots of these commands are boolean switches, were 1 is meaning ON and 0 is respe
The console does auto-completion by hitting `TAB`. The console does auto-completion by hitting `TAB`.
All commands in the config file `hltv.cfg` are executed during startup. All commands in the config file `hltv.cfg` are executed during startup.
Some parameters can only be set in the command line: ### Command-line parameters
<pre> <pre>
-port <n> - sets the HLTV proxy port that spectators connect to (default "27020" ) -port <n> - sets the HLTV proxy port that spectators connect to (default "27020" )
-ip <IP> - forces the proxy to use this IP on a multihomed host -ip <IP> - forces the proxy to use this IP on a multihomed host

View File

@ -260,21 +260,21 @@ bool DemoFile::StartRecording(char *newName)
} }
memset(&m_demoHeader, 0, sizeof(m_demoHeader)); memset(&m_demoHeader, 0, sizeof(m_demoHeader));
strcopy(m_demoHeader.szFileStamp, "HLDEMO"); strcpy(m_demoHeader.szFileStamp, "HLDEMO");
COM_FileBase(m_World->GetLevelName(), m_demoHeader.szMapName); COM_FileBase(m_World->GetLevelName(), m_demoHeader.szMapName);
COM_FileBase(m_World->GetGameDir(), m_demoHeader.szDllDir); COM_FileBase(m_World->GetGameDir(), m_demoHeader.szDllDir);
m_demoHeader.mapCRC = 0; m_demoHeader.mapCRC = 0;
m_demoHeader.nDemoProtocol = DEMO_VERSION; m_demoHeader.nDemoProtocol = DEMO_PROTOCOL;
m_demoHeader.nNetProtocolVersion = PROTOCOL_VERSION; m_demoHeader.nNetProtocolVersion = PROTOCOL_VERSION;
m_demoHeader.nDirectoryOffset = 0; m_demoHeader.nDirectoryOffset = 0;
m_FileSystem->Write(&m_demoHeader, sizeof(m_demoHeader), m_FileHandle); m_FileSystem->Write(&m_demoHeader, sizeof(m_demoHeader), m_FileHandle);
memset(&m_loadEntry, 0, sizeof(m_loadEntry)); memset(&m_loadEntry, 0, sizeof(m_loadEntry));
strcopy(m_loadEntry.szDescription, "LOADING"); strcpy(m_loadEntry.szDescription, "LOADING");
m_loadEntry.nEntryType = 0; m_loadEntry.nEntryType = DEMO_STARTUP;
m_loadEntry.nOffset = m_FileSystem->Tell(m_FileHandle); m_loadEntry.nOffset = m_FileSystem->Tell(m_FileHandle);
m_frameCount = 0; m_frameCount = 0;
@ -295,7 +295,8 @@ bool DemoFile::StartRecording(char *newName)
memset(&m_gameEntry, 0, sizeof(m_gameEntry)); memset(&m_gameEntry, 0, sizeof(m_gameEntry));
_snprintf(m_gameEntry.szDescription, sizeof(m_gameEntry.szDescription), "Playback"); _snprintf(m_gameEntry.szDescription, sizeof(m_gameEntry.szDescription), "Playback");
m_gameEntry.nEntryType = 1;
m_gameEntry.nEntryType = DEMO_NORMAL;
m_gameEntry.nOffset = m_FileSystem->Tell(m_FileHandle); m_gameEntry.nOffset = m_FileSystem->Tell(m_FileHandle);
b = 2; b = 2;
@ -353,7 +354,7 @@ bool DemoFile::LoadDemo(char *demoname)
return false; return false;
} }
if (m_demoHeader.nNetProtocolVersion != PROTOCOL_VERSION || m_demoHeader.nDemoProtocol != DEMO_VERSION) { if (m_demoHeader.nNetProtocolVersion != PROTOCOL_VERSION || m_demoHeader.nDemoProtocol != DEMO_PROTOCOL) {
m_System->Printf("WARNING! %s has an outdated demo format.\n", m_FileName); m_System->Printf("WARNING! %s has an outdated demo format.\n", m_FileName);
} }
@ -419,7 +420,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
return; return;
} }
int msglen; int msglen; // command length in bytes
unsigned char msgbuf[MAX_POSSIBLE_MSG]; unsigned char msgbuf[MAX_POSSIBLE_MSG];
float time; float time;
unsigned char cmd; unsigned char cmd;
@ -431,7 +432,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
while (readNextCmd) while (readNextCmd)
{ {
unsigned int curpos = m_FileSystem->Tell(m_FileHandle); unsigned int curpos = m_FileSystem->Tell(m_FileHandle);
if (m_FileSystem->Read(&cmd, sizeof(unsigned char), m_FileHandle) != 1) { if (m_FileSystem->Read(&cmd, sizeof(unsigned char), m_FileHandle) != sizeof(unsigned char)) {
StopPlayBack(); StopPlayBack();
return; return;
} }
@ -442,7 +443,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
m_FileSystem->Read(&frame, sizeof(int), m_FileHandle); m_FileSystem->Read(&frame, sizeof(int), m_FileHandle);
frame = _LittleLong(frame); frame = _LittleLong(frame);
if (cmd && cmd != 5) { if (cmd && cmd != DEM_READ) {
m_nextReadTime = m_startTime + time; m_nextReadTime = m_startTime + time;
} }
@ -453,19 +454,18 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
msglen = 0; msglen = 0;
// TODO: Find out or guess the names of the opcode
switch (cmd) switch (cmd)
{ {
case 2: case DEM_START_TIME:
m_startTime = (float)m_System->GetTime(); m_startTime = (float)m_System->GetTime();
break; break;
case 3: case DEM_STRING:
msglen = 64; msglen = sizeof(char [64]);
break; break;
case 4: case DEM_CLIENTDATA:
msglen = 32; msglen = sizeof(client_data_t);
break; break;
case 5: case DEM_READ:
{ {
if (++m_CurrentEntry >= m_EntryNumber) { if (++m_CurrentEntry >= m_EntryNumber) {
StopPlayBack(); StopPlayBack();
@ -477,23 +477,31 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
} }
break; break;
} }
case 6: case DEM_EVENT:
msglen = 84; msglen = sizeof(int) // flags
+ sizeof(int) // idx
+ sizeof(float) // delay
+ sizeof(event_args_t); // eargs
break; break;
case 7: case DEM_WEAPONANIM:
msglen = 8; msglen = sizeof(int) // anim
+ sizeof(int); // body
break; break;
case 8: case DEM_PLAYSOUND:
{ {
m_FileSystem->Read(&channel, sizeof(int), m_FileHandle); m_FileSystem->Read(&channel, sizeof(int), m_FileHandle);
channel = _LittleLong(channel); channel = _LittleLong(channel);
m_FileSystem->Read(&sampleSize, sizeof(int), m_FileHandle); m_FileSystem->Read(&sampleSize, sizeof(int), m_FileHandle);
sampleSize = _LittleLong(sampleSize); sampleSize = _LittleLong(sampleSize);
msglen = sampleSize + 16; msglen = sampleSize
+ sizeof(float) // attenuation
+ sizeof(float) // volume
+ sizeof(int) // flags
+ sizeof(int); // pitch
break; break;
} }
case 9: case DEM_PAYLOAD:
{ {
m_FileSystem->Read(&msglen, sizeof(int), m_FileHandle); m_FileSystem->Read(&msglen, sizeof(int), m_FileHandle);
msglen = _LittleLong(msglen); msglen = _LittleLong(msglen);
@ -512,11 +520,11 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
switch (cmd) switch (cmd)
{ {
case 8: case DEM_PLAYSOUND:
demoData->WriteLong(channel); demoData->WriteLong(channel);
demoData->WriteLong(sampleSize); demoData->WriteLong(sampleSize);
break; break;
case 9: case DEM_PAYLOAD:
demoData->WriteLong(msglen); demoData->WriteLong(msglen);
break; break;
} }
@ -529,7 +537,7 @@ void DemoFile::ReadDemoPacket(BitBuffer *demoData, demo_info_t *demoInfo)
ReadSequenceInfo(); ReadSequenceInfo();
int length; int length;
if (m_FileSystem->Read(&length, sizeof(int), m_FileHandle) != 4) { if (m_FileSystem->Read(&length, sizeof(int), m_FileHandle) != sizeof(int)) {
m_System->DPrintf("WARNING! DemoFile::ReadDemoPacket: Bad demo length.\n"); m_System->DPrintf("WARNING! DemoFile::ReadDemoPacket: Bad demo length.\n");
StopPlayBack(); StopPlayBack();
return; return;

View File

@ -33,34 +33,52 @@
#include "usercmd.h" #include "usercmd.h"
#include "ref_params.h" #include "ref_params.h"
#include "event_args.h"
#include "common/ServerInfo.h" #include "common/ServerInfo.h"
#include "vmodes.h" #include "vmodes.h"
#include "cdll_int.h" #include "cdll_int.h"
#define DEMO_VERSION 5 const int MAX_DEMO_ENTRY = 92;
#define MAX_DEMO_ENTRY 92
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
};
typedef struct demoheader_s { typedef struct demoheader_s {
char szFileStamp[6]; char szFileStamp[6];
int nDemoProtocol; int nDemoProtocol; // should be DEMO_PROTOCOL
int nNetProtocolVersion; int nNetProtocolVersion; // should be PROTOCOL_VERSION
char szMapName[260]; char szMapName[260]; // name of map
char szDllDir[260]; char szDllDir[260]; // name of game directory
CRC32_t mapCRC; CRC32_t mapCRC;
int nDirectoryOffset; int nDirectoryOffset; // offset of Entry Directory.
} demoheader_t; } demoheader_t;
typedef struct demoentry_s { typedef struct demoentry_s {
int nEntryType; int nEntryType; // DEMO_STARTUP or DEMO_NORMAL
char szDescription[64]; char szDescription[64];
int nFlags; int nFlags;
int nCDTrack; int nCDTrack;
float fTrackTime; float fTrackTime; // time of track
int nFrames; int nFrames; // # of frames in track
int nOffset; int nOffset; // file offset of track data
int nFileLength; int nFileLength; // length of track
} demoentry_t; } demoentry_t;
typedef struct demo_info_s { typedef struct demo_info_s {
@ -110,6 +128,7 @@ private:
DEMO_PLAYING, DEMO_PLAYING,
DEMO_RECORDING DEMO_RECORDING
}; };
int m_DemoState; int m_DemoState;
unsigned int m_frameCount; unsigned int m_frameCount;
FileHandle_t m_FileHandle; FileHandle_t m_FileHandle;