Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1.  static void HandleLogin(Connection con, string username, string password)
  2.         {
  3.             string index = con.index;
  4.             if (string.IsNullOrEmpty(index))
  5.             {
  6.                 Log.log(logType.Error, "Data send from null index?!");
  7.                 return;
  8.             }
  9.             bool canLogin = false;
  10.             string reason = "";
  11.  
  12.             string accountID = "";
  13.  
  14.             if (Database.getInstance.accountExistsAndIsOk(username, password))
  15.             {
  16.                 canLogin = true;
  17.             }
  18.  
  19.             //check from database
  20.             if (canLogin)
  21.             {
  22.                 //get account id, to see if it is logged in
  23.  
  24.                 //check if client is already signed in
  25.                 if (!Account.account.ContainsKey(index))
  26.                 {
  27.                     foreach (var acc in Account.account)
  28.                     {
  29.                         if (Account.isLoggedIn(username))
  30.                         {
  31.                             //account is already signed in
  32.                             canLogin = false;
  33.                             reason = "Account already signed in!";
  34.  
  35.                             goto loopEnd;
  36.                         }
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     canLogin = false;
  42.                     reason = "Client already has a signed in account!";
  43.                 }
  44.             }
  45.             else
  46.             {
  47.                 reason = "Wrong username or password!";
  48.             }
  49.  
  50.             loopEnd:
  51.  
  52.             if (canLogin)
  53.             {
  54.                 Database.getInstance.updateAccountStatues(true, username);
  55.                 Database.getInstance.loadPlayer(index, username);
  56.                 reason = "You are logging in...";
  57.  
  58.                 Account newAcc = new Account();
  59.                 newAcc.accountID = index;
  60.                 newAcc.password = password;
  61.                 newAcc.username = username;
  62.                 Account.account.Add(index, newAcc);
  63.                 Console.WriteLine("Account logged in: " + username + " | " + password);
  64.                 Spawner.SpawnPlayer(index);
  65.                 Player.player[index].initPlayer();
  66.             }
  67.  
  68.             Server.SendLogin(canLogin, reason, index);
  69.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement