예제 #1
0
파일: Form1.cs 프로젝트: xbojer/devel_vm
 private void button1_Click(object sender, EventArgs e)
 {
     Network_Broadcast.setTarget("10.11.11." + ipBox.Text);
     Packet p = new Packet();
     p.message = textBox1.Text;
     p.auth = "TestApp";
     switch (comboBox1.Text)
     {
         case "Info":
             p.dataIdentifier = Packet.DataIdentifier.Info;
             break;
         case "Error":
             p.dataIdentifier = Packet.DataIdentifier.Error;
             break;
         case "Kill":
             p.dataIdentifier = Packet.DataIdentifier.Kill;
             break;
         case "Ping":
             p.dataIdentifier = Packet.DataIdentifier.Ping;
             break;
         case "Update":
             p.dataIdentifier = Packet.DataIdentifier.Update;
             break;
         case "Execute":
             p.dataIdentifier = Packet.DataIdentifier.Execute;
             break;
         case "Chat":
             p.dataIdentifier = Packet.DataIdentifier.Chat;
             break;
         case "Reset":
             p.dataIdentifier = Packet.DataIdentifier.Reset;
             break;
         case "Version":
             p.dataIdentifier = Packet.DataIdentifier.Version;
             break;
         default:
             p.dataIdentifier = Packet.DataIdentifier.Null;
             break;
     }
     richTextBox1.Text += "\r\n [SEND:" + Network_Broadcast.getTarget() + "][" + p.dataIdentifier.ToString() + "] " + "TestApp" + ": " + textBox1.Text;
     richTextBox1.SelectionStart = richTextBox1.Text.Length;
     richTextBox1.ScrollToCaret();
     richTextBox1.Refresh();
     Network_Broadcast.send(p);
 }
예제 #2
0
        public Network_listener()
        {
            try
            {
                sock = new UdpClient();
                sock.ExclusiveAddressUse = false;
                sock.EnableBroadcast = true;
                sock.Client.Bind(ep_server);

                UdpState s = new UdpState();
                s.e = ep_server;
                s.u = sock;

                sock.BeginReceive(new AsyncCallback(this.ReceiveCallback), s);
            }
            catch (Exception)
            {
                Packet p = new Packet();
                p.dataIdentifier = Packet.DataIdentifier.Debug;
                p.message = "Listener ERROR. Disabling...";
                Network_Broadcast.send(p);
            }
        }
예제 #3
0
 public static void send(Packet pack)
 {
     pack.auth = Program.identity;
     send(pack.GetDataStream());
 }
예제 #4
0
        public void ReceiveCallback(IAsyncResult ar)
        {
            UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u;
            IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e;

            Packet packet = new Packet(u.EndReceive(ar, ref e));

            onAnyEvent(packet.dataIdentifier.ToString(), packet.auth, packet.message);

            switch (packet.dataIdentifier)
            {
                case Packet.DataIdentifier.Info:
                    onInfoEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Error:
                    onErrorEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Kill:
                    onKillEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Ping:
                    onPingEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Pong:
                    onPongEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Update:
                    onUpdateEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Execute:
                    onExecuteEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Chat:
                    onChatEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Reset:
                    if (packet.message == "root" || packet.message == Program.username)
                    {
                        onResetEvent(packet.auth);
                    }
                    break;
                case Packet.DataIdentifier.Debug:
                    onDebugEvent(packet.auth, packet.message);
                    break;
                case Packet.DataIdentifier.Version:
                    onVersionEvent(packet.auth, packet.message);
                    break;
                default:
                    break;
            }

            u.BeginReceive(new AsyncCallback(this.ReceiveCallback), ((UdpState)(ar.AsyncState)));
        }
예제 #5
0
 public static void send(Packet pack)
 {
     send(pack.GetDataStream());
 }
예제 #6
0
파일: Program.cs 프로젝트: xbojer/devel_vm
        public static void NetworkLog(String msg, String title, int priority)
        {
            string prio;
            switch (priority)
            {
                case 1:
                    prio = "Info";
                    break;
                case 2:
                    prio = "Warning";
                    break;
                case 3:
                    prio = "Error";
                    break;
                default:
                    prio = "-";
                    break;
            }

            Packet p = new Packet();
            p.dataIdentifier = Packet.DataIdentifier.Debug;
            p.message = title + ":" + prio + ":" + msg;
            Network_Broadcast.send(p);
        }
