public void Send(ref PacketWriter packet) { if (packet.Opcode == 0) return; var buffer = packet.ReadDataToSend(); try { if (Crypt.IsInitialized) { uint totalLength = (uint)packet.Size - 2; totalLength <<= 13; totalLength |= ((uint)packet.Opcode & 0x1FFF); var header = BitConverter.GetBytes(totalLength); Crypt.Encrypt(header); buffer[0] = header[0]; buffer[1] = header[1]; buffer[2] = header[2]; buffer[3] = header[3]; } clientSocket.Send(buffer, 0, buffer.Length, SocketFlags.None); string clientInfo = ((IPEndPoint)clientSocket.RemoteEndPoint).Address + ":" + ((IPEndPoint)clientSocket.RemoteEndPoint).Port; PacketLog.WritePacket(clientInfo, packet); packet.Flush(); } catch (Exception ex) { Log.Message(LogType.Error, "{0}", ex.Message); Log.Message(); clientSocket.Close(); } }
public async void Send(PacketWriter packet) { DataBuffer = packet.ReadDataToSend(true); try { DataWriter writer = new DataWriter(clientSocket.OutputStream); writer.WriteBytes(DataBuffer); await writer.StoreAsync(); packet.Flush(); } catch (Exception ex) { Log.Message(LogType.ERROR, "{0}", ex.Message); Log.Message(); clientSocket.Dispose(); } }
public void Send(PacketWriter packet) { if (packet == null) return; DataBuffer = packet.ReadDataToSend(true); try { clientSocket.Send(DataBuffer, DataBuffer.Length, SocketFlags.None); packet.Flush(); } catch (SocketException ex) { Log.Message(LogType.ERROR, "{0}", ex.Message); Log.Message(); clientSocket.Close(); } }
public void Send(PacketWriter packet) { DataBuffer = packet.ReadDataToSend(true); try { clientSocket.BeginSend(DataBuffer, 0, DataBuffer.Length, SocketFlags.None, new AsyncCallback(FinishSend), clientSocket); packet.Flush(); } catch (Exception ex) { Log.Message(LogType.ERROR, "{0}", ex.Message); Log.Message(); clientSocket.Close(); } }