namespace Devoid.Net.Server.Messages { using Devoid; using Devoid.Encoding; using System; public class serverMessage { private readonly byte[] mData; private readonly int mID; private int mIndex; public serverMessage(int messageID, byte[] baData) { this.mID = messageID; this.mData = baData; } public byte[] GetBytes() { int num = 0; string str = base64Encoding.Encode(this.mID); byte[] buffer = new byte[this.mData.Length + 3]; buffer[num++] = (byte) str[0]; buffer[num++] = (byte) str[1]; for (int i = 0; i < this.mData.Length; i++) { buffer[num++] = this.mData[i]; } buffer[num++] = 1; return buffer; } public string GetStringData() { return Engine.Latin1Encoder.GetString(this.mData, 0, this.mData.Length); } public bool PopBoolean() { return (this.mData[this.mIndex++] == 0x49); } public int PopInteger() { int i = wireEncoding.Decode(Engine.Latin1Encoder.GetString(this.mData, this.mIndex, this.remainingDataLength)); this.mIndex += wireEncoding.Encode(i).Length; return i; } public string PopString() { int numBytes = base64Encoding.Decode(this.ReadBytes(2)); return Engine.Latin1Encoder.GetString(this.ReadBytes(numBytes)); } public int PopStrInteger() { try { return int.Parse(this.PopString()); } catch { return 0; } } private byte[] ReadBytes(int numBytes) { byte[] buffer = new byte[this.remainingDataLength]; if (buffer.Length > 0) { int num = 0; for (int i = this.mIndex; i < (this.mIndex + numBytes); i++) { buffer[num++] = this.mData[i]; this.mIndex = i; } } return buffer; } public void Reset() { this.mIndex = 0; } public int dataLength { get { return this.mData.Length; } } public string encodedID { get { return base64Encoding.Encode(this.ID); } } public int ID { get { return this.mID; } } public int remainingDataLength { get { return (this.dataLength - this.mIndex); } } } }