Example #1
0
        static public string ShowScoreboard(RequestContext request)         //a scoreboard including stats of all users can be displayed
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 1 || userstate == 2)     //eingeloggt
            {
                return(UserDatabaseHandler.GenerateScoreboard());
            }
            return(Output.AuthError);
        }
Example #2
0
        static public int AuthUser(RequestContext request)
        {
            string token = GetToken(request);

            if (token != null)
            {
                return(UserDatabaseHandler.AuthUser(token));
            }

            return(0);
        }
Example #3
0
        static public void CreateUser(RequestContext request)                     //register user for further use
        {
            User tmpUser = JsonConvert.DeserializeObject <User>(request.Message); //temp user to write data into db

            try
            {
                UserDatabaseHandler.InsertUser(tmpUser);
                Output.WriteConsole(Output.UserCreated);
            }
            catch (Exception e)
            {
                Output.WriteConsole(e.Message);
            }
        }
Example #4
0
        static public void LoginUser(RequestContext request)    //login user to perform actions
        {
            User tmpUser = JsonConvert.DeserializeObject <User>(request.Message);

            try
            {
                UserDatabaseHandler.LoginUser(tmpUser);
                Output.WriteConsole(Output.UserLoginSuccess);
            }
            catch (Exception e)
            {
                Output.WriteConsole(e.Message);
            }
        }
Example #5
0
        static public void UpdateExtraUserData(RequestContext request)      //used to edit data like name, bio and image
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 1 || userstate == 2)   //eingeloggt
            {
                if (AccessUserdata(request))        //check if user is permitted to access data (if user tries to edit his own data)
                {
                    User user = JsonConvert.DeserializeObject <User>(request.Message);
                    user.username = ExtractUserFromToken(GetToken(request));
                    UserDatabaseHandler.UpdateExtraUserData(user);
                    Output.WriteConsole(Output.UserdataEditSuccess);
                    return;
                }
                Output.WriteConsole(Output.UserdataAccessError);
                return;
            }
            Output.WriteConsole(Output.AuthError);
        }
Example #6
0
        static User FindOpponent(User user)
        {
            List <int> goodOpponents = UserDatabaseHandler.SearchOpponentsWithElo(user);

            User opp = SelectOpponent(goodOpponents);

            if (opp != null)
            {
                Output.WriteConsole(Output.RatedMatchGoodOpp);
                return(opp);
            }

            List <int> allOpponents = UserDatabaseHandler.SearchOpponentsWithoutElo(user);

            opp = SelectOpponent(allOpponents);
            if (opp != null)
            {
                Output.WriteConsole(Output.RatedMatchBadOpp);
                return(opp);
            }

            throw new Exception(Output.RatedMatchNoOpp);
        }
Example #7
0
 static public void UpdateAfterBattle(User user1, User user2)
 {
     UserDatabaseHandler.UpdateAfterBattle(user1);
     UserDatabaseHandler.UpdateAfterBattle(user2);
 }
Example #8
0
 static public void UpdateCoins(User user)
 {
     UserDatabaseHandler.UpdateCoins(user);
 }
Example #9
0
 static public User GetUserDataByUsername(string username)
 {
     return(UserDatabaseHandler.GetUserDataByUsername(username));
 }
Example #10
0
 static public User GetUserDataById(int id)
 {
     return(UserDatabaseHandler.GetUserDataById(id));
 }
Example #11
0
        static public User GetUserDataByToken(RequestContext request)
        {
            string token = GetToken(request);

            return(UserDatabaseHandler.GetUserDataByToken(token));
        }