private void OnReceive(IAsyncResult ar) { try { int size = 0; try { size = this.Socket.EndReceive(ar); } catch { size = 0; } if (size <= 0) { this.Close( ); } else { byte [] tmp = this.Buffer.Take(size).ToArray( ); if (this.Status == ClientStatus.Connection) { if (size == 4) { return; } else if (size == 120) { tmp = tmp.Skip(4).ToArray( ); } this.Status = ClientStatus.Login; } if (size < 12) { this.Close( ); return; } PSecurity.Decrypt(tmp); //Log.Normal ( $"Size: {tmp.Length:N0}{Environment.NewLine}{string.Join ( ", ", tmp.Select ( a => $"0x{$"{a:X}".PadLeft ( 2, '0' )}" ) )}" ); PControl.Controller(this, tmp); } } catch (Exception ex) { Log.Error(ex); } finally { this.BeginReceive( ); } }
// Envia pacote public void Send <T> (T o) { if (o == null) { throw new Exception(""); } else { byte [] send = PConvert.ToByteArray(o); Log.Snd(this, PConvert.ToStruct <SHeader> (send)); PSecurity.Encrypt(ref send); this.Socket.BeginSend(send, 0, send.Length, SocketFlags.None, null, null); } }