Skip to content

Commit

Permalink
Merge pull request #115 from BranDougherty/small-misc-fixes
Browse files Browse the repository at this point in the history
Small misc fixes #1
  • Loading branch information
BranDougherty committed Jul 24, 2022
2 parents 41a9f28 + f9f3c91 commit a3aae37
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/opensoldat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
mkdir build
cd build
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opt/openssl@1.1/lib/pkgconfig
cmake -DCMAKE_INSTALL_PREFIX=./opensoldat -DOPENSSL_ROOT_DIR=$(brew --prefix openssl@1.1) ..
cmake -DCMAKE_INSTALL_PREFIX=./opensoldat -DOPENSSL_ROOT_DIR=$(brew --prefix openssl@1.1) .. -DCMAKE_BUILD_TYPE="Release"
make
make install
Expand Down
33 changes: 14 additions & 19 deletions client/Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,11 @@ procedure StartGame();
BasePathSDL := SDL_GetBasePath();

CvarInit();

InitClientCommands();

ParseCommandLine();

// NOTE: fs_basepath, fs_userpath and fs_portable must be set from command
// line, not in client.cfg.
if fs_portable.Value then
begin
UserDirectory := BasePathSDL;
Expand All @@ -606,7 +606,8 @@ procedure StartGame();
Debug('[FS] UserDirectory: ' + UserDirectory);
Debug('[FS] BaseDirectory: ' + BaseDirectory);

// Create the basic folder structure
// Now that we have UserDirectory and BaseDirectory set, we can create the
// basic directory structure and unpack the necessary config files.
CreateDirIfMissing(UserDirectory + '/configs');
CreateDirIfMissing(UserDirectory + '/screens');
CreateDirIfMissing(UserDirectory + '/demos');
Expand All @@ -615,17 +616,15 @@ procedure StartGame();
CreateDirIfMissing(UserDirectory + '/maps');
CreateDirIfMissing(UserDirectory + '/mods');

NewLogFiles;
PHYSFS_CopyFileFromArchive('configs/client.cfg', UserDirectory + '/configs/client.cfg');
PHYSFS_CopyFileFromArchive('configs/taunts.cfg', UserDirectory + '/configs/taunts.cfg');

MainConsole.CountMax := Round(15 * _rscala.y);
MainConsole.ScrollTickMax := 150;
MainConsole.NewMessageWait := 150;
MainConsole.AlphaCount := 255;
MainConsole.Count := 0;
MainConsole.CountMax := Round(ui_console_length.Value * _rscala.y);
LoadConfig('client.cfg');

if MainConsole.CountMax > 254 then
MainConsole.CountMax := 254;
// NOTE: Code depending on CVars should be run after this line if possible.
CvarsInitialized := True;

NewLogFiles;

// TODO remove HWIDs, replace by Fae auth tickets
HWID := '00000000000';
Expand Down Expand Up @@ -711,13 +710,6 @@ procedure StartGame();

LoadInterfaceArchives(UserDirectory + 'custom-interfaces/');

PHYSFS_CopyFileFromArchive('configs/client.cfg', UserDirectory + '/configs/client.cfg');
PHYSFS_CopyFileFromArchive('configs/taunts.cfg', UserDirectory + '/configs/taunts.cfg');

LoadConfig('client.cfg');

CvarsInitialized := True;

// these might change so keep a backup to avoid changing the settings file
ScreenWidth := r_screenwidth.Value;
ScreenHeight := r_screenheight.Value;
Expand Down Expand Up @@ -972,6 +964,9 @@ procedure ShutDown;

WriteLogFile(GameLog, ConsoleLogFileName);

CommandCleanup();
CvarCleanup();

Halt(0);
end;

Expand Down
5 changes: 5 additions & 0 deletions server/Server.pas
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@ procedure ShutDown;
GameNetworkingSockets_Kill();
{$ENDIF}

FreeAndNil(DummyPlayer);

AddLineToLogFile(GameLog, 'PhysFS closing.', ConsoleLogFileName);
PhysFS_deinit();

Expand All @@ -854,6 +856,9 @@ procedure ShutDown;
on e: Exception do
WriteLn('Error on SHUTDOWN during log writing: ' + e.Message);
end;

CommandCleanup();
CvarCleanup();
end;

function LoadMapsList(Filename: string = ''): Boolean;
Expand Down
4 changes: 2 additions & 2 deletions server/opensoldatserver.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{$IFDEF AUTOUPDATER}
StartAutoUpdater;
{$ENDIF}
RunServer;

DefaultSystemCodePage := CP_UTF8;

RunServer;
end.
20 changes: 7 additions & 13 deletions server/scriptcore/ScriptCoreInterface.pas
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ implementation
NetworkServerMessages, NetworkServerGame,
Server, Game, Calc, IniFiles, Sprites, fpmasks,
Math, ScriptDispatcher, Weapons, Things, Command, Bullets,
Constants, strutils, Version, RegExpr, Cvar, ServerHelper {$IFDEF RCON}, Rcon{$ENDIF};
TraceLog, Constants, strutils, Version, RegExpr, Cvar, ServerHelper {$IFDEF RCON}, Rcon{$ENDIF};

function ExistsFile(FileName: String): Boolean;
var
Expand Down Expand Up @@ -149,8 +149,7 @@ function SafeSplit(Source, Delimiter: String): TStringArray;
begin
Ret := Default(TStringArray);
Split := Default(TStringArray);
if log_level.Value = 3 then
WriteLn('|| Split();');
Trace('|| Split();');

Temp := Source;
Count := 0;
Expand Down Expand Up @@ -218,8 +217,7 @@ function ReadFile(FileName: String; UseEncryption: Boolean): String;
NumLines, NumLinesEnc: Integer;
begin
Result := '';
if log_level.Value = 3 then
WriteLn('|| ScriptCore.ReadFile(' + FileName + ');');
Trace('|| ScriptCore.ReadFile(' + FileName + ');');

Name := AnsiReplaceStr(FileName, '..', '');
assignfile(VarFile, UserDirectory + Name);
Expand Down Expand Up @@ -441,8 +439,7 @@ function AppendFile(FileName: String; Data: String): Boolean;
var
VarFile: TextFile;
begin
if log_level.Value = 3 then
WriteLn('|| ScriptCore.AppendFile(' + FileName + ');');
Trace('|| ScriptCore.AppendFile(' + FileName + ');');

FileName := AnsiReplaceStr(FileName, '..', '');
try
Expand Down Expand Up @@ -1040,8 +1037,7 @@ function WriteFile(FileName: String; SData: String): Boolean;
var
VarFile: TextFile;
begin
if log_level.Value = 3 then
WriteLn('|| ScriptCore.WriteFile(' + FileName + ');');
Trace('|| ScriptCore.WriteFile(' + FileName + ');');

FileName := AnsiReplaceStr(FileName, '..', '');
try
Expand Down Expand Up @@ -1101,8 +1097,7 @@ function SetVal(Script: TPSScript; Variable: String; Value: Integer): Boolean;
Result := False;
if not sc_enable.Value then
Exit;
// if log_level.Value = 3 then
// WriteLn('|| ScriptCore.SetVal('+Variable+', '+inttostr(Value)+');');
// Trace('|| ScriptCore.SetVal('+Variable+', '+inttostr(Value)+');');

VSetInt(Script.GetVariable(UpperCase(Variable)), Value);
Result := True;
Expand All @@ -1113,8 +1108,7 @@ function SetString(Script: TPSScript; Variable: String; Value: String): Boolean;
Result := False;
if not sc_enable.Value then
Exit;
// if log_level.Value = 3 then
// WriteLn('|| ScriptCore.SetString('+Variable+','+Value+');');
// Trace('|| ScriptCore.SetString('+Variable+','+Value+');');

VSetString(Script.GetVariable(UpperCase(Variable)), Value);
Result := True;
Expand Down
12 changes: 12 additions & 0 deletions shared/Command.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface
classes, contnrs, sysutils, variants, Constants;

procedure CommandInit();
procedure CommandCleanup();
function ParseInput(Input: String; Sender: Byte = 0): Boolean; overload;
function LoadConfig(ConfigName: AnsiString): Boolean;

Expand Down Expand Up @@ -644,4 +645,15 @@ procedure CommandInit();
{$ENDIF}
end;

procedure CommandCleanup();
var
i: Integer;
begin
FreeAndNil(DeferredCommands);
if Commands <> Nil then
for i := 0 to Commands.Count - 1 do
Dispose(PCommand(Commands[i]));
FreeAndNil(Commands);
end;

end.
16 changes: 15 additions & 1 deletion shared/Console.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ interface
end;

implementation
uses {$IFDEF SERVER}Server,{$ELSE}Client,{$ENDIF} Game, LogFile, sysutils {$IFDEF SERVER}, Net, NetworkServerMessages {$IFDEF RCON}, Rcon{$ENDIF}{$ENDIF};

