public GameId(string id) { Game = null; StatusCode = HttpStatusCode.OK; if (string.IsNullOrEmpty(id)) { StatusCode = HttpStatusCode.NotFound; Message = "You must provide a game id."; return; } if (Games == null || !Games.ContainsKey(id)) { StatusCode = HttpStatusCode.NotFound; Message = $"Game {id} doesn't exist."; return; } Game = Games[id]; if (Game.IsVoid) { Game = null; StatusCode = HttpStatusCode.NotAcceptable; Message = $"Player 1 is undefined, making the game {id} void." + Environment.NewLine + "Please start a new game."; } }
public async Task ProccessMessage(User user, string gameId, string message) { if (Games.ContainsKey(gameId)) { Games[gameId].chat += message; } }
private string Load(string opt) { if (Games.ContainsKey(opt)) { GameId = opt; return("Loaded Game!"); } return("Invalid Slot"); }
public Game Join(Player player, string world) { if (!Games.ContainsKey(player.Level.LevelId)) { Games.Add(player.Level.LevelId, new Game(this) { Name = player.Level.LevelId, Level = player.Level, State = GameState.Undefined }); } if (!Games.ContainsKey(world)) { if (!GameTemplates.ContainsKey(world)) { return(null); } GameSettings settings = GameTemplates[world]; Level gameLevel = new Level(settings.Name, new AnvilWorldProvider(settings.ArenaWorldPath)); gameLevel.Initialize(); var spawn = gameLevel.SpawnPoint; if (!world.Equals("Default")) { gameLevel.SpawnPoint = new BlockCoordinates { X = spawn.X, Y = spawn.Y + 20, Z = spawn.Z, }; } Games.Add(world, new Game(this) { Name = world, Level = gameLevel, State = GameState.WaitingToStart }); } Game currentGame = Games[player.Level.LevelId]; Game game = Games[world]; if (game.State == GameState.Started || game.State == GameState.Finshed) { return(currentGame); } currentGame.RemovePlayer(player); game.AddPlayer(player); player.SpawnLevel(game.Level); game.Level.BroadcastTextMessage(string.Format("{0} joined game <{1}>.", player.Username, game.Name)); return(game); }
public StatusResult GetGameStatus(int gameId) { if (!Games.ContainsKey(gameId)) { return(null); } var game = Games[gameId]; var result = game.GetStatus(null); return(result); }
void OnFinish(ChannelIdType channelId) { if (Games.ContainsKey(channelId)) { var players = Games[channelId].InitialPlayers; foreach (var player in players) { GamesByUsers.Remove(player.Id, out _); } Games.Remove(channelId, out _); } }
Task GuildMemberAdded(GuildMemberAddEventArgs _) { var defaultChannel = _.Guild.GetDefaultChannel(); if (_.Guild.Channels.Any(_ => Games.ContainsKey(_.Id))) { return(defaultChannel.SendMessageAsync("`게임이 진행중입니다. 게임에 참여하려면 BOT restart @참가인원1 @참가인원2...로 게임을 다시 시작해야 합니다.`")); } else { return(defaultChannel.SendMessageAsync("`BOT start @참가인원1 @참가인원2... 로 게임을 시작할 수 있습니다.`")); } }
protected void Page_Load(object sender, EventArgs e) { // We store the game in the Session, but use a dictionary keyed by GUIDs which // are stored in the ViewState. This allows the same user in the same browser // to open multiple games in different browser tabs. if (Games == null) { Games = new Dictionary <string, PlayerHandler>(); } if (OutputBuffers == null) { OutputBuffers = new Dictionary <string, OutputBuffer>(); } if (Resources == null) { Resources = new SessionResources(); } m_gameId = (string)ViewState["GameId"]; if (m_gameId == null) { m_gameId = Guid.NewGuid().ToString(); ViewState["GameId"] = m_gameId; } if (Page.IsPostBack) { if (Games.ContainsKey(m_gameId)) { m_player = Games[m_gameId]; } if (!OutputBuffers.ContainsKey(m_gameId)) { // TO DO: Think this only ever happens while debugging? return; } m_buffer = OutputBuffers[m_gameId]; } else { m_buffer = new OutputBuffer(m_gameId); OutputBuffers.Add(m_gameId, m_buffer); m_buffer.AddJavaScriptToBuffer("setOutputBufferId", new StringParameter(m_gameId)); } }
/// <summary> /// Adds a match to the GamesPerServerMap list of games that a particular server is tracking /// </summary> /// <param name="serverName">the name of the server to register this game under</param> /// <param name="game">the game to register</param> /// <param name="lockData">if the match data should be thread-synchronized. set yes, if you know this method is called first in the stack (i.e. when you're calling it as a response to an inbound packet). Using the wrong will value will decrease performance as unnecessary thread Monitors will be set</param> public bool CreateNewGame(GameServerGame game, bool lockData) { if (lockData) { Monitor.Enter(MatchDataLock); } try { if (GameCreationRequest != null) { if (!GameCreationRequest(game)) { return(false); } } if (Games.ContainsKey(game.GameID)) { // hm. we already know about that game. probably not great. #if DEBUG throw new ArgumentException("Tried AddGameToServerTracking for a game that we alrady knew about."); #endif return(false); } Games.Add(game.GameID, game); m_TotalProjectedPlayerCount += (game.MaxPlayers + game.MaxObservers); Log1.Logger("Server").Debug("Padded connection count for server is now [" + m_TotalProjectedPlayerCount + "]."); Log1.Logger("Server").Info("After adding this one, we are tracking [" + Games.Count.ToString() + " games] on this server now."); if (GameCreated != null) { GameCreated(game); } } catch { return(false); } finally { if (lockData) { Monitor.Exit(MatchDataLock); } } return(true); }
protected GameFile GetGameFile(FileEntry entry, bool parse = false) { if (!Games.ContainsKey(entry)) { var file = ExtractFile(entry); return(CreateGameFileModel(entry, file, parse)); } var game = Games[entry]; if (parse && !game.IsParsed) { game.Parse(); } return(game); }
public async Task <string> Decline(string name, string id) { int mmid = int.Parse(id); if (MMplayers[name].Game != null) { if (MMplayers[name].Game.ID == mmid) { lock (MMplayers[name].Game) { MMplayers[name].Game.Declined = true; foreach (var pl in GameList(MMplayers[name].Game)) { if (pl.Accepted == true) { pl.Accepted = false; EnqueueDeclined(pl.Name); } } } } } else if (Games.ContainsKey(mmid)) { lock (Games[mmid]) { Games[mmid].Declined = true; foreach (var pl in GameList(Games[mmid])) { if (pl.Accepted == true) { pl.Accepted = false; EnqueueDeclined(pl.Name); } } } } await ExitQ(name); return("Sad :("); }
public async Task <MMgame> Status(string id) { int mmid = int.Parse(id); /** * if (Games.ContainsKey(mmid)) * { * var json = JsonConvert.SerializeObject(Games[mmid], Formatting.Indented); * _logger.LogInformation(json); * } **/ if (!Games.ContainsKey(mmid)) { return(null); } else { return(Games[mmid]); } }
public async Task ProccessConnection(User u, GameOptions o, string socketId) { if (o.isHost) { Game g = new Game(); g.gameEnd = false; g.host = u; g.id = o.gameKey; g.hostCS = socketId; g.board = SetFgrsOnStart(); g.options = o; g.history = GetLogMove(string.Format("{0} connected successfuly!", u.login)); g.moveCount = 0; Games[o.gameKey] = g; } else { if (!Games.ContainsKey(o.gameKey)) { object[] mess = new object[1]; mess[0] = "Game with this id does not exist"; await Startup.gameHandler.InvokeClientMethodAsync(socketId, "sendmess", mess); } else { if (u.userId == Games[o.gameKey].host.userId) { Games[o.gameKey].hostCS = socketId; Games[o.gameKey].history += GetLogMove(string.Format("{0} connected successfuly!", u.login)); } else { Games[o.gameKey].guest = u; Games[o.gameKey].guestCS = socketId; Games[o.gameKey].history += GetLogMove(string.Format("{0} connected successfuly!", u.login)); } } } }
/// <summary> /// Gets a list of tags found on games, sorted by a popularity score. /// </summary> /// <param name="filter"> /// GameList including games to include in the search. If null, finds tags for all games in the /// database. /// </param> /// <param name="weightFactor"> /// Value of the popularity score contributed by the first processed tag for each game. Each subsequent tag contributes /// less to its own score. /// The last tag always contributes 1. Value less than or equal to 1 indicates no weighting. /// </param> /// <param name="minScore">Minimum score of tags to include in the result list. Tags with lower scores will be discarded.</param> /// <param name="tagsPerGame"> /// Maximum tags to find per game. If a game has more tags than this, they will be discarded. 0 /// indicates no limit. /// </param> /// <returns>List of tags, as strings</returns> public IEnumerable <Tuple <string, float> > CalculateSortedTagList(GameList filter, float weightFactor, int minScore, int tagsPerGame, bool excludeGenres, bool scoreSort) { SortedSet <string> genreNames = AllGenres(); Dictionary <string, float> tagCounts = new Dictionary <string, float>(); if (filter == null) { foreach (DatabaseEntry dbEntry in Games.Values) { CalculateSortedTagListHelper(tagCounts, dbEntry, weightFactor, tagsPerGame); } } else { foreach (int gameId in filter.Games.Keys) { if (Games.ContainsKey(gameId) && !filter.Games[gameId].Hidden) { CalculateSortedTagListHelper(tagCounts, Games[gameId], weightFactor, tagsPerGame); } } } if (excludeGenres) { foreach (string genre in genreNames) { tagCounts.Remove(genre); } } IEnumerable <Tuple <string, float> > unsortedList = from entry in tagCounts where entry.Value >= minScore select new Tuple <string, float>(entry.Key, entry.Value); IOrderedEnumerable <Tuple <string, float> > sortedList = scoreSort ? from entry in unsortedList orderby entry.Item2 descending select entry : from entry in unsortedList orderby entry.Item1 select entry; return(sortedList.ToList()); }
public static Game CreateGame(bool is906) { PiecePlaces = ""; int rook1Pos = 0; int rook2Pos = 0; int bishop1Pos = 0; int bishop2Pos = 0; int knight1Pos = 0; int knight2Pos = 0; int kingPos = 0; int queenPos = 0; Random rand = new Random(); List <int> positions = new List <int>() { 0, 1, 2, 3, 4, 5, 6, 7 }; kingPos = rand.Next(1, 6); positions.Remove(kingPos); if (kingPos == 1) { rook1Pos = 0; positions.Remove(0); rook2Pos = positions[rand.Next(0, positions.Count - 1)]; positions.Remove(rook2Pos); } else { rook1Pos = positions[rand.Next(0, positions.Count - 1)]; while (rook1Pos > kingPos) { rook1Pos = positions[rand.Next(0, positions.Count - 1)]; } positions.Remove(rook1Pos); rook2Pos = positions[rand.Next(0, positions.Count - 1)]; while (rook2Pos < kingPos) { rook2Pos = positions[rand.Next(0, positions.Count - 1)]; } positions.Remove(rook2Pos); } bool blackSpot = false; bishop1Pos = positions[rand.Next(0, positions.Count - 1)]; positions.Remove(bishop1Pos); if (bishop1Pos % 2 != 0) { blackSpot = true; } if (blackSpot) { bishop2Pos = positions[rand.Next(0, positions.Count - 1)]; while (bishop2Pos % 2 != 0) { bishop2Pos = positions[rand.Next(0, positions.Count - 1)]; } } else { bishop2Pos = positions[rand.Next(0, positions.Count - 1)]; while (bishop2Pos % 2 == 0) { bishop2Pos = positions[rand.Next(0, positions.Count - 1)]; } } positions.Remove(bishop2Pos); knight1Pos = positions[rand.Next(0, positions.Count - 1)]; positions.Remove(knight1Pos); knight2Pos = positions[rand.Next(0, positions.Count - 1)]; positions.Remove(knight2Pos); queenPos = positions[0]; positions.Clear(); List <string> all = new List <string>() { }; switch (kingPos) { case 1: all.Add("b1-wk"); break; case 2: all.Add("c1-wk"); break; case 3: all.Add("d1-wk"); break; case 4: all.Add("e1-wk"); break; case 5: all.Add("f1-wk"); break; case 6: all.Add("g1-wk"); break; } switch (queenPos) { case 0: all.Add("a1-wq"); break; case 1: all.Add("b1-wq"); break; case 2: all.Add("c1-wq"); break; case 3: all.Add("d1-wq"); break; case 4: all.Add("e1-wq"); break; case 5: all.Add("f1-wq"); break; case 6: all.Add("g1-wq"); break; case 7: all.Add("h1-wq"); break; } switch (rook1Pos) { case 0: all.Add("a1-wr"); break; case 1: all.Add("b1-wr"); break; case 2: all.Add("c1-wr"); break; case 3: all.Add("d1-wr"); break; case 4: all.Add("e1-wr"); break; case 5: all.Add("f1-wr"); break; case 6: all.Add("g1-wr"); break; case 7: all.Add("h1-wr"); break; } switch (rook2Pos) { case 0: all.Add("a1-wr"); break; case 1: all.Add("b1-wr"); break; case 2: all.Add("c1-wr"); break; case 3: all.Add("d1-wr"); break; case 4: all.Add("e1-wr"); break; case 5: all.Add("f1-wr"); break; case 6: all.Add("g1-wr"); break; case 7: all.Add("h1-wr"); break; } switch (bishop1Pos) { case 0: all.Add("a1-wb"); break; case 1: all.Add("b1-wb"); break; case 2: all.Add("c1-wb"); break; case 3: all.Add("d1-wb"); break; case 4: all.Add("e1-wb"); break; case 5: all.Add("f1-wb"); break; case 6: all.Add("g1-wb"); break; case 7: all.Add("h1-wb"); break; } switch (bishop2Pos) { case 0: all.Add("a1-wb"); break; case 1: all.Add("b1-wb"); break; case 2: all.Add("c1-wb"); break; case 3: all.Add("d1-wb"); break; case 4: all.Add("e1-wb"); break; case 5: all.Add("f1-wb"); break; case 6: all.Add("g1-wb"); break; case 7: all.Add("h1-wb"); break; } switch (knight1Pos) { case 0: all.Add("a1-wn"); break; case 1: all.Add("b1-wn"); break; case 2: all.Add("c1-wn"); break; case 3: all.Add("d1-wn"); break; case 4: all.Add("e1-wn"); break; case 5: all.Add("f1-wn"); break; case 6: all.Add("g1-wn"); break; case 7: all.Add("h1-wn"); break; } switch (knight2Pos) { case 0: all.Add("a1-wn"); break; case 1: all.Add("b1-wn"); break; case 2: all.Add("c1-wn"); break; case 3: all.Add("d1-wn"); break; case 4: all.Add("e1-wn"); break; case 5: all.Add("f1-wn"); break; case 6: all.Add("g1-wn"); break; case 7: all.Add("h1-wn"); break; } all = all.OrderBy(x => x).ToList(); var game = new Game(); if (is906) { game = new Game { Id = Guid.NewGuid().GetHashCode(), WhitePlayerIdentifier = Guid.NewGuid().GetHashCode(), BlackPlayerIdentifier = Guid.NewGuid().GetHashCode(), Moves = new List <string>(), Pieces = new Dictionary <string, string> { { "a1", $"w{all[0][4]}" }, { "b1", $"w{all[1][4]}" }, { "c1", $"w{all[2][4]}" }, { "d1", $"w{all[3][4]}" }, { "e1", $"w{all[4][4]}" }, { "f1", $"w{all[5][4]}" }, { "g1", $"w{all[6][4]}" }, { "h1", $"w{all[7][4]}" }, { "a2", "wp" }, { "b2", "wp" }, { "c2", "wp" }, { "d2", "wp" }, { "e2", "wp" }, { "f2", "wp" }, { "g2", "wp" }, { "h2", "wp" }, { "a8", $"b{all[0][4]}" }, { "b8", $"b{all[1][4]}" }, { "c8", $"b{all[2][4]}" }, { "d8", $"b{all[3][4]}" }, { "e8", $"b{all[4][4]}" }, { "f8", $"b{all[5][4]}" }, { "g8", $"b{all[6][4]}" }, { "h8", $"b{all[7][4]}" }, { "a7", "bp" }, { "b7", "bp" }, { "c7", "bp" }, { "d7", "bp" }, { "e7", "bp" }, { "f7", "bp" }, { "g7", "bp" }, { "h7", "bp" } } }; } else { game = new Game { Id = Guid.NewGuid().GetHashCode(), WhitePlayerIdentifier = Guid.NewGuid().GetHashCode(), BlackPlayerIdentifier = Guid.NewGuid().GetHashCode(), Moves = new List <string>(), Pieces = new Dictionary <string, string> { { "a1", "wr" }, { "b1", "wn" }, { "c1", "wb" }, { "d1", "wq" }, { "e1", "wk" }, { "f1", "wb" }, { "g1", "wn" }, { "h1", "wr" }, { "a2", "wp" }, { "b2", "wp" }, { "c2", "wp" }, { "d2", "wp" }, { "e2", "wp" }, { "f2", "wp" }, { "g2", "wp" }, { "h2", "wp" }, { "a8", "br" }, { "b8", "bn" }, { "c8", "bb" }, { "d8", "bq" }, { "e8", "bk" }, { "f8", "bb" }, { "g8", "bn" }, { "h8", "br" }, { "a7", "bp" }, { "b7", "bp" }, { "c7", "bp" }, { "d7", "bp" }, { "e7", "bp" }, { "f7", "bp" }, { "g7", "bp" }, { "h7", "bp" } } }; } if (Games.ContainsKey(game.Id)) { throw new Exception("Game already exists."); } Games.Add(game.Id, game); foreach (string item in all) { PiecePlaces += $"{item[4]}-"; } PiecePlaces.TrimEnd('-'); return(game); }
public async Task <MMgame> Report(dsreplay replay, string id) { MMgame mmgame = new MMgame(); int gid = int.Parse(id); if (Replays.ContainsKey(gid)) { Replays[gid].Add(replay); } else { Replays.TryAdd(gid, new ConcurrentBag <dsreplay>()); Replays[gid].Add(replay); } Save(Games[gid], replay); lock (Games) { if (Games.ContainsKey(gid)) { if (Games[gid].Reported == true) { return(Games[gid]); } } replay.GenHash(); if (ReplayHash.Contains(replay.HASH)) { //return null; } else { ReplayHash.Add(replay.HASH); } List <MMplayer> team1 = new List <MMplayer>(); List <MMplayer> team2 = new List <MMplayer>(); foreach (var pl in replay.PLAYERS) { MMplayer mmpl = new MMplayer(); if (MMplayers.ContainsKey(pl.NAME)) { mmpl = MMplayers[pl.NAME]; } else { mmpl.Name = "Dummy"; } if (pl.TEAM == replay.WINNER) { team1.Add(mmpl); } else { team2.Add(mmpl); } } MMgame repgame = new MMgame(); repgame = MMrating.RateGame(team1, team2); repgame.ID = Games[gid].ID; repgame.Quality = Games[gid].Quality; repgame.Server = Games[gid].Server; repgame.Reported = true; Games[gid] = repgame; } Save(); return(Games[gid]); }
public bool Contains(int appId) { return(Games.ContainsKey(appId)); }
/// <summary> /// load game library from xml and add new games /// </summary> /// <returns>games to update (without images)</returns> static bool LoadGames(string libraryToLoad = null) { using (var tb = new TimedBlock($"LoadGames({ libraryToLoad })")) { try { Games.Clear(); // deserialize library DeserializeLibrary(libraryToLoad); if (!string.IsNullOrEmpty(GamesDirectory)) { // add new games from current games folder foreach (var gameShortcut in Directory.GetFiles(GamesDirectory, "*.*", SearchOption.AllDirectories)) { var fileInfo = new FileInfo(gameShortcut); if (!SupportedGameExtensions.Contains(fileInfo.Extension.ToLower())) { continue; } var gameTitle = fileInfo.Name.Replace(fileInfo.Extension, string.Empty); var gameId = GetGameId(gameTitle); if (!Games.ContainsKey(gameId)) { var newGameInfo = new GameInfo { Title = gameTitle, Shortcut = gameShortcut, Added = DateTime.Now, }; // add new game Games.AddOrUpdate(gameId, newGameInfo, (key, oldGameInfo) => newGameInfo); } // update game shortcut everytime Games[gameId].Shortcut = gameShortcut; } } // mark games with not-existing shortcuts as removed foreach (var game in Games.Where(g => g.Value.Shortcut != null && !File.Exists(g.Value.Shortcut))) { game.Value.Shortcut = null; } return(true); } catch (Exception ex) { Log.WriteLine(ex.ToString()); } } return(false); }