Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved several commands from RPGMods #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Commands/SearchCommands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -56,4 +56,21 @@ public static void GiveItem(ChatCommandContext ctx, string search, int page = 1)
Core.LogException(e);
}
}


[Command("List All Items", "LAI", adminOnly: true)]
public static void listAllItems(ChatCommandContext ctx) {
var gameDataSystem = Core.Server.GetExistingSystem<GameDataSystem>();
var managed = gameDataSystem.ManagedDataRegistry;

foreach (var entry in gameDataSystem.ItemHashLookupMap) {
try {
var item = managed.GetOrDefault<ManagedItemData>(entry.Key);
ctx.Reply(item.PrefabName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of messages to send. I'd prefer for performance that it send fewer messages with newlines. I'm personally not sure that we should have both search and list items. It makes me think there's improvements that the search needs if it's not showing enough information.

Core.Log.LogInfo("Prefab Name: " + item.PrefabName);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this needs to be logged with each call.


} catch { }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what throws here? Should it not be logged?

}

}
}
82 changes: 82 additions & 0 deletions Commands/ServerCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using ProjectM.Network;
using Unity.Collections;
using Unity.Entities;

using VampireCommandFramework;

namespace CommunityCommands.Commands;
public class ServerCommands {
public static class Shutdown {
[Command("shutdown", shortHand: "quit", description: "Trigger the exit signal & shutdown the server.", adminOnly: true)]
public static void Initialize() {
Copy link
Owner

@decaprime decaprime Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? VCF commands should require ICommandContext

UnityEngine.Application.Quit();
}
}

public static class Kick {
Copy link
Owner

@decaprime decaprime Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reference the existing code in this project for examples. You should utilize the existing converters and systems for finding players for example.

[Command("kick", "kick <playername>", "Kick the specified player out of the server.", adminOnly: true)]
public static void Initialize(ICommandContext ctx, string name) {


if (FindPlayer(name, true, out _, out var targetUserEntity)) {
KickPlayer(targetUserEntity);
ctx.Reply($"Player \"{name}\" has been kicked from server.");
} else {
ctx.Reply("Specified player not found.");
}
}
public static bool FindPlayer(string name, bool mustOnline, out Entity playerEntity, out Entity userEntity) {
foreach (var UsersEntity in Core.EntityManager.CreateEntityQuery(ComponentType.ReadOnly<User>()).ToEntityArray(Allocator.Temp)) {
var target_component = Core.EntityManager.GetComponentData<User>(UsersEntity);
if (mustOnline) {
if (!target_component.IsConnected) continue;
}

string CharName = target_component.CharacterName.ToString();
if (CharName.Equals(name)) {
userEntity = UsersEntity;
playerEntity = target_component.LocalCharacter._Entity;
return true;
}
}
playerEntity = new Entity();
userEntity = new Entity();
return false;
}
public static void KickPlayer(Entity userEntity) {
EntityManager em = Core.Server.EntityManager;
var userData = em.GetComponentData<User>(userEntity);
int index = userData.Index;

var entity = em.CreateEntity(
ComponentType.ReadOnly<NetworkEventType>(),
ComponentType.ReadOnly<SendEventToUser>(),
ComponentType.ReadOnly<KickEvent>()
);

var KickEvent = new KickEvent() {
PlatformId = userData.PlatformId
};

em.SetComponentData<SendEventToUser>(entity, new() {
UserIndex = index
});
em.SetComponentData<NetworkEventType>(entity, new() {
EventId = NetworkEvents.EventId_KickEvent,
IsAdminEvent = false,
IsDebugEvent = false
});

em.SetComponentData(entity, KickEvent);
}
}

public static class Ping {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above remove wrapper class, please format code.

[Command("ping", "p", "ping", "Shows your latency.")]
public static void Initialize(ChatCommandContext ctx) {
var ping = Core.EntityManager.GetComponentData<Latency>(ctx.Event.SenderCharacterEntity).Value;
ctx.Reply($"Your latency is <color=#ffff00>{ping}</color>s");
}
}

}