protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { User user; if (Game.Current.Users.TryGetUser(input, out user)) { // User already exits. response.Invalidate(CommonResources.LoginAlreadyExists); return; } // Otherwise, create a user account and add a login. user = new User(); Login login; if (!Game.Current.Users.TryCreateLogin(input, out login)) { // User already exits. response.Invalidate(CommonResources.LoginAlreadyExists); return; } user.Logins.Add(login); Game.Current.Repository.SaveUser(user); response.Data = user.Id; connection.User = user; }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { if (connection.User == null) { response.Invalidate(CommonResources.LoginRequired); return; } var username = input.Get<string>("username"); var login = connection.User.Logins.FirstOrDefault(l => l.UserName.ToLower() == username); if (login != null) { response.Invalidate(CommonResources.LoginAlreadyExists); return; } if (!Game.Current.Users.TryCreateLogin(input, out login)) { response.Invalidate(CommonResources.LoginAlreadyExists); return; } connection.User.Logins.Add(login); Game.Current.Repository.SaveUser(connection.User); }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { User user; if (!Game.Current.Users.TryGetUser(input, out user)) { response.Invalidate(CommonResources.LoginInvalid); return; } Game.Current.Users.OnLoginSuccess(user, input); response.Data = user.Id; connection.User = user; }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { var commandName = input.Get<string>("command"); var cmd = Game.Current.Commands.FindCommandInternal(commandName); if (cmd == null) { response.Invalidate(CommonResources.HelpNotFoundFormat, commandName); return; } connection.Write(NotificationMessage.Heading(CommonResources.HelpName), NotificationMessage.Normal(cmd.Metadata.Name)); connection.Write(NotificationMessage.Heading(CommonResources.HelpDescription), NotificationMessage.Normal(cmd.Metadata.Description)); connection.Write(NotificationMessage.Heading(CommonResources.HelpSynopsis), NotificationMessage.Normal(cmd.Metadata.Synopsis)); connection.Write(NotificationMessage.Heading(CommonResources.HelpAliases), NotificationMessage.Normal(string.Join(",", cmd.Metadata.Aliases))); }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { var players = ConnectionManager.ActivePlayers(); var count = players.Count(); if (count > 0) { connection.Write(NotificationMessage.Normal(string.Format(CommonResources.WhoPlayersFormat, count))); foreach (var player in players) { connection.Write(NotificationMessage.Normal(player.ToShortString())); } } else { connection.Write(NotificationMessage.Normal(CommonResources.WhoNoPlayers)); } }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { CreateType createType; if (!Enum.TryParse(input.Get<string>("type"), true, out createType)) { response.Invalidate(CommonResources.CreateCommandInvalidTypeArg); return; } var type = typeof(GameObject); switch (createType) { case CreateType.Item: type = typeof(Item); break; case CreateType.Place: type = typeof(Place); break; case CreateType.Mobile: type = typeof(Mobile); break; case CreateType.Character: type = typeof(Character); break; } IGameObject obj; string errorMessage; if (!Game.Current.TryCreateObject(type, input, out errorMessage, out obj)) { response.Invalidate(errorMessage); return; } response.Data = obj; }
public ResponseMessage ProcessInput(IInput input) { // Record the current input in order to match the response during the Write operation. _currentInput = input; // Execute the command immediately. Game.Current.Commands.Execute(input, this); // Snag the current response and then clear the current input and response for the next operation. var response = _currentResponse; _currentInput = null; _currentResponse = null; return response; }
public void Write(params IMessage[] messages) { if (_currentResponse == null && _currentInput != null) _currentResponse = messages.Where(m => m is ResponseMessage).Select(m => (ResponseMessage)m).FirstOrDefault(m => m.Command == _currentInput.CommandName); _connection.Write(messages); }
/// <summary> /// Executes the current command. /// </summary> /// <param name="input">The IInput containing the command information to execute.</param> /// <param name="connection">The connection associated with the executing of the command.</param> /// <param name="response">A ResponseMessage associated with the current input and command.</param> /// <returns>A message detailing the results of command execution.</returns> protected abstract void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response);
/// <summary> /// Executes the current command. /// </summary> /// <param name="input">The IInput containing the command information to execute.</param> /// <param name="connection">The connection associated with the executing of the command.</param> /// <returns>A message detailing the results of command execution.</returns> public ResponseMessage Execute(IInput input, IConnection connection) { var response = new ResponseMessage(input); ExecuteOverride(input, connection, response); return response; }
private static void InvalidateResponse(IInput input, IConnection connection, string format, params object[] args) { var response = new ResponseMessage(input); response.Invalidate(format, args); connection.Write(response); }
protected virtual string FormatCommand(ResponseMessage msg) { return string.Empty; }