Search Unity

Third Party Photon Unity Networking

Discussion in 'Multiplayer' started by tobiass, Aug 23, 2011.

  1. Megagamefan100

    Megagamefan100

    Joined:
    Oct 24, 2012
    Posts:
    26
    How do I spawn a map in a room, if I have room that says it's map is forest I wan't it to spawn the map forest or if the map is city spawn that one or load level of that map I don't know how to do it
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Are those different scenes? Then set PhotonNetwork.automaticallySyncScene = true when you connect (or when the game starts. Anytime before you join a room).
    Then use PhotonNetwork.LoadLevel on the Master Client. This is the first player in a room (or the 2nd if the first is gone, etc). The check for PhotonNetwork.isMasterClient should only be true on one client.
     
  3. Megagamefan100

    Megagamefan100

    Joined:
    Oct 24, 2012
    Posts:
    26
    so what do I put that in?
     
  4. Megagamefan100

    Megagamefan100

    Joined:
    Oct 24, 2012
    Posts:
    26
    error CS0117: `PhotonNetwork' does not contain a definition for `automaticallySyncScene'
     
  5. Megagamefan100

    Megagamefan100

    Joined:
    Oct 24, 2012
    Posts:
    26
    If someone makes a room it adds it to the list in the lobby and say they selected the room and it's map was the forest or a city or just cubes, what I wan't it to do is load or spawn that scene or map for anyone who joins that room including the person that made it but I just don't know how to do it.
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    If you get "PhotonNetwork' does not contain a definition for `automaticallySyncScene", please update PUN from the Asset Store. You might have an older version.
     
  7. Megagamefan100

    Megagamefan100

    Joined:
    Oct 24, 2012
    Posts:
    26
    That fixed it thanks
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    I just updated PUN in the Asset Store to PUN v1.50.
    This time, there is a lot of stuff. Mecanim! 2D! Chat Api for PUN and PUN+. Ownership Transfer and lots of other improvements and fixes.

    v1.50 (10. December 2014)
    Updated: To Unity 4.3.4. We wanted to support 2D and Mecanim. Hopefully you are not in the 8% that still use Unity 3.x.
    Added: Chat Api and Chat Demo. The demo is just a basic UI which shows one option to handle input and commands. It should help you to use the very simple ChatClient functionality to build your own GUI for Chat. This can be combined easily with PUN but it's optional.
    Added: Mecanim Support! There is a new component "PhotonAnimatorView" which can be used to synchronize the state of a Mecanim Animator.
    Added: PhotonTransformView, PhotonRigidbodyView, PhotonRigidbody2DView. Each offers several options to smooth movement updates. Also check out their code as inspiration how you can implement your own.
    Added: New Demos: Mecanim, RpgMovement and 2D Jump and Run.
    Added: New feature: Ownership Transfer.
    Added: PhotonView.RequestOwnership() and .TransferOwnership(). Per PhotonView you can define if it can be "taken" by anyone or if the owner gets a "request" to hand over control. A PhotonView can also be "Fixed" and not transfer control at all. This is set as OwnershipOption in Inspector.
    Added: Callback OnOwnershipRequest() where a transfer could be executed (or rejected). For OwnershipOption.Request, this callback is called on the current owner of the PhotonView in question. It can TransferOwnership() but doesn't have to.
    Note: Ownership Transfer would break if you set the transfer-option changes at runtime (as it's not synced). Due to that it's deactivated in Editor when playing.
    Added: Events OwnershipTransfer and OwnershipRequest for internal use.
    New: IPunObservable and IPunCallbacks define the callbacks of PUN to be easier implemented.
    Added: Photon.PunBehaviour which implements all IPunCallbacks. If your scripts derive from this class, they can override the callback methods to implement them. This is easier to write as auto-completion in MonoDevelop and Visual Studio will support you. IPunObservable is not in PunBehaviour - OnPhotonSerializeView() is called too often to have it in all scripts.
    Changed: The PhotonView component has now a list of observed components. You can observe one or multiple components per GameObject, which makes it easier to split tasks across some scripts. Of course you can still observe no script at all (if you use RPCs only on that PhotonView). Existing prefabs with PhotonViews are compatible and will be updated.
    Changed: SendMonoMessage can now be limited to a specific Type. Instead of calling all MonoBehaviour, you could callback only on Photon.Monobehaviour. Set the Type via: PhotonNetwork.SendMonoMessageTargetType. By default, this is MonoBehaviour (as before).
    Added: Option to cache the scripts that get PUN callbacks. With this caching, you can skip expensive FindObjectsOfType() calls when a callback is done. The drawback is that new components won't automatically get the callbacks! They could miss something unless you refresh the caching. Use with care.
    Fixed: Issues with RoomOptions when using Object Initializer syntax. For example "new RoomOptions() { isVisible = false };" now actually sets isVisible of the room. We found this is a known issue in Unity, es discussed here: http://tinyurl.com/pnxrc8r .
    Added: PhotonNetwork.AllocateSceneViewID() to be able to allocate scene view IDs. Only allowed for a Master Client.
    Added: In offline mode, RPCs that are sent to AllViaServer and AllBufferedViaServer will execute locally (immediately). The RPC method will be called in the same frame. Before this, the RPC wasn't called in offline mode for those two settings.
    Fixed: Assignment of minimum ViewId for scenes in Editor. The Application.loadedLevelName is not correct in that case, so better use EditorApplication.currentScene to get the name in Editor. Thanks to paulusul from the forum.
    Changed: The PhotonNetwork constructor creates a NetworkingPeer based on protocol of server settings. This avoids creating another networking peer, unless you deliberately switch protocol. Debug Level and other settings won't be lost due to SwitchProtocol.
    Updated: The Demo for Custom Authentication and Find Friends. It should be a bit easier to use and digest.
    Changed: PhotonViewHandler now assigns a ViewID and InstantiationId to views (was using a "SubId"). Scene objects get the same InstantiationId for all views.
    Removed: NetworkingPeer.instantiatedObjects. PhotonViews are enough to access all instantiated game objects (even including scene objects). Adjusted NetworkingPeer.LocalCleanupAnythingInstantiated(), .DoInstantiate() and .DestroyPlayerObjects() and PhotonView.OnDestroy() accordingly.
    Changed: NetworkingPeer.RemoveInstantiatedGO() to use the creator's ActorNr when cleaning up the Instantiate events.
    Changed: ServerCleanInstantiateAndDestroy(). As scene objects are not created via buffered "Instantiate" events, a "Destroy" has to be buffered instead. This is now done automatically. Destroyed scene objects will be destroyed when a player joins late. Also ServerCleanInstantiateAndDestroy() now expects the creator's ActorNr to remove Instantiate events from the server's buffer.
    Changed: PhotonView.isSceneView now checks if the creator of an object is 0 (scene). Previously the owner was checked but this can change now.
    Changed: PhotonView.isMine now checks ownerId first. On the Master Client, isMine is also true if isOwnerActive is false! This way, abandoned and scene objects fall to the Master Client.
    Changed: PhotonView.isOwnerActive checks if the owner is 0 (scene). If so, the owner is never active. This is just a shortcut.
    Added: SupportLogger now logs Game Server address when entering a room.
    Changed: Some of the internally used classes are now wrapped in a namespace to avoid clashes with other products.
     
    p87 likes this.
  9. RGSMS

    RGSMS

    Joined:
    Jan 15, 2014
    Posts:
    2
    Hi guys, I'm trying to use the "ExitGames.Client.Photon.SocketUdpNativeStatic" to get my serveraddress "ServerAddress()" and my serverport "ServerPort()". This is my code:

    "ExitGames.Client.Photon.PeerBase peerB = new ExitGames.Client.Photon.PeerBase();

    ExitGames.Client.Photon.SocketUdpNativeStatic udpS = new ExitGames.Client.Photon.SocketUdpNativeStatic(peerB);

    Debug.Log(udpS.ServerAddress());
    Debug.Log(udpS.ServerPort());"

    My problem is: the ExitGames.Client.Photon.SocketUdpNative needs a ExitGames.Client.Photon.PeerBase but when I try o create a new ExitGames.Client.Photon.PeerBase the unity show me this message:

    Assets/TesteNetPhoton.cs(43,112): error CS0144: Cannot create an instance of the abstract class or interface `ExitGames.Client.Photon.PeerBase'

    Someone knows how can I solve my problem?
     
  10. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @BillyCoenWU: This is not the intended use. The class is in our package for internal usage and it's not setup to provide a DNS resolution. Also, this is from PUN+ and not PUN Free (this thread).
    Sorry, we won't support this.
     
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    We found out there's a bug in v1.50 and will release a fix soon.
    In the mean time: Using the type "PhotonPlayer" as parameter in RPCs will cause: "Exception: Serialization failed. Stream position corrupted. Should be ... ".

    The fix is really simple:
    Open CustomTypes.cs and edit method SerializePhotonPlayer(). Insert:
    outStream.Write(bytes, 0, 4);​
    in the line before the return statement. That's it.
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    I just uploaded PUN 1.50.1 with fixes for the 3 known issues:

    v1.50.1 (17. December 2014)
    Fixed: JoinRandomRoom filtering with the expectedMaxPlayers parameter wasn't working properly. If you create rooms with different maxplayer value, you can now filter them as expected.
    Fixed: PhotonPlayer could not be sent in RPCs or anywhere. It caused an exception "Exception: Serialization failed. Stream position corrupted.", even though you didn't do anything wrong.
    Fixed: PhotonView.viewID initialization. This only affected cases where a PhotonView was added to a GameObject by code at runtime. This was causing multiple different errors. Now the default viewID is 0 as expected by PUN. Before a PhotonView is really usable, it must get a viewID which you generate/select via AllocateViewId().
     
  13. jkcom

    jkcom

    Joined:
    Aug 31, 2013
    Posts:
    5
    Hi. @tobiass

    My Problem is Offline mode setting on runtime.
    I wish " connect -> joinroom -> multi play -> disconnect -> offlinemode -> single play -> disconnect -> re connect -> multi play"

    I set offlinemode after disconnect, but error occur "Failed to Instantiate prefab: Taron. Client should be in a room. Current connectionStateDetailed: PeerCreated".

    I don't know how to set offlinemode in runtime.
     
    Last edited: Dec 24, 2014
  14. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    I have the weirdest issue with PUN... Check this out!

    I have a working MOBA (Multiplayer Online Battle Arena) Framework which uses PUN and Photon Cloud. Now the Framework works perfectly fine with the present Character (Player) Assets, everything Syncs nicely from Animations, Movement, Actions etc... But when I decided to swap out the Character Assets for another (particularly this one:
    Blade warrior NPC V 2.6 https://www.assetstore.unity3d.com/en/#!/content/6515), the Player Characters begin to Glitch in Game! As in... first Player Connects becomes Master Client (host), second Player Connects to that Room, but these two Players (Clients) are unable to see each other's movement because they are Glitching out! In other words you can tell that the other Player is connected to the Room, but if you try to Move towards a Player you being to see that Player as a Ghost Glitching, and Moving around the Screen and Environment Erratically. Now the strangest thing of all is that when Testing from Unity Editor, you won't see any Error Messages at all! What Gives?

    I have tried Updating PUN, that didn't help. I tried other Character Assets of the same Artist and it did the same thing; I tried reverting back to my original character assets and there was no problem at all. So it's safe to say that the issue is related to the Character Asset not Photon, while you may wonder then Why am I posting here about it... well because the issues is only happening with Photon and Syncing this Particular Character Asset, while other Assets don't seem be a problem.

    Is there anything like this that happened before? Is there something I'm missing to add, or check on the Character Asset Setup to ensure the Character is visable in game and not glitching out? I copied all the the Player Scripts from my Original Characters that Work without Glitching to this new Character Asset and Compared the Scripts (Components) to ensure everything was setup the same, and it was...

    So i'm totally lost why this is happening with a Particular Character Asset, and why no Errors are being thrown to help me identify the problem. Please Help!
     
  15. jtadeo1

    jtadeo1

    Joined:
    Oct 18, 2006
    Posts:
    78
    @Kuroato, do you by chance have a rigidbody attached to the character? Try removing the rigidbody it.
     
  16. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    I'll double check but i'm pretty sure I don't... I'm using the standard Unity Character Controller plus other Scripts.

    Also, just to note, the erratic movement is not happening to the Player Character you control, it's happening to the 2nd player connected, at least it seems like the 2nd player is jumping all over the place but really the 2nd player is moving around like normal on their client end, as is with the 1st client, but too each other we are moving around the whole screen like a Ghost on Crack or something lol.
     
  17. Pathlesspath

    Pathlesspath

    Joined:
    May 8, 2013
    Posts:
    13
  18. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    I am working on a multiplayer racing game for WP8 and I get this exception:

    Exception: Exception has been thrown by the target of an invocation.
    Type: System.Reflection.TargetInvocationException
    Module: mscorlib
    InnerException: Object reference not set to an instance of an object.
    AdditionalInfo:<No Data>
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at NetworkingPeer.ExecuteRPC(Hashtable rpcData, PhotonPlayer sender)
    at NetworkingPeer.OnEvent(EventData photonEvent)
    at ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback(Byte[] inBuff)
    at ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands()
    at ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands()
    at PhotonHandler.Update()
    at PhotonHandler.$Invoke19(Int64 instance, Int64* args)
    at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)


    2-3 players join room and the master client starts the game here menu scene is changed to the race scene and now (with uttermost rarity) this exception happens. It crashes my game.

    I have no clue where to look for a solution.... please help
     
  19. jldevoy

    jldevoy

    Joined:
    May 2, 2014
    Posts:
    33
    Is there a hidden trick to getting this to work using the local server? It seems to work ok using the cloud option but local server always has an authentication problem.
     
  20. Quaker_SDR

    Quaker_SDR

    Joined:
    Jun 21, 2013
    Posts:
    39
    Photon Networking - Getroomlist() - I used the get room list function for getting the rooms in the server. But once i joined the particular room ,I am not able to see the list? How can i see the list even if i connected to room?
     
  21. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Can you post this specific problem in our forum please? I will get our server colleagues to take care then.
    Thanks.
     
  22. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @Quaker_SDR: The room list is only known to the Master Server. When you're in a room, you are on another machine and can't have the list. Sorry.

    @sathya: Are you building 64bit? Which RPC is causing this issue? I need to know the parameters you send.
    This might be a problem in our code but could as well be an issue in Unity's export. Please post a new thread in our forum about this.

    @Kuroato: You might be applying input to the "remote" character by accident. This can be solved by checking photonView.isMine before you check Input.

    @jkcom: Offline mode can be enabled by setting PhotonNetwork.offlineMode = true. You have to be disconnected to do so. It will create a fake room and you can instantiate.
     
    jonkuze likes this.
  23. wetfiregames

    wetfiregames

    Joined:
    Nov 17, 2012
    Posts:
    28
    @tobiass

    Sorry this is so lengthy I just hope that this will answer all my questions and concerns with my project right now and its current direction, thanks for understanding.

    Product Question: After reading the product explanation on your site here I am curious if the cloud supports some sort of 'Authoritative' server build via uploading our scene / other alternatives... of which then an instance of the server is instantiated per hosted game request but only created after a lobby is formed and users are ready to start the match via ready check?

    *Ultimately my challenge with my current prototype build in the Unity framework is that the 4-player Co-op game will resume regardless if the host leaves the game even if they responsible for setting up the match initially. Also the annoyance from hosting issues for client side perspective regarding NAT Punch-through eliminating the need for users to open ports and change router settings.

    If so where can I get more direct information/documentation/examples on the feasibility of this type of setup.

    If I'm not being clear I hope this is more direct -
    -> Users connect to Photon Master Server which then would point to the Photon Cloud - Hosting Server Instance they requested to be setup on the PhotonCloud which manages the AI and other Authoritative server responsibilities. The players connect to that hosting server and play their match until returned to the lobby and the hosted server instance is shutdown / reused for other matches.
     
  24. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @Wieljer: Don't worry about the post-length :)

    The Photon Cloud does not support authoritative server logic and can't run your scenes or Unity instances. This is really interesting for us but rather hard to manage in the shared environment we have.

    For cooperative games, I would say you can get away without a real authoritative server. You can sync game start without one and as everyone is cooperating, syncing the rest of the game should be rather forgiving.

    The Host is replaced by a Room in Photon and in said room, one player can take the extra role of running the AI. This behaves in principle as if one client has more than one player while the others just have one.

    Imho, AI doesn't need 10 updates/sec. Each mob needs to figure out where it wants to go and send the target position. If that's a position that's reached in a second, then you probably don't even need to send an update in that time.
     
  25. wetfiregames

    wetfiregames

    Joined:
    Nov 17, 2012
    Posts:
    28
    @tobiass: LoL okay well I'm gonna kill the post length then...

    Thanks tobiass! I have seen different pages on the exitgames.com but nothing was quite as direct as you have described (1). Thanks for clearing that up.

    So Per your example, how does Photon manage the room responsibilities if the user currently running the role of running the AI leaves in the middle of the game? Is there some sort of Roles class that can define the load balancing or transitioning of the responsibilities? I'm looking to avoid the problem "The host has left the match ... You have been Disconnected" -This leads me back into the authoritative server, I just can't seem to wrap my head around finding how the user that made the game isn't the host running all 'authoritative' game mechanics like AI, Rotation, Position (to provide protection from client side hacking/manipulation). Does the 'Photon Realtime' solution enable you to just provide non-authoritative updates through a peer to peer system without requiring a 'server' scene to be built and run via a separate dedicated host that the users are connected to? ("since the Unity servers are player hosted latency/ping is usually worse; you rely on the connection of the player acting as server. These connections are never any better than the connection of your dedicated Photon server.")-exitgames(2)

    (From what I come to understand)
    Within Unity, players host the network servers. So I am not sure if/how I could utilize Photon to avoid the need for a user to run a dedicated server. There seems to be only two options, build a server and host it on private server farms or give the user an option to make their own dedicated server before they can do matchmaking, essentially having two instances of the game running. -Perhaps what would be best is to run my own hosts, 10-1000+ servers that players would get matched from photon and connected to the available server not in use at the time. The server would receive the parameters configured such as selected map, game type and then initialize those parameters for the match. Once the game is closed or no users are connected then it would reset those parameters and mark its self as available to the photon master server?

    "AI doesn't need 10 updates/sec"-tobiass
    -It seems 5 or less for prototyping is feasible //configuring syncing only when AI states change/RPC's for animations, position, rotation.

    References:
    (1) "Out of the box, Photon does not leverage or interact with any scenes or physics." -ExitGames, Authoritative Server
    (2) "Photon Unity Networking (PUN) Compared To Unity Networking (UN)" -ExitGames, Photon vs Unity Networking

    Thanks for your time, it's such a huge step to understand the approach I am taking now before I continue further development on the built-in Unity networking solution. I want to be able to scale ccu's with photon but I am looking for other advantages.

    Note: I've looked for sample PUN projects that utilize AI but none seem to currently, any suggestions if there is one?
     
  26. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    I updated PUN Free and PUN+. The main fixes are highlighted below.

    v1.50.2 (13. January 2015)

    Fixed: Arrays of Custom Types can be sent again. Serialization failed for (e.g.) Vector3[] and is now fixed. (This is a fix in: Assets\Plugins\Photon3Unity3D.dll and it's platform-specific variants).
    Fixed: When leaving a room, GameObjects created by InstantiateSceneObject() will be cleaned up (destroyed). For this, the PhotonViews now have a new (internal!) value isRuntimeInstantiated. Objects loaded with the scene are not cleaned up (as before).
    Fixed: Destroying a scene GameObject that was created by InstantiateSceneObject() will not cause joining clients to log an error. Only objects that were loaded with the scene get a buffered Destroy message (for joining clients which load the GO with the scene from disc).
    Changed: NetworkingPeer.RemoveInstantiatedGO() now also finds disabled PhotonViews, which is cleaner for destroying the GOs.
    Added: PhotonView.RpcSecure(). This variant gives you the OPTION to encrypt an RPC. You should use this rarely but in some cases it makes sense to send your data encrypted. Simply set the "encrypted" parameter to true to do.
    Changed: Minor refactoring to avoid frequently creating objects.
     
  27. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @Wieljer: Hehehe. That wasn't an invitation to kill the forum :)

    Photon uses a server which is not run in Unity. It enables any client to send messages to the others, buffer them, etc. Also, there are room- and player- properties. It does not mind the scene or anything Unity related.
    You have to organize your clients in a way so that one takes control of AI. Just like you have to organize them to take control of a character (but without input).
    If that player leaves, the others are not affected but should take over the extra duty.
    To help with that, the server and clients know a "Master Client". This is the active player that's the longest time in the room. Only if a Master leaves, a new one is selected.

    One server can run many rooms (which are more or less equivalent to the host in Unity's networking). For 1000 to 2000 concurrent players you only need one machine with one Photon instance running.

    I think the only demo with AI is the Angry Bots Multiplayer variant. In it, one client moves the bots and the others just get updates and move accordingly. It's not very sophisticated but a better solution would also depend more on what your AI is capable of. You will have to experiment a bit with that.
     
  28. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    How is WebGL Support coming along for Photon? I have yet to do any testing... I'm really hoping WebGL and Photon are working by April with Chrome shutting down NPAPI (no more Unity Web Player). Any insight would be appreciated.
     
  29. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Is it possible to have a (self-hosted) server organize commands to send? I'd like to have all clients send an RPC to the server and the server will raise an event based on what it receives from the clients.
     
  30. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @Kuroato: We have a closed Early Access group for PUN WebGL export (it's working already). As far as I could see, the Unity player is rather good already! When you're ready to test this yourself and give us some feedback, get into the group by applying here.

    @jpthek9: Yes, that's what you could do with the Photon Server SDK. You would use Photon's "Operations" (RPCs you call on the server), "Responses" (for operations) and "Events". Get the SDK with a free license from our Download Page
     
  31. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    Thanks Tobiass I'm actually apart of the Group already, just haven't begun testing but we will soon. I was just curious where Exit Games stands in regards to WebGL Support beyond the early access user experience, but I guess if you say "it's working already" this means you guys have done your best so far to get Photon Working as best as possible with Unity WebGL.
     
  32. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    We will do more updates soon and let you all know what our plan is.
    I should be able to post news this week. :)
     
    jonkuze likes this.
  33. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Sorry for another (probably basic) question. This thread has been a great help so far.

    I've been trying to implement my own server confirmation system with the 'Adding Operations' tutorial and I'm confused as to how to call operations from the client. I can create a PhotonPeer variable and I have all the .OpCustom calls set up but I don't know how to assign the PhotonPeer to the current peer instance.

    In short, what I'm asking is for a more detailed explanation of calling a custom operation.

    Oh yeah, and a bit of a side question: Does each load balance instance run a new LitePeer instance? Is LitePeer a suitable place to write custom operations and data structures for individual games on the server.
     
  34. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    @jpthek9:
    In PUN, the NetworkingPeer is a PhotonPeer, so OpCustom() is part of the PhotonNetwork.networkingPeer instance. You can expose this in a static way in PhotonNetwork easily (it's not done in PUN, as it's a rare usecase).

    The server question is a bit off-topic for this thread, so please post the server questions in our forum. I am not sure if our server gurus have more docs online or just answer any question you might have.

    The peer might be a suitable place to implement operations that only affect one client. If an operation affects a room, you can implement that in the Room class. But the server guys know this better :)
     
  35. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Ah, thanks a lot tobiass. I'll try to find out more about the server stuff.
     
  36. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I did some more work with Photon and came to the conclusion that there were other networking solutions that could suit my game's needs better. I've written some feedback for Photon here about some things it could use some work on if you guys are interested in seeing.
     
  37. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Interesting read but (being biased) I think it's also a bit unfair. You skip a lot of what Photon Cloud does for you (hosting, loadbalancing, matchmaking, lots of options for in-game communication) and concentrate on things that didn't match your case.
    The PhotonView object syncing might not be useful in your case but there is RaiseEvent and you can aggregate commands in packages, which reduces the overall overhead.

    If you like, message me or mail us to developer@exitgames.com. I would like to find out what you plan to send which will blow the bandwidth...
     
  38. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    I run a game that uses all 500 room messages/second and i did not even optimize the messages (i send a lot of S*** haha), and the bandwidth is by no way perfect but no problem at all :D A bit more than i get from games like League of Legends which is a million dollar production.
     
  39. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    Oh, that's true. Sorry I kind of skipped over that. Just because it doesn't suit my games doesn't mean it won't suit others'. I actually only need 400B/s of server bandwidth with custom server code, about 7KB with the 50 bytes of overhead for an unreliable message. The thing is, not even considering the server, it'd be impossible for clients to play without custom server logic as the data going around would have to increase quadratically compared to linearly where the server facilitates all the information. This is true for all lockstep games. If developers could run even 1 custom script or plugin on the Cloud, it'd be a lot more practical for many games.
     
    Last edited: Feb 2, 2015
  40. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    @tobiass I just recently started working with PUN.
    I'm using the cloud and I wanted to know if there is an API for getting the amount of players in each room (when in lobby) and also an API to get total amount of players in server.
     
  41. AlucardJay

    AlucardJay

    Joined:
    May 28, 2012
    Posts:
    328
    I can help with the first part.

    Code (csharp):
    1. foreach ( RoomInfo roomInfo in PhotonNetwork.GetRoomList() )
    2. {
    3.     Debug.Log( roomInfo.name + " (" + roomInfo.playerCount + "/" + roomInfo.maxPlayers + ")" );
    4. }
     
  42. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Thanks @alucardj, I didn't see playerCount and maxPlayers in RoomInfo.
    I'm guessing I can use the same way to get all players in server (keep adding roomInfo.playerCount).
    But is There a way to get the max players in server? I know I have a limit of 100 but I don't want to hard code the value.
     
  43. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Use PhotonNetwork.countOfPlayers. It's updates while you are on the Master. There are also countOfPlayersOnMaster, countOfPlayersInRooms and countOfRooms.

    Your clients get a callback when the max CCU is reached: OnPhotonMaxCccuReached(). It's defined in PunBehaviour, so you can extend that class and override that method.
    This won't happen when you have a subscription with "overage". Basically any subscription with monthly fee has overage and can be increased when demand is there.
     
  44. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Thanks for the Info @tobiass. So there is no API to pull the max CCU as number to display?
     
  45. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    Ah. Now I get it.
    No, sorry. You can't pull the max CCU. It usually doesn't matter to your players though. Check it in the Dashboard and in doubt, get in contact and we give you "overage", so all players can play and you adjust the subscription when demand goes up/down.
     
  46. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Ok, that's what I wanted to know.
    I Have another question about getting the list of room:
    I made a function to get all rooms and create buttons for them.
    I triad running this function in the OnJoinedLobby, but I'm getting 0 rooms.
    Only If I run the function from a button, I get the correct amount of rooms.
    Any ideas to why this his happening?
     
  47. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,067
    It's not sent with the response to OpJoinLobby(), so it's not available in the callback. I think we could change that to make it work more as expected.
    The list is being updated by events while you are in a lobby, so you will need to fetch the list over and over again.

    When you get more players, you will want to show different rooms in the top ten per client to avoid a rush for the same room.
    In best case, you skip showing rooms and just to filter-based random matchmaking to find a suiting room with a level, skill, etc.
     
  48. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    I did add a refresh button so the user can refresh the list when he wants to.
    But I don't want the user to have to click refresh the first time he enters the lobby.
    But I think I figured out a way to do this:
    I'll do a "loading screen" while trying to connect to lobby and when lobby is connected I'll switch to the actual lobby scene.
    At the lobby scene I will get rooms list on start.
    Should work :)
     
  49. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    My Idea didn't work :(
    It's really weird because I'm displaying PhotonNetwork.countOfRooms and it shows 1.
    One line after that I'm calling the method that creates the buttons for rooms.
    In there, I'm doing PhotonNetwork.GetRoomList() but I'm getting an empty array....
    Only if I'm calling the method later through a button, it works as expected.
     
  50. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Hey @tobiass, I was wondering why you use double instead of float for the time (PhotonNetwork.time) ?

    I have to cast it to float sometime because the compiler isn't really happy :eek: