Пример #1
0
    public static void ListAll(bool details, bool hiden, bool color, Folder folder, CommandStructure value)
    {
        int c = 0;

        foreach (Folder f in folder.folders)
        {
            if (hiden || !f.name.StartsWith("."))                //Si enseñamos todos o no es oculto, lo mostramos
            {
                ListInode(details, color, value, f, true);
                ++c;
                if (!hiden && c % 4 == 0)                 //si no es lista, hacemos 4 columnas
                {
                    value.value += Console.jump;
                }
            }
        }
        c = 0;
        foreach (File f in folder.files)
        {
            if (hiden || !f.name.StartsWith("."))
            {
                ListInode(details, color, value, f, false);
                ++c;
                if (!hiden && c % 4 == 0)
                {
                    value.value += Console.jump;
                }
            }
        }
        if (!hiden && c % 4 != 0)
        {
            value.value += Console.jump;                               //pading final si no es multiple de 4
        }
    }
Пример #2
0
        public void OnClickGo()
        {
            //ping 192.168.0.3
            string[] command = new string[] {
                "ping",
                inputDirection.text
            };
            CommandStructure result = Console.ReadCommand(command, node);

            string output = "Command: ";

            foreach (string s in command)
            {
                output += s + " ";
            }
            output += Console.jump;
            if (result.prompt)
            {
                output += result.value;
            }

            shellResponseText.text = output;

            if (!shellResponseOut)
            {
                StartCoroutine(Routines.WaitFor(0.2f, delegate {
                    shellResponseOut = true;
                }));
                StartCoroutine(Routines.DoWhile(0.2f, delegate(float f) {
                    shellResponseRect.anchoredPosition = Vector2.Lerp(shellPosIn, shellPosOut, f);
                }));
            }
        }
Пример #3
0
    /// <summary>
    /// Reads the current input, evaluates it and print its result.
    /// </summary>
    public void ReadInput()
    {
        if (currentInputText.Length == 0)
        {
            return;                                       //nothing written
        }
        string[] splited = currentInputText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        PrintOutputNoAddress(currentInputText + Console.jump);
        RaiseEventFull(OnOutput, currentInputText);

        //tratar comando
        CommandStructure commandReturn = Console.ReadCommand(splited, this);

        history.Add(currentInputText);
        if (commandReturn.prompt)
        {
            PrintOutputNoAddress(commandReturn.value);
        }
        node.RaiseOnShellCommand(commandReturn);

        historyCommandIndex = history.Count;
        currentInputText    = "";
        PrintAddress();
    }
Пример #4
0
 // route
 // route -n
 static void List(bool arp, Node node, CommandStructure value)
 {
     value.value = "Kernel IP routing table" + Console.jump;
     foreach (RouteEntry re in node.RouteTable)
     {
         PrintEntry(re, arp, value);
     }
 }
Пример #5
0
    public static void PlaceBuilding(Vector2 pos)
    {
        isPlayerBuilding = false;

        CommandStructure selectedCommandStructure = SelectionManager.selected[0].GetComponent <CommandStructure>();

        selectedCommandStructure.CreateBuildingShip(Building, pos, Building.GetComponent <Structure>().buildingTime);
        Building = null;
    }
Пример #6
0
 static void PrintHistory(Shell shell, CommandStructure value)
 {
     value.correct = true;
     value.value   = "";
     foreach (string s in shell.history)
     {
         value.value += (s + Console.jump);
     }
 }
Пример #7
0
 static void PrintInterface(Interface i, CommandStructure value)
 {
     value.value +=
         i.Name + ": " + i.address_family + " " + i.ip +
         " netmask " + i.netmask +
         " broadcast " + i.broadcast +
         Console.jump
     ;
 }
Пример #8
0
    static void Move(string path, Shell shell, CommandStructure value)
    {
        Folder newFolder = shell.folder.GetFolder(path);

        if (newFolder != null)
        {
            shell.UpdateAddress(newFolder);
        }
    }
