mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-24 04:05:17 +00:00
Clean up logging from testing
This commit is contained in:
parent
24e4333fde
commit
ab318db1b8
4 changed files with 36 additions and 29 deletions
|
@ -38,8 +38,6 @@ public class Client : IDisposable {
|
|||
IMemoryOwner<byte> memory = MemoryPool<byte>.Shared.RentZero(Constants.HeaderSize + packet.Size);
|
||||
|
||||
PacketAttribute packetAttribute = Constants.PacketMap[typeof(T)];
|
||||
if (packetAttribute.Type is not PacketType.Cap and not PacketType.Player)
|
||||
Logger.Info($"Pre-header {packetAttribute.Type} ({(short)packetAttribute.Type}) - {typeof(T)}");
|
||||
try {
|
||||
Server.FillPacket(new PacketHeader {
|
||||
Id = sender?.Id ?? Id,
|
||||
|
@ -48,14 +46,11 @@ public class Client : IDisposable {
|
|||
}, packet, memory.Memory);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Logger.Error($"I will lose my shit {e} {memory.Memory.Span[..Constants.HeaderSize].Length} {memory.Memory.Span[Constants.HeaderSize..].Length} {packet.Size}");
|
||||
Logger.Error($"Failed to serialize {packetAttribute.Type}");
|
||||
Logger.Error(e);
|
||||
}
|
||||
|
||||
if (packetAttribute.Type is not PacketType.Cap and not PacketType.Player)
|
||||
Logger.Info($"About to receive {packetAttribute.Type} ({(short)packetAttribute.Type}) - {typeof(T)}");
|
||||
await Socket!.SendAsync(memory.Memory[..(Constants.HeaderSize + packet.Size)], SocketFlags.None);
|
||||
if (packetAttribute.Type is not PacketType.Cap and not PacketType.Player)
|
||||
Logger.Info($"Receiving {packetAttribute.Type} ({(short)packetAttribute.Type}) - {typeof(T)}");
|
||||
memory.Dispose();
|
||||
}
|
||||
|
||||
|
|
|
@ -58,9 +58,7 @@ timer.Enabled = true;
|
|||
timer.Elapsed += (_, _) => { SyncShineBag(); };
|
||||
timer.Start();
|
||||
|
||||
float MarioSize(bool is2d) {
|
||||
return is2d ? 180 : 160;
|
||||
}
|
||||
float MarioSize(bool is2d) => is2d ? 180 : 160;
|
||||
|
||||
server.PacketHandler = (c, p) => {
|
||||
switch (p) {
|
||||
|
@ -74,26 +72,27 @@ server.PacketHandler = (c, p) => {
|
|||
c.Metadata["speedrun"] = true;
|
||||
((ConcurrentBag<int>) (c.Metadata["shineSync"] ??= new ConcurrentBag<int>())).Clear();
|
||||
shineBag.Clear();
|
||||
c.Logger.Info("Entered Cap on scenario 0, enabling speedrun flag");
|
||||
c.Logger.Info("Entered Cap on new save, preventing moon sync until Cascade");
|
||||
break;
|
||||
case "WaterfallWorldHomeStage":
|
||||
bool wasSpeedrun = (bool) c.Metadata["speedrun"]!;
|
||||
c.Metadata["speedrun"] = false;
|
||||
if (wasSpeedrun)
|
||||
Task.Run(async () => {
|
||||
c.Logger.Info("Entered Cascade with speedrun mode on");
|
||||
c.Logger.Info("Entered Cascade with moon sync disabled, enabling moon sync");
|
||||
await Task.Delay(15000);
|
||||
await ClientSyncShineBag(c);
|
||||
});
|
||||
break;
|
||||
}
|
||||
server.BroadcastReplace(gamePacket, c, (from, to, gp) => {
|
||||
gp.ScenarioNum = (byte?) to.Metadata["scenario"] ?? 200;
|
||||
from.Logger.Warn($"to {to.Logger.Name}, {to.Metadata["scenario"]}-{gp.ScenarioNum}");
|
||||
|
||||
to.Send(gp, from);
|
||||
});
|
||||
return false;
|
||||
if (Settings.Instance.Scenario.MergeEnabled) {
|
||||
server.BroadcastReplace(gamePacket, c, (from, to, gp) => {
|
||||
gp.ScenarioNum = (byte?) to.Metadata["scenario"] ?? 200;
|
||||
to.Send(gp, from);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TagPacket tagPacket: {
|
||||
if ((tagPacket.UpdateType & TagPacket.TagUpdate.State) != 0) c.Metadata["seeking"] = tagPacket.IsIt;
|
||||
|
|
|
@ -68,7 +68,7 @@ public class Server {
|
|||
public delegate void PacketReplacer<in T>(Client from, Client to, T value); // replacer must send
|
||||
|
||||
public void BroadcastReplace<T>(T packet, Client sender, PacketReplacer<T> packetReplacer) where T : struct, IPacket {
|
||||
foreach (Client client in Clients.Where(client => sender.Id != client.Id)) packetReplacer(sender, client, packet);
|
||||
foreach (Client client in Clients.Where(client => client.Connected && sender.Id != client.Id)) packetReplacer(sender, client, packet);
|
||||
}
|
||||
|
||||
public async Task Broadcast<T>(T packet, Client sender) where T : struct, IPacket {
|
||||
|
@ -158,8 +158,6 @@ public class Server {
|
|||
break;
|
||||
}
|
||||
|
||||
// if (header.Type is not PacketType.Player and not PacketType.Cap and not PacketType.Capture)Logger.Info($"Got your mom {header.Id} {header.Type} 0x{header.PacketSize:X} 0x{memory.Memory.Length:X} 0x{header.Size:X}");
|
||||
|
||||
// connection initialization
|
||||
if (first) {
|
||||
first = false;
|
||||
|
@ -267,7 +265,6 @@ public class Server {
|
|||
}
|
||||
|
||||
try {
|
||||
// if (header.Type is not PacketType.Cap and not PacketType.Player) client.Logger.Warn($"lol {header.Type}");
|
||||
IPacket packet = (IPacket) Activator.CreateInstance(Constants.PacketIdMap[header.Type])!;
|
||||
packet.Deserialize(memory.Memory.Span[Constants.HeaderSize..(Constants.HeaderSize + packet.Size)]);
|
||||
if (PacketHandler?.Invoke(client, packet) is false) {
|
||||
|
@ -301,8 +298,7 @@ public class Server {
|
|||
try {
|
||||
client.Dispose();
|
||||
}
|
||||
catch { /*lol*/
|
||||
}
|
||||
catch { /*lol*/ }
|
||||
|
||||
Task.Run(() => Broadcast(new DisconnectPacket(), client));
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace Shared;
|
||||
using System.Text;
|
||||
|
||||
namespace Shared;
|
||||
|
||||
public class Logger {
|
||||
public Logger(string name) {
|
||||
|
@ -9,16 +11,31 @@ public class Logger {
|
|||
|
||||
public void Info(string text) {
|
||||
Console.ResetColor();
|
||||
Console.WriteLine($"Info [{Name}] {text}");
|
||||
Console.WriteLine(PrefixNewLines(text, $"Info [{Name}]"));
|
||||
}
|
||||
|
||||
public void Warn(string text) {
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine($"Warn [{Name}] {text}");
|
||||
Console.WriteLine(PrefixNewLines(text, $"Warn [{Name}]"));
|
||||
}
|
||||
|
||||
public void Error(string text) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Warn [{Name}] {text}");
|
||||
Console.WriteLine(PrefixNewLines(text, $"Error [{Name}]"));
|
||||
}
|
||||
|
||||
public void Error(Exception error) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(PrefixNewLines(error.ToString(), $"Error [{Name}]"));
|
||||
}
|
||||
|
||||
private string PrefixNewLines(string text, string prefix) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (string str in text.Split('\n'))
|
||||
builder
|
||||
.Append(prefix)
|
||||
.Append(' ')
|
||||
.AppendLine(str);
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue