public bool BankWithdraw(int amount) { if (!m_client.ConnectedAndInitialized || !Initialized || amount < 0) return false; Packet pkt = new Packet(PacketFamily.Bank, PacketAction.Take); pkt.AddInt(amount); return m_client.SendPacket(pkt); }
private void SendTestPacket(int value) { Packet pkt = PacketManager.Instance.AllocatePacket(); pkt.SetPacketID(Protocol.CLI_GW_ENTER_TEST); pkt.AddInt(value); SendPacket(pkt); LogManager.Info("Send test packet."); }
private void SendUdpTestPacket(int value) { Packet pkt = PacketManager.Instance.AllocatePacket(); pkt.SetPacketID(Protocol.UDP_CLI_GW_TEST); pkt.AddInt(value); SendPacket(pkt); LogManager.Info("Send udp test packet. UserID = " + this.UserID.ToString()); }
private void SendTestPacket() { Packet pkt = PacketManager.Instance.AllocatePacket(); pkt.SetPacketID(Protocol.CLI_GW_ENTER_TEST); pkt.AddInt(123456789); SendPacket(pkt); LogManager.Info("Send test packet. UserID = " + this.UserID.ToString()); }
/// <summary> /// Buy an item from a shopkeeper /// </summary> public bool BuyItem(short ItemID, int amount) { if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet pkt = new Packet(PacketFamily.Shop, PacketAction.Buy); pkt.AddShort(ItemID); pkt.AddInt(amount); return m_client.SendPacket(pkt); }
/// <summary> /// Add an item to a pending trade offer /// </summary> /// <param name="itemID">Item ID of the item to add</param> /// <param name="amount">Amount of the item to add</param> public bool TradeAddItem(short itemID, int amount) { if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet pkt = new Packet(PacketFamily.Trade, PacketAction.Add); pkt.AddShort(itemID); pkt.AddInt(amount); return m_client.SendPacket(pkt); }
public bool BankWithdraw(int amount) { if (!m_client.ConnectedAndInitialized || !Initialized || amount < 0) { return(false); } Packet pkt = new Packet(PacketFamily.Bank, PacketAction.Take); pkt.AddInt(amount); return(m_client.SendPacket(pkt)); }
public static bool BankWithdraw(int amount) { EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized || amount < 0) { return(false); } Packet pkt = new Packet(PacketFamily.Bank, PacketAction.Take); pkt.AddInt(amount); return(client.SendPacket(pkt)); }
/// <summary> /// Buy an item from a shopkeeper /// </summary> public static bool BuyItem(short ItemID, int amount) { EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized) { return(false); } Packet pkt = new Packet(PacketFamily.Shop, PacketAction.Buy); pkt.AddShort(ItemID); pkt.AddInt(amount); return(client.SendPacket(pkt)); }
public void SendUdpAuthPacket() { Debug.Assert(null != m_UserSession); Debug.Assert(m_UserSession is UdpSession); UdpSession sess = m_UserSession as UdpSession; IPEndPoint end_point = (IPEndPoint)sess.Socket.LocalEndPoint; Packet pkt = PacketManager.Instance.AllocatePacket(); pkt.SetPacketID(Protocol.UDP_CLI_GW_AUTH); pkt.AddInt(end_point.Port); SendPacket(pkt); LogManager.Info("Send udp auth packet. Local port = " + end_point.Port.ToString() + " UserID = " + this.m_UserID.ToString()); }
public static void HandleCreate(Packet packet, IClient client, bool fromQueue) { short createId = packet.GetShort(); Gender gender = (Gender)packet.GetShort(); short hairStyle = packet.GetShort(); short hairColor = packet.GetShort(); Skin skin = (Skin)packet.GetShort(); packet.GetByte(); string name = packet.GetBreakString().ToLower(); if (!Enum.IsDefined(typeof(Gender), gender)) throw new ArgumentOutOfRangeException("Invalid gender on character creation (" + gender + ")"); // TODO: Make these configurable if (hairStyle < 1 || hairStyle > 20 || hairColor < 0 || hairColor > 9) throw new ArgumentOutOfRangeException("Hair parameters out of range on character creation (" + hairStyle + ", " + hairColor + ")"); if (!Enum.IsDefined(typeof(Skin), skin)) throw new ArgumentOutOfRangeException("Invalid skin on character creation (" + skin + ")"); Packet reply = new Packet(PacketFamily.Character, PacketAction.Reply); // TODO: Make this configurable if (client.Account.Characters.Count >= 3) { reply.AddShort((short)CharacterReply.Full); client.Send(reply); return; } if (!Character.ValidName(name)) { reply.AddShort((short)CharacterReply.NotApproved); client.Send(reply); return; } // TODO: Make a CharacterExists function var checkCharacter = from Character c in client.Server.Database.Container where c.name == name select 1; if (checkCharacter.Count() != 0) { reply.AddShort((short)CharacterReply.Exists); client.Send(reply); return; } Character newCharacter = new Character(client.Server, client, name, gender, (byte)hairStyle, (byte)hairColor, skin); client.Account.Characters.Add(newCharacter); newCharacter.Store(); client.Account.Store(); client.Server.Database.Commit(); reply.AddShort((short)CharacterReply.OK); reply.AddChar((byte)client.Account.Characters.Count); reply.AddByte(1); // TODO: What is this? reply.AddBreak(); // TODO: Some kind of character list packet builder int i = 0; foreach (Character character in client.Account.Characters) { reply.AddBreakString(character.Name); reply.AddInt(i++); reply.AddChar(character.Level); reply.AddChar((byte)character.Gender); reply.AddChar(character.HairStyle); reply.AddChar(character.HairColor); reply.AddChar((byte)character.Skin); reply.AddChar((byte)character.Admin); reply.AddShort((short)(character.Boots != null ? character.Boots.Data.special1 : 0)); reply.AddShort((short)(character.Armor != null ? character.Armor.Data.special1 : 0)); reply.AddShort((short)(character.Hat != null ? character.Hat.Data.special1 : 0)); reply.AddShort((short)(character.Shield != null ? character.Shield.Data.special1 : 0)); reply.AddShort((short)(character.Weapon != null ? character.Weapon.Data.special1 : 0)); reply.AddBreak(); } client.Send(reply); }
public static void HandleTake(Packet packet, IClient client, bool fromQueue) { int id = packet.GetInt(); if (id < 0 || id > client.Account.Characters.Count) throw new ArgumentOutOfRangeException("Login character ID out of range"); Packet reply = new Packet(PacketFamily.Character, PacketAction.Player); reply.AddShort(1000); // Delete id // TODO: Generate a deletion id and check it reply.AddInt(id); client.Send(reply); }
public bool ResetCharacterStatSkill() { Packet pkt = new Packet(PacketFamily.StatSkill, PacketAction.Junk); pkt.AddInt(1234); //shop ID, ignored by eoserv - eomain may require this to be correct return !m_client.ConnectedAndInitialized || !Initialized || m_client.SendPacket(pkt); }
public bool ForgetSpell(short spellID) { if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet pkt = new Packet(PacketFamily.StatSkill, PacketAction.Remove); pkt.AddInt(1234); //shop ID, ignored by eoserv - eomain may require this to be correct pkt.AddShort(spellID); return m_client.SendPacket(pkt); }
public static void HandleMessage(Packet packet, IClient client, bool fromQueue) { Packet reply = new Packet(PacketFamily.Welcome, PacketAction.Reply); client.EnterGame(); client.Character.Map.Enter(client.Character, WarpAnimation.Admin); reply.AddShort((short)WelcomeReply.WorldInfo); reply.AddBreak(); for (int i = 0; i < 9; ++i) { reply.AddBreakString("A"); } reply.AddChar(client.Character.Weight); // Weight reply.AddChar(client.Character.MaxWeight); // Max Weight // Inventory foreach (ItemStack item in client.Character.Items) { reply.AddShort(item.Id); reply.AddInt(item.Amount); } reply.AddBreak(); // Spells reply.AddBreak(); IEnumerable<Character> characters = client.Character.GetInRange<Character>(); IEnumerable<NPC> npcs = client.Character.GetInRange<NPC>(); IEnumerable<MapItem> items = client.Character.GetInRange<MapItem>(); reply.AddChar((byte)characters.Count()); reply.AddBreak(); // Characters // { foreach (Character character in characters) { character.InfoBuilder(ref reply); reply.AddBreak(); } // } // NPCs foreach (NPC npc in npcs) { npc.InfoBuilder(ref reply); } reply.AddBreak(); // Items foreach (MapItem item in items) { item.InfoBuilder(ref reply); } client.Send(reply); }
public static void HandleRequest(Packet packet, IClient client, bool fromQueue) { int id = packet.GetInt(); if (id < 0 || id > client.Account.Characters.Count) throw new ArgumentOutOfRangeException("Login character ID out of range"); client.SelectCharacter(client.Account.Characters[id]); Packet reply = new Packet(PacketFamily.Welcome, PacketAction.Reply); reply.AddShort((short)WelcomeReply.CharacterInfo); reply.AddShort((short)client.Id); reply.AddInt(id); reply.AddShort((short)client.Character.Map.Data.Id); reply.AddBytes(client.Character.Map.Data.RevisionID); reply.AddThree((int)client.Character.Map.Data.PubFileLength); reply.AddBytes(client.Server.ItemData.revisionId); reply.AddShort((short)client.Server.ItemData.Count); reply.AddBytes(client.Server.NpcData.revisionId); reply.AddShort((short)client.Server.NpcData.Count); reply.AddBytes(client.Server.SpellData.revisionId); reply.AddShort((short)client.Server.SpellData.Count); reply.AddBytes(client.Server.ClassData.revisionId); reply.AddShort((short)client.Server.ClassData.Count); reply.AddBreakString(client.Character.Name); reply.AddBreakString(client.Character.Title ?? ""); reply.AddBreakString("Guild Name"); reply.AddBreakString("Guild Rank"); reply.AddChar(0); // Class reply.AddString("TAG"); // Guild tag reply.AddChar((byte)client.Character.Admin); reply.AddChar(client.Character.Level); // Level reply.AddInt(client.Character.Exp); // Exp reply.AddInt(client.Character.Usage); // Usage reply.AddShort(client.Character.Hp); // HP reply.AddShort(client.Character.MaxHp); // MaxHP reply.AddShort(client.Character.Tp); // TP reply.AddShort(client.Character.MaxTp); // MaxTP reply.AddShort(client.Character.MaxSp); // MaxSP reply.AddShort(client.Character.StatPoints); // StatPts reply.AddShort(client.Character.SkillPoints); // SkillPts reply.AddShort(client.Character.Karma); // Karma reply.AddShort(client.Character.MinDamage); // MinDam reply.AddShort(client.Character.MaxDamage); // MaxDam reply.AddShort(client.Character.Accuracy); // Accuracy reply.AddShort(client.Character.Evade); // Evade reply.AddShort(client.Character.Defence); // Armor reply.AddShort(client.Character.Strength); // Str reply.AddShort(client.Character.Wisdom); // Wis reply.AddShort(client.Character.Intelligence); // Int reply.AddShort(client.Character.Agility); // Agi reply.AddShort(client.Character.Constitution); // Con reply.AddShort(client.Character.Charisma); // Cha // Inventory reply.AddBreak(); reply.AddChar(1); // Guild Rank reply.AddShort(2); // Jail map reply.AddShort(4); // ? reply.AddChar(24); // ? reply.AddChar(24); // ? reply.AddShort(10); // ? reply.AddShort(10); // ? reply.AddShort(0); // Admin command flood rate reply.AddShort(2); // ? reply.AddChar(0); // Login warning message reply.AddBreak(); client.Send(reply); }
public bool WelcomeMessage(int id, out WelcomeMessageData data) { data = null; if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet builder = new Packet(PacketFamily.Welcome, PacketAction.Message); builder.AddThree(0x00123456); //? builder.AddInt(id); if (!m_client.SendPacket(builder)) return false; if (!m_welcome_responseEvent.WaitOne(Constants.ResponseTimeout)) return false; data = m_welcome_messageData; m_client.IsInGame = true; return true; }
public bool CharacterTake(int id, out int takeID) { takeID = -1; if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet builder = new Packet(PacketFamily.Character, PacketAction.Take); builder.AddInt(id); if (!m_client.SendPacket(builder) || !m_character_responseEvent.WaitOne(Constants.ResponseTimeout)) return false; takeID = m_character_takeID; return true; }
//255 means use character's current location public bool DropItem(short id, int amount, byte x = 255, byte y = 255) { if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet pkt = new Packet(PacketFamily.Item, PacketAction.Drop); pkt.AddShort(id); pkt.AddInt(amount); if (x == 255 && y == 255) { pkt.AddByte(x); pkt.AddByte(y); } else { pkt.AddChar(x); pkt.AddChar(y); } return m_client.SendPacket(pkt); }
private void Test_Share_Net_ReadWriteBuffer() { Packet pkt_orig = PacketManager.Instance.AllocatePacket(); CAssert.IsNotNull(pkt_orig); pkt_orig.SetPacketID(Protocol.CLI_GW_ENTER_TEST); CAssert.AreEqual(pkt_orig.GetPacketID(), Protocol.CLI_GW_ENTER_TEST); int int_test = 10000001; short short_test = 10001; double double_test = 123456789.987654321; float float_test = 12345.12345f; string str_test = "This is a testing string."; pkt_orig.AddInt(int_test); pkt_orig.AddShort(short_test); pkt_orig.AddDouble(double_test); pkt_orig.AddFloat(float_test); pkt_orig.AddString(str_test); byte[] buffer = new byte[ReadWriteBuffer.BUFFER_MAX_SIZE]; ReadWriteBuffer rw_buf = new ReadWriteBuffer(buffer); CAssert.IsNotNull(rw_buf); CAssert.AreEqual(0, rw_buf.GetCanReadSize()); CAssert.AreEqual(ReadWriteBuffer.BUFFER_MAX_SIZE, rw_buf.GetCanWriteSize()); rw_buf.WriteBytes(pkt_orig.Buf, pkt_orig.Size); CAssert.AreEqual(rw_buf.GetCanReadSize(), (int)pkt_orig.Size); Packet pkt_read = PacketManager.Instance.AllocatePacket(); CAssert.IsNotNull(pkt_read); rw_buf.ReadBytes(pkt_read.Buf, rw_buf.GetCanReadSize()); pkt_read.SetSize(); CAssert.AreEqual(0, rw_buf.GetCanReadSize()); CAssert.AreEqual(ReadWriteBuffer.BUFFER_MAX_SIZE, rw_buf.GetCanWriteSize()); CAssert.AreEqual(pkt_orig.Size, pkt_read.Size); CAssert.AreEqual(pkt_orig.Buf, pkt_read.Buf); int w_count = 0; while (rw_buf.GetCanWriteSize() >= pkt_orig.Size) { rw_buf.WriteBytes(pkt_orig.Buf, pkt_orig.Size); ++w_count; } CAssert.AreEqual(pkt_orig.Size * w_count, rw_buf.GetCanReadSize()); int r_count = 0; while (rw_buf.GetCanReadSize() > 0) { int pkt_size = rw_buf.PeekPacketSize(); CAssert.IsTrue(rw_buf.GetCanReadSize() >= pkt_size); Packet pkt_tmp = PacketManager.Instance.AllocatePacket(); CAssert.IsNotNull(pkt_tmp); pkt_tmp.Initialize(); rw_buf.ReadBytes(pkt_tmp.Buf, pkt_size); pkt_tmp.SetSize(); ++r_count; CAssert.AreEqual(pkt_tmp.Size, pkt_orig.Size); CAssert.AreEqual(pkt_tmp.Buf, pkt_orig.Buf); } CAssert.AreEqual(r_count, w_count); CAssert.AreEqual(0, rw_buf.GetCanReadSize()); CAssert.AreEqual(ReadWriteBuffer.BUFFER_MAX_SIZE, rw_buf.GetCanWriteSize()); rw_buf.Release(); //CAssert.IsNull(rw_buf.Buffer); }
public bool DoCastSelfSpell(short spellID) { if (spellID < 0) return false; if (!Initialized || !m_client.ConnectedAndInitialized) return false; Packet pkt = new Packet(PacketFamily.Spell, PacketAction.TargetSelf); pkt.AddChar(1); //target type pkt.AddShort(spellID); pkt.AddInt(DateTime.Now.ToEOTimeStamp()); return m_client.SendPacket(pkt); }
/// <summary> /// Select one of the 3 characters. Sends a WELCOME_REQUEST packet. /// </summary> /// <param name="id">id of the selected character</param> /// <param name="data">returned data from the server</param> /// <returns>true on successful transfer, false otherwise</returns> public bool SelectCharacter(int id, out WelcomeRequestData data) { data = null; if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet builder = new Packet(PacketFamily.Welcome, PacketAction.Request); builder.AddInt(id); if (!m_client.SendPacket(builder)) return false; if (!m_welcome_responseEvent.WaitOne(Constants.ResponseTimeout)) return false; data = m_welcome_requestData; return true; }
private void Test_Share_Net_Packet_Custom() { byte[] buffer = new byte[Packet.DEFAULT_PACKET_BUF_SIZE]; Packet pkt = new Packet(buffer); pkt.Initialize(); CAssert.AreEqual(buffer, pkt.Buf); CAssert.AreEqual((int)pkt.Size, Packet.PACKET_HEAD_LENGTH); pkt.SetPacketID(Protocol.CLI_GW_ENTER_TEST); CAssert.AreEqual(pkt.GetPacketID(), Protocol.CLI_GW_ENTER_TEST); int int_test = 10000001; uint uint_test = 88776655; short short_test = 10001; ushort ushort_test = 65530; long long_test = 9223372036854775805; double double_test = 123456789.987654321; float float_test = 12345.12345f; string str_test = "This is a testing string."; pkt.AddInt(int_test); pkt.AddUint(uint_test); pkt.AddShort(short_test); pkt.AddUshort(ushort_test); pkt.AddLong(long_test); pkt.AddDouble(double_test); pkt.AddFloat(float_test); pkt.AddString(str_test); int total_size = Packet.PACKET_HEAD_LENGTH + sizeof(int) + sizeof(uint) + sizeof(short) + sizeof(ushort) + sizeof(long) + sizeof(double) + sizeof(float) + sizeof(short) + str_test.Length; CAssert.AreEqual(total_size, (int)pkt.Size); pkt.ResetBufferIndex(); int int_get = pkt.GetInt(); CAssert.AreEqual(int_get, int_test); uint uint_get = pkt.GetUint(); CAssert.AreEqual(uint_get, uint_test); short short_get = pkt.GetShort(); CAssert.AreEqual(short_get, short_test); ushort ushort_get = pkt.GetUshort(); CAssert.AreEqual(ushort_get, ushort_test); long long_get = pkt.GetLong(); CAssert.AreEqual(long_get, long_test); double double_get = pkt.GetDouble(); CAssert.AreEqual(double_get, double_test); float float_get = pkt.GetFloat(); CAssert.AreEqual(float_get, float_test); string str_get = pkt.GetString(); CAssert.AreEqual(str_get, str_test); pkt.Release(); CAssert.IsNull(pkt.Buf); buffer = null; }
public bool CharacterRemove(int id, out CharacterRenderData[] data) { data = null; if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet builder = new Packet(PacketFamily.Character, PacketAction.Remove); builder.AddShort(255); builder.AddInt(id); if (!m_client.SendPacket(builder) || !m_character_responseEvent.WaitOne(Constants.ResponseTimeout)) return false; if (m_character_reply != CharacterReply.Deleted || m_character_data == null) return false; data = m_character_data; return true; }
public bool JunkItem(short id, int amount) { if (!m_client.ConnectedAndInitialized || !Initialized) return false; Packet pkt = new Packet(PacketFamily.Item, PacketAction.Junk); pkt.AddShort(id); pkt.AddInt(amount); return m_client.SendPacket(pkt); }
public static void HandleRemove(Packet packet, IClient client, bool fromQueue) { /*short deleteId = */packet.GetShort(); int id = packet.GetShort(); if (id < 0 || id > client.Account.Characters.Count) throw new ArgumentOutOfRangeException("Login character ID out of range"); Character deleteMe = client.Account.Characters[id]; client.Account.Characters.Remove(deleteMe); deleteMe.Delete(); client.Account.Store(); client.Server.Database.Commit(); Packet reply = new Packet(PacketFamily.Character, PacketAction.Reply); reply.AddShort((short)CharacterReply.Deleted); reply.AddChar((byte)client.Account.Characters.Count); reply.AddByte(1); // TODO: What is this? reply.AddBreak(); // TODO: Some kind of character list packet builder int i = 0; foreach (Character character in client.Account.Characters) { reply.AddBreakString(character.Name); reply.AddInt(i++); reply.AddChar(character.Level); reply.AddChar((byte)character.Gender); reply.AddChar(character.HairStyle); reply.AddChar(character.HairColor); reply.AddChar((byte)character.Skin); reply.AddChar((byte)character.Admin); reply.AddShort((short)(character.Boots != null ? character.Boots.Data.special1 : 0)); reply.AddShort((short)(character.Armor != null ? character.Armor.Data.special1 : 0)); reply.AddShort((short)(character.Hat != null ? character.Hat.Data.special1 : 0)); reply.AddShort((short)(character.Shield != null ? character.Shield.Data.special1 : 0)); reply.AddShort((short)(character.Weapon != null ? character.Weapon.Data.special1 : 0)); reply.AddBreak(); } client.Send(reply); }