Jump to content

Recommended Posts

Posted

Hello. Been lookin inside l2j sources for inspiration for own project ( no i, dont write lineage emulator, just and abstract universal base i made my authserver on ) and i stumbled upon the GamePacketHandler.java

 

Thats a decent factory pattern but the switch case CONNECTED AUTHED IN_GAME does not fit here.

So whats my problem? You switch the client state and so the factory goes to right "subfactory under the case". Thats definitely should be an abstarct factory and instead of the switch case state you should instantiate a conrete factory for every state. What do you think about it?

Greetz
 

Posted (edited)

You can make 3 different, overidden methods according cases and call them accordingly, but even as a comprehensive point of view that won't change a lot, ingame packets being 90% of packets.

 

Both on readable and performance views, you got no interests to do that, at least for L2 case. That's a switch drop for 3 classes/methods instead of one. And we speak of 9 packets for IL case.

Edited by Tryskell
Posted (edited)

Drop that whole class and make a big ass enum :D

Im afraid we dont understand eachother. But it happens sometimes :)

 

And to Tryskell - i would like to completly get rid of the switch between 3 states. You can instantiate concrete factory instead of changing the state enum and then switch casing esecially when 99% packtes are ingame packets. Everytime a game packet comes it checks "hey maybe in im connected on authed state" ? NO.

Edited by Szakalaka
Posted

Drop that whole class and make a big ass enum :D

 

Similar to that ? (Simple copy paste from stackoverflow)

enum Type {
    Y_TYPE(1) {
        @Override
        public X createInstance() {
            return new Y();
        }
    }, Z_TYPE(2) {
        @Override
        public X createInstance() {
            return new Z();
        }
    };

    private int id;

    private Type(int id) { 
        this.id = id; 
    }

    public abstract X createInstance();
}
Posted

They say noone understands good programmers. And noone seems to understand me :)

 

GamePacketHandler implements some abstract factory. And inside it has a switch based on cases lol. Every case should be another factory and the main GamePacketHandler should be set to factory of current state. Thats my point of view.

Posted

Damn I don't have the class anymore here, mind gisting/pastin whatever it ?

 

And no Tryskell we took a different approach, which I guess won't work with regular mmocore since it reuse some netty capability.

Posted

It will still need to check the state in the abstract factory. The only difference is that, you now have to instantiate one more object (e.g. the appropriate factory). :lol:

Sure, it's more readable that way.

Posted

No!! You instantiate the factory and the "guy who gets packet to pass to factory" passes it to ABSTARCT factory which is instantiated to CONCRETE instance of current state! Oh damn.  Well it works on my server. I dont want you to redesign anything - jsut asked for opinion

Posted (edited)
public enum IncomingPackets implements IIncomingPackets<L2GameClient>
{
	LOGOUT(0x00, Logout::new, ConnectionState.AUTHENTICATED, ConnectionState.IN_GAME),
	ATTACK(0x01, Attack::new, ConnectionState.IN_GAME),
	REQUEST_START_PLEDGE_WAR(0x03, RequestStartPledgeWar::new, ConnectionState.IN_GAME),
	REQUEST_REPLY_START_PLEDGE(0x04, RequestReplyStartPledgeWar::new, ConnectionState.IN_GAME),
	REQUEST_STOP_PLEDGE_WAR(0x05, RequestStopPledgeWar::new, ConnectionState.IN_GAME),
	REQUEST_REPLY_STOP_PLEDGE_WAR(0x06, RequestReplyStopPledgeWar::new, ConnectionState.IN_GAME),
	REQUEST_SURRENDER_PLEDGE_WAR(0x07, RequestSurrenderPledgeWar::new, ConnectionState.IN_GAME),
	REQUEST_REPLY_SURRENDER_PLEDGE_WAR(0x08, RequestReplySurrenderPledgeWar::new, ConnectionState.IN_GAME),
	REQUEST_SET_PLEDGE_CREST(0x09, RequestSetPledgeCrest::new, ConnectionState.IN_GAME),
	REQUEST_GIVE_NICK_NAME(0x0B, RequestGiveNickName::new, ConnectionState.IN_GAME),
	CHARACTER_CREATE(0x0C, CharacterCreate::new, ConnectionState.AUTHENTICATED),
	CHARACTER_DELETE(0x0D, CharacterDelete::new, ConnectionState.AUTHENTICATED),
	PROTOCOL_VERSION(0x0E, ProtocolVersion::new, ConnectionState.CONNECTED),
......

such kind of enum...

1st value is the packet optype, 2nd value is the class file factory, the next ones are just in which states the packet should be active.

Edited by Nik
Posted

Yes we are, you don't even know what we do with it lol

 

Anyway, I checked and it's netty specific, nvm as you said :D

Posted

The idea of abstarct factory is to skip IF or SWITCH CASE checks for current state. The switch case by opcodes for concrete factory is fine and the way to create concrete packet.

Instead of having the enum with state abstract factory would be instantiated to concrete one with current state. And voila, if u receive a packet from game it will NOT get checked "am i in auth? am i in connected? " NO because the factory would be set.

 

Thats enough thats for feedback :D

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Where's the proof? I can tell you're a scammer.
    • Where was I called a scammer? Is there any proof, etc.? There are a lot of reviews about our store online, etc. https://zhyk.org/forum/showthread.php?t=1108673
    • U was reported as scammer in your previos topic why u create new topic?
    • 🔍 Inventory 1.0 is a next-generation inventory system that stands out with its special minimal clothing system. Carefully designed and prepared according to the highest standards of your server, it not only enhances your gaming experience but also contributes to your server's infrastructure. ⚙️ Supported: QB-CORE Features: ✅ Instant Delivery: All products you purchase will be instantly assigned to your account as soon as your payment is completed. ✅ Clothing System: With the special animated clothing configurations in your inventory, you will be able to change outfits with ease. Experience a unique roleplaying experience with high-quality animations and customizable clothing options. ✅ Minimalist Inventory System: This inventory system, with its visuals, animations, and mechanics, offers maximum efficiency without overwhelming your screen and limiting your roleplaying experience. It’s designed to be user-friendly while enhancing your roleplaying experience. ✅ Continuous Updates: The content in the inventory is regularly updated with innovative features added. New animations, additional clothing options, and cutting-edge features ensure a fresh and dynamic experience. ✅ Easy Setup and Compatibility: Compatible with QB-CORE, this system is easy to install and optimized for quick integration into your server. It works seamlessly with a simple drag-and-drop method. ✅ Performance Optimization: The system is optimized to avoid low FPS and performance drops. All features of the inventory run smoothly without affecting your server’s performance. ✅ Multilingual Support: With support for different languages, you can cater to an international player base and build a larger community on your server. ✅ Flexible Customization Options: You can fully customize the inventory according to your needs and server rules. Choose between different outfits and animations to create a unique gaming experience. ✅ Comprehensive Help and Support: With 24/7 support, you can quickly resolve any issues you encounter. Our technical support and user guides are always here to assist you. Shop Now! Take your game to the next level with Inventory 1.0  and enjoy its unique features. Get ready to make a real difference in your roleplaying experience!   --------------------------TEBEX: https://matza.tebex.io/package/7174862 --------------------------
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock