1
votes

Actually for my server game I'm not using Netty. I've created a socket multithreaded system for send packet object who is serialized into and deserialized from (Int and Out)StreamBuffer.

I've discovered Netty and I think it's better to use it for my network system. I've actually created a Client and Server handler (both extends ChannelInboundHandlerAdapter) to serialized and deserialized my packet from the ByteBuf, it's work FINE :) !

Now I want migrate my authentication system. Actually, I've two Handler, the LoginHandler which can receive and process only the Login Packet (defined by an id when I send a buffer packet), and the ServerHandler which can receive and process all others packets.

Actual algorithme

  • Client side :
    1. User launch a client a new window ask him to enter his username and password When he click on "Login", the client connect to the server, and after send a LoginPacket.
    2. If a AuthServerPacket is sent by the server with the auth flag to true, he continue and open all others features.
    3. If a AuthServerPacket is sent by the server with the auth flag to false, it display a popup with the reason, and re-open the window login.
  • Server side :
    1. When a user is connecting to the server it's the LoginHandler which is attached to the client.
    2. In this LoginHandler, only LoginPacket is processed, so, when it receive a LoginPacket it check the informations in a database, if these are correct, the client are added to the ServerHandler and deleted from the LoginHandler, and now he can receive and send all others packets.
    3. ServerHandler send a AuthServerPacket with auth flag to true.

My question is, what is the best way to re-create this system with Netty ?

I don't know if I can add the login handler in the pipeline which it will be not check it if a channel is authentified. I don't know how or if the process is stopped if one of the handler reject the channel.

Someone can help me to understand what is the best way to do what I want with Netty ?

Thanks you in advance for your answers.
Programmatically, beaucoralk.

2

2 Answers

2
votes

we talked on IRC #netty today :)

My suggestion is:

  • In your Pipeline Initializer, always add the LoginHandler
  • Once Login is successful, then the LoginHandler should: ctx.pipeline.addAfter(this, "gameHandler", new GameLogicHandler()); ctx.pipeline.remove(this);

So basically your LoginHandler removes itself, after a successful authentication. Important: add the new Handler before removing the old Handler. :)

best regards

2
votes

I've solved my problem with this :

  • In my Pipeline Initialize always add the LoginHandler (don't add my ServerHandler)
  • Once Login is successful, then the LoginHandler do : ctx.pipeline.addLast(new GameLogicServerHandler()); ctx.pipeline.remove(this);

In fact I have not succeeded to use the addAfter like said Franz Bettag, no method was appropriate.

But thanks you to Bettag who help me to understand many things on #netty IRC.