Пример #1
0
        public static bool Ready(QNetworkConnection conn)
        {
            bool result;

            if (ready)
            {
                Debug.LogError("A connection has already been set as ready. There can only be one.");
                result = false;
            }
            else
            {
                Debug.Log($"ClientScene::Ready() called with connection [{conn}]");
                if (conn != null)
                {
                    var msg = new QReadyMessage();
                    conn.Send(35, msg);
                    ready                   = true;
                    readyConnection         = conn;
                    readyConnection.isReady = true;
                    result                  = true;
                }
                else
                {
                    Debug.LogError("Ready() called with invalid connection object: conn=null");
                    result = false;
                }
            }
            return(result);
        }
Пример #2
0
 internal static void HandleClientDisconnect(QNetworkConnection conn)
 {
     if (readyConnection == conn && ready)
     {
         ready           = false;
         readyConnection = null;
     }
 }
 protected void SendTargetRPCInternal(QNetworkConnection conn, QNetworkWriter writer, int channelId, string rpcName)
 {
     if (!IsServer)
     {
         QLog.Warning("TargetRpc call on un-spawned object");
         return;
     }
     writer.FinishMessage();
     conn.SendWriter(writer, channelId);
 }
Пример #4
0
 public QNetworkClient(QNetworkConnection conn)
 {
     m_MsgBuffer = new byte[65535];
     m_MsgReader = new NetworkReader(m_MsgBuffer);
     AddClient(this);
     SetActive(true);
     m_Connection   = conn;
     m_AsyncConnect = ConnectState.Connected;
     conn.SetHandlers(m_MessageHandlers);
     RegisterSystemHandlers(false);
 }
 public virtual bool OnCheckObserver(QNetworkConnection conn) => true;
Пример #6
0
 internal void SetHandlers(QNetworkConnection conn) => conn.SetHandlers(m_MessageHandlers);
Пример #7
0
 public static bool AddPlayer(QNetworkConnection readyConn, short playerControllerId) => AddPlayer(readyConn, playerControllerId, null);
Пример #8
0
        public static bool AddPlayer(QNetworkConnection readyConn, short playerControllerId, QMessageBase extraMessage)
        {
            bool result;

            if (playerControllerId < 0)
            {
                Debug.LogError($"ClientScene::AddPlayer: playerControllerId of {playerControllerId} is negative");
                result = false;
            }
            else if (playerControllerId > 32)
            {
                Debug.LogError($"ClientScene::AddPlayer: playerControllerId of {playerControllerId} is too high, max is {32}");
                result = false;
            }
            else
            {
                if (playerControllerId > 16)
                {
                    Debug.LogWarning($"ClientScene::AddPlayer: playerControllerId of {playerControllerId} is unusually high");
                }
                while (playerControllerId >= localPlayers.Count)
                {
                    localPlayers.Add(new QPlayerController());
                }
                if (readyConn == null)
                {
                    if (!ready)
                    {
                        Debug.LogError("Must call AddPlayer() with a connection the first time to become ready.");
                        return(false);
                    }
                }
                else
                {
                    ready           = true;
                    readyConnection = readyConn;
                }
                if (readyConnection.GetPlayerController(playerControllerId, out var playerController))
                {
                    if (playerController.IsValid && playerController.Gameobject != null)
                    {
                        Debug.LogError($"ClientScene::AddPlayer: playerControllerId of {playerControllerId} already in use.");
                        return(false);
                    }
                }
                Debug.Log($"ClientScene::AddPlayer() for ID {playerControllerId} called with connection [{readyConnection}]");
                var addPlayerMessage = new QAddPlayerMessage
                {
                    playerControllerId = playerControllerId
                };
                if (extraMessage != null)
                {
                    var networkWriter = new QNetworkWriter();
                    extraMessage.Serialize(networkWriter);
                    addPlayerMessage.msgData = networkWriter.ToArray();
                    addPlayerMessage.msgSize = networkWriter.Position;
                }
                readyConnection.Send(37, addPlayerMessage);
                result = true;
            }
            return(result);
        }