protected override async Task Process(WorldSession session, CharNew packet) { if (session.Account is null) { return; } var slotTaken = await characterRepository.IsSlotTaken(session.Account.Id, packet.Slot); if (slotTaken) { await session.Disconnect(); return; } var nameTaken = await characterRepository.IsNameTaken(packet.Name); if (nameTaken) { await session.Disconnect(); return; } await characterRepository.Save(new CharacterDTO { Name = packet.Name, Slot = packet.Slot, AccountId = session.Account.Id, Level = 1, JobLevel = 1, HeroLevel = 0, Job = Job.Adventurer, Gender = packet.Gender, HairColor = packet.HairColor, HairStyle = packet.HairStyle, Dignity = 0, Reputation = 0, Experience = 0, JobExperience = 0, HeroExperience = 0, MapId = 1, X = 75, Y = 115, Direction = Direction.South, Hp = 300, Mp = 150, }); await session.SendPacket(new Success()); var characters = await characterRepository.FindAll(session.Account.Id); await session.SendCList(characters); }
protected override async Task Process(WorldSession session, Select packet) { if (session.Account is null) { await session.Disconnect(); return; } var character = await characterRepository.GetCharacterInSlot(session.Account.Id, packet.Slot); if (character is null) { await session.Disconnect(); return; } session.Character = new Character(session) { Id = character.Id, Name = character.Name, Job = character.Job, HairColor = character.HairColor, HairStyle = character.HairStyle, Gender = character.Gender, Level = character.Level, JobLevel = character.JobLevel, HeroLevel = character.HeroLevel, Experience = character.Experience, JobExperience = character.JobExperience, HeroExperience = character.HeroExperience, Direction = character.Direction, Position = new Position { X = character.X, Y = character.Y }, Hp = character.Hp, Mp = character.Mp, MaxHp = 300, MaxMp = 150, Reputation = character.Reputation, Dignity = character.Dignity, Speed = 10, ReputationIcon = await reputationService.GetIcon(character.Reputation), Map = await mapManager.GetMap(character.MapId) }; await session.SendPacket(new Ok()); }
protected override async Task Process(WorldSession session, Walk packet) { var character = session.Character; if (character.Speed != packet.Speed) { logger.Debug("Incorrect character speed"); return; } var distance = character.Position.GetDistance(new Position { X = packet.X, Y = packet.Y }); if (distance > character.Speed / 2) { logger.Debug("Incorrect distance"); return; } if ((packet.X + packet.Y) % 3 % 2 != packet.Checksum) { logger.Debug("Incorrect walk checksum"); await session.Disconnect(); return; } var travelTime = 2500 / packet.Speed * distance; if (travelTime > 1000 * 1.5) { logger.Debug("Incorrect travel time"); await session.Disconnect(); return; } character.Position = new Position { X = packet.X, Y = packet.Y }; await character.Map.BroadcastMv(character); }
protected override async Task Process(WorldSession session, CharNew packet) { if (session.Account is null) { return; } var slotTaken = await characterRepository.IsSlotTaken(session.Account.Id, packet.Slot); if (slotTaken) { await session.Disconnect(); return; } var nameTaken = await characterRepository.IsNameTaken(packet.Name); if (nameTaken) { await session.Disconnect(); return; } await characterRepository.Save(new CharacterDTO { Name = packet.Name, Slot = packet.Slot, AccountId = session.Account.Id, Level = 1, JobLevel = 1, Job = Job.Adventurer, Gender = packet.Gender, HairColor = packet.HairColor, HairStyle = packet.HairStyle, MapId = 1, X = 75, Y = 115, Hp = 300, Mp = 150, }); await session.SendPacket(new Success()); var characters = await characterRepository.FindAll(session.Account.Id); await session.SendPacket(new CListStart()); foreach (var character in characters) { await session.SendPacket(new CList { Name = character.Name, Slot = character.Slot, HairColor = character.HairColor, HairStyle = character.HairStyle, Level = character.Level, Gender = character.Gender, HeroLevel = 0, JobLevel = character.JobLevel, Job = character.Job, Equipments = Enumerable.Range(0, 10).Select(x => (short?)null), Pets = Enumerable.Range(0, 24).Select(x => (short?)null), QuestCompletion = 1, QuestPart = 1, Rename = false }); } await session.SendPacket(new CListEnd()); }
public static void HandleAuthSession(ref PacketReader packet, ref WorldSession session) { byte[] digest = new byte[20]; packet.Skip(6); digest[5] = packet.ReadByte(); byte minorVersion = packet.ReadByte(); digest[2] = packet.ReadByte(); ushort clientBuild = packet.ReadUInt16(); digest[18] = packet.ReadByte(); digest[10] = packet.ReadByte(); uint clientSeed = packet.ReadUInt32();//???? digest[9] = packet.ReadByte(); digest[8] = packet.ReadByte(); digest[11] = packet.ReadByte(); digest[13] = packet.ReadByte(); digest[4] = packet.ReadByte(); digest[7] = packet.ReadByte(); digest[16] = packet.ReadByte(); digest[1] = packet.ReadByte(); digest[0] = packet.ReadByte(); digest[14] = packet.ReadByte(); digest[12] = packet.ReadByte(); byte majorVersion = packet.ReadByte(); digest[17] = packet.ReadByte(); digest[19] = packet.ReadByte(); packet.Skip(12); digest[3] = packet.ReadByte(); packet.Skip(8); digest[6] = packet.ReadByte(); digest[15] = packet.ReadByte(); // int addonSize = packet.ReadInt32(); byte[] addondata = packet.ReadBytes(addonSize); packet.GetBit(); uint namelength = packet.GetBits <uint>(12); string accountName = packet.ReadString(namelength); //"SELECT id, sha_pass_hash, sessionkey, last_ip, locked, expansion, mutetime, locale, recruiter, FROM account WHERE username = ?" PreparedStatement stmt = DB.Auth.GetPreparedStatement(LoginStatements.Sel_AccountInfoByName); stmt.AddValue(0, accountName); SQLResult result = DB.Auth.Select(stmt); if (result.Count == 0) { PacketWriter data = new PacketWriter(Opcodes.SMSG_AuthResponse); data.WriteBit(0); // has queue info data.WriteBit(0); // has account info data.WriteUInt8(AuthCodes.UnknownAccount); session.Send(data); Log.outError("HandleAuthSession: Sent Auth Response (unknown account)."); session.Disconnect(); return; } var account = new Account() { Id = result.Read <uint>(0, 0), Name = accountName, Password = result.Read <string>(0, 1), SessionKey = result.Read <string>(0, 2), LastIP = result.Read <string>(0, 3), Expansion = result.Read <byte>(0, "expansion"), Locale = result.Read <String>(0, 7), }; //uint world_expansion = sWorld->getIntConfig(CONFIG_EXPANSION); //if (account.expansion > world_expansion) //account.expansion = world_expansion; ///- Re-check ip locking (same check as in realmd). if (result.Read <byte>(0, 4) == 1) // if ip is locked { //if (strcmp (fields[2].GetCString(), GetRemoteAddress().c_str())) { PacketWriter data = new PacketWriter(Opcodes.SMSG_AuthResponse); data.WriteBit(0); // has queue info data.WriteBit(0); // has account info data.WriteUInt8(AuthCodes.Failed); session.Send(data); Log.outDebug("HandleAuthSession: Sent Auth Response (Account IP differs)."); return; } } byte[] kBytes = account.SessionKey.ToByteArray(); uint recruiter = result.Read <uint>(0, 8); //string os = result.Read<string>(0, 9); // Checks gmlevel per Realm stmt = DB.Auth.GetPreparedStatement(LoginStatements.Get_GMLevelByRealmID); stmt.AddValue(0, account.Id); stmt.AddValue(1, WorldConfig.RealmId); result = DB.Auth.Select(stmt); if (result.Count == 0) { account.GMLevel = 0; } else { account.GMLevel = (AccountTypes)result.Read <byte>(0, 0); } //Ban Shit here // Check if this user is by any chance a recruiter stmt = DB.Auth.GetPreparedStatement(LoginStatements.Sel_AccountRecruiter); stmt.AddValue(0, account.Id); result = DB.Auth.Select(stmt); bool isRecruiter = false; if (result.Count > 0) { isRecruiter = true; } // Update the last_ip in the database stmt = DB.Auth.GetPreparedStatement(LoginStatements.Upd_LastIP); stmt.AddValue(0, account.LastIP); stmt.AddValue(1, account.Name); DB.Auth.Execute(stmt); session.SetAccount(account); session.Crypt.Initialize(kBytes); //session.LoadGlobalAccountData(); session.LoadTutorialsData(); session.ReadAddonsInfo(addondata, addonSize - 4); session.SendAuthResponse(); session.SendAddonsInfo(); uint version = 0;//todo fixme PacketWriter data1 = new PacketWriter(Opcodes.SMSG_ClientcacheVersion); data1.WriteUInt32(version); //session.Send(data1); session.SendTutorialsData(); }