Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit 8b29a85

Browse files
Encapsulate Logger in GM
1 parent 01a9081 commit 8b29a85

14 files changed

Lines changed: 37 additions & 29 deletions

File tree

Scripts/Msc/Commands/CommandDebug.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public override void Run(string[] args)
1818

1919
if (args[0] == "a")
2020
if (NetworkManager.IsServerRunning())
21-
GM.Logger.LogDebug(NetworkManager.GameServer.Players.Print());
21+
GM.LogDebug(NetworkManager.GameServer.Players.Print());
2222
}
2323
}
2424
}

Scripts/Msc/Commands/CommandHelp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class CommandHelp : Command
1212
.Select(Activator.CreateInstance).Cast<Command>()
1313
.Select(x => x.GetType().Name.Replace("Command", "").ToLower()).ToList();
1414

15-
public override void Run(string[] args) => GM.Logger.Log($"Commands:\n{CommandNames.Print()}");
15+
public override void Run(string[] args) => GM.Log($"Commands:\n{CommandNames.Print()}");
1616
}
1717
}

Scripts/Msc/UIGameConsole.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void _on_Console_text_entered(string text)
4949
if (command != null)
5050
command.Run(inputArr.Skip(1).ToArray());
5151
else
52-
GM.Logger.Log($"The command '{cmd}' does not exist");
52+
GM.Log($"The command '{cmd}' does not exist");
5353

5454
Console.Clear();
5555
}

Scripts/Netcode/Client/ENetClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async void Start(string ip, ushort port)
6161
}
6262
catch (Exception e)
6363
{
64-
GM.Logger.LogErr(e, "Client");
64+
GM.LogErr(e, "Client");
6565
}
6666
}
6767

@@ -70,7 +70,7 @@ public async void Start(string ip, ushort port)
7070
/// </summary>
7171
public void Stop() => ENetCmds.Enqueue(new ThreadCmd<ENetOpcode>(ENetOpcode.ClientWantsToDisconnect));
7272

73-
public void Log(object obj) => GM.Logger.Log($"[Client]: {obj}", ConsoleColor.Yellow);
73+
public void Log(object obj) => GM.Log($"[Client]: {obj}", ConsoleColor.Yellow);
7474

7575
/// <summary>
7676
/// This is in the ENet thread, anything from the ENet thread can be used here

Scripts/Netcode/Client/GodotCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task Dequeue()
2222

2323
if (!ENetClient.HandlePacket.ContainsKey(opcode))
2424
{
25-
GM.Logger.LogWarning($"[Client]: Received malformed opcode: {opcode} (Ignoring)");
25+
GM.LogWarning($"[Client]: Received malformed opcode: {opcode} (Ignoring)");
2626
break;
2727
}
2828

@@ -33,7 +33,7 @@ public async Task Dequeue()
3333
}
3434
catch (System.IO.EndOfStreamException ex)
3535
{
36-
GM.Logger.LogWarning($"[Client]: Received malformed opcode: {opcode} {ex.Message} (Ignoring)");
36+
GM.LogWarning($"[Client]: Received malformed opcode: {opcode} {ex.Message} (Ignoring)");
3737
break;
3838
}
3939
await handlePacket.Handle();

Scripts/Netcode/Common/Server/ENetServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task Start(ushort port, int maxClients)
4747
}
4848
catch (Exception e)
4949
{
50-
GM.Logger.LogErr(e, "Server");
50+
GM.LogErr(e, "Server");
5151
}
5252
}
5353

@@ -75,7 +75,7 @@ public void Kick(uint id, DisconnectOpcode opcode)
7575

7676
public void Send(ServerPacketOpcode opcode, APacket data, PacketFlags flags = PacketFlags.Reliable, params Peer[] peers) => Outgoing.Enqueue(new ServerPacket((byte)opcode, flags, data, peers));
7777

78-
public void Log(object obj) => GM.Logger.Log($"[Server]: {obj}", ConsoleColor.Cyan);
78+
public void Log(object obj) => GM.Log($"[Server]: {obj}", ConsoleColor.Cyan);
7979

8080
protected Peer[] GetOtherPeers(uint id)
8181
{
@@ -188,7 +188,7 @@ private Task ENetThreadWorker(ushort port, int maxClients)
188188

189189
if (!HandlePacket.ContainsKey(opcode))
190190
{
191-
GM.Logger.LogWarning($"[Server]: Received malformed opcode: {opcode} (Ignoring)");
191+
GM.LogWarning($"[Server]: Received malformed opcode: {opcode} (Ignoring)");
192192
break;
193193
}
194194

@@ -199,7 +199,7 @@ private Task ENetThreadWorker(ushort port, int maxClients)
199199
}
200200
catch (System.IO.EndOfStreamException e)
201201
{
202-
GM.Logger.LogWarning($"[Server]: Received malformed opcode: {opcode} {e.Message} (Ignoring)");
202+
GM.LogWarning($"[Server]: Received malformed opcode: {opcode} {e.Message} (Ignoring)");
203203
break;
204204
}
205205
handlePacket.Handle(netEvent.Peer);

Scripts/Netcode/Common/Utils/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static bool Duplicate<TKey, TValue>(this IDictionary<TKey, TValue> dict,
1414
{
1515
if (dict.ContainsKey(key))
1616
{
17-
GM.Logger.LogWarning($"'{caller}' tried to add duplicate key '{key}' to dictionary\n" +
17+
GM.LogWarning($"'{caller}' tried to add duplicate key '{key}' to dictionary\n" +
1818
$" at {path} line:{lineNumber}");
1919
return true;
2020
}
@@ -29,7 +29,7 @@ public static bool DoesNotHave<TKey, TValue>(this IDictionary<TKey, TValue> dict
2929
{
3030
if (!dict.ContainsKey(key))
3131
{
32-
GM.Logger.LogWarning($"'{caller}' tried to access non-existent key '{key}' from dictionary\n" +
32+
GM.LogWarning($"'{caller}' tried to access non-existent key '{key}' from dictionary\n" +
3333
$" at {path} line:{lineNumber}");
3434
return true;
3535
}

Scripts/Netcode/Common/Utils/GodotFileManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static bool LoadDir(string path, System.Action<Directory, string> action)
2424
var error = dir.Open($"res://{path}");
2525
if (error != Error.Ok)
2626
{
27-
GM.Logger.LogWarning($"Failed to open {path}");
27+
GM.LogWarning($"Failed to open {path}");
2828
return false;
2929
}
3030

Scripts/Netcode/Common/Utils/NetworkManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override void _Ready()
2727
ENetInitialized = ENet.Library.Initialize();
2828
if (!ENetInitialized)
2929
{
30-
GM.Logger.LogWarning("Failed to initialize ENet! Remember ENet-CSharp.dll AND enet.dll are required in order for ENet to run properly!");
30+
GM.LogWarning("Failed to initialize ENet! Remember ENet-CSharp.dll AND enet.dll are required in order for ENet to run properly!");
3131
}
3232
}
3333

@@ -80,7 +80,7 @@ private static async Task ExitCleanup()
8080
{
8181
GameServerStillRunning++;
8282
if (GameServerStillRunning > 4)
83-
GM.Logger.LogDebug("Game server taking a long time to stop");
83+
GM.LogDebug("Game server taking a long time to stop");
8484
await Task.Delay(100);
8585
}
8686
}
@@ -94,7 +94,7 @@ private static async Task ExitCleanup()
9494
{
9595
GameClientStillRunning++;
9696
if (GameClientStillRunning > 4)
97-
GM.Logger.LogDebug("Game client taking a long time to stop");
97+
GM.LogDebug("Game client taking a long time to stop");
9898
await Task.Delay(100);
9999
}
100100
}
@@ -106,7 +106,7 @@ private static async Task ExitCleanup()
106106
}
107107
catch (Exception e)
108108
{
109-
GM.Logger.LogErr(e, "Game exit cleanup");
109+
GM.LogErr(e, "Game exit cleanup");
110110
await Task.Delay(3000);
111111
}
112112

Scripts/Netcode/Common/Utils/WebClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private async Task<WebServerResponse<string>> PostAsync(string path, Dictionary<
9696
if (LogExceptions)
9797
{
9898
var message = $"Failed to POST to http://{WEB_SERVER_IP}/api/{path} {e.Message}";
99-
GM.Logger.LogWarning(message);
99+
GM.LogWarning(message);
100100
}
101101
return new WebServerResponse<string>
102102
{
@@ -141,7 +141,7 @@ public async Task<WebServerResponse<T>> Get<T>(string path)
141141
if (LogExceptions)
142142
{
143143
var message = $"Failed to GET from http://{WEB_SERVER_IP}/api/{path} {e.Message}";
144-
GM.Logger.LogWarning(message); // no need to notify user of this kind of error
144+
GM.LogWarning(message); // no need to notify user of this kind of error
145145
}
146146
return new WebServerResponse<T>
147147
{

0 commit comments

Comments
 (0)