public long PerformOnChatEnter() { //No, don't do anything for these guys. /*if (isIrcUser) return true;*/ PerformOnPing(true); //bool result = false; lock (Lock) { //Our last join was now (assuming this is called correctly) recentJoins.Add(DateTime.Now); recentJoins = recentJoins.Where(x => x > DateTime.Now.AddDays(-1)).ToList(); //Fix bad sessions which may be present. foreach (UserSession badSession in sessions.Where(x => !x.Entered)) badSession.SetEnterNow(); //If a user is entering, close ALL other sessions. foreach (UserSession openSession in sessions.Where(x => !x.Left)) openSession.SetLeaveNow(); UserSession session = new UserSession(); session.SetEnterNow(); sessions.Add(session); // //If it's empty or we have no open sessions, add a new one // if (sessions.Count == 0 || sessions.All(x => x.Entered)) // { // sessions.Add(new UserSession()); // result = true; // } // try // { // //Look for the last session that hasn't entered yet and set the entry to now. // sessions.Last(x => !x.Entered).SetEnterNow(); // } // catch // { // return false; // } return session.ID; } //We're only good if we succeeded AND there's only one session open //return result && (sessions.Count(x => !x.Left) == 1); }
public long PerformOnChatEnter() { PerformOnPing(true); lock (Lock) { LastJoin = DateTime.Now; //Fix bad sessions which may be present. foreach (UserSession badSession in sessions.Where(x => !x.Entered)) badSession.SetEnterNow(); //If a user is entering, close ALL other sessions. foreach (UserSession openSession in sessions.Where(x => !x.Left)) openSession.SetLeaveNow(); UserSession session = new UserSession(); session.SetEnterNow(); sessions.Add(session); return session.ID; } }