// ---------------------------------------------------------------------------- // // PhotonNetwork Framework for Unity - Copyright (C) 2011 Exit Games GmbH // // // // // developer@exitgames.com // ---------------------------------------------------------------------------- #pragma warning disable 1587 /// \file /// Wraps up several of the commonly used enumerations. #pragma warning restore 1587 using System; using ExitGames.Client.Photon; /// /// This enum defines the set of MonoMessages Photon Unity Networking is using as callbacks. Implemented by PunBehaviour. /// /// /// Much like "Update()" in Unity, PUN will call methods in specific situations. /// Often, these methods are triggered when network operations complete (example: when joining a room). /// /// All those methods are defined and described in this enum and implemented by PunBehaviour /// (which makes it easy to implement them as override). /// /// Each entry is the name of such a method and the description tells you when it gets used by PUN. /// /// Make sure to read the remarks per entry as some methods have optional parameters. /// /// \ingroup publicApi public enum PhotonNetworkingMessage { /// /// Called when the initial connection got established but before you can use the server. OnJoinedLobby() or OnConnectedToMaster() are called when PUN is ready. /// /// /// This callback is only useful to detect if the server can be reached at all (technically). /// Most often, it's enough to implement OnFailedToConnectToPhoton() and OnDisconnectedFromPhoton(). /// /// OnJoinedLobby() or OnConnectedToMaster() are called when PUN is ready. /// /// When this is called, the low level connection is established and PUN will send your AppId, the user, etc in the background. /// This is not called for transitions from the masterserver to game servers. /// /// Example: void OnConnectedToPhoton() { ... } /// OnConnectedToPhoton, /// /// Called when the local user/client left a room. /// /// /// When leaving a room, PUN brings you back to the Master Server. /// Before you can use lobbies and join or create rooms, OnJoinedLobby() or OnConnectedToMaster() will get called again. /// /// Example: void OnLeftRoom() { ... } /// OnLeftRoom, /// /// Called after switching to a new MasterClient when the current one leaves. /// /// /// This is not called when this client enters a room. /// The former MasterClient is still in the player list when this method get called. /// /// Example: void OnMasterClientSwitched(PhotonPlayer newMasterClient) { ... } /// OnMasterClientSwitched, /// /// Called when a CreateRoom() call failed. Optional parameters provide ErrorCode and message. /// /// /// Most likely because the room name is already in use (some other client was faster than you). /// PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational. /// /// Example: void OnPhotonCreateRoomFailed() { ... } /// /// Example: void OnPhotonCreateRoomFailed(object[] codeAndMsg) { // codeAndMsg[0] is short ErrorCode. codeAndMsg[1] is string debug msg. } /// OnPhotonCreateRoomFailed, /// /// Called when a JoinRoom() call failed. Optional parameters provide ErrorCode and message. /// /// /// Most likely error is that the room does not exist or the room is full (some other client was faster than you). /// PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational. /// /// Example: void OnPhotonJoinRoomFailed() { ... } /// /// Example: void OnPhotonJoinRoomFailed(object[] codeAndMsg) { // codeAndMsg[0] is short ErrorCode. codeAndMsg[1] is string debug msg. } /// OnPhotonJoinRoomFailed, /// /// Called when this client created a room and entered it. OnJoinedRoom() will be called as well. /// /// /// This callback is only called on the client which created a room (see PhotonNetwork.CreateRoom). /// /// As any client might close (or drop connection) anytime, there is a chance that the /// creator of a room does not execute OnCreatedRoom. /// /// If you need specific room properties or a "start signal", it is safer to implement /// OnMasterClientSwitched() and to make the new MasterClient check the room's state. /// /// Example: void OnCreatedRoom() { ... } /// OnCreatedRoom, /// /// Called on entering a lobby on the Master Server. The actual room-list updates will call OnReceivedRoomListUpdate(). /// /// /// Note: When PhotonNetwork.autoJoinLobby is false, OnConnectedToMaster() will be called and the room list won't become available. /// /// While in the lobby, the roomlist is automatically updated in fixed intervals (which you can't modify). /// The room list gets available when OnReceivedRoomListUpdate() gets called after OnJoinedLobby(). /// /// Example: void OnJoinedLobby() { ... } /// OnJoinedLobby, /// /// Called after leaving a lobby. /// /// /// When you leave a lobby, [CreateRoom](@ref PhotonNetwork.CreateRoom) and [JoinRandomRoom](@ref PhotonNetwork.JoinRandomRoom) /// automatically refer to the default lobby. /// /// Example: void OnLeftLobby() { ... } /// OnLeftLobby, /// /// Called after disconnecting from the Photon server. /// /// /// In some cases, other callbacks are called before OnDisconnectedFromPhoton is called. /// Examples: OnConnectionFail() and OnFailedToConnectToPhoton(). /// /// Example: void OnDisconnectedFromPhoton() { ... } /// OnDisconnectedFromPhoton, /// /// Called when something causes the connection to fail (after it was established), followed by a call to OnDisconnectedFromPhoton(). /// /// /// If the server could not be reached in the first place, OnFailedToConnectToPhoton is called instead. /// The reason for the error is provided as StatusCode. /// /// Example: void OnConnectionFail(DisconnectCause cause) { ... } /// OnConnectionFail, /// /// Called if a connect call to the Photon server failed before the connection was established, followed by a call to OnDisconnectedFromPhoton(). /// /// /// OnConnectionFail only gets called when a connection to a Photon server was established in the first place. /// /// Example: void OnFailedToConnectToPhoton(DisconnectCause cause) { ... } /// OnFailedToConnectToPhoton, /// /// Called for any update of the room-listing while in a lobby (PhotonNetwork.insideLobby) on the Master Server. /// /// /// PUN provides the list of rooms by PhotonNetwork.GetRoomList().
/// Each item is a RoomInfo which might include custom properties (provided you defined those as lobby-listed when creating a room). /// /// Not all types of lobbies provide a listing of rooms to the client. Some are silent and specialized for server-side matchmaking. /// /// Example: void OnReceivedRoomListUpdate() { ... } ///
OnReceivedRoomListUpdate, /// /// Called when entering a room (by creating or joining it). Called on all clients (including the Master Client). /// /// /// This method is commonly used to instantiate player characters. /// If a match has to be started "actively", you can instead call an [PunRPC](@ref PhotonView.RPC) triggered by a user's button-press or a timer. /// /// When this is called, you can usually already access the existing players in the room via PhotonNetwork.playerList. /// Also, all custom properties should be already available as Room.customProperties. Check Room.playerCount to find out if /// enough players are in the room to start playing. /// /// Example: void OnJoinedRoom() { ... } /// OnJoinedRoom, /// /// Called when a remote player entered the room. This PhotonPlayer is already added to the playerlist at this time. /// /// /// If your game starts with a certain number of players, this callback can be useful to check the /// Room.playerCount and find out if you can start. /// /// Example: void OnPhotonPlayerConnected(PhotonPlayer newPlayer) { ... } /// OnPhotonPlayerConnected, /// /// Called when a remote player left the room. This PhotonPlayer is already removed from the playerlist at this time. /// /// /// When your client calls PhotonNetwork.leaveRoom, PUN will call this method on the remaining clients. /// When a remote client drops connection or gets closed, this callback gets executed. after a timeout /// of several seconds. /// /// Example: void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) { ... } /// OnPhotonPlayerDisconnected, /// /// Called after a JoinRandom() call failed. Optional parameters provide ErrorCode and message. /// /// /// Most likely all rooms are full or no rooms are available. /// When using multiple lobbies (via JoinLobby or TypedLobby), another lobby might have more/fitting rooms. /// PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational. /// /// Example: void OnPhotonRandomJoinFailed() { ... } /// /// Example: void OnPhotonRandomJoinFailed(object[] codeAndMsg) { // codeAndMsg[0] is short ErrorCode. codeAndMsg[1] is string debug msg. } /// OnPhotonRandomJoinFailed, /// /// Called after the connection to the master is established and authenticated but only when PhotonNetwork.autoJoinLobby is false. /// /// /// If you set PhotonNetwork.autoJoinLobby to true, OnJoinedLobby() will be called instead of this. /// /// You can join rooms and create them even without being in a lobby. The default lobby is used in that case. /// The list of available rooms won't become available unless you join a lobby via PhotonNetwork.joinLobby. /// /// Example: void OnConnectedToMaster() { ... } /// OnConnectedToMaster, /// /// Implement to customize the data a PhotonView regularly synchronizes. Called every 'network-update' when observed by PhotonView. /// /// /// This method will be called in scripts that are assigned as Observed component of a PhotonView. /// PhotonNetwork.sendRateOnSerialize affects how often this method is called. /// PhotonNetwork.sendRate affects how often packages are sent by this client. /// /// Implementing this method, you can customize which data a PhotonView regularly synchronizes. /// Your code defines what is being sent (content) and how your data is used by receiving clients. /// /// Unlike other callbacks, OnPhotonSerializeView only gets called when it is assigned /// to a PhotonView as PhotonView.observed script. /// /// To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the /// client that controls a PhotonView (PhotonStream.isWriting == true) and in "reading mode" on the /// remote clients that just receive that the controlling client sends. /// /// If you skip writing any value into the stream, PUN will skip the update. Used carefully, this can /// conserve bandwidth and messages (which have a limit per room/second). /// /// Note that OnPhotonSerializeView is not called on remote clients when the sender does not send /// any update. This can't be used as "x-times per second Update()". /// /// Example: void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { ... } /// OnPhotonSerializeView, /// /// Called on all scripts on a GameObject (and children) that have been Instantiated using PhotonNetwork.Instantiate. /// /// /// PhotonMessageInfo parameter provides info about who created the object and when (based off PhotonNetworking.time). /// /// Example: void OnPhotonInstantiate(PhotonMessageInfo info) { ... } /// OnPhotonInstantiate, /// /// Because the concurrent user limit was (temporarily) reached, this client is rejected by the server and disconnecting. /// /// /// When this happens, the user might try again later. You can't create or join rooms in OnPhotonMaxCcuReached(), cause the client will be disconnecting. /// You can raise the CCU limits with a new license (when you host yourself) or extended subscription (when using the Photon Cloud). /// The Photon Cloud will mail you when the CCU limit was reached. This is also visible in the Dashboard (webpage). /// /// Example: void OnPhotonMaxCccuReached() { ... } /// OnPhotonMaxCccuReached, /// /// Called when a room's custom properties changed. The propertiesThatChanged contains all that was set via Room.SetCustomProperties. /// /// /// Since v1.25 this method has one parameter: Hashtable propertiesThatChanged. /// Changing properties must be done by Room.SetCustomProperties, which causes this callback locally, too. /// /// Example: void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged) { ... } /// OnPhotonCustomRoomPropertiesChanged, /// /// Called when custom player-properties are changed. Player and the changed properties are passed as object[]. /// /// /// Since v1.25 this method has one parameter: object[] playerAndUpdatedProps, which contains two entries.
/// [0] is the affected PhotonPlayer.
/// [1] is the Hashtable of properties that changed.
/// /// We are using a object[] due to limitations of Unity's GameObject.SendMessage (which has only one optional parameter). /// /// Changing properties must be done by PhotonPlayer.SetCustomProperties, which causes this callback locally, too. /// /// Example:
    /// void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) {
    ///     PhotonPlayer player = playerAndUpdatedProps[0] as PhotonPlayer;
    ///     Hashtable props = playerAndUpdatedProps[1] as Hashtable;
    ///     //...
    /// }