uses
{$IFDEF SERVER}
Server,
Net,
NetworkServerMessages,
{$IFDEF RCON}Rcon,{$ENDIF}
{$ELSE}
Client,
TraceLog,
{$ENDIF}
Game,
LogFile,
SysUtils;

procedure TConsole.ScrollConsole;
var
Expand Down Expand Up @@ -119,6 +132,7 @@ procedure TConsole.Console(What: WideString; Col: Cardinal); overload;
if Count = CountMax then
ScrollConsole;
{$ELSE}
Debug('[Console] ' + AnsiString(What));
MainConsole.ConsoleAdd(What, Col);
BigConsole.ConsoleAdd(What, Col);
{$ENDIF}
Expand Down
62 changes: 43 additions & 19 deletions shared/Cvar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ TStringCvar = class(TCvar<AnsiString>)
end;

procedure CvarInit();
procedure CvarCleanup();
function DumpFlags(Cvar: TCvarBase): AnsiString;
procedure ResetSyncCvars;

Expand Down Expand Up @@ -195,6 +196,21 @@ function killlimitChange(Cvar: TStringCvar; NewValue: Integer): Boolean;
end;
{$ENDIF}

{$PUSH}
{$WARN 5024 OFF : Parameter "$1" not used}
function fs_portableChange(Cvar: TCvarBase; NewValue: Boolean): Boolean;
begin
if (UserDirectory <> '') or (BaseDirectory <> '') then
begin
Cvar.FErrorMessage := 'fs_portable must be set from the command line';
Result := False;
Exit;
end;

Result := True;
end;
{$POP}

function fs_basepathChange(Cvar: TCvarBase; NewValue: String): Boolean;
begin
if BaseDirectory <> '' then
Expand Down Expand Up @@ -269,9 +285,6 @@ function CheckIfCvarExists(Name: AnsiString): Boolean;

procedure DumpCvar(Cvar: TCvarBase; Value, DefaultValue: Variant);
begin
// FIXME: Workaround for access violation due to uninitialized log_level
if Cvar.Name = 'log_level' then
Exit;
Debug('[CVAR] CvarAdd: ' + Cvar.Name + ' Value: '
+ VarToStr(Value) + ' DefaultValue: ' + VarToStr(DefaultValue) +
' FLAGS: 0 ' + ' Description: ' + Cvar.Description);
Expand Down Expand Up @@ -735,9 +748,9 @@ procedure CvarInit();
Cvars := TFPHashList.Create;
CvarsSync := TFPHashList.Create;

log_level := TIntegerCvar.Add('log_level', 'Sets log level', 0, 0, [], nil, 0, 3);
log_level := TIntegerCvar.Add('log_level', 'Sets log level', LEVEL_OFF, LEVEL_OFF, [], nil, LEVEL_OFF, LEVEL_TRACE);
log_enable := TBooleanCvar.Add('log_enable', 'Enables logging to file', False, False, [], nil);
log_filesupdate := TIntegerCvar.Add('log_filesupdate', 'How often the log files should be updated', 3600, 3600, [], nil, 0, MaxInt);
log_filesupdate := TIntegerCvar.Add('log_filesupdate', 'How often the log files should be updated in ticks (60 ticks = 1 second)', 3600, 3600, [], nil, 0, MaxInt);
{$IFDEF SERVER}
log_timestamp := TBooleanCvar.Add('log_timestamp', 'Enables/Disables timestamps in console', False, False, [CVAR_SERVER], nil);
{$ENDIF}
Expand All @@ -748,12 +761,12 @@ procedure CvarInit();
{$ENDIF}

fs_localmount := TBooleanCvar.Add('fs_localmount', 'Mount game directory as game mod', False, False, [CVAR_CLIENT, CVAR_INITONLY], nil);
fs_mod := TStringCvar.Add('fs_mod', 'File name of mod placed in mods directory (without .smod extension)', '', '', [CVAR_CLIENT, CVAR_INITONLY], nil, 0, 255);
fs_portable := TBooleanCvar.Add('fs_portable', 'Enables portable mode', True, True, [CVAR_CLIENT, CVAR_INITONLY], nil);
fs_basepath := TStringCvar.Add('fs_basepath', 'Path to base game directory', '', '', [CVAR_CLIENT, CVAR_INITONLY], @fs_basepathChange, 0, 255);
fs_userpath := TStringCvar.Add('fs_userpath', 'Path to user game directory', '', '', [CVAR_CLIENT, CVAR_INITONLY], @fs_userpathChange, 0, 255);
fs_mod := TStringCvar.Add('fs_mod', 'File name of mod placed in mods directory (without .smod extension)', '', '', [CVAR_INITONLY], nil, 0, 255);
fs_portable := TBooleanCvar.Add('fs_portable', 'Enables portable mode', False, False, [CVAR_CLIENT, CVAR_INITONLY], @fs_portableChange);
fs_basepath := TStringCvar.Add('fs_basepath', 'Path to base game directory', '', '', [CVAR_INITONLY], @fs_basepathChange, 0, 255);
fs_userpath := TStringCvar.Add('fs_userpath', 'Path to user game directory', '', '', [CVAR_INITONLY], @fs_userpathChange, 0, 255);

demo_autorecord := TBooleanCvar.Add('demo_autorecord', 'Auto record demos', False, False, [CVAR_CLIENT], nil);
demo_autorecord := TBooleanCvar.Add('demo_autorecord', 'Auto record demos', False, False, [], nil);

{$IFNDEF SERVER}
// Render Cvars
Expand Down Expand Up @@ -952,13 +965,13 @@ procedure CvarInit();
net_floodingpacketslan := TIntegerCvar.Add('net_floodingpacketslan', 'When running on a LAN, controls how many packets should be considered flooding', 80, 80, [CVAR_SERVER], nil, 0, 100);
net_floodingpacketsinternet := TIntegerCvar.Add('net_floodingpacketsinternet', 'When running on the Internet, controls how many packets should be considered flooding', 42, 42, [CVAR_SERVER], nil, 0, 100);

net_t1_snapshot := TIntegerCvar.Add('net_t1_snapshot', 'Maximum number of simultaneous file transfer connections', 35, 35, [CVAR_SERVER], nil, 1, 1000);
net_t1_majorsnapshot := TIntegerCvar.Add('net_t1_majorsnapshot', 'Maximum number of simultaneous file transfer connections', 19, 19, [CVAR_SERVER], nil, 1, 1000);
net_t1_deadsnapshot := TIntegerCvar.Add('net_t1_deadsnapshot', 'Maximum number of simultaneous file transfer connections', 50, 50, [CVAR_SERVER], nil, 1, 1000);
net_t1_heartbeat := TIntegerCvar.Add('net_t1_heartbeat', 'Maximum number of simultaneous file transfer connections', 135, 135, [CVAR_SERVER], nil, 1, 1000);
net_t1_delta := TIntegerCvar.Add('net_t1_delta', 'Maximum number of simultaneous file transfer connections', 4, 4, [CVAR_SERVER], nil, 1, 1000);
net_t1_ping := TIntegerCvar.Add('net_t1_ping', 'Maximum number of simultaneous file transfer connections', 21, 21, [CVAR_SERVER], nil, 1, 1000);
net_t1_thingsnapshot := TIntegerCvar.Add('net_t1_thingsnapshot', 'Maximum number of simultaneous file transfer connections', 31, 31, [CVAR_SERVER], nil, 1, 1000);
net_t1_snapshot := TIntegerCvar.Add('net_t1_snapshot', 'How often to send sprite snapshot packets on the internet in ticks (60 ticks = 1 second)', 35, 35, [CVAR_SERVER], nil, 1, 1000);
net_t1_majorsnapshot := TIntegerCvar.Add('net_t1_majorsnapshot', 'How often to send major sprite snapshot packets on the internet in ticks (60 ticks = 1 second)', 19, 19, [CVAR_SERVER], nil, 1, 1000);
net_t1_deadsnapshot := TIntegerCvar.Add('net_t1_deadsnapshot', 'How often to send dead sprite snapshot packets on the internet in ticks (60 ticks = 1 second)', 50, 50, [CVAR_SERVER], nil, 1, 1000);
net_t1_heartbeat := TIntegerCvar.Add('net_t1_heartbeat', 'How often to send heartbeat packets on the internet in ticks (60 ticks = 1 second)', 135, 135, [CVAR_SERVER], nil, 1, 1000);
net_t1_delta := TIntegerCvar.Add('net_t1_delta', 'How often to send bot sprite deltas on the internet in ticks (60 ticks = 1 second)', 4, 4, [CVAR_SERVER], nil, 1, 1000);
net_t1_ping := TIntegerCvar.Add('net_t1_ping', 'How often to send ping packets on the internet in ticks (60 ticks = 1 second)', 21, 21, [CVAR_SERVER], nil, 1, 1000);
net_t1_thingsnapshot := TIntegerCvar.Add('net_t1_thingsnapshot', 'How often to send thing snapshot packets on the internet in ticks (60 ticks = 1 second)', 31, 31, [CVAR_SERVER], nil, 1, 1000);

