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); }
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); }
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); } } }
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(); //} }
// 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(); } }
public void AddCommand(CGCommand command) { m_commandRunner.AddToQueue(command); }