Exemplo n.º 1
0
        private byte[] MessageContentSerializer()
        {
            byte[] token         = Encoding.UTF8.GetBytes(Token);
            byte[] content       = Encoding.UTF8.GetBytes(Content);
            ushort contentLength = (ushort)content.Length;

            return(Server.Combine(token, new byte[] { (byte)(contentLength & 65280), (byte)(contentLength & 255) }, content));
        }
Exemplo n.º 2
0
        private byte[] LoginSerializer()
        {
            byte[] username       = Encoding.UTF8.GetBytes(Username);
            ushort usernameLength = (ushort)username.Length;

            byte[] password       = Encoding.UTF8.GetBytes(Password);
            ushort passwordLength = (ushort)password.Length;

            return(Server.Combine(new byte[] { (byte)(usernameLength & 65280), (byte)(usernameLength & 255) }, username, new byte[] { (byte)(passwordLength & 65280), (byte)(passwordLength & 255) }, password));
        }
Exemplo n.º 3
0
 new public byte[] Serialize()
 {
     byte[] baseBytes = base.Serialize();
     baseBytes = Server.Combine(baseBytes, GetBytes((UInt32)RequestIds.Length));
     foreach (var req in RequestIds)
     {
         baseBytes = Server.Combine(baseBytes, GetBytes(req));
     }
     return(baseBytes);
 }
Exemplo n.º 4
0
 private byte[] SerializeMessage(Message message)
 {
     byte[] messageId      = new byte[] { (byte)(message.Id & 4278190080), (byte)(message.Id & 16711680), (byte)(message.Id & 65280), (byte)(message.Id & 255) };
     byte[] content        = Encoding.UTF8.GetBytes(message.Content);
     byte[] contentLength  = new byte[] { (byte)(content.Length & 65280), (byte)(content.Length & 255) };
     byte[] username       = Encoding.UTF8.GetBytes(message.Author.Username);
     byte[] usernameLength = new byte[] { (byte)(username.Length & 65280), (byte)(username.Length & 255) };
     byte[] date           = BitConverter.GetBytes(message.CreationTime.Ticks);
     return(Server.Combine(messageId, usernameLength, username, contentLength, content, date));
 }
Exemplo n.º 5
0
 private byte[] SerializeMessages()
 {
     byte[] toreturn = new byte[2] {
         (byte)(_messages.Length & 65280), (byte)(_messages.Length & 255)
     };
     foreach (var message in _messages)
     {
         var serialized = SerializeMessage(message);
         toreturn = Server.Combine(toreturn, new byte[] { (byte)(serialized.Length & 65280), (byte)(serialized.Length & 255) }, serialized);
     }
     return(toreturn);
 }
Exemplo n.º 6
0
 public virtual byte[] Serialize()
 {
     byte[] baseBytes = new byte[] { (byte)MessageType };
     if (MessageType == MessageTypes.Login)
     {
         baseBytes = Server.Combine(baseBytes, LoginSerializer());
     }
     else if (MessageType == MessageTypes.SendMesssage)
     {
         baseBytes = Server.Combine(baseBytes, MessageContentSerializer());
     }
     return(baseBytes);
 }
Exemplo n.º 7
0
 new public byte[] Serialize()
 {
     return(Server.Combine(base.Serialize(), Encoding.ASCII.GetBytes(Token)));
 }
Exemplo n.º 8
0
 public override byte[] Serialize()
 {
     return(Server.Combine(base.Serialize(), LoginSerializer()));
 }
Exemplo n.º 9
0
 new public byte[] Serialize()
 {
     return(Server.Combine(base.Serialize(), SerializeMessages()));
 }
Exemplo n.º 10
0
 new public byte[] Serialize()
 {
     byte[] ahh = base.Serialize();
     return(Server.Combine(ahh, new byte[] { (byte)(Id & 4278190080), (byte)(Id & 16711680), (byte)(Id & 65280), (byte)(Id & 255) }));
 }