public static SendMonoMessage ( PhotonNetworkingMessage methodString ) : void | ||
methodString | PhotonNetworkingMessage | |
return | void |
public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false) { if (propertiesToSet == null) { return; } Hashtable hashtable = propertiesToSet.StripToStringKeys(); Hashtable hashtable2 = expectedValues.StripToStringKeys(); bool flag = hashtable2 == null || hashtable2.get_Count() == 0; bool flag2 = this.actorID > 0 && !PhotonNetwork.offlineMode; if (flag) { this.CustomProperties.Merge(hashtable); this.CustomProperties.StripKeysWithNullValues(); } if (flag2) { PhotonNetwork.networkingPeer.OpSetPropertiesOfActor(this.actorID, hashtable, hashtable2, webForward); } if (!flag2 || flag) { this.InternalCacheProperties(hashtable); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, new object[] { this, hashtable }); } }
/// <summary> /// Updates the current room's Custom Properties with new/updated key-values. /// </summary> /// <remarks> /// Custom Properties are a key-value set (Hashtable) which is available to all players in a room. /// They can relate to the room or individual players and are useful when only the current value /// of something is of interest. For example: The map of a room. /// All keys must be strings. /// /// The Room and the PhotonPlayer class both have SetCustomProperties methods. /// Also, both classes offer access to current key-values by: customProperties. /// /// Always use SetCustomProperties to change values. /// To reduce network traffic, set only values that actually changed. /// New properties are added, existing values are updated. /// Other values will not be changed, so only provide values that changed or are new. /// /// To delete a named (custom) property of this room, use null as value. /// /// Locally, SetCustomProperties will update it's cache without delay. /// Other clients are updated through Photon (the server) with a fitting operation. /// /// <b>Check and Swap</b> /// /// SetCustomProperties have the option to do a server-side Check-And-Swap (CAS): /// Values only get updated if the expected values are correct. /// The expectedValues can be different key/values than the propertiesToSet. So you can /// check some key and set another key's value (if the check succeeds). /// /// If the client's knowledge of properties is wrong or outdated, it can't set values with CAS. /// This can be useful to keep players from concurrently setting values. For example: If all players /// try to pickup some card or item, only one should get it. With CAS, only the first SetProperties /// gets executed server-side and any other (sent at the same time) fails. /// /// The server will broadcast successfully changed values and the local "cache" of customProperties /// only gets updated after a roundtrip (if anything changed). /// /// You can do a "webForward": Photon will send the changed properties to a WebHook defined /// for your application. /// /// <b>OfflineMode</b> /// /// While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored. /// In OfflineMode, the local customProperties values are immediately updated (without the roundtrip). /// </remarks> /// <param name="propertiesToSet">The new properties to be set. </param> /// <param name="expectedValues">At least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.</param> /// <param name="webForward">Set to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.</param> public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false) { if (propertiesToSet == null) { return; } Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable; // no expected values -> set and callback bool noCas = customPropsToCheck == null || customPropsToCheck.Count == 0; if (!PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(customProps, customPropsToCheck, webForward); } if (PhotonNetwork.offlineMode || noCas) { this.InternalCacheProperties(customProps); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, customProps); } }
public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby) { if (offlineMode) { if (offlineModeRoom != null) { Debug.LogError("JoinOrCreateRoom failed. In offline mode you still have to leave a room to enter another."); return(false); } offlineModeRoom = new Room(roomName, roomOptions); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom, 0, new object[0]); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, 0, new object[0]); return(true); } if ((networkingPeer.server != ServerConnection.MasterServer) || !connectedAndReady) { Debug.LogError("JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster."); return(false); } if (string.IsNullOrEmpty(roomName)) { Debug.LogError("JoinOrCreateRoom failed. A roomname is required. If you don't know one, how will you join?"); return(false); } return(networkingPeer.OpJoinRoom(roomName, roomOptions, typedLobby, true)); }
public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false) { if (propertiesToSet == null) { return; } Hashtable stringKeys1 = ((IDictionary)propertiesToSet).StripToStringKeys(); Hashtable stringKeys2 = ((IDictionary)expectedValues).StripToStringKeys(); bool flag = stringKeys2 == null || ((Dictionary <object, object>)stringKeys2).Count == 0; if (flag) { ((IDictionary)this.CustomProperties).Merge((IDictionary)stringKeys1); ((IDictionary)this.CustomProperties).StripKeysWithNullValues(); } if (!PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(stringKeys1, stringKeys2, webForward); } if (!PhotonNetwork.offlineMode && !flag) { return; } this.InternalCacheProperties(stringKeys1); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, (object)stringKeys1); }
public bool Handle() { IEnumerator <DictionaryEntry> enumerator2 = roomList.GetEnumerator(); try { while (enumerator2.MoveNext()) { DictionaryEntry current = enumerator2.Current; string roomName = (string)current.Key; RoomInfo info = new RoomInfo(roomName, (ExitGames.Client.Photon.Hashtable)current.Value); if (info.RemovedFromList) { NetworkingPeer.mGameList.Remove(roomName); } else { NetworkingPeer.mGameList[roomName] = info; } } } finally { if (enumerator2 == null) { } enumerator2.Dispose(); } PhotonNetwork.networkingPeer.mGameListCopy = new RoomInfo[NetworkingPeer.mGameList.Count]; NetworkingPeer.mGameList.Values.CopyTo(PhotonNetwork.networkingPeer.mGameListCopy, 0); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnReceivedRoomListUpdate, new object[0]); return(true); }
/// <summary> /// Updates the this player's Custom Properties with new/updated key-values. /// </summary> /// <remarks> /// Custom Properties are a key-value set (Hashtable) which is available to all players in a room. /// They can relate to the room or individual players and are useful when only the current value /// of something is of interest. For example: The map of a room. /// All keys must be strings. /// /// The Room and the PhotonPlayer class both have SetCustomProperties methods. /// Also, both classes offer access to current key-values by: customProperties. /// /// Always use SetCustomProperties to change values. /// To reduce network traffic, set only values that actually changed. /// New properties are added, existing values are updated. /// Other values will not be changed, so only provide values that changed or are new. /// /// To delete a named (custom) property of this room, use null as value. /// /// Locally, SetCustomProperties will update it's cache without delay. /// Other clients are updated through Photon (the server) with a fitting operation. /// /// <b>Check and Swap</b> /// /// SetCustomProperties have the option to do a server-side Check-And-Swap (CAS): /// Values only get updated if the expected values are correct. /// The expectedValues can be different key/values than the propertiesToSet. So you can /// check some key and set another key's value (if the check succeeds). /// /// If the client's knowledge of properties is wrong or outdated, it can't set values with CAS. /// This can be useful to keep players from concurrently setting values. For example: If all players /// try to pickup some card or item, only one should get it. With CAS, only the first SetProperties /// gets executed server-side and any other (sent at the same time) fails. /// /// The server will broadcast successfully changed values and the local "cache" of customProperties /// only gets updated after a roundtrip (if anything changed). /// /// You can do a "webForward": Photon will send the changed properties to a WebHook defined /// for your application. /// /// <b>OfflineMode</b> /// /// While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored. /// In OfflineMode, the local customProperties values are immediately updated (without the roundtrip). /// </remarks> /// <param name="propertiesToSet">The new properties to be set. </param> /// <param name="expectedValues">At least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.</param> /// <param name="webForward">Set to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.</param> public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false) { if (propertiesToSet == null) { return; } Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable; // no expected values -> set and callback bool noCas = customPropsToCheck == null || customPropsToCheck.Count == 0; bool inOnlineRoom = this.actorID > 0 && !PhotonNetwork.offlineMode; if (noCas) { this.CustomProperties.Merge(customProps); this.CustomProperties.StripKeysWithNullValues(); } if (inOnlineRoom) { PhotonNetwork.networkingPeer.OpSetPropertiesOfActor(this.actorID, customProps, customPropsToCheck, webForward); } if (!inOnlineRoom || noCas) { this.InternalCacheProperties(customProps); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, customProps); } }
/// <summary> /// Updates the current room's Custom Properties with new/updated key-values. /// </summary> /// <remarks> /// Custom Properties are a key-value set (Hashtable) which is available to all players in a room. /// They can relate to the room or individual players and are useful when only the current value /// of something is of interest. For example: The map of a room. /// All keys must be strings. /// /// The Room and the PhotonPlayer class both have SetCustomProperties methods. /// Also, both classes offer access to current key-values by: customProperties. /// /// Always use SetCustomProperties to change values. /// To reduce network traffic, set only values that actually changed. /// New properties are added, existing values are updated. /// Other values will not be changed, so only provide values that changed or are new. /// /// To delete a named (custom) property of this room, use null as value. /// /// Locally, SetCustomProperties will update it's cache without delay. /// Other clients are updated through Photon (the server) with a fitting operation. /// /// <b>Check and Swap</b> /// /// SetCustomProperties have the option to do a server-side Check-And-Swap (CAS): /// Values only get updated if the expected values are correct. /// The expectedValues can be different key/values than the propertiesToSet. So you can /// check some key and set another key's value (if the check succeeds). /// /// If the client's knowledge of properties is wrong or outdated, it can't set values with CAS. /// This can be useful to keep players from concurrently setting values. For example: If all players /// try to pickup some card or item, only one should get it. With CAS, only the first SetProperties /// gets executed server-side and any other (sent at the same time) fails. /// /// The server will broadcast successfully changed values and the local "cache" of customProperties /// only gets updated after a roundtrip (if anything changed). /// /// You can do a "webForward": Photon will send the changed properties to a WebHook defined /// for your application. /// /// <b>OfflineMode</b> /// /// While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored. /// In OfflineMode, the local customProperties values are immediately updated (without the roundtrip). /// </remarks> /// <param name="propertiesToSet">The new properties to be set. </param> /// <param name="expectedValues">At least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.</param> /// <param name="webForward">Set to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.</param> public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false) { if (propertiesToSet == null) { return; } Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable; // no expected values -> set and callback bool noCas = customPropsToCheck == null || customPropsToCheck.Count == 0; if (PhotonNetwork.offlineMode || noCas) { this.CustomProperties.Merge(customProps); // the customProps are already stripped to string-keys-only (custom-props keys) this.CustomProperties.StripKeysWithNullValues(); } if (!PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(customProps, customPropsToCheck, webForward); // as the customProps are stripped already, this equals OpSetCustomPropertiesOfRoom() } if (PhotonNetwork.offlineMode || noCas) { NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, customProps); } }
public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false) { if (propertiesToSet == null) { return; } Hashtable hashtable = propertiesToSet.StripToStringKeys(); Hashtable hashtable2 = expectedValues.StripToStringKeys(); bool flag = hashtable2 == null || hashtable2.get_Count() == 0; if (PhotonNetwork.offlineMode || flag) { base.CustomProperties.Merge(hashtable); base.CustomProperties.StripKeysWithNullValues(); } if (!PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(hashtable, hashtable2, webForward); } if (PhotonNetwork.offlineMode || flag) { NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, new object[] { hashtable }); } }
public static bool JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter) { if (offlineMode) { if (offlineModeRoom != null) { Debug.LogError("JoinRandomRoom failed. In offline mode you still have to leave a room to enter another."); return(false); } offlineModeRoom = new Room("offline room", null); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, new object[0]); return(true); } if ((networkingPeer.server == ServerConnection.MasterServer) && connectedAndReady) { Hashtable target = new Hashtable(); target.MergeStringKeys(expectedCustomRoomProperties); if (expectedMaxPlayers > 0) { target[(byte)0xff] = expectedMaxPlayers; } return(networkingPeer.OpJoinRandomRoom(target, 0, null, matchingType, typedLobby, sqlLobbyFilter)); } Debug.LogError("JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster."); return(false); }
public static bool JoinRoom(string roomName, bool createIfNotExists) { if (((connectionStateDetailed == PeerStates.Joining) || (connectionStateDetailed == PeerStates.Joined)) || (connectionStateDetailed == PeerStates.ConnectedToGameserver)) { Debug.LogError("JoinRoom aborted: You can only join a room while not currently connected/connecting to a room."); } else if (room != null) { Debug.LogError("JoinRoom aborted: You are already in a room!"); } else if (roomName == string.Empty) { Debug.LogError("JoinRoom aborted: You must specifiy a room name!"); } else { if (offlineMode) { offlineModeRoom = new Room(roomName, null); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, 0, new object[0]); return(true); } return(networkingPeer.OpJoinRoom(roomName, null, null, createIfNotExists)); } return(false); }
public void SetCustomProperties(Hashtable propertiesToSet, bool broadcast = true) { if (propertiesToSet != null) { customProperties.MergeStringKeys(propertiesToSet); customProperties.StripKeysWithNullValues(); Hashtable actorProperties = propertiesToSet.StripToStringKeys(); if (Id > 0 && !PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(Id, actorProperties, broadcast, 0); } NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, propertiesToSet); } }
public static void CheckPlayersProperties(Hashtable hash, int targetActorNr, PhotonPlayer sender) { NetworkingPeer peer = PhotonNetwork.networkingPeer; if (peer == null || hash == null || hash.Count <= 0) { return; } if (targetActorNr > 0) { PhotonPlayer target = PhotonPlayer.Find(targetActorNr); if (target != null) { Hashtable props = peer.GetActorPropertiesForActorNr(hash, targetActorNr); if (target.IsLocal) { bool needSend = false; if (sender == null || !sender.IsMasterClient) { if (props.ContainsKey(PhotonPlayerProperty.name)) { string checkName = props[PhotonPlayerProperty.name] as string; if (checkName == null || checkName != User.Name.Value) { //TODO: Localize UI.Log.AddLineRaw($"{(sender == null ? "Someone" : $"[{sender.ID}]" + sender.UIName.ToHTMLFormat())} tried to change your name."); props[PhotonPlayerProperty.name] = User.Name.Value; needSend = true; } } if (props.ContainsKey(PhotonPlayerProperty.guildName)) { string checkName = props[PhotonPlayerProperty.guildName] as string; if (checkName == null || checkName != User.AllGuildNames) { //TODO: Localize UI.Log.AddLineRaw($"{(sender == null ? "Someone" : $"[{sender.ID}]" + sender.UIName.ToHTMLFormat())} tried to change your guildname."); props[PhotonPlayerProperty.guildName] = User.AllGuildNames; needSend = true; } } } if (needSend) { target.SetCustomProperties(props); } } target.InternalCacheProperties(props); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, new object[] { target, props }); }
public static bool LeaveRoom() { if (offlineMode) { offlineModeRoom = null; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnLeftRoom, new object[0]); return(true); } if (room == null) { Debug.LogWarning("PhotonNetwork.room is null. You don't have to call LeaveRoom() when you're not in one. State: " + connectionStatesDetailed); } return(networkingPeer.OpLeave()); }
public void SetCustomProperties(Hashtable propertiesToSet, bool broadcast = true) { if (propertiesToSet != null) { base.customProperties.MergeStringKeys(propertiesToSet); base.customProperties.StripKeysWithNullValues(); Hashtable gameProperties = propertiesToSet.StripToStringKeys(); if (!PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(gameProperties, broadcast, 0); } NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, propertiesToSet); } }
public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues) { if (propertiesToSet == null) { return; } if (this.actorID > 0 && !PhotonNetwork.offlineMode) { Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable; PhotonNetwork.networkingPeer.OpSetPropertiesOfActor(this.actorID, customProps, false, 0, customPropsToCheck); } NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, propertiesToSet); }
public void SetCustomProperties(Hashtable propertiesToSet) { if (propertiesToSet != null) { base.customProperties.MergeStringKeys(propertiesToSet); base.customProperties.StripKeysWithNullValues(); Hashtable gameProperties = propertiesToSet.StripToStringKeys(); if (!PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(gameProperties, true, 0); } object[] parameters = new object[] { propertiesToSet }; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, parameters); } }
public void SetCustomProperties(Hashtable propertiesToSet) { if (propertiesToSet != null) { customProperties.MergeStringKeys(propertiesToSet); customProperties.StripKeysWithNullValues(); Hashtable actorProperties = propertiesToSet.StripToStringKeys(); if (actorID > 0) { PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(actorID, actorProperties, true, 0); } object[] parameters = new object[] { this, propertiesToSet }; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, parameters); } }
public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues) { if (propertiesToSet == null) { return; } if (!PhotonNetwork.offlineMode) { Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable; PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(customProps, false, 0, customPropsToCheck); // broadcast is always on for CAS } NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, propertiesToSet); }
public void SetCustomProperties(ExitGames.Client.Photon.Hashtable propertiesToSet) { if (propertiesToSet != null) { this.customProperties.MergeStringKeys(propertiesToSet); this.customProperties.StripKeysWithNullValues(); ExitGames.Client.Photon.Hashtable actorProperties = propertiesToSet.StripToStringKeys(); if ((this.actorID > 0) && !PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(this.actorID, actorProperties, true, 0); } object[] parameters = new object[] { this, propertiesToSet }; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, parameters); toChage(); } }
/// <summary> /// Updates and synchronizes the named properties of this Room with the values of propertiesToSet. /// </summary> /// <remarks> /// Any player can set a Room's properties. Room properties are available until changed, deleted or /// until the last player leaves the room. /// Access them by: Room.CustomProperties (read-only!). /// /// New properties are added, existing values are updated. /// Other values will not be changed, so only provide values that changed or are new. /// To delete a named (custom) property of this room, use null as value. /// Only string-typed keys are applied (everything else is ignored). /// /// Local cache is updated immediately, other clients are updated through Photon with a fitting operation. /// To reduce network traffic, set only values that actually changed. /// </remarks> /// <param name="propertiesToSet">Hashtable of props to udpate, set and sync. See description.</param> public void SetCustomProperties(Hashtable propertiesToSet) { if (propertiesToSet == null) { return; } // merge (delete null-values) this.customProperties.MergeStringKeys(propertiesToSet); // includes a Equals check (simplifying things) this.customProperties.StripKeysWithNullValues(); // send (sync) these new values Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfRoom(customProps, true, 0); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged); }
public bool Handle() { NetworkingPeer.mGameList = new Dictionary <string, RoomInfo>(); foreach (var pair in roomList) { string key = (string)pair.Key; NetworkingPeer.mGameList[key] = new RoomInfo(key, (Hashtable)pair.Value); } PhotonNetwork.networkingPeer.mGameListCopy = new RoomInfo[NetworkingPeer.mGameList.Count]; int i = 0; foreach (RoomInfo info in NetworkingPeer.mGameList.Values) { PhotonNetwork.networkingPeer.mGameListCopy[i++] = info; } NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnReceivedRoomListUpdate, new object[0]); return(true); }
/// <summary> /// Leave the current game room /// </summary> public static void LeaveRoom() { if (room == null) { UnityEngine.Debug.LogError("PhotonNetwork: Error, you cannot leave a room if you're not in a room!"); return; } if (offlineMode) { offlineMode_inRoom = false; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnLeftRoom); } else { networkingPeer.OpLeave(); } }
public static bool LeaveRoom(bool becomeInactive = true) { if (offlineMode) { offlineModeRoom = null; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnLeftRoom); return(true); } if (room == null) { Debug.LogWarning("PhotonNetwork.room is null. You don't have to call LeaveRoom() when you're not in one. State: " + connectionStateDetailed); } else { becomeInactive = becomeInactive && room.playerTtl != 0; } return(networkingPeer.OpLeave(becomeInactive)); }
/// <summary> /// Joins any available room but will fail if none is currently available. /// </summary> /// <remarks> /// If this fails, you can still create a room (and make this available for the next who uses JoinRandomRoom. /// </remarks> public static void JoinRandomRoom() { if (room != null) { Debug.LogError("JoinRandomRoom aborted: You are already in a room!"); } else { if (offlineMode) { offlineMode_inRoom = true; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom); } else { networkingPeer.OpJoinRandom(null); } } }
/// <summary> /// Creates a room with given name but fails if this room is existing already. /// </summary> /// <remarks> /// If you don't want to create a unique room-name, the master server will create one if roomName is null. /// This only works on the master server. The CreateRoom response will contain the room name to use on the /// game server. /// The game server will respond with an error if roomName is null or empty. /// </remarks> /// <param name="roomName">Unique name of the room to create.</param> /// <param name="isVisible">Shows (or hides) this room from the lobby's listing of rooms.</param> /// <param name="isOpen">Allows (or disallows) others to join this room.</param> /// <param name="maxPlayers">Max number of players that can join the room.</param> public static void CreateRoom(string roomName, bool isVisible, bool isOpen, byte maxPlayers) { if (room != null) { Debug.LogError("CreateRoom aborted: You are already in a room!"); } else { if (offlineMode) { offlineMode_inRoom = true; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom); } else { networkingPeer.OpCreateGame(roomName, isVisible, isOpen, (byte)maxPlayers, null); } } }
public bool CheckData(EventData data, PhotonPlayer sender, out string reason) { if (sender != null && !sender.IsLocal) { reason = UI.Log.GetString("senderMustBeNull"); return(false); } reason = ""; ExitGames.Client.Photon.Hashtable properties = (ExitGames.Client.Photon.Hashtable)data[0xf9]; int key = (int)data[254]; if (sender == null) { bool isLocal = PhotonNetwork.networkingPeer.mLocalActor.ID == key; PhotonNetwork.networkingPeer.AddNewPlayer(key, new PhotonPlayer(isLocal, key, properties)); PhotonNetwork.networkingPeer.ResetPhotonViewsOnSerialize(); } if (key != PhotonNetwork.networkingPeer.mLocalActor.ID) { object[] parameters = new object[] { NetworkingPeer.mActors[key] }; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerConnected, parameters); PhotonNetwork.SendChek(NetworkingPeer.mActors[key]); } else { int[] numArray = (int[])data[0xfc]; foreach (int num2 in numArray) { if ((PhotonNetwork.networkingPeer.mLocalActor.ID != num2) && !NetworkingPeer.mActors.ContainsKey(num2)) { PhotonNetwork.networkingPeer.AddNewPlayer(num2, new PhotonPlayer(false, num2, string.Empty)); } } NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, new object[0]); if ((PhotonNetwork.networkingPeer.mLastJoinType == JoinType.JoinOrCreateOnDemand) && (PhotonNetwork.networkingPeer.mLocalActor.ID == 1)) { NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom, new object[0]); } PhotonNetwork.SendChek(); } return(true); }
/// <summary> /// Updates the current room's Custom Properties with new/updated key-values. /// </summary> /// <remarks> /// Custom Properties are a key-value set (Hashtable) which is available to all players in a room. /// They can relate to the room or individual players and are useful when only the current value /// of something is of interest. For example: The map of a room. /// All keys must be strings. /// /// The Room and the PhotonPlayer class both have SetCustomProperties methods. /// Also, both classes offer access to current key-values by: customProperties. /// /// Always use SetCustomProperties to change values. /// To reduce network traffic, set only values that actually changed. /// New properties are added, existing values are updated. /// Other values will not be changed, so only provide values that changed or are new. /// /// To delete a named (custom) property of this room, use null as value. /// /// Locally, SetCustomProperties will update it's cache without delay. /// Other clients are updated through Photon (the server) with a fitting operation. /// /// <b>Check and Swap</b> /// /// SetCustomProperties have the option to do a server-side Check-And-Swap (CAS): /// Values only get updated if the expected values are correct. /// The expectedValues can be different key/values than the propertiesToSet. So you can /// check some key and set another key's value (if the check succeeds). /// /// If the client's knowledge of properties is wrong or outdated, it can't set values with CAS. /// This can be useful to keep players from concurrently setting values. For example: If all players /// try to pickup some card or item, only one should get it. With CAS, only the first SetProperties /// gets executed server-side and any other (sent at the same time) fails. /// /// The server will broadcast successfully changed values and the local "cache" of customProperties /// only gets updated after a roundtrip (if anything changed). /// /// You can do a "webForward": Photon will send the changed properties to a WebHook defined /// for your application. /// /// <b>OfflineMode</b> /// /// While PhotonNetwork.offlineMode is true, the expectedValues and webForward parameters are ignored. /// In OfflineMode, the local customProperties values are immediately updated (without the roundtrip). /// </remarks> /// <param name="propertiesToSet">The new properties to be set. </param> /// <param name="expectedValues">At least one property key/value set to check server-side. Key and value must be correct. Ignored in OfflineMode.</param> /// <param name="webForward">Set to true, to forward the set properties to a WebHook, defined for this app (in Dashboard). Ignored in OfflineMode.</param> public void SetCustomProperties(Hashtable propertiesToSet, Hashtable expectedValues = null, bool webForward = false) { if (propertiesToSet == null) { return; } if (!PhotonNetwork.offlineMode) { Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; Hashtable customPropsToCheck = expectedValues.StripToStringKeys() as Hashtable; PhotonNetwork.networkingPeer.OpSetPropertiesOfRoom(customProps, customPropsToCheck, webForward); } else { Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; this.InternalCacheProperties(customProps); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, customProps); } }
/// <summary> /// Updates and synchronizes the named properties of this Player with the values of propertiesToSet. /// </summary> /// <remarks> /// Any player's properties are available in a Room only and only until the player disconnect or leaves. /// Access any player's properties by: Player.CustomProperties (read-only!) but don't modify that hashtable. /// /// New properties are added, existing values are updated. /// Other values will not be changed, so only provide values that changed or are new. /// To delete a named (custom) property of this player, use null as value. /// Only string-typed keys are applied (everything else is ignored). /// /// Local cache is updated immediately, other players are updated through Photon with a fitting operation. /// To reduce network traffic, set only values that actually changed. /// </remarks> /// <param name="propertiesToSet">Hashtable of props to udpate, set and sync. See description.</param> public void SetCustomProperties(Hashtable propertiesToSet) { if (propertiesToSet == null) { return; } // merge (delete null-values) this.customProperties.MergeStringKeys(propertiesToSet); // includes a Equals check (simplifying things) this.customProperties.StripKeysWithNullValues(); // send (sync) these new values Hashtable customProps = propertiesToSet.StripToStringKeys() as Hashtable; if (this.actorID > 0 && !PhotonNetwork.offlineMode) { PhotonNetwork.networkingPeer.OpSetCustomPropertiesOfActor(this.actorID, customProps); } NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, this, propertiesToSet); }
public static bool CreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby) { if (offlineMode) { if (offlineModeRoom != null) { Debug.LogError("CreateRoom failed. In offline mode you still have to leave a room to enter another."); return(false); } offlineModeRoom = new Room(roomName, roomOptions); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom, 0, new object[0]); NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, 0, new object[0]); return(true); } if ((networkingPeer.server == ServerConnection.MasterServer) && connectedAndReady) { return(networkingPeer.OpCreateGame(roomName, roomOptions, typedLobby)); } Debug.LogError("CreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster."); return(false); }
/// <summary> /// Join room with given title. If no such room exists the room will be created. /// </summary> /// <param name="roomName">Unique name of the room to create.</param> public static void JoinRoom(string roomName) { if (room != null) { Debug.LogError("JoinRoom aborted: You are already in a room!"); } else if (roomName == string.Empty) { Debug.LogError("JoinRoom aborted: You must specifiy a room name!"); } else { if (offlineMode) { offlineMode_inRoom = true; NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom); } else { networkingPeer.OpJoin(roomName); } } }