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); }
public void ReceiveAuthAsync(IAsyncResult ar) { try { AsyncState state = (AsyncState)(ar.AsyncState); int bytes = Socket.Socket.EndReceive(ar); packetizer.QueuePackets(state.buffer, bytes); int p = packetizer.ProcessPackets(); for (int i = 0; i < p; i++) { try { byte[] packet = packetizer.PopItem(); PyObject obj = Unmarshal.Process <PyObject>(packet); if (obj != null) { PyObject result = TCPHandler.ProcessAuth(obj, this); if (result != null) { Send(result); } if (StageEnded == true) { if (Type == ConnectionType.Node) { recvAsync = new AsyncCallback(ReceiveNodeAsync); } else if (Type == ConnectionType.Client) { recvAsync = new AsyncCallback(ReceiveClientAsync); } // Exit from the loop to keep the packets in the list ;) break; } } } catch (Exception ex) { Log.Error("Connection", ex.ToString()); } } // Continue receiving data Socket.Socket.BeginReceive(state.buffer, 0, 8192, SocketFlags.None, recvAsync, state); } catch (ObjectDisposedException) { Log.Debug("Connection", "Disconnected"); ConnectionManager.RemoveConnection(this); } catch (SocketException) { Log.Debug("Connection", "Disconnected"); ConnectionManager.RemoveConnection(this); } catch (Exception ex) { Log.Error("Connection", "Caught unhandled exception: " + ex.ToString()); } }