// TODO: send in other thread private void SendCommand(string GET) { try { string ping = new System.Random().Next() + "|" + Guid() + "|" + DateTime.Now.ToShortTimeString() + "|" + new System.Random().Next(); string checkGET = (uint)Header.ID + "=" + RustAPI.GetUserID() + "&" + (uint)Header.Guid + "=" + Guid() + "&" + (uint)Header.Ping + "=" + ping + GET; #if !DEBUG string aesKey = ""; using (Aes aes = Aes.Create()) { checkGET = AES.Encrypt(checkGET, aes.Key, aes.IV); aesKey = Convert.ToBase64String(aes.Key) + "|" + Convert.ToBase64String(aes.IV); } aesKey = Rijndael.Encrypt(aesKey, Rijndael.pubKey); string request = aesKey + "|" + checkGET; checkGET = Convert.ToBase64String(Encoding.ASCII.GetBytes(request)); #else Log("[SendRequest] " + checkGET); #endif string strHost = serverHost.Split(':')[0]; IPAddress host = null; IPAddress.TryParse(strHost, out host); if (host == null) { host = Dns.GetHostEntry(strHost).AddressList[0]; } var client = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client.Connect(host, anticheatPort); byte[] byteData = Encoding.ASCII.GetBytes(checkGET); client.Send(byteData, 0, byteData.Length, 0); client.Close(); #if DEBUG Log("Send event. Request length: " + byteData.Length); #endif } catch (Exception ex) { ErrorLog(ex); } }
private void AnticheatLoop() { try { #if DEBUG Log("Anticheat loop started"); #endif #if DEMO int screenshotCount = 0; #endif #if DEBUG Log("Adding [LateUpdate] for screenshots"); #endif RustAPI.AddLateUpdate(RustAPI.GetPlayer(), 0, ScreenHook); #if DEBUG Log("[LateUpdate] added"); #endif int secondCounter = 0; while (true) { if (RustAPI.IsUserConnected() && RustAPI.GetUserID() != 0) { try { serverHost = string.Format("{0}:{1}", RustAPI.GetServerAddress(), RustAPI.GetServerPort()); } catch (Exception ex) { Log("[NoServerInLoop] " + ex.ToString()); } } else { Thread.Sleep(1000); continue; } try { #if DEMO if (screenshotCount == 3) { RustAPI.Disconnect("Trial: 3 screenshots limit"); } #endif #if !DEBUG if (secondCounter % 90 == 0 || screenArray != null) // screenshot every ~1.5 min #else if (secondCounter % 60 == 0 || screenArray != null) // for debugging send more often #endif { SendScreenshot(); #if DEMO if (screenArray != null) { screenshotCount++; } #endif } if (secondCounter % 10 == 0) // send ping { SendPing(); } if (secondCounter % 300 == 0) // send tasklist every ~5 min { SendTasklist(); } secondCounter++; Thread.Sleep(1000); } catch (Exception ex) { ErrorLog(ex); SendPing(); // try to ping anyway } } } catch (Exception ex) { Log("Failed to init anticheat!"); ErrorLog(ex); } }