예제 #1
0
            public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
            {
                string accName = trigger.Text.NextWord();

                if (accName != null)
                {
                    RealmAccount acc = ServerApp <RealmServer> .Instance.GetOrRequestAccount(accName);

                    if (acc != null)
                    {
                        if (acc.IsActive)
                        {
                            trigger.Reply("Account '" + acc.Name + "' is not banned.");
                        }

                        else
                        {
                            trigger.Reply(acc.StatusUntil.Value.ToLongDateString());
                        }
                    }

                    else
                    {
                        trigger.Reply("Account '" + accName + "' does not exist.");
                    }
                }
                else
                {
                    trigger.Reply("Please include the account name.");
                }
            }
예제 #2
0
 public static void DumpPacket(RealmAccount acc, RealmPacketIn packet, bool copy, PacketSender sender)
 {
     if (CanDump(packet.PacketId))
     {
         var writer = GetTextWriter(acc);
         DumpPacket(packet, sender, copy, writer);
     }
 }
예제 #3
0
        /// <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);
                }
            }
        }
예제 #4
0
        private static void LoginCharacter(IRealmClient client, uint charLowId, bool isLoginStep)
        {
            RealmAccount account = client.Account;

            if (account == null)
            {
                return;
            }
            CharacterRecord record = client.Account.GetCharacterRecord(charLowId);

            if (record == null)
            {
                Asda2LoginHandler.log.Error(string.Format(WCell_RealmServer.CharacterNotFound, (object)charLowId,
                                                          (object)account.Name));
                client.Disconnect(false);
            }
            else
            {
                if (client.ActiveCharacter != null)
                {
                    return;
                }
                Character character = (Character)null;
                try
                {
                    Func <IRealmClient, CharacterRecord, CharacterRecord> beforeLogin = Asda2LoginHandler.BeforeLogin;
                    if (beforeLogin != null)
                    {
                        record = beforeLogin(client, record);
                        if (record == null)
                        {
                            throw new ArgumentNullException("record", "BeforeLogin returned null");
                        }
                    }

                    character = record.CreateCharacter();
                    if (isLoginStep)
                    {
                        character.IsLoginServerStep     = true;
                        character.IsFirstGameConnection = true;
                    }

                    character.Create(account, record, client);
                    character.LoadAndLogin();
                }
                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);
                }
            }
        }
예제 #5
0
 public FakeRealmClient(RealmAccount acc)
     : base(RealmServer.Instance, FakePacketMgr.Instance)
 {
     Account = acc;
     //if (!Account.Initialize())
     //{
     //    throw new Exception("Could not initialize Account!");
     //}
 }
예제 #6
0
 /// <summary>
 /// Use this ctor on authed users only
 /// </summary>
 /// <param name="account"></param>
 public WCellArgs(RealmAccount account)
 {
     if (account == null)
     {
         throw new NullReferenceException("account");
     }
     Account = account;
     AcceptExceptionEchos = true;
 }
예제 #7
0
 public static void DumpPacketOut(RealmAccount acc, RealmPacketOut packetOut, PacketSender sender)
 {
     if (CanDump(packetOut.PacketId))
     {
         var writer = GetTextWriter(acc);
         using (var packet = DisposableRealmPacketIn.CreateFromOutPacket(packetOut))
         {
             DumpPacket(packet, sender, false, writer);
         }
     }
 }
예제 #8
0
        /// <summary>
        /// Dumps the content of an Update packet to the console
        /// </summary>
        //public static void DumpUpdatePacket(RealmPacketOut packet)
        //{
        //    try
        //    {
        //        ParsedUpdatePacket.Dump(packet.GetPacketPayload(), false, m_updatePacketWriter);
        //        m_updatePacketWriter.Flush();
        //    }
        //    catch (Exception e)
        //    {
        //        OnException("Failed to parse Update-Packet.", e, packet.GetPacketPayload());
        //    }
        //}

        public static void DumpPacketOut(RealmAccount acc, byte[] packetOut, int offset, int length, PacketSender sender)
        {
            if (Dumps)
            {
                var writer = GetTextWriter(acc);
                using (var packet = DisposableRealmPacketIn.CreateFromOutPacket(packetOut, offset, length))
                {
                    if (CanDump(packet.PacketId))
                    {
                        DumpPacket(packet, sender, false, writer);
                    }
                }
            }
        }
예제 #9
0
        public static void CharacterInitOnChanelChangeRequest(IRealmClient client, RealmPacketIn packet)
        {
            if (client == null || client.ClientAddress == null)
            {
                return;
            }
            int     num     = packet.ReadInt32();
            Account account = AccountMgr.GetAccount(num);

            if (account == null || account.LastIPStr != client.ClientAddress.ToString())
            {
                if (account != null)
                {
                    Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)num)
                    .AddAttribute("operation", 1.0, "login_on_map_change_bad_ip")
                    .AddAttribute("name", 0.0, account.Name)
                    .AddAttribute("ip", 0.0, client.ClientAddress.ToString())
                    .AddAttribute("old_ip", 0.0, account.LastIPStr).Write();
                }
                client.Disconnect(false);
            }
            else
            {
                RealmAccount loggedInAccount =
                    ServerApp <RealmServer> .Instance.GetLoggedInAccount(account.Name);

                if (loggedInAccount == null || loggedInAccount.ActiveCharacter == null)
                {
                    client.Disconnect(false);
                }
                else
                {
                    client.IsGameServerConnection = true;
                    client.Account = loggedInAccount;
                    LogHelperEntry lgDelete = Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)num)
                                              .AddAttribute("operation", 1.0, "login_on_map_change").AddAttribute("name", 0.0, account.Name)
                                              .AddAttribute("chr", loggedInAccount.ActiveCharacter.EntryId,
                                                            loggedInAccount.ActiveCharacter.Name)
                                              .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                    Log.Create(Log.Types.AccountOperations, LogSourceType.Character,
                               loggedInAccount.ActiveCharacter.EntityId.Low)
                    .AddAttribute("operation", 1.0, "login_on_map_change")
                    .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).AddAttribute("chr",
                                                                                           loggedInAccount.ActiveCharacter.EntryId, loggedInAccount.ActiveCharacter.Name)
                    .AddReference(lgDelete).Write();
                    PreLoginCharacter(client, loggedInAccount.ActiveCharacter.EntityId.Low, false);
                }
            }
        }
예제 #10
0
        public AccountFullInfo LogoffAccount(string name)
        {
            Account account = AccountMgr.GetAccount(name);

            if (account == null)
            {
                return((AccountFullInfo)null);
            }
            RealmAccount loggedInAccount = ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(name);

            if (loggedInAccount != null && loggedInAccount.ActiveCharacter != null)
            {
                loggedInAccount.ActiveCharacter.Kick("Logging of account by administrator.");
            }
            return(this.InitAccount(account));
        }
