Package org.menacheri.jetserver.app

Examples of org.menacheri.jetserver.app.PlayerSession


 
  protected void onDataIn(Event event)
  {
    if (null != getSession())
    {
      PlayerSession pSession = (PlayerSession) getSession();
      NetworkEvent networkEvent = new DefaultNetworkEvent(event);
      if (pSession.isUDPEnabled())
      {
        networkEvent.setDeliveryGuaranty(FAST);
      }
      pSession.getGameRoom().sendBroadcast(networkEvent);
    }
  }
View Full Code Here


  }
 
  @Override
  public PlayerSession createPlayerSession(Player player)
  {
    PlayerSession playerSession = getSessionInstance(player);
    return playerSession;
  }
View Full Code Here

    }
  }
 
  public PlayerSession getSessionInstance(Player player)
  {
    PlayerSession playerSession = Sessions.newPlayerSession(this,player);
    return playerSession;
  }
View Full Code Here

    CountDownLatch latch = new CountDownLatch(1);
    AtomicLong counter = new AtomicLong(1l);
    Session gameRoomSession = new TestGameRoom(sessionBuilder, counter,
        latch);
    GameRoom gameRoom = (GameRoom) gameRoomSession;
    PlayerSession playerSession = gameRoom.createPlayerSession(null);
    gameRoom.connectSession(playerSession);
    playerSession.addHandler(new SessionHandlerLatchCounter(playerSession,
        counter, latch));

    // start test
    gameRoom.disconnectSession(playerSession);
    JetlangEventDispatcher gameDispatcher = (JetlangEventDispatcher) gameRoomSession
        .getEventDispatcher();
    assertNoListeners(gameDispatcher);
    Event event = Events.event(null, Events.SESSION_MESSAGE);
    playerSession.onEvent(event);
    assertFalse(latch.await(500, TimeUnit.MILLISECONDS));

    // Connect to another game room
    sessionBuilder.gameRoomName("Zombie_ROOM_2");

    Session gameRoomSession2 = new TestGameRoom(sessionBuilder, counter,
        latch);
    GameRoom gameRoom2 = (GameRoom) gameRoomSession2;
    gameRoom2.connectSession(playerSession);
    playerSession.addHandler(new SessionHandlerLatchCounter(playerSession,
        counter, latch));
    playerSession.onEvent(event);
    assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
  }
View Full Code Here

    CountDownLatch latch2 = new CountDownLatch(2);
    AtomicLong counter = new AtomicLong(0l);
    Session gameRoomSession = new TestGameRoom(sessionBuilder, counter,
        latch1);
    GameRoom gameRoom = (GameRoom) gameRoomSession;
    PlayerSession playerSession = gameRoom.createPlayerSession(null);
    PlayerSession playerSession2 = gameRoom.createPlayerSession(null);
    PlayerSession playerSession3 = gameRoom.createPlayerSession(null);
    gameRoom.connectSession(playerSession);
    gameRoom.connectSession(playerSession2);
    gameRoom.connectSession(playerSession3);
    playerSession.addHandler(new SessionHandlerLatchCounter(playerSession,
        counter, latch1));
    playerSession2.addHandler(new SessionHandlerLatchCounter(playerSession,
        counter, latch2));
    playerSession3.addHandler(new SessionHandlerLatchCounter(playerSession,
        counter, latch2));
    // start test
    Event event1 = Events.event(null, Events.DISCONNECT);
    playerSession.onEvent(event1);// disconnect session 1.
    assertFalse(latch1.await(1000, TimeUnit.MILLISECONDS));// This is just a wait
    Event message = Events.event(null, Events.SESSION_MESSAGE);
    playerSession.onEvent(message);
    assertFalse(latch1.await(500, TimeUnit.MILLISECONDS));// Ensure that the message is not sent.
    Event event2 = Events.event(null, Events.DISCONNECT);
    Event event3 = Events.event(null, Events.DISCONNECT);
    playerSession2.onEvent(event2);
    playerSession3.onEvent(event3);

    assertTrue(latch2.await(500, TimeUnit.MILLISECONDS));
    // 1 ondisconnect(session1) + 0 onnetwork(session1) + 2 ondisconnect(session2 and 3)
    assertTrue(counter.get() == 3);
  }
View Full Code Here

    }
    for (GameRoom gameRoom : gameRoomList)
    {
      for (int j = 1; j <= SESSIONS_PER_GAME_ROOM; j++)
      {
        PlayerSession playerSession = gameRoom.createPlayerSession(null);
        gameRoom.connectSession(playerSession);
        playerSession.addHandler(new SessionHandler(playerSession));
        sessionList.add(playerSession);
      }
    }
  }
View Full Code Here

    }
    else if (Events.RECONNECT == type)
    {
      LOG.debug("Reconnect attempt from {}", channel.getRemoteAddress());
      String reconnectKey = NettyUtils.readString(buffer);
      PlayerSession playerSession = lookupSession(reconnectKey);
      handleReconnect(playerSession, channel, buffer);
    }
    else
    {
      LOG.error("Invalid event {} sent from remote address {}. "
View Full Code Here

    return player;
  }
 
  public PlayerSession lookupSession(final String reconnectKey)
  {
    PlayerSession playerSession = (PlayerSession)reconnectRegistry.getSession(reconnectKey);
    if(null != playerSession)
    {
      synchronized(playerSession){
        // if its an already active session then do not allow a
        // reconnect. So the only state in which a client is allowed to
        // reconnect is if it is "NOT_CONNECTED"
        if(playerSession.getStatus() == Session.Status.NOT_CONNECTED)
        {
          playerSession.setStatus(Session.Status.CONNECTING);
        }
        else
        {
          playerSession = null;
        }
View Full Code Here

    String refKey = NettyUtils.readString(buffer);
   
    GameRoom gameRoom = lookupService.gameRoomLookup(refKey);
    if(null != gameRoom)
    {
      PlayerSession playerSession = gameRoom.createPlayerSession(player);
      gameRoom.onLogin(playerSession);
      String reconnectKey = (String)idGeneratorService
          .generateFor(playerSession.getClass());
      playerSession.setAttribute(JetConfig.RECONNECT_KEY, reconnectKey);
      playerSession.setAttribute(JetConfig.RECONNECT_REGISTRY, reconnectRegistry);
      LOG.trace("Sending GAME_ROOM_JOIN_SUCCESS to channel {}", channel.getId());
      ChannelBuffer reconnectKeyBuffer = ChannelBuffers.wrappedBuffer(NettyUtils.createBufferForOpcode(Events.GAME_ROOM_JOIN_SUCCESS), NettyUtils.writeString(reconnectKey));
      ChannelFuture future = channel.write(reconnectKeyBuffer);
      connectToGameRoom(gameRoom, playerSession, future);
      loginUdp(playerSession, buffer);
View Full Code Here

        handleGameRoomJoin(player, channel, credList.get(2));
      }
      else if (type == Events.RECONNECT)
      {
        LOG.debug("Reconnect attempt from {}", channel.getRemoteAddress());
        PlayerSession playerSession = lookupSession((String)event.getSource());
        handleReconnect(playerSession, channel);
      }
      else
      {
        LOG.error(
View Full Code Here

TOP

Related Classes of org.menacheri.jetserver.app.PlayerSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.