mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-22 03:05:16 +00:00
Make some commands accept ids and partial names
This commit is contained in:
parent
b0b7bbf384
commit
c4c0616fb7
2 changed files with 9 additions and 5 deletions
|
@ -15,7 +15,7 @@ Run these commands in your shell:
|
|||
```shell
|
||||
git clone https://github.com/Sanae6/SmoOnlineServer
|
||||
cd SmoOnlineServer
|
||||
# replace run with build to only build the server
|
||||
# replace run with build to only build the server
|
||||
dotnet run --project Server/Server.csproj -c Release
|
||||
```
|
||||
If you ran `dotnet build` instead of `dotnet run`, you can find the binary at `Server/bin/net6.0/Release/Server.exe`
|
||||
|
|
|
@ -149,7 +149,8 @@ server.PacketHandler = (c, p) => {
|
|||
CommandHandler.RegisterCommand("rejoin", args => {
|
||||
bool moreThanOne = false;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (Client user in server.Clients.Where(c => c.Connected && args.Contains(c.Name))) {
|
||||
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)))) {
|
||||
if (moreThanOne) builder.Append(", ");
|
||||
builder.Append(user.Name);
|
||||
user.Dispose();
|
||||
|
@ -162,7 +163,8 @@ CommandHandler.RegisterCommand("rejoin", args => {
|
|||
CommandHandler.RegisterCommand("crash", args => {
|
||||
bool moreThanOne = false;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (Client user in server.Clients.Where(c => c.Connected && args.Contains(c.Name))) {
|
||||
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)))) {
|
||||
if (moreThanOne) builder.Append(", ");
|
||||
moreThanOne = true;
|
||||
builder.Append(user.Name);
|
||||
|
@ -183,7 +185,8 @@ CommandHandler.RegisterCommand("crash", args => {
|
|||
CommandHandler.RegisterCommand("ban", args => {
|
||||
bool moreThanOne = false;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (Client user in server.Clients.Where(c => c.Connected && args.Contains(c.Name))) {
|
||||
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)))) {
|
||||
if (moreThanOne) builder.Append(", ");
|
||||
moreThanOne = true;
|
||||
builder.Append(user.Name);
|
||||
|
@ -225,7 +228,8 @@ CommandHandler.RegisterCommand("send", args => {
|
|||
}
|
||||
|
||||
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();
|
||||
Client[] players = args[3] == "*" ? server.Clients.Where(c => c.Connected).ToArray() : server.Clients.Where(c => c.Connected && args[3..].Any(x => c.Name.StartsWith(x) ||
|
||||
(Guid.TryParse(x, out Guid result) && result == c.Id))).ToArray();
|
||||
Parallel.ForEachAsync(players, async (c, _) => {
|
||||
await c.Send(new ChangeStagePacket {
|
||||
Stage = stage,
|
||||
|
|
Loading…
Reference in a new issue