private void listener() { frmMain.authentication_response authenticationResponse = new frmMain.authentication_response(); string[] strArrays; byte[] numArray; TcpClient tcpClient = new TcpClient(); this.listener_handler.Start(); while (true) { try { if (this.listener_running) { if (this.listener_handler.Pending()) { tcpClient = this.listener_handler.AcceptTcpClient(); tcpClient.ReceiveTimeout = 7000; } if (tcpClient.Connected) { log("client connected!\n", true); string str = tcpClient.Client.RemoteEndPoint.ToString().Split(":".ToCharArray())[0]; byte[] numArray1 = new byte[49]; if (tcpClient.GetStream().Read(numArray1, 0, 49) > 0) { authentication_request authenticationRequest = b2s <authentication_request>(numArray1); string str1 = ""; byte[] cPUKey = authenticationRequest.CPUKey; for (int i = 0; i < (int)cPUKey.Length; i++) { byte num = cPUKey[i]; str1 = string.Concat(str1, num.ToString("X2")); } ClientHelper.KeyResponse keyResponse = ClientHelper.CheckCPUKey(str1); if (keyResponse == ClientHelper.KeyResponse.Banned) { strArrays = new string[] { "Banned user (", str1, ", ", str, ") connected, rejecting connection.\n" }; this.log(string.Concat(strArrays), true); tcpClient.Close(); } else if (keyResponse == ClientHelper.KeyResponse.Registered) { string text = ""; bool flag = false; int num1 = 0; ClientHelper.TierType tier = ClientHelper.TierType.Client; string text1 = ""; int num2 = 0; while (num2 < listViewEx1.Items.Count) { if (!(listViewEx1.Items[num2].SubItems[2].Text == str1)) { num2++; } else { text = listViewEx1.Items[num2].SubItems[3].Text; flag = DateTime.Compare(DateTime.Parse(text), DateTime.Now) == 1; num1 = int.Parse(listViewEx1.Items[num2].SubItems[0].Text); tier = ClientHelper.GetTier(num2); text1 = listViewEx1.Items[num2].SubItems[1].Text; listViewEx1.Items[num2].SubItems[4].Text = str; ClientHelper.EditIP(num2, str); break; } } if (!(XEXHelper.CheckXEXVersion(authenticationRequest.XEXVersion) ? false : ClientHelper.GetTier(num1) != ClientHelper.TierType.Admin)) { log(string.Concat(text1, " has connected ", (flag ? "and has time" : "but has no time"), ", sending authentication notice now.\n"), true); SHA1 sHA1 = SHA1.Create(); numArray = new byte[] { Convert.ToByte(tier) }; sHA1.TransformFinalBlock(numArray, 0, 1); byte[] hash = sHA1.Hash; authenticationResponse.Tier = (byte)tier; byte[] numArray2 = new byte[16]; numArray = numArray2; authenticationResponse.PacketChecksum = numArray2; Array.Copy(hash, numArray, 16); NetworkStream stream = tcpClient.GetStream(); numArray = new byte[] { 15 }; stream.Write(numArray, 0, 1); if (!flag) { tcpClient.GetStream().Write(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 0, 17); } else { tcpClient.GetStream().Write(this.s2b <frmMain.authentication_response>(authenticationResponse), 0, 17); } tcpClient.Close(); } else if (!flag) { log(string.Concat(text1, " has connected with an outdated .xex but doesn't have any time left, sending authentication notice now.\n"), true); NetworkStream stream1 = tcpClient.GetStream(); numArray = new byte[] { 15 }; stream1.Write(numArray, 0, 1); tcpClient.GetStream().Write(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 0, 17); tcpClient.Close(); } else { log(string.Concat(text1, " has connected but has an outdated .xex, sending update now.\n"), true); NetworkStream networkStream1 = tcpClient.GetStream(); numArray = new byte[] { 63 }; networkStream1.Write(numArray, 0, 1); byte[] numArray3 = File.ReadAllBytes(XEXHelper.GetXEXName()); byte[] bytes = BitConverter.GetBytes((int)numArray3.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(bytes); } tcpClient.GetStream().Write(bytes, 0, 4); tcpClient.GetStream().Write(numArray3, 0, (int)numArray3.Length); tcpClient.Close(); } } else if (!XEXHelper.CheckXEXChecksum(authenticationRequest.XEXChecksum)) { strArrays = new string[] { "Unknown client (", str1, ", ", str, ") has connected with a modified .xex, banning now.\n" }; log(string.Concat(strArrays), true); ClientHelper.BanCPUKey(str1); NetworkStream stream2 = tcpClient.GetStream(); numArray = new byte[] { 15 }; stream2.Write(numArray, 0, 1); tcpClient.GetStream().Write(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 0, 17); tcpClient.Close(); } else { strArrays = new string[] { "Unknown client (", str1, ", ", str, ") has connected", null, null }; strArrays[5] = (XEXHelper.CheckXEXVersion(authenticationRequest.XEXVersion) ? ", " : " with an outdated .xex, "); strArrays[6] = "sending authentication notice now.\n"; log(string.Concat(strArrays), true); NetworkStream networkStream2 = tcpClient.GetStream(); numArray = new byte[] { 15 }; networkStream2.Write(numArray, 0, 1); tcpClient.GetStream().Write(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }, 0, 17); tcpClient.Close(); } } } } } catch (Exception exmsg) { log("Major server crash caught, resuming work.\n", true); log("exception: \n", true); log(exmsg.Message); } } }