コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: LongFlags.cs プロジェクト: shoftee/OpenStory
        /// <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]);
            }
        }
コード例 #3
0
ファイル: LongFlags.cs プロジェクト: zhuomingliang/OpenStory
        /// <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]);
            }
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
ファイル: Session.cs プロジェクト: hazzik/uwow2
 public void Send(IPacketBuilder packetBuilder)
 {
     if (!packetBuilder.IsEmpty)
     {
         Send(packetBuilder.Build());
     }
 }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        public void RegisterPacketType(int protocolId, IPacketBuilder packetType)
        {
            PacketKey key = new PacketKey();

            key.ProtocolId = protocolId;

            packetStore[key] = packetType;
        }
コード例 #8
0
ファイル: ProtoDictionaryTable.cs プロジェクト: nikes/Link
 public virtual void Register <T>(IPacketBuilder <T> builder) where T : IDataSerializer
 {
     if (builder == null)
     {
         return;
     }
     Register(typeof(T), builder);
 }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        public PacketHandler(IPacketBuilder packetBuilder)
        {
            if (packetBuilder == null)
            {
                throw new ArgumentNullException(nameof(packetBuilder));
            }

            _packetBuilder = packetBuilder;
        }
コード例 #11
0
ファイル: NetSocket.cs プロジェクト: freedomWind/p.csk2
        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;
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: ProtoDictionaryTable.cs プロジェクト: nikes/Link
 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;
     }
 }
コード例 #15
0
 public Connection(int id, IPacketBuilder builder)
     : base(id, builder)
 {
     Handlers = new MutilMap <uint, Action <Packet> >();
 }
コード例 #16
0
 public abstract ICommandWriter CreateCommandWriter(IPacketBuilder builder);
コード例 #17
0
 protected bool TryGetBuilder(PacketKey key, out IPacketBuilder builder)
 {
     return(packetStore.TryGetValue(key, out builder));
 }
コード例 #18
0
ファイル: Flags.cs プロジェクト: shoftee/OpenStory
 /// <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);
コード例 #19
0
 public TextCommandWriter(IPacketBuilder builder)
 {
     m_builder = builder;
 }
コード例 #20
0
ファイル: Session.cs プロジェクト: hazzik/uwow2
 public void Send(IPacketBuilder packetBuilder)
 {
     if(!packetBuilder.IsEmpty) {
         Send(packetBuilder.Build());
     }
 }
コード例 #21
0
 public BinaryCommandWriter(IPacketBuilder builder)
 {
     m_builder = builder;
 }
コード例 #22
0
ファイル: Packets.cs プロジェクト: zhuomingliang/OpenStory
 public static void WriteWorld(this IPacketBuilder builder, IWorld world)
 {
 }
コード例 #23
0
ファイル: Packets.cs プロジェクト: zhuomingliang/OpenStory
 private static void WriteChannel(this IPacketBuilder builder, IChannel channel)
 {
 }
コード例 #24
0
ファイル: ByteBuffer.cs プロジェクト: shoftee/OpenStory
        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        public void Write(IPacketBuilder builder)
        {
            Guard.NotNull(() => builder, builder);

            builder.WriteBytes(this.bytes);
        }
コード例 #25
0
 public override ICommandWriter CreateCommandWriter(IPacketBuilder builder)
 {
     return(new TextCommandWriter(builder));
 }
コード例 #26
0
 /// <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);
コード例 #27
0
 public TextPacketBuilderTest()
 {
     m_mockBinaryWriter = new Mock <IBinaryWriter>(MockBehavior.Strict);
     m_builder          = new TextPacketBuilder(new Buffer <byte>(100));
 }
コード例 #28
0
        /// <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());
        }