Jump to content

Simple Explanation of SMP client-server communication wanted


Sinhika
 Share

Recommended Posts

Okay, I get that there are tutorials on how to set up packet handlers.  What I am having trouble wrapping my head around is what information does a mod need to send from client to server and vice versa? Versus what is auto-magically handled by Forge & Vanilla MC parent classes. My brain is failing to make a crucial connection somewhere for this all to make sense.

 

How do you know what you need to set up packet handlers for?

Where does that information come from and when?

Is it related to events? Which events? For what? When?

 

I'm really lost when it comes to figuring out what needs to be done to make sure a mod works in both SSP and SMP modes. Simple explanations and links to open-source/github/etc code that does what you are talking about would be appreciated.

Link to comment
Share on other sites

First advice: Don't think of SSP and SMP as two different things. They are exactly the same. A server & a client.

If you mod, always have a dedicated server in mind, then your mod will most likely also work on the integrated server (SSP).

 

The server holds all the data. It knows where blocks are in the world, it knows the contents of inventories, etc.

Also it simulates the world, makes entities move, updates TileEntities, handles redstone updates, etc. etc.

To get that information to the client, packets are needed in which the server tells the client what is currently happening.

Those are server to client packets.

 

Then there are client to server packets. These are for things like player movement. The server needs to know where the player looks, walks to etc. That information is only known by the client, because the client handles Keyboard and Mouse input (how could the server handle that? It might be at the other end of the world). So the client sends packets to the server, telling it the information it needs. But these packets should never be trusted for security reasons. Always assume a client might be hacked and send false information. For example if you want a GuiButton to trigger a block placement, you will need to send a Client => Server packet because the server doesn't know about GuiButtons (it doesn't know the mouse). But then don't send a packet telling the server to place a block, but send a packet to tell the server that a button has been pressed, then the server decides what to do with that information. Otherwise that packet may be used by malicious clients to mass-spam blocks.

 

I hope that made any sense, if you have more questions, just ask.

Link to comment
Share on other sites

So... if I just create new tools, blocks, items and recipes for the standard crafting table or forge, is the client-server communication handled already at the level of the parent classes? i.e., do I need a custom packet handler for placing blocks derived from class Block?

 

I'm sort of getting the idea that packet handlers might only be needed for new GUIs, such as new crafting interfaces and new inventory containers, and for things that move, like vehicles, riding animals, etc. Is that correct?

 

...I probably should look at the packet handler tutorials in more detail.

Link to comment
Share on other sites

So... if I just create new tools, blocks, items and recipes for the standard crafting table or forge, is the client-server communication handled already at the level of the parent classes? i.e., do I need a custom packet handler for placing blocks derived from class Block?

No you don't. The basic interactions are automatically handled.

I'm sort of getting the idea that packet handlers might only be needed for new GUIs, such as new crafting interfaces and new inventory containers, and for things that move, like vehicles, riding animals, etc. Is that correct?

Not even then, at least not all the time. Opening a simple chest-like GUI can be done without new packets, and also syncing basic data (furnace progressbar).
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
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.

 Share



×
×
  • Create New...

Important Information

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