// Bots cvars
bots_random_noteam := TIntegerCvar.Add('bots_random_noteam', 'Number of bots in DM, PM and RM modes', 0, 0, [CVAR_SERVER], nil, 0, 32);
Expand Down Expand Up @@ -998,7 +1011,7 @@ procedure CvarInit();
sv_kits_collide := TBooleanCvar.Add('sv_kits_collide', 'Enables colliding kits', False, False, [CVAR_SERVER, CVAR_SYNC], nil);
sv_survivalmode := TBooleanCvar.Add('sv_survivalmode', 'Enables survival mode', False, False, [CVAR_SERVER, CVAR_SYNC,CVAR_SERVER_INITONLY], nil); // Restart server
sv_survivalmode_antispy := TBooleanCvar.Add('sv_survivalmode_antispy', 'Enables anti spy chat in survival mode', False, False, [CVAR_SERVER, CVAR_SYNC], nil);
sv_survivalmode_clearweapons := TBooleanCvar.Add('sv_survivalmode_clearweapons', 'Cluster Grenades bonus availability', False, False, [CVAR_SERVER, CVAR_SYNC], nil);
sv_survivalmode_clearweapons := TBooleanCvar.Add('sv_survivalmode_clearweapons', 'Clear weapons in between survivalmode rounds', False, False, [CVAR_SERVER, CVAR_SYNC], nil);
sv_realisticmode := TBooleanCvar.Add('sv_realisticmode', 'Enables realistic mode', False, False, [CVAR_SERVER, CVAR_SYNC,CVAR_SERVER_INITONLY], nil); // Restart server
sv_advancemode := TBooleanCvar.Add('sv_advancemode', 'Enables advance mode', False, False, [CVAR_SERVER, CVAR_SYNC,CVAR_SERVER_INITONLY], nil); // Restart server
sv_advancemode_amount := TIntegerCvar.Add('sv_advancemode_amount', 'Number of kills required in Advance Mode to gain a weapon.', 2, 2, [CVAR_SERVER, CVAR_SYNC], nil, 1, 9999);
Expand All @@ -1012,9 +1025,20 @@ procedure CvarInit();

sv_killlimit := TIntegerCvar.Add('sv_killlimit', 'Game point limit', 10, 10, [CVAR_SERVER, CVAR_SYNC], nil, 0, 9999);
sv_downloadurl := TStringCvar.Add('sv_downloadurl', 'URL from which clients can download missing assets', '', '', [CVAR_SERVER, CVAR_SYNC], nil, 0, 100);
sv_pure := TBooleanCvar.Add('sv_pure', 'Requires clients to use the same game files (.smod) as the server', True, True, [CVAR_SERVER, CVAR_SYNC], nil);
sv_pure := TBooleanCvar.Add('sv_pure', 'Requires clients to use the same game files (.smod) as the server', False, False, [CVAR_SERVER, CVAR_SYNC], nil);

CommandInit();
end;

procedure CvarCleanup();
var
i: Integer;
begin
FreeAndNil(CvarsSync);
if Cvars <> Nil then
for i := 0 to Cvars.Count - 1 do
TCvarBase(Cvars[i]).Free;
FreeAndNil(Cvars);
end;

end.
6 changes: 3 additions & 3 deletions shared/LogFile.pas
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ procedure AddLineToLogFile(var F: TStringList; S: string; Name: string;
if Length(S) < 1 then
Exit;

if log_level.Value = 0 then
if log_level.Value = LEVEL_OFF then
Exit;

S2 := FormatDateTime('yy/mm/dd', Date);
Expand All @@ -124,7 +124,7 @@ procedure AddLineToLogFile(var F: TStringList; S: string; Name: string;
LogLock.Release;
end;

if log_level.Value > 1 then
if log_level.Value >= LEVEL_TRACE then
WriteLogFile(F, Name);
end;

Expand Down Expand Up @@ -235,7 +235,7 @@ procedure NewLogFiles;
Inc(j);
ConsoleLogFileName := Format('%slogs/consolelog-%s-%.2d.txt', [UserDirectory, S2, j]);
end;
if log_level.Value = 0 then
if log_level.Value = LEVEL_OFF then
ConsoleLogFileName := UserDirectory + 'logs/consolelog.txt';

NewLogFile(GameLog, ConsoleLogFileName);
Expand Down
Loading

0 comments on commit a3aae37

Please sign in to comment.