public void handleGameRoomJoin(Player player, Channel channel, ChannelBuffer buffer) { String refKey = NettyUtils.readString(buffer); GameRoom gameRoom = lookupService.gameRoomLookup(refKey); if (null != gameRoom) { PlayerSession playerSession = gameRoom.createPlayerSession(); playerSession.setConnectParameter( NettyUtils.NETTY_CHANNEL, channel); // TODO is this required? gameRoom.onLogin(playerSession); LOG.trace("Sending GAME_ROOM_JOIN_SUCCESS to channel {}", channel.getId()); ChannelFuture future = channel.write(NettyUtils.createBufferForOpcode(Events.GAME_ROOM_JOIN_SUCCESS)); connectToGameRoom(gameRoom, playerSession, future); loginUdp(playerSession, buffer); } else { // Write failure and close channel. ChannelFuture future = channel.write(NettyUtils.createBufferForOpcode(Events.GAME_ROOM_JOIN_FAILURE)); future.addListener(ChannelFutureListener.CLOSE); LOG.error( "Invalid ref key provided by client: {}. Channel {} will be closed", refKey, channel.getId()); } }
public void handleLogin(Player player, Channel channel) { if (null != player) { channel.write(NettyUtils.createBufferForOpcode(Events.LOG_IN_SUCCESS)); } else { // Write future and close channel closeChannelWithLoginFailure(channel); } }
/** * Helper method which will close the channel after writing {@link Events#LOG_IN_FAILURE} to * remote connection. * * @param channel The tcp connection to remote machine that will be closed. */ private void closeChannelWithLoginFailure(Channel channel) { ChannelFuture future = channel.write(NettyUtils.createBufferForOpcode(Events.LOG_IN_FAILURE)); future.addListener(ChannelFutureListener.CLOSE); }