public bool SendModCommandToServer(string command, int issuer, int target, string message) { StringBuilder sb = new StringBuilder(); sb.Append(Base64Encoding.EncodeInt(999, 2)); sb.Append(Base64Encoding.EncodeInt(command.Length, 2)); sb.Append(command); sb.Append(Base64Encoding.EncodeInt(issuer.ToString().Length, 2)); sb.Append(issuer); sb.Append(Base64Encoding.EncodeInt(target.ToString().Length, 2)); sb.Append(target); sb.Append(Base64Encoding.EncodeInt(message.Length, 2)); sb.Append(message); string packet = Base64Encoding.EncodeInt(sb.Length, 3) + sb.ToString(); IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), int.Parse(Settings.ListenPort)); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { server.Connect(ip); } catch { return(false); } byte[] data = new byte[1024]; int receivedDataLength = server.Receive(data); string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); if (stringData == "@@" + Convert.ToChar(1)) { server.Send(Encoding.ASCII.GetBytes(packet)); data = new byte[1024]; receivedDataLength = server.Receive(data); stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); } server.Shutdown(SocketShutdown.Both); server.Close(); if (stringData == "ACK") { return(true); } return(false); }
private void btnB64Encode_Click(object sender, EventArgs e) { try { txtB64Output.Text = Base64Encoding.EncodeInt(int.Parse(txtBase64Input.Text), 2); } catch { MessageBox.Show("Invalid input."); } }