예제 #7
0
파일: Program.cs 프로젝트: xbojer/devel_vm
        static void Main(string[] args)
        {
            if (Environment.GetCommandLineArgs().Contains<string>("/installed"))
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeSettings = false;
                Properties.Settings.Default.Save();
                Application.Restart();
                return;
            }
            mutex = new Mutex(true, "mutex_beta_manager_"+Properties.Settings.Default.vm_name+"_vm_runonce");
            if (mutex.WaitOne(TimeSpan.Zero, true) || System.Diagnostics.Debugger.IsAttached)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (Properties.Settings.Default.UpgradeSettings)
                {
                    Properties.Settings.Default.Upgrade();
                    Properties.Settings.Default.UpgradeSettings = false;
                    Properties.Settings.Default.Save();
                }

                if (Environment.GetCommandLineArgs().Contains<string>("/reset"))
                {
                    Properties.Settings.Default.Reset();
                    Properties.Settings.Default.Save();
                }

                identity = getIdentity(Environment.GetCommandLineArgs().Contains<string>("/auth"));

                LogEvents += new LogEvent(NetworkLog);

                VM = new VirtualMachine();

                DBG = new Forms.Debug();
                VM.OnVmEvent += new VirtualMachine.VmEvent(DBG.debugLog);
                VM.OnVmEvent += new VirtualMachine.VmEvent(Log);

                NL = new Network_listener();
                NL.OnPing += delegate(string auth, string msg)
                {
                    Packet p = new Packet();
                    p.dataIdentifier = Packet.DataIdentifier.Pong;
                    p.message = auth + "[" + msg +"]:T["+ DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds+"]";
                    Network_Broadcast.send(p);
                };
                NL.OnInfo += delegate(string auth, string msg)
                {
                    Log(auth + ": " + msg, "Devel VM Manager: Informator", 1);
                };
                NL.OnError += delegate(string auth, string msg)
                {
                    Log(String.Format("!!! {1} ({0}) !!!", auth, msg), "Devel VM Manager: Informator", 2);
                };
                NL.OnVersion += delegate(string auth, string msg)
                {
                    Packet p = new Packet();
                    p.dataIdentifier = Packet.DataIdentifier.Debug;
                    p.message = "AppVer: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
                    p.message += " / ImgVer: " + VM.getVersion();
                    Network_Broadcast.send(p);
                };

                Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                AppDomain.CurrentDomain.FirstChanceException += (object source, FirstChanceExceptionEventArgs e) =>
                {
                    Packet p = new Packet();
                    p.dataIdentifier = Packet.DataIdentifier.Debug;
                    p.message = String.Format("FirstChanceException event raised in {0}: {2}\nStackTrace:{1}", AppDomain.CurrentDomain.FriendlyName, e.Exception.StackTrace, e.Exception.Message);
                    Network_Broadcast.send(p);
                };
                SetProcessShutdownParameters(0x3FF, 0x00000001);
                Application.Run(new fMain());
                mutex.ReleaseMutex();
            }
            else
            {
                if(Environment.GetCommandLineArgs().Contains<string>("/r")) {
                    Process[] prcs = Process.GetProcessesByName("Devel_VM");
                    foreach (Process prc in prcs)
                    {
                        if (Process.GetCurrentProcess().Id != prc.Id)
                        {
                            prc.Kill();
                        }
                    }
                    prcs = Process.GetProcessesByName("Beta_Manager");
                    foreach (Process prc in prcs)
                    {
                        if (Process.GetCurrentProcess().Id != prc.Id)
                        {
                            prc.Kill();
                        }
                    }
                    prcs = Process.GetProcessesByName("VBoxSVC");
                    foreach (Process prc in prcs) prc.Kill();
                    prcs = Process.GetProcessesByName("VBoxHeadless");
                    foreach (Process prc in prcs) prc.Kill();
                    Application.Restart();
                }

                NativeMethods.PostMessage(
                    (IntPtr)NativeMethods.HWND_BROADCAST,
                    NativeMethods.WM_SHOWME,
                    IntPtr.Zero,
                    IntPtr.Zero
                );
            }
        }
예제 #8
0
파일: Program.cs 프로젝트: xbojer/devel_vm
 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
 {
     Exception e = (Exception) args.ExceptionObject;
     Packet p = new Packet();
     p.dataIdentifier = Packet.DataIdentifier.Debug;
     p.message = "Unhandled Exception: "+e.Source+": "+e.Message;
     Network_Broadcast.send(p);
 }
예제 #9
0
        public void initMachine()
        {
            if (MachineReady.getReadyOffline()) return;
            bool apiok = false;
            try
            {
                vb = new VirtualBox.VirtualBox();
                apiok = true;
            }
            catch (Exception) { }

            if (!apiok)
            {
                OnEvent("Brak API VB !!!", 3);
                return;
            }

            if (VbApiVersion != vb.APIVersion)
            {
                OnEvent("Niezgodna wersja API VB (Oczekiwano: "+VbApiVersion+" dostepna:" + vb.APIVersion + ")", 3);
                return;
            }
            VBVersion = vb.VersionNormalized;
            MachineReady.API = true;
            Session = new Session();

            reInit();

            Program.NL.OnReset += delegate(string auth)
            {
                Packet p = new Packet();
                p.dataIdentifier = Packet.DataIdentifier.Pong;
                p.message = "Resetting";
                Network_Broadcast.send(p);
                this.Restart();
            };
        }