Пример #1
0
        public static ClientPacketType Register(String name, ushort typeID,
                                                ClientPacketHandlerDelegate handler)
        {
            if (stTypeNames.ContainsKey(name))
            {
                throw new Exception("Can not register new packet type:"
                                    + "packet type already registered with the name \"" + name + "\"");
            }

            ClientPacketType type = new ClientPacketType(typeID, name, handler);

            while (stTypeIDs.Count < typeID)
            {
                stTypeIDs.Add(null);
            }

            if (stTypeIDs.Count == typeID)
            {
                stTypeIDs.Add(type);
            }
            else
            {
                stTypeIDs[typeID] = type;
            }

            stTypeNames.Add(name, type);

            stNextID = (ushort)Math.Max(stNextID, typeID + 1);

            return(type);
        }
Пример #2
0
        public static bool HandlePacket(ClientBase sender, Stream stream)
        {
            UInt16 id = BitConverter.ToUInt16(stream.ReadBytes(2), 0);

            if (stNextID <= id)
            {
                throw new Exception("Unknown packet type recieved");
            }

            ClientPacketType type = stTypeIDs[id];

            return(type.PacketHandler(sender, type, stream));
        }
Пример #3
0
        public static ClientPacketType Register( String name, ushort typeID,
            ClientPacketHandlerDelegate handler)
        {
            if ( stTypeNames.ContainsKey( name ) )
                throw new Exception( "Can not register new packet type:"
                    + "packet type already registered with the name \"" + name + "\"" );

            ClientPacketType type = new ClientPacketType( typeID, name, handler );

            while ( stTypeIDs.Count < typeID )
                stTypeIDs.Add( null );

            if ( stTypeIDs.Count == typeID )
                stTypeIDs.Add( type );
            else
                stTypeIDs[ typeID ] = type;

            stTypeNames.Add( name, type );

            stNextID = (ushort) Math.Max( stNextID, typeID + 1 );

            return type;
        }