Пример #9
0
        public void OnClickGo()
        {
            // ifconfig eth0 192.168.60.1 netmask 255.255.255.0 broadcast 192.169.60.255
            bool wasUp = selectedInterface.IsUp();

            string[] command = new string[] {
                "ifconfig",
                selectedInterface.Name,
                inputDirection.text,
                "netmask",
                inputMask.text,
                "broadcast",
                inputBroadcast.text
            };
            CommandStructure result = Console.ReadCommand(command, node);

            string output = "Command: ";

            foreach (string s in command)
            {
                output += s + " ";
            }
            output += Console.jump;
            if (result.prompt)
            {
                output += result.value;
            }

            if (result.correct && wasUp != toggleIsUp.isOn)               //ifup
            {
                command = new string[] {
                    "ifconfig",
                    selectedInterface.Name,
                    (toggleIsUp ? "up" : "down")
                };
                result = Console.ReadCommand(command, node);
                foreach (string s in command)
                {
                    output += s + " ";
                }
            }

            shellResponseText.text = output;

            if (!shellResponseOut)
            {
                StartCoroutine(Routines.WaitFor(0.2f, delegate {
                    shellResponseOut = true;
                }));
                StartCoroutine(Routines.DoWhile(0.2f, delegate(float f) {
                    shellResponseRect.anchoredPosition = Vector2.Lerp(shellPosIn, shellPosOut, f);
                }));
            }

            LoadValues();
        }
Пример #10
0
    private void Start()
    {
        commandStructure           = GetComponentInParent <CommandStructure>();
        productionStructureNoLimit = GetComponentInParent <ProductionStructureNoLimit>();
        productionStructureLimit   = GetComponentInParent <ProductionStructureLimit>();

        startingWidth    = transform.position.x - transform.parent.transform.position.x;
        startingHeight   = transform.position.y - transform.parent.transform.position.y;
        startingRotation = transform.rotation;
    }
Пример #11
0
 static void help(string[] command, Shell shell, CommandStructure value)
 {
     value.value = "List of avaliable commands:" + jump;
     foreach (string key in AvailableCommands)
     {
         value.value += key + jump;
     }
     value.correct = true;
     value.prompt  = true;
 }
Пример #12
0
 public static void Help(Shell shell, CommandStructure value)
 {
     value.prompt = true;
     value.value  = "theme <aparence> [r g b]" + Console.jump;
     value.value += "Avaliable aparences:" + Console.jump;
     foreach (aparenceToName a in aparences)
     {
         value.value += a.Name + Console.jump;
     }
 }
Пример #13
0
    public static void ReadOptions(string[] command, Shell shell, CommandStructure value)
    {
        bool          hiden = false, details = false, color = false;
        bool          target = false, multiple = false;
        List <string> paths = new List <string> ();
        Folder        root  = shell.folder;

        //solo pilla -la y -c como --color
        foreach (string word in command)           //cada parametro
        {
            if (word.StartsWith("-"))              //si es opcion
            {
                hiden   = word.Contains("a");
                details = word.Contains("l");
                color   = word.Contains("c");
            }
            else                 //si es directorio o fichero
            {
                if (target)
                {
                    multiple = true;
                }
                target = true;
                paths.Add(word);
            }
        }

        if (target)                     //si tenemos directorio/fichero especificado
        {
            foreach (string s in paths) //para cada uno
            {
                Folder folder = root.GetFolder(s);
                if (folder == null)
                {
                    File file = root.GetFile(s);
                    if (file != null)
                    {
                        ListInode(details, color, value, file, false);
                    }
                }
                else
                {
                    if (multiple)
                    {
                        value.value += folder.name + ":" + Console.jump;
                    }
                    ListAll(details, hiden, color, folder, value);
                }
            }
        }
        else             //si no, carpeta actual
        {
            ListAll(details, hiden, color, shell.folder, value);
        }
    }
Пример #14
0
    public static void Command(string[] command, Shell shell, CommandStructure value)
    {
        switch (command.Length)
        {
        case 1:
            if (command [0] == "help")
            {
                Help(shell, value);
                value.correct = true;
            }
            else
            {
                for (int i = 0; i < aparences.Length; ++i)
                {
                    if (command [0] == aparences [i].Name)
                    {
                        Apply(shell, aparences [i].aparence);
                        value.correct = true;
                        return;
                    }
                }
                Help(shell, value);
            }
            break;

        case 4:
            float r, g, b;
            Color c;
            try {
                r = float.Parse(command[1]);
                g = float.Parse(command[2]);
                b = float.Parse(command[3]);
                c = new Color(r / 255f, g / 255f, b / 255f);
            } catch {
                Help(shell, value);
                return;
            }
            for (int i = 0; i < aparences.Length; ++i)
            {
                if (command [0] == aparences[i].Name)
                {
                    Aparence a = new Aparence(aparences [i].aparence, c, c, Color.black);                      //TODO add back to parameter
                    Apply(shell, a);
                    value.correct = true;
                    return;
                }
            }
            break;

        default:
            Help(shell, value);
            break;
        }
    }
Пример #15
0
 static void Action(string[] command, Node node, CommandStructure value)
 {
     try {
         IP       address  = new IP(command[0]);
         PingInfo pingInfo = node.CanReach(address);
         value.value   = "Address " + command[0] + " " + (pingInfo.reached ? "reached" : "UNreachable") + ".";
         value.correct = true;
     } catch {
         value.value = "Error (1): Invalid IP address";
     }
 }