예제 #11
0
        /// <summary>
        /// Gets the <see cref="T:WCell.Util.Threading.IContextHandler" /> that should handle this incoming packet
        /// </summary>
        /// <param name="client"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public IContextHandler CheckConstraints(IRealmClient client,
                                                PacketHandler <IRealmClient, RealmPacketIn> handlerDesc, RealmPacketIn packet)
        {
            if (!client.IsConnected)
            {
                return((IContextHandler)null);
            }
            Character activeCharacter = client.ActiveCharacter;

            if (handlerDesc.RequiresLogIn && activeCharacter == null)
            {
                RealmPacketMgr.s_log.Warn("Client {0} sent Packet {1} without selected Character.", (object)client,
                                          (object)packet);
                return((IContextHandler)null);
            }

            RealmAccount account = client.Account;

            if (!handlerDesc.IsGamePacket)
            {
                if (account == null || !account.IsEnqueued)
                {
                    return((IContextHandler)ServerApp <WCell.RealmServer.RealmServer> .IOQueue);
                }
                RealmPacketMgr.s_log.Warn("Enqueued client {0} sent: {1}", (object)client, (object)packet);
                return((IContextHandler)null);
            }

            if (activeCharacter == null || account == null)
            {
                RealmPacketMgr.s_log.Warn("Client {0} sent Packet {1} before login completed.", (object)client,
                                          (object)packet);
                client.Disconnect(false);
            }
            else
            {
                if (activeCharacter.Map != null)
                {
                    return((IContextHandler)activeCharacter);
                }
                RealmPacketMgr.s_log.Warn("Received packet {0} from Character {1} while not in world.", (object)packet,
                                          (object)activeCharacter);
                client.Disconnect(false);
            }

            return((IContextHandler)null);
        }
예제 #12
0
 /// <summary>
 /// Gets the characters for the given account.
 /// </summary>
 /// <param name="account">the account</param>
 /// <returns>a collection of character objects of the characters on the given account</returns>
 public static CharacterRecord[] FindAllOfAccount(RealmAccount account)
 {
     CharacterRecord[] chrs;
     try
     {
         chrs = FindAllByProperty("Created", "AccountId", account.AccountId);
         //var chrs = FindAllByProperty("Created", "AccountId", account.AccountId);
         //chrs.Reverse();
         //return chrs;
     }
     catch (Exception ex)
     {
         RealmDBMgr.OnDBError(ex);
         chrs = FindAllByProperty("Created", "AccountId", account.AccountId);
     }
     //chrs.Reverse();
     return(chrs);
 }
예제 #13
0
 /// <summary>
 /// Creates a new CharacterRecord row in the database with the given information.
 /// </summary>
 /// <param name="account">the account this character is on</param>
 /// <param name="name">the name of the new character</param>
 /// <returns>the <seealso cref="T:WCell.RealmServer.Database.CharacterRecord" /> object</returns>
 public static CharacterRecord CreateNewCharacterRecord(RealmAccount account, string name)
 {
     try
     {
         return(new CharacterRecord(account.AccountId)
         {
             EntityLowId = (uint)CharacterRecord._idGenerator.Next(),
             Name = name,
             Created = DateTime.Now
         });
     }
     catch (Exception ex)
     {
         CharacterRecord.s_log.Error(
             "Character creation error (DBS: " + RealmServerConfiguration.DatabaseType + "): ", (object)ex);
         return((CharacterRecord)null);
     }
 }
예제 #14
0
        public static void ViewCharacterTradeShopRequest(IRealmClient client, RealmPacketIn packet)
        {
            RealmAccount loggedInAccount =
                ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(packet.ReadUInt32());

            if (loggedInAccount == null || loggedInAccount.ActiveCharacter == null)
            {
                Asda2PrivateShopHandler.SendCharacterPrivateShopInfoResponse(client,
                                                                             Asda2ViewTradeShopInfoStatus.TheCapacityHasExided, (Asda2PrivateShop)null);
            }
            else
            {
                Character activeCharacter = loggedInAccount.ActiveCharacter;
                if (activeCharacter.PrivateShop == null || !activeCharacter.PrivateShop.Trading)
                {
                    return;
                }
                activeCharacter.PrivateShop.Join(client.ActiveCharacter);
            }
        }
        public void UpdateCharacters()
        {
            this.SaveAndFlush();
            RealmAccount loggedInAccount1 =
                ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(this.AccId);

            RealmAccount loggedInAccount2 =
                ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(this.RelatedAccId);

            if (loggedInAccount1 != null && loggedInAccount1.ActiveCharacter != null)
            {
                if (!this.IsActive)
                {
                    loggedInAccount1.ActiveCharacter.RemovaAllSoulmateBonuses();
                }
                loggedInAccount1.ActiveCharacter.ProcessSoulmateRelation(false);
                if (this.IsActive && loggedInAccount2 != null && loggedInAccount2.ActiveCharacter != null)
                {
                    Asda2SoulmateHandler.SendYouHaveSoulmatedWithResponse(loggedInAccount1.ActiveCharacter.Client,
                                                                          SoulmatingResult.Ok, (uint)this.SoulmateRelationGuid, this.RelatedAccId,
                                                                          loggedInAccount2.ActiveCharacter.Name);
                }
            }

            if (loggedInAccount2 == null || loggedInAccount2.ActiveCharacter == null)
            {
                return;
            }
            if (!this.IsActive)
            {
                loggedInAccount2.ActiveCharacter.RemovaAllSoulmateBonuses();
            }
            loggedInAccount2.ActiveCharacter.ProcessSoulmateRelation(false);
            if (!this.IsActive || loggedInAccount1 == null || loggedInAccount1.ActiveCharacter == null)
            {
                return;
            }
            Asda2SoulmateHandler.SendYouHaveSoulmatedWithResponse(loggedInAccount2.ActiveCharacter.Client,
                                                                  SoulmatingResult.Ok, (uint)this.SoulmateRelationGuid, this.AccId,
                                                                  loggedInAccount1.ActiveCharacter.Name);
        }
예제 #16
0
        public AccountFullInfo UnBanAccount(string name)
        {
            Account account = AccountMgr.GetAccount(name);

            if (account == null)
            {
                return((AccountFullInfo)null);
            }
            RealmAccount loggedInAccount = ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(name);

            if (loggedInAccount != null)
            {
                loggedInAccount.SetAccountActive(true, new DateTime?());
            }
            else
            {
                account.IsActive = true;
                account.SaveLater();
            }

            return(this.InitAccount(account));
        }
예제 #17
0
        public static void AuthSessionRequest(IRealmClient client, RealmPacketIn packet)
        {
            if (client.ActiveCharacter != null || client.Account != null)
            {
                // Already logged in
                SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_ALREADY_ONLINE);
                client.Disconnect();
            }
            else if (!client.IsEncrypted)
            {
                var builtNumberClient = packet.ReadUInt32();
                var new302            = packet.ReadUInt32();      // NEW 0.0.2.8970
                var accName           = packet.ReadCString();
                var unk322            = packet.ReadUInt32();

                client.ClientSeed = packet.ReadUInt32();

                var unk1 = packet.ReadUInt32();                 // 3.3.5a
                var unk2 = packet.ReadUInt32();                 // 3.3.5a
                var unk3 = packet.ReadUInt32();                 // 3.3.5a
                var unk4 = packet.ReadUInt64();

                client.ClientDigest = packet.ReadBigInteger(20);

#if DEBUG
                log.Debug("builtNumberClient:{0} new302:{1} accName:{2} unk322:{3} client.ClientSeed:{4} unk4:{5} ClientDigest:{6}",
                          builtNumberClient,
                          new302, accName, unk322, client.ClientSeed, unk4, client.ClientDigest);
#endif

                var decompressedDataLength = packet.ReadInt32();
                var compressedData         = packet.ReadBytes(packet.RemainingLength);
                client.Addons = new byte[decompressedDataLength];
                Compression.DecompressZLib(compressedData, client.Addons);

                var acctLoadTask = Message.Obtain(() => RealmAccount.InitializeAccount(client, accName));
                RealmServer.IOQueue.AddMessage(acctLoadTask);
            }
        }
예제 #18
0
        public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
        {
            if (!trigger.Text.HasNext)
            {
                trigger.Reply("You need to specify the name of the Player to be summoned.");
            }
            else
            {
                string    str  = trigger.Text.NextModifiers();
                bool      flag = str.Contains("q");
                string    name = trigger.Text.NextWord();
                Character character;
                if (str.Contains("a"))
                {
                    RealmAccount loggedInAccount =
                        ServerApp <RealmServer> .Instance.GetLoggedInAccount(name);

                    character = loggedInAccount == null ? null : loggedInAccount.ActiveCharacter;
                }
                else
                {
                    character = World.GetCharacter(name, false);
                }

                if (character == null)
                {
                    trigger.Reply(RealmLangKey.CmdSummonPlayerNotOnline, (object)name);
                }
                else if (flag || character.Role > trigger.Args.Character.Role)
                {
                    character.StartSummon(trigger.Args.Character);
                }
                else
                {
                    character.TeleportTo(trigger.Args.Target.Map, trigger.Args.Target.Position);
                }
            }
        }
예제 #19
0
        public AccountFullInfo BanAccount(string name, DateTime until)
        {
            Account account = AccountMgr.GetAccount(name);

            if (account == null)
            {
                return(null);
            }
            RealmAccount loggedInAccount = ServerApp <RealmServer> .Instance.GetLoggedInAccount(name);

            if (loggedInAccount != null)
            {
                loggedInAccount.SetAccountActive(false, until);
            }
            else
            {
                account.IsActive    = false;
                account.StatusUntil = until;
                account.SaveLater();
            }

            return(InitAccount(account));
        }
예제 #20
0
        /// <summary>Gets the characters for the given account.</summary>
        /// <param name="account">the account</param>
        /// <returns>a collection of character objects of the characters on the given account</returns>
        public static CharacterRecord[] FindAllOfAccount(RealmAccount account)
        {
            CharacterRecord[] allByProperty;
            try
            {
                allByProperty =
                    FindAllByProperty("Created", "AccountId",
                                      account.AccountId);
                foreach (CharacterRecord characterRecord in allByProperty)
                {
                    characterRecord.LoadItems();
                }
            }
            catch (Exception ex)
            {
                RealmDBMgr.OnDBError(ex);
                allByProperty =
                    FindAllByProperty("Created", "AccountId",
                                      account.AccountId);
            }

            return(allByProperty);
        }
예제 #21
0
        public static IndentTextWriter GetTextWriter(RealmAccount account)
        {
            IndentTextWriter writer;

            if (account == null)
            {
                writer = DefaultWriter;
            }
            else if (!m_packetWriters.TryGetValue(account.Name, out writer))
            {
                lock (m_packetWriters)
                {
                    // check if the writer was added after the lock was released
                    if (!m_packetWriters.TryGetValue(account.Name, out writer))
                    {
                        try
                        {
                            var file     = Path.Combine(DumpDir.FullName, account.Name + ".txt");
                            var fileInfo = new FileInfo(file);
                            var append   = fileInfo.Exists ? fileInfo.Length < MaxDumpFileSize : false;
                            writer = new IndentTextWriter(new StreamWriter(file, append))
                            {
                                AutoFlush = true
                            };
                            m_packetWriters.Add(account.Name, writer);
                        }
                        catch (Exception e)
                        {
                            LogUtil.WarnException("Writing to Default writer - TextWriter for Account {0} could not be created: {1}", account, e);
                            return(DefaultWriter);
                        }
                    }
                }
            }
            return(writer);
        }
예제 #22
0
        public static void SendEnterGameResposeResponse(IRealmClient client)
        {
            if (client.Account == null)
            {
                return;
            }
            using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.EnterGameRespose))
            {
                RealmAccount account         = client.Account;
                Character    activeCharacter = account.ActiveCharacter;
                if (activeCharacter == null)
                {
                    return;
                }
                packet.WriteInt32(account.AccountId);
                packet.WriteFixedAsciiString(activeCharacter.Name, 20, Locale.Start);
                packet.WriteInt16(activeCharacter.Record.CharNum);
                packet.WriteByte(activeCharacter.Record.Zodiac);
                packet.WriteByte((byte)activeCharacter.Gender);
                packet.WriteByte(activeCharacter.ProfessionLevel);
                packet.WriteByte((byte)activeCharacter.Archetype.ClassId);
                packet.WriteByte(activeCharacter.Level);
                packet.WriteUInt32(activeCharacter.Experience);
                packet.WriteInt32(0);
                packet.WriteInt16(activeCharacter.Spells.AvalibleSkillPoints);
                packet.WriteInt16(0);
                packet.WriteByte(0);
                packet.WriteInt16(15000);
                packet.WriteInt16(1000);
                packet.WriteInt64(0L);
                packet.WriteByte(0);
                packet.WriteByte(3);
                packet.WriteInt16((client.ActiveCharacter.Record.PremiumWarehouseBagsCount + 1) * 30);
                packet.WriteInt16(
                    client.ActiveCharacter.Asda2Inventory.WarehouseItems.Count(
                        i => i != null));
                packet.WriteInt16((client.ActiveCharacter.Record.PremiumAvatarWarehouseBagsCount + 1) * 30);
                packet.WriteInt16(
                    client.ActiveCharacter.Asda2Inventory.AvatarWarehouseItems
                    .Count(i => i != null));
                packet.WriteByte(0);
                packet.WriteByte(1);
                packet.WriteInt16(-1);
                packet.WriteInt16(0);
                packet.WriteByte(activeCharacter.Record.Zodiac);
                packet.WriteByte(activeCharacter.HairStyle);
                packet.WriteByte(activeCharacter.HairColor);
                packet.WriteByte(activeCharacter.Facial);
                packet.WriteInt32(activeCharacter.Health);
                packet.WriteInt16(activeCharacter.Power);
                packet.WriteInt32(activeCharacter.MaxHealth);
                packet.WriteInt16(activeCharacter.MaxPower);
                packet.WriteInt16((short)activeCharacter.MinDamage);
                packet.WriteInt16((short)activeCharacter.MaxDamage);
                packet.WriteInt16((short)activeCharacter.RangedAttackPower);
                packet.WriteInt16((short)activeCharacter.RangedAttackPower);
                packet.WriteInt16(activeCharacter.ArcaneResist);
                packet.WriteInt16(activeCharacter.Defense);
                packet.WriteInt16(activeCharacter.Defense);
                packet.WriteInt32(activeCharacter.BlockValue);
                packet.WriteInt32(activeCharacter.BlockValue);
                packet.WriteInt16(15);
                packet.WriteInt16(7);
                packet.WriteInt16(4);
                packet.WriteSkip(unk51);
                packet.WriteSkip(activeCharacter.SettingsFlags);
                packet.WriteInt32(activeCharacter.AvatarMask);
                for (int index = 11; index < 20; ++index)
                {
                    Asda2Item asda2Item = client.ActiveCharacter.Asda2Inventory.Equipment[index];
                    Asda2InventoryHandler.WriteItemInfoToPacket(packet, asda2Item, false);
                }

                client.Send(packet, false);
            }
        }
예제 #23
0
		public static void DumpPacket(RealmAccount acc, RealmPacketIn packet, bool copy, PacketSender sender)
		{
			if (CanDump(packet.PacketId))
			{
				var writer = GetTextWriter(acc);
				DumpPacket(packet, sender, copy, writer);
			}
		}
예제 #24
0
		public static void DumpPacketOut(RealmAccount acc, RealmPacketOut packetOut, PacketSender sender)
		{
			if (CanDump(packetOut.PacketId))
			{
				var writer = GetTextWriter(acc);
				using (var packet = DisposableRealmPacketIn.CreateFromOutPacket(packetOut))
				{
					DumpPacket(packet, sender, false, writer);
				}
			}
		}
예제 #25
0
		/// <summary>
		/// Dumps the content of an Update packet to the console
		/// </summary>
		//public static void DumpUpdatePacket(RealmPacketOut packet)
		//{
		//    try
		//    {
		//        ParsedUpdatePacket.Dump(packet.GetPacketPayload(), false, m_updatePacketWriter);
		//        m_updatePacketWriter.Flush();
		//    }
		//    catch (Exception e)
		//    {
		//        OnException("Failed to parse Update-Packet.", e, packet.GetPacketPayload());
		//    }
		//}

		public static void DumpPacketOut(RealmAccount acc, byte[] packetOut, int offset, int length, PacketSender sender)
		{
			if (Dumps)
			{
				var writer = GetTextWriter(acc);
				using (var packet = DisposableRealmPacketIn.CreateFromOutPacket(packetOut, offset, length))
				{
					if (CanDump(packet.PacketId))
					{
						DumpPacket(packet, sender, false, writer);
					}
				}
			}
		}
예제 #26
0
        private static void QueryAccountCallback(IRealmClient client, Account acct)
        {
            if (client == null || !client.IsConnected)
            {
                return;
            }
            var accName  = client.AccountName;
            var realmAcc = RealmServer.Instance.GetLoggedInAccount(accName);

            if (acct != null && acct.IsLogedOn)
            {
                Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                .AddAttribute("operation", 1, "account_in_use")
                .AddAttribute("name", 0, acct.Name)
                .AddAttribute("ip", 0, client.ClientAddress.ToString())
                .Write();
                OnLoginError(client, AccountStatus.AccountInUse);
                return;
            }
            if (realmAcc != null && realmAcc.ActiveCharacter != null && realmAcc.Client != null && realmAcc.Client.IsConnected)
            {
                Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                .AddAttribute("operation", 1, "account_in_use")
                .AddAttribute("name", 0, acct.Name)
                .AddAttribute("ip", 0, client.ClientAddress.ToString())
                .Write();
                OnLoginError(client, AccountStatus.AccountInUse);
                return;
            }


            if (acct == null)
            {
                // Account doesn't exist yet -> Check for auto creation
                if (RealmServerConfiguration.AutocreateAccounts)
                {
                    if (!AccountMgr.NameValidator(ref accName) || client.Password == null || client.Password.Length > 20)
                    {
                        OnLoginError(client, AccountStatus.WrongLoginOrPass);
                        return;
                    }
                    client.AuthAccount = AccountMgr.Instance.CreateAccount(accName, client.Password, "", RealmServerConfiguration.DefaultRole);
                    client.AuthAccount.Save();

                    //client.Account = new RealmAccount(accName,new AccountInfo(){ClientId = ClientId.Original,AccountId = client.AuthAccount.AccountId,EmailAddress = "",LastIP = client.ClientAddress.GetAddressBytes(),LastLogin = DateTime.Now,Locale = ClientLocale.English,RoleGroupName = "Player"});
                    SendAuthChallengeSuccessReply(client);
                }
                else
                {
                    OnLoginError(client, AccountStatus.WrongLoginOrPass);
                    return;
                }
                client.AuthAccount.IsLogedOn = true;
            }
            else
            {
                // check if Account may be used

                if (acct.CheckActive())
                {
                    client.AuthAccount = acct;
                    if (realmAcc == null)
                    {
                        SendAuthChallengeSuccessReply(client);
                    }
                }
                else
                {
                    Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                    .AddAttribute("operation", 1, "login_banned")
                    .AddAttribute("name", 0, acct.Name)
                    .AddAttribute("ip", 0, client.ClientAddress.ToString())
                    .Write();
                    // Account has been deactivated
                    if (client.AuthAccount == null || client.AuthAccount.StatusUntil == null)
                    {
                        // temporarily suspended
                        OnLoginError(client, AccountStatus.WrongLoginOrPass);
                    }
                    else
                    {
                        // deactivated
                        OnLoginError(client, AccountStatus.WrongLoginOrPass);
                    }
                    return;
                }
            }
            if (realmAcc == null)
            {
                if (acct != null)
                {
                    Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                    .AddAttribute("operation", 1, "login_ok")
                    .AddAttribute("name", 0, acct.Name)
                    .AddAttribute("ip", 0, client.ClientAddress.ToString())
                    .Write();
                }
                RealmAccount.InitializeAccount(client, client.AuthAccount.Name);
            }
            else if (acct != null)
            {
                if (realmAcc.Client != null)
                {
                    if (realmAcc.Client.ActiveCharacter != null)
                    {
                        realmAcc.Client.ActiveCharacter.SendInfoMsg("Some one loggin in to your account. Disconnecting.");
                    }
                    realmAcc.Client.Disconnect();
                }
                if (client.ClientAddress == null)
                {
                    return;
                }
                realmAcc.LastIP = client.ClientAddress.GetAddressBytes();
                acct.LastIP     = client.ClientAddress.GetAddressBytes();
                acct.Save();
                client.Account = realmAcc;
                if (realmAcc.ActiveCharacter != null)
                {
                    ConnectClientToIngameCharacter(client, acct, realmAcc);
                }
                else
                {
                    Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                    .AddAttribute("operation", 1, "character_select_menu")
                    .AddAttribute("name", 0, acct.Name)
                    .AddAttribute("ip", 0, client.ClientAddress.ToString())
                    .Write();
                    SendAuthChallengeSuccessReply(client);
                }
            }
        }
