Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于版本校验bug #71

Closed
smilesnake opened this issue Aug 25, 2022 · 0 comments
Closed

关于版本校验bug #71

smilesnake opened this issue Aug 25, 2022 · 0 comments

Comments

@smilesnake
Copy link

smilesnake commented Aug 25, 2022

LoginActionHandler#handle

    String currentPluginVersion = CommonConstants.PLUGIN_VERSION;

    String userPluginVersion = body.getPluginVersion();

    // 这里是对用户版本和服务端版本补全,让两端版本长度一致
    if (StrUtil.isNotBlank(userPluginVersion)) {
        int len = currentPluginVersion.length();
        int len2 = userPluginVersion.length();
        int k = len - len2;
        String padding = "";
        for (int i = Math.abs(k); i > 0; i--) {
            padding += "0";
        }
        if (k > 0) {
            userPluginVersion += padding;
        } else if (k < 0) {
            currentPluginVersion += padding;
        }
    }

    // 比较版本,这里会用"."对用户版本和服务端版本进行切割,用于比较两端版本是否一致
    int versionState = VersionComparator.INSTANCE.compare(currentPluginVersion, userPluginVersion);
    // 客户端版本与服务端是否一致
    if (versionState > 0) {
        ctx.writeAndFlush(ResponseBuilder.system("温馨提醒~ 请尽快更新插件版本至v" + CommonConstants.PLUGIN_VERSION + "!"));
        ctx.close();
        return;
    }
    // 判断服务端版本是否有问题
    if (versionState < 0) {
        ctx.writeAndFlush(ResponseBuilder.system("当前服务端版本过低!你的版本:v" + body.getPluginVersion()
                + ",服务端版本:v" + CommonConstants.PLUGIN_VERSION));
        ctx.close();
        return;
    }

这里是不需要判断服务端的版本是否有问题,因为客户端本身就应该与服务端的版本一致,客户端不应该超过服务端的版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants