Jump to content

  • Log In with Google      Sign In   
  • Create Account

Server-side inventory system, what to send over the network?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 DoubleDouble   Members   -  Reputation: 107

Like
0Likes
Like

Posted 12 September 2012 - 07:24 PM

I've looked on Google quite a bit, trying to search multiplayer inventories and such, but I'm mostly getting results related to databases or minecraft. So while I am asking here, in addition to answering my questions, I will happily look at any links you may find useful to my situation. I am programming in c#, but I can at least understand code in whatever you guys throw at me.

I'm working on a multi-player rpg that has an inventory system similar to Diablo's in that the player has many "slots" they can store items in, and some items take up more than one slot.

Currently, my intention is to set it up like so:

Inventory: 20 x 20 (400) slots

Server: int array[400] playerInventory. //Stores item id's
Sends the array to the client

Client:
receives array of itemIDs,
sends any player input, //clicked an item? //moving an item?

so, my Questions:
In case it is relevant, I am using C# with XNA, Lidgrens

1) What should I use as the array? ints are much larger than something else I could use, yes?

2) How often should I send such a large amount of info? 400 itemIDs seem like a bad amount to send. I was thinking of having a game state monitor, which would let the server know when the player is looking at his inventory screen and only then send all the itemID's, I dislike that solution because I feel there are better ways. Help?

3) How should I send the player input? If a player clicked the item in slot 123 (to pick it up / hold it with mouse) should I send: playerID, actionType, itemSlot. Are there any bugs that I need to be aware of if I do it this way? (latency bugs, possible item dupes?)

In conclusion, I want the inventory server-side so it eliminates hacks related to items and inventorys, but I am aware of networking limitations (aware they exist, not what they are) as far as sending and receiving data. My current solution seems like it would send/receive too much, and I am trying to optimize that interaction between client and server. Any help is appreciated.

Sponsor:

#2 hplus0603   Moderators   -  Reputation: 5309

Like
2Likes
Like

Posted 12 September 2012 - 09:55 PM

I would store each item in inventory, together with the position of the top/left coordinate of the item. This only needs 10 bits per item (5 bits for X, 5 bits for Y.) The size of the item should already be known by the client based on the item type.
I would send the full inventory on connect, and only send delta updates when the inventory changes, to minimize traffic.

Edited by hplus0603, 12 September 2012 - 09:55 PM.

enum Bool { True, False, FileNotFound };

#3 DoubleDouble   Members   -  Reputation: 107

Like
0Likes
Like

Posted 14 September 2012 - 01:57 AM

I have it working currently by the client sending 9 bits on each update, 1 whether he clicked or not and a byte for a position
(I decided since I am coming up with an arbitrary number of inventory slots it might as well be 255 slots instead)

The server then does what needs to be done with that position and any item the player is holding.
Currently, it then sends back the entire inventory array. (255 * 1 byte)

You are saying I could send back (1byte position, 1byte itemID) instead... that would be quite good Posted Image
I may bring it back to 400 slots if its only two more bits, I'm starting to better understand how to get the most out of each bit.
As an afterthought, I can also save the bit on whether the player has clicked and just send the item position when the player clicks couldn't I?

Thanks for the response, the help is much appreciated and every little "bit" helps. Posted Image

#4 zfvesoljc   Members   -  Reputation: 440

Like
0Likes
Like

Posted 21 September 2012 - 12:54 AM

Wouldn't it be better to send player requests instead of "clicks"? ie: if user clicks an item, you pick it up locally, drag it around and drop it in slot. You then send a message to the server: user X, move item from XY to ZW; at this point it would be wise to lock the moved item and both slots until server responds. As for packing info, if you don't have multiple avatars in your party, you do not need to send "who" as server knows from which client he got message and for coordinates I'd rather send just index with the required number of bits (400 -> 9bits (512)) , so you just need two index values (from - to). Server then responds only with a confirmation and the client unlocks item and slots. If the server doesn't respond in timely fashion, you revert the whole action (move item back, unlock everything).
This is safe, but induces lag when user is doing stuff in inventory.

#5 Rasterman   Members   -  Reputation: 206

Like
0Likes
Like

Posted 21 September 2012 - 04:32 AM

Assuming your game logic doesn't depend on where the item is in inventory, why even manage the positions of items in inventory on the server? Simply let the user do what they want, and after a user adds inventory, the server calculates how many inventory slots the user has and is using, if they are using more then they have then you need to do an inventory audit of the user.

#6 hplus0603   Moderators   -  Reputation: 5309

Like
0Likes
Like

Posted 21 September 2012 - 10:23 AM

why even manage the positions of items in inventory on the server?


Because the next time the player logs on, it may not be from the same machine, or it may be from a restored backup, or similar. Server-side state for non-local things is one of the benefits of online games! (A draw-back is that you can't play if the intertubes are clogged...)

enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS