Jump to content

[1.7.2] Server connection events and server info on client


Recommended Posts

Posted

I have a class with these methods:

 

  Reveal hidden contents

 

 

An instance of this class is registered with FMLCommonHandler.instance().bus(). When I connect to a server

"Connected to server"

is printed to the console, but when I disconnect

"Disconnected from server"

is not (but it should, if I understand the javadoc correctly: "Fired at the client when the client is disconnected from the server.").

 

My question is, how do I get notified of being disconnected from a server (both by the client, by the server or by any sort of error)?

And once a connection is made to a server, can I still get info about the server (ip, name, whatever; I assume yes)? From where do I get that info, because I have been browsing through the javadoc for a long time, and I just cannot find the way to get some sort of reference to the currently connected server?

 

Thanks!

Posted

I have managed to get the ServerData of  a remote server by Minecraft::func_147104_D(), but now I don't know how could I get info about the singleplayer world during ClientConnectedToServerEvent:

 

  Reveal hidden contents

 

 

With a breakpoint in the else branch mc.theWorld, mc.thePlayer are null, but according to the console, I have already joined the game).

 

And I still don't know how to get notified about disconnection.

Posted

I didn't get much  (if any) further with this problem. To find a possible solution/workaround I made the task a bit more abstract, so maybe you can give me more ideas, because I'm running out of them.

 

When a player connects to a game (on a remote or the integrated server), I'd like to open (or at least get a path to) one or more files which should be unique to that server/sp world. Also, when the player disconnects (for whatever reason) I'd like to close these files (if any of them are open), or "forget" about their paths.

 

The problems I have encountered:

- during ClientConnectedToServerEvent, I cannot get a reference to the name of the current SP world

- my ClientConnectedToServerEvent handler is not called when connecting to a default bukkit server running on the same machine, due to some error in FML/Forge (I did not test this with a vanilla server) I don't have the error log right now, but I can attach it later if necessary.

- my ClientDisconnectionFromServerEvent handler never gets called, ever

- while trying to work around these with WorldEvent.Load, I have found that that event is fired variable number of times (some of those I could make some sense of and for some I couldn't)

 

Technically I could get a reference to the necessary files when things of interest happen, but that just seems like such a waste of computation power to "calculate" these things frequently when in theory I would only need to do it on connection. And with this method I still wouldn't know when to close/"forget about" these files.

 

TL;DR

- when joining a game, I would like to know the server IP (and possibly other data about it)[solved for remote servers, unsolved for local bukkit server] or the sp world name [unsolved]

- I would like to be notified, when a disconnect happens for whatever reason [unsolved]

  • 4 years later...
Posted

Ancient thread about an ancient version, locked.

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

  Reveal hidden contents

 

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.