Advertisement
Guest User

PlayerSendPackets

a guest
Nov 12th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.95 KB | None | 0 0
  1. using PangyaAPI.BinaryModels;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using PangyaCryptography;
  6.  
  7. namespace PangyaAPI
  8. {
  9.     public partial class Player
  10.     {
  11.  
  12.         public void Send(byte[] message, bool compress = true)
  13.         {
  14.            
  15.                 var buffer = new PangyaBuffer(compress);
  16.                 buffer._message = message;
  17.  
  18.                 var result = buffer.GetPacket(Key);
  19.  
  20.                 Tcp.GetStream().Write(result, 0, result.Length);
  21.         }
  22.  
  23.  
  24.         //Envia Resposta através do PangyaBinaryWriter
  25.         public void SendResponse(bool compress = false)
  26.         {
  27.             Send(Response.GetBytes(), compress);
  28.  
  29.             Response = new PangyaBinaryWriter(new MemoryStream());
  30.         }
  31.         public void Send(List<byte[]> list, bool compress = false)
  32.         {
  33.             var buffer = new PangyaBuffer(compress);
  34.             list.ForEach(item => buffer._message = (item));
  35.             list.ForEach(item => File.WriteAllBytes(@"C:\savepacket\Sends.hex", item));
  36.  
  37.             var result = buffer.GetPacket(Key);
  38.  
  39.             Tcp.GetStream().Write(result, 0, result.Length);
  40.         }
  41.         public void SendResponse(List<byte[]> list, bool compress = true)
  42.         {
  43.             list.ForEach(item => Response.Write(item));
  44.             list.ForEach(item =>  File.WriteAllBytes(@"C:\savepacket\Sends.hex", item));
  45.             SendResponse(compress);
  46.         }
  47.         public void SendResponse(byte[] message, bool compress = false)
  48.         {
  49.             Response.Write(message);
  50.             SendResponse(compress);
  51.         }
  52.  
  53.         /// <summary>
  54.         /// Teste              
  55.         /// </summary>
  56.         /// <param name="send"></param>
  57.         public void SendBytes(byte[] send)
  58.         {
  59.             Tcp.GetStream().Write(send, 0, send.Length);
  60.         }
  61.  
  62.         /// <summary>
  63.         /// Envia mensagem de um jogador para o outro
  64.         /// </summary>
  65.         /// <param name="player">Player Destino</param>
  66.         /// <param name="message">Mensagem a ser enviada</param>
  67.         /// <param name="sendToMe">Indica se o player de origem deve reseber a mesma mensagem</param>
  68.         public void SendToAnotherPlayer(Player player, byte[] message, bool sendToMe = true)
  69.         {
  70.             player.SendResponse(message);
  71.             this.SendResponse(message);
  72.         }
  73.        
  74.         #region Send + BufferOld
  75.         /// <summary>
  76.         /// SendBuffer OLD + buffer OLD
  77.         /// </summary>
  78.         /// <param name="message"></param>
  79.         /// <param name="compress"></param>
  80.         public void SendBuffer(byte[] message, bool compress = true)
  81.         {
  82.  
  83.             var buffer = new PangyaBufferOld(compress);
  84.             buffer._message = message;
  85.  
  86.             var result = buffer.GetPacket(Key);
  87.  
  88.             Tcp.GetStream().Write(result, 0, result.Length);
  89.         }
  90.  
  91.         //Envia Resposta através do PangyaBinaryWriter
  92.         public void ClientResponse(bool compress = false)
  93.         {
  94.             SendBuffer(Response.GetBytes(), compress);
  95.  
  96.             Response = new PangyaBinaryWriter(new MemoryStream());
  97.         }
  98.  
  99.         public void ClientResponse(List<byte[]> list, bool compress = false)
  100.         {
  101.             list.ForEach(item => Response.Write(item));
  102.             SendResponse(compress);
  103.         }
  104.         public void ClientResponse(byte[] message, bool compress = false)
  105.         {
  106.             Response.Write(message);
  107.             ClientResponse(compress);
  108.         }
  109.  
  110.         #endregion
  111.         #region PROJECTG Emulator Sends
  112.         //public List<byte[]> SendFromProjectGEmulator()
  113.         //{
  114.         //    //Obtém resposta do GameServer externo
  115.         //    var response = _projectG.Send(CurrentPacket.MessageCrypted).ToList();
  116.  
  117.         //    //Encaminha resposta para o player
  118.         //    response.ForEach(r => SendBytes(r));
  119.  
  120.         //    return response;
  121.         //}
  122.         #endregion
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement