From 4e05fe9e3fed98269ea02fa58c9c0c6e047a8724 Mon Sep 17 00:00:00 2001 From: CraftyBoss Date: Mon, 28 Mar 2022 06:05:32 +0000 Subject: [PATCH] add short-names for kingdoms, sendall cmd --- .gitignore | 1 + Server/Program.cs | 32 +++++++++++++++++++++- Shared/Constants.cs | 18 ++++++++++++ Shared/Packet/Packets/ChangeStagePacket.cs | 2 +- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 39c9242..ff742a2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ obj/ riderModule.iml /_ReSharper.Caches/ .idea/ +settings.json diff --git a/Server/Program.cs b/Server/Program.cs index c60f73c..f4ce75e 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -131,7 +131,12 @@ CommandHandler.RegisterCommand("send", args => { string stage = args[0]; string id = args[1]; - if (!byte.TryParse(args[2], out byte scenario)) return $"Invalid scenario number {args[2]} (range: [0-255])"; + + if (Constants.MapNames.TryGetValue(stage, out string? mapName)) { + stage = mapName; + } + + if (!sbyte.TryParse(args[2], out sbyte scenario)) return $"Invalid scenario number {args[2]} (range: [-128 to 127])"; Client[] players = args[3] == "*" ? server.Clients.Where(c => c.Connected).ToArray() : server.Clients.Where(c => c.Connected && args[3..].Contains(c.Name)).ToArray(); Parallel.ForEachAsync(players, async (c,_) => { await c.Send(new ChangeStagePacket { @@ -144,6 +149,31 @@ CommandHandler.RegisterCommand("send", args => { return $"Sent players to {stage}:{scenario}"; }); +CommandHandler.RegisterCommand("sendall", args => { + const string optionUsage = "Usage: sendall "; + if (args.Length < 1) + return optionUsage; + + string stage = args[0]; + + if (Constants.MapNames.TryGetValue(stage, out string? mapName)) { + stage = mapName; + } + + Client[] players = server.Clients.Where(c => c.Connected).ToArray(); + + Parallel.ForEachAsync(players, async (c,_) => { + await c.Send(new ChangeStagePacket { + Stage = stage, + Id = "", + Scenario = -1, + SubScenarioType = 0 + }); + }).Wait(); + + return $"Sent players to {stage}:{-1}"; +}); + CommandHandler.RegisterCommand("scenario", args => { const string optionUsage = "Valid options: merge "; if (args.Length < 1) diff --git a/Shared/Constants.cs b/Shared/Constants.cs index 1efa180..d47a413 100644 --- a/Shared/Constants.cs +++ b/Shared/Constants.cs @@ -21,4 +21,22 @@ public static class Constants { .ToDictionary(type => type.GetCustomAttribute()!.Type, type => type); public static int HeaderSize { get; } = Marshal.SizeOf(); + + public static readonly Dictionary MapNames = new Dictionary() { + {"Cap", "CapWorldHomeStage"}, + {"Cascade", "WaterfallWorldHomeStage"}, + {"Sand", "SandWorldHomeStage"}, + {"Lake", "LakeWorldHomeStage"}, + {"Wooded", "ForestWorldHomeStage"}, + {"Cloud", "CloudWorldHomeStage"}, + {"Lost", "ClashWorldHomeStage"}, + {"Metro", "CityWorldHomeStage"}, + {"Sea", "SeaWorldHomeStage"}, + {"Snow", "SnowWorldHomeStage"}, + {"Lunch", "LavaWorldHomeStage"}, + {"Ruined", "BossRaidWorldHomeStage"}, + {"Bowser", "SkyWorldHomeStage"}, + {"Moon", "MoonWorldHomeStage"}, + {"Mush", "PeachWorldHomeStage"} + }; } \ No newline at end of file diff --git a/Shared/Packet/Packets/ChangeStagePacket.cs b/Shared/Packet/Packets/ChangeStagePacket.cs index 0cab444..1f302d2 100644 --- a/Shared/Packet/Packets/ChangeStagePacket.cs +++ b/Shared/Packet/Packets/ChangeStagePacket.cs @@ -9,7 +9,7 @@ public struct ChangeStagePacket : IPacket { private const int StageSize = 0x30; public string Stage = ""; public string Id = ""; - public byte Scenario = 0; + public sbyte Scenario = 0; public byte SubScenarioType = 0; public ChangeStagePacket() { } public short Size => 0x44;