예제 #27
0
		/// <summary>
		/// Creates a new CharacterRecord row in the database with the given information.
		/// </summary>
		/// <param name="account">the account this character is on</param>
		/// <param name="name">the name of the new character</param>
		/// <returns>the <seealso cref="CharacterRecord"/> object</returns>
		public static CharacterRecord CreateNewCharacterRecord(RealmAccount account, string name)
		{
			CharacterRecord record;

			try
			{
				record = new CharacterRecord(account.AccountId)
				{
                    EntityLowId = (uint)NextId(),
					Name = name,
					Created = DateTime.Now
				};
			}
			catch (Exception ex)
			{
				Log.Error("Character creation error (DBS: " + RealmServerConfiguration.DBType + "): ", ex);
				record = null;
			}

			return record;
		}
예제 #28
0
        /// <summary>
        /// Creates a new character and loads all required character data from the database
        /// </summary>
        /// <param name="acc">The account the character is associated with</param>
        /// <param name="record">The name of the character to load</param>
        /// <param name="client">The client to associate with this character</param>
        internal protected void Create(RealmAccount acc, CharacterRecord record, IRealmClient client)
        {
            client.ActiveCharacter = this;
            acc.ActiveCharacter    = this;

            Type        |= ObjectTypes.Player;
            ChatChannels = new List <ChatChannel>(5);

            m_logoutTimer = new TimerEntry(0, DefaultLogoutDelayMillis, totalTime => FinishLogout());

            Account  = acc;
            m_client = client;

            m_record = record;
            EntityId = EntityId.GetPlayerId(m_record.EntityLowId);
            m_name   = m_record.Name;

            Archetype  = ArchetypeMgr.GetArchetype(record.Race, record.Class);
            MainWeapon = GenericWeapon.Fists;
            PowerType  = m_archetype.Class.DefaultPowerType;

            StandState = StandState.Sit;

            Money  = (uint)m_record.Money;
            Outfit = m_record.Outfit;
            //ScaleX = m_archetype.Race.Scale;
            ScaleX     = 1;
            Gender     = m_record.Gender;
            Skin       = m_record.Skin;
            Facial     = m_record.Face;
            HairStyle  = m_record.HairStyle;
            HairColor  = m_record.HairColor;
            FacialHair = m_record.FacialHair;
            UnitFlags  = UnitFlags.PlayerControlled;
            Experience = m_record.Xp;
            RestXp     = m_record.RestXp;

            SetInt32(UnitFields.LEVEL, m_record.Level);
            // cannot use Level property, since it will trigger certain events that we don't want triggered
            NextLevelXP = XpGenerator.GetXpForlevel(m_record.Level + 1);
            MaxLevel    = RealmServerConfiguration.MaxCharacterLevel;

            RestState = RestState.Normal;

            Orientation = m_record.Orientation;

            m_bindLocation = new WorldZoneLocation(
                m_record.BindMap,
                new Vector3(m_record.BindX, m_record.BindY, m_record.BindZ),
                m_record.BindZone);

            PvPRank         = 1;
            YieldsXpOrHonor = true;

            foreach (var school in SpellConstants.AllDamageSchools)
            {
                SetFloat(PlayerFields.MOD_DAMAGE_DONE_PCT + (int)school, 1);
            }
            SetFloat(PlayerFields.DODGE_PERCENTAGE, 1.0f);

            // Auras
            m_auras = new PlayerAuraCollection(this);

            // spells
            m_spells = PlayerSpellCollection.Obtain(this);

            // factions
            WatchedFaction = m_record.WatchedFaction;
            Faction        = FactionMgr.ByRace[(uint)record.Race];
            m_reputations  = new ReputationCollection(this);

            // skills
            m_skills = new SkillCollection(this);

            // talents
            m_talents = new PlayerTalentCollection(this);

            // achievements
            m_achievements = new AchievementCollection(this);

            // Items
            m_inventory = new PlayerInventory(this);

            m_mailAccount = new MailAccount(this);

            m_questLog = new QuestLog(this);

            // tutorial flags
            TutorialFlags = new TutorialFlags(m_record.TutorialFlags);

            // Make sure client and internal state is updated with combat base values
            UnitUpdates.UpdateSpellCritChance(this);

            // Mask of activated TaxiNodes
            m_taxiNodeMask = new TaxiNodeMask();

            PowerCostMultiplier = 1f;

            m_lastPlayTimeUpdate = DateTime.Now;

            MoveControl.Mover      = this;
            MoveControl.CanControl = true;

            IncMeleePermissionCounter();

            SpeedFactor = DefaultSpeedFactor;

            // basic setup
            if (record.JustCreated)
            {
                ModStatsForLevel(m_record.Level);
                BasePower = RegenerationFormulas.GetPowerForLevel(this);
            }
            else
            {
                BaseHealth = m_record.BaseHealth;
                SetBasePowerDontUpdate(m_record.BasePower);

                SetBaseStat(StatType.Strength, m_record.BaseStrength);
                SetBaseStat(StatType.Stamina, m_record.BaseStamina);
                SetBaseStat(StatType.Spirit, m_record.BaseSpirit);
                SetBaseStat(StatType.Intellect, m_record.BaseIntellect);
                SetBaseStat(StatType.Agility, m_record.BaseAgility);

                Power = m_record.Power;
                SetInt32(UnitFields.HEALTH, m_record.Health);
            }
        }
예제 #29
0
        /// <summary>
        /// Sets the Character of this trigger, according to the -a or -c switch, followed by the account- or character-name
        /// </summary>
        /// <param name="mod"></param>
        /// <returns></returns>
        public static Character GetCharacter(this CmdTrigger <RealmServerCmdArgs> trigger, string mod)
        {
            RealmServerCmdArgs args      = trigger.Args;
            Character          character = null;
            RoleGroup          role      = args.Role;
            bool flag1 = mod.Contains("a");
            bool flag2 = mod.Contains("c");

            if (flag1 || flag2)
            {
                if (flag1 && flag2)
                {
                    trigger.Reply("Invalid command-switch, cannot use -a and -c switch at the same time.");
                }
                else
                {
                    if (role != null && !role.CanUseCommandsOnOthers)
                    {
                        trigger.Reply("You may not use the -c or -a command-switch!");
                    }
                    string name = trigger.Text.NextWord();
                    if (flag1)
                    {
                        RealmAccount loggedInAccount =
                            ServerApp <RealmServer> .Instance.GetLoggedInAccount(name);

                        if (loggedInAccount == null || (character = loggedInAccount.ActiveCharacter) == null)
                        {
                            trigger.Reply("Account {0} is not online.", (object)name);
                        }
                    }
                    else
                    {
                        character = World.GetCharacter(name, false);
                        if (character == null)
                        {
                            trigger.Reply("Character {0} is not online.", (object)name);
                        }
                    }

                    if (character != null)
                    {
                        if (role == null || !(character.Account.Role > role))
                        {
                            return(character);
                        }
                        if (flag1)
                        {
                            trigger.Reply("Account {0} is not online.", (object)name);
                        }
                        else if (character.Stealthed == 0)
                        {
                            trigger.Reply("Cannot use this Command on {0}.", (object)character.Name);
                        }
                        else
                        {
                            trigger.Reply("Character {0} is not online.", (object)name);
                        }
                    }
                }
            }
            else
            {
                trigger.Reply("Invalid Command-Switch: " + mod);
            }

            return(null);
        }
예제 #30
0
        public override void Process(CmdTrigger <RealmServerCmdArgs> trigger)
        {
            Character chr    = trigger.Args.Target as Character;
            IUser     banner = trigger.Args.User;

            if (chr != null && object.ReferenceEquals((object)chr, (object)banner))
            {
                chr = chr.Target as Character;
            }
            if (chr == null || object.ReferenceEquals((object)chr, (object)banner))
            {
                trigger.Reply("Invalid Target.");
            }
            else if (banner != null && chr.Role >= banner.Role)
            {
                trigger.Reply("Cannot ban Users of higher or equal Rank.");
            }
            else
            {
                TimeSpan?nullable1 = trigger.Text.NextTimeSpan();
                DateTime?until;
                if (nullable1.HasValue)
                {
                    DateTime now       = DateTime.Now;
                    TimeSpan?nullable2 = nullable1;
                    until = nullable2.HasValue ? new DateTime?(now + nullable2.GetValueOrDefault()) : new DateTime?();
                }
                else
                {
                    until = new DateTime?();
                }

                string timeStr = until.HasValue ? "until " + (object)until : "(indefinitely)";
                trigger.Reply("Banning Account {0} ({1}) {2}...", (object)chr.Account.Name, (object)chr.Name,
                              (object)timeStr);
                ServerApp <WCell.RealmServer.RealmServer> .IOQueue.AddMessage((IMessage) new Message((Action)(() =>
                {
                    IContextHandler contextHandler = chr.ContextHandler;
                    RealmAccount account = chr.Account;
                    if (account == null || contextHandler == null)
                    {
                        trigger.Reply("Character logged off.");
                    }
                    else if (account.SetAccountActive(false, until))
                    {
                        contextHandler.AddMessage((Action)(() =>
                        {
                            if (chr.IsInWorld)
                            {
                                chr.Kick((INamed)banner, "Banned " + timeStr, 5);
                            }
                            trigger.Reply("Done.");
                        }));
                    }
                    else
                    {
                        trigger.Reply("Could not ban Account.");
                    }
                })));
            }
        }
예제 #31
0
 public WCellUser(RealmAccount acc, IrcUser user)
 {
     IrcUser  = user;
     m_Acc    = acc;
     EntityId = EntityId.GetPlayerId(CharacterRecord.NextId());
 }
예제 #32
0
		/// <summary>
		/// Creates a new character and loads all required character data from the database
		/// </summary>
		/// <param name="acc">The account the character is associated with</param>
		/// <param name="record">The name of the character to load</param>
		/// <param name="client">The client to associate with this character</param>
		internal protected void Create(RealmAccount acc, CharacterRecord record, IRealmClient client)
		{
			client.ActiveCharacter = this;
			acc.ActiveCharacter = this;

			Type |= ObjectTypes.Player;
			ChatChannels = new List<ChatChannel>(5);

			m_logoutTimer = new TimerEntry(0, DefaultLogoutDelayMillis, totalTime => FinishLogout());

			Account = acc;
			m_client = client;

			m_record = record;
			EntityId = EntityId.GetPlayerId(m_record.EntityLowId);
			m_name = m_record.Name;

			Archetype = ArchetypeMgr.GetArchetype(record.Race, record.Class);
			MainWeapon = GenericWeapon.Fists;
			PowerType = m_archetype.Class.DefaultPowerType;

			StandState = StandState.Sit;

			Money = (uint) m_record.Money;
			Outfit = m_record.Outfit;
			//ScaleX = m_archetype.Race.Scale;
			ScaleX = 1;
			Gender = m_record.Gender;
			Skin = m_record.Skin;
			Facial = m_record.Face;
			HairStyle = m_record.HairStyle;
			HairColor = m_record.HairColor;
			FacialHair = m_record.FacialHair;
			UnitFlags = UnitFlags.PlayerControlled;
			Experience = m_record.Xp;
			RestXp = m_record.RestXp;

			SetInt32(UnitFields.LEVEL, m_record.Level);
				// cannot use Level property, since it will trigger certain events that we don't want triggered
			NextLevelXP = XpGenerator.GetXpForlevel(m_record.Level + 1);
			MaxLevel = RealmServerConfiguration.MaxCharacterLevel;

			RestState = RestState.Normal;

			Orientation = m_record.Orientation;

			m_bindLocation = new WorldZoneLocation(
				m_record.BindMap,
				new Vector3(m_record.BindX, m_record.BindY, m_record.BindZ),
				m_record.BindZone);

			PvPRank = 1;
			YieldsXpOrHonor = true;

			foreach (var school in WCellDef.AllDamageSchools)
			{
				SetFloat(PlayerFields.MOD_DAMAGE_DONE_PCT + (int) school, 1);
			}
			SetFloat(PlayerFields.DODGE_PERCENTAGE, 1.0f);

			// Auras
			m_auras = new PlayerAuraCollection(this);

			// spells
			m_spells = PlayerSpellCollection.Obtain(this);

			// factions
			WatchedFaction = m_record.WatchedFaction;
			Faction = FactionMgr.ByRace[(uint) record.Race];
			m_reputations = new ReputationCollection(this);

			// skills
			m_skills = new SkillCollection(this);

			// talents
			m_talents = new PlayerTalentCollection(this);

			// achievements
			m_achievements = new AchievementCollection(this);

			// Items
			m_inventory = new PlayerInventory(this);

			m_mailAccount = new MailAccount(this);

			m_questLog = new QuestLog(this);

			// tutorial flags
			TutorialFlags = new TutorialFlags(m_record.TutorialFlags);

			// Make sure client and internal state is updated with combat base values
			UnitUpdates.UpdateSpellCritChance(this);

			// Mask of activated TaxiNodes
			m_taxiNodeMask = new TaxiNodeMask();

			PowerCostMultiplier = 1f;

			m_lastPlayTimeUpdate = DateTime.Now;

			MoveControl.Mover = this;
			MoveControl.CanControl = true;

			CanMelee = true;

			SpeedFactor = DefaultSpeedFactor;

			// basic setup
			if (record.JustCreated)
			{
				ModStatsForLevel(m_record.Level);
				BasePower = RegenerationFormulas.GetPowerForLevel(this);
			}
			else
			{
				BaseHealth = m_record.BaseHealth;
				SetBasePowerDontUpdate(m_record.BasePower);

				SetBaseStat(StatType.Strength, m_record.BaseStrength);
				SetBaseStat(StatType.Stamina, m_record.BaseStamina);
				SetBaseStat(StatType.Spirit, m_record.BaseSpirit);
				SetBaseStat(StatType.Intellect, m_record.BaseIntellect);
				SetBaseStat(StatType.Agility, m_record.BaseAgility);

				Power = m_record.Power;
				SetInt32(UnitFields.HEALTH, m_record.Health);
			}
		}
예제 #33
0
        public static void CharacterInitOnLoginRequest(IRealmClient client, RealmPacketIn packet)
        {
            int num1 = packet.ReadInt32();

            packet.Position += 2;
            short num2 = packet.ReadInt16();

            if (num2 < 10 || num2 > 12)
            {
                client.TcpSocket.Close();
            }
            else
            {
                packet.Position += 4;
                uint    num3    = (uint)(num1 + num2 * 1000000);
                string  str     = client.ClientAddress.ToString();
                Account account = AccountMgr.GetAccount(num1);
                if (account == null || account.LastIPStr != str)
                {
                    if (account != null)
                    {
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)num1)
                        .AddAttribute("operation", 1.0, "login_game_server_bad_ip")
                        .AddAttribute("name", 0.0, account.Name)
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString())
                        .AddAttribute("old_ip", 0.0, account.LastIPStr).Write();
                    }
                    client.Disconnect(false);
                }
                else
                {
                    RealmAccount loggedInAccount =
                        ServerApp <RealmServer> .Instance.GetLoggedInAccount(account.Name);

                    if (loggedInAccount == null || loggedInAccount.ActiveCharacter == null)
                    {
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)num1)
                        .AddAttribute("operation", 1.0, "login_game_server_no_character_selected")
                        .AddAttribute("name", 0.0, account.Name)
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString())
                        .AddAttribute("old_ip", 0.0, account.LastIPStr).Write();
                        client.Disconnect(false);
                    }
                    else
                    {
                        client.IsGameServerConnection = true;
                        client.Account = loggedInAccount;
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)num1)
                        .AddAttribute("operation", 1.0, "login_game_server").AddAttribute("name", 0.0, account.Name)
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString())
                        .AddAttribute("character", client.Account.ActiveCharacter.EntryId,
                                      client.Account.ActiveCharacter.Name).AddAttribute("chrLowId", num3, "")
                        .Write();
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Character, num3)
                        .AddAttribute("operation", 1.0, "login_game_server")
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                        PreLoginCharacter(client, num3, false);
                    }
                }
            }
        }
예제 #34
0
        private static void QueryAccountCallback(IRealmClient client, Account acct)
        {
            if (client == null || !client.IsConnected)
            {
                return;
            }
            if (acct != null)
            {
                Character characterByAccId = World.GetCharacterByAccId((uint)acct.AccountId);
                if (characterByAccId != null)
                {
                    characterByAccId.Logout(true, 0);
                    AuthenticationHandler.OnLoginError(client,
                                                       AccountStatus.WrongLoginOrPass | AccountStatus.AccountInUse);
                    return;
                }
            }

            string       accountName     = client.AccountName;
            RealmAccount loggedInAccount =
                ServerApp <WCell.RealmServer.RealmServer> .Instance.GetLoggedInAccount(accountName);

            if (acct != null && acct.IsLogedOn)
            {
                Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                .AddAttribute("operation", 1.0, "account_in_use").AddAttribute("name", 0.0, acct.Name)
                .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                AuthenticationHandler.OnLoginError(client, AccountStatus.AccountInUse);
            }
            else if (loggedInAccount != null && loggedInAccount.ActiveCharacter != null &&
                     (loggedInAccount.Client != null && loggedInAccount.Client.IsConnected))
            {
                Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                .AddAttribute("operation", 1.0, "account_in_use").AddAttribute("name", 0.0, acct.Name)
                .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                AuthenticationHandler.OnLoginError(client, AccountStatus.AccountInUse);
            }
            else
            {
                if (acct == null)
                {
                    if (RealmServerConfiguration.AutocreateAccounts)
                    {
                        if (!AccountMgr.NameValidator(ref accountName) || client.Password == null ||
                            client.Password.Length > 20)
                        {
                            AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                            return;
                        }

                        client.AuthAccount = AccountMgr.Instance.CreateAccount(accountName, client.Password, "",
                                                                               RealmServerConfiguration.DefaultRole);
                        client.AuthAccount.Save();
                        AuthenticationHandler.SendAuthChallengeSuccessReply(client);
                        client.AuthAccount.IsLogedOn = true;
                    }
                    else
                    {
                        AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                        return;
                    }
                }
                else if (acct.CheckActive())
                {
                    client.AuthAccount = acct;
                    if (loggedInAccount == null)
                    {
                        AuthenticationHandler.SendAuthChallengeSuccessReply(client);
                    }
                }
                else
                {
                    Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                    .AddAttribute("operation", 1.0, "login_banned").AddAttribute("name", 0.0, acct.Name)
                    .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                    if (client.AuthAccount == null || !client.AuthAccount.StatusUntil.HasValue)
                    {
                        AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                        return;
                    }

                    AuthenticationHandler.OnLoginError(client, AccountStatus.WrongLoginOrPass);
                    return;
                }

                if (loggedInAccount == null)
                {
                    if (acct != null)
                    {
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                        .AddAttribute("operation", 1.0, "login_ok").AddAttribute("name", 0.0, acct.Name)
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                    }
                    RealmAccount.InitializeAccount(client, client.AuthAccount.Name);
                }
                else
                {
                    if (acct == null)
                    {
                        return;
                    }
                    if (loggedInAccount.Client != null)
                    {
                        if (loggedInAccount.Client.ActiveCharacter != null)
                        {
                            loggedInAccount.Client.ActiveCharacter.SendInfoMsg(
                                "Some one loggin in to your account. Disconnecting.");
                        }
                        loggedInAccount.Client.Disconnect(false);
                    }

                    if (client.ClientAddress == null)
                    {
                        return;
                    }
                    loggedInAccount.LastIP = client.ClientAddress.GetAddressBytes();
                    acct.LastIP            = client.ClientAddress.GetAddressBytes();
                    acct.Save();
                    client.Account = loggedInAccount;
                    if (loggedInAccount.ActiveCharacter != null)
                    {
                        AuthenticationHandler.ConnectClientToIngameCharacter(client, acct, loggedInAccount);
                    }
                    else
                    {
                        Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
                        .AddAttribute("operation", 1.0, "character_select_menu")
                        .AddAttribute("name", 0.0, acct.Name)
                        .AddAttribute("ip", 0.0, client.ClientAddress.ToString()).Write();
                        AuthenticationHandler.SendAuthChallengeSuccessReply(client);
                    }
                }
            }
        }
예제 #35
0
		/// <summary>
		/// Writes a line into the debug log of the given Account.
		/// </summary>
		public static void Log(RealmAccount acc, string msg, params object[] args)
		{
			GetTextWriter(acc).WriteLine(string.Format(msg, args));
		}
예제 #36
0
		/// <summary>
		/// Gets the characters for the given account.
		/// </summary>
		/// <param name="account">the account</param>
		/// <returns>a collection of character objects of the characters on the given account</returns>
		public static IEnumerable<CharacterRecord> FindAllOfAccount(RealmAccount account)
		{
			IEnumerable<CharacterRecord> chrs;
			try
			{
				chrs = RealmWorldDBMgr.DatabaseProvider.FindAll<CharacterRecord>(x => x.AccountId == account.AccountId);
				//var chrs = FindAllByProperty("Created", "AccountId", account.AccountId);
				//chrs.Reverse();
				//return chrs;
			}
			catch (Exception ex)
			{
				RealmWorldDBMgr.OnDBError(ex);
				chrs = RealmWorldDBMgr.DatabaseProvider.FindAll<CharacterRecord>(x => x.AccountId == account.AccountId);
			}
			//chrs.Reverse();
			return chrs;
		}
예제 #37
0
		public static IndentTextWriter GetTextWriter(RealmAccount account)
		{
			IndentTextWriter writer;
			if (account == null)
			{
				writer = DefaultWriter;
			}
			else if (!m_packetWriters.TryGetValue(account.Name, out writer))
			{
				lock (m_packetWriters)
				{
					// check if the writer was added after the lock was released
					if (!m_packetWriters.TryGetValue(account.Name, out writer))
					{
						try
						{
							var file = Path.Combine(DumpDir.FullName, account.Name + ".txt");
							writer = new IndentTextWriter(new StreamWriter(file))
							         	{
							         		AutoFlush = true
							         	};
							m_packetWriters.Add(account.Name, writer);
						}
						catch (Exception e)
						{
							LogUtil.WarnException("Writing to Default writer - TextWriter for Account {0} could not be created: {1}", account, e);
							return DefaultWriter;
						}
					}
				}
			}
			return writer;
		}
예제 #38
0
 private static void ConnectClientToIngameCharacter(IRealmClient client, Account acct, RealmAccount realmAcc)
 {
     Log.Create(Log.Types.AccountOperations, LogSourceType.Account, (uint)acct.AccountId)
     .AddAttribute("operation", 1, "connecting_to_already_connected_character")
     .AddAttribute("name", 0, acct.Name)
     .AddAttribute("ip", 0, client.ClientAddress.ToString())
     .Write();
     realmAcc.ActiveCharacter.AddMessage(() =>
     {
         //realmAcc.ActiveCharacter.Logout(false);
         Asda2LoginHandler.PreLoginCharacter(client, realmAcc.ActiveCharacter.UniqId, true);
     });
 }
예제 #39
0
		/// <summary>
		/// Creates a new character and loads all required character data from the database
		/// </summary>
		/// <param name="acc">The account the character is associated with</param>
		/// <param name="record">The name of the character to load</param>
		/// <param name="client">The client to associate with this character</param>
		internal protected void Create(RealmAccount acc, CharacterRecord record, IRealmClient client)
		{			client.ActiveCharacter = this;
			acc.ActiveCharacter = this;

			Type |= ObjectTypes.Player;
			ChatChannels = new List<ChatChannel>();

			m_logoutTimer = new TimerEntry(0.0f, DefaultLogoutDelay, totalTime => FinishLogout());

			Account = acc;
			m_client = client;

			m_record = record;
			EntityId = EntityId.GetPlayerId(m_record.EntityLowId);
			m_name = m_record.Name;

			Archetype = ArchetypeMgr.GetArchetype(record.Race, record.Class);
			MainWeapon = GenericWeapon.Fists;
			PowerType = m_archetype.Class.PowerType;

			StandState = StandState.Sit;

			Money = (uint)m_record.Money;
			Outfit = m_record.Outfit;
			//ScaleX = m_archetype.Race.Scale;
			ScaleX = 1;
			Gender = m_record.Gender;
			Skin = m_record.Skin;
			Facial = m_record.Face;
			HairStyle = m_record.HairStyle;
			HairColor = m_record.HairColor;
			FacialHair = m_record.FacialHair;
			UnitFlags = UnitFlags.PlayerControlled;
			XP = m_record.Xp;
			RestXp = m_record.RestXp;
			Level = m_record.Level;
			NextLevelXP = XpGenerator.GetXpForlevel(m_record.Level + 1);
			MaxLevel = RealmServerConfiguration.MaxCharacterLevel;

			RestState = RestState.Normal;

			Orientation = m_record.Orientation;

			m_bindLocation = new ZoneWorldLocation(
				m_record.BindRegion,
				new Vector3(m_record.BindX, m_record.BindY, m_record.BindZ),
				m_record.BindZone);

			PvPRank = 1;
			YieldsXpOrHonor = true;

			foreach (var school in WCellDef.AllDamageSchools)
			{
				SetInt32(PlayerFields.MOD_DAMAGE_DONE_PCT + (int)school, 1);
			}
			SetFloat(PlayerFields.DODGE_PERCENTAGE, 1.0f);

			// Auras
			m_auras = new PlayerAuraCollection(this);

			// spells
			PlayerSpellCollection spells;
			if (!record.JustCreated && SpellHandler.PlayerSpellCollections.TryGetValue(EntityId.Low, out spells))
			{
				SpellHandler.PlayerSpellCollections.Remove(EntityId.Low);
				m_spells = spells;
				((PlayerSpellCollection)m_spells).OnReconnectOwner(this);
			}
			else
			{
				m_spells = new PlayerSpellCollection(this);
			}

			// factions
			WatchedFaction = m_record.WatchedFaction;
			Faction = FactionMgr.ByRace[(uint)record.Race];
			m_reputations = new ReputationCollection(this);

			// skills
			m_skills = new SkillCollection(this);

			// talents
			m_talents = new TalentCollection(this);

			// Items
			m_inventory = new PlayerInventory(this);

			m_mailAccount = new MailAccount(this);

			m_questLog = new QuestLog(this);

			// Talents
			m_record.SpecProfile = SpecProfile.NewSpecProfile(this);
			FreeTalentPoints = m_record.FreeTalentPoints;

			// tutorial flags
			TutorialFlags = new TutorialFlags(m_record.TutorialFlags);

			// Make sure client and internal state is updated with combat base values
			UnitUpdates.UpdateSpellCritChance(this);

			// Mask of activated TaxiNodes
			m_taxiNodeMask = new TaxiNodeMask();

			PowerCostMultiplier = 1f;

			m_lastPlayTimeUpdate = DateTime.Now;

			MoveControl.Mover = this;
			MoveControl.CanControl = true;

			BaseHealth = m_record.BaseHealth;
			SetBasePowerDontUpdate(m_record.BasePower);

			SetBaseStat(StatType.Strength, m_record.BaseStrength);
			SetBaseStat(StatType.Stamina, m_record.BaseStamina);
			SetBaseStat(StatType.Spirit, m_record.BaseSpirit);
			SetBaseStat(StatType.Intellect, m_record.BaseIntellect);
			SetBaseStat(StatType.Agility, m_record.BaseAgility);

			CanMelee = true;

			// basic setup
			if (record.JustCreated)
			{
				Power = PowerType == PowerType.Rage ? 0 : MaxPower;
				SetInt32(UnitFields.HEALTH, MaxHealth);
			}
			else
			{
				Power = m_record.Power;
				SetInt32(UnitFields.HEALTH, m_record.Health);
			}

		}