Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void HandleLogin(Connection con, string username, string password)
- {
- string index = con.index;
- if (string.IsNullOrEmpty(index))
- {
- Log.log(logType.Error, "Data send from null index?!");
- return;
- }
- bool canLogin = false;
- string reason = "";
- string accountID = "";
- if (Database.getInstance.accountExistsAndIsOk(username, password))
- {
- canLogin = true;
- }
- //check from database
- if (canLogin)
- {
- //get account id, to see if it is logged in
- //check if client is already signed in
- if (!Account.account.ContainsKey(index))
- {
- foreach (var acc in Account.account)
- {
- if (Account.isLoggedIn(username))
- {
- //account is already signed in
- canLogin = false;
- reason = "Account already signed in!";
- goto loopEnd;
- }
- }
- }
- else
- {
- canLogin = false;
- reason = "Client already has a signed in account!";
- }
- }
- else
- {
- reason = "Wrong username or password!";
- }
- loopEnd:
- if (canLogin)
- {
- Database.getInstance.updateAccountStatues(true, username);
- Database.getInstance.loadPlayer(index, username);
- reason = "You are logging in...";
- Account newAcc = new Account();
- newAcc.accountID = index;
- newAcc.password = password;
- newAcc.username = username;
- Account.account.Add(index, newAcc);
- Console.WriteLine("Account logged in: " + username + " | " + password);
- Spawner.SpawnPlayer(index);
- Player.player[index].initPlayer();
- }
- Server.SendLogin(canLogin, reason, index);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement