private 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 (this.Queue.Count == 0) { continue; } // Thread safe stuff lock (this.Queue) { LoginQueueEntry now = this.Queue.Dequeue(); if (now is null) { continue; } HandleLogin(now); } } } catch (ThreadAbortException) { // throw new ProxyClosingException(); return; } /*catch (ProxyClosingException) * { * throw new ProxyClosingException(); * }*/ catch (Exception ex) { Log.Error("Unhandled exception... " + ex.Message); Log.Error("Stack trace: " + ex.StackTrace); } Log.Error("LoginQueue is closing... Bye Bye!"); }
public void Enqueue(ClientConnection connection, AuthenticationReq request) { // Just to be thread safe lock (this.Queue) { LoginQueueEntry entry = new LoginQueueEntry(); entry.Connection = connection; entry.Request = request; this.Queue.Enqueue(entry); } }
public void HandleLogin(LoginQueueEntry entry) { Log.Debug("Processing login for " + entry.Request.user_name); LoginStatus status = LoginStatus.Waiting; long accountID = 0; bool banned = false; long role = 0; // First check if the account exists if (this.AccountDB.AccountExists(entry.Request.user_name) == false) { if (this.Configuration.Autoaccount == true) { Log.Info($"Auto account enabled, creating account for user {entry.Request.user_name}"); // Create the account this.AccountDB.CreateAccount(entry.Request.user_name, entry.Request.user_password, (ulong)this.Configuration.Role); } } if (this.AccountDB.LoginPlayer(entry.Request.user_name, entry.Request.user_password, ref accountID, ref banned, ref role) == false || banned == true) { Log.Trace(": Rejected by database"); status = LoginStatus.Failed; } else { Log.Trace(": success"); status = LoginStatus.Success; } entry.Connection.SendLoginNotification(status, accountID, role); }