public void Process(OuterNetworkConnection connection) { Connection = connection; using (Reader = new BinaryReader(new MemoryStream(Connection.Buffer))) { Read(); } try { Process(); } catch (Exception ex) { Log.WarnException("ARecvPacket", ex); } }
public void Send(IConnection state) { if (state == null || !state.IsValid) { return; } State = (OuterNetworkConnection)state; if (GetType() != typeof(SpTest) && !OuterNetworkOpcode.Send.ContainsKey(GetType())) { Log.Warn("UNKNOWN packet opcode: {0}", GetType().Name); return; } lock (WriteLock) { if (Datas == null) { try { using (MemoryStream stream = new MemoryStream()) { int lengthoffset = 6; using (BinaryWriter writer = new BinaryWriter(stream)) { WriteH(writer, 0); //Reserved for packet length switch (WorldServer.CountryCode) { case CountryCode.CN: { WriteC(writer, 0); lengthoffset = 7; } break; case CountryCode.EN: { lengthoffset = 6; } break; case CountryCode.TH: { lengthoffset = 6; } break; case CountryCode.TW: { WriteC(writer, 0); lengthoffset = 7; } break; } WriteH(writer, State.UID); WriteH(writer, (GetType() != typeof(SpTest)) ? OuterNetworkOpcode.Send[GetType()] : 0); WriteH(writer, 0); //Reserved for data length Write(writer); } Datas = stream.ToArray(); BitConverter.GetBytes((short)(Datas.Length - 2)).CopyTo(Datas, 0); BitConverter.GetBytes((short)(Datas.Length - 8)).CopyTo(Datas, lengthoffset); //Log.Debug("Send Data {0}: [{1}] {2}", GetType().Name, Datas.Length, Datas.FormatHex()); WriteScope(ref Datas); } } catch (Exception ex) { Log.Warn("Can't write packet: {0}", GetType().Name); Log.WarnException("ASendPacket", ex); return; } } } state.PushPacket(Datas); }
public void Send(IConnection state) { if (state == null || !state.IsValid) return; State = (OuterNetworkConnection)state; if (GetType() != typeof(SpTest) && !OuterNetworkOpcode.Send.ContainsKey(GetType())) { Log.Warn("UNKNOWN packet opcode: {0}", GetType().Name); return; } lock (WriteLock) { if (Datas == null) { try { using (MemoryStream stream = new MemoryStream()) { int lengthoffset = 6; using (BinaryWriter writer = new BinaryWriter(stream)) { WriteH(writer, 0); //Reserved for packet length switch (WorldServer.CountryCode) { case CountryCode.CN: { WriteC(writer, 0); lengthoffset = 7; } break; case CountryCode.EN: { lengthoffset = 6; } break; case CountryCode.TH: { lengthoffset = 6; } break; case CountryCode.TW: { WriteC(writer, 0); lengthoffset = 7; } break; } WriteH(writer, State.UID); WriteH(writer, (GetType() != typeof(SpTest)) ? OuterNetworkOpcode.Send[GetType()] : 0); WriteH(writer, 0); //Reserved for data length Write(writer); } Datas = stream.ToArray(); BitConverter.GetBytes((short)(Datas.Length - 2)).CopyTo(Datas, 0); BitConverter.GetBytes((short)(Datas.Length - 8)).CopyTo(Datas, lengthoffset); //Log.Debug("Send Data {0}: [{1}] {2}", GetType().Name, Datas.Length, Datas.FormatHex()); WriteScope(ref Datas); } } catch (Exception ex) { Log.Warn("Can't write packet: {0}", GetType().Name); Log.WarnException("ASendPacket", ex); return; } } } state.PushPacket(Datas); }