No PhotonNetwork.isClient / PhotonNetwork.isServer?

Options
jashan
jashan ✭✭
I'm currently in the process of converting my authoritative server based project to Photon Unity Networking and am noticing that there's no such thing as PhotonNetwork.isClient and PhotonNetwork.isServer.

It seems those are replaced with PhotonNetwork.isMasterClient (more or less equals Network.isServer) and PhotonNetwork.isNonMasterClientInGame (more or less equals Network.isClient). That doesn't happen automatically, though.

So I guess the only way Photon knows that my authoritative server really is the server is because it connects first. But what would happen if the authoritative server crashes?

With an authoritative server (which is compiled with different code than the game clients and has all kinds of cheat prevention built in), the automatic "then someone else is the master client" would cause quite a mess. In particular, my authoritative server handles distributing many of the messages (comes from a time when Unity didn't support scoping - ironically, I'll re-use that old code now because PUN also doesn't support that, yet).

Comments

  • dreamora
    Options
    The server is always the photon server itself.

    what you are looking for is PhotonNetwork.isMasterClient which is the unity network server counterpart
    The second "is" you quote there is to my understanding no counter part to isClient but a boolean that tells you if the master is sitting in the room on its own.


    The automatic transfer of masterclient indeed can be a pretty annoying problem.
    My solution to that is actually a define that cuts whole codes depending on which build it is + a static boolean on the network manager class MasterClient which is being used to additionally verify it that it is the masterclient (if (MasterClient != PhotonNetwork.isMasterClient) ...)
  • jashan
    Options
    dreamora wrote:
    The automatic transfer of masterclient indeed can be a pretty annoying problem.

    Is that something that happens in the code of PUN, i.e. in the code we have the source for?

    I guess I'll have to rewrite significant parts of that anyways. Like, while my game is kind of room based (a "GameGroup" kind of equals a room), my game servers (the actual Unity game servers) can host multiple GameGroups. So if I use the rooms concept, I'd have to be able to connect the server to multiple rooms simultaneously so that they can serve multiple game groups.

    Ironically, it seems that from that perspective, PUN is even more limited than Unity networking: In Unity networking, I can at least connect multiple groups of unrelated clients to a single game server- but I can't connect clients to multiple game servers. In PUN, I can't even connect multiple groups of unrelated clients to a single game server ;-)

    Also, I need the possibility to SetSendingEnabled for individual NetworkPlayers aka PhotonPlayers and I guess that's something I need to implement inside the Photon server.

    The "a client become a master client if the game server disconnects" is something that I definitely need to remove (doesn't work at all when using an authoritative server).

    Also, forcing Application.runInBackground = true doesn't work for me because my clients also have a single player mode in which they are not connected - and in that case, they should not run in background (wouldn't make them particularly nice Web player citizens ;-) ).

    Well, as long as I can make all those changes, I'll be better off than in Unity's networking. And I'll be better off than having to write all of that from scratch. But it seems like that whole thing was designed with a specific use case of Unity's networking in mind - and while Unity's networking is already quite limiting, there's a lot more possible than may initially meet the eye ;-)

    Like, it starts right there in the section "Differences to Unity Networking":
    Unity networking is server-client based (NOT P2P!). Servers are run via a
    Unity client (so via one of the players)

    That is one possible scenario. But I never even considered using Unity networking that way. I have a dedicated server running to which players can connect. This also has implications on performance because from the network perspective, my Unity game server without Photon is directly connected to the clients - while with Photon, I have Photon in between (which will make latency worse).

    Obviously, I'm still seeing quite a few benefits with using Photon, otherwise I wouldn't jump through the hoops I'll have to jump through .. besides, it's just V1.1 (but that's a tricky thing given that once I've applied all my changes, I probably won't be able to update anymore).
  • dreamora
    Options
    You have the source for anything don't you.
    The Unity client is part of the Unity AS bundle, the backend code is present in the Photon 3 RC3 bundle where the whole loadbalancing exists as a Lite extension.

    I stopped using the provided server in the AS because its simply broken. Its impossible to get the policy server to work at all for the webplayer & editor, while RC3 just works.
  • jashan
    Options
    dreamora wrote:
    You have the source for anything don't you.

    Do we have the source code for the DLL that's part of PUN and the standard Unity / DotNet package? Maybe the source code for that is in the DotNet package and I just didn't have a close enough look ...
    dreamora wrote:
    The Unity client is part of the Unity AS bundle, the backend code is present in the Photon 3 RC3 bundle where the whole loadbalancing exists as a Lite extension.

    I had already found the "Loadbalancing" project and that's one part I'll certainly have to rewrite ... even though maybe it makes more sense to just keep that untouched (for easy upgrades) and port parts of my networking to "custom Photon code" (not based on Unity's networking / PUN) and have that handled by a separate Photon application of my own.

    The AS bundle has one DLL included ... not sure if I really need the source code for that, though (I had one issue where it would have helped ... maybe ... but reading the manual again sure was the quicker way to solve that issue ;-) ). I really just noticed that there was this DLL because in my first experiments, I had "connection refused" issues when connecting to rooms and that happened inside of that DLL and I wanted to find out what IP it was trying to connect to (it's the IP-address that PUN gets from the "Master" application which is part of the LoadBalancer package ... and I guess that Master application retrieves it from the configuration files of the two server apps in there).
    dreamora wrote:
    I stopped using the provided server in the AS because its simply broken. Its impossible to get the policy server to work at all for the webplayer & editor, while RC3 just works.

    Same here ... I did the very first experiments with the server package from the AS bundle, then got myself the RC3 Server SDK and am using that one now.
  • dreamora
    Options
    jashan wrote:
    dreamora wrote:
    You have the source for anything don't you.

    Do we have the source code for the DLL that's part of PUN and the standard Unity / DotNet package? Maybe the source code for that is in the DotNet package and I just didn't have a close enough look ...

    Would need to dig that out. In Photon 2 it was part of the photon unity distribution and forms the "general layer". Back then you really needed the code to it because the operation handling for example was only present there and not exposed to the code in unity.

    But Photon 3 has finally resolved this issue so adding new ops and op response handling / op event handling is finally possible straight in the code you have at hand so I'm unsure one really still needs it.


    I'm currently also using Unity Photon Networking adding server side only ops on an own load balanced based derivate which calls out to a library and tech present only there and accessable only to master clients and so far it seems to work though it was a hairy way to get the loadbalancing dublicate app to show up in photon control and get it to start that one (its still not possible to start it as app, will always fire up loadbalancing too?! Might write a short tut about how I went once all is there, unsure though as I'm not the tut writer per se)
  • jashan
    Options
    dreamora wrote:
    I'm currently also using Unity Photon Networking adding server side only ops on an own load balanced based derivate which calls out to a library and tech present only there and accessable only to master clients and so far it seems to work though it was a hairy way to get the loadbalancing dublicate app to show up in photon control and get it to start that one (its still not possible to start it as app, will always fire up loadbalancing too?! Might write a short tut about how I went once all is there, unsure though as I'm not the tut writer per se)

    Which part did you have trouble with? I think one part is described very well in the docs (how to edit PhotonServer.config) ... but what I didn't see in the docs was the fact that you'll also need to change PhotonControl.exe.config (the setting named "Instances"). I now have both PhotonControl.exe.config and PhotonServer.config in my solution and in subversion (to keep track of changes I apply there).
  • dreamora
    Options
    The part I had problems in the very end (before there were a few other steps that backfired) is that when I left LoadBalancing in + our own loadbalance clone with an additional custom op, which has a whole own namespace and folder, the loadbalancing was showing up as "running" when I started the experimentplatform. Our application got an own instance naturally to expose it as an own application in the control

    In the end no problem there cause I just removed the other two exposed applications in photoncontrol, as well as the loadbalancing instance cause we don't need more than ours and what LoadBalancing requires to exist like Lite.
    But it was a strange anomaly that puzzled me at first cause nothing should lead it that way.
  • jashan
    Options
    Ah, so it was a good decision to remove everything I didn't feel I needed right away ... that way, I didn't even run into that anomaly. Now I only hope that building on top of Loadbalancer was the right decision ... but I guess it was ;-)