Package net.socialgamer.cah.data

Examples of net.socialgamer.cah.data.User


  @Override
  public Map<ReturnableData, Object> handle(final RequestWrapper request,
      final HttpSession session) {
    final Map<ReturnableData, Object> data = new HashMap<ReturnableData, Object>();

    final User user = (User) session.getAttribute(SessionAttribute.USER);
    assert (user != null);

    user.noLongerVaild();
    users.removeUser(user, DisconnectReason.MANUAL);
    session.invalidate();
    return data;
  }
View Full Code Here


    this.connectedUsers = connectedUsers;
  }

  @Override
  public Map<ReturnableData, Object> handle(final RequestWrapper request, final HttpSession session) {
    final User user = (User) session.getAttribute(SessionAttribute.USER);
    assert (user != null);

    if (!user.isAdmin()) {
      return error(ErrorCode.NOT_ADMIN);
    }

    if (null == request.getParameter(AjaxRequest.NICKNAME)
        || request.getParameter(AjaxRequest.NICKNAME).isEmpty()) {
      return error(ErrorCode.NO_NICK_SPECIFIED);
    }

    final User kickUser = connectedUsers.getUser(request.getParameter(AjaxRequest.NICKNAME));
    if (null == kickUser) {
      return error(ErrorCode.NO_SUCH_USER);
    }

    final Map<ReturnableData, Object> kickData = new HashMap<ReturnableData, Object>();
    kickData.put(LongPollResponse.EVENT, LongPollEvent.KICKED.toString());
    final QueuedMessage qm = new QueuedMessage(MessageType.KICKED, kickData);
    kickUser.enqueueMessage(qm);

    connectedUsers.removeUser(kickUser, DisconnectReason.KICKED);
    logger.warn(String.format("Kicking %s by request of %s", kickUser.getNickname(),
        user.getNickname()));

    return new HashMap<ReturnableData, Object>();
  }
