internal override IPromise <Nothing> Dispatch(PlayerHandle sender, CommandDomain domain, string tag, IEnumerable <string> arguments) { if (arguments.Count() == 0 || tag.Equals("/aalert") && arguments.Count() < 2) { return(this.dispatcher.InvalidUsage(domain)); } string message = ""; PlayerHandle[] players = null; lock (this.manager) { if (tag.Equals("/aalert")) { var player = CommandUtils.GetPlayer(arguments.First(), domain, this.manager); if (player == null) { return(this.dispatcher.Error(domain, Strings.PLAYER_NOT_FOUND, arguments.First())); } players = new PlayerHandle[] { player }; message = String.Join(" ", arguments.Skip(1)); } else { players = this.manager.World.Players.ToArray(); message = String.Join(" ", arguments); } } var promises = new List <IPromise <Nothing> >(); foreach (var player in players) { try { promises.Add(this.loginServer.Emit(player.Token, "alert", message)); } catch (LoginServerListener.NotFoundException) { promises.Add(player.Stream.Write(Responses.MakeshiftAlert(message))); } } return(new CombinedPromise <Nothing>(promises)); }
internal override IPromise <Nothing> Dispatch(PlayerHandle sender, CommandDomain domain, string tag, IEnumerable <string> arguments) { if (arguments.Count() < 1) { return(this.dispatcher.InvalidUsage(domain)); } var name = arguments.ElementAt(0); var reason = CommandUtils.GetText(arguments.Skip(1)) ?? Strings.REASON_NONE; if (name.Equals("\\all")) { List <PlayerHandle> players; lock (this.manager) { players = new List <PlayerHandle>(this.manager.World.Players); } foreach (var handle in players) { try { this.manager.Sink(this.manager.KickPlayer(handle, reason)); } catch (Exception e) { Log.Warning("Failed to kick player during kick-all: {exception}", e); } } return(Nothing.Resolved()); } else { PlayerHandle player = CommandUtils.GetPlayer(arguments.FirstOrDefault() ?? ".", domain, this.manager); if (player == null) { return(this.dispatcher.Error(domain, Strings.PLAYER_NOT_FOUND, arguments.First())); } return(this.manager.KickPlayer(player, reason) .Then(a => this.dispatcher.Output(domain, Strings.PLAYER_HAS_BEEN_KICKED, arguments.First()))); } }
internal IPromise <Nothing> status(PlayerHandle sender, CommandDomain domain, string name, string status) { PlayerHandle player = CommandUtils.GetPlayer(name, domain, this.manager); if (player != null) { name = player.Name; } Character character; try { character = this.characterService.Find(name); } catch (CharacterService.NotFoundException) { return(this.dispatcher.Error(domain, Strings.PLAYER_NOT_FOUND, name)); } User user = null; try { user = this.loginService.FindUser(character.UserId); } catch (LoginService.NotFoundException) { return(this.dispatcher.Error(domain, Strings.USER_HAS_NOT_BEEN_FOUND_FOR_PLAYER)); } if (user != null && user.AdminFlags > 0) { return(this.dispatcher.Error(domain, Strings.FORBIDDEN)); } this.loginService.UpdateStatus(user, status); return(this.dispatcher.Output(domain, Strings.STATUS_FOR_PLAYER_HAS_BEEN_SET, name, status)); }
internal override IPromise <Nothing> Dispatch(PlayerHandle sender, CommandDomain domain, string tag, IEnumerable <string> arguments) { var currentLobby = sender.CurrentLobby; if (currentLobby == null || !currentLobby.IsUserRoom) { return(this.dispatcher.Error(domain, Strings.YOU_ARE_NOT_IN_ROOM)); } if (!this.userRoomService.PlayerCanModerateRoom(sender, currentLobby.UserRoom)) { Log.Information("Player {sender} attempted to run /expel, but didn't have permission for that", sender.Digest); return(this.dispatcher.Error(domain, Strings.YOU_DONT_HAVE_PERMISSION_TO_MODERATE_ROOM)); } var userRoom = currentLobby.UserRoom; string name; uint duration; try { try { // single argument - duration name = "."; duration = UInt32.Parse(arguments.ElementAt(0).Trim()); } catch (ArgumentOutOfRangeException) { // no arguments name = "."; duration = 0; } catch (FormatException) { // single or two arguments name = arguments.First().Trim(); if (arguments.Count() > 1) { duration = UInt32.Parse(arguments.ElementAt(1).Trim()); } else { duration = 0; } } } catch (ArgumentOutOfRangeException) { return(this.dispatcher.InvalidUsage(domain)); } catch (FormatException) { return(this.dispatcher.InvalidUsage(domain)); } if (name.Equals("\\all")) { Log.Information("Player {sender} expelling everyone from user room {room}", sender.Digest, userRoom.Identifier); return(this.userRoomService.ExpellAll(userRoom)); } PlayerHandle player = CommandUtils.GetPlayer(name, domain, this.manager); if (player == null || player.Character.Equals(sender.Character) || player.Character.Id == userRoom.OwnerId) { return(this.dispatcher.Error(domain, Strings.PLAYER_NOT_FOUND, name)); } if (duration > this.config.Expel.MaxDuration.TotalMinutes) { return(this.dispatcher.Error(domain, Strings.DURATION_CANT_BE_MORE_MINUTES, this.config.Expel.MaxDuration.TotalMinutes)); } if (sender.CurrentLobby == null || !sender.CurrentLobby.IsUserRoom) { return(this.dispatcher.Error(domain, Strings.YOU_SHOULD_BE_IN_THE_ROOM_TO_MODERATE_IT)); } Log.Information("Player {sender} expelling player {player} from user room {room} for {duration} m.", sender.Digest, player.Digest, userRoom.Identifier, duration); return(this.userRoomService.ExpelPlayer(player, userRoom, TimeSpan.FromMinutes(duration)) .Then(a => this.dispatcher.Output(domain, Strings.PLAYER_HAS_BEEN_EXPELLED))); }
internal IPromise <Nothing> showInfo(PlayerHandle sender, CommandDomain domain, string name) { PlayerHandle player = CommandUtils.GetPlayer(name, domain, this.manager); if (player != null) { name = player.Name; } Character character; try { character = this.characterService.Find(name); } catch (CharacterService.NotFoundException) { return(this.dispatcher.Error(domain, Strings.PLAYER_NOT_FOUND, name)); } User user = null; try { user = this.loginService.FindUser(character.UserId); } catch (LoginService.NotFoundException) { } if (user != null && (user.AdminFlags > 0 && !sender.AdminOptions.HasFlag(AdminFlags.AdminPlayerManagement))) { return(this.dispatcher.Error(domain, Strings.FORBIDDEN)); } var messages = new List <string>(); messages.Add(String.Format("Player {0} ({1})", name, character.Id)); if (player == null) { messages.Add(String.Format("Last seen at {0}", character.LastLogin)); } else { messages.Add(String.Format("Currently online ({0}) from {1}", player.CurrentLobbyIdentifier, player.Stream.ConnectionEndpoint)); } if (user != null) { messages.Add(String.Format("User {0} ({1})", user.Username, user.Id)); messages.Add(String.Format("Last logged: {0}", user.LastSeenAt)); messages.Add(String.Format("Signed up: {0}", user.CreatedAt)); messages.Add(String.Format("Total time online: {0} hours", TimeSpan.FromSeconds(user.TotalSecondsOnline).TotalHours)); messages.Add(String.Format("Currency: {0}", user.Currency)); if (user.Status != null) { messages.Add(String.Format("Status: {0}", user.Status)); } if (user.AdminFlags > 0) { messages.Add(String.Format("Is admin (flags {0})", user.AdminFlags)); } } return(new CombinedPromise <Nothing>(messages.Select((m) => this.dispatcher.Output(domain, m)))); }
internal override IPromise <Nothing> Dispatch(PlayerHandle sender, CommandDomain domain, string tag, IEnumerable <string> arguments) { try { var playerName = arguments.ElementAt(0).Trim(); var amount = Convert.ToInt32(arguments.ElementAt(1).Trim()); PlayerHandle[] players; lock (this.manager) { if (playerName.Equals("\\world")) { players = this.manager.World.Players.ToArray(); } else if (playerName.Equals("\\lobby")) { if (sender.CurrentLobby == null) { return(this.dispatcher.Error(domain, Strings.YOU_ARE_NOT_IN_LOBBY)); } players = sender.CurrentLobby.Players.ToArray(); } else { var player = CommandUtils.GetPlayer(playerName, domain, this.manager); if (player == null) { return(this.dispatcher.Error(domain, Strings.PLAYER_NOT_FOUND, playerName)); } players = new PlayerHandle[] { player }; } } if (this.config.Currency.Enabled == false) { return(this.dispatcher.Error(domain, Strings.CURRENCY_IS_NOT_ENABLED)); } foreach (var player in players) { try { this.giftService.ChangeCurrency(player.User, amount); } catch (GiftsService.NotEnoughCurrencyException e) { Log.Warning("Failed to gift money as admin: {exception}", e); } } var message = String.Format(Strings.YOU_HAVE_BEEN_GIFTED_COINS_FROM_ADMIN, amount); return(new CombinedPromise <Nothing>(players.Select(p => p.Stream.Write(Responses.ServerDirectMessage(this.manager, message)))) .Then(a => this.dispatcher.Output(domain, Strings.DONE))); } catch (Exception e) { if (e is FormatException || e is ArgumentOutOfRangeException) { return(this.dispatcher.InvalidUsage(domain)); } else { throw e; } } }
internal override IPromise <Nothing> Dispatch(PlayerHandle sender, CommandDomain domain, string tag, IEnumerable <string> arguments) { try { if (this.config.Currency.Enabled == false) { return(this.dispatcher.Error(domain, Strings.CURRENCY_IS_NOT_ENABLED)); } var recipientName = "."; bool recepientless = false; uint amount; try { // single argument - amount amount = Convert.ToUInt32(arguments.ElementAt(0).Trim()); recepientless = true; } catch (FormatException) { // two arguments recipientName = arguments.ElementAt(0); amount = Convert.ToUInt32(arguments.ElementAt(1).Trim()); } PlayerHandle recipient = CommandUtils.GetPlayer(recipientName, domain, this.manager); if (recipient == null || recipient.User.Id == sender.User.Id) { return(this.dispatcher.Error(domain, Strings.PLAYER_NOT_FOUND, recipientName)); } this.giftsService.TransferCurrency(sender.User, recipient.User, amount); var reason = CommandUtils.GetText(arguments.Skip(recepientless ? 1 : 2)); var reasonText = reason != null ? ", \"" + reason + "\"" : ""; var senderMessage = String.Format(Strings.TRANSFERRED_COINS_TO, amount, recipient.Name, this.giftsService.GetCurrency(sender.User)); var recipientMessage = String.Format(Strings.PLAYER_SENT_YOU_COINS, sender.Name, amount, reasonText, this.giftsService.GetCurrency(recipient.User)); var localMessage = String.Format(Strings.GAVE_COINS_TO, sender.Name, amount, recipient.Name); var promises = new List <IPromise <Nothing> > { this.dispatcher.Output(domain, senderMessage), recipient.Stream.Write(Responses.ServerDirectMessage(this.manager, recipientMessage)) }; if (tag.Equals("/give")) { if (sender.CurrentLobby != null && this.lobbyService.CheckSlowmodeTimer(sender.CurrentLobby, sender)) { var localMsg = Responses.ServerLocalMessage(this.manager, localMessage); promises.Add(sender.Stream.Write(localMsg)); promises.AddRange(domain.Recipients.Select(r => r.Stream.Write(localMsg))); } } return(new CombinedPromise <Nothing>(promises)); } catch (GiftsService.NotEnoughCurrencyException) { return(this.dispatcher.Error(domain, Strings.NOT_ENOUGH_COINS)); } catch (Exception e) { if (e is FormatException || e is ArgumentOutOfRangeException) { return(this.dispatcher.Error(domain, Strings.INVALID_AMOUNT)); } else { throw e; } } }