mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-25 04:35:18 +00:00
Add wildcard to rejoin, crash, ban commands
This commit is contained in:
parent
f9c20e73a8
commit
72061215ce
1 changed files with 32 additions and 20 deletions
|
@ -16,8 +16,9 @@ DiscordBot bot = new DiscordBot();
|
||||||
await bot.Run();
|
await bot.Run();
|
||||||
|
|
||||||
server.ClientJoined += (c, _) => {
|
server.ClientJoined += (c, _) => {
|
||||||
if (Settings.Instance.BanList.Enabled && (Settings.Instance.BanList.Players.Contains(c.Id) ||
|
if (Settings.Instance.BanList.Enabled
|
||||||
Settings.Instance.BanList.IpAddresses.Contains(
|
&& (Settings.Instance.BanList.Players.Contains(c.Id)
|
||||||
|
|| Settings.Instance.BanList.IpAddresses.Contains(
|
||||||
((IPEndPoint) c.Socket!.RemoteEndPoint!).Address.ToString())))
|
((IPEndPoint) c.Socket!.RemoteEndPoint!).Address.ToString())))
|
||||||
throw new Exception($"Banned player attempted join: {c.Name}");
|
throw new Exception($"Banned player attempted join: {c.Name}");
|
||||||
c.Metadata["shineSync"] = new ConcurrentBag<int>();
|
c.Metadata["shineSync"] = new ConcurrentBag<int>();
|
||||||
|
@ -125,8 +126,8 @@ server.PacketHandler = (c, p) => {
|
||||||
&& Settings.Instance.Flip.Pov is FlipOptions.Both or FlipOptions.Others
|
&& Settings.Instance.Flip.Pov is FlipOptions.Both or FlipOptions.Others
|
||||||
&& Settings.Instance.Flip.Players.Contains(c.Id): {
|
&& Settings.Instance.Flip.Players.Contains(c.Id): {
|
||||||
playerPacket.Position += Vector3.UnitY * MarioSize((bool) c.Metadata["2d"]);
|
playerPacket.Position += Vector3.UnitY * MarioSize((bool) c.Metadata["2d"]);
|
||||||
playerPacket.Rotation *= Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationX(MathF.PI)) *
|
playerPacket.Rotation *= Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationX(MathF.PI))
|
||||||
Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(MathF.PI));
|
* Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(MathF.PI));
|
||||||
server.Broadcast(playerPacket, c);
|
server.Broadcast(playerPacket, c);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -136,8 +137,8 @@ server.PacketHandler = (c, p) => {
|
||||||
server.BroadcastReplace(playerPacket, c, (from, to, sp) => {
|
server.BroadcastReplace(playerPacket, c, (from, to, sp) => {
|
||||||
if (Settings.Instance.Flip.Players.Contains(to.Id)) {
|
if (Settings.Instance.Flip.Players.Contains(to.Id)) {
|
||||||
sp.Position += Vector3.UnitY * MarioSize((bool) c.Metadata["2d"]);
|
sp.Position += Vector3.UnitY * MarioSize((bool) c.Metadata["2d"]);
|
||||||
sp.Rotation *= Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationX(MathF.PI)) *
|
sp.Rotation *= Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationX(MathF.PI))
|
||||||
Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(MathF.PI));
|
* Quaternion.CreateFromRotationMatrix(Matrix4x4.CreateRotationY(MathF.PI));
|
||||||
}
|
}
|
||||||
|
|
||||||
to.Send(sp, from);
|
to.Send(sp, from);
|
||||||
|
@ -152,22 +153,28 @@ server.PacketHandler = (c, p) => {
|
||||||
CommandHandler.RegisterCommand("rejoin", args => {
|
CommandHandler.RegisterCommand("rejoin", args => {
|
||||||
bool moreThanOne = false;
|
bool moreThanOne = false;
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
foreach (Client user in server.Clients.Where(c => c.Connected && args.Any(x => c.Name.StartsWith(x) ||
|
Client[] clients = (args.Length == 1 && args[0] == "*"
|
||||||
(Guid.TryParse(x, out Guid result) && result == c.Id)))) {
|
? server.Clients.Where(c =>
|
||||||
|
c.Connected && args.Any(x => c.Name.StartsWith(x) || (Guid.TryParse(x, out Guid result) && result == c.Id)))
|
||||||
|
: server.Clients.Where(c => c.Connected)).ToArray();
|
||||||
|
foreach (Client user in clients) {
|
||||||
if (moreThanOne) builder.Append(", ");
|
if (moreThanOne) builder.Append(", ");
|
||||||
builder.Append(user.Name);
|
builder.Append(user.Name);
|
||||||
user.Dispose();
|
user.Dispose();
|
||||||
moreThanOne = true;
|
moreThanOne = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return moreThanOne ? $"Caused {builder} to rejoin" : "Usage: rejoin <usernames...>";
|
return clients.Length > 0 ? $"Caused {builder} to rejoin" : "Usage: rejoin <usernames...>";
|
||||||
});
|
});
|
||||||
|
|
||||||
CommandHandler.RegisterCommand("crash", args => {
|
CommandHandler.RegisterCommand("crash", args => {
|
||||||
bool moreThanOne = false;
|
bool moreThanOne = false;
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
foreach (Client user in server.Clients.Where(c => c.Connected && args.Any(x => c.Name.StartsWith(x) ||
|
Client[] clients = (args.Length == 1 && args[0] == "*"
|
||||||
(Guid.TryParse(x, out Guid result) && result == c.Id)))) {
|
? server.Clients.Where(c =>
|
||||||
|
c.Connected && args.Any(x => c.Name.StartsWith(x) || (Guid.TryParse(x, out Guid result) && result == c.Id)))
|
||||||
|
: server.Clients.Where(c => c.Connected)).ToArray();
|
||||||
|
foreach (Client user in clients) {
|
||||||
if (moreThanOne) builder.Append(", ");
|
if (moreThanOne) builder.Append(", ");
|
||||||
moreThanOne = true;
|
moreThanOne = true;
|
||||||
builder.Append(user.Name);
|
builder.Append(user.Name);
|
||||||
|
@ -182,14 +189,18 @@ CommandHandler.RegisterCommand("crash", args => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return moreThanOne ? $"Crashed {builder}" : "Usage: crash <usernames...>";
|
return clients.Length > 0 ? $"Crashed {builder}" : "Usage: crash <usernames...>";
|
||||||
});
|
});
|
||||||
|
|
||||||
CommandHandler.RegisterCommand("ban", args => {
|
CommandHandler.RegisterCommand("ban", args => {
|
||||||
bool moreThanOne = false;
|
bool moreThanOne = false;
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
foreach (Client user in server.Clients.Where(c => c.Connected && args.Any(x => c.Name.StartsWith(x) ||
|
|
||||||
(Guid.TryParse(x, out Guid result) && result == c.Id)))) {
|
Client[] clients = (args.Length == 1 && args[0] == "*"
|
||||||
|
? server.Clients.Where(c =>
|
||||||
|
c.Connected && args.Any(x => c.Name.StartsWith(x) || (Guid.TryParse(x, out Guid result) && result == c.Id)))
|
||||||
|
: server.Clients.Where(c => c.Connected)).ToArray();
|
||||||
|
foreach (Client user in clients) {
|
||||||
if (moreThanOne) builder.Append(", ");
|
if (moreThanOne) builder.Append(", ");
|
||||||
moreThanOne = true;
|
moreThanOne = true;
|
||||||
builder.Append(user.Name);
|
builder.Append(user.Name);
|
||||||
|
@ -207,7 +218,7 @@ CommandHandler.RegisterCommand("ban", args => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moreThanOne) {
|
if (clients.Length > 0) {
|
||||||
Settings.SaveSettings();
|
Settings.SaveSettings();
|
||||||
return $"Banned {builder}.";
|
return $"Banned {builder}.";
|
||||||
}
|
}
|
||||||
|
@ -235,9 +246,10 @@ CommandHandler.RegisterCommand("send", args => {
|
||||||
return $"Invalid scenario number {args[2]} (range: [-1 to 127])";
|
return $"Invalid scenario number {args[2]} (range: [-1 to 127])";
|
||||||
Client[] players = args[3] == "*"
|
Client[] players = args[3] == "*"
|
||||||
? server.Clients.Where(c => c.Connected).ToArray()
|
? server.Clients.Where(c => c.Connected).ToArray()
|
||||||
: server.Clients.Where(c => c.Connected && args[3..].Any(x => c.Name.StartsWith(x) ||
|
: server.Clients.Where(c =>
|
||||||
(Guid.TryParse(x, out Guid result) &&
|
c.Connected
|
||||||
result == c.Id))).ToArray();
|
&& args[3..].Any(x => c.Name.StartsWith(x) || (Guid.TryParse(x, out Guid result) && result == c.Id)))
|
||||||
|
.ToArray();
|
||||||
Parallel.ForEachAsync(players, async (c, _) => {
|
Parallel.ForEachAsync(players, async (c, _) => {
|
||||||
await c.Send(new ChangeStagePacket {
|
await c.Send(new ChangeStagePacket {
|
||||||
Stage = stage,
|
Stage = stage,
|
||||||
|
|
Loading…
Reference in a new issue