/// <summary> /// Logs your character into the game /// </summary> /// <param name="nIndex">Selected Character Index</param> /// <returns></returns> public void CreateLoginPacket(int nIndex) { try { PacketOut oLogin = new PacketOut(1); oLogin.FillString(m_iGameCharacterList.nList[nIndex - 1].szName, 61); oLogin.WriteByte((byte)m_iGameCharacterList.nList[nIndex - 1].nRace); oLogin.FinalizeLengthAndChecksum(); m_dHandles.Add(0, m_iGameCharacterList.nList[nIndex - 1].szName); m_cGameConnection.SendTCP(oLogin); XLog.AddMessage("", "", -5); // Clear box } catch (Exception e) { XLog.Log("Error while logging in to the server: {0}", e.Message); } }
/// <summary> /// The function which is used to proceed an incoming packet to the active TCPConnection /// </summary> /// <param name="con">The connection which received the packet</param> /// <param name="buf">byte[] array containing the raw content of the received packet</param> /// <param name="start">Start of the content in buf, usually 0</param> /// <param name="size">Size of the packet (minus start)</param> /// <returns>PacketIn -> Converted raw package to MemoryStream based PacketIn</returns> public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size) { PacketIn packet = new PacketIn(buf, start, size); switch (packet.ID) { case 0: // ResultMsg var res = new AUTH_PACKETS.RESULT(packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32()); if (res.nRequestPacket == 2005) { if (res.nResult == 0) { con.SendTCP(CreateReportPacket()); con.SendTCP(CreateCharacterListPacket()); } else { con.Disconnect(); XLog.Log("Can't connect to game server. Result: {0} - disconnecting...", res.nResult); } } break; case 2004: // CharacterList m_iGameCharacterList = new GAME_PACKETS.CharacterList(packet); XLog.Log("Character selection. Please use /use ID to select a character."); for (int i = 0; i < m_iGameCharacterList.nCount; i++) { XLog.Log("-> Character {0}: {1}", i + 1, m_iGameCharacterList.nList[i].szName); } break; case 21: // ChatLocal var tmp = packet.ReadInt32(); string szSource = m_dHandles.ContainsKey(tmp) ? m_dHandles[tmp] : "INVALID-HANDLE:" + tmp; int nLen = packet.ReadByte(); int nType = packet.ReadByte(); XLog.AddMessage(szSource, packet.ReadString(nLen), nType); break; case 22: // ChatMsg var pMessage = new GAME_PACKETS.ChatMessage(packet); XLog.AddMessage(pMessage.szName, pMessage.szMessage, pMessage.nType); break; case 3: // Enter: Handle -> Name, small hack so we don't have to read the full packet (which is f*****g large) if (packet.ReadByte() == 0) { int key = packet.ReadInt32(); if (m_dHandles.ContainsKey(key)) { m_dHandles.Remove(key); } packet.Seek(77, System.IO.SeekOrigin.Current); string value = packet.ReadString(19); m_dHandles.Add(key, value); } break; case 507: // Property: Own Name -> Handle if (m_dHandles.ContainsKey(0) && m_tPingThread == null) { var szName = m_dHandles[0]; m_dHandles.Remove(0); m_dHandles.Add(packet.ReadInt32(), szName); m_tPingThread = new System.Threading.Thread(new System.Threading.ThreadStart(SendPingPacket)); m_tPingThread.IsBackground = true; m_tPingThread.Start(); } break; default: break; } return(packet); }