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();
            }
        }
예제 #2
0
        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);
        }
예제 #4
0
        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();
            }
        }
예제 #5
0
        /// <summary>
        /// Gets QNetPlayer using Reader's Connection.
        /// </summary>
        public QNetPlayer GetPlayer()
        {
            var player = QNetPlayer.GetQNetPlayer(Reader.Connection);

            return(player);
        }