예제 #1
0
  /**
   * 登陆请求
   *
   * @return
   * @throws IOException
   */
  public Response login() throws IOException {

    initTestToken();

    UserToken userToken = checkUserLogin(tk, getUserId(), pid, sid);
    if (userToken != null) {
      // 暂时屏蔽
      kickoutOtherSession(userToken);
      UserSessionManager.getInstance()
          .setUserSession(userToken.getUserId(), request.getSession().getSid());

      Session session = ServerConnectorMgr.getInstance().getServerSession("logic");
      if (session == null) {
        LOG.info("无法获取服务器连接session");
      }
      InetSocketAddress address =
          (InetSocketAddress) request.getSession().getChannel().getRemoteAddress();
      Message msg = getProxyMessage();
      msg.setAct("User.login");
      // ut暂时无用
      msg.setAttribate("ut", ut);
      msg.setAttribate("tk", tk);
      msg.setAttribate("ip", address.getHostName());
      msg.setAttribate("uid", userToken.getUserId());
      request.getSession().setAttribute("userToken", userToken);
      session.send(msg);
    }
    return null;
  }
예제 #2
0
 public Response guideStep() throws IOException {
   UserToken userToken = (UserToken) request.getSession().getAttribute("userToken");
   Session session = ServerConnectorMgr.getInstance().getServerSession("logic");
   Message msg = getProxyMessage();
   msg.setAct("User.guideStep");
   msg.setAttribate("uid", userToken.getUserId());
   msg.setAttribate("gs", request.getParameter("gs"));
   session.send(msg);
   return null;
 }
예제 #3
0
 /**
  * 检测用户昵称
  *
  * @return
  * @throws IOException
  */
 public Response checkName() throws IOException {
   UserToken userToken = (UserToken) request.getSession().getAttribute("userToken");
   Session session = ServerConnectorMgr.getInstance().getServerSession("logic");
   if (session != null) {
     Message msg = getProxyReqMessage();
     msg.setAct("User.checkName");
     msg.setAttribate("uid", userToken.getUserId());
     session.send(msg);
   }
   return null;
 }
예제 #4
0
  public Response reLogin() throws IOException {

    // initTestToken();

    // tk = "tk00000013";

    UserToken userToken = TokenManager.getInstance().getToken(tk);
    if (userToken == null && tk != null) {
      OfflineUserToken offlineUserToken = OfflineTokenManager.getInstance().getToken(tk);
      // 离线不超过一个小时可以再次登录
      if (offlineUserToken != null
          && System.currentTimeMillis() - offlineUserToken.getLogoutTime() < 12 * 60 * 60 * 1000) {
        userToken = new UserToken();
        userToken.setUserId(offlineUserToken.getUserId());
        userToken.setPartnerUserId(offlineUserToken.getPartnerUserId());
        userToken.setServerId(offlineUserToken.getServerId());
        userToken.setPartnerId(offlineUserToken.getPartnerId());
        userToken.setToken(offlineUserToken.getToken());
        TokenManager.getInstance().setToken(userToken.getToken(), userToken);

        // 从离线那清掉
        OfflineTokenManager.getInstance().removeToken(tk);
      }
    }

    if (userToken == null) {
      throw new ServiceException(
          LOGIN_NOT_LOGIN, "userToken为空[" + tk + ":" + getUserId() + ":" + pid + "]");
    }

    // UserToken userToken = checkUserLogin(tk, getUserId(), pid, sid);
    if (userToken != null) {
      // 暂时屏蔽
      kickoutOtherSession(userToken);
      UserSessionManager.getInstance()
          .setUserSession(userToken.getUserId(), request.getSession().getSid());

      Session session = ServerConnectorMgr.getInstance().getServerSession("logic");
      if (session == null) {
        LOG.info("无法获取服务器连接session");
      }
      InetSocketAddress address =
          (InetSocketAddress) request.getSession().getChannel().getRemoteAddress();
      Message msg = getProxyMessage();
      msg.setAct("User.reLogin");
      msg.setAttribate("ut", ut);
      msg.setAttribate("tk", tk);
      msg.setAttribate("ip", address.getHostName());
      msg.setAttribate("uid", userToken.getUserId());
      request.getSession().setAttribute("userToken", userToken);
      session.send(msg);
    }
    return null;
  }
예제 #5
0
 /**
  * 创建游戏角色
  *
  * @return
  * @throws IOException
  */
 public Response create() throws IOException {
   Session session = request.getSession();
   UserToken userToken = (UserToken) session.getAttribute("userToken");
   Session logicSession = ServerConnectorMgr.getInstance().getServerSession("logic");
   if (logicSession != null) {
     // 发送创建角色消息到逻辑服
     InetSocketAddress address =
         (InetSocketAddress) request.getSession().getChannel().getRemoteAddress();
     Message msg = getProxyMessage();
     msg.setAct("User.create");
     msg.setAttribate("uid", userToken.getUserId());
     msg.setAttribate("sh", sh);
     msg.setAttribate("rn", rn);
     msg.setAttribate("ip", address.getHostName());
     logicSession.send(msg);
   }
   return null;
 }
예제 #6
0
 /**
  * 踢掉同一个用户的其它登陆链接
  *
  * @param userToken
  */
 private void kickoutOtherSession(UserToken userToken) {
   String sessionId = UserSessionManager.getInstance().getUserSessionId(userToken.getUserId());
   Session session = DefaultSessionManager.getInstance().getSession(sessionId);
   if (session != null) {
     Message msg = new Message();
     msg.setAct("error");
     msg.setRc(CodeConstants.KICKOUT);
     try {
       ChannelFuture future = session.send(msg);
       future.addListener(
           new ChannelFutureListener() {
             @Override
             public void operationComplete(ChannelFuture future) throws Exception {
               future.getChannel().close();
             }
           });
     } catch (IOException e) {
       LOG.error(e.getMessage(), e);
     }
   }
 }