コード例 #1
0
 /** 迁移当前机子的数据到其他机子 */
 public String updateCfgToOtherServer(ChangeServerVo changeServerVo) {
   String result = "success";
   try {
     WorldServer worldServer = CacheService.getWorldServerById(changeServerVo.getId());
     changeServerVo.setRemark("修改" + worldServer.getName() + "数据库配置中");
     if (changeServerVo.getServerId() == worldServer.getServerId()) {
       changeServerVo.setRemark("服务已在当前服务器,请确认目标服务器是否正确");
       result = "服务已在当前服务器,请确认目标服务器是否正确";
       return result;
     }
     int serverId = changeServerVo.getServerId(); // 迁移目标serverId
     Server server = CacheService.getServerById(serverId);
     String publicip = server.getServerName().trim(); // 目标机子公共ip
     // 获取排好序的world列表(port倒序)
     List<WorldServer> worldServerList = worldServerDao.getWorldServerListByServerId(serverId);
     if (worldServerList != null && worldServerList.size() > 0) {
       WorldServer worldServerTemp = worldServerList.get(0); // 获取port最大的WorldServer
       // 判断目标机子上是否已经存在改端口
       if (worldServerDao.get(
               new String[] {"port", "serverId"},
               new Object[] {worldServerTemp.getPort() + 1, serverId})
           != null) {
         result = "world存在相同的port,生成失败";
         System.out.println("world存在相同的port,生成失败");
         return result;
       }
       worldServer.setPort(worldServerTemp.getPort() + 1);
       worldServer.setAdminport(worldServerTemp.getAdminport() + 1);
       worldServer.setHttpport(worldServerTemp.getHttpport() + 1);
     } else { // 如果该机子没有记录,则设置初设值
       worldServer.setPort(6860);
       worldServer.setAdminport(28960);
       worldServer.setHttpport(6660);
     }
     worldServer.setServerId(serverId);
     worldServer.setAccountId(CacheService.getAccountServerByServerId(serverId).getId());
     worldServer.setPublicip(publicip);
     this.saveOrUpdate(worldServer);
     CacheService.initWorldServer();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return result;
 }
コード例 #2
0
 public void saveOrUpdateWorld(WorldServer worldServers) {
   try {
     WorldServer worldServer = null;
     if (worldServers.getId() == null) {
       worldServer = new WorldServer();
     } else {
       worldServer = this.get(worldServers.getId());
     }
     worldServer.setGameId(worldServers.getGameId());
     worldServer.setServerId(worldServers.getServerId());
     worldServer.setAccountId(worldServers.getAccountId());
     worldServer.setModelPath(worldServers.getModelPath());
     worldServer.setUpdatePath(worldServers.getUpdatePath());
     worldServer.setName(worldServers.getName());
     worldServer.setLocalip(worldServers.getLocalip());
     worldServer.setPort(worldServers.getPort());
     worldServer.setAdminip(worldServers.getAdminip());
     worldServer.setAdminport(worldServers.getAdminport());
     worldServer.setHttpip(worldServers.getHttpip());
     worldServer.setPublicip(worldServers.getPublicip());
     worldServer.setHttpport(worldServers.getHttpport());
     worldServer.setAuthip(worldServers.getAuthip());
     worldServer.setAuthport(worldServers.getAuthport());
     worldServer.setServerpassword(worldServers.getServerpassword());
     worldServer.setAreaid(worldServers.getAreaid());
     worldServer.setMachinecode(worldServers.getMachinecode());
     worldServer.setServerType(worldServers.getServerType());
     worldServer.setDid(worldServers.getDid());
     worldServer.setPath(worldServers.getPath());
     worldServer.setState(worldServers.getState());
     worldServer.setIsDeploy(worldServers.getIsDeploy());
     worldServer.setOrders(worldServers.getOrders());
     this.saveOrUpdate(worldServer);
     CacheService.initWorldServer();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #3
0
 @Override
 public void initCache() {
   CacheService.initWorldServer();
 }
コード例 #4
0
 /** 生成worldServer对象 */
 public String createWorldServer(WorldServer worldServers, String mergeIds) {
   String createResult = "";
   try {
     String cnType = Application.getConfig("system", "cnType"); // 分区前缀类型
     int serverId = worldServers.getServerId(); // 服务器Id(哪台机子)
     Server server = CacheService.getServerById(serverId);
     int machinecode = worldServers.getMachinecode(); // 分区号
     String publicip = server.getServerName().trim(); // 公网ip
     String battleip = worldServers.getBattleip(); // 对战服ip
     int battleport = worldServers.getBattleport(); // 对战服端口
     String areaId = cnType + "_" + machinecode; // 加前缀的分编号,如“CN_1”
     int serverType = worldServers.getServerType();
     String path = getWorldPath(worldServers, cnType);
     String name = getWorldName(worldServers, cnType);
     List<WorldServer> worldServerListCheck =
         worldServerDao.getWorldServerByServerTypeAndAreaId(serverType, machinecode);
     if (worldServerListCheck != null && worldServerListCheck.size() > 0) {
       createResult = "存在相同類型和分區號的記錄";
       return createResult;
     }
     WorldServer worldServer = null;
     List<WorldServer> worldServerList =
         worldServerDao.getWorldServerListByServerId(worldServers.getServerId());
     if (worldServerList != null && worldServerList.size() > 0) {
       worldServer = new WorldServer();
       WorldServer worldServerTemp = worldServerList.get(0);
       BeanUtils.copyProperties(worldServer, worldServerTemp);
       if (worldServerDao.get(
               new String[] {"port", "serverId"},
               new Object[] {worldServerTemp.getPort() + 1, serverId})
           != null) {
         createResult = "存在相同的port,生成失败";
         return createResult;
       }
       worldServer.setId(null);
       worldServer.setPort(worldServerTemp.getPort() + 1);
       worldServer.setAdminport(worldServerTemp.getAdminport() + 1);
       worldServer.setHttpport(worldServerTemp.getHttpport() + 1);
       worldServer.setAuthport(worldServerTemp.getAuthport());
       worldServer.setUpdateTime(null);
       worldServer.setState(0);
       worldServer.setIsDeploy(1);
       worldServer.setMergeIds("");
     } else {
       worldServer = this.getDefaultWorld();
     }
     worldServer.setServerId(serverId);
     worldServer.setAccountId(CacheService.getAccountServerByServerId(serverId).getId());
     worldServer.setName(name);
     worldServer.setPublicip(publicip);
     worldServer.setAreaid(areaId);
     worldServer.setMachinecode(machinecode);
     worldServer.setBattleport(battleport);
     worldServer.setBattleip(battleip);
     worldServer.setPath(path);
     worldServer.setServerType(worldServers.getServerType());
     worldServer.setOrders(this.getMaxOrderByType(serverType, worldServers.getOrders()) + 1);
     if (worldServers.getIsDeploy() != null) {
       worldServer.setIsDeploy(worldServers.getIsDeploy());
     }
     // 合服區
     if (!StringUtils.isEmpty(mergeIds)) {
       // String mergeIds = "";
       StringBuilder sb = new StringBuilder();
       String[] mergeIdArray = mergeIds.split(",");
       // if (mergeIdArray.length == 2) {
       for (String id : mergeIdArray) {
         if (!StringUtils.isNumeric(id)) {
           createResult = "合服id串格式錯誤";
           return createResult;
         }
         String mergeId = cnType + "_" + id;
         sb.append(mergeId).append(",");
       }
       mergeIds = sb.substring(0, sb.lastIndexOf(","));
       // } else if (mergeIdArray.length == 1) {
       // mergeIds = cnType + "_" + mergeIdArray[0];
       // } else {
       // createResult = "名稱格式錯誤";
       // return createResult;
       // }
       worldServer.setMergeIds(mergeIds);
     }
     this.saveOrUpdate(worldServer);
     CacheService.initWorldServer();
     createResult = "true";
   } catch (Exception e) {
     e.printStackTrace();
     createResult = "遇到未知错误";
   }
   return createResult;
 }