Ejemplo n.º 1
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 @RequestMapping("/webApi/updateConfigs.do")
 public ModelAndView updateServers() {
   Map<String, Object> map = new HashMap<String, Object>();
   try {
     GameServerCache.getInstance().reload();
     Properties properties = new Properties();
     properties.load(QiHooSdk.class.getResourceAsStream("/sdk.properties"));
     Iterator<Entry<Object, Object>> iterator = properties.entrySet().iterator();
     Set<String> set = new HashSet<String>();
     while (iterator.hasNext()) {
       try {
         Entry<Object, Object> entry = iterator.next();
         String className = StringUtils.split(entry.getKey().toString(), ".")[0];
         if (!set.contains(className)) {
           Class sdkClass = Class.forName("com.lodogame.ldsg.partner.sdk." + className);
           if (sdkClass == null) {
             continue;
           }
           Method instanceMethod = sdkClass.getMethod("instance", new Class[] {});
           Method reloadMethod = sdkClass.getMethod("reload", new Class[] {});
           Object object = instanceMethod.invoke(null, null);
           reloadMethod.invoke(object, null);
           LOG.info(className + " reload!");
           set.add(className);
         }
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   // QiHooSdk.instance().reload();
   // BaiduSdk.instance().reload();
   // UcSdk.instance().reload();
   // LenovoSdk.instance().reload();
   // EasouSdk.instance().reload();
   // PartnerConfig.ins().reload();
   // BaiduZsSdk.instance().reload();
   // AnZhiSdk.instance().reload();
   // AppChinaSdk.instance().reload();
   // AppleSdk.instance().reload();
   // ChangWanSdk.instance().reload();
   // ChinaMobileSdk.instance().reload();
   // DangleSdk.instance().reload();
   // DuokuSdk.instance().reload();
   // HucnSdk.instance().reload();
   // SanqiWanwanSdk.instance().reload();
   // ShiJiaSdk.instance().reload();
   // XiaomiSdk.instance().reload();
   // KuaiBoSdk.instance().reload();
   // AnZhiAdSdk.instance().reload();
   // PPSSdk.instance().reload();
   // KuWoSdk.instance().reload();
   map.put("rc", 1000);
   ModelAndView modelView = new ModelAndView();
   MappingJacksonJsonView view = new MappingJacksonJsonView();
   view.setAttributesMap(map);
   modelView.setView(view);
   return modelView;
 }
Ejemplo n.º 2
0
  // TODO 实现获取服务器列表
  @RequestMapping("/webApi/getServerList.do")
  public ModelAndView getServerList(HttpServletRequest req) {
    String partnerId =
        StringUtils.isBlank(req.getParameter("partnerId")) ? "1001" : req.getParameter("partnerId");
    List<GameServer> serverList = null;
    String version = req.getParameter("version");
    VersionServer versionServer = null;

    if (!StringUtils.isBlank(version)) {
      versionServer = versionServerDao.getVersionServer(version);
    }
    serverList = GameServerCache.getInstance().getGameServers(partnerId);
    if (serverList != null && serverList.size() > 0) {

      boolean isSpceImei = false;
      if (req.getParameter("fr") != null
          && activeCodeDao.isBlackImei(req.getParameter("fr"), partnerId)) {
        isSpceImei = true;
      }

      if (req.getParameter("mac") != null
          && activeCodeDao.isBlackImei(req.getParameter("mac"), partnerId)) {
        isSpceImei = true;
      }

      String ip = req.getRemoteAddr();

      if (this.serverStatusDao.isWhiteIp(partnerId, ip)) {
        isSpceImei = true;
      }

      // 处理IMEI白名单
      List<GameServer> serverListForSpecImei = new ArrayList<GameServer>(serverList.size());
      for (GameServer gs : serverList) {

        // IMEI白名单中的GameServer状态都需要为1
        int status = gs.getStatus();
        if (status == 100) {
          if (isSpceImei) {
            status = 1;
          } else {
            continue;
          }
        }

        String ind = gs.getServerId().replaceAll("[a-zA-Z]+", "");
        if (versionServer != null) {
          if (versionServer.getServerId().indexOf(gs.getServerId()) < 0) {
            continue;
          }
        }
        GameServer gameServerForSpecImei = new GameServer();
        gameServerForSpecImei.setServerId(gs.getServerId());
        gameServerForSpecImei.setServerName(ind + "-" + gs.getServerName());
        gameServerForSpecImei.setServerPort(gs.getServerPort());
        gameServerForSpecImei.setStatus(status);
        gameServerForSpecImei.setOpenTime(gs.getOpenTime());
        gameServerForSpecImei.setServerHost(gs.getServerHost());

        serverListForSpecImei.add(gameServerForSpecImei);
      }

      Collections.sort(
          serverListForSpecImei,
          new Comparator<GameServer>() {

            @Override
            public int compare(GameServer o1, GameServer o2) {
              if (o1.getOpenTime() > o2.getOpenTime()) {
                return -1;
              } else if (o1.getOpenTime() < o2.getOpenTime()) {
                return 1;
              }

              return 0;
            }
          });

      // 使用为IMEI白名单定制的ServerList
      serverList = serverListForSpecImei;

    } else {
      serverList = new ArrayList<GameServer>();
      GameServer gs = new GameServer();
      gs.setServerId("d1");
      gs.setServerName("测试服务器-潮哥");
      gs.setStatus(1);
      serverList.add(gs);
    }

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("sl", serverList);
    ModelAndView modelView = new ModelAndView();
    MappingJacksonJsonView view = new MappingJacksonJsonView();
    view.setAttributesMap(map);
    modelView.setView(view);
    return modelView;
  }