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);
    }
    protected string HideNodesCommand(string input, out bool success)
    {
        success = true;
        NodeGraphicManager.HideAll();

        return("Hiding Nodes...");
    }
Esempio n. 3
0
    public virtual void Init(double in_id)
    {
        id = in_id;

        connectedNode = NodeManager.CreateNode();
        int idx = UnityEngine.Random.Range(0, GameManager.gameOptions.nodeMemoryLength);

        MemoryBlock memory = connectedNode.GetMemory(idx);

        memory.SetContent(0, "READCON");
        memory.SetContent(1, id);

        memory = connectedNode.GetMemory(idx + 1);
        memory.SetContent(0, "JMP");
        memory.SetContent(1, idx);

        connectedNode.instructionQueue.Enqueue(new EnqueuedInstruction(connectedNode, idx));
        connectedNode.AddLabel(idx, "READC");

        NodeGraphicScript graphic = NodeGraphicManager.DisplayNode(Vector3.zero, connectedNode);

        cameraFocus.MoveTo(graphic);

        SetStaticValues();

        // XXX: Temporary code for local admin + non-admin
        GameManager.playerConsole = id;
        GameManager.activeConsole = id;
    }
Esempio n. 4
0
    string GetLostCommand(string input, out bool success)
    {
        double address = NodeManager.GetRandomAddress();

        NodeGraphicManager.DisplayNode(NodeGraphicManager.GetGraphic(player.connectedNode).transform.position, address);

        return(Connect(address.ToString(), true, out success));
    }
Esempio n. 5
0
    public static void CreatePacketGraphic(NodeScript source, NodeScript target)
    {
        Vector3    vrot           = Random.onUnitSphere;
        Quaternion rot            = Quaternion.Euler(vrot);
        GameObject packetGraphics = GameObject.Instantiate(packetPrefab, NodeGraphicManager.GetGraphic(source).transform.position,
                                                           rot, gameObject.transform) as GameObject;

        PacketGraphicScript graphicsScript = packetGraphics.GetComponent <PacketGraphicScript>();

        graphicsScript.MoveTo(target);
        packets.Add(graphicsScript);
    }
    protected string ResetCommand(string input, out bool success)
    {
        success = true;

        NodeGraphicScript graphic = NodeGraphicManager.GetGraphic(localNode);

        graphic.HideDisplay();
        graphic.ShowMemory(false);
        player.cameraFocus.Offset(Vector3.zero);
        player.cameraFocus.SetDistance(4);

        return("Resetting view...");
    }
Esempio n. 7
0
    public void MoveTo(NodeScript target)
    {
        Vector3 v_target;

        if (target == null || !NodeGraphicManager.NodeIsVisible(target))
        {
            v_target = Random.onUnitSphere * 40;
        }
        else
        {
            v_target = NodeGraphicManager.GetGraphic(target).transform.position;
        }
        positionTween.StartTween(transform.position, v_target, GameManager.gameOptions.packetTravelTime);
    }
    protected string ReadLogCommand(string input, out bool success)
    {
        success = false;

        /* XXX: Left for later use for log filtering
         * Regex pattern = new Regex(@"");
         * Match match = pattern.Match(input);
         * if( !match.Success ) {
         *      return "ReadLog invalid format";
         * }*/

        LogDetails detail;

        switch (input)
        {
        case "all":
            detail = LogDetails.ALL;
            break;

        case "command":
            detail = LogDetails.COMMAND;
            break;

        case "":
        case "response":
            detail = LogDetails.RESPONSE;
            break;

        default:
            return("ReadLog invalid format");
        }

        NodeGraphicScript graphic = NodeGraphicManager.GetGraphic(localNode);

        graphic.DisplayLog(detail);

        player.cameraFocus.Offset(new Vector3(-0.5f, 0, 2.5f));

        graphic.ShowMemory(false);
        success = true;
        return("Opening log...");
    }
    /*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...");
    }
Esempio n. 10
0
    protected string ReadMemoryCommand(string input, out bool success)
    {
        success = false;

        if (input.Length != 0)
        {
            if (input.ToLower() == "static")
            {
                return("Static not implemented...");

                /*for( int i = GameManager.gameOptions.nodeMemoryLength; i < player.connectedNode.GetMemoryLength(); i++ ) {
                 *      Memory memory = player.connectedNode.GetMemory(i);
                 *      output += FormatMemory(i, memory, false);
                 * }*/
            }
            else
            {
                int    index;
                int    subIndex;
                string error = localNode.ParseMemoryIndex(input, out index, out subIndex);
                if (error != null)
                {
                    return(error);
                }
                NodeGraphicScript graphic = NodeGraphicManager.GetGraphic(localNode);
                graphic.RotateMemory(index);
            }
        }
        else
        {
            NodeGraphicScript graphic = NodeGraphicManager.GetGraphic(localNode);
            graphic.SetRotationSpeed(graphic.memoryRotationSpeed);
        }
        NodeGraphicManager.GetGraphic(localNode).ShowMemory(true);
        player.cameraFocus.Offset(new Vector3(1.5f, 0, 0));

        success = true;
        return("Opening Memory...");
    }
Esempio n. 11
0
    // Use this for initialization
    void Start()
    {
        GameOptions gameOptions = new GameOptions(
            nodeCount,
            nodeMemoryLength,
            readMemoryCount,
            dataLength,
            memoryCellCount,
            numberOfSetAddressChars,
            labelLength,
            maxLog,
            codeFrameDelay,
            timeOut,
            packetTravelTime
            );

        GameManager.Init(gameOptions);
        NodeManager.Init();
        PacketManager.Init();
        NodeGraphicManager.Init();
        PacketGraphicManager.Init();

        GameManager.InitPlayers();
    }
Esempio n. 12
0
    public static void DisplayPacket(NodeScript source, NodeScript target)
    {
        // Determine if sourceNode needs graphic
        if (!NodeGraphicManager.NodeIsVisible(source) &&
            target != null &&
            NodeGraphicManager.NodeIsVisible(target))
        {
            foreach (PlayerScript console in GameManager.GetConsoles().Values)
            {
                if (target == console.connectedNode)
                {
                    NodeGraphicScript graphic = NodeGraphicManager.GetGraphic(target);
                    NodeGraphicManager.DisplayNode(graphic.transform.position, source);
                    break;
                }
            }
        }

        // Show packet graphics
        if (NodeGraphicManager.NodeIsVisible(source))
        {
            PacketGraphicManager.CreatePacketGraphic(source, target);
        }
    }