Jump to content

[1.11.2] [SOLVED] Changing variables Server-side only


Bektor

Recommended Posts

Hi,

 

if it is possible using Forge to change values server side only, for example to allow a server owner to change how much energy a machine produces or consumes

without the need of a update of the mod itself on the client side.

 

Basically the server owner should be able to change specific values and the client uses the values from the server instead of it's own values.

 

My problem there is:

  1. I don't know if this is possible with the current available systems in Forge/Minecraft.
  2. I don't know how to do it, except for that at some point the server has to send all the data to the client.

 

Thx in advance.

Bektor

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

8 minutes ago, OreCruncher said:

Uh, this isn't related to writing mods.  I suggest you read the documentation for the various mods you use in your pack.  A lot of them provide configuration settings to do specifically what you want, or provide integration with systems such as Minetweaker/Crafttweaker.

This is related to writing mods as I want my mod to have this feature, as I want for balancing and thus stuff my mod to sync data between the server and the client so that when I have for example a config file or a json file or whatever file I might want to use, I can change on the server just this file and everyone will be able to play with the new balanced variables instead of the old ones and the old ones are only used on the client when the client is not conntected to my server.

Developer of Primeval Forest.

Link to comment
Share on other sites

15 minutes ago, OreCruncher said:

Then your mod would have to send packets to clients when a player logs in.  Up to your mod to do that, assuming the client really needs your updated server side values.

And here we've got a few problems:

  • How to send the data to the client in a way the performance doesn't drop when it's a lot of data?
  • How should the client or the server know if the data is different?
  • How should I stop the client from using the data that already comes with the mod instead of using the new server data?
  • Where to save the data on the client side? I mean the data is server specific like a resource pack can be server specific.

Developer of Primeval Forest.

Link to comment
Share on other sites

On 8/11/2017 at 5:54 PM, Bektor said:

How to send the data to the client in a way the performance doesn't drop when it's a lot of data?

How much data do you plan on sending? I doubt the amount of data you'll need to send will show any drop in performance, especially since you'll only be sending the config packet once, on join.

On 8/11/2017 at 5:54 PM, Bektor said:

How should the client or the server know if the data is different?

The easiest way to fix this would be to just always send the configuration packet... In fact, that's probably the best way to do it. The only way to know if the values were different would be to send all the values either from client->server or from server->client, so you may as well just send them from server->client anyway...

 

On 8/11/2017 at 5:54 PM, Bektor said:

How should I stop the client from using the data that already comes with the mod instead of using the new server data?

Abstract away the config into an object or into static fields. When the client joins the server, the server should send the configuration values, and the client should set all the fields to the received values.

On 8/11/2017 at 5:54 PM, Bektor said:

Where to save the data on the client side? I mean the data is server specific like a resource pack can be server specific.

Don't save it. Unless you're storing large amounts of data, caching will likely be more trouble than it's worth..

 

--------------------------------

 

How much data do you plan on sending? If it really is just a config file of integer settings for machines, it shouldn't be too much...

  • Like 1

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

Link to comment
Share on other sites

7 hours ago, Socratic_Phoenix said:

Don't save it. Unless you're storing large amounts of data, caching will likely be more trouble than it's worth..

 

Why would caching be more trouble than it's worth?

 

7 hours ago, Socratic_Phoenix said:

How much data do you plan on sending?

Well, currently I plan just on sending a few hundred values to the client. This values might either be of integer type of boolean or long.

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

1 minute ago, Bektor said:

Well, currently I plan just on sending a few hundred values to the client. This values might either be of integer type of boolean or long.

Well, assuming the worst case, that they're all longs, you'd have about 300*8 bytes, or 3.2 kilobytes. I wouldn't consider that a lot of data, especially since you'd only be sending it on login. Furthermore, 3.2 kilobytes is worst case - I don't know how many longs vs. ints and booleans you plan on sending, it could easily cut my estimate in half, or more. Also note that Forge tests network transmissions of 2 MB, which is quite a lot larger than your packet.

 

You could also compress the data...

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

Link to comment
Share on other sites

9 minutes ago, Bektor said:

Well, currently I plan just on sending a few hundred values to the client. This values might either be of integer type of boolean or long.

First off, do you have a class that loads, saves, and stores all your config data? If not I would highly recommend you have one, it would  be the place to store all your variables.

Since you want to send data, try to create a PacketConfig class that handles sending data from Server->Client. In the packet, just define the variables inside of the packet that you want the server to be able to edit and send to the client side of things, e.g. MachineEnergyPerTick or MachineProgressSpeed.

Then, just send the packet to the client, have them read the packet and change the values specified in the Config class to match. It wouldn't change the config file and would sync up the server to client.

Edited by mysticalherobine
Link to comment
Share on other sites

Sounds like you're already close to a solution, but I found SimpleNetworkWrapper nice to use.

 

create a SimpleNetworkWrapper, something like:

SimpleNetworkWrapper simpleNetworkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("myChannel");

 

You will need to use that to register a message class, I did this in postinit like:

simpleNetworkWrapper.registerMessage(MyMessageHandler.class, MyMessage.class, 0, Side.CLIENT);

 

Declarations such as: 

MyMessage implements IMessage

MyMessageHandler implements IMessageHandler<MyMessage, IMessage>

 

For an example see the comment =~ line 62 of net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.java

 

Finally you send the message from the server like this:
 

simpleNetworkWrapper.sendToDimension(new MyMessage(myConfigurationSettings), 0);

 

Which will fire the MyMessageHandler.onMessage on any client attached to that server that is in the Overworld (That's the 0). You would have to repeat this for the Nether (-1) and The End (1) if that was important.

 

IMessage defines a dead simple ByteBuf serialization pattern which is where you'd convert your settings to something transportable.

toBytes(ByteBuf buf)

fromBytes(ByteBuf buf)

 

0d

 

  • Like 1
Link to comment
Share on other sites

6 hours ago, DougLazy said:

Finally you send the message from the server like this:

You can also invoke sendTo with an IMessage & Player, to send to a specific player when they log in.

Developer of Randores (adds 256^3 ores to the game) and Arcane Bags (adds ridiculous storage with ridiculous crafting recipes).

I know Java pretty well... So yeah...

Quote

This is where I'd put an inspirational and/or clever quote, but I can't think of one right now...

This is the output of the totally, 100% working compiler for my programming language, Planet9:

Beginning Compilation...
Failed compilation!
planet9.compiler.error.CompilationException: Compiler not yet implemented
	at planet9.compiler.Compiler.compile(Compiler.java:39)
	at planet9.compiler.app.CompilerApp.main(CompilerApp.java:147)

 

Link to comment
Share on other sites

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.