Example #1
0
 public HFTGame AddPlayer(HFTPlayer player, object data)
 {
     if (masterGame_ != null)
     {
         return(AddPlayerToGame(player, masterGame_.id, data));
     }
     log_.Error("no games to add player to");
     return(null);
 }
Example #2
0
        public HFTGame AddPlayerToGame(HFTPlayer player, string gameId, object data)
        {
            HFTGameGroup gameGroup = GetGameGroup(gameId);

            if (gameGroup == null)
            {
                return(null);
            }
            return(gameGroup.AddPlayer(player, data));
        }
Example #3
0
        public void SendMessageToPlayer(string id, object message)  // ???????????????????????????????????????????????????????????
        {
            HFTPlayer player = null;

            if (!players_.TryGetValue(id, out player))
            {
                log_.Error("SendMessageToPlayer no player " + id);
                return;
            }

            player.Send(message);
        }
Example #4
0
        /**
         * Adds a player to a specific game.
         * @param {Player} player to add
         * @param {string} id
         * @param {Object?} data add to send in connect msg
         */
        public HFTGame AddPlayerToGame(HFTPlayer player, string id, object data)
        {
            HFTGame game = GetGameById(id);

            if (game != null)
            {
                game.AddPlayer(player, data);
                return(game);
            }
            log_.Error("no game with id '" + id + "'");
            return(null);
        }
Example #5
0
        public void SwitchGame(string playerId, HFTMessageSwitchGame data)  // ?????????????????????????????????????????
        {
            HFTPlayer player = null;

            if (!players_.TryGetValue(playerId, out player))
            {
                log_.Error("SwitchGame player " + playerId);
                return;
            }

            RemovePlayer(player);
            gameGroup_.AddPlayerToGame(player, data.gameId, data.data);
        }
Example #6
0
        public void RemovePlayer(HFTPlayer player)
        {
            bool removed = players_.Remove(player.id);

            log_.Info("remove player " + player.id + " players left: " + players_.Count);
            if (!removed)
            {
                log_.Error("player " + player.id + " is not a member of game");
                return;
            }

            // remove queued messages from this player
            sendQueue_.RemoveAll(item => item.Key != null && item.Key.id == player.id);

            Send(null, new HFTRelayToGameMessage("remove", player.id, null));
        }
Example #7
0
        public void AddPlayer(HFTPlayer player, object data)
        {
            log_.Info("add player " + player.id + " to game ");
            HFTPlayer oldPlayer = null;

            if (players_.TryGetValue(player.id, out oldPlayer))
            {
                log_.Error("player " + player.id + " is already member of game");
                return;
            }

            player.SetGame(this);
            players_[player.id] = player;
            log_.Info("num players:" + players_.Count);
            Send(null, new HFTRelayToGameMessage("start", player.id, data));
        }
Example #8
0
 public void Send(HFTPlayer owner, HFTRelayToGameMessage msg)
 {
     if (client_ != null)
     {
         try
         {
             client_.Send(msg);
         }
         catch (System.Exception ex)
         {
             log_.Warn("Attempt to send message to game failed: " + ex);
         }
     }
     else
     {
         sendQueue_.Add(new KeyValuePair <HFTPlayer, HFTRelayToGameMessage>(owner, msg));
     }
 }