예제 #1
0
        public static ServerPacketType Register(String name, ushort typeID,
                                                ServerPacketHandlerDelegate handler)
        {
            ServerPacketType type = Register(name, handler);

            SetTypeID(name, typeID);

            return(type);
        }
예제 #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);
        }
예제 #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));
        }
예제 #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;
        }
예제 #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;
        }