Networking problem...

Hey all again, I'm in the process of working on my RPG (more info soon enough) and I was wondering if somebody could walk me through the steps of implementing an inventory system. Here's how I'm thinking of it and I just want to know how on/off I am with it.

So the server processes input and sends it to the client, then back to the server? In the case of the inventory, it doesn't need to go back to the server? Because we only want to open the inventory on the client's side when he/she presses the key?
How does it work then with drawing the inventory when the key is pressed? The object gets created after by the player which is created by the server (see LAN Platformer).

I'm putting '?' marks at the end of each piece because I want to know if that piece is correct.

If this needs clarification, please ask.
Thanks.
 

Mr Magnus

Viking King
Your client, when so required, asks the server what is in the player's inventory. The server helpfully responds with a list of things that are in said inventory. The client then handles actually putting that information on screen. If the player changes something in their inventory the client sends that information to the server which updates the database / inventory struct / relevant datastore.


The server doesn't have to do anything but provide a list of items ID's. It doesn't care about objects, or sprites, or anything the user sees. That's the client's job. The server code is just there to store, validate, and distribute information.
 
ahh, I see. But how doe the server keep track of which inventory is attached to each player? And the key for the inventory still has to be processed through the server, right?
 

Mr Magnus

Viking King
how doe the server keep track of which inventory is attached to each player?
That's for you, as the developer, to decide. Deciding how your server keeps track of the players and their information is part of the job of designing a server. You could use structs, ds_maps, arrays, files, objects for each player, you pick.
 

Mert

Member
Hey all again, I'm in the process of working on my RPG (more info soon enough) and I was wondering if somebody could walk me through the steps of implementing an inventory system. Here's how I'm thinking of it and I just want to know how on/off I am with it.

So the server processes input and sends it to the client, then back to the server? In the case of the inventory, it doesn't need to go back to the server? Because we only want to open the inventory on the client's side when he/she presses the key?
How does it work then with drawing the inventory when the key is pressed? The object gets created after by the player which is created by the server (see LAN Platformer).

I'm putting '?' marks at the end of each piece because I want to know if that piece is correct.

