mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-24 20:25:18 +00:00
Lycel go flippy flippy
This commit is contained in:
parent
4ccf33ad37
commit
514c68d2e9
4 changed files with 52 additions and 30 deletions
|
@ -31,7 +31,7 @@ public class Client : IDisposable {
|
||||||
Socket.Disconnect(false);
|
Socket.Disconnect(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Send<T>(T packet, Client? sender = null) where T : unmanaged, IPacket {
|
public async Task Send<T>(T packet, Client? sender = null) where T : struct, IPacket {
|
||||||
IMemoryOwner<byte> memory = MemoryPool<byte>.Shared.Rent(Constants.MaxPacketSize);
|
IMemoryOwner<byte> memory = MemoryPool<byte>.Shared.Rent(Constants.MaxPacketSize);
|
||||||
|
|
||||||
PacketHeader header = new PacketHeader {
|
PacketHeader header = new PacketHeader {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Numerics;
|
||||||
using Server;
|
using Server;
|
||||||
using Shared.Packet.Packets;
|
using Shared.Packet.Packets;
|
||||||
using Timer = System.Timers.Timer;
|
using Timer = System.Timers.Timer;
|
||||||
|
@ -32,24 +33,45 @@ timer.Elapsed += (_, _) => {
|
||||||
SyncShineBag();
|
SyncShineBag();
|
||||||
};
|
};
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
bool piss = false;
|
||||||
|
|
||||||
server.PacketHandler += async (c, p) => {
|
// Guid lycel = Guid.Parse("d5feae62-2e71-1000-88fd-597ea147ae88");
|
||||||
|
Guid lycel = Guid.Parse("5e1f9db4-1c27-1000-a421-4701972e443e");
|
||||||
|
|
||||||
|
server.PacketHandler = (c, p) => {
|
||||||
switch (p) {
|
switch (p) {
|
||||||
case CostumePacket:
|
case CostumePacket:
|
||||||
await ClientSyncShineBag(c);
|
ClientSyncShineBag(c);
|
||||||
c.Metadata["loadedSave"] = true;
|
c.Metadata["loadedSave"] = true;
|
||||||
break;
|
break;
|
||||||
case ShinePacket shinePacket: {
|
case ShinePacket shinePacket: {
|
||||||
if (c.Metadata["loadedSave"] is false) return;
|
if (c.Metadata["loadedSave"] is false) break;
|
||||||
ConcurrentBag<int> playerBag = (ConcurrentBag<int>) c.Metadata["shineSync"];
|
ConcurrentBag<int> playerBag = (ConcurrentBag<int>) c.Metadata["shineSync"];
|
||||||
shineBag.Add(shinePacket.ShineId);
|
shineBag.Add(shinePacket.ShineId);
|
||||||
if (playerBag.Contains(shinePacket.ShineId)) return;
|
if (playerBag.Contains(shinePacket.ShineId)) break;
|
||||||
c.Logger.Info($"Got shine {shinePacket.ShineId}");
|
c.Logger.Info($"Got shine {shinePacket.ShineId}");
|
||||||
playerBag.Add(shinePacket.ShineId);
|
playerBag.Add(shinePacket.ShineId);
|
||||||
SyncShineBag();
|
SyncShineBag();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PlayerPacket playerPacket: {
|
||||||
|
if (!piss || c.Id != lycel) break;
|
||||||
|
playerPacket.Position += Vector3.UnitY * 160;
|
||||||
|
playerPacket.Rotation *= Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationX(MathF.PI));
|
||||||
|
server.Broadcast(playerPacket, c);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Task.Run(() => {
|
||||||
|
while (true) {
|
||||||
|
Console.ReadLine();
|
||||||
|
piss = !piss;
|
||||||
|
server.Logger.Warn($"Lycel flipped to {piss}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await server.Listen(1027);
|
await server.Listen(1027);
|
|
@ -12,7 +12,7 @@ public class Server {
|
||||||
public readonly List<Client> Clients = new List<Client>();
|
public readonly List<Client> Clients = new List<Client>();
|
||||||
public readonly Logger Logger = new Logger("Server");
|
public readonly Logger Logger = new Logger("Server");
|
||||||
private readonly MemoryPool<byte> memoryPool = MemoryPool<byte>.Shared;
|
private readonly MemoryPool<byte> memoryPool = MemoryPool<byte>.Shared;
|
||||||
public event Action<Client, IPacket> PacketHandler = null!;
|
public Func<Client, IPacket, bool>? PacketHandler = null!;
|
||||||
public event Action<Client, ConnectPacket> ClientJoined = null!;
|
public event Action<Client, ConnectPacket> ClientJoined = null!;
|
||||||
|
|
||||||
public async Task Listen(ushort port) {
|
public async Task Listen(ushort port) {
|
||||||
|
@ -42,7 +42,7 @@ public class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FillPacket<T>(PacketHeader header, T packet, Memory<byte> memory) where T : unmanaged, IPacket {
|
public static void FillPacket<T>(PacketHeader header, T packet, Memory<byte> memory) where T : struct, IPacket {
|
||||||
Span<byte> data = memory.Span;
|
Span<byte> data = memory.Span;
|
||||||
|
|
||||||
MemoryMarshal.Write(data, ref header);
|
MemoryMarshal.Write(data, ref header);
|
||||||
|
@ -50,7 +50,7 @@ public class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
// broadcast packets to all clients
|
// broadcast packets to all clients
|
||||||
public async Task Broadcast<T>(T packet, Client sender) where T : unmanaged, IPacket {
|
public async Task Broadcast<T>(T packet, Client sender) where T : struct, IPacket {
|
||||||
IMemoryOwner<byte> memory = memoryPool.Rent(Constants.MaxPacketSize);
|
IMemoryOwner<byte> memory = memoryPool.Rent(Constants.MaxPacketSize);
|
||||||
|
|
||||||
PacketHeader header = new PacketHeader {
|
PacketHeader header = new PacketHeader {
|
||||||
|
@ -198,9 +198,9 @@ public class Server {
|
||||||
// if (header.Type is not PacketType.Cap and not PacketType.Player) client.Logger.Warn($"lol {header.Type}");
|
// 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..]);
|
packet.Deserialize(memory.Memory.Span[Constants.HeaderSize..]);
|
||||||
PacketHandler?.Invoke(client, packet);
|
if (PacketHandler?.Invoke(client, packet) is false) continue;
|
||||||
} catch {
|
} catch (Exception e){
|
||||||
// ignore failed packet deserialization!
|
client.Logger.Error($"Packet handler warning: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Broadcast(memory, client);
|
Broadcast(memory, client);
|
||||||
|
|
|
@ -31,25 +31,25 @@ async Task S() {
|
||||||
PacketHeader header = MemoryMarshal.Read<PacketHeader>(owner.Memory.Span);
|
PacketHeader header = MemoryMarshal.Read<PacketHeader>(owner.Memory.Span);
|
||||||
PacketType type = header.Type;
|
PacketType type = header.Type;
|
||||||
if (header.Id != otherId) continue;
|
if (header.Id != otherId) continue;
|
||||||
if (type is PacketType.Player) {
|
// if (type is PacketType.Player) {
|
||||||
CapPacket cap = new CapPacket();
|
// CapPacket cap = new CapPacket();
|
||||||
PlayerPacket playerPacket = new PlayerPacket();
|
// PlayerPacket playerPacket = new PlayerPacket();
|
||||||
playerPacket.Deserialize(owner.Memory.Span[Constants.HeaderSize..]);
|
// playerPacket.Deserialize(owner.Memory.Span[Constants.HeaderSize..]);
|
||||||
cap.Position = playerPacket.Position + Vector3.UnitY * 500f;
|
// cap.Position = playerPacket.Position + Vector3.UnitY * 500f;
|
||||||
// cap.Rotation = Quaternion.CreateFromYawPitchRoll(0,0,0);
|
// // cap.Rotation = Quaternion.CreateFromYawPitchRoll(0,0,0);
|
||||||
cap.CapAnim = "StayR";
|
// cap.CapAnim = "StayR";
|
||||||
playerPacket.Position = new Vector3(1000000f);
|
// playerPacket.Position = new Vector3(1000000f);
|
||||||
playerPacket.ThrowingCap = true;
|
// playerPacket.ThrowingCap = true;
|
||||||
header.Id = ownId;
|
// header.Id = ownId;
|
||||||
MemoryMarshal.Write(owner.Memory.Span, ref header);
|
// MemoryMarshal.Write(owner.Memory.Span, ref header);
|
||||||
playerPacket.Serialize(owner.Memory.Span[Constants.HeaderSize..]);
|
// playerPacket.Serialize(owner.Memory.Span[Constants.HeaderSize..]);
|
||||||
await stream.WriteAsync(owner.Memory[..Constants.MaxPacketSize]);
|
// await stream.WriteAsync(owner.Memory[..Constants.MaxPacketSize]);
|
||||||
header.Type = PacketType.Cap;
|
// header.Type = PacketType.Cap;
|
||||||
MemoryMarshal.Write(owner.Memory.Span, ref header);
|
// MemoryMarshal.Write(owner.Memory.Span, ref header);
|
||||||
cap.Serialize(owner.Memory.Span[Constants.HeaderSize..]);
|
// cap.Serialize(owner.Memory.Span[Constants.HeaderSize..]);
|
||||||
await stream.WriteAsync(owner.Memory[..Constants.MaxPacketSize]);
|
// await stream.WriteAsync(owner.Memory[..Constants.MaxPacketSize]);
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
if (reboundPackets.All(x => x != type)) continue;
|
if (reboundPackets.All(x => x != type)) continue;
|
||||||
header.Id = ownId;
|
header.Id = ownId;
|
||||||
MemoryMarshal.Write(owner.Memory.Span, ref header);
|
MemoryMarshal.Write(owner.Memory.Span, ref header);
|
||||||
|
|
Loading…
Reference in a new issue