Storing data on the server

edited August 2011 in Photon Server
I'm slowly getting my head around Photon and the sample applications. Some of the C# concepts are a little beyond me at the moment, but I'm finding things as I go.

I've done the first part of the blank server tutorial and everything worked well. I've added bits of the second part to simplify operation codes. (Side note, the code on the web does not match the code on the video, and it seems like it uses ReSharper which assumes every else does too)

I'm now at my next point - shared items (ie characters, items, inventory) on the server itself. I'm asking this question independent of what the client will do with the data, to simplify the concept.

My first assumption was that the MyPeer class is unique for every login - is that correct? If I add a value to the class, is it then stored for the entire user's logged in session? For example if I add username, will this be constant based on the peer who sent the request?

Second, If I wanted to have 100 items in memory on the server, with their stats (eg colour and weight), what is the best way to store them and where should they be stored, and when should they be initialized? I know they need to be stored outside of the MyPeer objects so they can all access them, but there seems to be major issues with making them serializable and in objects or classes not structs and so on. I want to be able to have the client request details about an item and then the server send it to them (so the clients are dumb and build the data on the fly).

The extension to this is if I want to store 10,000,000 items (let's say the game is really successful, 100,000 users with 100 items each) I don't want to have to reimplement what I am doing.

For me, the jump from the blank server setup to Lite and then Lite Lobby is huge, I just can't get my head around all of the things introduced. I am not worried about lobbies and rooms, every player is going to be in the same 'world' (there is no world).



  • MyPeer will get initialized as soon as a connection is etablished - so yes, its unique to the connection.
    From this point on, photon leaves the stuff going on to the developer - if you would like to store the items I'd go and store them in the database
    and request datasets as soon as they are required. If you have 10,000,000 items it wouldn't work to have everything in the ram directly.

    Assuming you have the player which has 100 items in his inventory you would load them when he's logging in, that's would I would go with. During the game session
    you should update them if necessary, e.g. player deletes itemID 5234 this item should be removed from the dataset of the player and also you need
    to send an immediate response to the client to remove the item from its inventory.

    I'd suggest you to setup a basic layout first, what should the client do, what the server has to do. Next step would be to have a loginsystem and character
    creation/deletion & selection running, then move on to the enter world.

    Checkout the tutorial Section here: viewtopic.php?f=18&t=612


  • Thanks Seb.

    I have already implemented user and item storage, creation, deletion and swapping in a SOAP based server and client relationship in Delphi, so have tested the basic system and finished the design (as such). However SOAP was just going to end up too slow under load, so I have moved to Photon. I know C# enough to make a start, but probably not enough to understand some of the advanced concepts that are going on with overrides in Photon, and I think thats where it's hurting.

    I think the key thing I am asking is not the 'how to design it' (I get the database stuff, etc), it's 'where to implement it' and 'what class to use'.

    Based on your answer, I think this is what I will do:

    Create a class called User
    Create a class called Item
    Put an array of Item in User
    Put a User in MyPeer

    Then any Operation request made by a MyPeer will automatically know about it's own user and item details.

    Have I got that correct?

    Thanks, for the tutorial link too, I had already been going through the ones here and on those links over and over.

  • Hey Darren,

    exactly you got it, you create a class for User & Item which should be as modular as necessary according to what it should do.
    You can also change the OperationHandler, lets say you start with MyPeer which handles all requests before the login. You'd then be able to set your User class as the OperationHandler and it will take care of all other requests beeing send to the Server.

    dragagon is using this in his tutorial here:

    You'll need to implement the IOperationHandler interface and assign the operationDispatcher to the class and all responses will get directed to this class.

    I for example use the MyPeer for everything before the login, then I change to Account for everything after the login and once the world is entered the Character class will be the OperationHandler.