Пример #16
0
 public static void Command(string[] command, Shell shell, CommandStructure value)
 {
     switch (command.Length)
     {
     default:
         value.prompt  = true;
         value.value   = "Not implemented yet.";
         value.correct = true;
         break;
     }
 }
Пример #17
0
 static void List(bool a, Node node, CommandStructure value)
 {
     value.prompt  = true;
     value.correct = true;
     foreach (Interface i in node.Interfaces)
     {
         if (a || i.IsUp())
         {
             PrintInterface(i, value);
         }
     }
 }
Пример #18
0
    public static void Command(string[] command, Shell shell, CommandStructure value)
    {
        switch (command.Length)
        {
        case 1:
            Move(command [0], shell, value);
            break;

        default:
            break;
        }
    }
Пример #19
0
 static void List(string family, Node node, CommandStructure value)
 {
     value.prompt  = true;
     value.correct = true;
     foreach (Interface i in node.Interfaces)
     {
         if (i.address_family == family)
         {
             PrintInterface(i, value);
         }
     }
 }
Пример #20
0
    public static CommandStructure ReadCommand(string[] command, Node node)
    {
        CommandStructure commandReturn = new CommandStructure();

        commandReturn.command = command;
        commandReturn.node    = node;
        if (nodeCommands.ContainsKey(command [0]) && AvailableCommands.Has(command[0]))
        {
            nodeCommands [command [0]] (command.SubArray(1, command.Length - 1), node, commandReturn);
        }
        if (OnCommandRead != null)
        {
            OnCommandRead(commandReturn);
        }
        return(commandReturn);
    }
Пример #21
0
    public static void Command(string[] command, Shell shell, CommandStructure value)
    {
        value.prompt = true;

        switch (command.Length)
        {
        case 0:
            value.correct = true;
            ListAll(false, false, false, shell.folder, value);
            break;

        default:
            ReadOptions(command, shell, value);
            break;
        }
    }
Пример #22
0
    public static void Command(string[] command, Shell shell, CommandStructure value)
    {
        value.prompt = true;

        switch (command.Length)
        {
        case 0:
            value.correct = true;
            PrintHistory(shell, value);
            break;

        default:
            value.correct = false;
            value.value   = "Just type history dude";
            break;
        }
    }
Пример #23
0
 static void PrintEntry(RouteEntry e, bool arp, CommandStructure value)
 {
     if (!arp)
     {
         value.value +=
             "Iface:" + e.iface +
             " (D)" + e.destination +
             " (GW)" + e.gateway +
             " (M)" + e.genmask +
             " (F)" + e.flags +
             " (M)" + e.metric +
             " (R)" + e.refe +
             " (U)" + e.use +
             Console.jump
         ;
     }
 }
Пример #24
0
    public static void Create(string path, Shell shell, CommandStructure value)
    {
        string[] splited = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
        string   s       = "";

        if (path.StartsWith("/"))
        {
            s += "/";
        }
        for (int i = 0; i < splited.Length - 1; ++i)
        {
            s += splited [i] + "/";
        }
        Folder f;

        if (splited.Length > 1)
        {
            f = shell.folder.GetFolder(s);
        }
        else
        {
            f = shell.folder;
        }

        if (f == null)
        {
            value.prompt  = true;
            value.correct = false;
            value.value   = "Mkdir: bad folder";
        }
        else
        {
            if (f.GetFolder(splited [splited.Length - 1]) != null)
            {
                value.prompt  = true;
                value.correct = false;
                value.value   = "Mkdir: folder already existing";
            }
            else
            {
                value.correct = true;
                Folder nF = new Folder(splited [splited.Length - 1], f);
                f.folders.Add(nF);
            }
        }
    }
Пример #25
0
 void CheckIfconfigs(CommandStructure comm)
 {
     //print (comm.command [0]);
     if (comm.command [0] == "ifconfig")
     {
         bool done = ((B.Interfaces [0].ip.word == "192.168.1.1") && (B.Interfaces [1].ip.word == "192.168.1.2")) ||
                     ((B.Interfaces [0].ip.word == "192.168.1.2") && (B.Interfaces [1].ip.word == "192.168.1.1"));
         done = done && (A.Interfaces [0].ip.word == "192.168.0.1");
         done = done && (C.Interfaces [0].ip.word == "192.168.2.1");
         if (done)
         {
             ev2 = false;
             Console.OnCommandRead -= CheckIfconfigs;
             speech.gameObject.SetActive(true);
             speech.SetSpeech(speech3);
         }
     }
 }
Пример #26
0
    public static void ListInode(bool details, bool color, CommandStructure value, Inode inode, bool folder)
    {
        //folder or file
        if (details)
        {
            value.value += folder ? "d" : "-";

            //permissions rwx
            for (int i = 0; i < 9; ++i)
            {
                if (inode.permissions [i])
                {
                    if (i % 3 == 0)
                    {
                        value.value += "r";
                    }
                    else if (i % 3 == 1)
                    {
                        value.value += "w";
                    }
                    else
                    {
                        value.value += "x";
                    }
                }
                else
                {
                    value.value += "-";
                }
            }

            value.value += " " + inode.owner;
            value.value += " " + inode.creator;
            value.value += " " + inode.date;
            value.value += " ";
        }

        value.value += inode.name + " ";

        if (details)
        {
            value.value += Console.jump;
        }
    }
Пример #27
0
    public static void Command(string[] command, Node node, CommandStructure value)
    {
        value.prompt = true;

        switch (command.Length)
        {
        case 0:
            Help(value);
            break;

        case 1:
            Action(command, node, value);
            break;

        default:
            Help(value);
            break;
        }
    }
Пример #28
0
//     ifconfig [-L] [-m] [-r] interface [create] [address_family] [address [dest_address]] [parameters]
//     ifconfig interface destroy
//     ifconfig -a [-L] [-d] [-m] [-r] [-u] [-v] [address_family]
//     ifconfig -l [-d] [-u] [address_family]
//     ifconfig [-L] [-d] [-m] [-r] [-u] [-v] [-C]
//     ifconfig interface vlan vlan-tag vlandev iface
//     ifconfig interface -vlandev iface
//     ifconfig interface bonddev iface
//     ifconfig interface -bonddev iface
//     ifconfig interface bondmode lacp | static

    // ifconfig [-a]
    // ifconfig interface up/down
    // ifconfig interface @address netmask @mask broadcast @mask
    // ifconfig eth0 192.168.60.1
    // ifconfig eth0 192.168.60.1 netmask 255.255.255.0
    // ifconfig eth0 192.168.60.1 netmask 255.255.255.0 broadcast 192.169.60.255
    public static void Command(string[] command, Node node, CommandStructure value)
    {
        switch (command.Length)
        {
        case 0:
            List(false, node, value);              //List up
            break;

        case 1:
            switch (command [0])
            {
            case "-a":
                List(true, node, value);                  //List all
                break;

            default:
                List(command [0], node, value);                  //List family
                break;
            }
            break;

        case 2:
            switch (command [1])
            {
            case "down":
                IfDown(command, node, value);
                break;

            case "up":
                IfUp(command, node, value);
                break;

            default:
                Configure(command, node, value);
                break;
            }
            break;

        default:
            Configure(command, node, value);
            break;
        }
    }
Пример #29
0
    public static CommandStructure ReadCommand(string[] command, Shell shell)
    {
        CommandStructure commandReturn = new CommandStructure();

        commandReturn.command = command;
        commandReturn.shell   = shell;
        if (shellCommands.ContainsKey(command [0]) && AvailableCommands.Has(command[0]))
        {
            shellCommands [command [0]] (command.SubArray(1, command.Length - 1), shell, commandReturn);
        }
        else if (nodeCommands.ContainsKey(command [0]) && AvailableCommands.Has(command[0]))
        {
            nodeCommands [command [0]] (command.SubArray(1, command.Length - 1), shell.node, commandReturn);
        }
        if (OnCommandRead != null)
        {
            OnCommandRead(commandReturn);
        }
        return(commandReturn);
    }
Пример #30
0
        public void OnClickGo()
        {
            string[] command = new string[] {
                "route",
                dropdownMode.options[dropdownMode.value].text,
                "-" + dropdownNet.options[dropdownNet.value].text,
                inputDestination.text,
                "netmask",
                inputNetmask.text,
                "gw",
                interfaces[dropdownGateway.value].ip.word,
                "dev",
                interfaces[dropdownGateway.value].Name
            };
            CommandStructure result = Console.ReadCommand(command, node);

            string output = "Command: ";

            foreach (string s in command)
            {
                output += s + " ";
            }
            output += Console.jump;
            if (result.prompt)
            {
                output += result.value;
            }

            shellResponseText.text = output;

            if (!shellResponseOut)
            {
                StartCoroutine(Routines.WaitFor(0.2f, delegate {
                    shellResponseOut = true;
                }));
                StartCoroutine(Routines.DoWhile(0.2f, delegate(float f) {
                    shellResponseRect.anchoredPosition = Vector2.Lerp(shellPosIn, shellPosOut, f);
                }));
            }
        }