internal override void Process() { if (this.Connection.Avatar.Rank >= this.RequiredRank) { if (this.Parameters.Length >= 2) { try { if (Enum.TryParse(this.Parameters[1], out this.Rank)) { if (this.Parameters[0] == this.Tag) { LogicLong id = LogicTagUtil.ToLogicLong(this.Tag); LogicClientAvatar avatar = Avatars.Get(id); if (this.Rank > this.Connection.Avatar.Rank) { this.Connection.SendChatMessage("Target privileges are higher then yours."); } else { if (avatar != null) { avatar.SetRank(this.Rank); this.Connection.SendChatMessage($"{avatar.Name} now has the rank {this.Rank}"); } else { this.Help.AppendLine("Hashtags can only contain these characters:"); this.Help.AppendLine("Numbers: 0, 2, 8, 9"); this.Help.AppendLine("Letters: P, Y, L, Q, G, R, J, C, U, V"); this.Connection.SendChatMessage(this.Help.ToString()); } } } } else { this.Connection.SendChatMessage(this.Help.ToString()); } } catch (Exception exception) { this.Connection.SendChatMessage($"Failed with error {exception.Message}"); } } else { this.Connection.SendChatMessage(this.Help.ToString()); } } else { this.Connection.SendChatMessage("Insufficient privileges."); } }
/// <summary> /// Handles the request. /// </summary> private static void EndProcess(this HttpListenerContext context) { LogicLong player = LogicTagUtil.ToLogicLong(context.Request.QueryString["player"]); int debugCmd = LogicStringUtil.ConvertToInt(context.Request.QueryString["command"]); Connection connection = Avatars.Get(player).Connection; if (connection != null) { if (connection.IsConnected && LogicVersion.IsIntegration) { new AvailableServerCommandMessage(connection, new LogicDebugCommand(connection, debugCmd)).Send(); context.Response.Close(LogicStringUtil.GetBytes("OK"), true); } else { context.Response.Close(LogicStringUtil.GetBytes("Error: Connection.IsConnected == false or the server is not in integration mode"), true); } } else { context.Response.Close(LogicStringUtil.GetBytes("Error: Connection == null"), true); } }
/// <summary> /// Initializes a new instance of the <see cref="Parser"/> class. /// </summary> internal static void Init() { if (Parser.Initialized) { return; } new Thread(() => { while (true) { int cursorTop2 = Console.CursorTop = Console.WindowTop + Console.WindowHeight - 1; Console.Write($"root@{Constants.LocalIP.ToString().Split(":")[0]} > "); string[] command = Console.ReadLine()?.Split(' '); Console.SetCursorPosition(0, cursorTop2 - 1); Console.WriteLine(new string(' ', Console.BufferWidth)); Console.SetCursorPosition(0, cursorTop2 - 2); switch (command?[0].Replace("/", string.Empty)) { case "stats": { if (Loader.Initialized) { Console.WriteLine(); Console.WriteLine($"# {DateTime.Now.ToString("d")} ---- STATS ---- {DateTime.Now.ToString("t")} #"); Console.WriteLine("# ----------------------------------- #"); Console.WriteLine($"# Connected Sockets # {LogicStringUtil.IntToString(Connections.Count).Pad(15)} #"); Console.WriteLine($"# In-Memory Avatars # {LogicStringUtil.IntToString(Avatars.Count).Pad(15)} #"); Console.WriteLine($"# In-Memory Clans # {LogicStringUtil.IntToString(Alliances.Count).Pad(15)} #"); Console.WriteLine("# ----------------------------------- #"); } break; } case "setrank": { if (Loader.Initialized) { var tag = command[1]; var rank = (Rank)Enum.GetValues(typeof(Rank)).GetValue(LogicStringUtil.ConvertToInt(command[2])); LogicTagUtil.ToHighLow(tag, out int highId, out int lowId); var player = Avatars.Get(new LogicLong(highId, lowId)); player.SetRank(rank); } break; } case "sendDebugCmd": { if (Loader.Initialized && LogicVersion.IsIntegration) { var commandId = LogicStringUtil.ConvertToInt(command[1]); var playerId = command[2].Split('-'); var player = Avatars.Get(new LogicLong(LogicStringUtil.ConvertToInt(playerId[0]), LogicStringUtil.ConvertToInt(playerId[1]))); new AvailableServerCommandMessage(player.Connection, new LogicDebugCommand(player.Connection, commandId)).Send(); // <- saving is false for the purpose of testing - this does not work yet new OwnAvatarDataMessage(player.Connection).Send(); Console.WriteLine($"Sent Debug Command with ID {commandId} to player {player}"); } break; } case "clear": { Console.Clear(); break; } case "exit": case "shutdown": case "stop": { EventsHandler.Exit(); break; } default: { Console.WriteLine(); break; } } } }).Start(); Parser.Initialized = true; }