2022-02-14 19:45:58 +00:00
|
|
|
|
using System.Collections.Concurrent;
|
2022-02-16 00:35:38 +00:00
|
|
|
|
using System.Numerics;
|
2022-02-14 19:45:58 +00:00
|
|
|
|
using Server;
|
|
|
|
|
using Shared.Packet.Packets;
|
2022-02-14 20:40:42 +00:00
|
|
|
|
using Timer = System.Timers.Timer;
|
2022-02-14 19:45:58 +00:00
|
|
|
|
|
|
|
|
|
Server.Server server = new Server.Server();
|
2022-02-14 20:40:42 +00:00
|
|
|
|
HashSet<int> shineBag = new HashSet<int>();
|
|
|
|
|
int shineTx = 0; // used for logging
|
2022-02-14 19:45:58 +00:00
|
|
|
|
|
|
|
|
|
server.ClientJoined += async (c, type) => {
|
|
|
|
|
c.Metadata["shineSync"] = new ConcurrentBag<int>();
|
|
|
|
|
c.Metadata["loadedSave"] = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async Task ClientSyncShineBag(Client client) {
|
|
|
|
|
foreach (int shine in shineBag.Except((ConcurrentBag<int>) client.Metadata["shineSync"]))
|
|
|
|
|
await client.Send(new ShinePacket {
|
|
|
|
|
ShineId = shine
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async void SyncShineBag() {
|
|
|
|
|
await Parallel.ForEachAsync(server.Clients, async (client, _) => {
|
|
|
|
|
await ClientSyncShineBag(client);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-14 20:40:42 +00:00
|
|
|
|
Timer timer = new Timer(120000);
|
|
|
|
|
timer.AutoReset = true;
|
|
|
|
|
timer.Enabled = true;
|
|
|
|
|
timer.Elapsed += (_, _) => {
|
|
|
|
|
SyncShineBag();
|
|
|
|
|
};
|
|
|
|
|
timer.Start();
|
2022-02-16 00:35:38 +00:00
|
|
|
|
bool piss = false;
|
2022-02-14 20:40:42 +00:00
|
|
|
|
|
2022-02-16 00:35:38 +00:00
|
|
|
|
// Guid lycel = Guid.Parse("d5feae62-2e71-1000-88fd-597ea147ae88");
|
|
|
|
|
Guid lycel = Guid.Parse("5e1f9db4-1c27-1000-a421-4701972e443e");
|
|
|
|
|
|
|
|
|
|
server.PacketHandler = (c, p) => {
|
2022-02-14 19:45:58 +00:00
|
|
|
|
switch (p) {
|
|
|
|
|
case CostumePacket:
|
2022-02-16 00:35:38 +00:00
|
|
|
|
ClientSyncShineBag(c);
|
2022-02-14 19:45:58 +00:00
|
|
|
|
c.Metadata["loadedSave"] = true;
|
|
|
|
|
break;
|
|
|
|
|
case ShinePacket shinePacket: {
|
2022-02-16 00:35:38 +00:00
|
|
|
|
if (c.Metadata["loadedSave"] is false) break;
|
2022-02-14 19:45:58 +00:00
|
|
|
|
ConcurrentBag<int> playerBag = (ConcurrentBag<int>) c.Metadata["shineSync"];
|
|
|
|
|
shineBag.Add(shinePacket.ShineId);
|
2022-02-16 00:35:38 +00:00
|
|
|
|
if (playerBag.Contains(shinePacket.ShineId)) break;
|
2022-02-15 20:26:50 +00:00
|
|
|
|
c.Logger.Info($"Got shine {shinePacket.ShineId}");
|
2022-02-14 19:45:58 +00:00
|
|
|
|
playerBag.Add(shinePacket.ShineId);
|
|
|
|
|
SyncShineBag();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-02-16 00:35:38 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2022-02-14 19:45:58 +00:00
|
|
|
|
}
|
2022-02-16 00:35:38 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
2022-02-14 19:45:58 +00:00
|
|
|
|
};
|
2021-11-29 04:04:34 +00:00
|
|
|
|
|
2022-02-16 00:35:38 +00:00
|
|
|
|
Task.Run(() => {
|
|
|
|
|
while (true) {
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
piss = !piss;
|
|
|
|
|
server.Logger.Warn($"Lycel flipped to {piss}");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-29 04:04:34 +00:00
|
|
|
|
await server.Listen(1027);
|