Пример #1
0
 public void receivedMessage(Channel channel, ClientSession sender, ByteBuffer message) {
   logger.log(
       Level.SEVERE,
       getName()
           + " received message from "
           + sender.getName()
           + ". This should not be possible. This channel is outgoing only.");
 }
Пример #2
0
  /**
   * Sets the current <code>UserID</code> for this <code>Player</code>, which changes from session
   * to session. Typically this is called when the player first logs again, and not again until the
   * player logs out and logs back in.
   *
   * @param uid the player's user identifier
   */
  public void setCurrentSession(ClientSession session) {
    DataManager dataMgr = AppContext.getDataManager();
    dataMgr.markForUpdate(this);
    currentSessionRef = dataMgr.createReference(session);

    // Also inform the client of the session ID
    // FIXME, this is hacked in as the only non-channel message
    // for ease of porting -JM
    BigInteger sid = currentSessionRef.getId();
    byte[] bytes = sid.toByteArray();
    session.send(ByteBuffer.wrap(bytes));
  }
 /**
  * Find or create the player object for the given session, and mark the player as logged in on
  * that session.
  *
  * @param session which session to find or create a player for
  * @return a player for the given session
  */
 public static SwordWorldPlayer loggedIn(ClientSession session) {
   String playerBinding = PLAYER_BIND_PREFIX + session.getName();
   // try to find player object, if non existent then create
   DataManager dataMgr = AppContext.getDataManager();
   SwordWorldPlayer player;
   try {
     player = (SwordWorldPlayer) dataMgr.getBinding(playerBinding);
   } catch (NameNotBoundException ex) {
     // this is a new player
     player = new SwordWorldPlayer(playerBinding);
     logger.log(Level.INFO, "New player created: {0}", player);
     dataMgr.setBinding(playerBinding, player);
   }
   player.setSession(session);
   return player;
 }