0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-10 13:45:06 +00:00

Fix a connect packet read among us

This commit is contained in:
Sanae 2022-02-14 14:40:42 -06:00
parent d60aa07e1f
commit 9b2d508a20
2 changed files with 22 additions and 2 deletions

View file

@ -1,9 +1,11 @@
using System.Collections.Concurrent;
using Server;
using Shared.Packet.Packets;
using Timer = System.Timers.Timer;
Server.Server server = new Server.Server();
ConcurrentBag<int> shineBag = new ConcurrentBag<int>();
HashSet<int> shineBag = new HashSet<int>();
int shineTx = 0; // used for logging
server.ClientJoined += async (c, type) => {
c.Metadata["shineSync"] = new ConcurrentBag<int>();
@ -23,6 +25,14 @@ async void SyncShineBag() {
});
}
Timer timer = new Timer(120000);
timer.AutoReset = true;
timer.Enabled = true;
timer.Elapsed += (_, _) => {
SyncShineBag();
};
timer.Start();
server.PacketHandler += async (c, p) => {
switch (p) {
case CostumePacket:
@ -33,6 +43,8 @@ server.PacketHandler += async (c, p) => {
if (c.Metadata["loadedSave"] is false) return;
ConcurrentBag<int> playerBag = (ConcurrentBag<int>) c.Metadata["shineSync"];
shineBag.Add(shinePacket.ShineId);
if (playerBag.Contains(shinePacket.ShineId)) return;
Console.WriteLine($"{c.Name} got {shinePacket.ShineId}");
playerBag.Add(shinePacket.ShineId);
SyncShineBag();
break;

View file

@ -107,7 +107,8 @@ public class Server {
first = false;
if (header.Type != PacketType.Connect) throw new Exception($"First packet was not init, instead it was {header.Type}");
ConnectPacket connect = MemoryMarshal.Read<ConnectPacket>(memory.Memory.Span[Constants.HeaderSize..size]);
ConnectPacket connect = new ConnectPacket();
connect.Deserialize(memory.Memory.Span[Constants.HeaderSize..size]);
lock (Clients) {
bool firstConn = false;
switch (connect.ConnectionType) {
@ -183,6 +184,13 @@ public class Server {
client.CurrentCostume = costumePacket;
}
{
if (header.Type is not PacketType.Cap and not PacketType.Player) Logger.Warn($"lol {header.Type}");
IPacket packet = (IPacket) Activator.CreateInstance(Constants.PacketIdMap[header.Type])!;
packet.Deserialize(memory.Memory.Span[Constants.HeaderSize..]);
PacketHandler?.Invoke(client, packet);
}
await Broadcast(memory, client);
}
} catch (Exception e) {