protected override void ProcessAccept(GamespyUdpPacket Packet)
{
// If we dont reply, we must manually release the EventArgs back to the pool
bool replied = false;
try
{
// Decrypt message
IPEndPoint remote = (IPEndPoint)Packet.AsyncEventArgs.RemoteEndPoint;
string decrypted = Xor(Encoding.UTF8.GetString(Packet.BytesRecieved)).Trim('\\');
// Ignore keep alive pings
if (!decrypted.StartsWith("ka"))
{
Dictionary<string, string> recv = ConvertToKeyValue(decrypted.Split('\\'));
if (recv.ContainsKey("auth") && recv.ContainsKey("resp") && recv.ContainsKey("skey"))
{
// Normally you would check the CD key database for the CD key MD5, but we arent Gamespy, we dont care
DebugLog.Write("CDKey Check Requested from: {0}:{1}", remote.Address, remote.Port);
string reply = String.Format(@"\uok\\cd\{0}\skey\{1}", recv["resp"].Substring(0, 32), recv["skey"]);
// Set new packet contents, and send a reply
Packet.SetBufferContents(Encoding.UTF8.GetBytes(Xor(reply)));
base.ReplyAsync(Packet);
replied = true;
}
else if (recv.ContainsKey("disc"))
{
// Handle, User disconnected from server
}
else
{
DebugLog.Write("Incomplete or Invalid CDKey Packet Received: " + decrypted);
}
}
}
catch (Exception E)
{
Program.ErrorLog.Write("ERROR: [MasterServer.CDKeySocket_OnDataReceived] " + E.Message);
}
finally
{
// Release so that we can pool the EventArgs to be used on another connection
if (!replied)
base.Release(Packet.AsyncEventArgs);
}
}