Is it possible to have a game server host in a room, that controls everything in the game?

Options
Sorry if the question was unclear, but I'm wondering if it's possible to have server run code that determines things in a game (like scores, respawning etc.) instead of having a master client. To my current understanding, you have to have a master client that runs the logic code once and tells everyone else in the room what to do (through RPCs). I was wondering if this can be accomplished server side, and how to go about doing that. For reference, I'm building in webGL so using Photon Bolt is not an option.

Answers

  • Hi @dsprui11,

    when using the public Photon Cloud you can not run server-side custom code, unless you have an Enterprise plan / subscription. In this case you can use Plugins to inject custom code to the server's application. Those Plugins can be used, too, if you are hosting the server(s) on your own instead of using the Photon Cloud.

    When using the public Photon Cloud you would have to 'use' the MasterClient to have something similar to server-side logic.
  • dsprui11
    Options
    Thanks for the answer @Christian_Simon . My startup is considering upgrading to Enterprise, and I've read up on the plugins page, thank you for the link. I still don't entirely understand where the code is run. Ex: if theres a game with 10 players in a room, is it still the master client that has to control things like spawning power ups/etc. or is it possible to have a separate entity on the server side control things like that. Could you point me to any examples of this?
  • I think this depends on what you are doing. Spawning power ups for example can be done either by the MasterClient or by the Plugin. In both cases you would have to send a certain event which tells everybody that a certain client has picked up a power up (or at least they the clients have to disable a certain object). If you are using the MasterClient to control the game, he would have to start a countdown for that power up describing the moment to respawn it. After this countdown he would have to send an event which tells each client to respawn the object. If you want to do this on server-side, you would have to use the OnRaiseEvent hook. Here you would have to start a timer which sends the respawning event after a certain amount of time to tell all clients later, that they have to respawn a certain power up.

    Please note, that you don't have an Unity instance running on the server, so dealing when you deal with objects, you have to identify them uniquely.
  • dsprui11
    Options
    Thanks! I think in my case it's probably best to implement it through master client. Will definitely look into an enterprise plan when we grow to that point :smiley: