Skip to content

Commit

Permalink
main server: improved debugging logs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed May 30, 2018
1 parent c975692 commit 27c9255
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions vMenuServer/MainServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@
using static CitizenFX.Core.Native.API;
using Newtonsoft.Json;
using System.Dynamic;
using static vMenuServer.DebugLog;

namespace vMenuServer
{

public static class DebugLog
{
/// <summary>
/// Global log data function, only logs when debugging is enabled.
/// </summary>
/// <param name="data"></param>
public static void Log(dynamic data)
{
if (MainServer.DebugMode)
{
Debug.Write(data.ToString() + "\n");
}
}
}

public class MainServer : BaseScript
{
public static bool UpToDate = true;
Expand Down Expand Up @@ -352,7 +369,7 @@ public MainServer()
{
foreach (var modelName in json["vehicles"])
{
if (DebugMode) { Debug.WriteLine("Addon vehicle loaded: " + modelName, ""); }
Log("Addon vehicle loaded: " + modelName);
addonVehicles.Add(modelName);
}
}
Expand All @@ -361,7 +378,7 @@ public MainServer()
{
foreach (var modelName in json["peds"])
{
if (DebugMode) { Debug.WriteLine("Addon ped loaded:" + modelName, ""); }
Log("Addon ped loaded:" + modelName);
addonPeds.Add(modelName);
}
}
Expand All @@ -370,7 +387,7 @@ public MainServer()
{
foreach (var modelName in json["weapons"])
{
if (DebugMode) { Debug.WriteLine("Addon weapon loaded:" + modelName, ""); }
Log("Addon weapon loaded:" + modelName);
addonWeapons.Add(modelName);
}
}
Expand Down Expand Up @@ -436,10 +453,11 @@ private async Task WeatherLoop()
{
dynamicWeatherTimeLeft = 5 * 12 * 10;
RefreshWeather();

if (DebugMode)
{
long gameTimer2 = GetGameTimer();
Debug.WriteLine($"Duration: {((gameTimer2 - gameTimer) / 100).ToString()}. New Weather Type: {currentWeather}");
Log($"Duration: {((gameTimer2 - gameTimer) / 100).ToString()}. New Weather Type: {currentWeather}");
gameTimer = gameTimer2;
}
}
Expand Down Expand Up @@ -577,10 +595,10 @@ private void KickPlayer([FromSource] Player source, int target, string kickReaso
if (!IsPlayerAceAllowed(targetPlayer.Handle, "vMenu.DontKickMe"))
{
TriggerEvent("vMenu:KickSuccessful", source.Name, kickReason, targetPlayer.Name);

KickLog($"Player: {source.Name} has kicked: {targetPlayer.Name} for: {kickReason}.");
TriggerClientEvent(player: source, eventName: "vMenu:Notify", args: $"The target player (<C>{targetPlayer.Name}</C>) has been kicked.");

// Kick the player from the server using the specified reason.
DropPlayer(targetPlayer.Handle, kickReason);
return;
Expand Down

0 comments on commit 27c9255

Please sign in to comment.