Skip to content

add support for colon separated identifiers for networking #89

Description

@Yedelo

hypixel uses colons for its payload channel names, such as hypixel:hello, which fail for different reasons:

NamespacedIdentifier#toString does not work properly when there is no namespace

toString always prepends the namespace and separator :, even when the namespace is empty.
this results in identifier names like :REGISTER or :hypixel:hello
here is a proposed fix, tested with mixin:

    public String toString() {
        if (namespace.isEmpty()) {
            return identifier;
        }
        else {
            return namespace + SEPARATOR + identifier;
        }
    }

StringChannelIdentifierParser#fromString does not support colons

fromString only creates a NamespacedIdentifierImpl with a separate namespace and identifier if there is a |, it does not do this for colons.
here is a proposed fix, tested with mixin:

    public static NamespacedIdentifier fromString(String s) {
        int i = s.indexOf('|');

        if (i < 1) {
            i = s.indexOf(":");
            if (i < 1) {
                // allow null namespaces to support channel ids that do not conform
                // to OSL spec - MC did not enforce a strict spec before 1.13
                return new NamespacedIdentifierImpl("", s);
            }
        }
        return new NamespacedIdentifierImpl(s.substring(0, i), s.substring(i + 1));
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions