/// <summary> /// Checks whether the client is allowed to login and -if so- logs it in /// </summary> /// <remarks>Executed in IO-Context.</remarks> /// <param name="client"></param> /// <param name="charLowId"></param> private static void LoginCharacter(IRealmClient client, uint charLowId) { RealmAccount account = client.Account; if (account == null) { return; } CharacterRecord record = client.Account.GetCharacterRecord(charLowId); if (record == null) { LoginHandler.log.Error(string.Format(WCell_RealmServer.CharacterNotFound, (object)charLowId, (object)account.Name)); LoginHandler.SendCharacterLoginFail((IPacketReceiver)client, LoginErrorCode.CHAR_LOGIN_NO_CHARACTER); } else if (record.CharacterFlags.HasAnyFlag(CharEnumFlags.NeedsRename | CharEnumFlags.LockedForBilling)) { LoginHandler.SendCharacterLoginFail((IPacketReceiver)client, LoginErrorCode.AUTH_BILLING_EXPIRED); } else { if (client.ActiveCharacter != null) { return; } Character character = (Character)null; try { Func <IRealmClient, CharacterRecord, CharacterRecord> beforeLogin = LoginHandler.BeforeLogin; if (beforeLogin != null) { record = beforeLogin(client, record); if (record == null) { throw new ArgumentNullException("record", "BeforeLogin returned null"); } } character = record.CreateCharacter(); character.Create(account, record, client); character.LoadAndLogin(); string str = string.Format("Welcome to " + WCell.RealmServer.RealmServer.FormattedTitle); MiscHandler.SendMotd((IPacketReceiver)client, str); } catch (Exception ex) { LogUtil.ErrorException(ex, "Failed to load Character from Record: " + (object)record, new object[0]); if (character == null) { return; } character.Dispose(); client.Disconnect(false); } } }
/// <summary>Sends an auth session success response to the client.</summary> /// <param name="client">the client to send to</param> public static void InviteToRealm(IRealmClient client) { Action <RealmAccount> accountLogin = LoginHandler.AccountLogin; if (accountLogin != null) { accountLogin(client.Account); } LoginHandler.SendAuthSuccessful(client); }
/// <summary>Handles an incoming player login request.</summary> /// <param name="client">the Session the incoming packet belongs to</param> /// <param name="packet">the full packet</param> public static void PlayerLoginRequest(IRealmClient client, RealmPacketIn packet) { if (client.Account == null || client.ActiveCharacter != null) { return; } uint charLowId = packet.ReadEntityId().Low; try { Character chr = World.GetCharacter(charLowId); if (chr != null) { if (!chr.IsLoggingOut) { LoginHandler.log.Error(WCell_RealmServer.CharacterAlreadyConnected, (object)charLowId, (object)client.Account.Name); LoginHandler.SendCharacterLoginFail((IPacketReceiver)client, LoginErrorCode.CHAR_LOGIN_DUPLICATE_CHARACTER); } else { chr.Map.AddMessage((IMessage) new Message((Action)(() => { if (!chr.IsInContext) { ServerApp <WCell.RealmServer.RealmServer> .IOQueue.AddMessage( (IMessage) new Message((Action)(() => LoginHandler.LoginCharacter(client, charLowId)))); } else { chr.ReconnectCharacter(client); } }))); } } else { LoginHandler.LoginCharacter(client, charLowId); } } catch (Exception ex) { LoginHandler.log.Error((object)ex); LoginHandler.SendCharacterLoginFail((IPacketReceiver)client, LoginErrorCode.CHAR_LOGIN_FAILED); } }