mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-28 06:03:05 +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);
|
IMemoryOwner<byte> memory = MemoryPool<byte>.Shared.RentZero(Constants.HeaderSize + packet.Size);
|
||||||
|
|
||||||
PacketAttribute packetAttribute = Constants.PacketMap[typeof(T)];
|
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 {
|
try {
|
||||||
Server.FillPacket(new PacketHeader {
|
Server.FillPacket(new PacketHeader {
|
||||||
Id = sender?.Id ?? Id,
|
Id = sender?.Id ?? Id,
|
||||||
|
@ -48,14 +46,11 @@ public class Client : IDisposable {
|
||||||
}, packet, memory.Memory);
|
}, packet, memory.Memory);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
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);
|
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();
|
memory.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,7 @@ timer.Enabled = true;
|
||||||
timer.Elapsed += (_, _) => { SyncShineBag(); };
|
timer.Elapsed += (_, _) => { SyncShineBag(); };
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
float MarioSize(bool is2d) {
|
float MarioSize(bool is2d) => is2d ? 180 : 160;
|
||||||
return is2d ? 180 : 160;
|
|
||||||
}
|
|
||||||
|
|
||||||
server.PacketHandler = (c, p) => {
|
server.PacketHandler = (c, p) => {
|
||||||
switch (p) {
|
switch (p) {
|
||||||
|
@ -74,26 +72,27 @@ server.PacketHandler = (c, p) => {
|
||||||
c.Metadata["speedrun"] = true;
|
c.Metadata["speedrun"] = true;
|
||||||
((ConcurrentBag<int>) (c.Metadata["shineSync"] ??= new ConcurrentBag<int>())).Clear();
|
((ConcurrentBag<int>) (c.Metadata["shineSync"] ??= new ConcurrentBag<int>())).Clear();
|
||||||
shineBag.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;
|
break;
|
||||||
case "WaterfallWorldHomeStage":
|
case "WaterfallWorldHomeStage":
|
||||||
bool wasSpeedrun = (bool) c.Metadata["speedrun"]!;
|
bool wasSpeedrun = (bool) c.Metadata["speedrun"]!;
|
||||||
c.Metadata["speedrun"] = false;
|
c.Metadata["speedrun"] = false;
|
||||||
if (wasSpeedrun)
|
if (wasSpeedrun)
|
||||||
Task.Run(async () => {
|
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 Task.Delay(15000);
|
||||||
await ClientSyncShineBag(c);
|
await ClientSyncShineBag(c);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
server.BroadcastReplace(gamePacket, c, (from, to, gp) => {
|
if (Settings.Instance.Scenario.MergeEnabled) {
|
||||||
gp.ScenarioNum = (byte?) to.Metadata["scenario"] ?? 200;
|
server.BroadcastReplace(gamePacket, c, (from, to, gp) => {
|
||||||
from.Logger.Warn($"to {to.Logger.Name}, {to.Metadata["scenario"]}-{gp.ScenarioNum}");
|
gp.ScenarioNum = (byte?) to.Metadata["scenario"] ?? 200;
|
||||||
|
to.Send(gp, from);
|
||||||
to.Send(gp, from);
|
});
|
||||||
});
|
return false;
|
||||||
return false;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case TagPacket tagPacket: {
|
case TagPacket tagPacket: {
|
||||||
if ((tagPacket.UpdateType & TagPacket.TagUpdate.State) != 0) c.Metadata["seeking"] = tagPacket.IsIt;
|
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 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 {
|
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 {
|
public async Task Broadcast<T>(T packet, Client sender) where T : struct, IPacket {
|
||||||
|
@ -158,8 +158,6 @@ public class Server {
|
||||||
break;
|
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
|
// connection initialization
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
|
@ -267,7 +265,6 @@ public class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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])!;
|
IPacket packet = (IPacket) Activator.CreateInstance(Constants.PacketIdMap[header.Type])!;
|
||||||
packet.Deserialize(memory.Memory.Span[Constants.HeaderSize..(Constants.HeaderSize + packet.Size)]);
|
packet.Deserialize(memory.Memory.Span[Constants.HeaderSize..(Constants.HeaderSize + packet.Size)]);
|
||||||
if (PacketHandler?.Invoke(client, packet) is false) {
|
if (PacketHandler?.Invoke(client, packet) is false) {
|
||||||
|
@ -301,8 +298,7 @@ public class Server {
|
||||||
try {
|
try {
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
}
|
}
|
||||||
catch { /*lol*/
|
catch { /*lol*/ }
|
||||||
}
|
|
||||||
|
|
||||||
Task.Run(() => Broadcast(new DisconnectPacket(), client));
|
Task.Run(() => Broadcast(new DisconnectPacket(), client));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
namespace Shared;
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Shared;
|
||||||
|
|
||||||
public class Logger {
|
public class Logger {
|
||||||
public Logger(string name) {
|
public Logger(string name) {
|
||||||
|
@ -9,16 +11,31 @@ public class Logger {
|
||||||
|
|
||||||
public void Info(string text) {
|
public void Info(string text) {
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
Console.WriteLine($"Info [{Name}] {text}");
|
Console.WriteLine(PrefixNewLines(text, $"Info [{Name}]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Warn(string text) {
|
public void Warn(string text) {
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine($"Warn [{Name}] {text}");
|
Console.WriteLine(PrefixNewLines(text, $"Warn [{Name}]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Error(string text) {
|
public void Error(string text) {
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
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