Merge pull request #247 from gkbrk/list_command

Added list command
This commit is contained in:
Drew DeVault 2016-04-26 13:37:54 -04:00
commit 9ca7bcabca
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,40 @@
using System;
using TrueCraft.API.Networking;
using System.Text;
namespace TrueCraft.Commands
{
public class ListCommand : Command
{
public override string Name
{
get { return "list"; }
}
public override string Description
{
get { return "Lists online players"; }
}
public override void Handle(IRemoteClient client, string alias, string[] arguments)
{
StringBuilder listMessage = new StringBuilder("Currently connected players: ");
foreach (IRemoteClient c in client.Server.Clients)
{
if (listMessage.Length + c.Username.Length + 2 >= 120)
{
client.SendMessage(listMessage.ToString());
listMessage.Clear();
}
listMessage.AppendFormat("{0}, ", c.Username);
}
listMessage.Remove(listMessage.Length - 2, 2);
client.SendMessage(listMessage.ToString());
}
public override void Help(IRemoteClient client, string alias, string[] arguments)
{
client.SendMessage("Correct usage is /" + alias);
}
}
}

View File

@ -67,6 +67,7 @@
<Compile Include="ServerConfiguration.cs" />
<Compile Include="MobManager.cs" />
<Compile Include="Rules\OverworldSpawnRules.cs" />
<Compile Include="Commands\ListCommand.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>