ekgame / bancho-api

Common API for custom osu!Bancho client and server software.
MIT License
10 stars 6 forks source link

Get Username By ID #1

Open viddie opened 8 years ago

viddie commented 8 years ago

I want to get a users name by their ID. As far as I understand all this it should be as follows:

In this repository there is actually a different packet named "PacketUserPresence" with the methods I need but it does not seem to be implemented in the bancho-api.jar.

Any ideas on how to fix this or get the username differently?

Edit: Looking at the releases source code, I see the values from "PacketUserInfo" are stored in the object but aren't visible. Can I get them in any other way? (Sorry, I am not really experienced with streams and stuff)

ekgame commented 8 years ago

I really wouldn't recommend using the release jar as library anymore. What you should do is clone this repository and use it as an exernal library.

I've made effort to handle user presence packets within the new API. I don't have any documentations on how to use the new api, so here's a quick tutorial:

BanchoClient bancho = new BanchoClientBuilder(username, password).build();

bancho.addPacketHandler((packet) -> {
    if (packet instanceof PacketReceivingFinished) {
        bancho.getClientManager().changeStatus()
            .setStatus(UserState.TESTING)
            .setBeatmap(new Beatmap(" the bot!"))
            .send();
    }
});

bancho.addEventHandler((event) -> {
    if (event instanceof EventMessage) {
        EventMessage message = (EventMessage) event;
        System.out.println(message.toString());
    }
});

With this to get the user by ID you can do:

User user = bancho.getChannelManager().getUserById(userId);