Esempio n. 1
0
        private void Awake()
        {
            //Если в прошлом бою уже был создан UdpClient
            udpClientWrapper?.Stop();

            BattleRoyaleClientMatchModel matchData = MyMatchDataStorage.Instance.GetMatchModel();
            int         matchId          = matchData.MatchId;
            int         gameServerPort   = matchData.GameServerPort;
            string      gameServerIp     = matchData.GameServerIp;
            IPEndPoint  serverIpEndPoint = new IPEndPoint(IPAddress.Parse(gameServerIp), gameServerPort);
            UdpMediator udpMediator      = new UdpMediator();

            log.Info("Установка прослушки udp.");
            UdpClient udpClient = new UdpClient
            {
                Client =
                {
                    Blocking = false
                }
            };

            udpClient.Connect(serverIpEndPoint);
            udpClientWrapper = new BattleUdpClientWrapper(udpMediator, udpClient);
            udpSendUtils     = new UdpSendUtils(matchId, udpClientWrapper);
            udpMediator.Initialize(udpSendUtils, matchId);
            udpClientWrapper.StartReceiveThread();
        }
 public PlayerDeathHandler(MatchmakerNotifier matchmakerNotifier, UdpSendUtils udpSendUtils,
                           IpAddressesStorage ipAddressesStorage)
 {
     this.udpSendUtils       = udpSendUtils;
     this.matchmakerNotifier = matchmakerNotifier;
     this.ipAddressesStorage = ipAddressesStorage;
 }
 public CooldownUpdaterSystem(Contexts contexts, int matchId, UdpSendUtils udpSendUtils)
 {
     this.matchId      = matchId;
     this.udpSendUtils = udpSendUtils;
     gameContext       = contexts.game;
     playersGroup      = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.Player).NoneOf(GameMatcher.Bot));
 }
Esempio n. 4
0
 public MapInitSystem(Contexts contexts, BattleRoyaleMatchModel matchModel, UdpSendUtils udpSendUtils, out PositionChunks chunks)
 {
     gameContext       = contexts.game;
     this.matchModel   = matchModel;
     this.udpSendUtils = udpSendUtils;
     chunks            = new PositionChunks(mapIntRadius);
 }
Esempio n. 5
0
        private void Start()
        {
            BattleRoyaleClientMatchModel matchModel = matchModelStorage.GetMatchModel();
            UdpSendUtils udpSendUtils = udpManager.CreateConnection(matchModel);

            PingStatisticsStorage pingStatisticsStorage = new PingStatisticsStorage(udpSendUtils);

            clientMatchSimulation = new ClientMatchSimulation(battleUiController, udpSendUtils, matchModel, pingStatisticsStorage);

            var playersStorage      = clientMatchSimulation.GetPlayersStorage();
            var transformStorage    = clientMatchSimulation.GetTransformStorage();
            var healthPointsStorage = clientMatchSimulation.GetHealthPointsStorage();
            var maxHealthPointsMessagePackStorage  = clientMatchSimulation.GetMaxHealthPointsMessagePackStorage();
            IKillMessageStorage killMessageStorage = clientMatchSimulation.GetKillMessageStorage();

            var messageWrapperHandler = new MessageWrapperHandler(udpSendUtils,
                                                                  matchModel.MatchId,
                                                                  transformStorage,
                                                                  playersStorage,
                                                                  healthPointsStorage,
                                                                  maxHealthPointsMessagePackStorage,
                                                                  pingStatisticsStorage,
                                                                  killMessageStorage);

            IByteArrayHandler byteArrayHandler = new ByteArrayHandler(messageWrapperHandler);


            udpManager.StartListening(byteArrayHandler);
        }
Esempio n. 6
0
        public UdpSendUtils CreateConnection(BattleRoyaleClientMatchModel matchData)
        {
            if (matchData == null)
            {
                throw new Exception("Нет данных о матче. Симуляция не работает.");
            }

            int        matchId          = matchData.MatchId;
            int        gameServerPort   = matchData.GameServerPort;
            string     gameServerIp     = matchData.GameServerIp;
            IPEndPoint serverIpEndPoint = new IPEndPoint(IPAddress.Parse(gameServerIp), gameServerPort);


            log.Info("Установка прослушки udp.");
            UdpClient udpClient = new UdpClient
            {
                Client =
                {
                    Blocking = false
                }
            };

            udpClient.Connect(serverIpEndPoint);
            udpClientWrapper = new UdpClientWrapper(udpClient);
            UdpSendUtils udpSendUtils = new UdpSendUtils(matchId, udpClientWrapper);

            return(udpSendUtils);
        }
