コード例 #1
0
        private IEnumerator DoFollowerNetworkActivityWork()
        {
            LogMessage(" :::::::: DoFollowerNetworkActivityWork called", 1);

            int timeoutInSeconds = 3;

            string url = Settings.NetworkActivityUrl.Value;

            if (string.IsNullOrEmpty(url) || !_networkRequestFinished)
            {
                LogMessage(" :::::::: DoFollowerNetworkActivityWork BREAKING", 1);
                yield break;
            }

            _networkRequestFinished = false;

            HttpClient.Timeout = TimeSpan.FromSeconds(timeoutInSeconds); // Always set a short timeout
            try
            {
                LogMessage(" :::::::: Firing a request", 1);

                var callback = new Action <string>((reply) =>
                {
                    NetworkActivityObject networkActivityObject =
                        JsonConvert.DeserializeObject <NetworkActivityObject>(reply);
                    ProcessNetworkActivityResponse(networkActivityObject);
                });
                _networkHelper.MakeGetNetworkRequest(url, timeoutInSeconds, LogMessage, callback);
            }
            finally
            {
                //LogMessage(" :::::::: Network request finished", 1);
                _networkRequestFinished = true;
            }
        }
コード例 #2
0
        public void MakeAsyncListen(HttpListener listener)
        {
            IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);

            void ListenerCallback(IAsyncResult res)
            {
                HttpListener list = (HttpListener)res.AsyncState;

                HttpListenerContext context;

                try
                {
                    context = list.EndGetContext(res);
                }
                catch (Exception e)
                {
                    // Probably listener was closed so everything is OK
                    return;
                }

                HttpListenerRequest req = context.Request;
                // Obtain a response object.
                HttpListenerResponse response = context.Response;
                // Construct a response.

                NetworkActivityObject networkActivityObject = new NetworkActivityObject(
                    _followerSettings.NetworkActivityPropagateWorking.Value,
                    FollowerType.Follower,
                    _followerSettings.NetworkActivityPropagateLeaderName.Value,
                    _followerSettings.NetworkActivityPropagateUseMovementSkill.Value,
                    _followerSettings.NetworkActivityPropagateMovementSkillKey.Value,
                    GetFollowerSkills(),
                    _followerSettings.PropagateFollowerAggressiveness,
                    _followerSettings.PropagateEnterInstance
                    );

                // Construct a response.
                string responseString = JsonConvert.SerializeObject(networkActivityObject);

                ;
                byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                // Get a response stream and write the response to it.
                response.ContentLength64 = buffer.Length;
                System.IO.Stream output = response.OutputStream;
                output.Write(buffer, 0, buffer.Length);
                // You must close the output stream.
                output.Close();
            }
        }
コード例 #3
0
        private void ProcessNetworkActivityResponse(NetworkActivityObject activityObj)
        {
            if (activityObj == null)
            {
                return;
            }

            Settings.LeaderName.Value       = activityObj.LeaderName;
            Settings.UseMovementSkill.Value = activityObj.UseMovementSkill;
            _currentFollowerMode            = activityObj.FollowerMode;
            _followerAggressivenessMode     = activityObj.PropagateFollowerAggressiveness;
            _followerShouldWork             = activityObj.Working;
            _enterInstanceValue             = activityObj.PropagateEnterInstance;

            if (activityObj.Working)
            {
                _followerCoroutine.Resume();
            }
            else
            {
                _followerCoroutine.Pause();
            }

            if (activityObj.FollowerSkills != null && activityObj.FollowerSkills.Any())
            {
                List <SkillSettings> settingsSkills = new List <SkillSettings>()
                {
                    Settings.SkillOne,
                    Settings.SkillTwo,
                    Settings.SkillThree
                };
                foreach (FollowerSkill skill in activityObj.FollowerSkills.OrderBy(o => o.Position))
                {
                    SkillSettings settingsSkill = settingsSkills[skill.Position - 1];

                    settingsSkill.Enable.Value               = skill.Enable;
                    settingsSkill.SkillHotkey.Value          = skill.Hotkey;
                    settingsSkill.UseAgainstMonsters.Value   = skill.UseAgainstMonsters;
                    settingsSkill.CooldownBetweenCasts.Value = skill.Cooldown.ToString();
                    settingsSkill.Priority.Value             = skill.Priority;
                    settingsSkill.Position.Value             = skill.Position;
                    settingsSkill.Range.Value = skill.Range;
                }
            }

            return;
        }