public override void Handle(SnapshotMessage message) { if (_localClient.IsConnected == false) { return; } foreach (PlayerSnapshotData playerData in message.playersData) { Player player = _playerRegistry.Players.Find(x => x.PlayerId == playerData.playerId); if (player == null) { _playerRegistry.RegisterPlayer(_spawner.SpawnRemotePlayer(playerData.team), playerData.playerId); } else if (player.PlayerId != _localClient.LocalPlayerId) { _playerRegistry.GetRemotePlayerById(player.PlayerId).EnqueuePosition(playerData.position, message.TickIndex); } else { _reconciler.Reconcile(message.TickIndex, playerData.position); } } _ball.EnqueuePosition(message.ballPosition, message.TickIndex); }
public override void Handle(SpawnPlayerMessage message) { if (_client.LocalPlayerId == -1) { // Client snaps to server's tick + some offset which will be adjusted later by clock sync. _loop.TickIndex = message.TickIndex + 5; _client.LocalPlayerId = message.playerId; _client.IsConnected = true; _client.SetServerEndpoint(message.Sender); _playerRegistry.RegisterPlayer(_spawner.SpawnControlledPlayer(message.team), message.playerId); _events.LocalPlayerSpawned?.Invoke(); } }
public override void Handle(HandshakeMessage message) { string clientId = message.Sender.ToString(); if (!_server.HasClient(clientId)) { ControlledPlayer player = _spawner.SpawnControlledPlayer(_playerRegistry.GetNextTeamAssignment()); _playerRegistry.RegisterPlayer(player, clientId); _server.RegisterClient(clientId, message.Sender); } else { Debug.LogWarning("Client with this id is already connected."); } var serverPlayer = _playerRegistry.GetControlledPlayerByClientId(clientId); var spawnMessage = new SpawnPlayerMessage(clientId, serverPlayer.PlayerId, serverPlayer.Team); _server.SendMessage(spawnMessage, message.Sender); }