-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -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); | ||
Core.Log.LogInfo("Prefab Name: " + item.PrefabName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know what throws here? Should it not be logged? |
||
} | ||
|
||
} | ||
} |
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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.