Skip to content

Commit

Permalink
Fix team names,
Browse files Browse the repository at this point in the history
Optimize config loading
  • Loading branch information
MD-V committed Nov 16, 2023
1 parent 54044b5 commit 7c42351
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions PugSharp/PugSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
using Microsoft.Extensions.Logging;
using PugSharp.Api.Contract;
using PugSharp.Config;
using PugSharp.Api.G5Api;
using PugSharp.Logging;
using PugSharp.Match.Contract;
using PugSharp.Models;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text.Json;
using ChatColors = CounterStrikeSharp.API.Modules.Utils.ChatColors;
using Player = PugSharp.Models.Player;
using PugSharp.Server.Contract;
using PugSharp.Api.Json;
using PugSharp.Match;
using PugSharp.Translation;
using PugSharp.Translation.Properties;
using PugSharp.Api;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Utils;

namespace PugSharp;

Expand Down Expand Up @@ -132,7 +129,7 @@ private void ResetForMatch(MatchConfig matchConfig)

if (!string.IsNullOrEmpty(matchConfig.G5ApiUrl))
{
var g5Stats = new G5ApiClient(matchConfig.G5ApiUrl, matchConfig.G5ApiHeader ?? string.Empty, matchConfig.G5ApiHeaderValue ?? string.Empty);
var g5Stats = new Api.G5Api.G5ApiClient(matchConfig.G5ApiUrl, matchConfig.G5ApiHeader ?? string.Empty, matchConfig.G5ApiHeaderValue ?? string.Empty);
var g5ApiProvider = new G5ApiProvider(g5Stats, _CsServer);
RegisterConsoleCommandAttributeHandlers(g5ApiProvider);
_ApiProvider.AddApiProvider(g5ApiProvider);
Expand All @@ -157,9 +154,7 @@ private void ResetForMatch(MatchConfig matchConfig)
private void InitializeMatch(MatchConfig matchConfig)
{
ResetForMatch(matchConfig);

_Match = new Match.Match(this, _ApiProvider, _TextHelper, matchConfig);

}

private void InitializeMatch(MatchInfo matchInfo, string roundBackupFile)
Expand Down Expand Up @@ -242,14 +237,13 @@ private void SetMatchVariable(MatchConfig matchConfig)
UpdateConvar("mp_overtime_maxrounds", matchConfig.MaxOvertimeRounds);
UpdateConvar("mp_maxrounds", matchConfig.MaxRounds);

// Set T Name
UpdateConvar("mp_teamname_1", matchConfig.Team2.Name);
UpdateConvar("mp_teamflag_1", matchConfig.Team2.Flag);
// Set T Name, can be changed to ConVar if issue https://github.com/roflmuffin/CounterStrikeSharp/issues/45 is fixed
_CsServer.ExecuteCommand($"mp_teamname_1 {matchConfig.Team2.Name}");
_CsServer.ExecuteCommand($"mp_teamflag_1 {matchConfig.Team2.Flag}");


// Set CT Name
UpdateConvar("mp_teamname_2", matchConfig.Team1.Name);
UpdateConvar("mp_teamflag_2", matchConfig.Team1.Flag);
// Set CT Name, can be changed to ConVar if issue https://github.com/roflmuffin/CounterStrikeSharp/issues/45 is fixed
_CsServer.ExecuteCommand($"mp_teamname_2 {matchConfig.Team1.Name}");
_CsServer.ExecuteCommand($"mp_teamflag_2 {matchConfig.Team1.Flag}");

_Logger.LogInformation("Set match variables done");
}
Expand All @@ -266,17 +260,17 @@ private void LoadAndExecuteLiveConfig()

private void LoadAndExecuteConfig(string configFileName)
{
var configFile = Path.Combine(_CsServer.GameDirectory, "csgo", "cfg", "PugSharp", configFileName);
if (!File.Exists(configFile))
var absoluteConfigFilePath = Path.Combine(_CsServer.GameDirectory, "csgo", "cfg", "PugSharp", configFileName);
if (!File.Exists(absoluteConfigFilePath))
{
_Logger.LogError("Config {configFile} was not found on the server.", configFile);
_Logger.LogError("Config {configFile} was not found on the server.", absoluteConfigFilePath);
return;
}

configFile = Path.Join("PugSharp", configFileName);
var configFilePath = $"PugSharp/{configFileName}";

_Logger.LogInformation("Loading {configFile}.", configFile);
_CsServer.ExecuteCommand($"exec \"{configFile}\"");
_Logger.LogInformation("Loading {configFilePath} with absolute path {absoluteConfigFilePath}.", configFilePath, absoluteConfigFilePath);
_CsServer.ExecuteCommand($"exec {configFilePath}");
}

private void EndWarmup()
Expand All @@ -300,7 +294,6 @@ public void OnCommandStopMatch(CCSPlayerController? player, CommandInfo command)
{
HandleCommandAsync(() =>
{
if (_Match == null)
{
command.ReplyToCommand("Currently no Match is running. ");
Expand Down

0 comments on commit 7c42351

Please sign in to comment.