internal static void OnPlayerCreate(QNetMessage message, QNetMessageReader reader, ref bool disallowRecycle) { JEMLogger.Log("QNet is receiving player create event."); // de-serialized message var serializedPlayer = reader.ReadMessage <QNetPlayerSerialized>(); // resolve qNetPlayer var qNetPlayer = QNetPlayer.GetQNetPlayer(serializedPlayer.ConnectionIdentity); if (qNetPlayer == null) { if (QNetManager.IsHostActive) { throw new InvalidOperationException( $"Host is unable to GetQNetPlayer by identity {serializedPlayer.ConnectionIdentity}."); } qNetPlayer = QNetPlayer.CreateQNetPlayer(serializedPlayer.ConnectionIdentity, serializedPlayer.NickName, 0); } if (QNetManager.Client.ConnectionIdentity == serializedPlayer.ConnectionIdentity) { // do something with local player // we can't TagAsReady because WORLD_SERIALIZED message already do this } else { // tag player as ready qNetPlayer.TagAsReady(); } }
public static void OnClientLevelLoadedOnFly(QNetMessage message, QNetMessageReader reader, ref bool disallowRecycle) { var player = QNetPlayer.GetQNetPlayer(reader.Connection); if (player == null) { throw new NullReferenceException("player"); } if (player.Loaded) { return; } }
internal static void OnPlayerDelete(QNetMessage message, QNetMessageReader reader, ref bool disallowRecycle) { JEMLogger.Log("QNet is receiving player delete event."); var connectionIdentity = reader.ReadInt16(); var player = QNetPlayer.GetQNetPlayer(connectionIdentity); if (player == null) { throw new InvalidOperationException("InvalidConnectionIdentityError"); } player.TagAsNotReady(); QNetPlayer.DestroyQNetPlayer(player); }
internal static void OnClientWorldSerialized(QNetMessage message, QNetMessageReader reader, ref bool disallowRecycle) { // SERVER: player loads all sent qnet objects // prepare this client's controller and send final message so the player can play // we will tag this connection as ready, so the system should send this player to all connections on server including owner // if owner receive it's player instance from server, they will initialize local systems including camera and movement controller var player = QNetPlayer.GetQNetPlayer(reader.Connection); if (player == null) { JEMLogger.LogError("QNet encounter an unexcepted error. Connection QNetPlayer not exists."); QNetManager.Server.CloseConnection(reader.Connection, "QNetUnexceptedError"); } else { player.TagAsReady(); } }
/// <summary> /// Gets QNetPlayer using Reader's Connection. /// </summary> public QNetPlayer GetPlayer() { var player = QNetPlayer.GetQNetPlayer(Reader.Connection); return(player); }