Example #1
0
        public static async Task NewDay()
        {
            if (!_instance.isServerActive)
            {
                return;
            }
            LogInfo("NewDay");
            Day    day  = new Day();
            string json = JsonConvert.SerializeObject(day);

            using (var client = new HttpClient())
            {
                string url      = _instance.url + _instance.gameId.ToString() + "/days/";
                var    content  = new StringContent(json, Encoding.UTF8);
                var    response = await client.PostAsync(url, content);

                if (response.IsSuccessStatusCode)
                {
                    string data = await response.Content.ReadAsStringAsync();

                    ResDay retDay = JsonConvert.DeserializeObject <ResDay>(data);
                    _instance.dayId = retDay.dayId;
                }
                else
                {
                    _instance.isServerActive = false;
                }
            }
            TimerCallback tc = new TimerCallback(OnTimedEvent);

            _instance.timer     = new Timer(tc, null, 0, 100);
            _instance.isRunning = true;
            return;
        }
Example #2
0
        public static async Task EndDay()
        {
            if (!_instance.isServerActive)
            {
                return;
            }
            LogInfo("EndDay");
            // フレームキャプチャの定期実行を停止
            if (_instance.isRunning)
            {
                _instance.timer.Dispose();
                _instance.isRunning = false;
            }
            // 溜めていたフレームを強制アップロード
            NewFrame(true);

            // 死んだプレイヤーと追放されたプレイヤーを更新
            using (var client = new HttpClient())
            {
                string url      = _instance.url + _instance.gameId.ToString() + "/days/" + _instance.dayId.ToString() + "/";
                var    response = await client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    string data = await response.Content.ReadAsStringAsync();

                    ResDay retDay = JsonConvert.DeserializeObject <ResDay>(data);
                    retDay.deadPlayers   = JsonConvert.SerializeObject(_instance.deadPlayers);
                    retDay.exiledPlayers = JsonConvert.SerializeObject(_instance.exiledPlayers);
                    LogInfo("Update deadPlayers: " + retDay.deadPlayers);
                    LogInfo("Update exiledPlayers: " + retDay.exiledPlayers);
                    string json    = JsonConvert.SerializeObject(retDay);
                    var    content = new StringContent(json, Encoding.UTF8);
                    response = await client.PutAsync(url, content);

                    if (!response.IsSuccessStatusCode)
                    {
                        LogInfo("Error:Update Day");
                    }
                }
                else
                {
                    _instance.isServerActive = false;
                }
            }
        }