/// <summary> /// Takes a message sent through the Stream and sends back a respose /// </summary> /// <param name="message"></param> protected void ParseRequest(string message) { string[] data = message.Split(new char[] { '\x00' }, StringSplitOptions.RemoveEmptyEntries); string gamename = data[1].ToLowerInvariant(); string validate = data[2].Substring(0, 8); string filter = data[2].Substring(8); string[] fields = data[3].Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); // Fix filter because the filter from BF2 can be messed up, missing spaces and such string fixedFilter = FixFilter(filter); if (String.IsNullOrEmpty(fixedFilter)) { fixedFilter = ""; } // Send the encrypted serverlist to the client byte[] unencryptedServerList = PackServerList(fixedFilter, fields); Stream.SendAsync( Enctypex.Encode( Encoding.UTF8.GetBytes("hW6m9a"), // Battlfield 2 Handoff Key Encoding.UTF8.GetBytes(validate), unencryptedServerList, unencryptedServerList.LongLength ) ); }
public static byte[] DecryptResponseManaged(byte[] data, ClientRequestInfo ps) { Enctypex.Enctypex_data_t encx_data = null; long len = (long)data.Length; var xyz = Encoding.ASCII.GetBytes("y3D28k"); var decoded = Enctypex.enctypex_decoder(ref xyz, ref ps.Validate, ref data, ref len, ref encx_data); return(decoded); }
/// <summary> /// Called when a connection comes in on the CDKey server /// known messages /// \ka\ = keep alive from the game server every 20s, we don't care about this /// \auth\ ... = authenticate cd key, this is what we care about /// \disc\ ... = disconnect cd key, because there's checks if the cd key is in use, which we don't care about really, but we could if we wanted to /// </summary> protected override void OnReceived(EndPoint endPoint, byte[] message) { string decrypted = Enctypex.XorEncoding(message, 0); decrypted.Replace(@"\r\n", "").Replace("\0", ""); string[] recieved = decrypted.TrimStart('\\').Split('\\'); Dictionary <string, string> recv = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); CommandSwitcher.Switch(this, endPoint, recv); }
/// <summary> /// /// </summary> /// <param name="str">MD5cdkey string</param> /// <returns></returns> public static void IsCDKeyValid(CDKeyServer server, UDPPacket packet, Dictionary <string, string> recv) { if (DBQuery.IsCDKeyValidate(recv["skey"])) { string reply = string.Format(@"\uok\\cd\{0}\skey\{1}", recv["resp"].Substring(0, 32), recv["skey"]); server.Send(packet, Enctypex.XorEncoding(reply, 0)); } else { LogWriter.Log.Write(LogLevel.Debug, "Incomplete or Invalid CDKey Packet Received: {0}", recv); //TODO cdkey invalid response } }
/// <summary> /// Called when a connection comes in on the CDKey server /// known messages /// \ka\ = keep alive from the game server every 20s, we don't care about this /// \auth\ ... = authenticate cd key, this is what we care about /// \disc\ ... = disconnect cd key, because there's checks if the cd key is in use, which we don't care about really, but we could if we wanted to /// </summary> protected override void ProcessAccept(UDPPacket packet) { // If we dont reply, we must manually release the EventArgs back to the pool Replied = false; try { // Decrypt message IPEndPoint remote = (IPEndPoint)packet.AsyncEventArgs.RemoteEndPoint; string decrypted = Enctypex.XorEncoding(packet.BytesRecieved, 0).Trim('\\'); string[] recieved = decrypted.TrimStart('\\').Split('\\'); Dictionary <string, string> recv = GameSpyUtils.ConvertGPResponseToKeyValue(recieved); switch (recieved[0]) { //keep client alive request, we skip this case "ka": case "auth": case "resp": case "skey": CDKeyHandler.IsCDKeyValid(this, packet, recv); break; case "disc": CDKeyHandler.DisconnectRequest(packet, recv); break; default: CDKeyHandler.InvalidCDKeyRequest(this, packet, recv); break; } } catch (Exception e) { LogWriter.Log.WriteException(e); } finally { // Release so that we can pool the EventArgs to be used on another connection if (!Replied) { Release(packet.AsyncEventArgs); } } }
/// <summary> /// Takes a message sent through the Stream and sends back a respose /// </summary> /// <param name="message"></param> public static void ParseRequest(SBSession session, string message) { string[] data = message.Split(new char[] { '\x00' }, StringSplitOptions.RemoveEmptyEntries); string gamename = data[1].ToLowerInvariant(); string validate = data[2].Substring(0, 8); string filter = FixFilter(data[2].Substring(8)); string[] fields = data[3].Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); // Send the encrypted serverlist to the client byte[] unencryptedServerList = PackServerList(session, filter, fields); string sendingBuffer = Encoding.UTF8.GetString(Enctypex.Encode( Encoding.UTF8.GetBytes("hW6m9a"), // Battlfield 2 Handoff Key Encoding.UTF8.GetBytes(validate), unencryptedServerList, unencryptedServerList.LongLength) ); session.SendAsync(sendingBuffer); }
/// <summary> /// Encrypt and Decrypt using XOR with type3 method /// </summary> /// <param name="msg"></param> /// <returns></returns> public static string GstatsXOR(string msg) { return(Enctypex.XorEncoding(msg, Enctypex.XorEncodingType.Type1)); }
public void Send(string sendingBuffer) { sendingBuffer = Enctypex.XorEncoding(sendingBuffer, 1); Stream.SendAsync(sendingBuffer); }