Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon Unity Networking

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

  1. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Just released a small update to PUN 2:

    v2.8 (15. March 2019)
    Changed: Unity 5.6.6f2 is now the minimum supported version. Older versions won't run in the most up to date MacOS anymore, so we decided to drop those.
    Added: VIVEPORT Authentication provider. See: https://www.photonengine.com/en-us/viveport and docs: https://doc.photonengine.com/en-us/...d-authentication/authentication/viveport-auth
    Changed: The cached "best region" is cleared whenever a region's pinging finishes. This fixes a potential issue when the BestRegion value is used before the pinging is done. Then, you end up with a wrong selection.
    Added: When connecting to a Master Server directly (likely a Photon Server / OnPremise) without a UserId, PUN will now set a GUID. This reflects the behaviour of the Photon Cloud and helps differentiate clients by a UserId in matchmaking.
    Changed: When connecting to a Master Server directly (likely a Photon Server / OnPremise) with WebSockets, PUN now automatically uses a compatible serialization protocol (GpBinaryV16).
    Changed: The callback OnRoomPropertiesUpdate is not called when/before entering a room. It was called whenever properties change, which is also the case when the Realtime API constructs the room (with properties). Wait for OnJoinedRoom and check properties the first time when that's called.
    Updated: Photon3Unity3d.dll library to 4.1.2.10, rev5023.
     
  2. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
  4. chaenator

    chaenator

    Joined:
    Jun 29, 2017
    Posts:
    9
    Any good tutorials I can check out for PvP ("permadeath") setup with Photon?
     
  5. btckey

    btckey

    Joined:
    Nov 1, 2012
    Posts:
    40
    Hello
    My version: Unity 2018.2.20f1
    I use: PUN 2
    And I get the error:
    Assets / Photon / PhotonUnityNetworking / Code / PhotonNetwork.cs (1085,17): error CS0103: the name `SocketWebTcp 'does not exist in the current context
    Can't create WebGL
    How can I fix this?
    thank
     
  6. Tesrym

    Tesrym

    Joined:
    Dec 2, 2012
    Posts:
    64
  7. btckey

    btckey

    Joined:
    Nov 1, 2012
    Posts:
    40
    PhotonUnityNetworking.asmdef
    I have a code

    Code (CSharp):
    1. {
    2.     "name": "PhotonUnityNetworking",
    3.     "references": [
    4.         "PhotonRealtime"
    5.     ],
    6.     "optionalUnityReferences": [],
    7.     "includePlatforms": [],
    8.     "excludePlatforms": [],
    9.     "allowUnsafeCode": false
    10. }
    how to add here
    PhotonWebSocket

    Code (CSharp):
    1. {
    2.     "name": "PhotonUnityNetworking",
    3.     "references": [
    4.         "PhotonRealtime","PhotonWebSocket"
    5.     ],
    6.     "optionalUnityReferences": [],
    7.     "includePlatforms": [],
    8.     "excludePlatforms": [],
    9.     "allowUnsafeCode": false
    10. }
    I did the right thing?
     
    Last edited: Mar 21, 2019
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @btckey: Should be fine.

    We just submitted a tiny update to fix the problems with the PhotonWebSocket assembly. No new version number (except in the changelog):

    v2.8.1 (21. March 2019)
    Fixed: Problem with assembly definition and WebSockets usage.
    Removed: Unused code (fixing the warning about that).
    Note: This version has minimal changes that don't affect the gameplay, so we decided not to change the version in PUN (which would separate players) or in the Asset Store (which triggers a mail).
     
  9. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    We just submitted another version for PUN 2 to fix a bug in the previous release. Changing "the callback OnRoomPropertiesUpdate is not called when/before entering a room" had an unexpected side-effect when synchronizing scenes. The sequence of scene loading was changed and affected the lifetime of objects. This is fixed. Let us know if anything is odd.


    v2.9 (26. March 2019)
    Fixed: Automatic level synchronization, which was affected by the callback change in v2.8.0. Now, as in 2.7 and earlier, the scene is loaded on join, before the OnJoinedRoom callback.
    Changed: The api reference for LevelLoadingProgress and LoadLevel.
    Fixed: Surplus call to Disconnect when the app quits but PUN is offline. This also means there is no OnDisconnected() callback in this case (which happened unintentionally).
    Internal: SetLevelInPropsIfSynced() is now called in NewSceneLoaded() under the condition that PUN was not causing the scene-load. So it's not called when the scene loaded via PhotonNetwork.LoadScene.
    Fixed: SetLevelInPropsIfSynced() now checks if the new value is not in the props yet and if so, it will set the property right away.
    Fixed: When using LoadLevel(), this will set the new sceneId as property right away (unless it didn't change). This should avoid delays on other clients loading the same scene.
    Changed: The condition when a async load is canceled. If at all, it only cancels a PUN-initiated loading, if the new sceneId does not refer to the scene in the properties.
    Fixed: PunCockpit script. Using the left side of the lobby panel, it now uses the default lobby (no name, type = default) for CreateRoom and JoinRandom. If you JoinLobby in one client and CreateRoom in another, the created room will also show up in the list (bottom right).
     
    digiross and Stanchion like this.
  10. Rob-161

    Rob-161

    Joined:
    Dec 1, 2016
    Posts:
    20
    Hi folks, how would I go about caching raised events and sending them to all other players once the current player hits "end turn"? Rather than sending the events instantly each time they are raised.
     
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @Rob-161: You could create a list of actions for each turn, fill it locally and send/serialize it on "End Turn". Just store it locally.

    If everyone is in the room for the whole duration of the game, you don't need to cache turns server-side. If you want to support late-join, you can send the turns as "Cached Events" and the server will send all turns to joining players for you, so they are up to date. Of course, then the amount of turns to "load" on join should have limits (to avoid issues when players join after thousands of turns).
     
  12. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    @tobiass I've noticed that the AllocateViewID() variant that didn't take a parameter and UnAllocateViewID(int id) have both been removed in a recent update.

    I use these functions in my game to manually obtain unique network IDs for objects that haven't got a PhotonView and then use UnAllocateViewID(id) to free them up after I've finished with them.

    Whilst I've made a workaround for this, it requires that I edit the PhotonNetwork.cs script to make it work, which means I have to reapply the changes every time I update PUN2.

    Is it possible to have this functionality put back in or was there a solid reason for removing it?
     
  13. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    We removed UnAllocateViewID(), as it was not always used correctly. In the new workflow, you don't have to free viewIDs, even when allocated manually.
    This changed with v2.1.

    The change in AllocateViewID() was meant to make sure the viewID is applied to the view. It also makes sure that you don't overwrite some existing value, which is a little more likely if you make use of the object pooling.

    It does not make sense to bring back UnAllocateViewID(), I think. Could you adjust your code for AllocateViewID()?
     
  14. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    My understanding is that now I can only use AllocateViewID() for an object that also has a PhotonView, and I'm guessing that is why UnallocateView() is no longer needed. Please correct me if I'm wrong about that.

    In my usage case I was using AllocateViewID() to get a temporary network identifier for objects that are created without attached PhotonViews, hence my requirement for the old version of the function.

    As I said, I've edited the PhotonNetwork class to get around this, and it sounds like I'll just have to accept that I'll need to reapply the change every time I update PUN or look into writing my own custom function that achieves the same thing without making use of that part of your code, which is most likely what I'll end up doing.

    If the same criteria for removal applied to every function in PUN, you'd have hardly anything left :p
     
    Last edited: Apr 2, 2019
  15. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Good point! Can't keep that up, obviously. :D

    So you have networked objects without a PhotonView?
    Then you're not really bound by the viewIDs that PUN allocates.
    I would like to know more about how you use that. I guess you can make yourself independent from AllocateViewID.
     
  16. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Without getting bogged down with too much detail, the game we are developing is an RPG and some players can be in different maps to other players.

    We sometimes spawn objects which only players in the same map as each other need to know about (specifically for the party system and combat system we have developed), and to cut down on network traffic we only spawn them on the clients that need to have them, therefore we don't use the PhotonNetwork system to spawn them.

    But as there can be multiple instances of them, each belonging to different players on the same map and each one being interactable with multiple players, we need to have the means to identify them uniquely in a networked way, hence using AllocateViewID(), as this was a handy way to get such an ID.

    However, if the old version of AllocateViewID isn't likely to be reinstated, I'll probably just roll my own replacement as previously mentioned.
     
    tobiass likes this.
  17. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    How about using a separate room per instance? Then you don't need fine tuned control what to send to whom?
    I guess you want to stay in touch with everyone else? Could be a use case for Photon Chat.
    I'm just thinking. Don't change anything if it's working for you. Then it's fine!
     
  18. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    I never considered using a different room for each map, there's a few aspects of the game that may need to be reworked to make them behave the same way as currently, but it's certainly something worth keeping in mind if we run into insurmountable issues with our current approach later on down the line.

    As it stands at the moment, they way we do it does allow all connected players to communicate regardless of which map they are in, without the need for Photon chat. (anything we can do to keep the running costs down is a bonus).

    My original request for change was a convenience matter rather than a game breaker, so it's not a major issue either way.

    Thanks for your time :)
     
  19. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    It just occurred to me that I may have misunderstood this as meaning separate room for each map, when you might have meant separate room for each player, if it was the latter then that definitely wouldn't work for us.
     
  20. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Just deleted a reply for an outdated message. Page didn't reload...

    You've been right initially. A room per player would really not work well. A room per "party" might work.

    Using a room per location is another option but you have to make sure you can "shard" the locations, if one room becomes too busy. As the MaxPlayers of a room should probably stay below 20 or 30, a location would get a occupancy limit, so you would need a way to dynamically use more than one instance of a hub space. This could be done by using a Room Property for the matchmaking.
     
    Munchy2007 likes this.
  21. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    We've already tailored things for a maximum of around 30 players per game session, we aren't intending it to be a massively multiplayer experience. Because parties can interact with other parties, separating them out into their own rooms would present its own set of problems, so that's probably not going to work for us either.

    I think for the time being at least, we'll keep things as they are, with the only change maybe being the way we allocate the manual IDs so we can apply PUN updates more easily.
     
  22. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Sounds good to me. To make sure: I was just thinking out loud. No need to change anything that works for you.
     
    Munchy2007 likes this.
  23. bComponent

    bComponent

    Joined:
    Apr 8, 2019
    Posts:
    9
    Hi everyone,

    so I decided diving into game programming, still don't know much about C# though. I intend to make a multiplayer game (obviously), so after reading/watching basic C# documentations and tutorials I realized that I'd need to set up the multiplayer scenario first in order to avoid double work.

    The game is really simple, though:

    You'll enter a Lobby and find a "Play" button.
    On "Play" you'll be send to the matchmaker.
    The game itself will be up to three Players, playing a minigame similar to Tic Tac Toe:
    • Every Player sits on a pile of coins/plates (even visually with an avatar)
    • It's turn based and each turn will be handled in sequence, not simultaniously by each Player
    • The player basically has the Option to steal coins/plates from another player under certain conditions (irrelevant here)
    • The pile grows/shrinks depending on player Input (needs to be networked)
    • The game Ends after certain amount of rounds or when one Player loses all coins/plates.
    • Input will only be handled via Buttons ("Steal from A" e. g.)
    • No player movement (except prefabbed animations at the end of a turn, or basically after Player Input or when losing a coin/plate)
    • No camera movement (static Scene, except the increasing/decreasing piles and some animations as mentioned before).
    Return to Lobby
    Rewarding system based on Outcome of the minigames
    Avatars to be freed/accessable spending reward Points
    Ranking System overall

    That's the rough outline. I'm just Setting up a more sophisticated decision tree.


    I have read UNET and Photon 2 (and partially Photon 1) documentations, still I'm a bit confused regarding the setup I need. Primarily I'm confused about the usage of PunTurnBasedManager, event raising and RPCs.

    a) Are RPCs possible using the TurnManager?
    b) As described like above the actual possible Messages to be sent are limited (in the minigame). Does this provoke the usage of events over RPCs?
    c) I think I'll use a dedicated server solution for this and hand over a lot of authority to the Server in order to prevent cheating/using assets that one shouldn't be able to use: does this change my decision regarding Events/RPCs
    d) Is the documentation about TurnBasedManager for V1 still valid to the most degree? I like the tutorial series you have in your documentation, they help a lot to understand the main workflow (or "how to think about what you need" ;) ).

    I understood how matchmaking works. I also understood how communications works in general (for the above mentioned cases). But being new to this I don't grasp which way to go. I guess there's a solution for every way, but which is the best?


    Thanks in advance, and best regards from Germany,

    Marcel


    Edit:
    There has also been some discussion on Page 41? here, but it didn't completly tell me what I need to know. Just wanted to let you know I actually used the search function :D
     
    Last edited: Apr 8, 2019
  24. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    699
    I have a Dictionary<CustomType, float> that I am trying to send in OnPhotonSerializeView. Unfortunately, when I do this, it throws an exception as follows-

    Is this not supported? The docs on Serialization says it should be. I'm using PUN 2.9 and my code is simple-

    Code (CSharp):
    1.  
    2. public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    3.     {
    4.         if (stream.IsWriting)
    5.         {
    6.             stream.SendNext(MyData);
    7.         }
    8.         else
    9.         {
    10.             MyData = stream.ReceiveNext() as Dictionary<MyType, float>;
    11.         }
    12.     }
    13.  

    I have verified that MyType otherwise works correcty, and also sending arrays of the keys and values also works as a workaround. It just doesn't seem to like my Dictionary.
     
  25. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @bComponent: Sorry about the late reply!

    a) The TurnManager works with "Moves", not RPCs. It's about the same with a different meaning. Moves don't target a specific networked object (they just affect your game logic/state, which is typically less dependent on Unity objects).
    b) RPCs are events of a specific kind. They target some networked object, have a sent-time, etc. Both are just messages to the other players (or everyone).
    c) Yes, as the Photon Server is not aware of PhotonViews, updates or RPCs. It forwards those messages as is and to read them, you'd have to implement the related concepts on the server. It's easier to use RaiseEvent (or the simple "Move" messages).
    d) Yes, the doc is still valid mostly. The principles are the same as before. PUN 2 just changed the icing on Photon's cake.
    Glad to read you like the tutorial series!

    To simplify matters, you could use the Photon Cloud and not modify the server. Make your game independent from Unity itself (use that as view / graphical interface) and you should be able to port the game to the server if ever necessary.
    A trick is to send event to "All" (or AllViaServer) and reliable. This means anyone in the room gets those events in the same order and all clients will know who was first to react to something (if you have anything that's happening concurrently).

    Preventing cheating can be done (to a degree) on the clients. Yes, the game logic on the server is "how it's done safely" but it's also expensive and complicated.
    Here are a few thoughts on Hacking Protection.

    @jRocket : That exception happens when you simply call that OnPhotonSerializeView()? Or is that a simplified example? Have to test.
     
  26. bComponent

    bComponent

    Joined:
    Apr 8, 2019
    Posts:
    9
    @tobiass
    Thanks a lot for your detailed reply!

    So my actual way to go would be using the TurnManager, working with turns/events but adressing AllViaServer? I'm definitly aiming for your cloud version (firstly because I can test it for free with 20 CCUs and secondly because it's scalable without reworking everything).
    Will have to dig a bit deeper into moves then, as right now I understand them as "gates/rounds" rather than single actions by a player. But I'll figure it out eventually.

    One last thing, though: Where's the best place to seek for project specific help once I have some code ready but get stuck? You know, once Google can't help you anymore ;)

    Appreciate your feedback!

    KR

    Marcel
     
  27. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    In best case, you try a forum post first. Explain how you are stuck and include logs. Just imagine we don't know the project :) If that doesn't help in a day or two, you may ping us by mail.
     
  28. DeanUC

    DeanUC

    Joined:
    Jun 12, 2017
    Posts:
    3
    I see that this post was never really followed up by the original poster. We have encountered this problem and are having trouble figuring out the cause. The error only started to appear today. The project was running fine before this, but noe after a few minutes running it will produce the above error. Was anything discovered about this, and how it can be fixed?
     
    Last edited: Apr 24, 2019
  29. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @DeanUC: That case was never resolved as we failed to reproduce it and then there was no further input on this.
    Please let us know which version you are using. If it's not the latest: Please update and try to repro. If you can: Mail us a repro case to: developer@exitgames.com.
     
  30. DeanUC

    DeanUC

    Joined:
    Jun 12, 2017
    Posts:
    3
    Thank you for your reply, Tobiass.

    We have updated PUN2 from version 2.2 to the latest (2.9), and it seems to have fixed the issue! Thank you for the suggestion. I'm sorry I couldn't offer you any repro info :/
     
  31. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    With PUN2, are players on opposite sides of the world going to be able to connect? or are they only going to connect to other players that are connected to the same server?
     
  32. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    They can only connect to other players on the same region server as them.

    You could potentially allow players from anywhere in the world to connect to the same region server, but that could result in high latency problems for the players that are located far from the server.
     
  33. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    We just submitted PUN v2.10 to the Asset Store. We fixed some issues with Unity 2019, improved performance and did some housekeeping.

    Edit: It takes unexpectedly long for this update to show up in the Asset Store. There should be a notification by mail, when it does...


    v2.10 (26. April 2019)
    Fixed: Unity 2019 compatibility. Removed warnings about obsolete APIs. Code clean up to remove compiler warnings in Unity 2019.
    Fixed: PhotonTransformView does not interpolate between the first streamed data and subsequent to avoid the initial drift between the player's original position and the current position.
    Added: Nintendo Switch Authentication enum value. More about this on our doc page for Nintendo Switch development.
    Changed: GetGameList operation is not sent when filter is null or empty. This resulted in a server-side error and now GetGameList logs this case and returns false.
    Changed: IsConnectedAndReady is now also false for ClientState.DisconnectingFromGameserver, DisconnectingFromMasterserver and DisconnectingFromNameServer.
    Changed: InLobby property is now checking the State == JoinedLobby, which is analog to InRoom.
    Changed: InRoom property getter checks if CurrentRoom is not null.
    Changed: removed references to PUN1's removed PhotonNetwork.GetRoomList().
    Changed: Renamed ClientState items which ended on "Gameserver" and "Masterserver" to using PascalCase "GameServer" and "MasterServer". The previous names are obsolete to ease upgrading this, if needed.
    Fixed: BroadcastPropsChangeToAll is applied correctly (it wasn't used properly, when false).
    Fixed: When in offline mode, OpSetPropertiesOfActor does not get called (it failed due to not being connected).
    Updated: To new library version 4.1.2.12 (26. April 2019 - rev5046).
    Note: EventData.Parameters is no longer guaranteed to be non-null! Events sent via RaiseEvent (the most common form) will have Code, Sender and CustomData but Parameters will be null. Internally, this means we can re-use some more memory. PUN covers this change for you but if you use the events more directly, you may notice.
    Chat
    Fixed: properly add local client's UserId to public channels' Subscribers list when applicable.
     
    Last edited: Apr 26, 2019
    digiross likes this.
  34. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    @tobiass

    While I've been developing my latest game over the few months, I've noticed that every couple of weeks or so there are periods of unexpected disconnections and high latency which seem to last as much as a couple of hours (although usually 30-40 minutes).

    During these periods I also sometimes get this error:-

    Connect() to 'ns.exitgames.com' () failed: System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'ns.exitgames.com'
    at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <3845a180c26b4889bc2d47593a665814>:0
    at System.Net.Dns.GetHostByName (System.String hostName)


    I've ruled out my ISP as being the root of the problem as when it happens it also affects other players at different locations using different service providers.

    Is this something you would consider normal? My concern is that once the game is released I will get complaints from users if this continues to happen.
     
    Last edited: Apr 28, 2019
  35. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    @Munchy2007: As DNS issues are involved, this sounds a bit like this may be our of our control but we would like to look into this.

    Can you mail us and provide some details? Do you recall when this happened? Which region were you using? Can you quantify how the ping is affected and how frequent the DNS error is out of how many attempts?
    Which version of PUN do you use and which Unity version and build settings?
    Edit: Can you reproduce the issue with another network or do any remote test players have similar issues at the same time?

    I have to discuss this with my colleagues from the server-side.
     
    Last edited: Apr 29, 2019
  36. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Unless you can reproduce the issues in another network, it makes sense to check your local settings.
    You should try different DNS servers. Cloudflare is supposed to be best ones atm: IP: 1.1.1.1.
     
    Munchy2007 likes this.
  37. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Hi @tobiass

    the problem affects all current connected players, regardless of which network they are on, so I don't think it's a DNS problem at this end. Also I should probably mention the DNS error only happens occasionally during the periods of lag and disconnections.

    temporarily switching to another region server usually seems to help, so it appears to be localised to the region server. Which made me wonder if you regularly carried out maintenance on the servers which could cause disruptions.

    It doesn't happen terribly often, so unless there's anything obvious that springs to mind at your end I'll continue to monitor it and see what feedback we get once we increase the number of testers.
     
    Last edited: Apr 29, 2019
  38. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    I think we should treat the DNS issue of the Name Server as a separate problem. There are several but they are not related to the cloud regions at all.

    Please mail us, should you notice either event again. If we know which region you're been using and when something didn't work well, we can have a better look. Also mail the appid you're using, so we can check the logs quickly.

    Thanks.
     
    Munchy2007 likes this.
  39. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Thanks @tobiass, I'll do that.
     
  40. Wothanar

    Wothanar

    Joined:
    Sep 2, 2016
    Posts:
    122
    hi guys i need some help im using photon old version not v2 but its all working fine i think and i have something to do and still cant see how to made it so thats why i come here i search over internet and well i think its something with filters but well the thing i want to do is the next:
    i have one button that its for join to CLANS MATCH so only people who is in a clan can join BUT, i want to when people join here only can fight between different clans members so i want to avoid that people of the same clan fight each other , how can i made this?

    this is what i have so far , but now im stuck coz i know this only would lead me to people of the same clan fight each other , coz i dont know where to put , join to room that the loobyoptions[1] is not same as me clanname? . i will appreciate your help thanks.

    LobbyOptions = new string[2];
    //0 mapname // 1 ClanName
    //here the answear map name
    LobbyOptions[0] = "M";
    //here the clan of the player who create the room
    LobbyOptions[1] = "C";
    MainGui maing = FindObjectOfType<MainGui>();
    ExitGames.Client.Photon.Hashtable customProperties = new ExitGames.Client.Photon.Hashtable() {
    { "M", roommapname }, { "C", maing.PlayerClanName }
    };
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.IsVisible = true;
    roomOptions.IsOpen = true;
    roomOptions.MaxPlayers = (byte)2;
    roomOptions.CustomRoomPropertiesForLobby = LobbyOptions;
    roomOptions.CustomRoomProperties = customProperties;
    PhotonNetwork.JoinOrCreateRoom(roommapname, roomOptions, TypedLobby.Default);
     
  41. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    You should be able to do this with the SQL Lobby Type.

    Per room, you'd reserve a property as "clan". The random matchmaking for the SQL Lobby can contain a where-clause (filter), so it's easy to avoid the rooms with "my clan" as clan property.
    Details to keep in mind:
    The SQL Lobby uses pre-defined column-names (for technical reasons): C0, C1, ... C9 for values that can be used in the where-clause (filter). So your "clan" property will be one of those pre-defined columns. That means the filter would look similar to "C0 != "+myClan.
    Despite the fixed naming, you have to let the server know the CustomRoomPropertiesForLobby when you create a room.
    See the docs for the SQL Lobby. Hope that helps.
     
    Wothanar likes this.
  42. badotter

    badotter

    Joined:
    Mar 29, 2013
    Posts:
    19
    Hi Tobiass,

    Quick question: is there any way in Photon to change the ownership of an object? My situation is that I have a multiplayer environment, with human characters and vehicles. I spawn the vehicles on the master client, but I want any client to be able to jump in one. However this means I need that client to be able to use their inputs to drive it around, and I'd like to make this client the owner of the vehicle now so that Photon can send transform updates from it to the rest of the clients, instead of taking on the lag of sending my inputs to the master client and getting position updates back from there.

    Possible?
     
  43. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    See the RequestOwnship and TransferOwnership methods of PhotonView.

    https://doc-api.photonengine.com/en/pun/v2/class_photon_1_1_pun_1_1_photon_view.html
     
    badotter likes this.
  44. badotter

    badotter

    Joined:
    Mar 29, 2013
    Posts:
    19
    AH, thank you sir!
     
  45. Wothanar

    Wothanar

    Joined:
    Sep 2, 2016
    Posts:
    122
    Hi @tobiass how can i add C0 and C1 in filter coz i need map to be in filter too but now i cant figure out how to add the two variables filter can you help me this would be the last thing i need thanks !
     
  46. Wothanar

    Wothanar

    Joined:
    Sep 2, 2016
    Posts:
    122
    nvm i think i got it... i think should work now :


    MainGui maing = FindObjectOfType<MainGui>();
    TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby);
    string sqlLobbyFilter = "C0 != " + maing.PlayerClanName + " AND C1 = " + roommapname;
    PhotonNetwork.JoinRandomRoom(null, 2, MatchmakingMode.RandomMatching, sqlLobby, sqlLobbyFilter);
     
  47. Wothanar

    Wothanar

    Joined:
    Sep 2, 2016
    Posts:
    122
    then i add this on the part when its fail join ... @tobiass what you think it should work right? :D

    public virtual void OnPhotonRandomJoinFailed()
    {
    Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
    if (PhotonNetwork.offlineMode == false)
    {
    if (masterC.batallaclan == false)
    {
    PhotonNetwork.JoinOrCreateRoom(roommapname, new RoomOptions() { MaxPlayers = 5 }, null);
    }
    else
    {
    MainGui maing = FindObjectOfType<MainGui>();
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.MaxPlayers = 2;
    // in this example, C0 might be 0 or 1 for the two (fictional) game modes
    roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "C0", maing.PlayerClanName }, { "C1", roommapname } };
    roomOptions.CustomRoomPropertiesForLobby = new string[] { "C0","C1" }; // this makes "C0" available in the lobby
    TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby);// let's create this room in SqlLobby "myLobby" explicitly
    PhotonNetwork.CreateRoom(roommapname, roomOptions, sqlLobby);
    }
    }
    else
    {
    PhotonNetwork.CreateRoom(roommapname, new RoomOptions() { MaxPlayers = 1 }, null);
    }
    }
     
  48. Wothanar

    Wothanar

    Joined:
    Sep 2, 2016
    Posts:
    122
  49. Wothanar

    Wothanar

    Joined:
    Sep 2, 2016
    Posts:
    122
    i get it at the end i think this is working fine , i test it and it works as i want thank you tobiass for your help ! :D

    here is the code maby its of nice use to someone...

    public virtual void OnConnectedToMaster()
    {
    Debug.Log("OnConnectedToMaster() was called by PUN. Now this client is connected and could join a room. Calling: PhotonNetwork.JoinRandomRoom();");
    if (PhotonNetwork.offlineMode == false) {
    if (masterC.batallaclan == false) {
    PhotonNetwork.JoinOrCreateRoom(roommapname, new RoomOptions() { MaxPlayers = 5 }, null);
    }
    else
    {
    MainGui maing = FindObjectOfType<MainGui>();
    TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby); // same as above
    string sqlLobbyFilter = "C1 = \""+ roommapname + "\" AND C0 != \"" + maing.PlayerClanName + "\"";
    PhotonNetwork.JoinRandomRoom(null, 2, MatchmakingMode.RandomMatching, sqlLobby, sqlLobbyFilter);
    // "C5 = \"Map2\" AND C2 > 10 AND C3 < 20"
    }
    }
    else
    {
    PhotonNetwork.JoinOrCreateRoom(roommapname, new RoomOptions() { MaxPlayers = 1 }, null);
    }
    }

    public virtual void OnJoinedLobby()
    {
    Debug.Log("OnJoinedLobby(). This client is connected and does get a room-list, which gets stored as PhotonNetwork.GetRoomList(). This script now calls: PhotonNetwork.JoinRandomRoom();");
    //PhotonNetwork.JoinRoom(roommapname);
    }

    public virtual void OnPhotonRandomJoinFailed()
    {
    Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
    if (PhotonNetwork.offlineMode == false)
    {
    if (masterC.batallaclan == false)
    {
    PhotonNetwork.JoinOrCreateRoom(roommapname, new RoomOptions() { MaxPlayers = 5 }, null);
    }
    else
    {
    MainGui maing = FindObjectOfType<MainGui>();
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.MaxPlayers = 2;
    // in this example, C0 might be 0 or 1 for the two (fictional) game modes
    roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "C0", maing.PlayerClanName }, { "C1", roommapname } };
    roomOptions.CustomRoomPropertiesForLobby = new string[] { "C0","C1" }; // this makes "C0" available in the lobby
    TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby);// let's create this room in SqlLobby "myLobby" explicitly
    PhotonNetwork.CreateRoom(null, roomOptions, sqlLobby);
    }
    }
    else
    {
    PhotonNetwork.CreateRoom(roommapname, new RoomOptions() { MaxPlayers = 1 }, null);
    }
    }
     
  50. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    166
    I just downloaded Pun 2 free from the asset store and imported it into my project. I am using Unity 2018.3.13f1

    I am getting a whole bunch of errors. all seeming to stem from the demo scenes
    this is one of the errors
    Assets\Photon\PhotonUnityNetworking\Demos\DemoAsteroids\Scripts\Game\AsteroidsGameManager.cs(128,30): error CS0721: 'Player': static types cannot be used as parameters

    upload_2019-5-2_22-30-21.png