/// <summary> /// </summary> /// <param name="Self"> /// </param> /// <param name="Caller"> /// </param> /// <param name="Target"> /// </param> /// <param name="Arguments"> /// </param> /// <returns> /// </returns> public bool FunctionExecute( INamedEntity Self, INamedEntity Caller, IInstancedEntity Target, MessagePackObject[] Arguments) { if (Arguments.Length == 2) { ((Character)Self).Stats[StatIds.headmesh].Value = Arguments[1].AsInt32(); ((Character)Self).MeshLayer.AddMesh(0, Arguments[1].AsInt32(), Arguments[0].AsInt32(), 4); } else { int placement = (Int32)Arguments[Arguments.Length - 1]; if (placement >= 49) { // Social page ((Character)Self).SocialMeshLayer.AddMesh(0, Arguments[1].AsInt32(), Arguments[0].AsInt32(), 4); } else { ((Character)Self).Stats[StatIds.headmesh].Value = Arguments[0].AsInt32(); ((Character)Self).MeshLayer.AddMesh(0, Arguments[1].AsInt32(), Arguments[0].AsInt32(), 4); } } AppearanceUpdate.AnnounceAppearanceUpdate((Character)Self); return(true); }
/// <summary> /// </summary> /// <param name="Self"> /// </param> /// <param name="Caller"> /// </param> /// <param name="Target"> /// </param> /// <param name="Arguments"> /// </param> /// <returns> /// </returns> public bool FunctionExecute( INamedEntity Self, INamedEntity Caller, IInstancedEntity Target, MessagePackObject[] Arguments) { if (Self is Character) { Character t = (Character)Self; bool found = false; int placement; if (Arguments.Length == 2) { placement = 0; } else { placement = (Int32)Arguments[Arguments.Length - 1]; } if (placement >= 49) { if (t.SocialTab.ContainsKey((Int32)Arguments[1])) { t.SocialTab[(Int32)Arguments[1]] = (Int32)Arguments[0]; } else { t.SocialTab.Add((Int32)Arguments[1], (Int32)Arguments[0]); } } else { foreach (AOTextures aot in t.Textures) { if (aot.place == (Int32)Arguments[1]) { found = true; aot.Texture = (Int32)Arguments[0]; } } if (!found) { t.Textures.Add(new AOTextures((Int32)Arguments[1], (Int32)Arguments[0])); } } AppearanceUpdate.AnnounceAppearanceUpdate(t); } return(true); }
/// <summary> /// </summary> /// <param name="message"> /// </param> /// <param name="cli"> /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// </exception> /// <exception cref="NotImplementedException"> /// </exception> public static void AddItemToContainer(ContainerAddItemMessage message, ZoneClient cli) { bool noAppearanceUpdate = false; /* Container ID's: * 0065 Weaponpage * 0066 Armorpage * 0067 Implantpage * 0068 Inventory (places 64-93) * 0069 Bank * 006B Backpack * 006C KnuBot Trade Window * 006E Overflow window * 006F Trade Window * 0073 Socialpage * 0767 Shop Inventory * 0790 Playershop Inventory * DEAD Trade Window (incoming) It's bank now (when you put something into the bank) */ var fromContainerID = (int)message.SourceContainer.Type; int fromPlacement = message.SourceContainer.Instance; Identity toIdentity = message.Target; int toPlacement = message.TargetPlacement; // Where and what does need to be moved/added? IInventoryPage sendingPage = cli.Character.BaseInventory.Pages[fromContainerID]; IItem itemFrom = sendingPage[fromPlacement]; // Receiver of the item (IInstancedEntity, can be mostly all from NPC, Character or Bag, later even playfields) // Turn 0xDEAD into C350 if instance is the same if (toIdentity.Type == IdentityType.IncomingTradeWindow) { toIdentity.Type = IdentityType.CanbeAffected; } IItemContainer itemReceiver = cli.Playfield.FindByIdentity(toIdentity) as IItemContainer; if (itemReceiver == null) { throw new ArgumentOutOfRangeException( "No Entity found: " + message.Target.Type.ToString() + ":" + message.Target.Instance); } // On which inventorypage should the item be added? IInventoryPage receivingPage; if ((toPlacement == 0x6f) && (message.Target.Type == IdentityType.IncomingTradeWindow)) { receivingPage = itemReceiver.BaseInventory.Pages[(int)IdentityType.Bank]; } else { receivingPage = itemReceiver.BaseInventory.PageFromSlot(toPlacement); } // Get standard page if toplacement cant be found (0x6F for next free slot) // TODO: If Entities are not the same (other player, bag etc) then always add to the standard page if ((receivingPage == null) || (itemReceiver.GetType() != cli.Character.GetType())) { receivingPage = itemReceiver.BaseInventory.Pages[itemReceiver.BaseInventory.StandardPage]; } if (receivingPage == null) { throw new ArgumentOutOfRangeException("No inventorypage found."); } if (toPlacement == 0x6f) { toPlacement = receivingPage.FindFreeSlot(); } // Is there already a item? IItem itemTo; try { itemTo = receivingPage[toPlacement]; } catch (Exception) { itemTo = null; } // Calculating delay for equip/unequip/switch gear int delay = 20; cli.Character.DoNotDoTimers = true; IItemSlotHandler equipTo = receivingPage as IItemSlotHandler; IItemSlotHandler unequipFrom = sendingPage as IItemSlotHandler; noAppearanceUpdate = !((equipTo is WeaponInventoryPage) || (equipTo is ArmorInventoryPage) || (equipTo is SocialArmorInventoryPage)); noAppearanceUpdate &= !((unequipFrom is WeaponInventoryPage) || (unequipFrom is ArmorInventoryPage) || (unequipFrom is SocialArmorInventoryPage)); if (equipTo != null) { if (itemTo != null) { if (receivingPage.NeedsItemCheck) { Actions action = GetAction(sendingPage, itemFrom); if (action.CheckRequirements(cli.Character)) { UnEquip.Send(cli, receivingPage, toPlacement); if (!noAppearanceUpdate) { // Equipmentpages need delays // Delay when equipping/unequipping // has to be redone, jumping breaks the equiping/unequiping // and other messages have to be done too // like heartbeat timer, damage from environment and such delay = (itemFrom.GetAttribute(211) == 1234567890 ? 20 : itemFrom.GetAttribute(211)) + (itemTo.GetAttribute(211) == 1234567890 ? 20 : itemTo.GetAttribute(211)); } Thread.Sleep(delay * 10); // social has to wait for 0.2 secs too (for helmet update) cli.Character.Send(message); equipTo.HotSwap(sendingPage, fromPlacement, toPlacement); Equip.Send(cli, receivingPage, toPlacement); } } } else { if (receivingPage.NeedsItemCheck) { if (itemFrom == null) { throw new NullReferenceException("itemFrom can not be null, possible inventory error"); } Actions action = GetAction(receivingPage, itemFrom); if (action.CheckRequirements(cli.Character)) { if (!noAppearanceUpdate) { // Equipmentpages need delays // Delay when equipping/unequipping // has to be redone, jumping breaks the equiping/unequiping // and other messages have to be done too // like heartbeat timer, damage from environment and such delay = itemFrom.GetAttribute(211); if ((equipTo is SocialArmorInventoryPage) || (delay == 1234567890)) { delay = 20; } Thread.Sleep(delay * 10); } if (sendingPage == receivingPage) { // Switch rings for example UnEquip.Send(cli, sendingPage, fromPlacement); } cli.Character.Send(message); equipTo.Equip(sendingPage, fromPlacement, toPlacement); Equip.Send(cli, receivingPage, toPlacement); } } } } else { if (unequipFrom != null) { // Send to client first if (!noAppearanceUpdate) { // Equipmentpages need delays // Delay when equipping/unequipping // has to be redone, jumping breaks the equiping/unequiping // and other messages have to be done too // like heartbeat timer, damage from environment and such delay = itemFrom.GetAttribute(211); if ((unequipFrom is SocialArmorInventoryPage) || (delay == 1234567890)) { delay = 20; } Thread.Sleep(delay * 10); } UnEquip.Send(cli, sendingPage, fromPlacement); unequipFrom.Unequip(fromPlacement, receivingPage, toPlacement); cli.Character.Send(message); } else { // No equipment page involved, just send ContainerAddItemMessage back message.TargetPlacement = receivingPage.FindFreeSlot(); IItem item = sendingPage.Remove(fromPlacement); receivingPage.Add(message.TargetPlacement, item); cli.Character.Send(message); } } cli.Character.DoNotDoTimers = false; cli.Character.Stats.ClearChangedFlags(); // Apply item functions before sending the appearanceupdate message cli.Character.CalculateSkills(); if (!noAppearanceUpdate) { AppearanceUpdate.AnnounceAppearanceUpdate(cli.Character); } }
/// <summary> /// </summary> /// <param name="charID"> /// </param> /// <param name="client"> /// </param> public void Read(int charID, ZoneClient client) { // Don't edit anything in this region // unless you are 300% sure you know what you're doing // Character is created and read when Client connects in Client.cs->CreateCharacter // client.CreateCharacter(charID); client.Server.Info( client, "Client connected. ID: {0} IP: {1} Character name: {2}", client.Character.Identity.Instance, client.ClientAddress, client.Character.Name); // now we have to start sending packets like // character stats, inventory, playfield info // and so on. I will put some packets here just // to get us in game. We have to start moving // these packets somewhere else and make packet // builders instead of sending (half) hardcoded // packets. /* send chat server info to client */ ChatServerInfo.Send(client); /* send playfield info to client */ PlayfieldAnarchyF.Send(client); var sendSCFUs = new IMSendPlayerSCFUs { toClient = client }; ((Playfield)client.Playfield).SendSCFUsToClient(sendSCFUs); /* set SocialStatus to 0 */ client.Character.Stats[521].BaseValue = 0; // Stat.SendDirect(client, 521, 0, false); var identity = new Identity { Type = IdentityType.CanbeAffected, Instance = charID }; /* Action 167 Animation and Stance Data maybe? */ var message = new CharacterActionMessage { Identity = identity, Action = CharacterActionType.ChangeAnimationAndStance, Target = Identity.None, Parameter1 = 0x00000000, Parameter2 = 0x00000001 }; client.SendCompressed(message); var gameTimeMessage = new GameTimeMessage { Identity = identity, Unknown1 = 30024.0f, Unknown3 = 185408, Unknown4 = 80183.3125f }; client.SendCompressed(gameTimeMessage); /* set SocialStatus to 0 */ // Stat.SendDirect(client, 521, 0, false); /* again */ // Stat.SendDirect(client, 521, 0, false); /* visual */ SimpleCharFullUpdate.SendToPlayfield(client); /* inventory, items and all that */ FullCharacter.Send(client); var specials = new[] { new SpecialAttackInfo { Unknown1 = 0x0000AAC0, Unknown2 = 0x00023569, Unknown3 = 0x00000064, Unknown4 = "MAAT" }, new SpecialAttackInfo { Unknown1 = 0x0000A431, Unknown2 = 0x0000A430, Unknown3 = 0x00000090, Unknown4 = "DIIT" }, new SpecialAttackInfo { Unknown1 = 0x00011294, Unknown2 = 0x00011295, Unknown3 = 0x0000008E, Unknown4 = "BRAW" } }; var specialAttackWeaponMessage = new SpecialAttackWeaponMessage { Identity = identity, Specials = specials }; client.SendCompressed(specialAttackWeaponMessage); // done // Timers are allowed to update client stats now. client.Character.DoNotDoTimers = false; // spawn all active monsters to client // TODO: Implement NonPlayerCharacterHandler // NonPlayerCharacterHandler.SpawnMonstersInPlayfieldToClient(client, client.Character.PlayField); // TODO: Implement VendorHandler // if (VendorHandler.GetNumberofVendorsinPlayfield(client.Character.PlayField) > 0) // { // Shops // VendorHandler.GetVendorsInPF(client); // } // WeaponItemFullCharUpdate Maybe the right location , First Check if weapons present usually in equipment // Packets.WeaponItemFullUpdate.Send(client, client.Character); // TODO: create a better alternative to ProcessTimers // client.Character.ProcessTimers(DateTime.Now + TimeSpan.FromMilliseconds(200)); client.Character.CalculateSkills(); AppearanceUpdate.AnnounceAppearanceUpdate((Character)client.Character); // done, so we call a hook. // Call all OnConnect script Methods Program.csc.CallMethod("OnConnect", (Character)client.Character); }
public static void Read(CharacterActionMessage packet, Client client) { var mys = new SqlWrapper(); var actionNum = (int)packet.Action; var unknown1 = packet.Unknown1; var args1 = packet.Parameter1; var args2 = packet.Parameter2; var unknown2 = packet.Unknown2; switch (actionNum) { case 19: { // Cast nano // CastNanoSpell var msg = new CastNanoSpellMessage { Identity = client.Character.Identity, Unknown = 0x00, NanoId = args2, Target = packet.Target, Unknown1 = 0x00000000, Caster = client.Character.Identity }; client.Character.Playfield.Announce(msg); // CharacterAction 107 var characterAction107 = new CharacterActionMessage { Identity = client.Character.Identity, Unknown = 0x00, Action = CharacterActionType.Unknown1, Unknown1 = 0x00000000, Target = Identity.None, Parameter1 = 1, Parameter2 = args2, Unknown2 = 0x0000 }; client.Character.Playfield.Announce(characterAction107); // CharacterAction 98 var characterAction98 = new CharacterActionMessage { Identity = packet.Target, Unknown = 0x00, Action = CharacterActionType.Unknown2, Unknown1 = 0x00000000, Target = new Identity { Type = IdentityType .NanoProgram, Instance = args2 }, Parameter1 = client.Character.Identity.Instance, Parameter2 = 0x249F0, // duration? Unknown2 = 0x0000 }; client.Character.Playfield.Announce(characterAction98); } break; /* this is here to prevent server crash that is caused by * search action if server doesn't reply if something is * found or not */ case 66: { // If action == search /* Msg 110:136744723 = "No hidden objects found." */ // TODO: SEARCH!! SendFeedback.Send(client, 110, 136744723); } break; case 105: { // If action == Info Request IInstancedEntity tPlayer = client.Playfield.FindByIdentity(packet.Target); var tChar = tPlayer as Character; if (tChar != null) { var LegacyScore = tChar.Stats["PvP_Rating"].BaseValue; string LegacyTitle = null; if (LegacyScore < 1400) { LegacyTitle = string.Empty; } else if (LegacyScore < 1500) { LegacyTitle = "Freshman"; } else if (LegacyScore < 1600) { LegacyTitle = "Rookie"; } else if (LegacyScore < 1700) { LegacyTitle = "Apprentice"; } else if (LegacyScore < 1800) { LegacyTitle = "Novice"; } else if (LegacyScore < 1900) { LegacyTitle = "Neophyte"; } else if (LegacyScore < 2000) { LegacyTitle = "Experienced"; } else if (LegacyScore < 2100) { LegacyTitle = "Expert"; } else if (LegacyScore < 2300) { LegacyTitle = "Master"; } else if (LegacyScore < 2500) { LegacyTitle = "Champion"; } else { LegacyTitle = "Grand Master"; } var orgGoverningForm = 0; var ms = new SqlWrapper(); var dt = ms.ReadDatatable( "SELECT `GovernmentForm` FROM organizations WHERE ID=" + tChar.Stats["Clan"].BaseValue); if (dt.Rows.Count > 0) { orgGoverningForm = (Int32)dt.Rows[0][0]; } // Uses methods in ZoneEngine\PacketHandlers\OrgClient.cs /* Known packetFlags-- * 0x40 - No org | 0x41 - Org | 0x43 - Org and towers | 0x47 - Org, towers, player has personal towers | 0x50 - No pvp data shown * Bitflags-- * Bit0 = hasOrg, Bit1 = orgTowers, Bit2 = personalTowers, Bit3 = (Int32) time until supression changes (Byte) type of supression level?, Bit4 = noPvpDataShown, Bit5 = hasFaction, Bit6 = ?, Bit 7 = null. */ int? orgId; string orgRank; InfoPacketType type; if (tPlayer.Stats["Clan"].BaseValue == 0) { type = InfoPacketType.Character; orgId = null; orgRank = null; } else { type = InfoPacketType.CharacterOrg; orgId = (int?)tPlayer.Stats["Clan"].BaseValue; if (client.Character.Stats["Clan"].BaseValue == tPlayer.Stats["Clan"].BaseValue) { orgRank = OrgClient.GetRank( orgGoverningForm, tPlayer.Stats["ClanLevel"].BaseValue); } else { orgRank = string.Empty; } } var info = new CharacterInfoPacket { Unknown1 = 0x01, Profession = (Profession) tPlayer.Stats["Profession"].Value, Level = (byte)tPlayer.Stats["Level"].Value, TitleLevel = (byte)tPlayer.Stats["TitleLevel"].Value, VisualProfession = (Profession) tPlayer.Stats["VisualProfession"].Value, SideXp = 0, Health = tPlayer.Stats["Health"].Value, MaxHealth = tPlayer.Stats["Life"].Value, BreedHostility = 0x00000000, OrganizationId = orgId, FirstName = tChar.FirstName, LastName = tChar.LastName, LegacyTitle = LegacyTitle, Unknown2 = 0x0000, OrganizationRank = orgRank, TowerFields = null, CityPlayfieldId = 0x00000000, Towers = null, InvadersKilled = tPlayer.Stats["InvadersKilled"].Value, KilledByInvaders = tPlayer.Stats["KilledByInvaders"].Value, AiLevel = tPlayer.Stats["AlienLevel"].Value, PvpDuelWins = tPlayer.Stats["PvpDuelKills"].Value, PvpDuelLoses = tPlayer.Stats["PvpDuelDeaths"].Value, PvpProfessionDuelLoses = tPlayer.Stats["PvpProfessionDuelDeaths"].Value, PvpSoloKills = tPlayer.Stats["PvpRankedSoloKills"].Value, PvpTeamKills = tPlayer.Stats["PvpRankedTeamKills"].Value, PvpSoloScore = tPlayer.Stats["PvpSoloScore"].Value, PvpTeamScore = tPlayer.Stats["PvpTeamScore"].Value, PvpDuelScore = tPlayer.Stats["PvpDuelScore"].Value }; var infoPacketMessage = new InfoPacketMessage { Identity = tPlayer.Identity, Unknown = 0x00, Type = type, Info = info }; client.SendCompressed(infoPacketMessage); } else // TODO: NPC's { /* * var npc = * (NonPlayerCharacterClass) * FindDynel.FindDynelById(packet.Target); * if (npc != null) * { * var infoPacket = new PacketWriter(); * * // Start packet header * infoPacket.PushByte(0xDF); * infoPacket.PushByte(0xDF); * infoPacket.PushShort(10); * infoPacket.PushShort(1); * infoPacket.PushShort(0); * infoPacket.PushInt(3086); // sender (server ID) * infoPacket.PushInt(client.Character.Id.Instance); // receiver * infoPacket.PushInt(0x4D38242E); // packet ID * infoPacket.PushIdentity(npc.Id); // affected identity * infoPacket.PushByte(0); // ? * * // End packet header * infoPacket.PushByte(0x50); // npc's just have 0x50 * infoPacket.PushByte(1); // esi_001? * infoPacket.PushByte((byte)npc.Stats.Profession.Value); // Profession * infoPacket.PushByte((byte)npc.Stats.Level.Value); // Level * infoPacket.PushByte((byte)npc.Stats.TitleLevel.Value); // Titlelevel * infoPacket.PushByte((byte)npc.Stats.VisualProfession.Value); // Visual Profession * * infoPacket.PushShort(0); // no idea for npc's * infoPacket.PushUInt(npc.Stats.Health.Value); // Current Health (Health) * infoPacket.PushUInt(npc.Stats.Life.Value); // Max Health (Life) * infoPacket.PushInt(0); // BreedHostility? * infoPacket.PushUInt(0); // org ID * infoPacket.PushShort(0); * infoPacket.PushShort(0); * infoPacket.PushShort(0); * infoPacket.PushShort(0); * infoPacket.PushInt(0x499602d2); * infoPacket.PushInt(0x499602d2); * infoPacket.PushInt(0x499602d2); * var infoPacketA = infoPacket.Finish(); * client.SendCompressed(infoPacketA); * }*/ } } break; case 120: { // If action == Logout // Start 30 second logout timer if client is not a GM (statid 215) if (client.Character.Stats["GMLevel"].Value == 0) { // client.startLogoutTimer(); } else { // If client is a GM, disconnect without timer client.Server.DisconnectClient(client); } } break; case 121: { // If action == Stop Logout // Stop current logout timer and send stop logout packet client.Character.UpdateMoveType((byte)client.Character.PreviousMoveMode); //client.CancelLogOut(); } break; case 87: { // If action == Stand client.Character.UpdateMoveType(37); // Send stand up packet, and cancel timer/send stop logout packet if timer is enabled //client.StandCancelLogout(); } break; case 22: { // Kick Team Member } break; case 24: { // Leave Team /* * var team = new TeamClass(); * team.LeaveTeam(client); */ } break; case 25: { // Transfer Team Leadership } break; case 26: { // Team Join Request // Send Team Invite Request To Target Player /* * var team = new TeamClass(); * team.SendTeamRequest(client, packet.Target); */ } break; case 28: { /* * // Request Reply * // Check if positive or negative response * * // if positive * var team = new TeamClass(); * var teamID = TeamClass.GenerateNewTeamId(client, packet.Target); * * // Destination Client 0 = Sender, 1 = Reciever * * // Reciever Packets * /////////////////// * * // CharAction 15 * team.TeamRequestReply(client, packet.Target); * * // CharAction 23 * team.TeamRequestReplyCharacterAction23(client, packet.Target); * * // TeamMember Packet * team.TeamReplyPacketTeamMember(1, client, packet.Target, "Member1"); * * // TeamMemberInfo Packet * team.TeamReplyPacketTeamMemberInfo(1, client, packet.Target); * * // TeamMember Packet * team.TeamReplyPacketTeamMember(1, client, packet.Target, "Member2"); * * // Sender Packets * ///////////////// * * // TeamMember Packet * team.TeamReplyPacketTeamMember(0, client, packet.Target, "Member1"); * * // TeamMemberInfo Packet * team.TeamReplyPacketTeamMemberInfo(0, client, packet.Target); * * // TeamMember Packet * team.TeamReplyPacketTeamMember(0, client, packet.Target, "Member2"); */ } break; case 0x70: // Remove/Delete item ItemDao.RemoveItem((int)packet.Target.Type, client.Character.Identity.Instance, packet.Target.Instance); client.Character.BaseInventory.RemoveItem((int)packet.Target.Type, packet.Target.Instance); client.SendCompressed(packet); break; case 0x34: // Split? IItem it = client.Character.BaseInventory.Pages[(int)packet.Target.Type][packet.Target.Instance]; it.MultipleCount -= args2; Item newItem = new Item(it.Quality, it.LowID, it.HighID); newItem.MultipleCount = args2; client.Character.BaseInventory.Pages[(int)packet.Target.Type].Add( client.Character.BaseInventory.Pages[(int)packet.Target.Type].FindFreeSlot(), newItem); client.Character.BaseInventory.Pages[(int)packet.Target.Type].Write(); break; #region Join item case 0x35: client.Character.BaseInventory.Pages[(int)packet.Target.Type][packet.Target.Instance].MultipleCount += client.Character.BaseInventory.Pages[(int)packet.Target.Type][args2].MultipleCount; client.Character.BaseInventory.Pages[(int)packet.Target.Type].Remove(args2); client.Character.BaseInventory.Pages[(int)packet.Target.Type].Write(); client.SendCompressed(packet); break; #endregion #region Sneak Action // ################################################################################### // Spandexpants: This is all i have done so far as to make sneak turn on and off, // currently i cannot find a missing packet or link which tells the server the player // has stopped sneaking, hidden packet or something, will come back to later. // ################################################################################### // Sneak Packet Received case 163: { // TODO: IF SNEAKING IS ALLOWED RUN THIS CODE. // Send Action 162 : Enable Sneak var sneak = new CharacterActionMessage { Identity = client.Character.Identity, Unknown = 0x00, Action = CharacterActionType.StartedSneaking, Unknown1 = 0x00000000, Target = Identity.None, Parameter1 = 0, Parameter2 = 0, Unknown2 = 0x0000 }; client.SendCompressed(sneak); // End of Enable sneak // TODO: IF SNEAKING IS NOT ALLOWED SEND REJECTION PACKET } break; #endregion #region Use Item on Item /* * case 81: * { * var item1 = packet.Target; * var item2 = new Identity { Type = (IdentityType)args1, Instance = args2 }; * * var cts = new Tradeskill(client, item1.Instance, item2.Instance); * cts.ClickBuild(); * break; * } */ #endregion #region Change Visual Flag case 166: { client.Character.Stats["VisualFlags"].Value = args2; // client.SendChatText("Setting Visual Flag to "+unknown3.ToString()); AppearanceUpdate.AnnounceAppearanceUpdate(client.Character); break; } #endregion /* #region Tradeskill Source Changed * * case 0xdc: * TradeSkillReceiver.TradeSkillSourceChanged(client, args1, args2); * break; * #endregion * #region Tradeskill Target Changed * * case 0xdd: * TradeSkillReceiver.TradeSkillTargetChanged(client, args1, args2); * break; * #endregion * #region Tradeskill Build Pressed * * case 0xde: * TradeSkillReceiver.TradeSkillBuildPressed(client, packet.Target.Instance); * break; * #endregion */ #region default default: { client.Playfield.Announce(packet); } break; #endregion } }
public static void Read(byte[] packet, Client client) { SqlWrapper mys = new SqlWrapper(); // Packet Reader Unknown Values are Returning 0 Integers, Unable to Store Needed Packet data To Reply. #region PacketReader PacketReader packetReader = new PacketReader(packet); Header m_header = packetReader.PopHeader(); // 0 - 28 byte unknown = packetReader.PopByte(); // 29 int actionNum = packetReader.PopInt(); // 30 - 33 int unknown1 = packetReader.PopInt(); // 34 - 37 Identity m_ident = packetReader.PopIdentity(); // 38 - 35 int unknown2 = packetReader.PopInt(); // 36 - 39 int unknown3 = packetReader.PopInt(); // 40 - 43 short unknown4 = packetReader.PopShort(); // 44 - 45 #endregion switch (actionNum) { #region Cast nano case 19: // Cast nano { // CastNanoSpell PacketWriter castNanoSpell = new PacketWriter(); castNanoSpell.PushByte(0xDF); castNanoSpell.PushByte(0xDF); castNanoSpell.PushShort(10); castNanoSpell.PushShort(1); castNanoSpell.PushShort(0); castNanoSpell.PushInt(3086); castNanoSpell.PushInt(client.Character.Id); castNanoSpell.PushInt(0x25314D6D); castNanoSpell.PushIdentity(50000, client.Character.Id); castNanoSpell.PushByte(0); castNanoSpell.PushInt(unknown3); // Nano ID castNanoSpell.PushIdentity(m_ident); // Target castNanoSpell.PushInt(0); castNanoSpell.PushIdentity(50000, client.Character.Id); // Caster byte[] castNanoSpellA = castNanoSpell.Finish(); Announce.Playfield(client.Character.PlayField, castNanoSpellA); // CharacterAction 107 PacketWriter characterAction107 = new PacketWriter(); characterAction107.PushByte(0xDF); characterAction107.PushByte(0xDF); characterAction107.PushShort(10); characterAction107.PushShort(1); characterAction107.PushShort(0); characterAction107.PushInt(3086); characterAction107.PushInt(client.Character.Id); characterAction107.PushInt(0x5E477770); characterAction107.PushIdentity(50000, client.Character.Id); characterAction107.PushByte(0); characterAction107.PushInt(107); characterAction107.PushInt(0); characterAction107.PushInt(0); characterAction107.PushInt(0); characterAction107.PushInt(1); characterAction107.PushInt(unknown3); characterAction107.PushShort(0); byte[] characterAction107A = characterAction107.Finish(); Announce.Playfield(client.Character.PlayField, characterAction107A); // CharacterAction 98 PacketWriter characterAction98 = new PacketWriter(); characterAction98.PushByte(0xDF); characterAction98.PushByte(0xDF); characterAction98.PushShort(10); characterAction98.PushShort(1); characterAction98.PushShort(0); characterAction98.PushInt(3086); characterAction98.PushInt(client.Character.Id); characterAction98.PushInt(0x5E477770); characterAction98.PushIdentity(m_ident); characterAction98.PushByte(0); characterAction98.PushInt(98); characterAction98.PushInt(0); characterAction98.PushInt(0xCF1B); characterAction98.PushInt(unknown3); characterAction98.PushInt(client.Character.Id); characterAction98.PushInt(0x249F0); // duration? characterAction98.PushShort(0); byte[] characterAction98A = characterAction98.Finish(); Announce.Playfield(client.Character.PlayField, characterAction98A); } break; #endregion #region search /* this is here to prevent server crash that is caused by * search action if server doesn't reply if something is * found or not */ case 66: // If action == search { /* Msg 110:136744723 = "No hidden objects found." */ client.SendFeedback(110, 136744723); } break; #endregion #region info case 105: // If action == Info Request { Client tPlayer = null; if ((tPlayer = FindClient.FindClientById(m_ident.Instance)) != null) { #region Titles uint LegacyScore = tPlayer.Character.Stats.PvpRating.StatBaseValue; string LegacyTitle = null; if (LegacyScore < 1400) { LegacyTitle = ""; } else if (LegacyScore < 1500) { LegacyTitle = "Freshman"; } else if (LegacyScore < 1600) { LegacyTitle = "Rookie"; } else if (LegacyScore < 1700) { LegacyTitle = "Apprentice"; } else if (LegacyScore < 1800) { LegacyTitle = "Novice"; } else if (LegacyScore < 1900) { LegacyTitle = "Neophyte"; } else if (LegacyScore < 2000) { LegacyTitle = "Experienced"; } else if (LegacyScore < 2100) { LegacyTitle = "Expert"; } else if (LegacyScore < 2300) { LegacyTitle = "Master"; } else if (LegacyScore < 2500) { LegacyTitle = "Champion"; } else { LegacyTitle = "Grand Master"; } #endregion int orgGoverningForm = 0; SqlWrapper ms = new SqlWrapper(); DataTable dt = ms.ReadDatatable( "SELECT `GovernmentForm` FROM organizations WHERE ID=" + tPlayer.Character.OrgId); if (dt.Rows.Count > 0) { orgGoverningForm = (Int32)dt.Rows[0][0]; } string orgRank = OrgClient.GetRank( orgGoverningForm, tPlayer.Character.Stats.ClanLevel.StatBaseValue); // Uses methods in ZoneEngine\PacketHandlers\OrgClient.cs /* Known packetFlags-- * 0x40 - No org | 0x41 - Org | 0x43 - Org and towers | 0x47 - Org, towers, player has personal towers | 0x50 - No pvp data shown * Bitflags-- * Bit0 = hasOrg, Bit1 = orgTowers, Bit2 = personalTowers, Bit3 = (Int32) time until supression changes (Byte) type of supression level?, Bit4 = noPvpDataShown, Bit5 = hasFaction, Bit6 = ?, Bit 7 = null. */ byte packetFlags = 0x40; // Player has no Org if (tPlayer.Character.OrgId != 0) { packetFlags = 0x41; // Player has Org, no towers } PacketWriter infoPacket = new PacketWriter(); // Start packet header infoPacket.PushByte(0xDF); infoPacket.PushByte(0xDF); infoPacket.PushShort(10); infoPacket.PushShort(1); infoPacket.PushShort(0); infoPacket.PushInt(3086); // sender (server ID) infoPacket.PushInt(client.Character.Id); // receiver infoPacket.PushInt(0x4D38242E); // packet ID infoPacket.PushIdentity(50000, tPlayer.Character.Id); // affected identity infoPacket.PushByte(0); // ? // End packet header infoPacket.PushByte(packetFlags); // Based on flags above infoPacket.PushByte(1); // esi_001? infoPacket.PushByte((byte)tPlayer.Character.Stats.Profession.Value); // Profession infoPacket.PushByte((byte)tPlayer.Character.Stats.Level.Value); // Level infoPacket.PushByte((byte)tPlayer.Character.Stats.TitleLevel.Value); // Titlelevel infoPacket.PushByte((byte)tPlayer.Character.Stats.VisualProfession.Value); // Visual Profession infoPacket.PushShort(0); // Side XP Bonus infoPacket.PushUInt(tPlayer.Character.Stats.Health.Value); // Current Health (Health) infoPacket.PushUInt(tPlayer.Character.Stats.Life.Value); // Max Health (Life) infoPacket.PushInt(0); // BreedHostility? infoPacket.PushUInt(tPlayer.Character.OrgId); // org ID infoPacket.PushShort((short)tPlayer.Character.FirstName.Length); infoPacket.PushBytes(Encoding.ASCII.GetBytes(tPlayer.Character.FirstName)); infoPacket.PushShort((short)tPlayer.Character.LastName.Length); infoPacket.PushBytes(Encoding.ASCII.GetBytes(tPlayer.Character.LastName)); infoPacket.PushShort((short)LegacyTitle.Length); infoPacket.PushBytes(Encoding.ASCII.GetBytes(LegacyTitle)); infoPacket.PushShort(0); // Title 2 // If receiver is in the same org as affected identity, whom is not orgless, send org rank and city playfield if ((client.Character.OrgId == tPlayer.Character.OrgId) && (tPlayer.Character.OrgId != 0)) { infoPacket.PushShort((short)orgRank.Length); infoPacket.PushBytes(Encoding.ASCII.GetBytes(orgRank)); infoPacket.PushInt(0); //infoPacket.PushIdentity(0, 0); // City (50201, Playfield) // Pushed 1 zero to much and screwed info for characters in orgs, but I´ll leave it for later just incase. } infoPacket.PushUInt(tPlayer.Character.Stats.InvadersKilled.Value); // Invaders Killed infoPacket.PushUInt(tPlayer.Character.Stats.KilledByInvaders.Value); // Killed by Invaders infoPacket.PushUInt(tPlayer.Character.Stats.AlienLevel.Value); // Alien Level infoPacket.PushUInt(tPlayer.Character.Stats.PvpDuelKills.Value); // Pvp Duel Kills infoPacket.PushUInt(tPlayer.Character.Stats.PvpDuelDeaths.Value); // Pvp Duel Deaths infoPacket.PushUInt(tPlayer.Character.Stats.PvpProfessionDuelDeaths.Value); // Pvp Profession Duel Kills infoPacket.PushUInt(tPlayer.Character.Stats.PvpRankedSoloKills.Value); // Pvp Solo Kills infoPacket.PushUInt(tPlayer.Character.Stats.PvpRankedSoloDeaths.Value); // Pvp Team Kills infoPacket.PushUInt(tPlayer.Character.Stats.PvpSoloScore.Value); // Pvp Solo Score infoPacket.PushUInt(tPlayer.Character.Stats.PvpTeamScore.Value); // Pvp Team Score infoPacket.PushUInt(tPlayer.Character.Stats.PvpDuelScore.Value); // Pvp Duel Score byte[] infoPacketA = infoPacket.Finish(); client.SendCompressed(infoPacketA); } else { NonPlayerCharacterClass npc = (NonPlayerCharacterClass)FindDynel.FindDynelById(m_ident.Type, m_ident.Instance); if (npc != null) { PacketWriter infoPacket = new PacketWriter(); // Start packet header infoPacket.PushByte(0xDF); infoPacket.PushByte(0xDF); infoPacket.PushShort(10); infoPacket.PushShort(1); infoPacket.PushShort(0); infoPacket.PushInt(3086); // sender (server ID) infoPacket.PushInt(client.Character.Id); // receiver infoPacket.PushInt(0x4D38242E); // packet ID infoPacket.PushIdentity(50000, npc.Id); // affected identity infoPacket.PushByte(0); // ? // End packet header infoPacket.PushByte(0x50); // npc's just have 0x50 infoPacket.PushByte(1); // esi_001? infoPacket.PushByte((byte)npc.Stats.Profession.Value); // Profession infoPacket.PushByte((byte)npc.Stats.Level.Value); // Level infoPacket.PushByte((byte)npc.Stats.TitleLevel.Value); // Titlelevel infoPacket.PushByte((byte)npc.Stats.VisualProfession.Value); // Visual Profession infoPacket.PushShort(0); // no idea for npc's infoPacket.PushUInt(npc.Stats.Health.Value); // Current Health (Health) infoPacket.PushUInt(npc.Stats.Life.Value); // Max Health (Life) infoPacket.PushInt(0); // BreedHostility? infoPacket.PushUInt(0); // org ID infoPacket.PushShort(0); infoPacket.PushShort(0); infoPacket.PushShort(0); infoPacket.PushShort(0); infoPacket.PushInt(0x499602d2); infoPacket.PushInt(0x499602d2); infoPacket.PushInt(0x499602d2); byte[] infoPacketA = infoPacket.Finish(); client.SendCompressed(infoPacketA); } } } break; #endregion #region logout case 120: // If action == Logout { //Start 30 second logout timer if client is not a GM (statid 215) if (client.Character.Stats.GMLevel.Value == 0) { client.startLogoutTimer(); } else // If client is a GM, disconnect without timer { client.Server.DisconnectClient(client); } } break; case 121: // If action == Stop Logout { //Stop current logout timer and send stop logout packet client.Character.UpdateMoveType((byte)client.Character.PreviousMoveMode); client.CancelLogOut(); } break; #endregion #region stand case 87: // If action == Stand { client.Character.UpdateMoveType(37); //Send stand up packet, and cancel timer/send stop logout packet if timer is enabled client.StandCancelLogout(); } break; #endregion #region Team case 22: //Kick Team Member { } break; case 24: //Leave Team { TeamClass team = new TeamClass(); team.LeaveTeam(client); } break; case 25: //Transfer Team Leadership { } break; case 26: //Team Join Request { // Send Team Invite Request To Target Player TeamClass team = new TeamClass(); team.SendTeamRequest(client, m_ident); } break; case 28: //Request Reply { // Check if positive or negative response // if positive TeamClass team = new TeamClass(); uint teamID = TeamClass.GenerateNewTeamId(client, m_ident); // Destination Client 0 = Sender, 1 = Reciever // Reciever Packets /////////////////// // CharAction 15 team.TeamRequestReply(client, m_ident); // CharAction 23 team.TeamRequestReplyCharacterAction23(client, m_ident); // TeamMember Packet team.TeamReplyPacketTeamMember(1, client, m_ident, "Member1"); // TeamMemberInfo Packet team.TeamReplyPacketTeamMemberInfo(1, client, m_ident); // TeamMember Packet team.TeamReplyPacketTeamMember(1, client, m_ident, "Member2"); // Sender Packets ///////////////// // TeamMember Packet team.TeamReplyPacketTeamMember(0, client, m_ident, "Member1"); // TeamMemberInfo Packet team.TeamReplyPacketTeamMemberInfo(0, client, m_ident); // TeamMember Packet team.TeamReplyPacketTeamMember(0, client, m_ident, "Member2"); } break; #endregion #region Delete Item case 0x70: mys.SqlDelete( "DELETE FROM " + client.Character.GetSqlTablefromDynelType() + "inventory WHERE placement=" + m_ident.Instance.ToString() + " AND container=" + m_ident.Type.ToString()); InventoryEntries i_del = client.Character.GetInventoryAt(m_ident.Instance); client.Character.Inventory.Remove(i_del); byte[] action2 = new byte[0x37]; Array.Copy(packet, action2, 0x37); action2[8] = 0x00; action2[9] = 0x00; action2[10] = 0x0C; action2[11] = 0x0E; client.SendCompressed(action2); break; #endregion #region Split item case 0x34: int nextid = client.Character.GetNextFreeInventory(m_ident.Type); InventoryEntries i = client.Character.GetInventoryAt(m_ident.Instance); i.Item.MultipleCount -= unknown3; InventoryEntries i2 = new InventoryEntries(); i2.Item = i.Item.ShallowCopy(); i2.Item.MultipleCount = unknown3; i2.Placement = nextid; client.Character.Inventory.Add(i2); client.Character.WriteInventoryToSql(); break; #endregion #region Join item case 0x35: InventoryEntries j1 = client.Character.GetInventoryAt(m_ident.Instance); InventoryEntries j2 = client.Character.GetInventoryAt(unknown3); j1.Item.MultipleCount += j2.Item.MultipleCount; client.Character.Inventory.Remove(j2); client.Character.WriteInventoryToSql(); byte[] joined = new byte[0x37]; Array.Copy(packet, joined, 0x37); joined[8] = 0x00; joined[9] = 0x00; joined[10] = 0x0C; joined[11] = 0x0E; client.SendCompressed(joined); break; #endregion #region Sneak Action // ################################################################################### // Spandexpants: This is all i have done so far as to make sneak turn on and off, // currently i cannot find a missing packet or link which tells the server the player // has stopped sneaking, hidden packet or something, will come back to later. // ################################################################################### // Sneak Packet Received case 163: { PacketWriter Sneak = new PacketWriter(); // TODO: IF SNEAKING IS ALLOWED RUN THIS CODE. // Send Action 162 : Enable Sneak Sneak.PushByte(0xDF); Sneak.PushByte(0xDF); Sneak.PushShort(0xA); Sneak.PushShort(1); Sneak.PushShort(0); Sneak.PushInt(3086); // Send Sneak.PushInt(client.Character.Id); // Reciever Sneak.PushInt(0x5e477770); // Packet ID Sneak.PushIdentity(50000, client.Character.Id); // TYPE / ID Sneak.PushInt(0); Sneak.PushByte(0xA2); // Action ID Sneak.PushInt(0); Sneak.PushInt(0); Sneak.PushInt(0); Sneak.PushInt(0); Sneak.PushInt(0); Sneak.PushShort(0); byte[] sneakpacket = Sneak.Finish(); client.SendCompressed(sneakpacket); // End of Enable sneak // TODO: IF SNEAKING IS NOT ALLOWED SEND REJECTION PACKET } break; #endregion #region Use Item on Item case 81: { Identity item1 = new Identity(); Identity item2 = new Identity(); item1.Type = m_ident.Type; item1.Instance = m_ident.Instance; item2.Type = unknown2; item2.Instance = unknown3; Tradeskill cts = new Tradeskill(client, item1.Instance, item2.Instance); cts.ClickBuild(); break; } #endregion #region Change Visual Flag case 166: { client.Character.Stats.VisualFlags.Set(unknown3); // client.SendChatText("Setting Visual Flag to "+unknown3.ToString()); AppearanceUpdate.AnnounceAppearanceUpdate(client.Character); break; } #endregion #region Tradeskill Source Changed case 0xdc: TradeSkillReceiver.TradeSkillSourceChanged(client, unknown2, unknown3); break; #endregion #region Tradeskill Target Changed case 0xdd: TradeSkillReceiver.TradeSkillTargetChanged(client, unknown2, unknown3); break; #endregion #region Tradeskill Build Pressed case 0xde: TradeSkillReceiver.TradeSkillBuildPressed(client, m_ident.Instance); break; #endregion #region default default: { byte[] action = new byte[0x37]; Array.Copy(packet, action, 0x37); action[8] = 0x00; action[9] = 0x00; action[10] = 0x0C; action[11] = 0x0E; Announce.Playfield(client.Character.PlayField, action); } break; #endregion } packetReader.Finish(); }
/// <summary> /// /// </summary> /// <param name="packet"></param> /// <param name="client"></param> public void Read(byte[] packet, Client client) { // Don't edit anything in this region // unless you are 300% sure you know what you're doing #region Do not edit MemoryStream memoryStream = new MemoryStream(packet); BinaryReader binaryReader = new BinaryReader(memoryStream); memoryStream.Position = 20; // we get character ID of a client and store // it in this ClientBase so we can use it later int charID = IPAddress.NetworkToHostOrder(binaryReader.ReadInt32()); binaryReader.Close(); memoryStream.Dispose(); client.Character = new Character(charID, 0); client.Character.Client = client; client.Character.ReadNames(); client.Server.Info( client, "Client connected. ID: {0} IP: {1}", client.Character.Id, client.TcpIP + " Character name: " + client.Character.Name); // now we have to start sending packets like // character stats, inventory, playfield info // and so on. I will put some packets here just // to get us in game. We have to start moving // these packets somewhere else and make packet // builders instead of sending (half) hardcoded // packets. // lets get char ID as byte array byte[] chrID = new[] { packet[20], packet[21], packet[22], packet[23] }; /* send chat server info to client */ ChatServerInfo.Send(client); /* send playfield info to client */ PlayfieldAnarchyF.Send(client); /* set SocialStatus to 0 */ client.Character.Stats.SetBaseValue(521, 0); Stat.Send(client, 521, 0, false); /* Action 167 Animation and Stance Data maybe? */ byte[] tempBytes = new byte[] { 0xDF, 0xDF, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x37, 0x00, 0x00, 0x0c, 0x0e, chrID[0], chrID[1], chrID[2], chrID[3], 0x5E, 0x47, 0x77, 0x70, // CharacterAction 0x00, 0x00, 0xC3, 0x50, chrID[0], chrID[1], chrID[2], chrID[3], 0x00, 0x00, 0x00, 0x00, 0xA7, // 167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x01, 0x00, 0x00 }; client.SendCompressed(tempBytes); tempBytes = new byte[] { // current in game time 0xDF, 0xDF, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x2D, 0x00, 0x00, 0x0c, 0x0e, chrID[0], chrID[1], chrID[2], chrID[3], 0x5F, 0x52, 0x41, 0x2E, // GameTime 0x00, 0x00, 0xC3, 0x50, chrID[0], chrID[1], chrID[2], chrID[3], 0x01, 0x46, 0xEA, 0x90, 0x00, // 30024.0 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xD4, 0x40, // 185408 0x47, 0x9C, 0x9B, 0xA8 // 80183.3125 }; client.SendCompressed(tempBytes); /* set SocialStatus to 0 */ Stat.Set(client, 521, 0, false); /* again */ Stat.Set(client, 521, 0, false); /* visual */ SimpleCharFullUpdate.SendToPlayfield(client); /* inventory, items and all that */ FullCharacter.Send(client); tempBytes = new byte[] { // this packet gives you (or anyone else) // special attacks like brawl, fling shot and so 0xDF, 0xDF, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x65, 0x00, 0x00, 0x0c, 0x0e, chrID[0], chrID[1], chrID[2], chrID[3], 0x1D, 0x3C, 0x0F, 0x1C, // SpecialAttackWeapon 0x00, 0x00, 0xC3, 0x50, chrID[0], chrID[1], chrID[2], chrID[3], 0x01, 0x00, 0x00, 0x0F, 0xC4, // (4036/1009)-1 = 3 special attacks 0x00, 0x00, 0xAA, 0xC0, // 43712 0x00, 0x02, 0x35, 0x69, // 144745 0x00, 0x00, 0x00, 0x64, // 100 0x4D, 0x41, 0x41, 0x54, // "MAAT" 0x00, 0x00, 0xA4, 0x31, // 42033 0x00, 0x00, 0xA4, 0x30, // 42032 0x00, 0x00, 0x00, 0x90, // 144 0x44, 0x49, 0x49, 0x54, // "DIIT" 0x00, 0x01, 0x12, 0x94, // 70292 0x00, 0x01, 0x12, 0x95, // 70293 0x00, 0x00, 0x00, 0x8E, // 142 0x42, 0x52, 0x41, 0x57, // "BRAW" 0x00, 0x00, 0x00, 0x07, // 7 0x00, 0x00, 0x00, 0x07, // 7 0x00, 0x00, 0x00, 0x07, // 7 0x00, 0x00, 0x00, 0x0E, // 14 0x00, 0x00, 0x00, 0x64 // 100 }; client.SendCompressed(tempBytes); // done #endregion // Timers are allowed to update client stats now. client.Character.DoNotDoTimers = false; // spawn all active monsters to client NonPlayerCharacterHandler.SpawnMonstersInPlayfieldToClient(client, client.Character.PlayField); if (VendorHandler.GetNumberofVendorsinPlayfield(client.Character.PlayField) > 0) { /* Shops */ VendorHandler.GetVendorsInPF(client); } // WeaponItemFullCharUpdate Maybe the right location , First Check if weapons present usually in equipment //Packets.WeaponItemFullUpdate.Send(client, client.Character); client.Character.ProcessTimers(DateTime.Now + TimeSpan.FromMilliseconds(200)); client.Character.CalculateSkills(); AppearanceUpdate.AnnounceAppearanceUpdate(client.Character); // done, so we call a hook. // Call all OnConnect script Methods Program.csc.CallMethod("OnConnect", client.Character); }
/// <summary> /// </summary> /// <param name="character"> /// </param> public void AnnounceAppearanceUpdate(ICharacter character) { AppearanceUpdate.AnnounceAppearanceUpdate(character); }