public void Dispatch(ISession session, IPacket packet) { BinaryReader reader = packet.CreateReader(); int guildId = reader.ReadInt32(); var guild = new Guild { Id = guildId, Name = "guild" }; IPacketBuilder responce = WorldPacketFactory.Build( WMSG.SMSG_GUILD_QUERY_RESPONSE, writer => { writer.Write(guild.Id); writer.WriteCString(guild.Name); foreach (GuildRank rank in guild.Ranks) { writer.WriteCString(rank.Name); } for (int i = 0; i < 10 - guild.Ranks.Count; i++) { writer.WriteCString(string.Empty); } writer.Write(guild.Tabard.EmblemStyle); writer.Write(guild.Tabard.EmblemColor); writer.Write(guild.Tabard.BorderStyle); writer.Write(guild.Tabard.BorderColor); writer.Write(guild.Tabard.BackgroundColor); writer.Write(0); // NEW 3.0.2 }); session.Send(responce); }
/// <inheritdoc /> /// <exception cref="ArgumentNullException">Thrown if <paramref name="builder"/> is <see langword="null"/>.</exception> public override sealed void Write(IPacketBuilder builder) { Guard.NotNull(() => builder, builder); var bitCount = this.Bits.Length; var numberCount = bitCount / LongBitCount; var numbers = new ulong[numberCount]; int numberIndex = 0; for (int i = 0; i < bitCount; i++) { if (i > 0 && i % LongBitCount == 0) { numberIndex++; } else { // TODO: Actually figure out if this is how they're packed. numbers[numberIndex] <<= 1; } numbers[numberIndex] |= Convert.ToUInt32(this.Bits[i]); } for (int i = 0; i < numberCount; i++) { builder.WriteInt64(numbers[i]); } }
/// <inheritdoc /> /// <exception cref="ArgumentNullException">Thrown if <paramref name="builder"/> is <see langword="null"/>.</exception> public sealed override void Write(IPacketBuilder builder) { Guard.NotNull(() => builder, builder); var bitCount = Bits.Length; var numberCount = bitCount / LongBitCount; var numbers = new ulong[numberCount]; int numberIndex = 0; for (int i = 0; i < bitCount; i++) { if (i > 0 && i % LongBitCount == 0) { numberIndex++; } else { // TODO: Actually figure out if this is how they're packed. numbers[numberIndex] <<= 1; } numbers[numberIndex] |= Convert.ToUInt32(Bits[i]); } for (int i = 0; i < numberCount; i++) { builder.WriteInt64(numbers[i]); } }
/// <summary> /// Writes a <see cref="PointS"/>. /// </summary> /// <param name="builder">The <see cref="IPacketBuilder">packet builder</see> to use.</param> /// <param name="vector">The <see cref="PointS"/> to write.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="builder"/> is <see langword="null"/>.</exception> /// <inheritdoc cref="PacketBuilder.WriteInt16(short)" select="exception[@cref='ObjectDisposedException']" /> public static void WriteVector(this IPacketBuilder builder, PointS vector) { Guard.NotNull(() => builder, builder); builder.WriteInt16(vector.X); builder.WriteInt16(vector.Y); }
public void Send(IPacketBuilder packetBuilder) { if (!packetBuilder.IsEmpty) { Send(packetBuilder.Build()); } }
/// <summary> /// Writes a FILETIME timestamp. /// </summary> /// <param name="builder">The <see cref="IPacketBuilder">packet builder</see> to use.</param> /// <param name="instant">An <see cref="DateTimeOffset"/> value.</param> /// <inheritdoc cref="PacketBuilder.WriteInt64(long)" select="exception[@cref='ObjectDisposedException']" /> public static void WriteTimestamp(this IPacketBuilder builder, DateTimeOffset instant) { Guard.NotNull(() => builder, builder); var timestamp = instant.ToFileTime(); builder.WriteInt64(timestamp); }
public void RegisterPacketType(int protocolId, IPacketBuilder packetType) { PacketKey key = new PacketKey(); key.ProtocolId = protocolId; packetStore[key] = packetType; }
public virtual void Register <T>(IPacketBuilder <T> builder) where T : IDataSerializer { if (builder == null) { return; } Register(typeof(T), builder); }
/// <summary> /// Writes a flags instance. /// </summary> /// <typeparam name="TFlags">The <see cref="Flags"/>-derived type to read into.</typeparam> /// <param name="builder">The <see cref="IPacketBuilder">packet builder</see> to use.</param> /// <param name="flags">The flags to write.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="builder"/> or <paramref name="flags"/> is <see langword="null"/>.</exception> public static void WriteFlags <TFlags>(this IPacketBuilder builder, TFlags flags) where TFlags : Flags { Guard.NotNull(() => builder, builder); Guard.NotNull(() => flags, flags); flags.Write(builder); }
public PacketHandler(IPacketBuilder packetBuilder) { if (packetBuilder == null) { throw new ArgumentNullException(nameof(packetBuilder)); } _packetBuilder = packetBuilder; }
public NetSocket(int id, IPacketBuilder builder) { ID = id; _byteRecvBuffer = new byte[NetOptions.SOCKET_MAX_RECV_SIZE]; _packetlist = new List <Packet>(); _listenerList = new List <ISocketListener>(); _sendList = new List <Packet>(); _packetBuilder = builder; }
public void SetUp() { Mock <IPacketValidator> mockPacketValidator = new Mock <IPacketValidator>(); mockPacketValidator .Setup(validator => validator.Validate(It.IsAny <Packet>())) .Returns(true); mockPacketValidator .Setup(validator => validator.GetChecksum(It.IsAny <Packet>())) .Returns(new byte[] { 0x1C, 0x7F }); PacketBuilder = new PacketBuilder(mockPacketValidator.Object); }
public DefaultProtocol(IProtocolFactory factory, ProtocolOptions options) { m_buffer = new Buffer <byte>(options.BufferSize); m_factory = factory; Options = options; m_keyEncoder = factory.CreateEncoder(); m_builder = factory.CreatePacketBuilder(m_buffer); m_formatter = factory.CreateObjectFormatter(); m_commandWriter = factory.CreateCommandWriter(m_builder); }
public virtual void Register(Type type, IPacketBuilder builder) { if (builder.Information == null || builder == null) { return; } lock (lockObject) { IdTable[builder.Information.Id] = builder; TypeTable[type] = builder; } }
public Connection(int id, IPacketBuilder builder) : base(id, builder) { Handlers = new MutilMap <uint, Action <Packet> >(); }
public abstract ICommandWriter CreateCommandWriter(IPacketBuilder builder);
protected bool TryGetBuilder(PacketKey key, out IPacketBuilder builder) { return(packetStore.TryGetValue(key, out builder)); }
/// <summary> /// Writes the flag bits into the specified <see cref="IPacketBuilder"/>. /// </summary> /// <param name="builder">The builder to write the bits into.</param> public abstract void Write(IPacketBuilder builder);
public TextCommandWriter(IPacketBuilder builder) { m_builder = builder; }
public void Send(IPacketBuilder packetBuilder) { if(!packetBuilder.IsEmpty) { Send(packetBuilder.Build()); } }
public BinaryCommandWriter(IPacketBuilder builder) { m_builder = builder; }
public static void WriteWorld(this IPacketBuilder builder, IWorld world) { }
private static void WriteChannel(this IPacketBuilder builder, IChannel channel) { }
/// <summary> /// /// </summary> /// <param name="builder"></param> public void Write(IPacketBuilder builder) { Guard.NotNull(() => builder, builder); builder.WriteBytes(this.bytes); }
public override ICommandWriter CreateCommandWriter(IPacketBuilder builder) { return(new TextCommandWriter(builder)); }
public TextPacketBuilderTest() { m_mockBinaryWriter = new Mock <IBinaryWriter>(MockBehavior.Strict); m_builder = new TextPacketBuilder(new Buffer <byte>(100)); }
/// <summary> /// Writes an <see cref="Int32" /> from the <see cref="PacketValueAttribute" /> value of the specified enum value. /// </summary> /// <param name="builder">The <see cref="IPacketBuilder">packet builder</see> to use.</param> /// <param name="enumValue">An enum value decorated with <see cref="PacketValueAttribute" />.</param> /// <inheritdoc cref="PacketValueExtensions.ToPacketValue(Enum)" select="exception[@cref='ArgumentException']" /> /// <inheritdoc cref="PacketValueExtensions.ToPacketValue(Enum)" select="exception[@cref='ArgumentOutOfRangeException']" /> /// <inheritdoc cref="PacketBuilder.WriteInt32(int)" select="exception[@cref='ObjectDisposedException']" /> public static void WriteInt32(this IPacketBuilder builder, Enum enumValue) { Guard.NotNull(() => builder, builder); builder.WriteInt32(enumValue.ToPacketValue()); }