예제 #1
0
        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;
        }
예제 #2
0
        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);
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
        }
예제 #5
0
        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)));
        }
예제 #6
0
 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);
 }