예제 #1
0
        public int readPacket(NetworkObjectBase header, ref Byte[] data, int dataSize = -1)
        {
            int gotSize = tryRead(header.bufferByteSize, ref _readBuff);

            if (gotSize == header.bufferByteSize)
            {
                header.copyBufferFromArray(_readBuff);
            }
            else
            {
                netStream().Flush(); //제대로 읽어오지 못했다면 메시지큐의 모든 내용을 한번에 소비한다..
                return(0);
            }
            dataSize = (dataSize > 0) ? dataSize : header.__dataSize;
            if (data == null)
            {
                data = new Byte[dataSize];
            }
            if (dataSize > 0)
            {
                return(tryRead(dataSize, ref data));
            }
            else
            {
                return(0);
            }
        }
예제 #2
0
        public int readPacketSwapped(NetworkObjectBase header, ref Byte[] data, int dataSize = -1)
        {
            int gotSize = tryRead(header.bufferByteSize, ref _readBuff);

            if (gotSize == header.bufferByteSize)
            {
                header.copyBufferSwapFromArray(_readBuff);
            }
            else
            {
                return(0);
            }

            dataSize = (dataSize > 0) ? dataSize : header.__dataSize;
            if (data == null)
            {
                data = new Byte[dataSize];
            }
            if (dataSize > 0)
            {
                int retSize = tryRead(dataSize, ref data); // data should now swapped. it would swap in the application level.
                return(retSize);
            }
            else
            {
                return(0);
            }
        }
예제 #3
0
        /// <summary>
        /// 두 패킷이 같은 것인지 비교. 정확히는 두 패킷이 가진 버퍼의 크기가 같은 것인지 비교한다.
        /// </summary>
        /// <param name="packet"></param>
        /// <returns></returns>
        public override Boolean isSamePacket(NetworkObjectBase packet)
        {
            NetworkObject <T> obj;

            try
            {
                obj = packet as NetworkObject <T>;
            }
            catch
            {
                return(false);
            }
            //null이라도 같으면 true.
            if (buffer == null && obj.buffer == null)
            {
                return(true);
            }
            else if (buffer == null || obj.buffer == null)
            {
                return(false);                                           //둘 중 하나가 null이면 false
            }
            else if (buffer.Length != obj.buffer.Length)
            {
                return(false);                                         //버퍼의 크기가 달라도 false
            }
            for (int i = 0; i < buffer.Length; i++)
            {
                if (Buffer.GetByte(obj.buffer, i) != Buffer.GetByte(buffer, i))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #4
0
        public override Boolean isSamePacket(NetworkObjectBase packet)
        {
            NetworkObject <T> obj;

            try
            {
                obj = (NetworkObject <T>)packet;
            }
            catch
            {
                return(false);
            }
            if (buffer == null && obj.buffer == null)
            {
                return(true);
            }
            else if (buffer == null || obj.buffer == null)
            {
                return(false);
            }

            for (int i = 0; i < buffer.Length; i++)
            {
                if (Buffer.GetByte(obj.buffer, i) != Buffer.GetByte(buffer, i))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #5
0
        public void writePacket(NetworkObjectBase header, Byte[] dataBuff, int dataSize = -1)
        {
            int headerSize = header.bufferByteSize;

            dataSize = (dataSize < 0) ? header.__dataSize : dataSize;

            try
            {
                netStream().Write(header.getByteBufferCopied(), 0, header.bufferByteSize);
                if (dataSize > 0)
                {
                    netStream().Write(dataBuff, 0, dataSize);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("NetHandlerBase::writePacketHeaderSwapped - Error when write packet..." + e);
            }
        }
예제 #6
0
 /// <summary>
 /// *** don't use it. it exists for comportability from lower version. ***
 /// </summary>
 /// <param name="src"></param>
 public void copyHeaderFrom(NetworkObjectBase src)
 {
     headerBuffer.SetValue(src.__tag, 0);
     headerBuffer.SetValue(src.__dataSize, 1);
     headerBuffer.SetValue(src.__id, 2);
 }
예제 #7
0
 public abstract Boolean isSamePacket(NetworkObjectBase packet);