示例#1
0
        private static void LoadScripts()
        {
            IsScriptLoaded = true;

            var          assembly     = Assembly.GetExecutingAssembly();
            const string resourceName = "FoE.Farmer.Library.Windows.External.Inject.js";

            using (var stream = assembly.GetManifestResourceStream(resourceName))
                using (var reader = new StreamReader(stream))
                {
                    var result = new StringBuilder(reader.ReadToEnd());
                    var wn     = Requests.WorldName == null ? "null" : $"'{Requests.WorldName}'";

                    result.Insert(0, $"var FoELoginUserName = '******'; var FoELoginPassword = '******'; var FoEWordName = {wn};");
                    result.Replace("FoELoginUserName", AP._f("FoELoginUserName"));
                    result.Replace("FoELoginPassword", AP._f("FoELoginPassword"));
                    result.Replace("FoEWordName", AP._f("FoEWordName"));
                    result.Replace("FoEInit", AP._f("FoEInit"));
                    result.Replace("FoELogin", AP._f("FoELogin"));
                    result.Replace("FoFTimer", AP._f("FoFTimer"));
                    result.Replace("FoEPlay", AP._f("FoEPlay"));

                    Browser.ExecuteScriptAsync(result.ToString());
                }

            //Browser.ExecuteScriptAsync()
        }
示例#2
0
        private void InitBrowser()
        {
#if UI_BROWSER
            Browser            = new ChromiumWebBrowser();
            Browser.WebBrowser = Browser;
            Browser.Address    = new Uri($"https://{Requests.Domain}/").AbsoluteUri;
#else
            Browser = new ChromiumWebBrowser(new Uri($"https://{Requests.Domain}/").AbsoluteUri);
#endif
            ////otherBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
            //otherBrowser.WebBrowser = otherBrowser;
            ////otherBrowser.Address = new Uri("http://api.michalosoft.cz/ResourceService.html").AbsoluteUri;
            //otherBrowser.Address = new Uri(Path.Combine(TempFolder, "OtherResources.html")).AbsoluteUri;

            //otherBrowser.BrowserSettings.DefaultEncoding = "UTF-8";
            //otherBrowser.BrowserSettings.FileAccessFromFileUrls = CefState.Enabled;
            //otherBrowser.BrowserSettings.WindowlessFrameRate = 30;
            //otherBrowser.Margin = new Thickness(10, 113, 10.4, 10.4);
            //otherBrowser.Width = double.NaN;
            //otherBrowser.Height = double.NaN;

            //ResourceInfoGrid.Children.Add(otherBrowser);

            Browser.RegisterAsyncJsObject(AP._f("responseManager"), new RequestObject());
            Browser.BrowserSettings.DefaultEncoding        = "UTF-8";
            Browser.BrowserSettings.FileAccessFromFileUrls = CefState.Enabled;
            Browser.BrowserSettings.WindowlessFrameRate    = 30;

            Browser.RequestHandler = new RequestHandler();
            //Browser.IsBrowserInitializedChanged += (sender, args) =>
            //{
            //    if (Browser.IsBrowserInitialized)
            //    {
            //    }
            //};
            Browser.FrameLoadEnd += (sender, args) =>
            {
                Dispatcher.Invoke(() =>
                {
                    FrameLoaded = true;

                    if (UserName.Text.Length == 0 || Password.Password.Length == 0)
                    {
                        return;
                    }
                    LoadScripts();
                });
            };
            //LoadScripts();

#if UI_BROWSER
            BrowserGrid.Children.Add(Browser);
#else
            BrowserTabItem.Visibility = Visibility.Collapsed;
#endif
        }
示例#3
0
        public static async void SendRequest(Payload payload)
        {
            Manager.Log("Request sent: " + payload.ToString(), LogMessageType.Request);
            var data      = "[" + payload + "]";
            var signature = Requests.BuildSignature(data);
            var script    = $"(async () => {AP._f("responseManager")}.setData(JSON.stringify(await {AP._f("sendRequest")}('{data}', '{signature}')), '{signature}') )();";

            payloads.Add(signature, payload);
            await Browser.EvaluateScriptAsync(script);
        }
示例#4
0
        private static void LoadRequestString()
        {
            var FncSend = "function " + AP._f("sendRequest") + "(data, signature){return new Promise((r, c) => {$.ajax({type: 'POST',url: '/game/json?h=" + Requests.UserKey + "', data: data, contentType: 'application/json', dataType: 'json', beforeSend: (xhr) => {" +
                          "xhr.setRequestHeader('Signature', signature);" +
                          $"xhr.setRequestHeader('Client-Identification', '{Requests.TemplateRequestHeader["Client-Identification"]}');" +
                          //$"xhr.setRequestHeader('X-Requested-With', '{Requests.TemplateRequestHeader["X-Requested-With"]}');" +
                          "},success: function(result) {r(result);},error: function(result) { c(result);}});});}";

            Browser.ExecuteScriptAsync(FncSend);
            ForgeOfEmpires.Manager.IsInitialized = true;
        }