Esempio n. 7
0
        public MessageProcessor(UdpSendUtils udpSendUtils, int matchId)
        {
            receivedMessagesRudp   = new HashSet <uint>();
            rudpConfirmationSender = new RudpConfirmationSender(udpSendUtils);

            var lastEnum = Enum.GetValues(typeof(MessageType)).Cast <MessageType>().Max();

            handlers = new IMessageHandler[(int)lastEnum + 1];

            handlers[(int)MessageType.PlayerInfo]           = new PlayerInfoMessageHandler();
            handlers[(int)MessageType.Positions]            = new PositionsMessageHandler();
            handlers[(int)MessageType.Radiuses]             = new RadiusesMessageHandler();
            handlers[(int)MessageType.Parents]              = new ParentsMessageHandler();
            handlers[(int)MessageType.Detaches]             = new DetachesMessageHandler();
            handlers[(int)MessageType.Destroys]             = new DestroysMessageHandler();
            handlers[(int)MessageType.Hides]                = new HidesMessageHandler();
            handlers[(int)MessageType.HealthPoints]         = new HealthPointsHandler();
            handlers[(int)MessageType.DeliveryConfirmation] = new RudpConfirmationReceiver();
            handlers[(int)MessageType.MaxHealthPoints]      = new MaxHealthPointsHandler();
            handlers[(int)MessageType.Kill] = new KillsHandler();
            handlers[(int)MessageType.ShowPlayerAchievements] = new ShowPlayerAchievementsHandler(matchId);
            handlers[(int)MessageType.CooldownsInfos]         = new CooldownsInfosHandler();
            handlers[(int)MessageType.Cooldowns] = new CooldownsHandler();
            handlers[(int)MessageType.FrameRate] = new FrameRateHandler();
            handlers[(int)MessageType.Teams]     = new TeamsHandler();
        }
 public RudpMessagesSender(ByteArrayRudpStorage byteArrayRudpStorage, MatchStorage matchStorage,
                           UdpSendUtils udpSendUtils, IpAddressesStorage ipAddressesStorage)
 {
     this.matchStorage         = matchStorage;
     this.udpSendUtils         = udpSendUtils;
     this.ipAddressesStorage   = ipAddressesStorage;
     this.byteArrayRudpStorage = byteArrayRudpStorage;
 }
Esempio n. 9
0
 private IEnumerator ServerPinging(UdpSendUtils udpSendUtils)
 {
     while (!cts.IsCancellationRequested)
     {
         udpSendUtils.SendPingMessage();
         yield return(new WaitForSeconds(0.5f));
     }
 }
Esempio n. 10
0
        private void Start()
        {
            var          udpController = GetComponent <UdpController>();
            UdpSendUtils udpSendUtils  = udpController.GetUdpSendUtils();

            cts = new CancellationTokenSource();
            StartCoroutine(ServerPinging(udpSendUtils));
        }
 public CooldownInfoUpdaterSystem(Contexts contexts, int matchId, UdpSendUtils udpSendUtils)
 {
     this.matchId      = matchId;
     this.udpSendUtils = udpSendUtils;
     gameContext       = contexts.game;
     playersGroup      = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.Player).NoneOf(GameMatcher.Bot));
     lastWeaponInfos   = new Dictionary <int, WeaponInfo[]>(10);
 }
Esempio n. 12
0
 public void Initialize(UdpSendUtils udpSendUtils, int matchId)
 {
     if (messageProcessor != null)
     {
         throw new Exception("Повторная инициализация");
     }
     messageProcessor = new MessageProcessor(udpSendUtils, matchId);
 }
 public FrameRateSenderSystem(Contexts contexts, int matchId, UdpSendUtils udpSendUtils)
 {
     this.matchId      = matchId;
     this.udpSendUtils = udpSendUtils;
     gameContext       = contexts.game;
     playersGroup      = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.Player).NoneOf(GameMatcher.Bot));
     sentDeltaTime     = ServerTimeConstants.MinDeltaTime;
 }
Esempio n. 14
0
 public TeamsUpdaterSystem(Contexts contexts, int matchId, UdpSendUtils udpSendUtils) : base(contexts.game)
 {
     this.matchId      = matchId;
     this.udpSendUtils = udpSendUtils;
     playersGroup      = contexts.game
                         .GetGroup(GameMatcher
                                   .AllOf(GameMatcher.Player)
                                   .NoneOf(GameMatcher.Bot));
 }
