Exemple #1
0
        /// <summary>
        /// Login mit Nutzernamen und Passwort
        /// Benutzt das Networkinterface
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Request LoginRemote(User user)
        {
            bool updateUserCache = false;

            currentUser = user;

            Package returnPackage;
            Package loginPackage = new Package(Request.Login, currentUser);

            //Falls der Nutzer im Cache vorhanden, wähle die gespeicherte IP
            if (UserCache.ContainsKey(user))
            {
                updateUserCache = true;
                clientConnection.ChangeIP(UserCache[user]);
            }
            else if (user.serverID == 0)
            {
                clientConnection.ChangeP2P();
            }

            returnPackage = clientConnection.Start(loginPackage);
            if (returnPackage == null)
            {
                throw new Exception("Client login failed.");
            }

            if (returnPackage.request == Request.ChangeServer)
            {
                clientConnection.ChangeIP(returnPackage.sourceServer);
                if (updateUserCache)
                {
                    UserCache.Remove(user);
                }
                //Füge Nutzer dem Cache hinzu
                UserCache.Add(user, clientConnection.GetIPAddress());
                loginPackage.serverSwitched = true;
                returnPackage = clientConnection.Start(loginPackage);
            }
            else
            {
                MessageBox.Show("Login fehlgeschlagen!!!");
            }

            if (returnPackage.kaEvents != null)
            {
                eventList = returnPackage.kaEvents;
            }
            if (returnPackage.invites != null)
            {
                inviteList = returnPackage.invites;
            }

            return(returnPackage.request);
        }