public static void Add(WaitingUserData user)
        {
            var index = 0;

            if (users.Count < highIndex)
            {
                // Procura por um slot que não está sendo usado.
                for (var i = 1; i <= highIndex; i++)
                {
                    if (!users.ContainsKey(i))
                    {
                        index = i;
                        break;
                    }
                }
            }
            // Caso contrário, adiciona um novo slot.
            else
            {
                index = ++highIndex;
            }

            user.ListIndex = index;
            users.Add(index, user);
            Global.WriteLog(LogType.Player, $"Received Key {user.UniqueKey} Username {user.Username}", LogColor.Coral);
        }
Beispiel #2
0
        public Player(IConnection connection, WaitingUserData user)
        {
            Index       = connection.Index;
            Connection  = connection;
            AccountId   = user.AccountId;
            Username    = user.Username;
            UniqueKey   = user.UniqueKey;
            AccessLevel = user.AccessLevel;
            Cash        = user.Cash;
            GameState   = GameState.Characters;

            Vitals = new int[Enum.GetValues(typeof(VitalType)).Length];

            Inventory = new Dictionary <int, Inventory>();

            for (var i = 1; i <= Configuration.MaxInventories; i++)
            {
                Inventory.Add(i, new Inventory());
            }

            CharacterSelection = new Dictionary <int, CharacterSelection>();

            for (var i = 1; i <= Configuration.MaxCharacters; i++)
            {
                CharacterSelection.Add(i, new CharacterSelection());
            }
        }
Beispiel #3
0
        public void Authenticate()
        {
            var user = new WaitingUserData();

            if (Validate())
            {
                // Sai do método quando o login está duplicado.
                if (IsLoginDuplicated())
                {
                    // Remove os dados da lista obrigando um novo login.
                    WaitingUserData.Remove(user.ListIndex);
                }
                else
                {
                    user = WaitingUserData.FindUser(UniqueKey);

                    // Depois de conferido, adiciona na lista de usuários.
                    Authentication.Add(user, Connection);

                    // Remove da lista já que não é mais necessário.
                    WaitingUserData.Remove(user.ListIndex);

                    SendData();

                    Global.WriteLog(LogType.Player, $"Authenticated user {Username} {UniqueKey}", LogColor.Green);
                }
            }
            else
            {
                Disconnect(Connection, AlertMessageType.Connection);
                return;
            }
        }
        public static void Add(WaitingUserData user, IConnection connection)
        {
            var index = connection.Index;
            var pData = new Player(connection, user);

            ((Connection)connection).OnDisconnect += OnDisconnect;
            ((Connection)connection).Authenticated = true;

            Players.Add(index, pData);

            var highIndex = new SpHighIndex(HighIndex);

            highIndex.SendToAll();
        }
Beispiel #5
0
        private bool Validate()
        {
            var user    = new WaitingUserData();
            var isValid = false;

            if (!string.IsNullOrEmpty(UniqueKey))
            {
                user = WaitingUserData.FindUser(UniqueKey);

                if (user != null)
                {
                    if (string.CompareOrdinal(user.Username.ToLower(), Username.ToLower()) == 0)
                    {
                        isValid = true;
                    }
                }
            }

            return(isValid);
        }