0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-22 03:05:16 +00:00

add short-names for kingdoms, sendall cmd

This commit is contained in:
CraftyBoss 2022-03-28 06:05:32 +00:00
parent 661763b23f
commit 4e05fe9e3f
4 changed files with 51 additions and 2 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ obj/
riderModule.iml
/_ReSharper.Caches/
.idea/
settings.json

View file

@ -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 <stage>";
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 <true/false>";
if (args.Length < 1)

View file

@ -21,4 +21,22 @@ public static class Constants {
.ToDictionary(type => type.GetCustomAttribute<PacketAttribute>()!.Type, type => type);
public static int HeaderSize { get; } = Marshal.SizeOf<PacketHeader>();
public static readonly Dictionary<string, string> MapNames = new Dictionary<string, string>() {
{"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"}
};
}

View file

@ -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;