private string ReadConsoleCommand(string input, out bool success)
    {
        success = false;

        string[] cells = input.Split(' ');

        double d_input;

        if (!AlphaNumeral.StringToDbl(cells[1], out d_input))
        {
            return("'" + cells[1] + "' invalid number format");
        }

        // Find player
        PlayerScript player = GameManager.FindPlayerAtNode(d_input, instruction.GetNode());

        if (player == null)
        {
            return("Console '" + cells[1] + "' not found");
        }

        player.timeLastRead = Time.time;
        // Move command into queue
        if (player.commandQueue.Count > 0)
        {
            EnqueuedCommand command = player.commandQueue.Dequeue();
            command.sourceInstruction = instruction.GetSource();
            instruction.GetNode().commandQueue.Enqueue(command);
        }

        // XXX: Unsure if 'readconsole' should be enqueued as a command itself first
        instruction.EnqueueNextInstruction();
        success = true;
        return(null);
    }
Пример #2
0
    protected void ConnectCallback(NodeScript node, string input, int sourceInstruction, bool success)
    {
        if (!success)
        {
            player.PrintToConsole("Connection attempt failed to send");
            return;
        }

        Regex pattern = new Regex(@"^(" + P.DATA + @")\s+(" + P.INT + @")");
        Match match   = pattern.Match(input);

        // Format
        // XXX: Add option to force Connect ignoring safe mode
        string address = match.Groups[1].Value;
        double d_address;

        AlphaNumeral.StringToDbl(address, out d_address);

        NodeScript targetNode = NodeManager.GetNode(d_address, true);

        /* XXX:
         * if( targetNode == null ) {
         *      player.connectedNode = null;
         *      PacketGraphicScript packet = PacketGraphicManager.GetPacket();
         *      player.cameraFocus.MoveTo();
         * }*/

        // Connect to new Node
        player.connectedNode = targetNode;

        // Camera pan to new Node
        player.cameraFocus.MoveTo(NodeGraphicManager.GetGraphic(targetNode),
                                  GameManager.gameOptions.packetTravelTime);
    }
    public string Interpret(EnqueuedInstruction in_instruction)
    {
        instruction = in_instruction;
        MemoryBlock memoryBlock = instruction.GetNode().GetMemory(instruction.GetSource());
        double      in_command  = memoryBlock.GetCell(0).value;

        // Interpret command
        // XXX: Comparing using values instead of strings to guarantee interpretation
        //		Will require a better setup
        Command cmd = null;

        //Debug.Log("IN: " + in_command);
        foreach (string commandString in commands.Keys)
        {
            double commandValue;
            AlphaNumeral.StringToDbl(commandString, out commandValue);

            //Debug.Log("CMD: " + commandString);
            //Debug.Log("VAL: " + commandValue);

            if (in_command == commandValue)
            {
                cmd = commands[commandString];
                break;
            }
        }
        if (cmd == null)
        {
            return("Commands '" + memoryBlock.GetCell(0).content + "' not found");
        }

        // Gather 'input' string from MemoryBlock contents
        string input = "";

        for (int i = 0; i < GameManager.gameOptions.memoryCellCount; i++)
        {
            input += memoryBlock.GetCell(i).content + " ";
        }

        bool   success;
        string output = cmd(input, out success);

        instruction = null;
        return(output);
    }
Пример #4
0
    public string SetContent(int idx, string content)
    {
        if (idx < 0 || idx >= GameManager.gameOptions.memoryCellCount)
        {
            return("subIndex out of bounds");
        }

        // XXX: The used symbols for modifiers should be stored somewhere else
        if (content[0] == '*')
        {
            cells[idx].indirect = true;
            content             = content.Substring(1);
        }
        else
        {
            cells[idx].indirect = false;
        }

        // Set new value of cell
        double value;

        if (!AlphaNumeral.StringToDbl(content, out value))
        {
            return("'" + content + "' invalid number format");
        }

        // Set content
        if (content.Length <= GameManager.gameOptions.dataLength)
        {
            // Content fits = explicit
            cells[idx].value = value;
            cells[idx].ExplicitSetContent(content);
        }
        else
        {
            // Content does not fit = convert
            return(SetContent(idx, value));
        }

        return(null);
    }
