public override void OnClientConnect(QNetworkConnection connection) // Called on the client when connecting to a server { DebugLog.DebugWrite("OnClientConnect", MessageType.Info); base.OnClientConnect(connection); QSBEventManager.Init(); gameObject.AddComponent <RespawnOnDeath>(); if (QSBSceneManager.IsInUniverse) { WorldObjectManager.Rebuild(QSBSceneManager.CurrentScene); } var specificType = QNetworkServer.active ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect; QSBPatchManager.DoPatchType(specificType); QSBPatchManager.DoPatchType(QSBPatchTypes.OnClientConnect); _lobby.CanEditName = false; OnNetworkManagerReady?.SafeInvoke(); IsReady = true; QSBCore.UnityEvents.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null, () => QSBEventManager.FireEvent(EventNames.QSBPlayerJoin, _lobby.PlayerName)); if (!QSBCore.IsServer) { QSBCore.UnityEvents.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null, () => QSBEventManager.FireEvent(EventNames.QSBPlayerStatesRequest)); } _everConnected = true; }
public virtual void OnServerRemovePlayer(QNetworkConnection conn, QPlayerController player) { if (player.Gameobject != null) { QNetworkServer.Destroy(player.Gameobject); } }
private void FinishLoadScene() { if (client != null) { if (s_ClientReadyConnection != null) { clientLoadedScene = true; OnClientConnect(s_ClientReadyConnection); s_ClientReadyConnection = null; } } else { QLog.Error("FinishLoadScene client is null"); } if (QNetworkServer.active) { QNetworkServer.SpawnObjects(); OnServerSceneChanged(networkSceneName); } if (IsClientConnected() && client != null) { RegisterClientMessages(client); OnClientSceneChanged(client.connection); } }
public virtual void OnClientSceneChanged(QNetworkConnection conn) { QClientScene.Ready(conn); if (autoCreatePlayer) { var flag = QClientScene.localPlayers.Count == 0; var flag2 = false; foreach (var player in QClientScene.localPlayers) { if (player.Gameobject != null) { flag2 = true; break; } } if (!flag2) { flag = true; } if (flag) { QClientScene.AddPlayer(0); } } }
// QNET public static uint GetPlayerId(this QNetworkConnection connection) { var go = connection.PlayerControllers[0].Gameobject; var controller = go.GetComponent <PlayerTransformSync>(); return(controller.NetId.Value); }
public virtual void OnClientDisconnect(QNetworkConnection conn) { StopClient(); if (conn.LastError != NetworkError.Ok) { QLog.Error($"ClientDisconnected due to error: {conn.LastError}"); } }
public virtual void OnServerReady(QNetworkConnection conn) { if (conn.PlayerControllers.Count == 0) { QLog.Warning("Ready with no player object"); } QNetworkServer.SetClientReady(conn); }
public virtual void OnServerDisconnect(QNetworkConnection conn) { QNetworkServer.DestroyPlayersForConnection(conn); if (conn.LastError != NetworkError.Ok) { QLog.Error($"ServerDisconnected due to error: {conn.LastError}"); } }
public static void Shutdown() { if (!(singleton == null)) { s_ClientReadyConnection = null; singleton.StopHost(); singleton = null; } }
public override void OnServerAddPlayer(QNetworkConnection connection, short playerControllerId) // Called on the server when a client joins { DebugLog.DebugWrite($"OnServerAddPlayer {playerControllerId}", MessageType.Info); base.OnServerAddPlayer(connection, playerControllerId); QNetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), connection); QNetworkServer.SpawnWithClientAuthority(Instantiate(_cameraPrefab), connection); QNetworkServer.SpawnWithClientAuthority(Instantiate(_probePrefab), connection); QNetworkServer.SpawnWithClientAuthority(Instantiate(_stickPrefab), connection); }
public virtual void OnClientConnect(QNetworkConnection conn) { if (!clientLoadedScene) { QClientScene.Ready(conn); if (autoCreatePlayer) { QClientScene.AddPlayer(0); } } }
public override void OnServerDisconnect(QNetworkConnection connection) // Called on the server when any client disconnects { base.OnServerDisconnect(connection); DebugLog.DebugWrite("OnServerDisconnect", MessageType.Info); foreach (var item in QSBWorldSync.OrbSyncList) { var identity = item.GetComponent <QNetworkIdentity>(); if (identity.ClientAuthorityOwner == connection) { identity.RemoveClientAuthority(connection); } } }
internal void OnClientConnectInternal(QNetworkMessage netMsg) { QLog.Log("NetworkManager:OnClientConnectInternal"); netMsg.Connection.SetMaxDelay(maxDelay); var name = SceneManager.GetSceneAt(0).name; if (string.IsNullOrEmpty(onlineScene) || onlineScene == offlineScene || name == onlineScene) { clientLoadedScene = false; OnClientConnect(netMsg.Connection); } else { s_ClientReadyConnection = netMsg.Connection; } }
public QChannelBuffer(QNetworkConnection conn, int bufferSize, byte cid, bool isReliable, bool isSequenced) { _connection = conn; _maxPacketSize = bufferSize - 100; _currentPacket = new QChannelPacket(_maxPacketSize, isReliable); _channelId = cid; _maxPendingPacketCount = 16; _isReliable = isReliable; _allowFragmentation = isReliable && isSequenced; if (isReliable) { _pendingPackets = new Queue <QChannelPacket>(); if (_freePackets == null) { _freePackets = new List <QChannelPacket>(); } } }
private void OnServerAddPlayerInternal(QNetworkConnection conn, short playerControllerId) { if (playerPrefab == null) { QLog.FatalError("The PlayerPrefab is empty on the QSBNetworkManager. Please setup a PlayerPrefab object."); } else if (playerPrefab.GetComponent <QNetworkIdentity>() == null) { QLog.FatalError("The PlayerPrefab does not have a QSBNetworkIdentity. Please add a QSBNetworkIdentity to the player prefab."); } else if (playerControllerId < conn.PlayerControllers.Count && conn.PlayerControllers[playerControllerId].IsValid && conn.PlayerControllers[playerControllerId].Gameobject != null) { QLog.Warning("There is already a player at that playerControllerId for this connections."); } else { var player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity); QNetworkServer.AddPlayerForConnection(conn, player, playerControllerId); } }
public bool SendToTransport(QNetworkConnection conn, int channelId) { var result = true; if (!conn.TransportSend(m_Buffer, (ushort)m_Position, channelId, out var b)) { if (!m_IsReliable || b != 4) { Debug.LogError($"Failed to send internal buffer channel:{channelId} bytesToSend:{m_Position}"); result = false; } } if (b != 0) { if (m_IsReliable && b == 4) { return(false); } Debug.LogError($"Send Error: {(NetworkError)b} channel:{channelId} bytesToSend:{m_Position}"); result = false; } m_Position = 0; return(result); }
public virtual void OnServerAddPlayer(QNetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader) => OnServerAddPlayerInternal(conn, playerControllerId);
public virtual void OnServerConnect(QNetworkConnection conn) { }
public virtual void OnClientNotReady(QNetworkConnection conn) { }
public virtual void OnClientError(QNetworkConnection conn, int errorCode) { }
public virtual void OnServerAddPlayer(QNetworkConnection conn, short playerControllerId) => OnServerAddPlayerInternal(conn, playerControllerId);
public virtual void OnServerError(QNetworkConnection conn, int errorCode) { }