private void ReadPaths() { string allpaths = File.ReadAllText("targetpath.txt"); string[] paths = allpaths.Split(';'); WowAutomater.SetPathCoordinates(Program.ExtractCommaDelimitedDoubles(paths[0]), Program.ExtractCommaDelimitedDoubles(paths[1])); allpaths = File.ReadAllText("revivepath.txt"); paths = allpaths.Split(';'); WowAutomater.SetReviveCoordinates(Program.ExtractCommaDelimitedDoubles(paths[0]), Program.ExtractCommaDelimitedDoubles(paths[1])); allpaths = File.ReadAllText("shoppath.txt"); paths = allpaths.Split(';'); WowAutomater.SetShopCoordinates(Program.ExtractCommaDelimitedDoubles(paths[0]), Program.ExtractCommaDelimitedDoubles(paths[1])); allpaths = File.ReadAllText("walkpath.txt"); paths = allpaths.Split(';'); WowAutomater.SetWalkCoordinates(Program.ExtractCommaDelimitedDoubles(paths[0]), Program.ExtractCommaDelimitedDoubles(paths[1])); }
public MainUI() { InitializeComponent(); if (File.Exists("Config.ftw")) { ReadConfigString(File.ReadAllText("Config.ftw")); } if (!File.Exists("targetpath.txt")) { File.WriteAllText("targetpath.txt", ";"); } if (!File.Exists("revivepath.txt")) { File.WriteAllText("revivepath.txt", ";"); } if (!File.Exists("shoppath.txt")) { File.WriteAllText("shoppath.txt", ";"); } if (!File.Exists("walkpath.txt")) { File.WriteAllText("walkpath.txt", ";"); } ReadPaths(); RecordWowPath.RecordPathEvent += Automater_RecordPathEvent; RecordWowPath.StopEvent += Automater_StopEvent; PathTypeDropDown.SelectedIndex = 0; ModeDropDown.SelectedIndex = 0; m_ApiDataUpdateTimer.Interval = 50; m_ApiDataUpdateTimer.Tick += ApiDataUpdateTimer_Tick; m_ApiDataUpdateTimer.Enabled = true; WowAutomater.AutomaterStatusEvent += AutomaterStatusEvent; WowApi.UpdateEvent += WowApi_UpdateEvent; Task.Run(() => { try { WowAutomater.Run(); } catch (Exception err) { MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
private void MainUI_FormClosing(object sender, FormClosingEventArgs e) { RecordWowPath.RecordPathEvent -= Automater_RecordPathEvent; RecordWowPath.StopEvent -= Automater_StopEvent; m_ApiDataUpdateTimer.Enabled = false; m_ApiDataUpdateTimer.Tick -= ApiDataUpdateTimer_Tick; WowAutomater.AutomaterStatusEvent -= AutomaterStatusEvent; WowAutomater.Stop(); }
private void Stop(NetworkStream ns) { string contentString = "Stopped"; WowAutomater.RemoteStop(); string responseString = "HTTP/1.1 200 OK\r\n"; responseString += "Content-Length: " + contentString.Length.ToString() + "\r\n"; responseString += "Content-Type: text/html\r\n"; responseString += "Connection: Closed\r\n\r\n"; responseString += contentString; ns.Write(ASCIIEncoding.ASCII.GetBytes(responseString), 0, responseString.Length); }
private void Relay(NetworkStream ns, string rawRelayString) { string relayString = rawRelayString.Substring(6, rawRelayString.Length - 6); relayString = relayString.Replace("%20", " "); WowAutomater.SetRelayString(relayString); string contentString = "Sent: " + relayString; string responseString = "HTTP/1.1 200 OK\r\n"; responseString += "Content-Length: " + contentString.Length.ToString() + "\r\n"; responseString += "Content-Type: text/html\r\n"; responseString += "Connection: Closed\r\n\r\n"; responseString += contentString; ns.Write(ASCIIEncoding.ASCII.GetBytes(responseString), 0, responseString.Length); }
private void ConnectToRemote(string host, string user) { byte[] loginBytes = new byte[LOGIN_LENGTH]; loginBytes[0] = LOGIN_BYTE_1; loginBytes[1] = LOGIN_BYTE_2; Array.Copy(ASCIIEncoding.ASCII.GetBytes(user), 0, loginBytes, 2, user.Length); try { using (TcpClient tcpClient = new TcpClient(host, PORT)) { tcpClient.NoDelay = true; using (NetworkStream ns = tcpClient.GetStream()) { ns.Write(loginBytes, 0, loginBytes.Length); byte[] dataBuffer = new byte[READ_BUFFER_LENGTH]; while (true) { while (tcpClient.Available == 0 && !m_StopRemote && tcpClient.Connected) { if (tcpClient.Client.Poll(0, SelectMode.SelectRead)) { byte[] buff = new byte[1]; if (tcpClient.Client.Receive(buff, SocketFlags.Peek) == 0) { m_StopRemote = true; } } System.Threading.Thread.Sleep(10); } if (m_StopRemote || !tcpClient.Connected) { break; } byte command = (byte)ns.ReadByte(); switch (command) { case BAD_LOGIN_BYTE: { throw new Exception("User not found"); } case LOGIN_BYTE: { ns.WriteByte(LOGIN_BYTE); SetRemoteWebInterfaceButtonStyle(true); break; } case START_BYTE: { ns.WriteByte(START_BYTE); WowAutomater.RemoteStart(); break; } case STOP_BYTE: { ns.WriteByte(STOP_BYTE); WowAutomater.RemoteStop(); break; } case SCREEN_BYTE: { ns.WriteByte(SCREEN_BYTE); ns.ReadByte(); byte[] jpegBytes = GetScreenJpegBytes(); int jpegSize = jpegBytes.Length; byte[] sizeBytes = BitConverter.GetBytes(jpegSize); ns.Write(sizeBytes, 0, sizeBytes.Length); ns.ReadByte(); ns.Write(jpegBytes, 0, jpegBytes.Length); break; } case RELAY_BYTE: { ns.WriteByte(RELAY_BYTE); int bread = ns.Read(dataBuffer, 0, dataBuffer.Length); byte[] dataRead = new byte[bread]; Array.Copy(dataBuffer, dataRead, bread); string relayString = ASCIIEncoding.ASCII.GetString(dataRead); WowAutomater.SetRelayString(relayString); break; } default: { throw new Exception("BAD COMMAND"); } } } } } } catch (Exception err) { SetRemoteWebInterfaceButtonStyle(false); m_RemoteConnected = false; MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } remotewait.Set(); }