private static void ClearRoom(AdminCommandArgs adminArgs, CommandArgs args) { if (adminArgs.Parameters.Length == 1) { ClearRoom(adminArgs.Parameters[0], args); } else { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); } }
private static void Help(AdminCommandArgs adminArgs, CommandArgs args) { var commandsBuilder = new StringBuilder(); commandsBuilder.AppendLine(); foreach (var command in TextCommands.Values) { commandsBuilder.AppendLine(command.ToString()); } ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandsList, commandsBuilder.ToString())); }
private static void RemoveMessage(AdminCommandArgs adminArgs, CommandArgs args) { if (adminArgs.Parameters.Length < 2) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } using (var server = ServerModel.Get()) { var name = adminArgs.Parameters[0]; var messageIds = adminArgs.Parameters .Skip(1) .Select(idStr => { if (!long.TryParse(idStr, out long messageId)) { return(-1); } return(messageId); }) .Where(id => id > 0) .ToArray(); if (messageIds.Length == 0) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } var room = server.Chat.TryGetRoom(name); if (room == null) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } foreach (var messageId in messageIds) { room.RemoveMessage(messageId); } foreach (var userId in room.Users) { ServerModel.Api.Perform(new ServerRemoveMessagesAction(userId, name, messageIds)); } } }
private static void Unban(AdminCommandArgs adminArgs, CommandArgs args) { if (adminArgs.Parameters.Length != 2) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } using (var server = ServerModel.Get()) { var nick = adminArgs.Parameters[0]; var thumbprint = adminArgs.Parameters[1]; var userId = new UserId(nick, thumbprint); ServerModel.Server.Bans.Unban(userId); } }
private static void ShowMessageId(AdminCommandArgs adminArgs, CommandArgs args) { if (adminArgs.Parameters.Length != 2) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } using (var server = ServerModel.Get()) { var roomName = adminArgs.Parameters[0]; var timeStr = adminArgs.Parameters[1]; var room = server.Chat.TryGetRoom(roomName); if (room == null) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } if (!DateTime.TryParse(timeStr, out DateTime time)) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } Message minMssage = null; foreach (var message in room.Messages) { if (minMssage == null) { minMssage = message; continue; } var diff = message.Time.Subtract(time); var minDiff = minMssage.Time.Subtract(time); if (Math.Abs(diff.TotalMilliseconds) < Math.Abs(minDiff.TotalMilliseconds)) { minMssage = message; } } ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandMessageId, minMssage.Id.ToString())); } }
protected override void OnRun(MessageContent content, CommandArgs args) { if (!string.Equals(content.Password, _password, StringComparison.Ordinal)) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.InvalidPassword)); return; } var adminArgs = new AdminCommandArgs(content.TextCommand); if (!TextCommands.TryGetValue(adminArgs.Command, out AdminCommand command)) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandNotFound)); return; } command.Run(adminArgs, args); }
private static void ShowBanned(AdminCommandArgs adminArgs, CommandArgs args) { if (adminArgs.Parameters.Length != 1) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } var nick = adminArgs.Parameters[0]; var commandsBuilder = new StringBuilder(); commandsBuilder.AppendLine(); foreach (var userId in ServerModel.Server.Bans.FindAll(nick)) { commandsBuilder.AppendLine(userId.ToString()); } ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandUsersList, commandsBuilder.ToString())); }
private static void Kick(AdminCommandArgs adminArgs, CommandArgs args) { if (adminArgs.Parameters.Length != 1) { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); return; } using (var server = ServerModel.Get()) { var nick = adminArgs.Parameters[0]; var user = server.Chat.TryGetUser(nick); if (user != null) { ServerModel.Api.Perform(new ServerRemoveUserAction(nick)); } else { ServerModel.Api.Perform(new ServerSendSystemMessageAction(args.ConnectionId, SystemMessageId.TextCommandInvalidParams)); } } }
private static void ClearMainRoom(AdminCommandArgs adminArgs, CommandArgs args) { ClearRoom(ServerChat.MainRoomName, args); }
public void Run(AdminCommandArgs adminArgs, CommandArgs args) { _command(adminArgs, args); }