/// <summary> /// Sends a packet to the client constructed by prepending the size and opcode to a provided byte array. /// </summary> /// <param name="opcode">opcode</param> /// <param name="packet">packet contents</param> public void Send(ShardServerOpcode opcode, byte[] packet) { using (ByteBuffer output = new ByteBuffer()) { // the extra ushort is the opcode output.Append(Arrays.Reverse(BitConverter.GetBytes((ushort)(packet.Length + sizeof(ushort))))); output.Append((ushort)opcode); output.Append(packet); log.DebugFormat("sending {0} packet to client. size is {1} bytes including header", opcode, output.Size); Send(output.GetArraySegment()); } }
/// <summary> /// Sends the specified ArraySegment as a packet to the client. /// </summary> /// <param name="segment">packet</param> public override void Send(ArraySegment <byte> segment) { if (packetLog.IsInfoEnabled && segment.Count >= 4) { ShardServerOpcode opcode = (ShardServerOpcode)BitConverter.ToUInt16(segment.Array, segment.Offset + 2); ushort size = BitConverter.ToUInt16(new byte[] { segment.Array[segment.Offset + 1], segment.Array[segment.Offset] }, 0); // big endian string hexDump = Strings.HexDump(segment.Array, segment.Offset + 4, size - sizeof(ushort)); // sizeof the opcode packetLog.InfoFormat("Server [{0}] -> Client [{1}]", LocalEndPoint.ToString(), RemoteEndPoint.ToString()); packetLog.InfoFormat("Opcode: {0} [0x{1:x4}]", opcode, (ushort)opcode); packetLog.InfoFormat("Length: {0}", size - sizeof(ushort)); packetLog.InfoFormat("{1}{0}{1}", hexDump, Environment.NewLine); } Cipher.EncryptHeader(segment); base.Send(segment); }
/// <summary> /// Sends a packet to the client constructed of an opcode and a single byte of packet data. Frequently useful for failure response codes. /// </summary> /// <param name="opcode">opcode</param> /// <param name="responseCode">packet contents</param> public void Send(ShardServerOpcode opcode, byte responseCode) { Send(opcode, new byte[] { responseCode }); }
/// <summary> /// Sends a packet to the client constructed by prepending the size and opcode to a provided ByteBuffer. /// </summary> /// <param name="opcode">opcode</param> /// <param name="packet">packet contents</param> public void Send(ShardServerOpcode opcode, ByteBuffer packet) { Send(opcode, packet.GetBytes()); }
public MovementOutPacket(ShardServerOpcode opcode) { this.opcode = opcode; }