0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-25 04:35:18 +00:00
This commit is contained in:
CraftyBoss 2022-04-27 04:43:48 +00:00
commit 3e462ddb64
2 changed files with 7 additions and 21 deletions

View file

@ -34,11 +34,9 @@ public class Client : IDisposable {
public delegate IPacket PacketTransformerDel(Client? sender, IPacket packet);
public event PacketTransformerDel? PacketTransformer;
public async Task Send<T>(T packet, Client? sender = null) where T : struct, IPacket {
IMemoryOwner<byte> memory = MemoryPool<byte>.Shared.RentZero(Constants.HeaderSize + packet.Size);
packet = (T) (PacketTransformer?.Invoke(sender, packet) ?? packet);
PacketHeader header = new PacketHeader {
Id = sender?.Id ?? Id,
Type = Constants.PacketMap[typeof(T)].Type,
@ -56,13 +54,6 @@ public class Client : IDisposable {
}
int packetSize = MemoryMarshal.Read<short>(data.Span[18..]);
// if (PacketTransformer != null) {
// PacketType type = MemoryMarshal.Read<PacketType>(data.Span[16..]);
// IPacket packet = (IPacket) Activator.CreateInstance(Constants.PacketIdMap[type])!;
// packet.Deserialize(data.Span);
// packet = PacketTransformer?.Invoke(sender, packet) ?? packet;
// packet.Serialize(data.Span);
// }
await Socket!.SendAsync(data[..(Constants.HeaderSize + packetSize)], SocketFlags.None);
}

View file

@ -7,7 +7,6 @@ using Timer = System.Timers.Timer;
Server.Server server = new Server.Server();
HashSet<int> shineBag = new HashSet<int>();
// int shineTx = 0; // used for logging
CancellationTokenSource cts = new CancellationTokenSource();
Task listenTask = server.Listen(cts.Token);
Logger consoleLogger = new Logger("Console");
@ -26,15 +25,6 @@ server.ClientJoined += (c, _) => {
// lol who gives a fuck
}
}
c.PacketTransformer += (_, packet) => {
if (Settings.Instance.Scenario.MergeEnabled && packet is GamePacket gamePacket) {
gamePacket.ScenarioNum = (byte?) c.Metadata["scenario"] ?? 200;
return gamePacket;
}
return packet;
};
};
async Task ClientSyncShineBag(Client client) {
@ -97,7 +87,12 @@ server.PacketHandler = (c, p) => {
});
break;
}
break;
server.BroadcastReplace(gamePacket, c, (from, to, gp) => {
gp.ScenarioNum = (byte?) from.Metadata["scenario"] ?? 200;
to.Send(gp, from);
});
return false;
}
case TagPacket tagPacket: {
if ((tagPacket.UpdateType & TagPacket.TagUpdate.State) != 0) c.Metadata["seeking"] = tagPacket.IsIt;
@ -113,7 +108,7 @@ server.PacketHandler = (c, p) => {
ConcurrentBag<int> playerBag = (ConcurrentBag<int>) c.Metadata["shineSync"];
shineBag.Add(shinePacket.ShineId);
if (playerBag.Contains(shinePacket.ShineId)) break;
c.Logger.Info($"Got shine {shinePacket.ShineId}");
c.Logger.Info($"Got moon {shinePacket.ShineId}");
playerBag.Add(shinePacket.ShineId);
SyncShineBag();
break;