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

The /server command cannot be used for Chinese name servers #1362

Closed
WarSkyGod opened this issue Jun 22, 2024 · 8 comments · May be fixed by #1363
Closed

The /server command cannot be used for Chinese name servers #1362

WarSkyGod opened this issue Jun 22, 2024 · 8 comments · May be fixed by #1363

Comments

@WarSkyGod
Copy link

When I try to use /server in my server, the Chinese name of the server is inaccessible
bug
bug2

@powercasgamer
Copy link
Contributor

powercasgamer commented Jun 22, 2024

This is a Brigadier issue, see Mojang/brigadier#103

@electronicboy electronicboy closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2024
@willkroboth
Copy link

Given that Velocity server names can contain non-ASCII characters, would it be more appropriate to use Brigadier's StringArgumentType.string() rather than the current StringArgumentType.word()? That would allow these server names to at least be input surrounded by quotes.

@electronicboy
Copy link
Member

does brig auto quote them for you or would that need to be handled elsewhere? I didn't think that there was a solution here which didn't downgrade the UX in a manner which was pretty bleh to substantiate a setup which is niche and often caused other issues

@willkroboth
Copy link

StringArgumentType.string() accepts everything that StringArgumentType.word() does (e.g. unquoted strings), so everything that worked before would still work. Additionally, if the input starts with a ", it reads any character until it finds another " (implementation here). When retrieving the argument from the command context, the quotes are not included.

@electronicboy
Copy link
Member

image

Yes, but you still cannot just send a list of server names and have the server smartly figure it out, you'd need to quote any invalid name manually, but, Mojang also does not deal with that properly, until you place the ending quote, the argument is not passed to the server to filter the list.

image image image

The only solution here would be to use a greedy string, which last I knew was something that the team was against.

@willkroboth
Copy link

I believe the desired suggestions can be generated like so (low optimization code, just proof of concept with maximum readibility):

RequiredArgumentBuilder.argument("SERVER_ARG", StringArgumentType.string())
                .suggests((ctx, builder) -> {
                    String soFar = builder.getRemaining();
                    if (soFar.isEmpty()) {
                        // Suggest all names
                        for (final RegisteredServer sv : server.getAllServers()) {
                            final String serverName = sv.getServerInfo().getName();
                            // Note: Unquoted strings do not actually accept all of ASCII
                            //  They only accept the characters defined by `StringReader#isAllowedInUnquotedString`
                            if (CharMatcher.ascii().matchesAllOf(serverName)) {
                                builder.suggest(serverName);
                            } else {
                                // Quote names that have characters which require quotes
                                builder.suggest('"' + serverName + '"');
                            }
                        }
                        return builder.buildFuture();
                    } else if (soFar.charAt(0) == '"') {
                        // Suggest all names within quotes
                        soFar = soFar.substring(1);
                        for (final RegisteredServer sv : server.getAllServers()) {
                            final String serverName = sv.getServerInfo().getName();
                            if (serverName.startsWith(soFar)) {
                                builder.suggest('"' + serverName + '"');
                            }
                        }
                    } else {
                        // Only suggest names that don't need quotes
                        for (final RegisteredServer sv : server.getAllServers()) {
                            final String serverName = sv.getServerInfo().getName();
                            if (CharMatcher.ascii().matchesAllOf(serverName) && serverName.startsWith(soFar)) {
                                builder.suggest(serverName);
                            }
                        }
                    }
                    return builder.buildFuture();
                })

StringArgumentType.getString(ctx, SERVER_ARG) will indeed never return the current input to the argument within the suggestions block. Arguments are only available in the context once they have been parsed, and if an argument is being suggested, then it hasn't been fully parsed yet. Instead, SuggestionsBuilder#getRemaining can be used to get the current input that has not yet been parsed.

@electronicboy
Copy link
Member

it's not something that I will be putting effort into, especially with my current state of health. If somebody wants to PR and test it, I or somebody might be able to get around to it, but, this is generally a bottom of the barrel sorta thing.

@willkroboth
Copy link

I noticed this is a duplicate of #1220

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

Successfully merging a pull request may close this issue.

4 participants