Ejemplo n.º 1
0
        internal bool AddUserTest([PexAssumeUnderTest] UserList target, User user)
        {
            bool result = target.AddUser(user);

            return(result);
            // TODO: add assertions to method UserListTest.AddUserTest(UserList, User)
        }
Ejemplo n.º 2
0
    public static UserList importFromFile(string path)
    {
        UserList newList = new UserList();
        User     re;

        try
        {
            FileStream   fs = File.Open(path, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            do
            {
                re = User.DeserialisiereBinärMitReader(br);
                if (re != null)
                {
                    newList.AddUser(re);
                }
            } while (re != null);
            br.Close();
            fs.Close();
        } catch
        {
            return(null);
        }
        return(newList);
    }
Ejemplo n.º 3
0
        private void AddNewUserClick(object sender, RoutedEventArgs e)
        {
            UserList.AddUser(username.Text, firstname.Text, lastname.Text);

            username.Clear();
            firstname.Clear();
            lastname.Clear();
            username.Focus();
        }
        ///--------------------------------------------------------------------------------------------------------
        ///
        public async Task <bool> Process(long requesterId, string requesterName, DateTime requestTime, params object[] args)
        {
            IsCompleted = false;

            UserList.AddUser(requesterId);

            LogStartCommand(GetCommandType().ToString(), requesterId, requesterName);

            return(await OnStart(requesterId, requesterName, requestTime, args));
        }
Ejemplo n.º 5
0
 public IActionResult Post([FromBody] User UserP)
 {
     if (ModelState.IsValid)
     {
         if (!UserList.AddUser(UserP))
         {
             return(BadRequest());
         }
         return(Created(Url.Action("Post", UserP.id), UserP));
     }
     return(BadRequest());
 }
Ejemplo n.º 6
0
    static UserList HandleImportedUsers(UserList newUsers, UserList oldUsers)
    {
        UserList       users = new UserList();
        ConsoleKeyInfo select;
        User           tmp = newUsers.FindByIndex(0);

        Console.WriteLine("Aktuelle Nutzer durch Import ersetzen? (Y/n)");
        select = Console.ReadKey();
        if (select.Key == ConsoleKey.Y)
        {
            users = newUsers;
            return(users);
        }
        else
        {
            while (tmp != null)
            {
                oldUsers.AddUser(User.DeserialisiereBinär(tmp.SerialisiereBinaer()));
                tmp = tmp.next;
            }
            users = oldUsers;
            return(users);
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Parses LoginSuccess instructions for users
        /// and adds them to the UserList
        /// </summary>
        /// <param name="content">Byte array containing
        /// all recieved buffer</param>
        /// <param name="users">Userlist to add to</param>
        /// returns index of beginning of gamelist
        /// <param name="games">Game list to add 
        /// games to</param>
        /// <param name="currindex">index of buffer to
        /// begin parsing</param>
        public static void parseUsersGames(byte[] content, ref UserList users, ref GameList games, int currindex)
        {

            currindex += 2;      
            int numUsers = BitConverter.ToInt32(content, currindex);
            currindex += 4;
            int numGames = BitConverter.ToInt32(content, currindex);
            currindex += 4;

            //Parse the users
            for (int i = 0; i < numUsers; i++)
            {
                User user = new User();
                StringBuilder usrName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    usrName.Append((char)content[currindex++]);
                }
                user.Name = usrName.ToString();
                currindex++;
                user.ping = BitConverter.ToInt32(content, currindex);
                currindex += 4;
                user.status = content[currindex];
                currindex++;
                user.id = BitConverter.ToInt16(content, currindex);
                currindex += 2;
                user.connection = content[currindex++];
                user.assignCategory();
                users.AddUser(user);
            }

            //Now for the games
            for (int i = 0; i < numGames; i++)
            {
                Game game = new Game();
                StringBuilder gamename = new StringBuilder();
                while (content[currindex] != 0)
                {
                    gamename.Append((char)content[currindex++]);
                }
                game.name = gamename.ToString();
                currindex++;
                game.id = BitConverter.ToInt32(content, currindex);
                currindex += 4;
                StringBuilder emuName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    emuName.Append((char)content[currindex++]);
                }
                game.emuName = emuName.ToString();
                currindex++;
                StringBuilder hostUser = new StringBuilder();
                
                while (content[currindex] != 0)
                {
                    hostUser.Append((char)content[currindex++]);
                }


                game.gameHost = hostUser.ToString();
                currindex++;

                StringBuilder usersStr = new StringBuilder();

                while (content[currindex] != 0)
                {
                    usersStr.Append((char)content[currindex++]);
                }

                //Note property setter also sets game users and max users
                game.Users_count = usersStr.ToString();

                game.status = content[++currindex];
                games.AddGame(game);
                currindex++;

            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Parses LoginSuccess instructions for users
        /// and adds them to the UserList
        /// </summary>
        /// <param name="content">Byte array containing
        /// all recieved buffer</param>
        /// <param name="users">Userlist to add to</param>
        /// returns index of beginning of gamelist
        /// <param name="games">Game list to add
        /// games to</param>
        /// <param name="currindex">index of buffer to
        /// begin parsing</param>
        public static void parseUsersGames(byte[] content, ref UserList users, ref GameList games, int currindex)
        {
            currindex += 2;
            int numUsers = BitConverter.ToInt32(content, currindex);

            currindex += 4;
            int numGames = BitConverter.ToInt32(content, currindex);

            currindex += 4;

            //Parse the users
            for (int i = 0; i < numUsers; i++)
            {
                User          user    = new User();
                StringBuilder usrName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    usrName.Append((char)content[currindex++]);
                }
                user.Name = usrName.ToString();
                currindex++;
                user.ping   = BitConverter.ToInt32(content, currindex);
                currindex  += 4;
                user.status = content[currindex];
                currindex++;
                user.id         = BitConverter.ToInt16(content, currindex);
                currindex      += 2;
                user.connection = content[currindex++];
                user.assignCategory();
                users.AddUser(user);
            }

            //Now for the games
            for (int i = 0; i < numGames; i++)
            {
                Game          game     = new Game();
                StringBuilder gamename = new StringBuilder();
                while (content[currindex] != 0)
                {
                    gamename.Append((char)content[currindex++]);
                }
                game.name = gamename.ToString();
                currindex++;
                game.id    = BitConverter.ToInt32(content, currindex);
                currindex += 4;
                StringBuilder emuName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    emuName.Append((char)content[currindex++]);
                }
                game.emuName = emuName.ToString();
                currindex++;
                StringBuilder hostUser = new StringBuilder();

                while (content[currindex] != 0)
                {
                    hostUser.Append((char)content[currindex++]);
                }


                game.gameHost = hostUser.ToString();
                currindex++;

                StringBuilder usersStr = new StringBuilder();

                while (content[currindex] != 0)
                {
                    usersStr.Append((char)content[currindex++]);
                }

                //Note property setter also sets game users and max users
                game.Users_count = usersStr.ToString();

                game.status = content[++currindex];
                games.AddGame(game);
                currindex++;
            }
        }
Ejemplo n.º 9
0
    public static void Main(String[] args)
    {
        string inputPassword;

        char[] encryptedFakeRealPassword =
        { (char)36, (char)61, (char)72, (char)72, (char)75, (char)13, (char)14, (char)15 };
        string         encryptedRealPassword = new string(encryptedFakeRealPassword);
        string         encryptedInputPassword;
        string         usernameInput;
        string         message = "";
        string         filepath;
        int            key         = 65500;
        UserList       users       = new UserList();
        ConsoleKeyInfo auswahl     = new ConsoleKeyInfo();
        bool           passed      = false;
        User           currentUser = null;

        while (auswahl.Key != ConsoleKey.X)
        {
            Console.Clear();
            if (message != "")
            {
                Console.Write(message + "\n");
                message = "";
            }
            if (passed && currentUser != null)
            {
                Console.WriteLine("Eingeloggt als: " + currentUser.Username);
            }
            Console.Write("Was wollen sie tun? \n");
            if (!passed)
            {
                Console.Write("Login (L) \n");
                Console.Write("Registrieren (R) \n");
            }
            else
            {
                Console.Write("Ausloggen (L) \n");
                Console.Write("Nutzer kopieren (C) \n");
            }
            Console.Write("Nutzer auflisten (i) \n");
            Console.Write("Nutzerliste Exportieren (E) \n");
            Console.Write("Nutzerliste aus Datei Importieren (F) \n");
            Console.Write("User löschen (D) \n");
            Console.Write("Verlassen (X) \n");

            auswahl = Console.ReadKey();
            switch (auswahl.Key)
            {
            case ConsoleKey.F:
                filepath = GetFilePath();
                UserList tempUsers = UserList.importFromFile(filepath);
                if (tempUsers != null)
                {
                    HandleImportedUsers(tempUsers, users);
                }
                else
                {
                    message = "Fehler beim importieren aus Datei bitte Dateipfad überprüfen!";
                }
                break;

            case ConsoleKey.E:
                filepath = GetFilePath();
                users.saveToFile(filepath);
                message = "Saved To File!";
                break;

            case ConsoleKey.C:
                if (passed)
                {
                    Console.Write("\n Nutzer zum kopieren auswählen \n");
                    Console.Write(users.GetUserList());
                    int index = GetNumber();
                    Console.Write("byte Array Length: " + users.FindByIndex(index).SerialisiereBinaer().Length + "\n");
                    User habib = User.DeserialisiereBinär(users.FindByIndex(index).SerialisiereBinaer());
                    users.AddUser(habib);
                    message = "Nutzer: " + habib.Username + " erfolgreich kopiert!";
                }
                break;

            case ConsoleKey.L:
                if (!passed)
                {
                    while (!passed)
                    {
                        Console.Write("\nEinloggen!");
                        Console.Write("\nUsername: "******"Passwort: ");
                        inputPassword = Console.ReadLine();
                        // Eingelesenes Passwort durch Aufruf der Funktion Encrypt verschlüsseln:
                        encryptedInputPassword = Encrypt(inputPassword, key);

                        // Überprüfen ob Login Daten übereinstimmen:
                        Console.Write(users.GetUserList());
                        User existingUser = users.FindUser(new User(usernameInput, encryptedInputPassword));

                        if (existingUser != null)
                        {
                            currentUser = existingUser;
                            passed      = true;
                        }

                        if (passed)
                        {
                            inputPassword = null;
                        }
                        else
                        {
                            Console.Write("\nUsername oder Passwort Falsch! Wiederholen? Y/n \n");
                            auswahl = Console.ReadKey();
                            if (auswahl.Key == ConsoleKey.N)
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    currentUser = null;
                    passed      = false;
                }
                break;

            case ConsoleKey.R:
                if (!passed)
                {
                    Console.Write("\nRegistrieren!");
                    Console.Write("\nUsername: "******"Passwort: ");
                    inputPassword = Console.ReadLine();
                    // Eingelesenes Passwort durch Aufruf der Funktion Encrypt verschlüsseln:
                    encryptedInputPassword = Encrypt(inputPassword, key);

                    User newUser = new User(usernameInput, encryptedInputPassword);
                    users.AddUser(newUser);
                    currentUser = newUser;
                    passed      = true;
                }
                break;

            case ConsoleKey.D:
                if (passed)
                {
                    Console.Write("Passwort eingeben um Löschen des Users zu bestätigen: ");
                    inputPassword = Console.ReadLine();
                    // Eingelesenes Passwort durch Aufruf der Funktion Encrypt verschlüsseln:
                    encryptedInputPassword = Encrypt(inputPassword, key);
                    if (currentUser.Password == encryptedInputPassword)
                    {
                        users.DeleteUser(currentUser);
                        currentUser = null;
                        passed      = false;
                    }
                }
                break;

            case ConsoleKey.I:
                Console.Write("\nCurrent Users: \n");
                Console.Write(users.GetUserList());
                Console.ReadKey();
                break;
            }
        }
    }