Esempio n. 15
0
        protected override void SendData(UdpSendUtils udpSendUtils, int matchId, ushort playerId, IEnumerable <GameEntity> entities)
        {
            var visibleDict = entities.ToDictionary(e => e.id.value,
                                                    e => new ViewTransform(e.position.value,
                                                                           e.direction.angle,
                                                                           e.viewType.id));

            udpSendUtils.SendPositions(matchId, playerId, visibleDict);
        }
 public MaxHpUpdaterSystem(Contexts contexts, int matchId, UdpSendUtils udpSendUtils, PlayersViewAreas playersViewAreas)
 {
     this.matchId      = matchId;
     this.udpSendUtils = udpSendUtils;
     viewAreas         = playersViewAreas;
     gameContext       = contexts.game;
     withMaxHp         = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.MaxHealthPoints, GameMatcher.ViewType));
     knownMaxHps       = new Dictionary <ushort, Dictionary <ushort, ushort> >(playersViewAreas.Count);
 }
Esempio n. 17
0
        //ECS
        public void ConfigureSystems(BattleRoyaleMatchModel matchModelArg, UdpSendUtils udpSendUtils,
                                     IpAddressesStorage ipAddressesStorage)
        {
            log.Info($"Создание нового матча {nameof(matchId)} {matchId}");

            //TODO это нужно убрать в отдельный класс
            Dictionary <int, (int playerId, ViewTypeId type)> possibleKillersInfo = new Dictionary <int, (int playerId, ViewTypeId type)>();


            // var test = new BattleRoyalePlayerModelFactory().Create(matchModelArg).Select(model=>model.AccountId);
            // playersIds = new HashSet<int>(test);

            contexts = ContextsPool.GetContexts();
            contexts.SubscribeId();
            TryEnableDebug();

            playerDeathHandler = new PlayerDeathHandler(matchmakerNotifier, udpSendUtils, ipAddressesStorage);
            var playersViewAreas = new PlayersViewAreas(matchModelArg.GameUnits.Players.Count);

            systems = new Entitas.Systems()
                      .Add(new MapInitSystem(contexts, matchModelArg, udpSendUtils, out var chunks))
                      .Add(new ViewAreasInitSystem(contexts, playersViewAreas))
                      // .Add(new TestEndMatchSystem(contexts))
                      .Add(new PlayerMovementHandlerSystem(contexts))
                      .Add(new PlayerAttackHandlerSystem(contexts))
                      .Add(new PlayerAbilityHandlerSystem(contexts))
                      .Add(new ParentsSystems(contexts))
                      .Add(new AISystems(contexts))
                      .Add(new MovementSystems(contexts))
                      .Add(new GlobalTransformSystem(contexts))
                      .Add(new ShootingSystems(contexts))
                      .Add(new UpdatePositionChunksSystem(contexts, chunks))
                      .Add(new CollisionSystems(contexts, chunks))
                      .Add(new EffectsSystems(contexts))
                      .Add(new TimeSystems(contexts))
                      .Add(new UpdatePossibleKillersSystem(contexts, possibleKillersInfo))

                      .Add(new PlayerExitSystem(contexts, matchModelArg.MatchId, playerDeathHandler, matchRemover))
                      .Add(new FinishMatchSystem(contexts, matchRemover, matchId))
                      .Add(new NetworkKillsSenderSystem(contexts, possibleKillersInfo, matchModelArg.MatchId, playerDeathHandler, udpSendUtils))

                      .Add(new DestroySystems(contexts))
                      // .Add(new MatchDebugSenderSystem(contexts, matchModelArg.MatchId, udpSendUtils))
                      .Add(new NetworkSenderSystems(contexts, matchModelArg.MatchId, udpSendUtils, playersViewAreas))
                      .Add(new MovingCheckerSystem(contexts))

                      .Add(new DeleteSystem(contexts))
                      .Add(new InputDeletingSystem(contexts))
                      .Add(new GameDeletingSystem(contexts))
            ;

            systems.ActivateReactiveSystems();
            systems.Initialize();
            gameStartTime = DateTime.UtcNow;
        }
 public MatchFactory(MatchRemover matchRemover, UdpSendUtils udpSendUtils,
                     MatchmakerNotifier matchmakerNotifier, IpAddressesStorage ipAddressesStorage,
                     MessageIdFactory messageIdFactory, MessagesPackIdFactory messagesPackIdFactory)
 {
     this.matchRemover          = matchRemover;
     this.udpSendUtils          = udpSendUtils;
     this.messageIdFactory      = messageIdFactory;
     this.messagesPackIdFactory = messagesPackIdFactory;
     this.matchmakerNotifier    = matchmakerNotifier;
     this.ipAddressesStorage    = ipAddressesStorage;
 }
Esempio n. 19
0
        private void Start()
        {
            UdpSendUtils udpSendUtils = udpControllerSingleton.GetUdpSendUtils();

            systems = CreateSystems(udpSendUtils);
            Contexts.sharedInstance.game.ReplaceZoneInfo(Vector2.zero, 100f);
            systems.ActivateReactiveSystems();
            systems.Initialize();
            //Костыль на временное отключение
            enabled = false;
            StartCoroutine(DelayedStart(2.5f));
        }
Esempio n. 20
0
 public MatchRemover(MatchStorage matchStorage, ByteArrayRudpStorage byteArrayRudpStorage,
                     UdpSendUtils udpSendUtils, MatchmakerNotifier matchmakerNotifier, IpAddressesStorage ipAddressesStorage,
                     MessageIdFactory messageIdFactory, MessagesPackIdFactory messagesPackIdFactory)
 {
     this.messagesPackIdFactory = messagesPackIdFactory;
     this.matchStorage          = matchStorage;
     this.byteArrayRudpStorage  = byteArrayRudpStorage;
     this.matchmakerNotifier    = matchmakerNotifier;
     this.ipAddressesStorage    = ipAddressesStorage;
     this.messageIdFactory      = messageIdFactory;
     matchesToRemove            = new ConcurrentQueue <int>();
     playersMatchFinishNotifier = new PlayersMatchFinishNotifier(udpSendUtils, ipAddressesStorage);
 }
        public HidesSenderSystem(Contexts contexts, int matchId, UdpSendUtils udpSendUtils, PlayersViewAreas playersViewAreas)
        {
            this.matchId      = matchId;
            this.udpSendUtils = udpSendUtils;
            viewAreas         = playersViewAreas;
            gameContext       = contexts.game;
            players           = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.Player).NoneOf(GameMatcher.Bot));
            var grandMatcher = GameMatcher.AllOf(GameMatcher.GlobalTransform).NoneOf(GameMatcher.Parent);

            grandObjects           = gameContext.GetGroup(grandMatcher);
            removedObjects         = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.Destroyed, GameMatcher.Position, GameMatcher.Direction, GameMatcher.ViewType));
            removedObjectIdsBuffer = new List <ushort>();
        }
Esempio n. 22
0
 public ClientMatchSimulation(BattleUiController battleUiController, UdpSendUtils udpSendUtils,
                              BattleRoyaleClientMatchModel matchModel, PingStatisticsStorage pingStatisticsStorage)
 {
     this.battleUiController    = battleUiController;
     this.pingStatisticsStorage = pingStatisticsStorage;
     if (matchModel == null)
     {
         log.Error("Симуляция матча не запущена ");
         return;
     }
     systems = CreateSystems(udpSendUtils, matchModel, pingStatisticsStorage);
     systems.ActivateReactiveSystems();
     systems.Initialize();
 }
 public UnhiddenStoppedSenderSystem(Contexts contexts, int matchId, UdpSendUtils udpSendUtils, PlayersViewAreas playersViewAreas)
 {
     this.matchId      = matchId;
     viewAreas         = playersViewAreas;
     this.udpSendUtils = udpSendUtils;
     gameContext       = contexts.game;
     withTransforms    = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.ViewType,
                                                                GameMatcher.Position,
                                                                GameMatcher.Direction).NoneOf(GameMatcher.Moving));
     withRadiuses = gameContext.GetGroup(GameMatcher.AllOf(GameMatcher.ViewType,
                                                           GameMatcher.CircleCollider,
                                                           GameMatcher.NonstandardRadius)
                                         .NoneOf(GameMatcher.CircleScaling));
 }
        protected override void SendData(UdpSendUtils udpSendUtils, int matchId, ushort playerId, IEnumerable <GameEntity> entities)
        {
            var dict = entities.ToDictionary(e => e.id.value, e =>
            {
                var hp = e.healthPoints.value;
                if (hp > 0f)
                {
                    return((ushort)hp);
                }
                return((ushort)0);
            });

            udpSendUtils.SendHealthPoints(matchId, playerId, dict);
        }
