Jump to content

[1.7.10] Checking if server is dedicated on client thread.


Recommended Posts

Posted

How can I know if the server, the client is connected to, is dedicated?

 

Not asking about isRemote or Side, because those two say something like this: "This thread is client/server." and "This world belongs to client/server."

 

What I want is client thread to say "I am now connected to dedicated/local server"

 

Why?

On client and server I have equivalent class (layer). If client is connecting to dedicated server, both client and server will generate that class and the server will send packets to synchronize data. When client disconnects both client and server will remove that data (ofc. server will first save it to NBT).

Problem appears when I am on SP. On SP (local server) there is no network bridge (packeting) between client and server, so the class described before is shared (only one). This makes my mod go crazy when player logs off because:

- client is always reacting first

- since it's reacting 1st it unloads my class with data.

- server is the one responsible for saving data (NBT), and since client was 1st and alredy removed that data, server cannot save it.

 

I need to check on client thread is server is not dedicated and if it's not then not unload my data before server saves it.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Short - layer on player.

 

Long:

Everytime player appears in game in any form, his entity is wrapped and put inside map.

ExtendedPlayer ep = ExtendedPlayer.wrapPlayer(player);

public static Map<UUID, ExtendedPlayer> playerMap = new WeakHashMap<UUID, ExtendedPlayer>();
public static ExtendedPlayer wrapPlayer(EntityPlayer player)
{
	if (playerMap.containsKey(player.getUniqueID()))
		return playerMap.get(player.getUniqueID());
	else
		return new ExtendedPlayer(player);
}

 

Map is static and is generated for both client and server.

While server gets ALL data for given player from his data files, client just creates ExtendedPlayer object with generic values. After server loads that data, it's sent to client side.

 

Now: As said before when having 2 threads (Client connected to dedicated server) I have 2 Static maps that are working nice and tidy.

When I am on SP I have to deal with client being faster than server. I have to make server act before client does (read: cancel client cleanup action IF the server is NOT dedicated)

 

Why use such a layer/map.

ExtendedProps are useless when it comes to storing and sharing such data. And without caching it on client side inside my static map packeting system would go nuts (too much data). Ofc. any changes are updated and synchronized (and everythig is still issued on server side), so there is no way to cheat this system.

1.7.10 is no longer supported by forge, you are on your own.

Posted

What can I say, thank for this diesieben: http://www.minecraftforge.net/forum/index.php?topic=10614.0

 

Anyway, I managed to pull that off with one cross-mapping:

 

if ((side == Side.CLIENT && !Minecraft.getMinecraft().isIntegratedServerRunning()) || 
			(side == Side.SERVER && MinecraftServer.getServer().isDedicatedServer()) || 
			(side == Side.SERVER && !MinecraftServer.getServer().isDedicatedServer() && Minecraft.getMinecraft().isIntegratedServerRunning()))
	{}

In if  statement:

1. Is client thread connected to dedicated server

2. Is dedicated server thread

3. Is integrated server thread

 

Anyway, launching code under this will cleanup map on server AND client if they are separated (dedicated server), and ONLY on server if they are together (integrated), so the client is no longer problem on SP.

 

Only bad thing about my whole layer is fact that it's reloaded when player changes dimension, but I saw that it also happens on IExtendedEntityProperties (documentation:  Such as when a player switches dimension {Minecraft re-creates the player entity}) so I am not worried.

 

Yeah, I am stubborn, don't do things like me kids ;p

 

Thanks

 

CLOSED

1.7.10 is no longer supported by forge, you are on your own.

Posted

Well it's all working now, but I see your point, it might be tricky in later updating and overall safety.

 

Only thing pushing me to do this is the fact it is done, and my ExtendedPlayer is saved in different directory.

 

**Can I somehow make ExtendedProps for player be saved in other place? (other than player.dat file)

 

I'll probably make a rewrite (damn you for being right).

1.7.10 is no longer supported by forge, you are on your own.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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