Advertisement
Guest User

ServerPacket

a guest
Apr 22nd, 2014
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.56 KB | None | 0 0
  1. // Copyright (C) Paul Becker, - All Rights Reserved
  2. // Unauthorized copying of this file, via any medium is strictly prohibited
  3. // Proprietary and confidential
  4. // Written by Paul Becker <paul.becker1@gmx.de>, 22:06
  5.  
  6. #region usings
  7.  
  8. using System;
  9. using System.IO;
  10.  
  11. #endregion
  12.  
  13. namespace SeraphimServer.Network
  14. {
  15.     public abstract class ServerPacket : BasePacket
  16.     {
  17.         public ServerPacket()
  18.             : base(PacketType.SERVER)
  19.         {
  20.         }
  21.  
  22.         public void WriteBytes(byte[] bytes)
  23.         {
  24.             Write(bytes, 0, bytes.Length);
  25.         }
  26.  
  27.         public void WriteInt(int value)
  28.         {
  29.             WriteBytes(BitConverter.GetBytes(value));
  30.         }
  31.  
  32.         public void WriteShort(short value)
  33.         {
  34.             WriteBytes(BitConverter.GetBytes(value));
  35.         }
  36.  
  37.         public void WriteDouble(double value)
  38.         {
  39.             WriteBytes(BitConverter.GetBytes(value));
  40.         }
  41.  
  42.         public void WriteUnsignedShort(ushort value)
  43.         {
  44.             WriteBytes(BitConverter.GetBytes(value));
  45.         }
  46.  
  47.         public void WriteLong(long value)
  48.         {
  49.             WriteBytes(BitConverter.GetBytes(value));
  50.         }
  51.  
  52.         public void WriteFloat(float value)
  53.         {
  54.             WriteBytes(BitConverter.GetBytes(value));
  55.         }
  56.  
  57.         /**
  58.      * Write int to buffer.
  59.      *
  60.      * @param buf
  61.      * @param value
  62.      */
  63.  
  64.         protected void writeD(int value)
  65.         {
  66.             WriteInt(value);
  67.         }
  68.  
  69.         /**
  70.          * Write short to buffer.
  71.          *
  72.          * @param buf
  73.          * @param value
  74.          */
  75.  
  76.         protected void writeH(int value)
  77.         {
  78.             WriteShort((short) value);
  79.         }
  80.  
  81.         /**
  82.          * Write byte to buffer.
  83.          *
  84.          * @param buf
  85.          * @param value
  86.          */
  87.  
  88.         protected void writeC(int value)
  89.         {
  90.             WriteByte((byte) value);
  91.         }
  92.  
  93.         /**
  94.          * Write double to buffer.
  95.          *
  96.          * @param buf
  97.          * @param value
  98.          */
  99.  
  100.         protected void writeDF(double value)
  101.         {
  102.             WriteDouble(value);
  103.         }
  104.  
  105.         /**
  106.          * Write float to buffer.
  107.          *
  108.          * @param buf
  109.          * @param value
  110.          */
  111.  
  112.         protected void writeF(float value)
  113.         {
  114.             WriteFloat(value);
  115.         }
  116.  
  117.         /**
  118.          * Write long to buffer.
  119.          *
  120.          * @param buf
  121.          * @param value
  122.          */
  123.  
  124.         protected void writeQ(long value)
  125.         {
  126.             WriteLong(value);
  127.         }
  128.  
  129.         /**
  130.      * Write String to buffer
  131.      *
  132.      * @param buf
  133.      * @param text
  134.      */
  135.  
  136.         protected void writeS(String text)
  137.         {
  138.             WriteString(text);
  139.         }
  140.  
  141.         /**
  142.          * Write byte array to buffer.
  143.          *
  144.          * @param buf
  145.          * @param data
  146.          */
  147.  
  148.         protected void writeB(byte[] data)
  149.         {
  150.             WriteBytes(data);
  151.         }
  152.  
  153.         public void WriteSbyte(sbyte[] s)
  154.         {
  155.             using (var writ = new BinaryWriter(this))
  156.             {
  157.                 for (var i = 0; i < s.Length; i++)
  158.                 {
  159.                     writ.Write(s[i]);
  160.                 }
  161.             }
  162.         }
  163.  
  164.         public void WriteString(string str)
  165.         {
  166.             foreach (var c in str)
  167.             {
  168.                 var tmp = BitConverter.GetBytes(c);
  169.                 WriteBytes(tmp);
  170.             }
  171.             WriteShort(0);
  172.         }
  173.  
  174.         public void WriteAionDescription(int message)
  175.         {
  176.             WriteShort(0x24);
  177.             WriteInt(message);
  178.             WriteShort(0);
  179.         }
  180.  
  181.         public abstract void WritePacket();
  182.     }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement