Esempio n. 1
0
    // 주기적으로 RTT 측정용 패킷을 송신한다.
    private IEnumerator SendLocalSyncInfo()
    {
        while (true)
        {
            SyncData data = new SyncData();
            data.sendTime = DateTime.UtcNow.Ticks;
            SyncPacket packet = new SyncPacket(data);

            networkManager.SendReliable <SyncData>(packet);
            // Debug.Log("Send Sync data " + data.ToString());
            // 2초마다 데이터 송신
            yield return(new WaitForSeconds(2f));
        }
    }
Esempio n. 2
0
    // 이동 정보 패킷 획득 함수
    public void OnReceiveSyncPacket(PacketId id, byte[] data)
    {
        SyncPacket packet = new SyncPacket(data);
        SyncData   sync   = packet.GetPacket();
        // Debug.Log(sync + " 수신완료(싱크).");

        TimeSpan elapsedSpan = new TimeSpan(DateTime.UtcNow.Ticks - sync.sendTime);

        if (rtt.Count >= 5)
        {
            rtt.RemoveAt(0);
        }

        rtt.Add(elapsedSpan.Milliseconds);
    }
Esempio n. 3
0
        public void HandleSyncPacket(SyncPacket packet)
        {
            BeepLiveGame = new BeepLiveGame(packet.BeepConfig, PlayerGuid);

            BeepLiveGame.Map.OnSimulationStop += () =>
                                                 Flow(PlayerFlowPacket.FlowType.FinishedSimulation);

            BeepGameState.Connecting = false;

            _physicsTimer = BeepLiveGame.Run(); // Simulating is false, so this doesn't run immediately

            TeamMocks = BeepLiveGame.Teams.Select(t => new TeamMock
            {
                TeamColor  = t.TeamConfig.Color,
                MaxPlayers = t.TeamConfig.MaxPlayers,
                TeamGuid   = t.TeamConfig.TeamGuid
            }).ToList();
            PlayerMocks = new List <PlayerMock>();
        }
Esempio n. 4
0
        public async Task <ulong?> ProcessSyncPacket(SyncPacket syncPacket)
        {
            if (_cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            switch (syncPacket.PacketCase)
            {
            case Items:
                _log.Info($"Received batch: '{syncPacket.Items.Batch.Count}'");
                ulong?lastPos = null;
                foreach (var responseItem in syncPacket.Items.Batch)
                {
                    if (_cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                    var pos = await SyncHandler(responseItem.LogEvent);

                    lastPos = pos;
                }
                return(lastPos);

            case Item:
                //                            Console.WriteLine($"Received: '{syncPacket}'");
                return(await SyncHandler(syncPacket.Item.LogEvent));

            case SkipPos:
                await _lmdb.WriteAsync(txn =>
                {
                    _replicationTable.SetLastPos(txn, _targetReplicaId, syncPacket.SkipPos.LastPos);
                    _updateClock(txn, _targetReplicaId, syncPacket.SkipPos.LastPos);
                }, false, true);

                return(syncPacket.SkipPos.LastPos);

            case SyncFrom:
            case None:
            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 5
0
        public void OnPlayerSync(SyncPacket packet)
        {
            Position destination = null;

            if (UnityClient.Player.FollowingPath != null)
            {
                destination = UnityClient.Player.FollowingPath.Last();
            }
            UnityClient.Player.PlayerObject.GetComponent <PlayerBehaviour>().StopMovement();
            UnityClient.Player.FollowingPath = null;
            UnityClient.Player.MoveToTile(packet.Position.X, packet.Position.Y);
            Debug.Log("SYNC TO " + packet.Position.X + " - " + packet.Position.Y);

            // recalculating route to destination
            var path = Map.FindPath(UnityClient.Player.Position, destination, UnityClient.Map.Chunks);

            if (path != null)
            {
                UnityClient.Player.FollowingPath = path;
            }
        }
Esempio n. 6
0
        // When something goes wrong, we sync (force) the player to a state
        public void OnPlayerSync(SyncPacket packet)
        {
            Position destination = null;

            if (UnityClient.Player.Behaviour.Route.Count > 0)
            {
                destination = UnityClient.Player.Behaviour.Route.Last();
            }
            UnityClient.Player.PlayerObject.GetComponent <PlayerBehaviour>().StopMovement();
            UnityClient.Player.Behaviour.Route.Clear();
            UnityClient.Player.TeleportToTile(packet.Position.X, packet.Position.Y);

            // recalculating route to destination
            if (destination != null)
            {
                var path = UnityClient.Map.FindPath(UnityClient.Player.Position, destination);
                if (path != null)
                {
                    UnityClient.Player.Behaviour.Route = path;
                }
            }
        }