private static void Run() { // We should never exit from this loop try { while (true) { Thread.Sleep(1); if (Environment.HasShutdownStarted) { // This will shutdown all the nodes // throw new ProxyClosingException(); return; } if (queue.Count == 0) { continue; } // Thread safe stuff lock (queue) { LoginQueueEntry now = queue.Dequeue(); if (now == null) { continue; } HandleLogin(now); } } } catch (ThreadAbortException) { // throw new ProxyClosingException(); return; } /*catch (ProxyClosingException) * { * throw new ProxyClosingException(); * }*/ catch (Exception ex) { Log.Error("LoginQueue", "Unhandled exception... " + ex.Message); Log.Error("ExceptionHandler", "Stack trace: " + ex.StackTrace); } Log.Error("LoginQueue", "LoginQueue is closing... Bye Bye!"); }
public static void Enqueue(Connection con, AuthenticationReq packet) { // Just to be thread safe lock (queue) { LoginQueueEntry entry = new LoginQueueEntry(); entry.connection = con; entry.request = packet; queue.Enqueue(entry); } }
public static void HandleLogin(LoginQueueEntry entry) { Log.Debug("LoginQueue", "Login try " + entry.request.user_name); LoginStatus status = LoginStatus.Waiting; long accountID = 0; bool banned = false; long role = 0; // First check if the account exists if (Database.AccountDB.AccountExists(entry.request.user_name) == false) { // Create the account Database.AccountDB.CreateAccount(entry.request.user_name, entry.request.user_password); } if ((Database.AccountDB.LoginPlayer(entry.request.user_name, entry.request.user_password, ref accountID, ref banned, ref role) == false) || (banned == true)) { Log.Trace("LoginQueue", ": Rejected by database"); status = LoginStatus.Failed; } else { Log.Trace("LoginQueue", ": success"); // Fill the class with the required data entry.connection.AccountID = accountID; entry.connection.Banned = banned; entry.connection.Role = role; entry.connection.LanguageID = entry.request.user_languageid; status = LoginStatus.Sucess; } TCPHandler.SendLoginNotification(status, entry.connection); }