public PacketAPI(EOClient client) { if (!client.Connected) { throw new ArgumentException("The client must be connected to the server in order to construct the API!"); } m_client = client; //each of these sets up members of the partial PacketAPI class relevant to a particular packet family _createBankMembers(); _createChestMembers(); _createEffectMembers(); _createEmoteMembers(); _createInitMembers(); _createItemMembers(); _createLockerMembers(); _createMessageMembers(); _createMusicMembers(); _createPaperdollMembers(); _createPartyMembers(); _createNPCMembers(); _createQuestMembers(); _createRecoverMembers(); _createShopMembers(); _createSpellMembers(); _createStatSkillMembers(); _createTradeMembers(); }
public EOBot(int index, string host, int port) { m_index = index + 1; m_client = new EOClient(); if (!m_client.ConnectToServer(host, port)) { throw new ArgumentException(); } m_api = new PacketAPI(m_client); InitData data; if (!m_api.Initialize(0, 0, 28, EOLib.Win32.GetHDDSerial(), out data)) { throw new TimeoutException(); } m_client.SetInitData(data); if (!m_api.ConfirmInit(data.emulti_e, data.emulti_d, data.clientID)) { throw new TimeoutException(); } if (!m_api.Initialized || !m_client.ConnectedAndInitialized || data.ServerResponse != InitReply.INIT_OK) { throw new InvalidOperationException(); } m_terminationEvent = new AutoResetEvent(false); }
public static bool BankOpen(short npcIndex) { EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized || npcIndex < 0) { return(false); } Packet pkt = new Packet(PacketFamily.Bank, PacketAction.Open); pkt.AddShort(npcIndex); return(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> /// Sends SHOP_OPEN to server, opening a "Shop" dialog /// </summary> /// <returns>false on connection problems, true otherwise</returns> public static bool RequestShop(short NpcID) { EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized) { return(false); } Packet pkt = new Packet(PacketFamily.Shop, PacketAction.Open); pkt.AddShort(NpcID); return(client.SendPacket(pkt)); }
/// <summary> /// Craft an item with a shopkeeper /// </summary> public static bool CraftItem(short ItemID) { EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized) { return(false); } Packet pkt = new Packet(PacketFamily.Shop, PacketAction.Create); pkt.AddShort(ItemID); return(client.SendPacket(pkt)); }
public static bool AddStatPoint(short statID) { EOClient client = (EOClient)World.Instance.Client; if (client == null || !client.ConnectedAndInitialized) { return(false); } Packet pkt = new Packet(PacketFamily.StatSkill, PacketAction.Add); pkt.AddChar((byte)TrainType.Stat); pkt.AddShort(statID); return(client.SendPacket(pkt)); }
/// <summary> /// sends all different types of Talk packets to server based on which chat type we're doing /// </summary> /// <param name="chatType">Which type of chat message is being sent</param> /// <param name="message">The message being sent</param> /// <param name="character">The character (required for TalkType.PM)</param> /// <returns></returns> public static bool Speak(TalkType chatType, string message, string character = null) { EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized) { return(false); } Packet builder; switch (chatType) { case TalkType.Local: builder = new Packet(PacketFamily.Talk, PacketAction.Report); break; case TalkType.PM: builder = new Packet(PacketFamily.Talk, PacketAction.Tell); if (string.IsNullOrWhiteSpace(character)) { return(false); } builder.AddBreakString(character); break; case TalkType.Global: builder = new Packet(PacketFamily.Talk, PacketAction.Message); break; case TalkType.Guild: builder = new Packet(PacketFamily.Talk, PacketAction.Request); break; case TalkType.Party: builder = new Packet(PacketFamily.Talk, PacketAction.Open); break; default: throw new NotImplementedException(); } builder.AddString(message); return(client.SendPacket(builder)); }
public static bool ReportEmote(EndlessClient.Emote emote) { //trade/level up happen differently if (emote == EndlessClient.Emote.Trade || emote == EndlessClient.Emote.LevelUp) { return(false); //signal error client-side } EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized) { return(false); } Packet pkt = new Packet(PacketFamily.Emote, PacketAction.Report); pkt.AddChar((byte)emote); return(client.SendPacket(pkt)); }
/// <summary> /// Opens a locker at X/Y coordinates /// </summary> public static bool OpenLocker(byte x, byte y) { if (EOLockerDialog.Instance == null) { return(true); } EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized) { return(false); } Packet pkt = new Packet(PacketFamily.Locker, PacketAction.Open); pkt.AddChar(x); pkt.AddChar(y); return(client.SendPacket(pkt)); }
/// <summary> /// Withdraw an item from your private locker /// </summary> public static bool TakeItem(short id) { if (EOLockerDialog.Instance == null) { return(true); } EOClient client = (EOClient)World.Instance.Client; if (!client.ConnectedAndInitialized) { return(false); } Packet pkt = new Packet(PacketFamily.Locker, PacketAction.Take); pkt.AddChar(EOLockerDialog.Instance.X); pkt.AddChar(EOLockerDialog.Instance.Y); pkt.AddShort(id); return(client.SendPacket(pkt)); }
public void Dispose() { if (m_client != null) { m_client.Dispose(); m_client = null; } if (m_api != null) { m_api.Dispose(); m_api = null; } if (m_terminationEvent != null) { m_terminationEvent.Dispose(); m_terminationEvent = null; } if (s_partyEvent != null) { s_partyEvent.Dispose(); s_partyEvent = null; } }
//all bots are going to want to do the init handshake with the server public virtual void Initialize() { _client = new EOClient(CreatePacketProcessorActions()); if (!_client.ConnectToServer(_host, _port)) { throw new ArgumentException($"Bot {_index}: Unable to connect to server! Host={_host} Port={_port}"); } _api = new PacketAPI(_client); //todo: adapt to new networking architecture //InitData data; //if (!_api.Initialize(0, 0, 28, new HDSerialNumberService().GetHDSerialNumber(), out data)) // throw new TimeoutException(string.Format("Bot {0}: Failed initialization handshake with server!", _index)); //_client.SetInitData(data); //if (!_api.ConfirmInit(data.emulti_e, data.emulti_d, data.clientID)) // throw new TimeoutException(string.Format("Bot {0}: Failed initialization handshake with server!", _index)); //if (!_api.Initialized || !_client.ConnectedAndInitialized || data.ServerResponse != InitReply.INIT_OK) // throw new InvalidOperationException(string.Format("Bot {0}: Invalid response from server or connection failed! Must receive an OK reply.", _index)); //_initialized = true; }
protected virtual void Dispose(bool disposing) { if (disposing) { Terminate(); if (_workerThread != null) { _workerThread.Join(); } if (_client != null) { _client.Dispose(); _client = null; } if (_api != null) { _api.Dispose(); _api = null; } if (_terminationEvent != null) { _terminationEvent.Dispose(); _terminationEvent = null; } if (_cancelTokenSource != null) { _cancelTokenSource.Dispose(); _cancelTokenSource = null; } } }