Procedure for implementing server side logic?

Options
Ford
edited November 2011 in Photon Server
I've been at this on and off for weeks but still cannot figure out exactly how server side logic is supposed to be implemented (specifically in the load balancing server for Unity).

Specifically I was wondering about the following things
-Where should room specific variables such as information about a room's teams, the score of the teams, and the score of the individual players be declared?
-Where should iterative logic be implemented like the ticks of a round timer?
-How exactly does the client set and access all this stuff?

I've looked at the server code enough to realize a lot of this stuff should be implemented through events and operations but all my attempts to do so have ended in failure.

Comments

  • I *think* you can mostly ignore the loadbalancing stuff and just implement your game logic like you would otherwise (with LitePeer.OpCustom, for example). Here's my best understanding of how the loadbalancing works:

    When a game server starts up, it registers with the master server and starts sending periodic server load status events to it. The game server also starts a periodic latency check against a latency server (which happens to be itself at the moment).

    When a client wants to play, it tells the master server that it wants to create or join a game. The master server consults its list of game servers and tells the client which game server to use.

    The client then tells the specified game server (the one the master server returned) that it wants to create or join a game. The game server creates the game and tells the master server about it with an event. As the game state is updated in ways that the master server cares about, the game server sends more game update events to the master server.

    Once your client is connected to the game server, it seems like you don't need to worry about the master server anymore. But I'm still learning this too, so I might be wrong.
  • Thanks for your reply but how to implement the game logic is exactly what I don't understand.

    Say for example I want to implement a simple match timer that counts down from 6 minutes. Every second it should send an event to every client with the current time remaining- when it reaches zero it should send an event to every client saying that the match has ended.

    -Where do I declare the variable for the remaining time? Can I just declare it in LiteGame.cs as a member of the class? If so, does that have to be mirrored somehow in the client implementation of Room? Or does it have to be declared in the Room's properties hashtable? If so, where and how do I do that?

    -Once I get that declared, how/where can I decrement the time at specified intervals?

    -After that, how do I send the events to the client? There must be a dozen or more event, message, and operation related functions available from LiteGame.cs- I have no idea which to use.

    -Where do I implement event handlers on the client? I noticed that there's an OnEvent function in NetworkingPeer.cs- are you supposed to just add cases to the giant switch statement there?

    How can you give players globally accessible data such as a kill count? I've seen a lot of stuff in the code involving a properties hashtable implemented on PhotonPlayer and I've tried setting the properties using PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor but after that I can't find a working method of actually accessing the properties. When I try to access a photonplayer's custom properties hashtable it's always empty. I can't seem to find an example of this stuff being used anywhere. :/
  • Oh, I see. Well, like I said I'm still new at this and I should probably let someone with more experience help you so I don't put you on the wrong track.
  • This is pretty essential stuff right?
  • tutibueno
    Options
    I also would like to know how to use PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor to see player scores, name, level, etc and PhotonNetwork.room.properties in order to load current room unity loaded level, game modes, etc.