From 9cd4eaf775571bdd27b45201c1f9e153cc702bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6kberk=20Yalt=C4=B1rakl=C4=B1?= Date: Mon, 25 Apr 2016 19:34:32 +0300 Subject: [PATCH] Added list command --- TrueCraft/Commands/ListCommand.cs | 40 +++++++++++++++++++++++++++++++ TrueCraft/TrueCraft.csproj | 1 + 2 files changed, 41 insertions(+) create mode 100644 TrueCraft/Commands/ListCommand.cs diff --git a/TrueCraft/Commands/ListCommand.cs b/TrueCraft/Commands/ListCommand.cs new file mode 100644 index 0000000..2698bb1 --- /dev/null +++ b/TrueCraft/Commands/ListCommand.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/TrueCraft/TrueCraft.csproj b/TrueCraft/TrueCraft.csproj index 70ea6dc..e7a5667 100644 --- a/TrueCraft/TrueCraft.csproj +++ b/TrueCraft/TrueCraft.csproj @@ -67,6 +67,7 @@ +