Exemple #1
0
    // XXX: Dare I say I do not like how I am handling Packets
    public string Interpret(NodeScript node, PacketScript in_packet)
    {
        localNode = node;
        packet    = in_packet;

        // Divide input
        Regex pattern = new Regex(@"^([^ ]+)(?:\s+(.+))?");
        Match match   = pattern.Match(packet.GetContents());

        if (!match.Success)
        {
            return("'" + packet.GetContents() + "' invalid command format");
        }
        string command    = match.Groups[1].Value;
        string parameters = match.Groups[2].Value;

        // Interpret command across all command lists
        Command cmd = null;

        if (!commands.TryGetValue(command.ToLower(), out cmd))
        {
            return("'" + command + "' in '" + packet.GetContents() + "' command not found");
        }

        /*if( packet.GetTarget() != null ) {
         *      string error = EvalLabels( parameters, out parameters, packet.GetTarget() );
         *      if( error != null ) {
         *              return error;
         *      }
         * }*/

        // Run command
        bool   success;
        string output = cmd(parameters, out success);

        if (!success)
        {
            return(output);
        }

        return(null);
    }