public async Task <IActionResult> PutLiveGame(int id, LiveGame liveGame) { if (id != liveGame.Id) { return(BadRequest()); } _context.Entry(liveGame).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LiveGameExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void On(LoginService.Logout_Server logout) { var name = logout.creds.username; if (gamesByUsername.ContainsKey(name)) { Log.Info($"On(Logout_Server): user {name} being logged out next tick"); LiveGame live = gamesByUsername[name]; loggedOut.Add(live); } else { Log.Warning($"On(Logout_Server): user {name} never bound to a LiveGame!"); } }
/// <summary> Callback every global server tick </summary> /// <param name="delta"> Delta between last tick and 'now' </param> public override void OnTick(float delta) { if (liveGames.Count > 0) { LiveGame peek = liveGames.Peek(); TimeSpan diff = DateTime.UtcNow - peek.lastUpdate; while (diff.TotalSeconds > TickTime && liveGames.Count > 0) { LiveGame next = liveGames.Peek(); Guid id = next.creds.userId; string name = next.creds.username; diff = DateTime.UtcNow - next.lastUpdate; if (diff.TotalSeconds < TickTime) { break; } try { next = liveGames.Pop(); next.Updated(); Log.Info($"Ticking {name}'s game data. ID={id}"); // Actual tick logic goes here: next.state.stats.baseExp += 1; gameStateDB.Save($"{id}", next.state); } catch (Exception e) { Log.Warning($"Game.OnTick: Error during tick", e); } finally { if (loggedOut.Contains(next)) { Log.Info($"Stopping ticks for {name}"); gamesByGUID.Remove(id); gamesByUsername.Remove(name); loggedOut.Remove(next); } else { liveGames.Push(next); } } } } }
public async Task <ActionResult <LiveGame> > PostLiveGame(LiveGame liveGame) { _context.LiveGame.Add(liveGame); await _context.SaveChangesAsync(); var tokens = await _context.Token.ToListAsync <PushToken>(); var registrationTokens = tokens.Select(c => c.Token).ToList(); var request = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send"); request.Headers.TryAddWithoutValidation("Authorization", "key=AAAAxDTznoQ:APA91bGacTqXyAHk6KW98J9AWDLPaxu_e8hma4sB5KYJ7KDKFt7gKenAyzRKxE-ToyY2ggMM7oaUVZ9tv389TAowSV0RfVRWFVaM1UI02Aq0VGnDUcH1-nnHflXZn6EGPVIId8_DNOdl"); request.Headers.TryAddWithoutValidation("Content-Type", "application/json"); var tokenModel = new TokenModel { Tokens = registrationTokens, ContentAvailable = true, NotificationPush = new TokenModel.Notification { Title = "Teste C#", Body = "Body C#" }, DataPush = new TokenModel.Data { Extra = Newtonsoft.Json.JsonConvert.SerializeObject(liveGame) } }; var tokenJson = Newtonsoft.Json.JsonConvert.SerializeObject(tokenModel); request.Content = new StringContent(tokenJson, Encoding.UTF8, "application/json"); var client = _clientFactory.CreateClient(); var response = await client.SendAsync(request); string pushResponse = ""; if (response.IsSuccessStatusCode) { pushResponse = await response.Content.ReadAsStringAsync(); } return(CreatedAtAction("GetLiveGame", new { id = liveGame.Id, pushResponse }, liveGame)); }
public void On(LoginService.LoginSuccess_Server succ) { LiveGame live = new LiveGame(succ.creds); gamesByUsername[succ.creds.username] = live; gamesByGUID[succ.creds.userId] = live; liveGames.Push(live); var game = live.state; var createEntity = new EntityService.CreateEntityForUser(); createEntity.userId = succ.creds.userId; server.On(createEntity); var ctrl = entity.AddComponent <Control>(succ.client.id); ctrl.mode = game.controlMode; ctrl.Send(); }
public IActionResult GetLiveMatches() { var client = new RestClient($"https://api.pandascore.co//lives?per_page=10&token=" + _token); var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); TextInfo myTI = new CultureInfo("sv-SE", false).TextInfo; if (response.IsSuccessful) { var content = JsonConvert.DeserializeObject <JToken>(response.Content); List <LiveGame> liveGames = new List <LiveGame>(); foreach (var item in content) { var match = item["match"]; var league = new League { Id = (int)match["league"]["id"], ImgUrl = (string)match["league"]["image_url"], Name = (string)match["league"]["name"], Slug = (string)match["league"]["slug"], Url = (string)"" }; var opponentOne = new Team { Id = (int)match["opponents"][0]["opponent"]["id"], Acronym = (string)match["opponents"][0]["opponent"]["acronym"], Name = (string)match["opponents"][0]["opponent"]["name"], ImgUrl = (string)match["opponents"][0]["opponent"]["image_url"] }; var opponentTwo = new Team { Id = (int)match["opponents"][1]["opponent"]["id"], Acronym = (string)match["opponents"][1]["opponent"]["acronym"], Name = (string)match["opponents"][1]["opponent"]["name"], ImgUrl = (string)match["opponents"][1]["opponent"]["image_url"] }; var live = new LiveGame { id = (int)item["event"]["id"], startDate = (string)match["begin_at"], isActive = (bool)match["live"]["supported"], matchType = (string)match["match_type"], streamUrl = (string)match["live_embed_url"], linkUrl = (string)match["live_url"], draw = (bool)match["draw"], forfeit = (bool)match["forfeit"], opponentOne = opponentOne, opponentTwo = opponentTwo, opponentOneResult = (int)match["results"][0]["score"], opponentTwoResult = (int)match["results"][1]["score"], numberOfGames = (int)match["number_of_games"], season = (string)match["tournament"]["name"], name = (string)match["league"]["name"], league = league, status = (string)match["status"], Videogame = ((string)item["event"]["game"]).Replace("-", " ") }; live.Videogame = myTI.ToTitleCase(live.Videogame); liveGames.Add(live); } return(Ok(liveGames)); } System.Diagnostics.Debug.WriteLine("Connection not possible"); return(BadRequest()); }