public static bool getLoginInfo(string username, out UserLoginInformation user) { UserLoginInformation loginAttempt = (UserLoginInformation)userLoginColl.FindOne(x => x.username == username); user = loginAttempt; if (loginAttempt == null) { return(false); } return(true); }
//Should later be rewritten so we separate a update and a new entry. For opting the performance //Also use Generics/Polymorphism #region Setters public static void updateLoginInfo(UserLoginInformation update) { UserLoginInformation loginAttempt = userLoginColl.FindOne(x => x.username == update.username); if (loginAttempt == null) { userLoginColl.Insert(update); } else { userLoginColl.Update(update); } }
//Right now the peerID and username search makes no sense... Fix later //To error check we could later store the peerID -> Username somewhere private static void addActiveUser(UserLoginInformation user, int newPeerID) { ActiveUser newUser = activeUsersColl.FindOne(x => x.username == user.username); if (newUser == null) { activeUsersColl.Insert(new ActiveUser { username = user.username, peerId = newPeerID.ToString() }); //Debug.LogError ("Adding user with ID: " + newPeerID); } else //This should never happen { newUser.peerId = newPeerID.ToString(); activeUsersColl.Update(newUser); } }
private static void incrementLoginCounter(UserLoginInformation user) { UserInfo info; if (getUserData(user.username, out info) == false) { return; } int currentLogins; if (int.TryParse(info.logins, out currentLogins) == false) { return; } info.logins = (currentLogins + 1).ToString(); updateGameStat(info); }
public static void onPlayerDissconnected(int peerID) { string keyID = peerID.ToString(); ActiveUser oldUser = activeUsersColl.FindOne(x => x.peerId == keyID); if (oldUser != null) { //Debug.LogError ("Removing for id: " + peerID); activeUsersColl.Delete(oldUser.peerId); UserLoginInformation savedUser = userLoginColl.FindOne(x => x.username == oldUser.username); if (savedUser != null) { savedUser.isLoggedIn = false; updateLoginInfo(savedUser); } UserDataModule.userLogedOut(oldUser.username); } }
public static void onUserLogedIn(UserLoginInformation user, int peerID) { user.isLoggedIn = true; updateLoginInfo(user); addActiveUser(user, peerID); }