Esempio n. 1
0
        public void Work(NetworkActivityObject obj)
        {
            LogMsg("Server.Work called");
            _obj = obj;

            if (_serverIsListening)
            {
                LogMsg("Server._serverIsListening is true, skipping");
                return;
            }

            if (!_httpListener.IsListening)
            {
                LogMsg("HttpListener is not listening, skipping");
                return;
            }

            LogMsg("Server._serverIsListening is false, starting server listening");

            _serverIsListening = true;

            try
            {
                IAsyncResult result = _httpListener.BeginGetContext(new AsyncCallback(ListenerCallback), _httpListener);
            }
            finally
            {
                _serverIsListening = false;
            }
        }
Esempio n. 2
0
        private void ProcessNetworkActivityResponse(NetworkActivityObject obj)
        {
            LogMsgWithVerboseDebug("ProcessNetworkActivityResponse called");

            if (obj == null)
            {
                return;
            }

            Settings.FollowerModeSettings.FollowerShouldWork          = obj.FollowersShouldWork;
            Settings.FollowerModeSettings.LeaderName.Value            = obj.LeaderName;
            Settings.FollowerModeSettings.LeaderProximityRadius.Value = obj.LeaderProximityRadius;

            string selfName = GameController.EntityListWrapper.Player.GetComponent <Player>().PlayerName;
            var    follower = obj.FollowerCommandSettings.FollowerCommandsDataSet.First(f => f.FollowerName == selfName);

            if (follower == null)
            {
                return;
            }

            _followerState.LastTimeEntranceUsedDateTime     = follower.LastTimeEntranceUsedDateTime;
            _followerState.LastTimePortalUsedDateTime       = follower.LastTimePortalUsedDateTime;
            _followerState.LastTimeQuestItemPickupDateTime  = follower.LastTimeQuestItemPickupDateTime;
            _followerState.LastTimeNormalItemPickupDateTime = follower.LastTimeNormalItemPickupDateTime;
            _followerState.LastTimeNormalItemPickupDateTime = follower.LastTimeNormalItemPickupDateTime;
            _followerState.NormalItemId = follower.NormalItemId;
        }
Esempio n. 3
0
        private IEnumerator DoFollowerNetworkActivityWork()
        {
            LogMsgWithVerboseDebug("DoFollowerNetworkActivityWork called");

            string url       = Settings.FollowerModeSettings.FollowerModeNetworkSettings.Url.Value;
            int    timeoutMs = Settings.FollowerModeSettings.FollowerModeNetworkSettings.RequestTimeoutMs.Value;

            if (string.IsNullOrEmpty(url))
            {
                LogMsgWithVerboseDebug("    url in DoFollowerNetworkActivityWork was null or empty");
                yield break;
            }

            if (_networkRequestStatusRetries > 5)
            {
                _networkRequestStatus = NetworkRequestStatus.Finished;
            }

            if (_networkRequestStatus == NetworkRequestStatus.Working)
            {
                LogMsgWithVerboseDebug("    request has not been finished in DoFollowerNetworkActivityWork");
                _networkRequestStatusRetries++;
                yield break;
            }

            _networkRequestStatus = NetworkRequestStatus.Working;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method  = "GET";
            request.Timeout = timeoutMs;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            try
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream       stream = response.GetResponseStream();
                    StreamReader reader = new StreamReader(stream);
                    string       reply  = reader.ReadToEnd();

                    NetworkActivityObject networkActivityObject = JsonConvert.DeserializeObject <NetworkActivityObject>(reply);
                    ProcessNetworkActivityResponse(networkActivityObject);
                }
                else
                {
                    LogMsgWithVerboseDebug(
                        $"Follower - tried to make a HTTP request to {url} but the return message was not successful");
                }
            }
            finally
            {
                _networkRequestStatus = NetworkRequestStatus.Finished;
            }

            yield break;
        }
Esempio n. 4
0
        public void Work(NetworkActivityObject obj)
        {
            LogMsg("Server.Work called");

            if (_serverIsListening)
            {
                LogMsg("Server._serverIsListening is true, skipping");
                return;
            }

            if (!_httpListener.IsListening)
            {
                LogMsg("HttpListener is not listening, skipping");
                return;
            }

            LogMsg("Server._serverIsListening is false, starting server listening");

            _serverIsListening = true;

            try
            {
                // SYNC WORKING SERVER
                HttpListenerContext  context  = _httpListener.GetContext();
                HttpListenerRequest  request  = context.Request;
                HttpListenerResponse response = context.Response;
                byte[] buffer = { };
                response.ContentLength64 = 0;
                response.StatusCode      = (int)HttpStatusCode.OK;

                if (request.HttpMethod == "GET")
                {
                    string responseString = JsonConvert.SerializeObject(obj);

                    buffer = Encoding.UTF8.GetBytes(responseString);
                    response.ContentLength64 = buffer.Length;
                }

                Stream output = response.OutputStream;
                output.Write(buffer, 0, buffer.Length);
                output.Close();
                // SYNC WORKING SERVER ENDS
            }
            finally
            {
                _serverIsListening = false;
            }
        }
Esempio n. 5
0
 public void Work(NetworkActivityObject obj)
 {
     // This will overwrite the existing file
     File.WriteAllText(GetFileName(), JsonConvert.SerializeObject(obj));
 }