IGWMod.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:IGW-mod 作者:
/**
 * This method is used to reject connection when the server has server info available for IGW-mod. Unless the properties.txt explicitly says
 * it's okay to connect without IGW-Mod, by setting "optional=true".
 * @param installedMods
 * @param side
 * @return
 */
@NetworkCheckHandler
public boolean onConnectRequest(Map<String, String> installedMods, Side side){
    if(side == Side.SERVER || proxy == null) return true;
    File serverFolder = new File(proxy.getSaveLocation() + File.separator + "igwmod" + File.separator);
    if(serverFolder.exists() || new File(proxy.getSaveLocation() + File.separator + "igwmodServer" + File.separator).exists()) {//TODO remove legacy
        String str = proxy.getSaveLocation() + File.separator + "igwmod" + File.separator + "properties.txt";
        File file = new File(str);
        if(!file.exists()) {
            file = new File(proxy.getSaveLocation() + File.separator + "igwmodServer" + File.separator + "properties.txt");//TODO remove legacy
        }
        if(file.exists()) {
            try {
                FileInputStream stream = new FileInputStream(file);
                BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
                List<String> textList = new ArrayList<String>();
                String line = br.readLine();
                while(line != null) {
                    textList.add(line);
                    line = br.readLine();
                }
                br.close();

                if(textList != null) {
                    for(String s : textList) {
                        String[] entry = s.split("=");
                        if(entry[0].equals("optional")) {
                            if(Boolean.parseBoolean(entry[1])) return true;
                        }
                    }
                }
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
        String version = installedMods.get(Constants.MOD_ID);
        if(version.equals("${version}")) return true;
        return version != null && version.equals(Constants.fullVersionString());
    } else {
        return true;
    }

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号