View Full Code Here

  @Override
  public Map<ReturnableData, Object> handle(final RequestWrapper request,
      final HttpSession session) {
    final Map<ReturnableData, Object> data = new HashMap<ReturnableData, Object>();

    final User user = (User) session.getAttribute(SessionAttribute.USER);
    assert (user != null);
    final boolean wall = request.getParameter(AjaxRequest.WALL) != null
        && Boolean.valueOf(request.getParameter(AjaxRequest.WALL));
    final boolean emote = request.getParameter(AjaxRequest.EMOTE) != null
        && Boolean.valueOf(request.getParameter(AjaxRequest.EMOTE));

    if (request.getParameter(AjaxRequest.MESSAGE) == null) {
      return error(ErrorCode.NO_MSG_SPECIFIED);
    } else if (wall && !user.isAdmin()) {
      return error(ErrorCode.NOT_ADMIN);
    } else {
      final String message = request.getParameter(AjaxRequest.MESSAGE).trim();

      // Intentionally leaving flood protection as per-user, rather than
      // changing it to per-user-per-game.
      if (user.getLastMessageTimes().size() >= Constants.CHAT_FLOOD_MESSAGE_COUNT) {
        final Long head = user.getLastMessageTimes().get(0);
        if (System.currentTimeMillis() - head < Constants.CHAT_FLOOD_TIME) {
          return error(ErrorCode.TOO_FAST);
        }
        user.getLastMessageTimes().remove(0);
      }

      if (message.length() > Constants.CHAT_MAX_LENGTH) {
        return error(ErrorCode.MESSAGE_TOO_LONG);
      } else if (message.length() == 0) {
        return error(ErrorCode.NO_MSG_SPECIFIED);
      } else {
        user.getLastMessageTimes().add(System.currentTimeMillis());
        final HashMap<ReturnableData, Object> broadcastData = new HashMap<ReturnableData, Object>();
        broadcastData.put(LongPollResponse.EVENT, LongPollEvent.CHAT.toString());
        broadcastData.put(LongPollResponse.FROM, user.getNickname());
        broadcastData.put(LongPollResponse.MESSAGE, message);
        if (user.isAdmin()) {
          broadcastData.put(LongPollResponse.FROM_ADMIN, true);
        }
        if (wall) {
          broadcastData.put(LongPollResponse.WALL, true);
        }
View Full Code Here

      if (!validName.matcher(nick).matches()) {
        return error(ErrorCode.INVALID_NICK);
      } else if ("xyzzy".equalsIgnoreCase(nick)) {
        return error(ErrorCode.RESERVED_NICK);
      } else {
        final User user = new User(nick, request.getRemoteAddr(),
            Constants.ADMIN_IP_ADDRESSES.contains(request.getRemoteAddr()));
        final ErrorCode errorCode = users.checkAndAdd(user, maxUsers);
        if (null == errorCode) {
          // There is a findbugs warning on this line:
          // cah/src/net/socialgamer/cah/handlers/RegisterHandler.java:85 Store of non serializable
View Full Code Here

  @Override
  public Map<ReturnableData, Object> handle(final RequestWrapper request,
      final HttpSession session) {
    final HashMap<ReturnableData, Object> ret = new HashMap<ReturnableData, Object>();

    final User user = (User) session.getAttribute(SessionAttribute.USER);
    if (user == null) {
      ret.put(AjaxResponse.IN_PROGRESS, Boolean.FALSE);
      ret.put(AjaxResponse.NEXT, AjaxOperation.REGISTER.toString());
    } else {
      // They already have a session in progress, we need to figure out what they were doing
      // and tell the client where to continue from.
      ret.put(AjaxResponse.IN_PROGRESS, Boolean.TRUE);
      ret.put(AjaxResponse.NICKNAME, user.getNickname());

      if (user.getGame() != null) {
        ret.put(AjaxResponse.NEXT, ReconnectNextAction.GAME.toString());
        ret.put(AjaxResponse.GAME_ID, user.getGame().getId());
      } else {
        ret.put(AjaxResponse.NEXT, ReconnectNextAction.NONE.toString());
      }
    }
View Full Code Here

    final long start = System.nanoTime();
    // Pick a random timeout point between [TIMEOUT_BASE, TIMEOUT_BASE + TIMEOUT_RANDOMNESS)
    // nanoseconds from now.
    final long end = start + TIMEOUT_BASE + (long) (Math.random() * TIMEOUT_RANDOMNESS);
    final User user = (User) hSession.getAttribute(SessionAttribute.USER);
    assert (user != null);
    user.contactedServer();
    while (!(user.hasQueuedMessages()) && System.nanoTime() - end < 0) {
      try {
        user.waitForNewMessageNotification(TimeUnit.NANOSECONDS.toMillis(end - System.nanoTime()));
      } catch (final InterruptedException ie) {
        // pass
      }
    }
    if (user.hasQueuedMessages()) {
      try {
        // Delay for a short while in case there will be other messages queued to be delivered.
        // This will certainly happen in some game states. We want to deliver as much to the client
        // in as few round-trips as possible while not waiting too long.
        Thread.sleep(WAIT_FOR_MORE_DELAY);
      } catch (final InterruptedException ie) {
        // pass
      }
      final Collection<QueuedMessage> msgs = user.getNextQueuedMessages(MAX_MESSAGES_PER_POLL);
      // just in case...
      if (msgs.size() > 0) {
        final List<Map<ReturnableData, Object>> data =
            new ArrayList<Map<ReturnableData, Object>>(msgs.size());
        for (final QueuedMessage qm : msgs) {
View Full Code Here

  @Override
  protected void handleRequest(final HttpServletRequest request,
      final HttpServletResponse response, final HttpSession hSession) throws ServletException,
      IOException {
    final PrintWriter out = response.getWriter();
    final User user = (User) hSession.getAttribute(SessionAttribute.USER);
    if (null != user) {
      user.userDidSomething();
    }
    int serial = -1;
    if (request.getParameter(AjaxRequest.SERIAL.toString()) != null) {
      try {
        serial = Integer.parseInt(request.getParameter(AjaxRequest.SERIAL.toString()));
View Full Code Here

      }
    }

    try {
      final HttpSession hSession = request.getSession(true);
      final User user = (User) hSession.getAttribute(SessionAttribute.USER);

      if (verboseDebug()) {
        // TODO if we have any sort of authentication later, we need to make sure to not log passwords!
        // I could use getParameterMap, but that returns an array, and getting pretty strings out of
        // array values is a lot of work.
        final Map<String, Object> params = new HashMap<String, Object>();
        final Enumeration<String> paramNames = request.getParameterNames();
        while (paramNames.hasMoreElements()) {
          final String name = paramNames.nextElement();
          params.put(name, request.getParameter(name));
        }
        log(user, "Request: " + JSONValue.toJSONString(params));
      }

      final String op = request.getParameter(AjaxRequest.OP.toString());
      // we don't make sure they have a User object if they are doing either of the requests that
      // create or check for the User object. That would be silly.
      final boolean skipSessionUserCheck = op != null
          && (op.equals(AjaxOperation.REGISTER.toString())
          || op.equals(AjaxOperation.FIRST_LOAD.toString()));
      if (!skipSessionUserCheck && hSession.getAttribute(SessionAttribute.USER) == null) {
        returnError(user, response.getWriter(), ErrorCode.NOT_REGISTERED, serial);
      } else if (user != null && !user.isValid()) {
        // user probably pinged out, or possibly kicked by admin
        hSession.invalidate();
        returnError(user, response.getWriter(), ErrorCode.SESSION_EXPIRED, serial);
      } else {
        try {
View Full Code Here

    this.banList = banList;
  }

  @Override
  public Map<ReturnableData, Object> handle(final RequestWrapper request, final HttpSession session) {
    final User user = (User) session.getAttribute(SessionAttribute.USER);
    assert (user != null);

    if (!user.isAdmin()) {
      return error(ErrorCode.NOT_ADMIN);
    }

    if (null == request.getParameter(AjaxRequest.NICKNAME)
        || request.getParameter(AjaxRequest.NICKNAME).isEmpty()) {
      return error(ErrorCode.NO_NICK_SPECIFIED);
    }

    final String banIp;
    final User kickUser = connectedUsers.getUser(request.getParameter(AjaxRequest.NICKNAME));
    if (null != kickUser) {
      banIp = kickUser.getHostName();

      final Map<ReturnableData, Object> kickData = new HashMap<ReturnableData, Object>();
      kickData.put(LongPollResponse.EVENT, LongPollEvent.BANNED.toString());
      final QueuedMessage qm = new QueuedMessage(MessageType.KICKED, kickData);
      kickUser.enqueueMessage(qm);

      connectedUsers.removeUser(kickUser, DisconnectReason.BANNED);
      logger.info(String.format("Banning %s (%s) by request of %s", kickUser.getNickname(), banIp,
          user.getNickname()));
    } else {
      banIp = request.getParameter(AjaxRequest.NICKNAME);
      logger.info(String.format("Banning %s by request of %s", banIp, user.getNickname()));
    }
View Full Code Here

    this.gameManager = gameManager;
  }

  @Override
  public Map<ReturnableData, Object> handle(final RequestWrapper request, final HttpSession session) {
    final User user = (User) session.getAttribute(SessionAttribute.USER);
    assert (user != null);

    final int gameId;

    if (request.getParameter(AjaxRequest.GAME_ID) == null) {
View Full Code Here

TOP

Related Classes of net.socialgamer.cah.data.User

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.