Пример #5
0
    /*protected string DownloadCommand( string input, out bool success )
     * {
     *      success = false;
     *
     *      // Parse
     *      Regex pattern = new Regex(@"^(" + P.INT + @")\s+(" + P.INT + @")\s+(.*)");
     *      Match match = pattern.Match(input);
     *      if( !match.Success ) {
     *              return "'" + input + "' invalid Download command format";
     *      }
     *
     *      // Validate
     *      string index = match.Groups[1].Value;
     *      int i_index;
     *      int subIndex;
     *      string error = localNode.ParseMemoryIndex(index, out i_index, out subIndex);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      string count = match.Groups[2].Value;
     *      int i_count;
     *      bool b = AlphaNumeral.StringToInt(count, out i_count);
     *      if( !b ) {
     *              return "'" + count + "' in '" + input + "' invalid number format";
     *      }
     *
     *      string fileName = match.Groups[3].Value;
     *
     *      // Gather Data
     *      string[] data = new string[i_count];
     *      for( int i=0; i < i_count; i++ ) {
     *              int idx = (i_index + i) % GameManager.gameOptions.nodeMemoryLength;
     *              Memory memory = localNode.GetMemory(idx);
     *              data[i] = "[" + localNode.GetLabel(idx) + "]" + " " + (memory.isData?"d":"i") + " " + memory.contents;
     *      }
     *
     *      // Write to file
     *      error = ClusterManager.SaveProgram(fileName, data);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      success = true;
     *      return "Downloading program...";
     * }
     * protected string UploadCommand( string input, out bool success )
     * {
     *      success = false;
     *
     *      // Parse
     *      Regex pattern = new Regex(@"^(" + P.INDEX + @")\s+(.*)");
     *      Match match = pattern.Match(input);
     *      if( !match.Success ) {
     *              return "'" + input + "' invalid Upload command format";
     *      }
     *
     *      // Validate
     *      string index = match.Groups[1].Value;
     *      int i_index;
     *      string error = localNode.ParseMemoryIndex(index, out i_index);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      string fileName = match.Groups[2].Value;
     *
     *      // Gather Data
     *      string[] data;
     *      error = ClusterManager.LoadProgram(fileName, out data);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      // Parse data lines
     *      Regex dataPattern = new Regex(@"^[(" + P.LABEL + @")]\s+(" + P.INDEX + @")\s+(.*)");
     *      for( int i=0; i < data.Length; i++ ) {
     *              Match dataMatch = dataPattern.Match(data[i]);
     *              if( !dataMatch.Success ) {
     *                      return "'" + data[i] + "' invalid data format";
     *              }
     *              string dataLabel = dataMatch.Groups[1].Value;
     *              string dataIndex = dataMatch.Groups[2].Value;
     *              string dataContent = dataMatch.Groups[3].Value;
     *
     *              // Calc index
     *              int i_dataIndex;
     *              if( !int.TryParse(dataIndex, out i_dataIndex) ) {
     *                      return "'" + dataIndex + "' in '" + data[i] + "' invalid number format";
     *              }
     *              int idx = (i_index + i_dataIndex) % GameManager.gameOptions.nodeMemoryLength;
     *
     *              // Apply data to node memory
     *              localNode.SetMemory(idx, dataContent);
     *              localNode.AddLabel(idx, dataLabel);
     *      }
     *
     *      success = true;
     *      return "Uploading program...";
     * }
     * protected string SaveKitCommand( string input, out bool success )
     * {
     *      success = false;
     *
     *      // Collect all Memory
     *      string[] data = new string[GameManager.gameOptions.nodeMemoryLength];
     *      for( int i=0; i < data.Length; i++ ) {
     *              Memory memory = localNode.GetMemory(i);
     *              data[i] = "[" + localNode.GetLabel(i) + "]" + " " + (memory.isData?"d":"i") + " " + memory.contents;
     *      }
     *
     *      // Write to file
     *      string error = ClusterManager.SaveProgram(input, data);
     *      if( error != null ) {
     *              return error;
     *      }
     *
     *      success = true;
     *      return "Saving kit...";
     * }*/

    protected string Connect(string input, bool safe, out bool success)
    {
        success = false;

        // Parse
        Regex pattern = new Regex(@"^(" + P.DATA + @")\s+(" + P.INT + @")");
        Match match   = pattern.Match(input);

        if (!match.Success)
        {
            return("'" + input + "' invalid connect format");
        }

        // Format
        // XXX: Add option to force Connect ignoring safe mode
        string address = match.Groups[1].Value;
        double d_address;

        if (!AlphaNumeral.StringToDbl(address, out d_address))
        {
            return("'" + address + "' in '" + input + "' invalid number format");
        }

        if (safe)
        {
            if (!NodeGraphicManager.NodeIsVisible(d_address))
            {
                return("Safe Mode: Unknown Node. Use connectforce to force.");
            }
        }

        string index = match.Groups[2].Value;

        // Enqueue send exec command to new node to activate the new readconsole
        string sendInput = address + " exec " + index;

        player.commandQueue.Enqueue(new EnqueuedCommand(SendAction, sendInput, 0, ConnectCallback));

        success = true;
        return("Connecting...");
    }
Пример #6
0
    public static double GenerateAddress()
    {
        // Randomize address string based on AddressFormat
        string s_address = GameManager.GetAddressFormat();

        for (int i = 0; i < s_address.Length; i++)
        {
            if (s_address[i] == '*')
            {
                int rand = UnityEngine.Random.Range(0, CharSets.ALPHA_LOWER.Length);
                s_address = s_address.Remove(i, 1);
                s_address = s_address.Insert(i, CharSets.ALPHA_LOWER[rand].ToString());
            }
        }
        // Convert to number
        double address = 0;

        AlphaNumeral.StringToDbl(s_address, out address);

        return(address);
    }