///
OnPhotonPlayerPropertiesChanged, /// /// Called when the server sent the response to a FindFriends request and updated PhotonNetwork.Friends. /// /// /// The friends list is available as PhotonNetwork.Friends, listing name, online state and /// the room a user is in (if any). /// /// Example: void OnUpdatedFriendList() { ... } /// OnUpdatedFriendList, /// /// Called when the custom authentication failed. Followed by disconnect! /// /// /// Custom Authentication can fail due to user-input, bad tokens/secrets. /// If authentication is successful, this method is not called. Implement OnJoinedLobby() or OnConnectedToMaster() (as usual). /// /// During development of a game, it might also fail due to wrong configuration on the server side. /// In those cases, logging the debugMessage is very important. /// /// Unless you setup a custom authentication service for your app (in the [Dashboard](https://www.photonengine.com/dashboard)), /// this won't be called! /// /// Example: void OnCustomAuthenticationFailed(string debugMessage) { ... } /// OnCustomAuthenticationFailed, /// /// Called when your Custom Authentication service responds with additional data. /// /// /// Custom Authentication services can include some custom data in their response. /// When present, that data is made available in this callback as Dictionary. /// While the keys of your data have to be strings, the values can be either string or a number (in Json). /// You need to make extra sure, that the value type is the one you expect. Numbers become (currently) int64. /// /// Example: void OnCustomAuthenticationResponse(Dictionary<string, object> data) { ... } /// /// OnCustomAuthenticationResponse, /// /// Called by PUN when the response to a WebRPC is available. See PhotonNetwork.WebRPC. /// /// /// Important: The response.ReturnCode is 0 if Photon was able to reach your web-service. /// The content of the response is what your web-service sent. You can create a WebResponse instance from it. /// Example: WebRpcResponse webResponse = new WebRpcResponse(operationResponse); /// /// Please note: Class OperationResponse is in a namespace which needs to be "used": /// using ExitGames.Client.Photon; // includes OperationResponse (and other classes) /// /// The OperationResponse.ReturnCode by Photon is: /// 0 for "OK" /// -3 for "Web-Service not configured" (see Dashboard / WebHooks) /// -5 for "Web-Service does now have RPC path/name" (at least for Azure) /// /// Example: void OnWebRpcResponse(OperationResponse response) { ... } /// OnWebRpcResponse, /// /// Called when another player requests ownership of a PhotonView from you (the current owner). /// /// /// The parameter viewAndPlayer contains: /// /// PhotonView view = viewAndPlayer[0] as PhotonView; /// /// PhotonPlayer requestingPlayer = viewAndPlayer[1] as PhotonPlayer; /// /// void OnOwnershipRequest(object[] viewAndPlayer) {} // OnOwnershipRequest, /// /// Called when the Master Server sent an update for the Lobby Statistics, updating PhotonNetwork.LobbyStatistics. /// /// /// This callback has two preconditions: /// EnableLobbyStatistics must be set to true, before this client connects. /// And the client has to be connected to the Master Server, which is providing the info about lobbies. /// OnLobbyStatisticsUpdate, } /// Used to define the level of logging output created by the PUN classes. Either log errors, info (some more) or full. /// \ingroup publicApi public enum PhotonLogLevel { /// Show only errors. Minimal output. Note: Some might be "runtime errors" which you have to expect. ErrorsOnly, /// Logs some of the workflow, calls and results. Informational, /// Every available log call gets into the console/log. Only use for debugging. Full } /// Enum of "target" options for RPCs. These define which remote clients get your RPC call. /// \ingroup publicApi public enum PhotonTargets { /// Sends the RPC to everyone else and executes it immediately on this client. Player who join later will not execute this RPC. All, /// Sends the RPC to everyone else. This client does not execute the RPC. Player who join later will not execute this RPC. Others, /// Sends the RPC to MasterClient only. Careful: The MasterClient might disconnect before it executes the RPC and that might cause dropped RPCs. MasterClient, /// Sends the RPC to everyone else and executes it immediately on this client. New players get the RPC when they join as it's buffered (until this client leaves). AllBuffered, /// Sends the RPC to everyone. This client does not execute the RPC. New players get the RPC when they join as it's buffered (until this client leaves). OthersBuffered, /// Sends the RPC to everyone (including this client) through the server. /// /// This client executes the RPC like any other when it received it from the server. /// Benefit: The server's order of sending the RPCs is the same on all clients. /// AllViaServer, /// Sends the RPC to everyone (including this client) through the server and buffers it for players joining later. /// /// This client executes the RPC like any other when it received it from the server. /// Benefit: The server's order of sending the RPCs is the same on all clients. /// AllBufferedViaServer } /// Currently available Photon Cloud regions as enum. /// /// This is used in PhotonNetwork.ConnectToRegion. /// public enum CloudRegionCode { /// European servers in Amsterdam. eu = 0, /// US servers (East Coast). us = 1, /// Asian servers in Singapore. asia = 2, /// Japanese servers in Tokyo. jp = 3, /// Australian servers in Melbourne. au = 5, ///USA West, San José, usw usw = 6, ///South America , Sao Paulo, sa sa = 7, ///Canada East, Montreal, cae cae = 8, ///South Korea, Seoul, kr kr = 9, ///India, Chennai, in @in = 10, /// No region selected. none = 4 }; /// /// Available regions as enum of flags. To be used as "enabled" flags for Best Region pinging. /// /// Note that these enum values skip CloudRegionCode.none and their values are in strict order (power of 2). [Flags] public enum CloudRegionFlag { eu = 1 << 0, us = 1 << 1, asia = 1 << 2, jp = 1 << 3, au = 1 << 4, usw = 1 << 5, sa = 1 << 6, cae = 1 << 7, kr = 1 << 8, @in = 1 << 9, }; /// /// High level connection state of the client. Better use the more detailed . /// public enum ConnectionState { Disconnected, Connecting, Connected, Disconnecting, InitializingApplication } /// /// Defines how the communication gets encrypted. /// public enum EncryptionMode { /// /// This is the default encryption mode: Messages get encrypted only on demand (when you send operations with the "encrypt" parameter set to true). /// PayloadEncryption, /// /// With this encryption mode for UDP, the connection gets setup and all further datagrams get encrypted almost entirely. On-demand message encryption (like in PayloadEncryption) is skipped. /// /// /// This mode requires AuthOnce or AuthOnceWss as AuthMode! /// DatagramEncryption = 10, } public static class EncryptionDataParameters { /// /// Key for encryption mode /// public const byte Mode = 0; /// /// Key for first secret /// public const byte Secret1 = 1; /// /// Key for second secret /// public const byte Secret2 = 2; }