Exemple #1
0
        //============================================================================
        // processStream
        //============================================================================
        static public void processBinaryStream(BinaryReader pStream, string pdbFilename, uint throttleAmout)
        {
            forceOnConnectEvent("127.0.0.1", pdbFilename);


            byte[] header = new byte[4];

            Interlocked.Exchange(ref mIsRunning, 1);

            mNumBytesWritten = (ulong)pStream.BaseStream.Length;
            mNumBytesRead    = 0;

            int numPacketsRecieved = 0;

            while (mIsRunning > 0 && mNumBytesRead < mNumBytesWritten)
            {
                if (mIsPaused == 1)
                {
                    continue;
                }

                try
                {
                    pStream.Read(header, 0, 4); //read the header..

                    byte packetStart = header[0];
                    byte packetType  = header[1];
                    int  packetSize  = (int)Xbox_EndianSwap.endSwapI16(BitConverter.ToUInt16(header, 2));


                    if (packetStart != HaloWarsMem.cALPacketPrefix)
                    {
                        continue; //ERROR HERE??
                    }
                    //modify our packet size since we've already read in 4 bytes..
                    packetSize -= 4; // -= sizeof the data we've already read in..
                    if (packetSize < 0)
                    {
                        packetSize = 0;
                    }

                    //read in the rest of the packet data
                    byte[] packetData = null;
                    if (packetSize > 0)
                    {
                        //read the packet
                        packetData = new byte[packetSize];
                        int readSize = pStream.Read(packetData, 0, packetSize);

                        if (readSize != packetSize)
                        {
                            break; //ERROR HERE??
                        }
                    }

                    recieveProcessPacket(header, packetType, packetSize, ref packetData);

                    numPacketsRecieved++;

                    mNumBytesRead += (ulong)(4 + packetSize);

                    //this is for reading from Disk. We throttle a bit to let the UI catch up..
                    if (throttleAmout != 0)
                    {
                        for (int i = 0; i < throttleAmout; i++)
                        {
                            ;
                        }
                        //Thread.Sleep((int)throttleAmout);
                    }
                }
                catch (Exception e)
                {
                    GlobalErrors.addError(e.InnerException.ToString());
                    break;
                }
            }

            forceOnDisconnectEvent();
        }
Exemple #2
0
        //============================================================================
        // processNetworkStream
        //============================================================================
        static public void processNetworkStream(string IPAddy, NetworkStream pStream, string pdbFilename, TcpClient pClient)
        {
            forceOnConnectEvent(IPAddy, pdbFilename);
            Interlocked.Exchange(ref mIsRunning, 1);


            string cTempNetworkFile = "C:\\_tmpNetworkLog.bin";

            if (File.Exists(cTempNetworkFile))
            {
                File.Delete(cTempNetworkFile);
            }

            initNetworkReaderThread(cTempNetworkFile, pStream, pClient);

            FileStream mLoggedFileStreamReader = null;

            try
            {
                mLoggedFileStreamReader = new FileStream(cTempNetworkFile, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
            }catch (Exception ex)
            {
                GlobalErrors.addError("Error opening temp network stream file : \n" + ex.InnerException.ToString());
                Interlocked.Exchange(ref mIsRunning, 0);
            }

            BinaryReader br = new BinaryReader(mLoggedFileStreamReader);


            byte[] header = new byte[4];

            mNumBytesRead = 0;
            while (mIsRunning > 0)
            {
                try
                {
                    if (mIsPaused == 1 || mNumBytesRead >= mNumBytesWritten)
                    {
                        continue;
                    }

                    if (!fillBufferFromStream(br, header, 4, pClient))
                    {
                        GlobalErrors.addError("Error reading buffer from streams");
                        break;
                    }

                    byte packetStart = header[0];
                    byte packetType  = header[1];
                    int  packetSize  = (int)Xbox_EndianSwap.endSwapI16(BitConverter.ToUInt16(header, 2));


                    if (packetStart != HaloWarsMem.cALPacketPrefix)
                    {
                        GlobalErrors.addError("Invalid Packet recieved in network stream. Disconnecting..");
                        break;
                    }

                    //modify our packet size since we've already read in 4 bytes..
                    packetSize -= 4; // -= sizeof the data we've already read in..
                    if (packetSize < 0)
                    {
                        packetSize = 0;
                    }



                    //read in the rest of the packet data
                    byte[] packetData = null;
                    if (packetSize > 0)
                    {
                        //read the packet
                        packetData = new byte[packetSize];
                        if (!fillBufferFromStream(br, packetData, packetSize, pClient))
                        {
                            GlobalErrors.addError("Error reading buffer from streams");
                            break;
                        }
                    }


                    recieveProcessPacket(header, packetType, packetSize, ref packetData);

                    int incAmt = 4 + packetSize;


                    mNumBytesRead += (ulong)incAmt;
                }
                catch (Exception e)
                {
                    GlobalErrors.addError(e.InnerException.ToString());
                    break;
                }
            }
            stopProcessing();

            mLoggedFileStreamReader.Close();
            br.Close();

            forceOnDisconnectEvent();
        }