예제 #1
0
  private void handleChat(final Message clientMsg) {
    Message broadcastMsg;

    if (clientMsg.SUBTYPE.equals("MSG")) {

      lastActivityTime = System.currentTimeMillis();

      ChatMsg chatMsg = new ChatMsg();
      broadcastMsg = clientMsg;
      // You can't trust nobody ;)
      chatMsg.MSG = clientMsg.CHAT_MSG.MSG.replace("<", "&lt;").replace("&", "&amp;");
      chatMsg.COLOR = (String) thisSession.getUserProperties().get("COLOR");
      chatMsg.FROM = (String) thisSession.getUserProperties().get("USER");

      ChatLog logMsg = new ChatLog();
      logMsg.setDate(new Date(lastActivityTime));
      logMsg.setUser(chatMsg.FROM);
      logMsg.setMessage(chatMsg.MSG);

      try {
        chatLogRepository.insert(logMsg);
      } catch (Exception e) {
        LOG.error(e.getMessage());
      }

      broadcastMsg.CHAT_MSG = chatMsg;
      broadcastMessage(broadcastMsg, true);
    }
  }