Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (C) Paul Becker, - All Rights Reserved
- // Unauthorized copying of this file, via any medium is strictly prohibited
- // Proprietary and confidential
- // Written by Paul Becker <paul.becker1@gmx.de>, 22:06
- #region usings
- using System;
- #endregion
- namespace SeraphimServer.Network
- {
- public abstract class ClientPacket : BasePacket
- {
- public ClientPacket()
- : base(PacketType.CLIENT)
- {
- }
- public abstract void ProcessPacket();
- protected byte[] ReadBytes(int length)
- {
- var result = new byte[length];
- Read(result, 0, length);
- return result;
- }
- protected new byte ReadByte()
- {
- return ReadBytes(1)[0];
- }
- protected int ReadInt()
- {
- return BitConverter.ToInt32(ReadBytes(4), 0);
- }
- protected double ReadDouble()
- {
- return BitConverter.ToDouble(ReadBytes(8), 0);
- }
- protected float ReadFloat()
- {
- return BitConverter.ToSingle(ReadBytes(4), 0);
- }
- protected long ReadLong()
- {
- return BitConverter.ToInt64(ReadBytes(8), 0);
- }
- protected short ReadShort()
- {
- return BitConverter.ToInt16(ReadBytes(2), 0);
- }
- protected ushort ReadUnsignedShort()
- {
- return BitConverter.ToUInt16(ReadBytes(2), 0);
- }
- protected string ReadString()
- {
- var result = "";
- // loop the stream until end, will be broken in middle if string end found
- while ((Length - Position) > 2)
- {
- var c = BitConverter.ToChar(ReadBytes(2), 0);
- if (c == 0)
- break;
- result += c;
- }
- return result;
- }
- protected int readD()
- {
- return ReadInt();
- }
- /**
- * Read byte from this packet buffer.
- *
- * @return int
- */
- protected int readC()
- {
- return ReadByte();
- }
- /**
- * Read signed byte from this packet buffer.
- *
- * @return int
- */
- protected byte readSC()
- {
- return ReadByte();
- }
- /**
- * Read signed short from this packet buffer.
- *
- * @return int
- */
- protected short readSH()
- {
- return ReadShort();
- }
- protected int readH()
- {
- return ReadUnsignedShort();
- }
- /**
- * Read double from this packet buffer.
- *
- * @return double
- */
- protected double readDF()
- {
- return ReadDouble();
- }
- /**
- * Read double from this packet buffer.
- *
- * @return double
- */
- protected float readF()
- {
- return ReadFloat();
- }
- /**
- * Read long from this packet buffer.
- *
- * @return long
- */
- protected long readQ()
- {
- return ReadLong();
- }
- /**
- * Read String from this packet buffer.
- *
- * @return String
- */
- protected String readS()
- {
- return ReadString();
- }
- /**
- * Read n bytes from this packet buffer, n = length.
- *
- * @param length
- * @return byte[]
- */
- protected byte[] readB(int length)
- {
- return ReadBytes(length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement