Esempio n. 1
0
        public User.User.UserState InsertResponse(string response, string userId)
        {
            User.User.UserState state = User.User.UserState.LOGGING_IN;

            UserScript specificUser = usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault();

            if (specificUser != null && specificUser.currentStep == Steps.AWAITINGRESPONSE)
            {
                switch (specificUser.lastStep)
                {
                case Steps.NAME:
                    if (ValidatePlayerName(specificUser.user.UserID, response))
                    {
                        userId = specificUser.user.UserID;
                        specificUser.user.LogID = specificUser.user.UserID;
                        usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().currentStep = Steps.PASSWORD;
                        usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().lastStep    = Steps.AWAITINGRESPONSE;
                    }
                    else
                    {
                        usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().currentStep = Steps.NAME;
                        usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().lastStep    = Steps.NAME;
                    }
                    break;

                case Steps.PASSWORD:
                    if (ValidatePlayerPassword(specificUser.user.UserID, response))
                    {
                        specificUser.currentStep = Steps.SUCCEEDED;
                        specificUser.lastStep    = Steps.PASSWORD;
                    }
                    else
                    {
                        usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().currentStep = Steps.PASSWORD;
                        usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().lastStep    = Steps.PASSWORD;
                    }
                    break;

                case Steps.CREATECHAR:
                    if (String.Compare(response[0].ToString(), "y", true) == 0)
                    {
                        state = User.User.UserState.CREATING_CHARACTER;
                        usersLoggingIn.Remove(specificUser);
                    }
                    else
                    {
                        specificUser.currentStep = Steps.NAME;
                        specificUser.lastStep    = Steps.NONE;
                    }
                    break;

                default:
                    //something has gone terribly wrong if we get here
                    break;
                }
            }
            return(state);
        }
Esempio n. 2
0
        public string ExecuteScript(string userId)
        {
            string     message      = null;
            UserScript specificUser = usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault();

            if (specificUser != null && specificUser.lastStep != specificUser.currentStep)
            {
                switch (specificUser.currentStep)
                {
                case Steps.SPLASH:
                    message = SplashScreen();
                    usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().currentStep = Steps.NAME;
                    usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().lastStep    = Steps.NONE;
                    break;

                case Steps.NAME:
                    message = AskForFirstName();
                    usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().currentStep = Steps.AWAITINGRESPONSE;
                    usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().lastStep    = Steps.NAME;
                    break;

                case Steps.PASSWORD:
                    message = AskForPassword();
                    usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().currentStep = Steps.AWAITINGRESPONSE;
                    usersLoggingIn.Where(u => u.user.UserID == userId).SingleOrDefault().lastStep    = Steps.PASSWORD;
                    break;

                case Steps.SUCCEEDED:
                    //let's see if they are connecting back to a limbo character first and set things right
                    User.User user = new User.User();
                    user = MySockets.Server.GetAUserPlusState(specificUser.user.UserID, User.User.UserState.LIMBO);
                    if (user != null)
                    {
                        MySockets.Server.UpdateUserSocket(specificUser.user.UserID);
                        specificUser.user = user;
                    }
                    else
                    {
                        specificUser.user.Player.Load(specificUser.user.Player.ID);
                    }
                    message = "Welcome " + specificUser.user.Player.FirstName + " " + specificUser.user.Player.LastName + "!";
                    specificUser.user.CurrentState = User.User.UserState.TALKING;
                    specificUser.user.InBuffer     = "look\r\n";
                    usersLoggingIn.Remove(specificUser);
                    break;

                case Steps.AWAITINGRESPONSE:
                default:
                    break;
                }
            }
            else
            {
                if (specificUser != null && specificUser.currentStep == Steps.NAME)
                {
                    message = "No character with that name exists!\n\rDo you want to create a new character? (Y/N)";
                    specificUser.currentStep = Steps.AWAITINGRESPONSE;
                    specificUser.lastStep    = Steps.CREATECHAR;
                }
                else if (specificUser != null && specificUser.currentStep == Steps.PASSWORD)
                {
                    message = "Incorrect Password!";
                    specificUser.lastStep = Steps.NONE;
                }
            }

            return(message);
        }