public void StartListening() { R = RowacCore.R; R.Log("[Listener] Starting TCP listener..."); TcpListener listener = new TcpListener(IPAddress.Any, 28165); listener.Start(); while (true) { try { var client = listener.AcceptSocket(); #if DEBUG R.Log("[Listener] Connection accepted."); #endif var childSocketThread = new Thread(() => { byte[] data = new byte[1048576]; // for screenshots and tasklists int size = 0; while (client.Available != 0) size += client.Receive(data, size, 256, SocketFlags.None); // TODO: increase reading rate from 256? client.Close(); string request = Encoding.ASCII.GetString(data, 0, size); #if DEBUG R.Log(string.Format("Received [{0}]: {1}", size, request)); #endif ParseRequest(request); }); childSocketThread.Start(); } catch (Exception ex) { R.LogEx("ListenerLoop", ex); } } }
// TODO: fix id parsing // TODO: use guid private void ParseRequest(string data) { #if !DEBUG data = Encoding.ASCII.GetString(Convert.FromBase64String(data)); string[] split = data.Split('|'); // 0 - AES; 1 - data string AESData = RSA.Decrypt(split[0], RSA.privKey); string key = AESData.Split('|')[0]; string iv = AESData.Split('|')[1]; data = split[1]; // encryped client data data = AES.Decrypt(data, key, iv); #endif string[] commands = data.Split('&'); // list of "header=arg" ulong ID = 0; string GUID = ""; foreach (string command in commands) { try { #if DEBUG R.Log(command); #endif string[] segment = command.Split(new char[] { '=' }, 2); if (segment.Length != 2) // header and argument { continue; } Header header = (Header)(int.Parse(segment[0])); string argument = segment[1]; switch (header) { case Header.ID: ID = ulong.Parse(argument); break; case Header.Ping: ParsePing(argument, ID); break; case Header.Guid: GUID = ParseGuid(argument, ID); break; case Header.Screenshot: ParseScreenshot(argument, ID); break; case Header.Tasklist: ParseTasklist(argument, ID); break; default: R.Log(string.Format("[Header] Not valid header: {0}. Data: {1}", header, argument)); break; } } catch (Exception ex) { R.LogEx("ParseRequest", string.Format("\"{0}\"; {1}", command, ex.ToString())); } } }
internal static void Tests() { RLog rlog = new RLog("rlogTests", ""); try { RLog log = new RLog("[Test1]", ""); log.Log("test1"); Console.WriteLine("==="); log = new RLog("[><Test2.!?:|]", ""); log.Log("test2"); Console.WriteLine("==="); log = new RLog("[Test3]", ".\\NoSuchFolder"); log.Log("test3"); Console.WriteLine("==="); log = new RLog("[Test4]", ".\\NoSuchFolder\\Nonono"); log.Log("test4"); Console.WriteLine("==="); log = new RLog("[Test5]", ".\\NoSuchFolder\\No$uch4ol!?:der"); log.Log("test5"); Console.WriteLine("==="); rlog.Log("OK"); } catch (Exception ex) { rlog.Log("FAIL: " + ex.ToString()); } rlog.Log("END"); }
internal void Initialize() { System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest; R.Log("[Anticheat] is loading..."); aconf = RowacCore.LoadConfig <Config>(Path.Combine(RowacCore.rowacFolder, "anticheat.json")); if (aconf != null && aconf.enabled) { takeCoordsTimer = new Timer(aconf.checkInterval * 1000); takeCoordsTimer.Elapsed += takeCoordsEvent; takeCoordsTimer.Start(); R.Log("[Anticheat] loaded!"); } else { R.Log("[Anticheat] disabled! Check your config."); } }
public void StartListening() { R = RowacCore.R; R.Log("[Listener] Starting TCP listener..."); TcpListener listener = new TcpListener(IPAddress.Any, 28165); listener.Start(); while (true) { try { var client = listener.AcceptSocket(); #if DEBUG R.Log("[Listener] Connection accepted."); #endif var childSocketThread = new Thread(() => { byte[] data = new byte[1048576]; // for screenshots and tasklists int size = 0; while (client.Available != 0) { size += client.Receive(data, size, 256, SocketFlags.None); // TODO: increase reading rate from 256? } client.Close(); string request = Encoding.ASCII.GetString(data, 0, size); #if DEBUG R.Log(string.Format("Received [{0}]: {1}", size, request)); #endif ParseRequest(request); }); childSocketThread.Start(); } catch (Exception ex) { R.LogEx("ListenerLoop", ex); } } }
internal static void Init() { try { R.Log("[RowAC] loading..."); if (!Directory.Exists(rowacFolder)) { Directory.CreateDirectory(rowacFolder); } if (!Directory.Exists(screenshotsFolderPath)) { Directory.CreateDirectory(screenshotsFolderPath); } if (!Directory.Exists(taskListsFolderPath)) { Directory.CreateDirectory(taskListsFolderPath); } if (!Directory.Exists(logsFolderPath)) { Directory.CreateDirectory(logsFolderPath); } rconf = LoadConfig <Config>(Path.Combine(RowacCore.rowacFolder, "rowac.json")); if (rconf == null || !rconf.enabled) { R.Log("[RowAC] disabled! Check your config."); return; } AnticheatLocal ACLocal = new AnticheatLocal(); Anticheat = new Thread(ACLocal.Initialize); // server-side Anticheat.Start(); AnticheatRemote = new Thread(AntiCheat); // ping checking AnticheatRemote.Start(); Listener server = new Listener(); ServerListener = new Thread(server.StartListening); // client-side listener ServerListener.Start(); R.Log("[RowAC] loaded! Version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); } catch (Exception ex) { R.LogEx("Init", ex); } }