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;
|
2022-02-18 01:56:12 +00:00
|
|
|
|
using Shared;
|
2022-02-14 19:45:58 +00:00
|
|
|
|
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>();
|
2022-02-22 04:05:13 +00:00
|
|
|
|
// int shineTx = 0; // used for logging
|
|
|
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
|
|
|
|
Task listenTask = server.Listen(cts.Token);
|
|
|
|
|
Logger consoleLogger = new Logger("Console");
|
2022-02-14 19:45:58 +00:00
|
|
|
|
|
2022-03-13 11:14:01 +00:00
|
|
|
|
server.ClientJoined += (c, _) => {
|
2022-02-14 19:45:58 +00:00
|
|
|
|
c.Metadata["shineSync"] = new ConcurrentBag<int>();
|
|
|
|
|
c.Metadata["loadedSave"] = false;
|
2022-03-01 21:08:53 +00:00
|
|
|
|
c.Metadata["scenario"] = 0;
|
2022-03-13 11:14:01 +00:00
|
|
|
|
c.Metadata["2d"] = false;
|
2022-03-31 19:48:31 +00:00
|
|
|
|
c.Metadata["speedrun"] = false;
|
2022-03-15 07:26:28 +00:00
|
|
|
|
foreach (Client client in server.Clients.Where(client => client.Metadata.ContainsKey("lastGamePacket")).ToArray()) {
|
2022-03-15 07:23:37 +00:00
|
|
|
|
try {
|
2022-04-04 20:43:44 +00:00
|
|
|
|
c.Send((GamePacket) client.Metadata["lastGamePacket"]!, client).Wait();
|
2022-03-15 07:23:37 +00:00
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
// lol who gives a fuck
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-22 09:17:48 +00:00
|
|
|
|
c.PacketTransformer += (_, packet) => {
|
2022-03-13 11:14:01 +00:00
|
|
|
|
if (Settings.Instance.Scenario.MergeEnabled && packet is GamePacket gamePacket) {
|
2022-03-31 19:48:31 +00:00
|
|
|
|
gamePacket.ScenarioNum = (byte?) c.Metadata["scenario"] ?? 200;
|
2022-03-13 11:14:01 +00:00
|
|
|
|
return gamePacket;
|
2022-03-01 21:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return packet;
|
|
|
|
|
};
|
2022-02-14 19:45:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async Task ClientSyncShineBag(Client client) {
|
2022-02-23 02:51:48 +00:00
|
|
|
|
try {
|
2022-03-31 19:48:31 +00:00
|
|
|
|
if ((bool?) client.Metadata["speedrun"] ?? false) return;
|
2022-03-15 07:23:37 +00:00
|
|
|
|
ConcurrentBag<int> clientBag = (ConcurrentBag<int>) (client.Metadata["shineSync"] ??= new ConcurrentBag<int>());
|
2022-03-15 06:47:51 +00:00
|
|
|
|
foreach (int shine in shineBag.Except(clientBag).ToArray()) {
|
|
|
|
|
clientBag.Add(shine);
|
2022-02-23 02:51:48 +00:00
|
|
|
|
await client.Send(new ShinePacket {
|
|
|
|
|
ShineId = shine
|
|
|
|
|
});
|
2022-03-04 04:24:33 +00:00
|
|
|
|
}
|
2022-03-15 05:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
catch {
|
2022-02-23 02:51:48 +00:00
|
|
|
|
// errors that can happen when sending will crash the server :)
|
|
|
|
|
}
|
2022-02-14 19:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async void SyncShineBag() {
|
2022-03-02 01:42:14 +00:00
|
|
|
|
try {
|
2022-03-04 04:24:33 +00:00
|
|
|
|
await Parallel.ForEachAsync(server.Clients.ToArray(), async (client, _) => await ClientSyncShineBag(client));
|
2022-03-15 05:59:23 +00:00
|
|
|
|
}
|
|
|
|
|
catch {
|
2022-03-02 01:42:14 +00:00
|
|
|
|
// errors that can happen shines change will crash the server :)
|
|
|
|
|
}
|
2022-02-14 19:45:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-14 20:40:42 +00:00
|
|
|
|
Timer timer = new Timer(120000);
|
|
|
|
|
timer.AutoReset = true;
|
|
|
|
|
timer.Enabled = true;
|
2022-02-18 01:56:12 +00:00
|
|
|
|
timer.Elapsed += (_, _) => { SyncShineBag(); };
|
2022-02-14 20:40:42 +00:00
|
|
|
|
timer.Start();
|
|
|
|
|
|
2022-03-01 21:08:53 +00:00
|
|
|
|
float MarioSize(bool is2d) {
|
|
|
|
|
return is2d ? 180 : 160;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 00:35:38 +00:00
|
|
|
|
server.PacketHandler = (c, p) => {
|
2022-02-14 19:45:58 +00:00
|
|
|
|
switch (p) {
|
2022-03-22 09:17:48 +00:00
|
|
|
|
case GamePacket gamePacket: {
|
|
|
|
|
c.Logger.Info($"Got game packet {gamePacket.Stage}->{gamePacket.ScenarioNum}");
|
|
|
|
|
c.Metadata["scenario"] = gamePacket.ScenarioNum;
|
|
|
|
|
c.Metadata["2d"] = gamePacket.Is2d;
|
|
|
|
|
c.Metadata["lastGamePacket"] = gamePacket;
|
2022-03-31 19:48:31 +00:00
|
|
|
|
switch (gamePacket.Stage) {
|
|
|
|
|
case "CapWorldHomeStage" when gamePacket.ScenarioNum == 0:
|
|
|
|
|
c.Metadata["speedrun"] = true;
|
2022-03-31 21:34:08 +00:00
|
|
|
|
((ConcurrentBag<int>) (c.Metadata["shineSync"] ??= new ConcurrentBag<int>())).Clear();
|
|
|
|
|
shineBag.Clear();
|
2022-04-04 04:29:34 +00:00
|
|
|
|
c.Logger.Info("Entered Cap on scenario 0, enabling speedrun flag");
|
2022-03-31 19:48:31 +00:00
|
|
|
|
break;
|
2022-03-31 21:34:08 +00:00
|
|
|
|
case "WaterfallWorldHomeStage":
|
2022-03-31 19:56:48 +00:00
|
|
|
|
bool wasSpeedrun = (bool) c.Metadata["speedrun"]!;
|
2022-03-31 19:48:31 +00:00
|
|
|
|
c.Metadata["speedrun"] = false;
|
2022-03-31 19:56:48 +00:00
|
|
|
|
if (wasSpeedrun)
|
|
|
|
|
Task.Run(async () => {
|
2022-04-04 04:29:34 +00:00
|
|
|
|
c.Logger.Info("Entered Cascade with speedrun mode on");
|
2022-03-31 19:56:48 +00:00
|
|
|
|
await Task.Delay(15000);
|
|
|
|
|
await ClientSyncShineBag(c);
|
|
|
|
|
});
|
2022-03-31 19:48:31 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-03-22 09:17:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TagPacket tagPacket: {
|
|
|
|
|
if ((tagPacket.UpdateType & TagPacket.TagUpdate.State) != 0) c.Metadata["seeking"] = tagPacket.IsIt;
|
|
|
|
|
if ((tagPacket.UpdateType & TagPacket.TagUpdate.Time) != 0) c.Metadata["time"] = new Time(tagPacket.Minutes, tagPacket.Seconds, DateTime.Now);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-02-14 19:45:58 +00:00
|
|
|
|
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-03-06 23:32:49 +00:00
|
|
|
|
case PlayerPacket playerPacket when Settings.Instance.Flip.Enabled
|
2022-03-04 04:24:33 +00:00
|
|
|
|
&& Settings.Instance.Flip.Pov is FlipOptions.Both or FlipOptions.Others
|
|
|
|
|
&& Settings.Instance.Flip.Players.Contains(c.Id): {
|
2022-03-13 11:14:01 +00:00
|
|
|
|
playerPacket.Position += Vector3.UnitY * MarioSize((bool) c.Metadata["2d"]);
|
2022-02-16 21:00:52 +00:00
|
|
|
|
playerPacket.Rotation *= Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationX(MathF.PI)) * Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(MathF.PI));
|
2022-02-16 00:35:38 +00:00
|
|
|
|
server.Broadcast(playerPacket, c);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-03-06 23:32:49 +00:00
|
|
|
|
case PlayerPacket playerPacket when Settings.Instance.Flip.Enabled
|
|
|
|
|
&& Settings.Instance.Flip.Pov is FlipOptions.Both or FlipOptions.Self
|
|
|
|
|
&& !Settings.Instance.Flip.Players.Contains(c.Id): {
|
2022-02-16 20:36:24 +00:00
|
|
|
|
server.BroadcastReplace(playerPacket, c, (from, to, sp) => {
|
2022-02-18 01:56:12 +00:00
|
|
|
|
if (Settings.Instance.Flip.Players.Contains(to.Id)) {
|
2022-03-13 11:14:01 +00:00
|
|
|
|
sp.Position += Vector3.UnitY * MarioSize((bool) c.Metadata["2d"]);
|
2022-02-16 20:36:24 +00:00
|
|
|
|
sp.Rotation *= Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationX(MathF.PI)) * Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(MathF.PI));
|
|
|
|
|
}
|
2022-02-18 01:56:12 +00:00
|
|
|
|
|
2022-02-16 20:36:24 +00:00
|
|
|
|
to.Send(sp, from);
|
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
};
|
2022-03-01 21:08:53 +00:00
|
|
|
|
|
2022-03-25 04:53:00 +00:00
|
|
|
|
CommandHandler.RegisterCommand("send", args => {
|
|
|
|
|
const string optionUsage = "Usage: send <stage> <id> <scenario[0..255]> <player/*>";
|
|
|
|
|
if (args.Length < 4)
|
|
|
|
|
return optionUsage;
|
|
|
|
|
|
|
|
|
|
string stage = args[0];
|
|
|
|
|
string id = args[1];
|
2022-03-28 06:05:32 +00:00
|
|
|
|
|
2022-04-05 19:35:13 +00:00
|
|
|
|
if (Constants.MapNames.TryGetValue(stage.ToLower(), out string? mapName)) {
|
2022-03-28 06:05:32 +00:00
|
|
|
|
stage = mapName;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-05 19:35:13 +00:00
|
|
|
|
if(!stage.Contains("Stage") && !stage.Contains("Zone")) {
|
|
|
|
|
return "Invalid Stage Name!";
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 06:05:32 +00:00
|
|
|
|
if (!sbyte.TryParse(args[2], out sbyte scenario)) return $"Invalid scenario number {args[2]} (range: [-128 to 127])";
|
2022-03-25 04:53:00 +00:00
|
|
|
|
Client[] players = args[3] == "*" ? server.Clients.Where(c => c.Connected).ToArray() : server.Clients.Where(c => c.Connected && args[3..].Contains(c.Name)).ToArray();
|
2022-03-31 19:48:31 +00:00
|
|
|
|
Parallel.ForEachAsync(players, async (c, _) => {
|
2022-03-25 04:53:00 +00:00
|
|
|
|
await c.Send(new ChangeStagePacket {
|
|
|
|
|
Stage = stage,
|
|
|
|
|
Id = id,
|
|
|
|
|
Scenario = scenario,
|
|
|
|
|
SubScenarioType = 0
|
|
|
|
|
});
|
|
|
|
|
}).Wait();
|
|
|
|
|
return $"Sent players to {stage}:{scenario}";
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-28 06:05:32 +00:00
|
|
|
|
CommandHandler.RegisterCommand("sendall", args => {
|
|
|
|
|
const string optionUsage = "Usage: sendall <stage>";
|
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
return optionUsage;
|
|
|
|
|
|
|
|
|
|
string stage = args[0];
|
|
|
|
|
|
2022-04-05 19:35:13 +00:00
|
|
|
|
if (Constants.MapNames.TryGetValue(stage.ToLower(), out string? mapName)) {
|
2022-03-28 06:05:32 +00:00
|
|
|
|
stage = mapName;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-05 19:35:13 +00:00
|
|
|
|
if(!stage.Contains("Stage") && !stage.Contains("Zone")) {
|
|
|
|
|
return "Invalid Stage Name!";
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 06:05:32 +00:00
|
|
|
|
Client[] players = server.Clients.Where(c => c.Connected).ToArray();
|
|
|
|
|
|
2022-03-31 19:48:31 +00:00
|
|
|
|
Parallel.ForEachAsync(players, async (c, _) => {
|
2022-03-28 06:05:32 +00:00
|
|
|
|
await c.Send(new ChangeStagePacket {
|
|
|
|
|
Stage = stage,
|
|
|
|
|
Id = "",
|
|
|
|
|
Scenario = -1,
|
|
|
|
|
SubScenarioType = 0
|
|
|
|
|
});
|
|
|
|
|
}).Wait();
|
|
|
|
|
|
|
|
|
|
return $"Sent players to {stage}:{-1}";
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-01 21:08:53 +00:00
|
|
|
|
CommandHandler.RegisterCommand("scenario", args => {
|
2022-03-31 19:48:31 +00:00
|
|
|
|
const string optionUsage = "Valid options: merge [true/false]";
|
2022-03-01 21:08:53 +00:00
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
return optionUsage;
|
|
|
|
|
switch (args[0]) {
|
|
|
|
|
case "merge" when args.Length == 2: {
|
|
|
|
|
if (bool.TryParse(args[1], out bool result)) {
|
|
|
|
|
Settings.Instance.Scenario.MergeEnabled = result;
|
|
|
|
|
Settings.SaveSettings();
|
|
|
|
|
return result ? "Enabled scenario merge" : "Disabled scenario merge";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return optionUsage;
|
|
|
|
|
}
|
2022-03-31 19:48:31 +00:00
|
|
|
|
case "merge" when args.Length == 1: {
|
2022-04-04 04:29:34 +00:00
|
|
|
|
return $"Scenario merging is {Settings.Instance.Scenario.MergeEnabled}";
|
2022-03-31 19:48:31 +00:00
|
|
|
|
}
|
2022-03-01 21:08:53 +00:00
|
|
|
|
default:
|
|
|
|
|
return optionUsage;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-02-22 21:28:51 +00:00
|
|
|
|
|
2022-03-15 05:59:23 +00:00
|
|
|
|
CommandHandler.RegisterCommand("tag", args => {
|
|
|
|
|
const string optionUsage = "Valid options:\n\ttime <user/*> <minutes[0-65535]> <seconds[0-59]>\n\tseeking <user/*> <true/false>\n\tstart <time> <seekers>";
|
|
|
|
|
if (args.Length < 3)
|
|
|
|
|
return optionUsage;
|
|
|
|
|
switch (args[0]) {
|
2022-03-15 07:01:37 +00:00
|
|
|
|
case "time" when args.Length == 4: {
|
2022-03-15 05:59:23 +00:00
|
|
|
|
if (args[1] != "*" && server.Clients.All(x => x.Name != args[1])) return $"Cannot find user {args[1]}";
|
|
|
|
|
Client? client = server.Clients.FirstOrDefault(x => x.Name == args[1]);
|
|
|
|
|
if (!ushort.TryParse(args[2], out ushort minutes)) return $"Invalid time for minutes {args[2]} (range: 0-65535)";
|
|
|
|
|
if (!byte.TryParse(args[3], out byte seconds) || seconds >= 60) return $"Invalid time for seconds {args[3]} (range: 0-59)";
|
|
|
|
|
TagPacket tagPacket = new TagPacket {
|
|
|
|
|
UpdateType = TagPacket.TagUpdate.Time,
|
|
|
|
|
Minutes = minutes,
|
|
|
|
|
Seconds = seconds
|
|
|
|
|
};
|
|
|
|
|
if (args[1] == "*")
|
|
|
|
|
server.Broadcast(tagPacket);
|
|
|
|
|
else
|
|
|
|
|
client?.Send(tagPacket);
|
|
|
|
|
return $"Set time for {(args[1] == "*" ? "everyone" : args[1])} to {minutes}:{seconds}";
|
|
|
|
|
}
|
|
|
|
|
case "seeking" when args.Length == 3: {
|
|
|
|
|
if (args[1] != "*" && server.Clients.All(x => x.Name != args[1])) return $"Cannot find user {args[1]}";
|
|
|
|
|
Client? client = server.Clients.FirstOrDefault(x => x.Name == args[1]);
|
|
|
|
|
if (!bool.TryParse(args[2], out bool seeking)) return $"Usage: tag seeking {args[1]} <true/false>";
|
|
|
|
|
TagPacket tagPacket = new TagPacket {
|
|
|
|
|
UpdateType = TagPacket.TagUpdate.State,
|
|
|
|
|
IsIt = seeking
|
|
|
|
|
};
|
|
|
|
|
if (args[1] == "*")
|
|
|
|
|
server.Broadcast(tagPacket);
|
|
|
|
|
else
|
|
|
|
|
client?.Send(tagPacket);
|
|
|
|
|
return $"Set {(args[1] == "*" ? "everyone" : args[1])} to {(seeking ? "seeker" : "hider")}";
|
|
|
|
|
}
|
|
|
|
|
case "start" when args.Length > 2: {
|
|
|
|
|
if (!byte.TryParse(args[1], out byte time)) return $"Invalid countdown seconds {args[1]} (range: 0-255)";
|
|
|
|
|
string[] seekerNames = args[2..];
|
|
|
|
|
Client[] seekers = server.Clients.Where(c => seekerNames.Contains(c.Name)).ToArray();
|
|
|
|
|
if (seekers.Length != seekerNames.Length)
|
|
|
|
|
return $"Couldn't find seeker{(seekerNames.Length > 1 ? "s" : "")}: {string.Join(", ", seekerNames.Where(name => server.Clients.All(c => c.Name != name)))}";
|
|
|
|
|
Task.Run(async () => {
|
|
|
|
|
int realTime = 1000 * time;
|
|
|
|
|
await Task.Delay(realTime);
|
|
|
|
|
await Task.WhenAll(
|
|
|
|
|
Parallel.ForEachAsync(seekers, async (seeker, _) =>
|
2022-03-31 22:21:20 +00:00
|
|
|
|
await server.Broadcast(new TagPacket {
|
2022-03-15 05:59:23 +00:00
|
|
|
|
UpdateType = TagPacket.TagUpdate.State,
|
|
|
|
|
IsIt = true
|
2022-03-31 22:21:20 +00:00
|
|
|
|
}, seeker)),
|
2022-03-15 05:59:23 +00:00
|
|
|
|
Parallel.ForEachAsync(server.Clients.Except(seekers), async (hider, _) =>
|
2022-03-31 22:21:20 +00:00
|
|
|
|
await server.Broadcast(new TagPacket {
|
2022-03-15 05:59:23 +00:00
|
|
|
|
UpdateType = TagPacket.TagUpdate.State,
|
2022-03-15 08:08:52 +00:00
|
|
|
|
IsIt = false
|
2022-03-31 22:21:20 +00:00
|
|
|
|
}, hider)
|
2022-03-15 05:59:23 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
consoleLogger.Info($"Started game with seekers {string.Join(", ", seekerNames)}");
|
|
|
|
|
});
|
|
|
|
|
return $"Starting game in {time} seconds with seekers {string.Join(", ", seekerNames)}";
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return optionUsage;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-15 20:44:46 +00:00
|
|
|
|
CommandHandler.RegisterCommand("list", _ => $"List: {string.Join("\n\t", server.Clients.Select(x => $"{x.Name} ({x.Id})"))}");
|
2021-11-29 04:04:34 +00:00
|
|
|
|
|
2022-02-18 01:56:12 +00:00
|
|
|
|
CommandHandler.RegisterCommand("flip", args => {
|
2022-03-15 05:59:23 +00:00
|
|
|
|
const string optionUsage = "Valid options: \n\tlist\n\tadd <user id>\n\tremove <user id>\n\tset <true/false>\n\tpov <both/self/others>";
|
2022-02-18 01:56:12 +00:00
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
return optionUsage;
|
|
|
|
|
switch (args[0]) {
|
|
|
|
|
case "list" when args.Length == 1:
|
|
|
|
|
return "User ids: " + string.Join(", ", Settings.Instance.Flip.Players.ToList());
|
|
|
|
|
case "add" when args.Length == 2: {
|
|
|
|
|
if (Guid.TryParse(args[1], out Guid result)) {
|
|
|
|
|
Settings.Instance.Flip.Players.Add(result);
|
|
|
|
|
Settings.SaveSettings();
|
|
|
|
|
return $"Added {result} to flipped players";
|
2022-02-18 02:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $"Invalid user id {args[1]}";
|
2022-02-18 01:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
case "remove" when args.Length == 2: {
|
|
|
|
|
if (Guid.TryParse(args[1], out Guid result)) {
|
|
|
|
|
string output = Settings.Instance.Flip.Players.Remove(result) ? $"Removed {result} to flipped players" : $"User {result} wasn't in the flipped players list";
|
|
|
|
|
Settings.SaveSettings();
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $"Invalid user id {args[1]}";
|
|
|
|
|
}
|
|
|
|
|
case "set" when args.Length == 2: {
|
|
|
|
|
if (bool.TryParse(args[1], out bool result)) {
|
2022-03-06 23:32:49 +00:00
|
|
|
|
Settings.Instance.Flip.Enabled = result;
|
|
|
|
|
Settings.SaveSettings();
|
|
|
|
|
return result ? "Enabled player flipping" : "Disabled player flipping";
|
2022-02-18 01:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return optionUsage;
|
|
|
|
|
}
|
|
|
|
|
case "pov" when args.Length == 2: {
|
|
|
|
|
if (Enum.TryParse(args[1], true, out FlipOptions result)) {
|
|
|
|
|
Settings.Instance.Flip.Pov = result;
|
|
|
|
|
Settings.SaveSettings();
|
|
|
|
|
return $"Point of view set to {result}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return optionUsage;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return optionUsage;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-18 02:39:48 +00:00
|
|
|
|
CommandHandler.RegisterCommand("shine", args => {
|
2022-03-31 00:34:47 +00:00
|
|
|
|
const string optionUsage = "Valid options: list, clear, sync, send";
|
2022-02-18 01:56:12 +00:00
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
return optionUsage;
|
|
|
|
|
switch (args[0]) {
|
|
|
|
|
case "list" when args.Length == 1:
|
|
|
|
|
return $"Shines: {string.Join(", ", shineBag)}";
|
2022-02-23 02:51:48 +00:00
|
|
|
|
case "clear" when args.Length == 1:
|
|
|
|
|
shineBag.Clear();
|
2022-03-01 21:08:53 +00:00
|
|
|
|
foreach (ConcurrentBag<int> playerBag in server.Clients.Select(serverClient => (ConcurrentBag<int>) serverClient.Metadata["shineSync"])) playerBag.Clear();
|
|
|
|
|
|
2022-02-23 02:51:48 +00:00
|
|
|
|
return "Cleared shine bags";
|
2022-03-15 20:44:46 +00:00
|
|
|
|
case "sync" when args.Length == 1:
|
|
|
|
|
SyncShineBag();
|
|
|
|
|
return "Synced shine bag automatically";
|
2022-03-31 00:34:47 +00:00
|
|
|
|
case "send" when args.Length >= 3:
|
2022-03-31 19:56:48 +00:00
|
|
|
|
if (int.TryParse(args[1], out int id)) {
|
2022-03-31 00:34:47 +00:00
|
|
|
|
Client[] players = args[2] == "*" ? server.Clients.Where(c => c.Connected).ToArray() : server.Clients.Where(c => c.Connected && args[3..].Contains(c.Name)).ToArray();
|
2022-03-31 19:56:48 +00:00
|
|
|
|
Parallel.ForEachAsync(players, async (c, _) => {
|
2022-03-31 00:34:47 +00:00
|
|
|
|
await c.Send(new ShinePacket {
|
|
|
|
|
ShineId = id
|
|
|
|
|
});
|
|
|
|
|
}).Wait();
|
|
|
|
|
return $"Sent Shine Num {id}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return optionUsage;
|
2022-02-18 01:56:12 +00:00
|
|
|
|
default:
|
|
|
|
|
return optionUsage;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-18 02:39:48 +00:00
|
|
|
|
CommandHandler.RegisterCommand("loadsettings", _ => {
|
|
|
|
|
Settings.LoadSettings();
|
|
|
|
|
return "Loaded settings.json";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CommandHandler.RegisterCommand("savesettings", _ => {
|
|
|
|
|
Settings.SaveSettings();
|
|
|
|
|
return "Saved settings.json";
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-22 04:05:13 +00:00
|
|
|
|
Console.CancelKeyPress += (_, e) => {
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
consoleLogger.Info("Received Ctrl+C");
|
|
|
|
|
cts.Cancel();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CommandHandler.RegisterCommand("exit", _ => {
|
|
|
|
|
cts.Cancel();
|
|
|
|
|
return "Shutting down clients";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CommandHandler.RegisterCommand("quit", _ => {
|
|
|
|
|
cts.Cancel();
|
|
|
|
|
return "Shutting down clients";
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-16 00:35:38 +00:00
|
|
|
|
Task.Run(() => {
|
2022-02-22 04:05:13 +00:00
|
|
|
|
consoleLogger.Info("Run help command for valid commands.");
|
2022-02-16 00:35:38 +00:00
|
|
|
|
while (true) {
|
2022-02-18 01:56:12 +00:00
|
|
|
|
string? text = Console.ReadLine();
|
2022-03-15 05:59:23 +00:00
|
|
|
|
if (text != null) {
|
|
|
|
|
foreach (string returnString in CommandHandler.GetResult(text).ReturnStrings) {
|
|
|
|
|
consoleLogger.Info(returnString);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-16 00:35:38 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-22 04:05:13 +00:00
|
|
|
|
await listenTask;
|