PUN with server-side state

I guess I can do it by joining the pieces of the manual, but it could be great if there were a concise tutorial using PUN and an stateful server (any MMO or password-required game needs to store player's stats).

I thought of something simple, like a GUI.Button that sends a "click" to the server and this one counts the hits and stores the "Top 5 clickers" in server app's memory. I'll try to do that, but will be twice as hard, since I'm a Mac-only Indie and my DotNet skills are really (really) rusty... :D

Comments

  • PUN is a purely client side code construct which exists in Unity only.

    You can't create any kind of persistence or server side code when you work with the Photon Cloud.

    If you work with an own PhotonServer and the LoadBalancing instance (required for PUN), then you could do it, but if you are mac only you can not work with the Photonserver at all. If you could you would likely implement an additional operation to handle this
  • It seems my suggestion needs a little more clarification.

    Three things that I already knew before asking: PUN is client-only; I need my own Photon Server to store the state; and my MacBook will not run PS out-of-the-box.

    As I said, "I guess I can do it by joining the pieces of the manual". And that's what I'm doing in a really painful way. For the server part I thought it was really easy and obvious: using a VM. I'm playing with it using an Amazon EC2 instance. Now, I'm trying to choose the way I will suffer less: installing and running Visual Studio Express at Amazon or using MonoDevelop locally (uploading the binaries for each build).

    All Photon tutorials are so easy to follow that I read once and undestood everything, even without a running PS. This means I could focus on what matters: making my obnoxious environment work. I just don't understand why something so important as persistent state does not deserve its own tutorial. It's like see an parallel universe where Unity site does not have any tutorials on game controls (WASD/virtual joystick). And it could be as simple as a "click count competition" (i.e. does not need fancy graphics and models).
  • The easy way would be what you state 'using a VM'.
    That though out of my view explicitely excludes 'using a very badly performing webservice with no interest in consistent realtime experiences' aka AEC2. Its by far too expensive for the quality it offers unless the instance is primarily paused.

    For development and small testing I definitely would go with VMWare Fusion / Parallels running Windows on your own box.

    As for why there is no tutorial on persistant state: Thats likely cause Photon has no support for persistence or db in any way, as such there is nothing to cover for tutorials.

    On top of this there are other reasons: Adding a tutorial on a beginner topic if you need to be an intermediate to advanced developer to stand a chance changing the photon side server logic in a reliable way seems at least to me counterproductive. It makes more sense that tutorials cover the side where the majority of tutorial consumers are in and thats the client side. With the cloud more than ever before.

    But to answer your question with some pointers to get you going:
    As you use PUN and LoadBalancing, you can not have a global persistence in memory at least not without a major effort, as the different game servers on which the players and rooms actually reside are distinct universes. You would need a db or shared memory architecture here or toy with the server2server communication assuming it can be used for game server to game server communication.
    If you only want the counter to be game specific then its far easier. What you need to do is
    • add the desired operation to the game server application
    • add a function to the room thats being called by the op for the increment
    • add the counter variable to the room
    • add a corresponding entry on the enum for the packet id.
    • add the same entry on the client side

    That would be the way to go here unless I missed something.

    This or you would use room properties which are 'room lifetime persistent'

    The Unity side does not need a WASD tutorial as importing the character controller removes any need for it. You can check the FPS script and are done :)
  • m4c9: It's cool to read that you are OK with our tutorials and the help you got so far. That's great to read, every now and then.

    > "I just don't understand why something so important as persistent state does not deserve its own tutorial."

    Like dreamora said, the reason is simply: We don't want to take care of this and we don't want to support persistency. There are so many abstraction layers and more than one company and product tries to solve this task. The requirements go from "i only need a text file" to "i need a cluster of highly-synchronous DB servers" and we can hardly cover all with any solution we pick.

    However, I understand that we should have some more general guide. Maybe like: How and where to insert your persistency logic?!
    We don't have a guide for this but then it's not impossible to come up with a solution: Identify the triggers when you need to save something and when you require the data. Then save and load anything in ways that are non-blocking. Make the clients cope with situations where info takes a while to be fetched (non blocking) and pick a DB solution that you like and that fits your budget and coding style.