Skip to content

Commit

Permalink
Update Convar as Command
Browse files Browse the repository at this point in the history
  • Loading branch information
TheR00st3r committed Nov 15, 2023
1 parent 8f5db74 commit 6c1cd57
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions PugSharp/PugSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,25 @@ private void InitializeMatch(MatchInfo matchInfo, string roundBackupFile)
_Match = new Match.Match(this, _ApiProvider, _TextHelper, matchInfo, roundBackupFile);
}

public static void UpdateConvar<T>(string name, T value)
public void UpdateConvar<T>(string name, T value)
{
try
{
var convar = ConVar.Find(name);

if (convar == null)
{
_Logger.LogError("ConVar {name} couldn't be found", name);
return;
}

if (value is string stringValue)
{
_Logger.LogInformation("Update ConVar {name} to stringvalue {value}", name, stringValue);
convar.StringValue = stringValue;
_CsServer.ExecuteCommand($"{name} {stringValue}");
}
else
{
var convar = ConVar.Find(name);

if (convar == null)
{
_Logger.LogError("ConVar {name} couldn't be found", name);
return;
}

_Logger.LogInformation("Update ConVar {name} to value {value}", name, value);
convar.SetValue(value);
}
Expand Down Expand Up @@ -234,7 +234,7 @@ private void ResetServer(string map)
_CsServer.ExecuteCommand($"changelevel {map}");
}

private static void SetMatchVariable(MatchConfig matchConfig)
private void SetMatchVariable(MatchConfig matchConfig)
{
_Logger.LogInformation("Start set match variables");

Expand All @@ -245,6 +245,7 @@ private static void SetMatchVariable(MatchConfig matchConfig)
UpdateConvar("mp_teamname_1", matchConfig.Team2.Name);
UpdateConvar("mp_teamflag_1", matchConfig.Team2.Flag);


// Set CT Name
UpdateConvar("mp_teamname_2", matchConfig.Team1.Name);
UpdateConvar("mp_teamflag_2", matchConfig.Team1.Flag);
Expand Down Expand Up @@ -283,7 +284,7 @@ private void EndWarmup()
_CsServer.ExecuteCommand("mp_warmup_end");
}

private static void DisableCheats()
private void DisableCheats()
{
_Logger.LogInformation("Disabling cheats");
UpdateConvar("sv_cheats", false);
Expand Down Expand Up @@ -1234,7 +1235,7 @@ private HookResult OnRoundMvp(EventRoundMvp eventRoundMvp, GameEventInfo info)
mvpStats.Mvp = true;

// Report MVP
if(mvp.UserId.HasValue)
if (mvp.UserId.HasValue)
{
var roundMvpParams = new RoundMvpParams(
_Match.MatchInfo.Config.MatchId,
Expand Down

0 comments on commit 6c1cd57

Please sign in to comment.