コード例 #1
0
		public WebRequestClass(WebProxy proxy, SecondLife secondlife, string strUrl, SecondLife.list parameters, string postData, SecondLife.key key)
		{
			try
			{
				// Create a new webrequest to the mentioned URL.   
				WebRequest myWebRequest = WebRequest.Create(strUrl);

				myWebRequest.Headers.Add("Cache-Control", "max-age=259200");
				//myWebRequest.Headers.Add("Connection", "keep-alive");
				myWebRequest.Headers.Add("Pragma", "no-cache");
				//myWebRequest.Headers.Add("Via", "1.1 sim3560.agni.lindenlab.com:3128 (squid/2.6.STABLE12)");
				//myWebRequest.Headers.Add("Content-Length", "3");
				//myWebRequest.Headers.Add("Content-Type", "text/plain;charset=utf-8");
				//myWebRequest.Headers.Add("Accept", "text/*");
				myWebRequest.Headers.Add("Accept-Charset", "utf-8;q=1.0, *;q=0.5");
				myWebRequest.Headers.Add("Accept-Encoding", "deflate, gzip");
				//myWebRequest.Headers.Add("Host", "www.lsleditor.org");
				//myWebRequest.Headers.Add("User-Agent", "LSLEditor 2.24 (http://www.lsleditor.org)");
				myWebRequest.Headers.Add("X-SecondLife-Shard", "Production");

				SecondLife.vector RegionCorner = secondlife.llGetRegionCorner();
				SecondLife.vector pos = secondlife.llGetPos();

				myWebRequest.Headers.Add("X-SecondLife-Object-Name", secondlife.host.GetObjectName());
				myWebRequest.Headers.Add("X-SecondLife-Object-Key", secondlife.host.GetKey().ToString());
				myWebRequest.Headers.Add("X-SecondLife-Region", Properties.Settings.Default.RegionName + " (" + (int)RegionCorner.x + ", " + (int)RegionCorner.y + ")");
				myWebRequest.Headers.Add("X-SecondLife-Local-Position", "("+pos.x+", "+pos.y+", "+pos.z+")");
				myWebRequest.Headers.Add("X-SecondLife-Local-Rotation", "(0.000000, 0.000000, 0.000000, 1.000000)");
				myWebRequest.Headers.Add("X-SecondLife-Local-Velocity", "(0.000000, 0.000000, 0.000000)");
				myWebRequest.Headers.Add("X-SecondLife-Owner-Name", Properties.Settings.Default.AvatarName);
				myWebRequest.Headers.Add("X-SecondLife-Owner-Key", Properties.Settings.Default.AvatarKey);
				myWebRequest.Headers.Add("X-Forwarded-For", "127.0.0.1");

				// Setting up paramters
				for (int intI = 0; intI < parameters.Count; intI += 2)
				{
					switch (int.Parse(parameters[intI].ToString()))
					{
						case 0:
							myWebRequest.Method = parameters[intI + 1].ToString();
							break;
						case 1:
							myWebRequest.ContentType = parameters[intI + 1].ToString();
							break;
						case 2:
							// HTTP_BODY_MAXLENGTH
							break;
						default:
							break;
					}
				}

				if (proxy != null)
					myWebRequest.Proxy = proxy;

				// Create a new instance of the RequestState.
				RequestState myRequestState = new RequestState();

				myRequestState.secondlife = secondlife;
				myRequestState.httpkey = key;
				myRequestState.postData = Encoding.UTF8.GetBytes(postData);

				// 19 sep 2007
				myWebRequest.ContentLength = myRequestState.postData.Length;

				// The 'WebRequest' object is associated to the 'RequestState' object.
				myRequestState.request = myWebRequest;

				// Start the Asynchronous call for response.
				IAsyncResult asyncResult;
				if (myWebRequest.Method == "POST" || myWebRequest.Method == "PUT")
					asyncResult = (IAsyncResult)myWebRequest.BeginGetRequestStream(new AsyncCallback(RespCallback), myRequestState);
				else
					asyncResult = (IAsyncResult)myWebRequest.BeginGetResponse(new AsyncCallback(RespCallback), myRequestState);
			}
			catch (WebException e)
			{
				secondlife.host.VerboseMessage(e.Message);
				secondlife.host.VerboseMessage(e.Status.ToString());
			}
			catch (Exception e)
			{
				Console.WriteLine("Exception raised!");
				Console.WriteLine("Source : " + e.Source);
				Console.WriteLine("Message : " + e.Message);
				secondlife.host.VerboseMessage(e.Message);
			}
		}
コード例 #2
0
        private object[] GetArguments(string strName, string strArgs)
        {
            object[] objResult = new object[0];
            if (strArgs != "")
            {
                try {
                    string[] args       = strArgs.Trim().Split(new char[] { ',' });
                    object[] argobjects = new object[args.Length];
                    for (int intI = 0; intI < argobjects.Length; intI++)
                    {
                        string[] argument = args[intI].Trim().Split(new char[] { ' ' });
                        if (argument.Length == 2)
                        {
                            string[] arArgs;
                            string   strArgumentValue = GetArgumentValue(strName + "_" + intI);
                            string   strArgumentName  = argument[1];
                            string   strArgumentType  = argument[0];
                            switch (strArgumentType)
                            {
                            case "System.String":
                                argobjects[intI] = strArgumentValue;
                                break;

                            case "System.Int32":
                                argobjects[intI] = int.Parse(strArgumentValue);
                                break;

                            case "LSLEditor.SecondLife+Float":
                                argobjects[intI] = new SecondLife.Float(strArgumentValue);
                                break;

                            case "LSLEditor.SecondLife+integer":
                                argobjects[intI] = new SecondLife.integer(int.Parse(strArgumentValue));
                                break;

                            case "LSLEditor.SecondLife+String":
                                argobjects[intI] = new SecondLife.String(strArgumentValue);
                                break;

                            case "LSLEditor.SecondLife+key":
                                argobjects[intI] = new SecondLife.key(strArgumentValue);
                                break;

                            case "LSLEditor.SecondLife+list":
                                argobjects[intI] = new SecondLife.list(new string[] { strArgumentValue });
                                break;

                            case "LSLEditor.SecondLife+rotation":
                                arArgs           = strArgumentValue.Replace("<", "").Replace(">", "").Replace(" ", "").Split(new char[] { ',' });
                                argobjects[intI] = new SecondLife.rotation(double.Parse(arArgs[0]), double.Parse(arArgs[1]), double.Parse(arArgs[2]), double.Parse(arArgs[3]));
                                break;

                            case "LSLEditor.SecondLife+vector":
                                arArgs           = strArgumentValue.Replace("<", "").Replace(">", "").Replace(" ", "").Split(new char[] { ',' });
                                argobjects[intI] = new SecondLife.vector(double.Parse(arArgs[0]), double.Parse(arArgs[1]), double.Parse(arArgs[2]));
                                break;

                            default:
                                MessageBox.Show("Compiler->GetArguments->[" + strArgumentType + "][" + strArgumentName + "]");
                                argobjects[intI] = null;
                                break;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Argument must be 'type name' [" + args[intI] + "]");
                            break;
                        }
                    }
                    objResult = argobjects;
                } catch { }
            }
            return(objResult);
        }
コード例 #3
0
        public static void Request(WebProxy proxy, SecondLife secondlife, string strUrl, SecondLife.list parameters, string postData, SecondLife.key key)
        {
            string strMethod      = "GET";
            string strContentType = "text/plain; charset=utf-8";

            for (int intI = 0; intI < parameters.Count; intI += 2)
            {
                int intKey;
                if (!int.TryParse(parameters[intI].ToString(), out intKey))
                {
                    continue;
                }
                switch (intKey)
                {
                case 0:
                    // get, post, put, delete
                    strMethod = parameters[intI + 1].ToString().ToUpper();
                    break;

                case 1:
                    strContentType = parameters[intI + 1].ToString();
                    break;

                case 2:
                    // HTTP_BODY_MAXLENGTH
                    break;

                case 3:
                    // HTTP_VERIFY_CERT
                    break;

                default:
                    break;
                }
            }

            WebClient wc = new WebClient();

            wc.Headers.Add("Content-Type", strContentType);
            wc.Headers.Add("Accept", "text/*");
            wc.Headers.Add("Accept-Charset", "utf-8; q=1.0, *; q=0.5");
            wc.Headers.Add("Accept-Encoding", "deflate, gzip");
            wc.Headers.Add("User-Agent", "Second Life LSL/1.19.0(12345) (http://secondlife.com)");

            System.Drawing.Point point        = Properties.Settings.Default.RegionCorner;
            SecondLife.vector    RegionCorner = new SecondLife.vector(point.X, point.Y, 0);

            SecondLife.vector pos = secondlife.GetLocalPos;

            wc.Headers.Add("X-SecondLife-Shard", Properties.Settings.Default.XSecondLifeShard);
            wc.Headers.Add("X-SecondLife-Object-Name", secondlife.host.GetObjectName());
            wc.Headers.Add("X-SecondLife-Object-Key", secondlife.host.GetKey().ToString());
            wc.Headers.Add("X-SecondLife-Region", string.Format("{0} ({1}, {2})", Properties.Settings.Default.RegionName, (int)RegionCorner.x, (int)RegionCorner.y));
            wc.Headers.Add("X-SecondLife-Local-Position", string.Format("({0}, {1}, {2})", pos.x, pos.y, pos.z));
            wc.Headers.Add("X-SecondLife-Local-Rotation", "(0.000000, 0.000000, 0.000000, 1.000000)");
            wc.Headers.Add("X-SecondLife-Local-Velocity", "(0.000000, 0.000000, 0.000000)");
            wc.Headers.Add("X-SecondLife-Owner-Name", Properties.Settings.Default.AvatarName);
            wc.Headers.Add("X-SecondLife-Owner-Key", Properties.Settings.Default.AvatarKey);
            wc.Headers.Add("X-Forwarded-For", "127.0.0.1");

            if (proxy != null)
            {
                wc.Proxy = proxy;
            }

            Uri uri = new Uri(strUrl);

            // Basic Authentication scheme, added 28 mrt 2008
            if (uri.UserInfo != "")
            {
                string[] UserInfo = uri.UserInfo.Split(':');
                if (UserInfo.Length == 2)
                {
                    CredentialCache mycache = new CredentialCache();
                    mycache.Add(uri, "Basic",
                                new NetworkCredential(UserInfo[0], UserInfo[1]));
                    wc.Credentials = mycache;
                }
            }


            UserState userState = new UserState(key, secondlife);

            if (strMethod == "POST" || strMethod == "PUT")
            {
                wc.UploadDataCompleted += new UploadDataCompletedEventHandler(wc_UploadDataCompleted);
                wc.UploadDataAsync(uri, strMethod, Encoding.UTF8.GetBytes(postData), userState);
            }
            else
            {
                wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);
                wc.DownloadDataAsync(uri, userState);
            }
        }