/// <summary> /// Handles the request to create a new account. /// </summary> /// <param name="conn">Connection that the request was made on.</param> /// <param name="name">The name of the character to create.</param> public void CreateAccountCharacter(IIPSocket conn, string name) { if (!RequireServerRunning()) { return; } ThreadAsserts.IsMainThread(); // Get the account var account = conn.Tag as IUserAccount; if (account == null) { return; } // Try to create the character string errorMessage; var success = UserAccountManager.TryAddCharacter(account.Name, name, out errorMessage); // Send the result to the client (which we have to do both when successful and failed) using (var pw = ServerPacket.CreateAccountCharacter(success, errorMessage)) { conn.Send(pw, ServerMessageType.System); } // If we successfully created the character, reload and resync the character listing if (success) { account.LoadCharacterIDs(); account.SendAccountCharacterInfos(); } }
/// <summary> /// Handles the login attempt of an account. /// </summary> /// <param name="conn">Connection that the login request was made on.</param> /// <param name="name">Name of the account.</param> /// <param name="password">Entered password for this account.</param> public void LoginAccount(IIPSocket conn, string name, string password) { if (!RequireServerRunning()) { return; } ThreadAsserts.IsMainThread(); if (conn == null) { if (log.IsErrorEnabled) { log.Error("conn is null."); } return; } // Try to log in the account IUserAccount userAccount; var loginResult = UserAccountManager.Login(conn, name, password, out userAccount); // Check that the login was successful if (loginResult != AccountLoginResult.Successful) { HandleFailedLogin(conn, loginResult, name); return; } // Check if banned int banMins; string banReason; if (BanningManager.Instance.IsBanned(userAccount.ID, out banReason, out banMins)) { userAccount.Dispose(GameMessage.AccountBanned, banMins, banReason); if (log.IsInfoEnabled) { log.InfoFormat("Disconnected account `{0}` after successful login since they have been banned.", name); } return; } // Set the connection's tag to the account conn.Tag = userAccount; // Send the "Login Successful" message using (var pw = ServerPacket.LoginSuccessful()) { conn.Send(pw, ServerMessageType.System); } if (log.IsInfoEnabled) { log.InfoFormat("Login for account `{0}` successful.", name); } // Send the account characters userAccount.SendAccountCharacterInfos(); }
/// <summary> /// Handles the request to create a new account. /// </summary> /// <param name="conn">Connection that the request was made on.</param> /// <param name="name">Name of the account.</param> /// <param name="password">Entered password for this account.</param> /// <param name="email">The email address.</param> public void CreateAccount(IIPSocket conn, string name, string password, string email) { if (!RequireServerRunning()) { return; } ThreadAsserts.IsMainThread(); if (conn == null) { if (log.IsErrorEnabled) { log.Error("conn is null."); } return; } // Create the account GameMessage failReason; var success = UserAccountManager.TryCreateAccount(conn, name, password, email, out failReason); // Send the appropriate success message using (var pw = ServerPacket.CreateAccount(success, failReason)) { conn.Send(pw, ServerMessageType.System); } }
void RecvSynchronizeGameTime(IIPSocket conn, BitStream r) { // Just reply immediately with the current game time using (var pw = ServerPacket.SetGameTime(DateTime.Now)) { conn.Send(pw, ServerMessageType.GUI); } }
void RecvRequestMapEntityIndex(IIPSocket conn, BitStream r) { var index = r.ReadMapEntityIndex(); // Get the user and their map User user; if ((user = TryGetUser(conn)) == null) { return; } Map map; if (!TryGetMap(user, out map)) { return; } // Get the DynamicEntity var de = map.GetDynamicEntity(index); if (de == null) { // The DynamicEntity for the index was null, so tell the client to delete whatever is at that index using (var pw = ServerPacket.RemoveDynamicEntity(index)) { conn.Send(pw, ServerMessageType.Map); } } else { // A DynamicEntity does exist at that index, so tell the client to create it using (var pw = ServerPacket.CreateDynamicEntity(de)) { conn.Send(pw, ServerMessageType.Map); } } }
/// <summary> /// When overridden in the derived class, allows for handling when the status of an <see cref="IIPSocket"/> changes. /// </summary> /// <param name="sender">The <see cref="IIPSocket"/> who's status has changed.</param> /// <param name="status">The new status.</param> /// <param name="reason">The reason for the status change.</param> protected override void OnReceiveStatusChanged(IIPSocket sender, NetConnectionStatus status, string reason) { base.OnReceiveStatusChanged(sender, status, reason); switch (status) { case NetConnectionStatus.Disconnected: // If there was an account on the socket, destroy it var acc = World.GetUserAccount(sender, false); if (acc != null) { acc.Dispose(); } break; case NetConnectionStatus.Connected: // Send the server time to the client using (var pw = ServerPacket.SetGameTime(DateTime.Now)) { sender.Send(pw, ServerMessageType.GUI); } break; } }
/// <summary> /// When overridden in the derived class, allows for handling when the status of an <see cref="IIPSocket"/> changes. /// </summary> /// <param name="sender">The <see cref="IIPSocket"/> who's status has changed.</param> /// <param name="status">The new status.</param> /// <param name="reason">The reason for the status change.</param> protected override void OnReceiveStatusChanged(IIPSocket sender, NetConnectionStatus status, string reason) { base.OnReceiveStatusChanged(sender, status, reason); switch (status) { case NetConnectionStatus.Disconnected: // If there was an account on the socket, destroy it var acc = World.GetUserAccount(sender, false); if (acc != null) acc.Dispose(); break; case NetConnectionStatus.Connected: // Send the server time to the client using (var pw = ServerPacket.SetGameTime(DateTime.Now)) { sender.Send(pw, ServerMessageType.GUI); } break; } }
void RecvRequestMapEntityIndex(IIPSocket conn, BitStream r) { var index = r.ReadMapEntityIndex(); // Get the user and their map User user; if ((user = TryGetUser(conn)) == null) return; Map map; if (!TryGetMap(user, out map)) return; // Get the DynamicEntity var de = map.GetDynamicEntity(index); if (de == null) { // The DynamicEntity for the index was null, so tell the client to delete whatever is at that index using (var pw = ServerPacket.RemoveDynamicEntity(index)) { conn.Send(pw, ServerMessageType.Map); } } else { // A DynamicEntity does exist at that index, so tell the client to create it using (var pw = ServerPacket.CreateDynamicEntity(de)) { conn.Send(pw, ServerMessageType.Map); } } }
/// <summary> /// Handles the login attempt of an account. /// </summary> /// <param name="conn">Connection that the login request was made on.</param> /// <param name="name">Name of the account.</param> /// <param name="password">Entered password for this account.</param> public void LoginAccount(IIPSocket conn, string name, string password) { if (!RequireServerRunning()) return; ThreadAsserts.IsMainThread(); if (conn == null) { if (log.IsErrorEnabled) log.Error("conn is null."); return; } // Try to log in the account IUserAccount userAccount; var loginResult = UserAccountManager.Login(conn, name, password, out userAccount); // Check that the login was successful if (loginResult != AccountLoginResult.Successful) { HandleFailedLogin(conn, loginResult, name); return; } // Check if banned int banMins; string banReason; if (BanningManager.Instance.IsBanned(userAccount.ID, out banReason, out banMins)) { userAccount.Dispose(GameMessage.AccountBanned, banMins, banReason); if (log.IsInfoEnabled) log.InfoFormat("Disconnected account `{0}` after successful login since they have been banned.", name); return; } // Set the connection's tag to the account conn.Tag = userAccount; // Send the "Login Successful" message using (var pw = ServerPacket.LoginSuccessful()) { conn.Send(pw, ServerMessageType.System); } if (log.IsInfoEnabled) log.InfoFormat("Login for account `{0}` successful.", name); // Send the account characters userAccount.SendAccountCharacterInfos(); }
/// <summary> /// Handles the request to create a new account. /// </summary> /// <param name="conn">Connection that the request was made on.</param> /// <param name="name">The name of the character to create.</param> public void CreateAccountCharacter(IIPSocket conn, string name) { if (!RequireServerRunning()) return; ThreadAsserts.IsMainThread(); // Get the account var account = conn.Tag as IUserAccount; if (account == null) return; // Try to create the character string errorMessage; var success = UserAccountManager.TryAddCharacter(account.Name, name, out errorMessage); // Send the result to the client (which we have to do both when successful and failed) using (var pw = ServerPacket.CreateAccountCharacter(success, errorMessage)) { conn.Send(pw, ServerMessageType.System); } // If we successfully created the character, reload and resync the character listing if (success) { account.LoadCharacterIDs(); account.SendAccountCharacterInfos(); } }
/// <summary> /// Handles the request to create a new account. /// </summary> /// <param name="conn">Connection that the request was made on.</param> /// <param name="name">Name of the account.</param> /// <param name="password">Entered password for this account.</param> /// <param name="email">The email address.</param> public void CreateAccount(IIPSocket conn, string name, string password, string email) { if (!RequireServerRunning()) return; ThreadAsserts.IsMainThread(); if (conn == null) { if (log.IsErrorEnabled) log.Error("conn is null."); return; } // Create the account GameMessage failReason; var success = UserAccountManager.TryCreateAccount(conn, name, password, email, out failReason); // Send the appropriate success message using (var pw = ServerPacket.CreateAccount(success, failReason)) { conn.Send(pw, ServerMessageType.System); } }