Exemple #1
0
        public async Task BroadcastServerHeartbeat(MasterServerSession session, BroadcastServerHeartbeatRequest request)
        {
            _logger.Verbose(
                $"Handling {nameof(BroadcastServerHeartbeatRequest)} " +
                $"(UserId='{request.UserId}', " +
                $"UserName='******', " +
                $"Secret='{request.Secret}', " +
                $"CurrentPlayerCount={request.CurrentPlayerCount})."
                );
            if (session.Secret != request.Secret)
            {
                _logger.Warning(
                    $"User sent {nameof(BroadcastServerHeartbeatRequest)} " +
                    "with an invalid secret " +
                    $"(UserId='{request.UserId}', " +
                    $"UserName='******', " +
                    $"Secret='{request.Secret}', " +
                    $"Expected='{session.Secret}')."
                    );
                _messageDispatcher.Send(session, new BroadcastServerHeartbeatResponse
                {
                    Result = BroadcastServerHeartbeatResponse.ResultCode.UnknownError
                });
                return;
            }

            var server = await _serverRepository.GetServer(request.Secret);

            if (server == null)
            {
                _messageDispatcher.Send(session, new BroadcastServerHeartbeatResponse
                {
                    Result = BroadcastServerHeartbeatResponse.ResultCode.ServerDoesNotExist
                });
                return;
            }

            session.LastKeepAlive = DateTimeOffset.UtcNow;
            _serverRepository.UpdateCurrentPlayerCount(request.Secret, (int)request.CurrentPlayerCount);
            _messageDispatcher.Send(session, new BroadcastServerHeartbeatResponse
            {
                Result = BroadcastServerHeartbeatResponse.ResultCode.Success
            });
        }
        protected override void HandleBroadcastServerHeartbeatRequest(BroadcastServerHeartbeatRequest packet, MessageOrigin origin)
        {
            SendUnreliableMessage(1u, origin.endPoint, BroadcastServerHeartbeatResponse.pool.Obtain().Init(BroadcastServerHeartbeatResponse.Result.Success));

            packet.Release();
        }