예제 #1
0
        private static void executeThreadedScript(string[] script, OS os)
        {
            var      nullable = new KeyValuePair <string, string>?();
            var      flag1    = false;
            var      target   = os.thisComputer;
            Computer source   = null;
            var      timeout  = TimeSpan.FromSeconds(0.5);

            for (var index = 0; index < script.Length; ++index)
            {
                if (source != null && source.disabled)
                {
                    Multiplayer.parseInputMessage(getBasicNetworkCommand("cDisconnect", target, source), os);
                    Console.WriteLine("Early Script Exit on Source Disable");
                    return;
                }
                var strArray = script[index].Split(Utils.spaceDelim, StringSplitOptions.RemoveEmptyEntries);
                var flag2    = true;
                switch (strArray[0])
                {
                case "config":
                    target   = (Computer)ComputerLoader.findComputer(strArray[1]);
                    source   = (Computer)ComputerLoader.findComputer(strArray[2]);
                    timeout  = TimeSpan.FromSeconds(Convert.ToDouble(strArray[3]));
                    flag2    = false;
                    nullable = new KeyValuePair <string, string>(source.ip, target.ip);
                    os.ActiveHackers.Add(nullable.Value);
                    break;

                case "delay":
                    Thread.Sleep(TimeSpan.FromSeconds(Convert.ToDouble(strArray[1])));
                    break;

                case "connect":
                    Multiplayer.parseInputMessage(getBasicNetworkCommand("cConnection", target, source), os);
                    break;

                case "openPort":
                    Multiplayer.parseInputMessage(
                        getBasicNetworkCommand("cPortOpen", target, source) + " " + strArray[1], os);
                    break;

                case "delete":
                    var pathString = getPathString(strArray[1], os, target.files.root);
                    Multiplayer.parseInputMessage(
                        "cDelete #" + target.ip + "#" + source.ip + "#" + strArray[2] + pathString, os);
                    break;

                case "reboot":
                    os.runCommand("reboot");
                    break;

                case "forkbomb":
                    Multiplayer.parseInputMessage(getBasicNetworkCommand("eForkBomb", target, source), os);
                    break;

                case "disconnect":
                    Multiplayer.parseInputMessage(getBasicNetworkCommand("cDisconnect", target, source), os);
                    break;
                }
                try
                {
                    if (flag2)
                    {
                        if (!os.thisComputer.disabled)
                        {
                            os.beepSound.Play();
                            if (!flag1)
                            {
                                os.IncConnectionOverlay.Activate();
                                flag1 = true;
                            }
                        }
                    }
                }
                catch
                {
                    return;
                }
                Thread.Sleep(timeout);
            }
            if (!nullable.HasValue)
            {
                return;
            }
            os.ActiveHackers.Remove(nullable.Value);
        }