public void SendPacket(ASendPacket packet) { packet._Client = this; if (!Opcode.Send.ContainsKey(packet.GetType())) { Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name); return; } try { packet.WriteH(0); // packet len packet.WriteH(SessID); // session packet.WriteH(Opcode.Send[packet.GetType()]); // opcode packet.WriteH(0); // data len packet.Write(); byte[] Data = packet.ToByteArray(); BitConverter.GetBytes((short)(Data.Length - 2)).CopyTo(Data, 0); BitConverter.GetBytes((short)(Data.Length - 8)).CopyTo(Data, 6); Funcs.WriteScope(ref Data); if(Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex()); _stream = _client.GetStream(); _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null); } catch (Exception ex) { Log.Warn("Can't send GS packet: {0}", GetType().Name); Log.WarnException("GSASendPacket", ex); return; } }
public void SendPacket(ASendPacket packet) { packet._Client = this; if (!Opcode.Send.ContainsKey(packet.GetType())) { Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name); return; } try { packet.WriteH(0); // packet len packet.WriteH(SessID); // session packet.WriteH(Opcode.Send[packet.GetType()]); // opcode packet.WriteH(0); // data len packet.Write(); byte[] Data = packet.ToByteArray(); BitConverter.GetBytes((short)(Data.Length - 2)).CopyTo(Data, 0); BitConverter.GetBytes((short)(Data.Length - 8)).CopyTo(Data, 6); if (Configuration.Setting.Debug) { Log.Debug("Send: {0}", Data.FormatHex()); } Funcs.WriteScope(ref Data); _stream = _client.GetStream(); _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null); } catch (Exception ex) { Log.Warn("Can't send packet: {0}", GetType().Name); Log.WarnException("ASendPacket", ex); return; } }