Exemplo n.º 1
0
        public static ServerPacketType Register(String name, ushort typeID,
                                                ServerPacketHandlerDelegate handler)
        {
            ServerPacketType type = Register(name, handler);

            SetTypeID(name, typeID);

            return(type);
        }
Exemplo n.º 2
0
        public static ServerPacketType Register(String name,
                                                ServerPacketHandlerDelegate handler)
        {
            if (stTypeNames.ContainsKey(name))
            {
                throw new Exception("Can not register new packet type: "
                                    + "packet type already registered with the name \"" + name + "\"");
            }

            ServerPacketType type = new ServerPacketType(name, handler);

            stTypeNames.Add(name, type);

            return(type);
        }
Exemplo n.º 3
0
        public static bool HandlePacket(ServerBase sender, Stream stream)
        {
            UInt16 id = BitConverter.ToUInt16(stream.ReadBytes(2), 0);

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

            ServerPacketType type = stTypeIDs[id];

            if (type == null)
            {
                throw new Exception("Unknown packet type recieved");
            }

            return(type.PacketHandler(sender, type, stream));
        }
Exemplo n.º 4
0
        public static void SetTypeID(String name, UInt16 typeID)
        {
            ServerPacketType type = stTypeNames[name];

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

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

            type.ID = typeID;
        }
Exemplo n.º 5
0
        public static ServerPacketType Register( String name,
            ServerPacketHandlerDelegate handler)
        {
            if ( stTypeNames.ContainsKey( name ) )
                throw new Exception( "Can not register new packet type: "
                    + "packet type already registered with the name \"" + name + "\"" );

            ServerPacketType type = new ServerPacketType( name, handler );

            stTypeNames.Add( name, type );

            return type;
        }