예제 #1
0
        public async Task <IActionResult> Create(RegistrationViewModel registrationViewModel, IEnumerable <int> colorsList, IEnumerable <int> drinksList)
        {
            if (colorsList != null)
            {
                foreach (var color in colorsList)
                {
                    UserColors userColor = new UserColors {
                        Color = db.Colors.Where(s => s.id.Equals(color)).SingleOrDefault(), User = registrationViewModel.Users
                    };
                    db.userColors.Add(userColor);
                }
            }
            if (drinksList != null)
            {
                foreach (var drink in drinksList)
                {
                    UserDrinks userDrinks = new UserDrinks {
                        Drink = db.Drinks.Where(s => s.id.Equals(drink)).SingleOrDefault(), User = registrationViewModel.Users
                    };
                    db.userDrinks.Add(userDrinks);
                }
            }
            db.Users.Add(registrationViewModel.Users);
            await db.SaveChangesAsync();

            return(RedirectToAction("Result"));
        }
예제 #2
0
 protected void AddColor(string username, Color color)
 {
     if (UserColors.ContainsKey(username))
     {
         UserColors[username] = color;
     }
     else
     {
         UserColors.Add(username, color);
     }
 }
예제 #3
0
        public string GetColor()
        {
            Match match = Regex.Match(Command, "[./]color ((>?#[0-9A-F]{6})|Blue|BlueViolet|CadetBlue|Chocolate|Coral|DodgerBlue|Firebrick|GoldenRod|Green|HotPink|OrangeRed|Red|SeaGreen|SpringGreen|YellowGreen)$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            if (match.Success)
            {
                string color = match.Groups[1].Value.ToLowerInvariant();
                return(UserColors.TryGetValue(color, out string hexcolor) ? hexcolor : color);
            }
            return(null);
        }
예제 #4
0
    private void ShowColorOptions()
    {
        for (int i = 0; i < currentLevelData.userColorOptions.Length; i++)
        {
            GameObject colorOptionsGameObject = colorOptionsObjectPool.GetObject();
            colorOptionsGameObject.GetComponent <Button>().image.color = currentLevelData.userColorOptions[i];
            colorOptionsGameObjects.Add(colorOptionsGameObject);
            colorOptionsGameObject.transform.SetParent(colorOptionsButtonsParent.transform, false);

            UserColors userColor = colorOptionsGameObject.GetComponent <UserColors>();
            userColor.Setup(currentLevelData.userColorOptions[i]);
        }
    }
예제 #5
0
        private SyncState LoadState(long ssid)
        {
            var state = SyncManager.LoadState(ssid);

            if (state != null)
            {
                // Fix user colors
                foreach (var user in state.Users)
                {
                    UserColors.CountColor(user);
                }
            }

            return(state);
        }
예제 #6
0
        private void RegisterUser(UserContext context, SyncCommand command)
        {
            // Client is trying to register
            // Find his connection and link it to a new user
            var conn = FindConnection(context);

            if (conn != null)
            {
                if (!conn.IsRegistered)
                {
                    var id        = (int)command.Data.Id;
                    var ssid      = (long)command.Data.Ssid;
                    var name      = command.Data.Name.ToString();
                    var shortname = command.Data.ShortName.ToString();
                    var password  = command.Data.Password.ToString();

                    // Check password
                    if (password == _password)
                    {
                        // Check subsession ID
                        if (ssid == _subSessionId)
                        {
                            // Check name length
                            if (!string.IsNullOrWhiteSpace(name) && name.Length >= MIN_NAME_LENGTH)
                            {
                                // Try to find previously connected user
                                var user = this.State.Users.FromId(id);
                                if (user == null)
                                {
                                    // New user
                                    user        = new User();
                                    user.CustId = id;
                                    this.State.Users.Add(user);

                                    UserColors.SetColor(user);
                                }

                                if (!user.IsConnected)
                                {
                                    user.Name         = name;
                                    user.ShortName    = shortname;
                                    user.IsRegistered = true;
                                    user.IsConnected  = true;
                                    user.IsHost       = id == _adminId;

                                    // Link him to his connection
                                    conn.User = user;

                                    this.OnLog("User registered: " + name);

                                    var response = new SyncResponse(SyncResponse.ResponseTypes.Connect);
                                    response.Data = new { Success = true, User = user };

                                    this.Reply(context, response);
                                    this.BroadcastUserlist();
                                    this.SendState(context);
                                }
                                else
                                {
                                    this.OnLog("Already connected: " + name);
                                    this.FailRegistration(context, "You are already connected.");
                                }
                            }
                            else
                            {
                                this.OnLog("Name too short: " + name);
                                this.FailRegistration(context,
                                                      string.Format("Please choose a name with a minimum of {0} characters.", MIN_NAME_LENGTH));
                            }
                        }
                        else
                        {
                            this.OnLog("Incorrect session ID.");
                            this.FailRegistration(context, "Incorrect subsession ID: you must join the same session as the server host.");
                        }
                    }
                    else
                    {
                        this.OnLog("Incorrect password attempt: " + password);
                        this.FailRegistration(context, "Incorrect password.");
                    }
                }
                else
                {
                    this.OnLog("Already registered: " + conn.Username);
                    this.FailRegistration(context, "You are already registered.");
                }
            }
            else
            {
                this.OnLog("Unknown client tried to register: " + context.ClientAddress);
                this.FailRegistration(context, "Unknown client.");
            }
        }
예제 #7
0
 protected Color GetColor(string username)
 {
     return(UserColors.ContainsKey(username)
         ? UserColors[username]
         : Color.White);
 }