If this needs clarification, please ask.
Thanks.
The best option is to verify this on server. For example: (Let's say the user has a potion in the first slot in his inventory)
Send a data package to server indicating that the user has clicked the first slot in his inventory. Server is recording everything in the users' inventory. Now server gets this message and checks what the player has in his first slot. In our case, it's a potion. Server then begins healing the player and sends a message back to client indicating that the player is healing now.
 
Well right now I'm focusing one piece at a time. I don't have items yet. I'm just trying to get the inventory to process first.
 
In other words that doesn't answer my question. I built mine around the LAN Platformer demo, so most of it works that way. The first problem was with showing the inventory. It would only show on the server when I pressed the enter key, then I put the enter key in with the other keys in ServerReceivedData function (with all the others). Now regardless of whether I press enter with the client or server, it shows on the server. Please help.

I feel that I should also mention that I'm a veteran with GM. Been using it since 7.0 and my username was always +1 ahead of the version until studio came out. I just don't understand GM networking very well at all. Perhaps somebody could provide a link with a network inventory? I searched, but I couldn't find anything which is why I'm asking here.
 
In other words that doesn't answer my question. I built mine around the LAN Platformer demo
Be aware that this is a VERY basic demo. This doesn't have a proper server like what you want to do, as every "game" control it's own state.
Basically it works like this (you can imagine why this is no good in most cases):



You will need to look up and make an authoritative client-server architecture if you want your game to be minimally secure. This is how most game work nowadays.
It would look more like this:
 
So rough translation: It's not even a start? Ugh. And are you saying that the server should be run along size the game instead of within it? Where should I start with all of this?
Also, for now I only want to use LAN connections. Down the road maybe, I'll see about adding heavier stuff. Right now I'm mainly focused on the minimum viable product. A simple inventory system, with a simple server and simple game mechanics. I can always build on it later.
 
Last edited:

FrostyCat

Member
You should start by understanding the relationship between multiplayer games and correspondence chess.
One thing that I now demand of all networking novices is an understanding of procedures in correspondence chess, even if they don't all play chess. That's the closest physical analogue of how actual multiplayer games work, and it stops dead most rookie myths about multiplayer games.
  • The connection is not a shared board between the players on a table, it's just the mailman in a correspondence game.
  • Nothing happens on your board until you act upon mail sent out by your opponent.
  • Nothing happens on your opponent's board until you send him/her mail stating what your move is.
  • For the same reason you can't use chess notation in backgammon, bridge or StarCraft, you have to tailor the form and notation to the game.
For you specifically, I'll add two additional points:
  • For the same reason a correspondence form doesn't have room for what your opponent is eating while thinking of a response, you do not communicate undecided or non-affirmative actions.
  • For the same reason a correspondence form doesn't have room for what material your chess set is made of, you do not communicate purely decorative elements.
Then instead of asking around for tutorials for every little thing (which you will never get), you think about what needs to be said and what doesn't, and who would say what to who. Example:
  • The server has the authoritative list of items for all clients (e.g. A, B, C).
  • Ahead of time, the server tells client A what it holds, client B what it holds, and client C what it holds.
  • Each client then keeps a non-authoritative list of what they hold respectively, for visual purposes.
  • Client A opens the inventory screen looking for an item to use, based on its non-authoritative list. Nothing gets sent here as this is an undecided action.
  • Client A selects item X. It closes the screen, and tells the server that it intends to use item X.
  • The server receives the request and verifies that A holds item X, and removes it from A's authoritative list.
  • The server tells all clients that A has used item X.
  • All receiving clients then perform the action associated with using item X. For client A in particular, it also removes item X from its local non-authoritative list.
 
Hello !

In my own experience you should first make a huge plan on paper for your game architecture :

-how many players to together ?
-how are they connected ?
-what does the server needs to check / store ?
-how does the server store (and then check) ?
-what are function you need ? (chat, save, groups, trading etc..)
-is it open-world or not ? (mean are players in small groups or large packs ?)
-coordinate system
etc ...

Once you have a list of what you may need (because during the development it may evolve ...)
think of how you can make it but as a hole.
You shouldn't make a piece and then add another piece on that, then another one all independently like this.
It will be extremely heavy and bad functioning in the long run.

For online game like this, you will have a big flow of many different kind of data coming make sure that both server and clients use a clear and flexible protocol
between each-other too.

My advise is a bit general but I can tell organization is often a central problem ...

otherwise @Mr Magnus gave a nice idea function itself, yet in my opinion depending on what I've said above : organization !

Good luck !
 
Thank you all for your suggestions. I think with all of the advice here, I will be able to get a start. I will report progress as soon as I have progress to show. In the meantime, have a like, all of you!
 
So rough translation: It's not even a start? Ugh. And are you saying that the server should be run along size the game instead of within it? Where should I start with all of this?
Rough answer: Nope, not really a good start, unfortunately.
And yes, you should code another "game" (which we will now call a SERVER) that will be ran alongside the other "games" the users actually have (we'll call them CLIENTS).
The server should run 24/7, minus the maintenance downtimes. It is God and knows/has access to everything about the game. It doesn't even need to render stuff, tho.
The client is what regular people will download and play. They only render and "know" only what is necessary for the players to play their game.
If client and server should disagree on something, server should win.

And about the "where should you start" part, I'd say that if you only know GML, this is going to be tougher than doing it in, say, Python...But only you can know how serious you are about making this thing happen and what skills you're lacking to get it done.
 
Luckily, over the approx. 15 years I have been behind a computer (since age 12), I have picked up on various languages. I hate Python though. If I were to go down that route (and I'm somewhat against it at the moment), I would use the "raw" functions, correct?

Like I said, for now I just want to do a simple LAN server so me and my brother can connect, but maybe more advanced stuff down the road. With that being said, is all this dedicated server stuff required still?
 

Mr Magnus

Viking King
Frankly, if you're just making something small for yourself doing a dedicated server in a different language is overkill. Good practice, sure, but overkill. Having a "server" inside your game written in GML is plenty enough to get you started with learning how server/client interaction works.

My only recommendation here is to try to keep the code running the server as distinct from the code running the game as possible. Pretending the server can't access the game is good practice. Beyond that I'd recommend you just try. Start small, make pong. See what works. Once you've made pong, try something bigger. Try online Bomberman. Once you have bomberman running go a step bigger. This is best taught just trying it out and hitting walls. When you hit a specific issue you can't mess about with until it goes away ask here, and keep going. Don't start on a full sprint, a clumsy crawl is perfectly fine as a starting point
 
Beyond that I'd recommend you just try. Start small, make pong. See what works. Once you've made pong, try something bigger. Try online Bomberman. Once you have bomberman running go a step bigger.
Agreed on the principle, but the thing is these don't really need to access stuff from a DB, it can be done in the same fashion the OP currently uses.
If you want to save an inventory, player stats, store usernames and passwords, etc. it will require something more solid.

Like I said, for now I just want to do a simple LAN server so me and my brother can connect, but maybe more advanced stuff down the road. With that being said, is all this dedicated server stuff required still?
I said Python because it's the most used language, but you can do it in any language. Go with C-family, if you want to, that's not a problem.
Python has good libraries, tho, but just go with whatever.
The part of your quote I highlighted is one of the reason you should try to make this as solid as possible from the get-go. Better yet: make a plan and stick to it. ;)
 

Mr Magnus

Viking King
it will require something more solid.
It can be achieved with a single object with a "player" struct that is retrieved and saved to a json file on disc. Storing data for simple games doesn't always need a very fancy fullstack solution.

While I highly encourage learning proper backend web development given the discussion happening in this thread I think we need to scale back a bit what we should be recommending.
 
While I highly encourage learning proper backend web development given the discussion happening in this thread I think we need to scale back a bit what we should be recommending.
There's truth in this for sure. Here's how I see it: if there's a definitive plan, and no expectation for scalability and security (i.e. playing with friends/family), I agree saving on disc can be an effective and simple solution. Cheap too, which is good.
On the other hand, the OP made it clear he's not a total n00b, has some relevant CS knowledge, and the endgame would ultimately be to have a user DB that needs to be secured (storing emails, passwords, IAP, etc.), then I would just recommend getting 100% into networking for a couple weeks, read and soak-in all he can, and then try to move in the bigger leagues, if I may say.

I know it can be intimidating, I shied away from networking for decades, but now I know from experience there's no voodoo in it, it's just a new thing to learn and understand.
Only he knows his ambitions and goals, and, considering that, that's how he should choose the amount of time researching this. I wouldn't spend 100+hrs in books and stuff for something I wouldn't really use often and is only of mild interest to me, for sure! In these cases, I have no shame taking the shortcuts!!
 
Hello aagin, so I took a short break to gather my thoughts on this inventory thing and here's where I'm at: I thought I was onto something, but perhaps not. I started by testing the Draw GUI event in the client object. Only showed on the server game's screen. Then I tried on the server (not really expecting much), still to no avail. Now I'm trying to render it the same place as the sprites are being drawn (the client draw event under the for loop where it adds "allsprites" to the list). Am I at least on the right track? Probably not, right? Because in there it draws all sprites to the screen (for both players), is the way I understand it. If I were to add this to the LAN Platformer demo, which object would draw the inventory? That's all I need to know for now (I think).

I'll keep trying in the meantime.
 
Top