private JObject ParseModeScriptCallback(MethodCall call)
        {
            XmlRpcArray  dataArr = (XmlRpcArray)call.Arguments[1];
            XmlRpcString dataStr = (XmlRpcString)dataArr.Values[0];

            return(JObject.Parse(dataStr.Value));
        }
Example #2
0
    private void WriteArray( XmlRpcArray v )
    {
      WriteStartElement( "array" );
      WriteStartElement( "data" );
      foreach( object entry in v ) {
	WriteValue( entry );
      }
      WriteEndElement(); // data
      WriteEndElement(); // array
    }
Example #3
0
        public void ToXmlRpcArray_Returns_XmlRpcArray_of_Integers_From_Int_Array()
        {
            int[] arr = new int[] { 1, 2, 3 };

            XmlRpcArray result   = XmlRpcTypes.ToXmlRpcArray(arr);
            XmlRpcArray expected = new XmlRpcArray(new XmlRpcBaseType[] {
                new XmlRpcInteger(1),
                new XmlRpcInteger(2),
                new XmlRpcInteger(3)
            });

            Assert.Equal(expected, result);
        }
Example #4
0
    protected XmlRpcParameterArray CreateLoginParameters(Credential credential, Slurl slurl, bool getInventoryLibrary, bool godMode)
    {
        XmlRpcArray options = new XmlRpcArray();

        options.Append(new XmlRpcString("inventory-root"));
        options.Append(new XmlRpcString("inventory-skeleton"));
        //options.Append(new XmlRpcString("inventory-meat"));
        //options.Append(new XmlRpcString("inventory-skel-targets"));
        if (getInventoryLibrary == true)
        {
            options.Append(new XmlRpcString("inventory-lib-root"));
            options.Append(new XmlRpcString("inventory-lib-owner"));
            options.Append(new XmlRpcString("inventory-skel-lib"));
            //options.Append(new XmlRpcString("inventory-meat-lib"));
        }
        options.Append(new XmlRpcString("initial-outfit"));
        options.Append(new XmlRpcString("gestures"));
        options.Append(new XmlRpcString("display_names"));
        options.Append(new XmlRpcString("event_categories"));
        options.Append(new XmlRpcString("event_notifications"));
        options.Append(new XmlRpcString("classified_categories"));
        options.Append(new XmlRpcString("adult_compliant"));
        options.Append(new XmlRpcString("buddy-list"));
        options.Append(new XmlRpcString("newuser-config"));
        options.Append(new XmlRpcString("ui-config"));

        //send this info to login.cgi for stats gathering
        //since viewerstats isn't reliable enough
        options.Append(new XmlRpcString("advanced-mode"));

        options.Append(new XmlRpcString("max-agent-groups"));
        options.Append(new XmlRpcString("map-server-url"));
        options.Append(new XmlRpcString("voice-config"));
        options.Append(new XmlRpcString("tutorial_setting"));
        options.Append(new XmlRpcString("login-flags"));
        options.Append(new XmlRpcString("global-textures"));

        if (godMode == true)
        {
            options.Append(new XmlRpcString("UseDebugMenus"));
            options.Append(new XmlRpcString("god-connect"));
        }

        XmlRpcStruct data = new XmlRpcStruct();

        data["start"]              = new XmlRpcString(slurl.GetLoginString());
        data["agree_to_tos"]       = new XmlRpcBoolean(false);
        data["read_critical"]      = new XmlRpcBoolean(false);
        data["last_exec_event"]    = new XmlRpcInteger(LastExecEvent);
        data["last_exec_duration"] = new XmlRpcInteger(LastExecDuration);
        data["mac"]              = new XmlRpcString(MachineId);
        data["version"]          = new XmlRpcString(ViewerVersion);
        data["channel"]          = new XmlRpcString(ViewerChannel);
        data["platform"]         = new XmlRpcString(Platform);
        data["address_size"]     = new XmlRpcInteger(ADDRESS_SIZE);
        data["platform_version"] = new XmlRpcString(PlatformVersion);
        data["platform_string"]  = new XmlRpcString(PlatformVersionName);
        data["id0"]              = new XmlRpcString(SerialNumber);
        data["host_id"]          = new XmlRpcString(HostId);
        data["extended_errors"]  = new XmlRpcBoolean(true);

        data["passwd"] = new XmlRpcString(credential.Secret);
        data["first"]  = new XmlRpcString(credential.First);
        data["last"]   = new XmlRpcString(credential.Last);

        data["options"] = options;

        XmlRpcParameterArray parameters = new XmlRpcParameterArray();

        parameters.Append(data);
        return(parameters);
    }
        /// <summary>
        /// Call multiple methods without multiple round-trip times.
        /// </summary>
        /// <param name="multicall">MultiCall object containing the calls to perform.</param>
        /// <returns>An array of results for each call.</returns>
        public async Task <object[]> MultiCallAsync(MultiCall multicall)
        {
            List <XmlRpcBaseType> calls = new();

            // build the call
            foreach (var call in multicall.MethodCalls)
            {
                string methodName = call.MethodName;
                if (methodName.EndsWith("Async"))
                {
                    methodName = methodName.Substring(0, methodName.Length - 5);
                }

                XmlRpcBaseType[] args       = MethodArgs(call.Arguments);
                XmlRpcStruct     callStruct = new(new Struct()
                {
                    { "methodName", new XmlRpcString(methodName) },
                    { "params", new XmlRpcArray(args) }
                });

                calls.Add(callStruct);
            }

            // run the call
            XmlRpcArray multicallArgs = new(calls.ToArray());
            var         msg           = await CallAsync("system.multicall", multicallArgs);

            if (msg.IsFault)
            {
                logger.Error("Multicall failed with reason: {message}", (XmlRpcFault)msg.ResponseData);
                throw new XmlRpcFaultException((XmlRpcFault)msg.ResponseData);
            }

            // convert response to native values, should always be array if no error
            XmlRpcArray results = (XmlRpcArray)msg.ResponseData;

            object[] converted = new object[results.Values.Length];

            for (int i = 0; i < converted.Length; i++)
            {
                if (results.Values[i] is XmlRpcStruct)
                {
                    // if struct we have a fault instead
                    XmlRpcStruct faultStruct = (XmlRpcStruct)results.Values[i];

                    converted[i] = new XmlRpcFault(
                        ((XmlRpcInteger)faultStruct.Fields["faultCode"]).Value,
                        ((XmlRpcString)faultStruct.Fields["faultString"]).Value
                        );
                }
                else
                {
                    // else normal resutl
                    XmlRpcArray resultArr = (XmlRpcArray)results.Values[i];

                    if (resultArr.Values.Length == 0)
                    {
                        converted[i] = null;
                    }
                    else
                    {
                        converted[i] = XmlRpcTypes.ToNativeValue <object>(resultArr.Values[0]);
                    }
                }
            }

            return(converted);
        }
    private void WriteArray( XmlRpcArray v )
    {
      WriteStartElement( "array" );
      WriteStartElement( "data" );
      foreach( object entry in v ) {
	WriteValue( entry );
      }
      WriteEndElement(); // data
      WriteEndElement(); // array
    }