Esempio n. 25
0
 public async Task StubNotifyGameServerAsync(UdpSendUtils udpSendUtils)
 {
     try
     {
         for (int i = 0; i < 10; i++)
         {
             udpSendUtils.SendExitNotification();
             await Task.Delay(100);
         }
     }
     catch (Exception e)
     {
         log.Error($"Брошено исключение в методе {nameof(StubNotifyGameServerAsync)}. {e.Message}");
     }
 }
Esempio n. 26
0
        public MessageWrapperHandler(UdpSendUtils udpSendUtils, int matchId,
                                     ITransformStorage transformStorage, IPlayersStorage playersStorage,
                                     IHealthPointsStorage healthPointsStorage,
                                     IMaxHealthPointsMessagePackStorage maxHealthPointsMessagePackStorage,
                                     IPingStatisticsStorage pingStatisticsStorage,
                                     IKillMessageStorage killMessageStorage)
        {
            receivedMessagesRudp       = new HashSet <uint>();
            deliveryConfirmationSender = new DeliveryConfirmationSender(udpSendUtils);
            MessageType lastEnum = Enum.GetValues(typeof(MessageType)).Cast <MessageType>().Max();

            handlers = new IMessageHandler[(int)lastEnum + 1];
            handlers[(int)MessageType.PlayerInfo] = new PlayerInfoMessageHandler(playersStorage);
            handlers[(int)MessageType.Positions]  = new PositionsMessageHandler(transformStorage);
            handlers[(int)MessageType.HealthPointsMessagePack]    = new HealthPointsPackHandler(healthPointsStorage);
            handlers[(int)MessageType.DeliveryConfirmation]       = new RudpConfirmationReceiver();
            handlers[(int)MessageType.ShowPlayerAchievements]     = new ShowPlayerAchievementsHandler(matchId);
            handlers[(int)MessageType.MaxHealthPointsMessagePack] = new MaxHealthPointsMessagePackHandler(maxHealthPointsMessagePackStorage);
            handlers[(int)MessageType.PingAnswerMessage]          = new PingAnswerMessageHandler(pingStatisticsStorage);
            handlers[(int)MessageType.Kill] = new KillMessageHandler(killMessageStorage);
        }
Esempio n. 27
0
        public NetworkSenderSystems(Contexts contexts, int matchId, UdpSendUtils udpSendUtils, PlayersViewAreas viewAreas) : base("Network Sender Systems")
        {
            Add(new FrameRateSenderSystem(contexts, matchId, udpSendUtils));

            Add(new HidesSenderSystem(contexts, matchId, udpSendUtils, viewAreas));
            Add(new ChangingPositionsSenderSystem(contexts, matchId, udpSendUtils, viewAreas));
            Add(new UnhiddenStoppedSenderSystem(contexts, matchId, udpSendUtils, viewAreas));

            Add(new RadiusesUpdaterSystem(contexts, matchId, udpSendUtils, viewAreas));
            Add(new FinalRadiusesSystem(contexts, matchId, udpSendUtils, viewAreas));

            Add(new ParentsSenderSystem(contexts, matchId, udpSendUtils));
            Add(new DetachesSenderSystem(contexts, matchId, udpSendUtils));

            Add(new HealthUpdaterSystem(contexts, matchId, udpSendUtils, viewAreas));
            Add(new MaxHpUpdaterSystem(contexts, matchId, udpSendUtils, viewAreas));

            Add(new TeamsUpdaterSystem(contexts, matchId, udpSendUtils));

            Add(new CooldownInfoUpdaterSystem(contexts, matchId, udpSendUtils));
            Add(new CooldownUpdaterSystem(contexts, matchId, udpSendUtils));

            Add(new DestroysSenderSystem(contexts, matchId, udpSendUtils));
        }
Esempio n. 28
0
 public DeliveryConfirmationSender(UdpSendUtils udpSendUtils)
 {
     this.udpSendUtils = udpSendUtils;
 }
Esempio n. 29
0
 public RudpConfirmationSender(UdpSendUtils udpSendUtils)
 {
     this.udpSendUtils = udpSendUtils;
 }
Esempio n. 30
0
 protected abstract void SendData(UdpSendUtils udpSendUtils, int matchId, ushort playerId, IEnumerable <GameEntity> entities);