private bool handleData(byte[] data) { int pLenght = 0; recievedData.SetBytes(data); if (recievedData.UnreadLength() >= 4) { pLenght = recievedData.ReadInt(); if (pLenght <= 0) { return(true); } } while (pLenght > 0 && pLenght <= recievedData.UnreadLength()) { byte[] pBytes = recievedData.ReadBytes(pLenght); ThreadManager.ExecuteOnMainThread(() => { using (Packet P = new Packet(pBytes)) { int PID = P.ReadInt(); Handlers[PID](P); } }); pLenght = 0; if (recievedData.UnreadLength() >= 4) { pLenght = recievedData.ReadInt(); if (pLenght <= 0) { return(true); } } } if (pLenght <= 1) { return(true); } else { return(false); } }
private bool HandlleData(byte[] data) { int packetLength = 0; receiveData.SetBytes(data); if (receiveData.UnreadLength() >= 4) { packetLength = receiveData.ReadInt(); if (packetLength <= 0) { return(true); } } while (packetLength > 0 && packetLength <= receiveData.UnreadLength()) { byte[] packetBytes = receiveData.ReadBytes(packetLength); using (Packet packet = new Packet(packetBytes)) { int packetId = packet.ReadInt(); Client.packetHandlers[packetId](packet); } } packetLength = 0; if (receiveData.UnreadLength() >= 4) { packetLength = receiveData.ReadInt(); if (packetLength <= 0) { return(true); } } if (packetLength <= 1) { return(true); } return(false); }