Ejemplo n.º 1
0
    public CGCommand ReceiveCommand()
    {
        NetworkStream stream = m_client.GetStream();

        while (stream.DataAvailable)
        {
            //Debug.Log("Data available! Reading stream...");
            // Decode the first 32 bits to find the length of the remaining data
            byte[] dataSizeBytes = new byte[4];
            stream.Read(dataSizeBytes, 0, 4);
            int dataSize = BitConverter.ToInt32(dataSizeBytes, 0);
            dataSize = IPAddress.NetworkToHostOrder(dataSize);
            //Debug.Log("Received data of size " + dataSize + " bytes");

            // Receive the data
            // Convert size to bytes
            byte[] data = new byte[dataSize];
            stream.Read(data, 0, dataSize);

            // Put the data into a BitStream
            BKSystem.IO.BitStream serverStream = new BKSystem.IO.BitStream(dataSize * 8);
            serverStream.Write(data);

            if (serverStream.Length > 0)
            {
                return(CGCommand.CreateCommandFromPacket(serverStream));
            }
        }
        return(null);
    }
Ejemplo n.º 2
0
    void SendGmCommand(string cmd)
    {
        CGCommand msg = new CGCommand();

        byte[] temp = EncodeUtility.Instance.GetGbBytes(cmd);
        Array.Copy(temp, msg.Command, temp.Length);
        msg.CommandSize = (byte)temp.Length;

        NetManager.GetNetManager().SendPacket(msg);
    }
Ejemplo n.º 3
0
 public void AiUpdate()
 {
     // See ClientConnectionInterface.Update()
     if (m_aiConMgr != null && m_aiConMgr.IsConnected())
     {
         CGCommand command = m_aiConMgr.ReceiveCommand();
         if (command != null)
         {
             command.OnReceivedAi(m_aiPlayer, m_aiConMgr);
             command.ExecuteAiCommand(m_aiPlayer, m_aiConMgr);
         }
     }
 }
Ejemplo n.º 4
0
    public void AddToQueue(CGCommand command)
    {
        if (m_visualManager == null)
        {
            m_visualManager = GameObject.FindObjectOfType <CGVisualManager>();
            if (m_visualManager == null)
            {
                Debug.LogError("No CGVisualManager found");
            }
        }

        command.m_visualManager = m_visualManager;
        command.SetCommandRunner(this);
        m_commandQueue.Enqueue(command);
        //if(!m_runningQueue)
        //{
        //    RunQueue();
        //}
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (m_client != null && m_client.IsConnected())
        {
            if (m_visualManager == null)
            {
                SetUpVisualManager();
            }

            CGCommand command = m_client.ReceiveCommand();
            if (command != null)
            {
                command.m_visualManager = m_visualManager;
                command.OnReceived();
                m_visualManager.AddCommand(command);
            }
        }
        // Run AI client if it exists
        if (m_offline && m_localServerRunner != null)
        {
            m_localServerRunner.AiUpdate();
        }
    }
Ejemplo n.º 6
0
 public void AddCommand(CGCommand command)
 {
     m_commandRunner.AddToQueue(command);
 }