Config









How do I use Config
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: NamePickGui.cs Copy
38     public void OnGUI()
39     {
40         // Enter-Key handling:
41         if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
42         {
43             if (!string.IsNullOrEmpty(this.InputLine))
44             {
45                 this.StartChat();
46                 return;
47             }
48         }
49
50
51         GUI.skin.label.wordWrap = true;
52         GUILayout.BeginArea(guiCenteredRect);
53
54
55         if (this.chatComponent != null && string.IsNullOrEmpty(this.chatComponent.ChatAppId))
56         {
57             GUILayout.Label("To continue, configure your Chat AppId.\nIt's listed in the Chat Dashboard (online).\nStop play-mode and edit:\nScripts/ChatGUI in the Hierarchy.");
58             if (GUILayout.Button("Open Chat Dashboard"))
59             {
60                 Application.OpenURL("https://www.exitgames.com/en/Chat/Dashboard");
61             }
62             GUILayout.EndArea();
63             return;
64         }
65
66         GUILayout.Label(this.helpText);
67
68         GUILayout.BeginHorizontal();
69         GUI.SetNextControlName("NameInput");
70         this.InputLine = GUILayout.TextField(this.InputLine);
71         if (GUILayout.Button("Connect", GUILayout.ExpandWidth(false)))
72         {
73             this.StartChat();
74         }
75         GUILayout.EndHorizontal();
76
77         GUILayout.EndArea();
78
79
80         GUI.FocusControl("NameInput");
81     }
File name: GUICustomAuth.cs Copy
81     void OnGUI()
82     {
83         if (PhotonNetwork.connected)
84         {
85             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
86             return;
87         }
88
89
90         GUILayout.BeginArea(GuiRect);
91         switch (guiState)
92         {
93             case GuiState.AuthFailed:
94                 GUILayout.Label("Authentication Failed");
95
96                 GUILayout.Space(10);
97
98                 GUILayout.Label("Error message:\n'" + this.authDebugMessage + "'");
99
100                 GUILayout.Space(10);
101
102                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
103                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");
104                 GUILayout.Label("The error message comes from that service and can be customized.");
105
106                 GUILayout.Space(10);
107
108                 GUILayout.BeginHorizontal();
109                 if (GUILayout.Button("Back"))
110                 {
111                     SetStateAuthInput();
112                 }
113                 if (GUILayout.Button("Help"))
114                 {
115                     SetStateAuthHelp();
116                 }
117                 GUILayout.EndHorizontal();
118                 break;
119
120             case GuiState.AuthHelp:
121
122                 GUILayout.Label("By default, any player can connect to Photon.\n'Custom Authentication' can be enabled to reject players without valid user-account.");
123
124                 GUILayout.Label("The actual authentication must be done by a web-service which you host and customize. Example sourcecode for these services is available on the docs page.");
125
126                 GUILayout.Label("For this demo set the Authentication URL in the Dashboard to:\nhttp://photon.webscript.io/auth-demo-equals");
127                 GUILayout.Label("That authentication-service has no user-database. It confirms any user if 'name equals password'.");
128
129                 GUILayout.Space(10);
130                 if (GUILayout.Button("Configure Authentication (Dashboard)"))
131                 {
132                     Application.OpenURL("https://cloud.exitgames.com/dashboard");
133                 }
134                 if (GUILayout.Button("Authentication Docs"))
135                 {
136                     Application.OpenURL("https://doc.exitgames.com/en/pun/current/tutorials/pun-and-facebook-custom-authentication");
137                 }
138
139
140                 GUILayout.Space(10);
141                 if (GUILayout.Button("Back to input"))
142                 {
143                     SetStateAuthInput();
144                 }
145                 break;
146
147             case GuiState.AuthInput:
148
149                 GUILayout.Label("Authenticate yourself");
150
151                 GUILayout.BeginHorizontal();
152                 this.authName = GUILayout.TextField(this.authName, GUILayout.Width(Screen.width/4 - 5));
153                 GUILayout.FlexibleSpace();
154                 this.authToken = GUILayout.TextField(this.authToken, GUILayout.Width(Screen.width/4 - 5));
155                 GUILayout.EndHorizontal();
156
157
158                 if (GUILayout.Button("Authenticate"))
159                 {
160                     PhotonNetwork.AuthValues = new AuthenticationValues();
161                     PhotonNetwork.AuthValues.SetAuthParameters(this.authName, this.authToken);
162                     PhotonNetwork.ConnectUsingSettings("1.0");
163                 }
164
165                 GUILayout.Space(10);
166
167                 if (GUILayout.Button("Help", GUILayout.Width(100)))
168                 {
169                     SetStateAuthHelp();
170                 }
171
172                 break;
173         }
174
175         GUILayout.EndArea();
176     }
File name: HubGui.cs Copy
28     void OnGUI()
29     {
30         GUI.skin = this.Skin;
31         GUILayout.Space(10);
32
33         GUILayout.BeginHorizontal();
34         GUILayout.Space(10);
35         scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(320));
36
37         GUILayout.Label("Basics", m_Headline);
38         if (GUILayout.Button("Demo Boxes", GUILayout.Width(280)))
39         {
40             demoDescription = "Demo Boxes\n\nUses ConnectAndJoinRandom script.\n(joins a random room or creates one)\n\nInstantiates simple prefab.\nSynchronizes positions without smoothing.";
41             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoBoxes-Scene" };
42         }
43         if (GUILayout.Button("Demo Worker", GUILayout.Width(280)))
44         {
45             demoDescription = "Demo Worker\n\nJoins the default lobby and shows existing rooms.\nLets you create or join a room.\nInstantiates an animated character.\nSynchronizes position and animation state of character with smoothing.\nImplements simple in-room Chat via RPC calls.";
46             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoWorker-Scene" };
47         }
48         if (GUILayout.Button("Movement Smoothing", GUILayout.Width(280)))
49         {
50             demoDescription = "Movement Smoothing\n\nUses ConnectAndJoinRandom script.\nShows several basic ways to update positions of remote objects.";
51             demoBtn = new DemoBtn() { Text = "Start", Link = "DemoSynchronization-Scene" };
52         }
53
54         GUILayout.Label("Advanced", m_Headline);
55         if (GUILayout.Button("Ownership Transfer", GUILayout.Width(280)))
56         {
57             demoDescription = "Ownership Transfer\n\nShows how to transfer the ownership of a PhotonView.\nThe owner will send position updates of the GameObject.\nTransfer can be edited per PhotonView and set to Fixed (no transfer), Request (owner has to agree) or Takeover (owner can't object).";
58             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChangeOwner-Scene" };
59             this.webLink = new DemoBtn();
60         }
61         if (GUILayout.Button("Pickup, Teams, Scores", GUILayout.Width(280)))
62         {
63             demoDescription = "Pickup, Teams, Scores\n\nUses ConnectAndJoinRandom script.\nImplements item pickup with RPCs.\nUses Custom Properties for Teams.\nCounts score per player and team.\nUses PhotonPlayer extension methods for easy Custom Property access.";
64             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoPickup-Scene" };
65             this.webLink = new DemoBtn();
66         }
67
68         GUILayout.Label("Feature Demos", m_Headline);
69         if (GUILayout.Button("Chat", GUILayout.Width(280)))
70         {
71             demoDescription = "Chat\n\nUses the Chat API (now part of PUN).\nSimple UI.\nYou can enter any User ID.\nAutomatically subscribes some channels.\nAllows simple commands via text.\n\nRequires configuration of Chat App ID in scene.";
72             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChat-Scene" };
73             this.webLink = new DemoBtn();
74         }
75         if (GUILayout.Button("RPG Movement", GUILayout.Width(280)))
76         {
77             demoDescription = "RPG Movement\n\nDemonstrates how to use the PhotonTransformView component to synchronize position updates smoothly using inter- and extrapolation.\n\nThis demo also shows how to setup a Mecanim Animator to update animations automatically based on received position updates (without sending explicit animation updates).";
78             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoRPGMovement-Scene" };
79             this.webLink = new DemoBtn();
80         }
81         if (GUILayout.Button("Mecanim Animations", GUILayout.Width(280)))
82         {
83             demoDescription = "Mecanim Animations\n\nThis demo shows how to use the PhotonAnimatorView component to easily synchronize Mecanim animations.\n\nIt also demonstrates another feature of the PhotonTransformView component which gives you more control how position updates are inter-/extrapolated by telling the component how fast the object moves and turns using SetSynchronizedValues().";
84             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoMecanim-Scene" };
85             this.webLink = new DemoBtn();
86         }
87         if (GUILayout.Button("2D Game", GUILayout.Width(280)))
88         {
89             demoDescription = "2D Game Demo\n\nSynchronizes animations, positions and physics in a 2D scene.";
90             this.demoBtn = new DemoBtn() { Text = "Start", Link = "Demo2DJumpAndRunWithPhysics-Scene" };
91             this.webLink = new DemoBtn();
92         }
93         if (GUILayout.Button("Friends & Authentication", GUILayout.Width(280)))
94         {
95             demoDescription = "Friends & Authentication\n\nShows connect with or without (server-side) authentication.\n\nAuthentication requires minor server-side setup (in Dashboard).\n\nOnce connected, you can find (made up) friends.\nJoin a room just to see how that gets visible in friends list.";
96             this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoFriends-Scene" };
97             this.webLink = new DemoBtn();
98         }
99
100         GUILayout.Label("Tutorial", m_Headline);
101         if (GUILayout.Button("Marco Polo Tutorial", GUILayout.Width(280)))
102         {
103             demoDescription = "Marco Polo Tutorial\n\nFinal result you could get when you do the Marco Polo Tutorial.\nSlightly modified to be more compatible with this package.";
104             this.demoBtn = new DemoBtn() { Text = "Start", Link = "MarcoPolo-Scene" };
105             this.webLink = new DemoBtn() { Text = "Open Tutorial (www)", Link = "http://tinyurl.com/nmylf44" };
106         }
107         GUILayout.EndScrollView();
108
109         GUILayout.BeginVertical(GUILayout.Width(Screen.width - 345));
110         GUILayout.Label(demoDescription);
111         GUILayout.Space(10);
112         if (!string.IsNullOrEmpty(this.demoBtn.Text))
113         {
114             if (GUILayout.Button(this.demoBtn.Text))
115             {
116                 Application.LoadLevel(this.demoBtn.Link);
117             }
118         }
119         if (!string.IsNullOrEmpty(this.webLink.Text))
120         {
121             if (GUILayout.Button(this.webLink.Text))
122             {
123                 Application.OpenURL(this.webLink.Link);
124             }
125         }
126         GUILayout.EndVertical();
127
128
129         GUILayout.EndHorizontal();
130     }
File name: WorkerMenu.cs Copy
65     public void OnGUI()
66     {
67         if (this.Skin != null)
68         {
69             GUI.skin = this.Skin;
70         }
71
72         if (!PhotonNetwork.connected)
73         {
74             if (PhotonNetwork.connecting)
75             {
76                 GUILayout.Label("Connecting to: " + PhotonNetwork.ServerAddress);
77             }
78             else
79             {
80                 GUILayout.Label("Not connected. Check console output. Detailed connection state: " + PhotonNetwork.connectionStateDetailed + " Server: " + PhotonNetwork.ServerAddress);
81             }
82
83             if (this.connectFailed)
84             {
85                 GUILayout.Label("Connection failed. Check setup and use Setup Wizard to fix configuration.");
86                 GUILayout.Label(String.Format("Server: {0}", new object[] {PhotonNetwork.ServerAddress}));
87                 GUILayout.Label("AppId: " + PhotonNetwork.PhotonServerSettings.AppID);
88
89                 if (GUILayout.Button("Try Again", GUILayout.Width(100)))
90                 {
91                     this.connectFailed = false;
92                     PhotonNetwork.ConnectUsingSettings("0.9");
93                 }
94             }
95
96             return;
97         }
98
99         Rect content = new Rect((Screen.width - WidthAndHeight.x)/2, (Screen.height - WidthAndHeight.y)/2, WidthAndHeight.x, WidthAndHeight.y);
100         GUI.Box(content,"Join or Create Room");
101         GUILayout.BeginArea(content);
102
103         GUILayout.Space(40);
104
105         // Player name
106         GUILayout.BeginHorizontal();
107         GUILayout.Label("Player name:", GUILayout.Width(150));
108         PhotonNetwork.playerName = GUILayout.TextField(PhotonNetwork.playerName);
109         GUILayout.Space(158);
110         if (GUI.changed)
111         {
112             // Save name
113             PlayerPrefs.SetString("playerName", PhotonNetwork.playerName);
114         }
115         GUILayout.EndHorizontal();
116
117         GUILayout.Space(15);
118
119         // Join room by title
120         GUILayout.BeginHorizontal();
121         GUILayout.Label("Roomname:", GUILayout.Width(150));
122         this.roomName = GUILayout.TextField(this.roomName);
123
124         if (GUILayout.Button("Create Room", GUILayout.Width(150)))
125         {
126             PhotonNetwork.CreateRoom(this.roomName, new RoomOptions() { maxPlayers = 10 }, null);
127         }
128
129         GUILayout.EndHorizontal();
130
131         // Create a room (fails if exist!)
132         GUILayout.BeginHorizontal();
133         GUILayout.FlexibleSpace();
134         //this.roomName = GUILayout.TextField(this.roomName);
135         if (GUILayout.Button("Join Room", GUILayout.Width(150)))
136         {
137             PhotonNetwork.JoinRoom(this.roomName);
138         }
139
140         GUILayout.EndHorizontal();
141
142
143         if (!string.IsNullOrEmpty(this.ErrorDialog))
144         {
145             GUILayout.Label(this.ErrorDialog);
146
147             if (timeToClearDialog < Time.time)
148             {
149                 timeToClearDialog = 0;
150                 this.ErrorDialog = "";
151             }
152         }
153
154         GUILayout.Space(15);
155
156         // Join random room
157         GUILayout.BeginHorizontal();
158
159         GUILayout.Label(PhotonNetwork.countOfPlayers + " users are online in " + PhotonNetwork.countOfRooms + " rooms.");
160         GUILayout.FlexibleSpace();
161         if (GUILayout.Button("Join Random", GUILayout.Width(150)))
162         {
163             PhotonNetwork.JoinRandomRoom();
164         }
165
166
167         GUILayout.EndHorizontal();
168
169         GUILayout.Space(15);
170         if (PhotonNetwork.GetRoomList().Length == 0)
171         {
172             GUILayout.Label("Currently no games are available.");
173             GUILayout.Label("Rooms will be listed here, when they become available.");
174         }
175         else
176         {
177             GUILayout.Label(PhotonNetwork.GetRoomList().Length + " rooms available:");
178
179             // Room listing: simply call GetRoomList: no need to fetch/poll whatever!
180             this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
181             foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
182             {
183                 GUILayout.BeginHorizontal();
184                 GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers);
185                 if (GUILayout.Button("Join", GUILayout.Width(150)))
186                 {
187                     PhotonNetwork.JoinRoom(roomInfo.name);
188                 }
189
190                 GUILayout.EndHorizontal();
191             }
192
193             GUILayout.EndScrollView();
194         }
195
196         GUILayout.EndArea();
197     }
File name: LoadbalancingPeer.cs Copy
86         public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
87         {
88             if (this.DebugOut >= DebugLevel.INFO)
89             {
90                 this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
91             }
92
93             Dictionary op = new Dictionary();
94
95             if (!string.IsNullOrEmpty(roomName))
96             {
97                 op[ParameterCode.RoomName] = roomName;
98             }
99             if (lobby != null)
100             {
101                 op[ParameterCode.LobbyName] = lobby.Name;
102                 op[ParameterCode.LobbyType] = (byte)lobby.Type;
103             }
104
105             if (onGameServer)
106             {
107                 if (playerProperties != null && playerProperties.Count > 0)
108                 {
109                     op[ParameterCode.PlayerProperties] = playerProperties;
110                     op[ParameterCode.Broadcast] = true; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties
111                 }
112
113
114                 if (roomOptions == null)
115                 {
116                     roomOptions = new RoomOptions();
117                 }
118
119                 Hashtable gameProperties = new Hashtable();
120                 op[ParameterCode.GameProperties] = gameProperties;
121                 gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
122
123                 gameProperties[GameProperties.IsOpen] = roomOptions.isOpen; // TODO: check default value. dont send this then
124                 gameProperties[GameProperties.IsVisible] = roomOptions.isVisible; // TODO: check default value. dont send this then
125                 gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
126                 if (roomOptions.maxPlayers > 0)
127                 {
128                     gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
129                 }
130                 if (roomOptions.cleanupCacheOnLeave)
131                 {
132                     op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
133                     gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
134                 }
135             }
136
137             // UnityEngine.Debug.Log("CreateGame: " + SupportClass.DictionaryToString(op));
138             return this.OpCustom(OperationCode.CreateGame, op, true);
139         }
File name: LoadbalancingPeer.cs Copy
143         public virtual bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, bool createIfNotExists, Hashtable playerProperties, bool onGameServer)
144         {
145             Dictionary op = new Dictionary();
146
147             if (!string.IsNullOrEmpty(roomName))
148             {
149                 op[ParameterCode.RoomName] = roomName;
150             }
151             if (createIfNotExists)
152             {
153                 op[ParameterCode.CreateIfNotExists] = true;
154                 if (lobby != null)
155                 {
156                     op[ParameterCode.LobbyName] = lobby.Name;
157                     op[ParameterCode.LobbyType] = (byte)lobby.Type;
158                 }
159             }
160
161             if (onGameServer)
162             {
163                 if (playerProperties != null && playerProperties.Count > 0)
164                 {
165                     op[ParameterCode.PlayerProperties] = playerProperties;
166                     op[ParameterCode.Broadcast] = true; // broadcast actor properties
167                 }
168
169
170                 if (createIfNotExists)
171                 {
172                     if (roomOptions == null)
173                     {
174                         roomOptions = new RoomOptions();
175                     }
176
177                     Hashtable gameProperties = new Hashtable();
178                     op[ParameterCode.GameProperties] = gameProperties;
179                     gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
180
181                     gameProperties[GameProperties.IsOpen] = roomOptions.isOpen;
182                     gameProperties[GameProperties.IsVisible] = roomOptions.isVisible;
183                     gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
184                     if (roomOptions.maxPlayers > 0)
185                     {
186                         gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
187                     }
188                     if (roomOptions.cleanupCacheOnLeave)
189                     {
190                         op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
191                         gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
192                     }
193                 }
194             }
195
196             // UnityEngine.Debug.Log("JoinGame: " + SupportClass.DictionaryToString(op));
197             return this.OpCustom(OperationCode.JoinGame, op, true);
198         }
File name: NetworkingPeer.cs Copy
1016     public void OnOperationResponse(OperationResponse operationResponse)
1017     {
1018         if (PhotonNetwork.networkingPeer.State == global::PeerState.Disconnecting)
1019         {
1020             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1021             {
1022                 Debug.Log("OperationResponse ignored while disconnecting. Code: " + operationResponse.OperationCode);
1023             }
1024             return;
1025         }
1026
1027         // extra logging for error debugging (helping developers with a bit of automated analysis)
1028         if (operationResponse.ReturnCode == 0)
1029         {
1030             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1031                 Debug.Log(operationResponse.ToString());
1032         }
1033         else
1034         {
1035             if (operationResponse.ReturnCode == ErrorCode.OperationNotAllowedInCurrentState)
1036             {
1037                 Debug.LogError("Operation " + operationResponse.OperationCode + " could not be executed (yet). Wait for state JoinedLobby or ConnectedToMaster and their callbacks before calling operations. WebRPCs need a server-side configuration. Enum OperationCode helps identify the operation.");
1038             }
1039             else if (operationResponse.ReturnCode == ErrorCode.WebHookCallFailed)
1040             {
1041                 Debug.LogError("Operation " + operationResponse.OperationCode + " failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: " + operationResponse.DebugMessage);
1042             }
1043             else if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1044             {
1045                 Debug.LogError("Operation failed: " + operationResponse.ToStringFull() + " Server: " + this.server);
1046             }
1047         }
1048
1049         // use the "secret" or "token" whenever we get it. doesn't really matter if it's in AuthResponse.
1050         if (operationResponse.Parameters.ContainsKey(ParameterCode.Secret))
1051         {
1052             if (this.CustomAuthenticationValues == null)
1053             {
1054                 this.CustomAuthenticationValues = new AuthenticationValues();
1055                 // this.DebugReturn(DebugLevel.ERROR, "Server returned secret. Created CustomAuthenticationValues.");
1056             }
1057
1058             this.CustomAuthenticationValues.Secret = operationResponse[ParameterCode.Secret] as string;
1059         }
1060
1061         switch (operationResponse.OperationCode)
1062         {
1063             case OperationCode.Authenticate:
1064                 {
1065                     // PeerState oldState = this.State;
1066
1067                     if (operationResponse.ReturnCode != 0)
1068                     {
1069                         if (operationResponse.ReturnCode == ErrorCode.InvalidOperationCode)
1070                         {
1071                             Debug.LogError(string.Format("If you host Photon yourself, make sure to start the 'Instance LoadBalancing' "+ this.ServerAddress));
1072                         }
1073                         else if (operationResponse.ReturnCode == ErrorCode.InvalidAuthentication)
1074                         {
1075                             Debug.LogError(string.Format("The appId this client sent is unknown on the server (Cloud). Check settings. If using the Cloud, check account."));
1076                             SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, DisconnectCause.InvalidAuthentication);
1077                         }
1078                         else if (operationResponse.ReturnCode == ErrorCode.CustomAuthenticationFailed)
1079                         {
1080                             Debug.LogError(string.Format("Custom Authentication failed (either due to user-input or configuration or AuthParameter string format). Calling: OnCustomAuthenticationFailed()"));
1081                             SendMonoMessage(PhotonNetworkingMessage.OnCustomAuthenticationFailed, operationResponse.DebugMessage);
1082                         }
1083                         else
1084                         {
1085                             Debug.LogError(string.Format("Authentication failed: '{0}' Code: {1}", operationResponse.DebugMessage, operationResponse.ReturnCode));
1086                         }
1087
1088                         this.State = global::PeerState.Disconnecting;
1089                         this.Disconnect();
1090
1091                         if (operationResponse.ReturnCode == ErrorCode.MaxCcuReached)
1092                         {
1093                             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1094                                 Debug.LogWarning(string.Format("Currently, the limit of users is reached for this title. Try again later. Disconnecting"));
1095                             SendMonoMessage(PhotonNetworkingMessage.OnPhotonMaxCccuReached);
1096                             SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, DisconnectCause.MaxCcuReached);
1097                         }
1098                         else if (operationResponse.ReturnCode == ErrorCode.InvalidRegion)
1099                         {
1100                             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1101                                 Debug.LogError(string.Format("The used master server address is not available with the subscription currently used. Got to Photon Cloud Dashboard or change URL. Disconnecting."));
1102                             SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, DisconnectCause.InvalidRegion);
1103                         }
1104                         else if (operationResponse.ReturnCode == ErrorCode.AuthenticationTicketExpired)
1105                         {
1106                             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1107                                 Debug.LogError(string.Format("The authentication ticket expired. You need to connect (and authenticate) again. Disconnecting."));
1108                             SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, DisconnectCause.AuthenticationTicketExpired);
1109                         }
1110                         break;
1111                     }
1112                     else
1113                     {
1114                         if (this.server == ServerConnection.NameServer)
1115                         {
1116                             // on the NameServer, authenticate returns the MasterServer address for a region and we hop off to there
1117                             this.MasterServerAddress = operationResponse[ParameterCode.Address] as string;
1118                             this.DisconnectToReconnect();
1119                         }
1120                         else if (this.server == ServerConnection.MasterServer)
1121                         {
1122                             if (PhotonNetwork.autoJoinLobby)
1123                             {
1124                                 this.State = global::PeerState.Authenticated;
1125                                 this.OpJoinLobby(this.lobby);
1126                             }
1127                             else
1128                             {
1129                                 this.State = global::PeerState.ConnectedToMaster;
1130                                 NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnConnectedToMaster);
1131                             }
1132                         }
1133                         else if (this.server == ServerConnection.GameServer)
1134                         {
1135                             this.State = global::PeerState.Joining;
1136
1137                             if (this.mLastJoinType == JoinType.JoinGame || this.mLastJoinType == JoinType.JoinRandomGame || this.mLastJoinType == JoinType.JoinOrCreateOnDemand)
1138                             {
1139                                 // if we just "join" the game, do so. if we wanted to "create the room on demand", we have to send this to the game server as well.
1140                                 this.OpJoinRoom(this.mRoomToGetInto.name, this.mRoomOptionsForCreate, this.mRoomToEnterLobby, this.mLastJoinType == JoinType.JoinOrCreateOnDemand);
1141                             }
1142                             else if (this.mLastJoinType == JoinType.CreateGame)
1143                             {
1144                                 // on the game server, we have to apply the room properties that were chosen for creation of the room, so we use this.mRoomToGetInto
1145                                 this.OpCreateGame(this.mRoomToGetInto.name, this.mRoomOptionsForCreate, this.mRoomToEnterLobby);
1146                             }
1147
1148                             break;
1149                         }
1150                     }
1151                     break;
1152                 }
1153
1154             case OperationCode.GetRegions:
1155                 // Debug.Log("GetRegions returned: " + operationResponse.ToStringFull());
1156
1157                 if (operationResponse.ReturnCode == ErrorCode.InvalidAuthentication)
1158                 {
1159                     Debug.LogError(string.Format("The appId this client sent is unknown on the server (Cloud). Check settings. If using the Cloud, check account."));
1160                     SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, DisconnectCause.InvalidAuthentication);
1161
1162                     this.State = global::PeerState.Disconnecting;
1163                     this.Disconnect();
1164                     return;
1165                 }
1166
1167                 string[] regions = operationResponse[ParameterCode.Region] as string[];
1168                 string[] servers = operationResponse[ParameterCode.Address] as string[];
1169
1170                 if (regions == null || servers == null || regions.Length != servers.Length)
1171                 {
1172                     Debug.LogError("The region arrays from Name Server are not ok. Must be non-null and same length.");
1173                     break;
1174                 }
1175
1176                 this.AvailableRegions = new List(regions.Length);
1177                 for (int i = 0; i < regions.Length; i++)
1178                 {
1179                     string regionCodeString = regions[i];
1180                     if (string.IsNullOrEmpty(regionCodeString))
1181                     {
1182                         continue;
1183                     }
1184                     regionCodeString = regionCodeString.ToLower();
1185
1186                     CloudRegionCode code = Region.Parse(regionCodeString);
1187                     this.AvailableRegions.Add(new Region() { Code = code, HostAndPort = servers[i] });
1188                 }
1189
1190                 // PUN assumes you fetch the name-server's list of regions to ping them
1191                 if (PhotonNetwork.PhotonServerSettings.HostType == ServerSettings.HostingOption.BestRegion)
1192                 {
1193                     PhotonHandler.PingAvailableRegionsAndConnectToBest();
1194                 }
1195                 break;
1196
1197             case OperationCode.CreateGame:
1198                 {
1199                     if (this.server == ServerConnection.GameServer)
1200                     {
1201                         this.GameEnteredOnGameServer(operationResponse);
1202                     }
1203                     else
1204                     {
1205                         if (operationResponse.ReturnCode != 0)
1206                         {
1207                             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1208                                 Debug.LogWarning(string.Format("CreateRoom failed, client stays on masterserver: {0}.", operationResponse.ToStringFull()));
1209
1210                             SendMonoMessage(PhotonNetworkingMessage.OnPhotonCreateRoomFailed);
1211                             break;
1212                         }
1213
1214                         string gameID = (string) operationResponse[ParameterCode.RoomName];
1215                         if (!string.IsNullOrEmpty(gameID))
1216                         {
1217                             // is only sent by the server's response, if it has not been
1218                             // sent with the client's request before!
1219                             this.mRoomToGetInto.name = gameID;
1220                         }
1221
1222                         this.mGameserver = (string)operationResponse[ParameterCode.Address];
1223                         this.DisconnectToReconnect();
1224                     }
1225
1226                     break;
1227                 }
1228
1229             case OperationCode.JoinGame:
1230                 {
1231                     if (this.server != ServerConnection.GameServer)
1232                     {
1233                         if (operationResponse.ReturnCode != 0)
1234                         {
1235                             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1236                                 Debug.Log(string.Format("JoinRoom failed (room maybe closed by now). Client stays on masterserver: {0}. State: {1}", operationResponse.ToStringFull(), this.State));
1237
1238                             SendMonoMessage(PhotonNetworkingMessage.OnPhotonJoinRoomFailed);
1239                             break;
1240                         }
1241
1242                         this.mGameserver = (string)operationResponse[ParameterCode.Address];
1243                         this.DisconnectToReconnect();
1244                     }
1245                     else
1246                     {
1247                         this.GameEnteredOnGameServer(operationResponse);
1248                     }
1249
1250                     break;
1251                 }
1252
1253             case OperationCode.JoinRandomGame:
1254                 {
1255                     // happens only on master. on gameserver, this is a regular join (we don't need to find a random game again)
1256                     // the operation OpJoinRandom either fails (with returncode 8) or returns game-to-join information
1257                     if (operationResponse.ReturnCode != 0)
1258                     {
1259                         if (operationResponse.ReturnCode == ErrorCode.NoRandomMatchFound)
1260                         {
1261                             if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1262                                 Debug.Log("JoinRandom failed: No open game. Calling: OnPhotonRandomJoinFailed() and staying on master server.");
1263                         }
1264                         else if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1265                         {
1266                             Debug.LogWarning(string.Format("JoinRandom failed: {0}.", operationResponse.ToStringFull()));
1267                         }
1268
1269                         SendMonoMessage(PhotonNetworkingMessage.OnPhotonRandomJoinFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
1270                         break;
1271                     }
1272
1273                     string roomName = (string)operationResponse[ParameterCode.RoomName];
1274                     this.mRoomToGetInto.name = roomName;
1275                     this.mGameserver = (string)operationResponse[ParameterCode.Address];
1276                     this.DisconnectToReconnect();
1277                     break;
1278                 }
1279
1280             case OperationCode.JoinLobby:
1281                 this.State = global::PeerState.JoinedLobby;
1282                 this.insideLobby = true;
1283                 SendMonoMessage(PhotonNetworkingMessage.OnJoinedLobby);
1284
1285                 // this.mListener.joinLobbyReturn();
1286                 break;
1287             case OperationCode.LeaveLobby:
1288                 this.State = global::PeerState.Authenticated;
1289                 this.LeftLobbyCleanup(); // will set insideLobby = false
1290                 break;
1291
1292             case OperationCode.Leave:
1293                 this.DisconnectToReconnect();
1294                 break;
1295
1296             case OperationCode.SetProperties:
1297                 // this.mListener.setPropertiesReturn(returnCode, debugMsg);
1298                 break;
1299
1300             case OperationCode.GetProperties:
1301                 {
1302                     Hashtable actorProperties = (Hashtable)operationResponse[ParameterCode.PlayerProperties];
1303                     Hashtable gameProperties = (Hashtable)operationResponse[ParameterCode.GameProperties];
1304                     this.ReadoutProperties(gameProperties, actorProperties, 0);
1305
1306                     // RemoveByteTypedPropertyKeys(actorProperties, false);
1307                     // RemoveByteTypedPropertyKeys(gameProperties, false);
1308                     // this.mListener.getPropertiesReturn(gameProperties, actorProperties, returnCode, debugMsg);
1309                     break;
1310                 }
1311
1312             case OperationCode.RaiseEvent:
1313                 // this usually doesn't give us a result. only if the caching is affected the server will send one.
1314                 break;
1315
1316             case OperationCode.FindFriends:
1317                 bool[] onlineList = operationResponse[ParameterCode.FindFriendsResponseOnlineList] as bool[];
1318                 string[] roomList = operationResponse[ParameterCode.FindFriendsResponseRoomIdList] as string[];
1319
1320                 if (onlineList != null && roomList != null && this.friendListRequested != null && onlineList.Length == this.friendListRequested.Length)
1321                 {
1322                     List friendList = new List(this.friendListRequested.Length);
1323                     for (int index = 0; index < this.friendListRequested.Length; index++)
1324                     {
1325                         FriendInfo friend = new FriendInfo();
1326                         friend.Name = this.friendListRequested[index];
1327                         friend.Room = roomList[index];
1328                         friend.IsOnline = onlineList[index];
1329                         friendList.Insert(index, friend);
1330                     }
1331                     PhotonNetwork.Friends = friendList;
1332                 }
1333                 else
1334                 {
1335                     // any of the lists is null and shouldn't. print a error
1336                     Debug.LogError("FindFriends failed to apply the result, as a required value wasn't provided or the friend list length differed from result.");
1337                 }
1338
1339                 this.friendListRequested = null;
1340                 this.isFetchingFriends = false;
1341                 this.friendListTimestamp = Environment.TickCount;
1342                 if (this.friendListTimestamp == 0)
1343                 {
1344                     this.friendListTimestamp = 1; // makes sure the timestamp is not accidentally 0
1345                 }
1346
1347                 SendMonoMessage(PhotonNetworkingMessage.OnUpdatedFriendList);
1348                 break;
1349
1350             case OperationCode.WebRpc:
1351                 SendMonoMessage(PhotonNetworkingMessage.OnWebRpcResponse, operationResponse);
1352                 break;
1353
1354             default:
1355                 Debug.LogWarning(string.Format("OperationResponse unhandled: {0}", operationResponse.ToString()));
1356                 break;
1357         }
1358
1359         this.externalListener.OnOperationResponse(operationResponse);
1360     }
File name: NetworkingPeer.cs Copy
1411     public void OnStatusChanged(StatusCode statusCode)
1412     {
1413         if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
1414             Debug.Log(string.Format("OnStatusChanged: {0}", statusCode.ToString()));
1415
1416         switch (statusCode)
1417         {
1418             case StatusCode.Connect:
1419                 if (this.State == global::PeerState.ConnectingToNameServer)
1420                 {
1421                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1422                         Debug.Log("Connected to NameServer.");
1423
1424                     this.server = ServerConnection.NameServer;
1425                     if (this.CustomAuthenticationValues != null)
1426                     {
1427                         this.CustomAuthenticationValues.Secret = null; // when connecting to NameServer, invalidate any auth values
1428                     }
1429                 }
1430
1431                 if (this.State == global::PeerState.ConnectingToGameserver)
1432                 {
1433                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1434                         Debug.Log("Connected to gameserver.");
1435
1436                     this.server = ServerConnection.GameServer;
1437                     this.State = global::PeerState.ConnectedToGameserver;
1438                 }
1439
1440                 if (this.State == global::PeerState.ConnectingToMasterserver)
1441                 {
1442                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
1443                         Debug.Log("Connected to masterserver.");
1444
1445                     this.server = ServerConnection.MasterServer;
1446                     this.State = global::PeerState.ConnectedToMaster;
1447
1448                     if (this.IsInitialConnect)
1449                     {
1450                         this.IsInitialConnect = false; // after handling potential initial-connect issues with special messages, we are now sure we can reach a server
1451                         SendMonoMessage(PhotonNetworkingMessage.OnConnectedToPhoton);
1452                     }
1453                 }
1454
1455                 this.EstablishEncryption(); // always enable encryption
1456
1457                 if (this.IsAuthorizeSecretAvailable)
1458                 {
1459                     // if we have a token we don't have to wait for encryption (it is encrypted anyways, so encryption is just optional later on)
1460                     this.didAuthenticate = this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, this.CloudRegion.ToString());
1461                     if (this.didAuthenticate)
1462                     {
1463                         this.State = global::PeerState.Authenticating;
1464                     }
1465                 }
1466                 break;
1467
1468             case StatusCode.EncryptionEstablished:
1469                 // on nameserver, the "process" is stopped here, so the developer/game can either get regions or authenticate with a specific region
1470                 if (this.server == ServerConnection.NameServer)
1471                 {
1472                     this.State = global::PeerState.ConnectedToNameServer;
1473
1474                     if (!this.didAuthenticate && this.CloudRegion == CloudRegionCode.none)
1475                     {
1476                         // this client is not setup to connect to a default region. find out which regions there are!
1477                         this.OpGetRegions(this.mAppId);
1478                     }
1479                 }
1480
1481                 // we might need to authenticate automatically now, so the client can do anything at all
1482                 if (!this.didAuthenticate && (!this.IsUsingNameServer || this.CloudRegion != CloudRegionCode.none))
1483                 {
1484                     // once encryption is availble, the client should send one (secure) authenticate. it includes the AppId (which identifies your app on the Photon Cloud)
1485                     this.didAuthenticate = this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, this.CloudRegion.ToString());
1486                     if (this.didAuthenticate)
1487                     {
1488                         this.State = global::PeerState.Authenticating;
1489                     }
1490                 }
1491                 break;
1492
1493             case StatusCode.EncryptionFailedToEstablish:
1494                 Debug.LogError("Encryption wasn't established: " + statusCode + ". Going to authenticate anyways.");
1495                 this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, this.CloudRegion.ToString()); // TODO: check if there are alternatives
1496                 break;
1497
1498             case StatusCode.Disconnect:
1499                 this.didAuthenticate = false;
1500                 this.isFetchingFriends = false;
1501                 if (server == ServerConnection.GameServer) this.LeftRoomCleanup();
1502                 if (server == ServerConnection.MasterServer) this.LeftLobbyCleanup();
1503
1504                 if (this.State == global::PeerState.DisconnectingFromMasterserver)
1505                 {
1506                     if (this.Connect(this.mGameserver, ServerConnection.GameServer))
1507                     {
1508                         this.State = global::PeerState.ConnectingToGameserver;
1509                     }
1510                 }
1511                 else if (this.State == global::PeerState.DisconnectingFromGameserver || this.State == global::PeerState.DisconnectingFromNameServer)
1512                 {
1513                     if (this.Connect(this.MasterServerAddress, ServerConnection.MasterServer))
1514                     {
1515                         this.State = global::PeerState.ConnectingToMasterserver;
1516                     }
1517                 }
1518                 else
1519                 {
1520                     if (this.CustomAuthenticationValues != null)
1521                     {
1522                         this.CustomAuthenticationValues.Secret = null; // invalidate any custom auth secrets
1523                     }
1524
1525                     this.State = global::PeerState.PeerCreated; // if we set another state here, we could keep clients from connecting in OnDisconnectedFromPhoton right here.
1526                     SendMonoMessage(PhotonNetworkingMessage.OnDisconnectedFromPhoton);
1527                 }
1528                 break;
1529
1530             case StatusCode.SecurityExceptionOnConnect:
1531             case StatusCode.ExceptionOnConnect:
1532                 this.State = global::PeerState.PeerCreated;
1533                 if (this.CustomAuthenticationValues != null)
1534                 {
1535                     this.CustomAuthenticationValues.Secret = null; // invalidate any custom auth secrets
1536                 }
1537
1538                 DisconnectCause cause = (DisconnectCause)statusCode;
1539                 SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, cause);
1540                 break;
1541
1542             case StatusCode.Exception:
1543                 if (this.IsInitialConnect)
1544                 {
1545                     Debug.LogError("Exception while connecting to: " + this.ServerAddress + ". Check if the server is available.");
1546                     if (this.ServerAddress == null || this.ServerAddress.StartsWith("127.0.0.1"))
1547                     {
1548                         Debug.LogWarning("The server address is 127.0.0.1 (localhost): Make sure the server is running on this machine. Android and iOS emulators have their own localhost.");
1549                         if (this.ServerAddress == this.mGameserver)
1550                         {
1551                             Debug.LogWarning("This might be a misconfiguration in the game server config. You need to edit it to a (public) address.");
1552                         }
1553                     }
1554
1555                     this.State = global::PeerState.PeerCreated;
1556                     cause = (DisconnectCause)statusCode;
1557                     SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, cause);
1558                 }
1559                 else
1560                 {
1561                     this.State = global::PeerState.PeerCreated;
1562
1563                     cause = (DisconnectCause)statusCode;
1564                     SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, cause);
1565                 }
1566
1567                 this.Disconnect();
1568                 break;
1569
1570             case StatusCode.TimeoutDisconnect:
1571             case StatusCode.ExceptionOnReceive:
1572             case StatusCode.DisconnectByServer:
1573             case StatusCode.DisconnectByServerLogic:
1574             case StatusCode.DisconnectByServerUserLimit:
1575                 if (this.IsInitialConnect)
1576                 {
1577                     Debug.LogWarning(statusCode + " while connecting to: " + this.ServerAddress + ". Check if the server is available.");
1578
1579                     cause = (DisconnectCause)statusCode;
1580                     SendMonoMessage(PhotonNetworkingMessage.OnFailedToConnectToPhoton, cause);
1581                 }
1582                 else
1583                 {
1584                     cause = (DisconnectCause)statusCode;
1585                     SendMonoMessage(PhotonNetworkingMessage.OnConnectionFail, cause);
1586                 }
1587                 if (this.CustomAuthenticationValues != null)
1588                 {
1589                     this.CustomAuthenticationValues.Secret = null; // invalidate any custom auth secrets
1590                 }
1591
1592                 this.Disconnect();
1593                 break;
1594
1595             case StatusCode.SendError:
1596                 // this.mListener.clientErrorReturn(statusCode);
1597                 break;
1598
1599             case StatusCode.QueueOutgoingReliableWarning:
1600             case StatusCode.QueueOutgoingUnreliableWarning:
1601             case StatusCode.QueueOutgoingAcksWarning:
1602             case StatusCode.QueueSentWarning:
1603                 // this.mListener.warningReturn(statusCode);
1604                 break;
1605
1606             case StatusCode.QueueIncomingReliableWarning:
1607             case StatusCode.QueueIncomingUnreliableWarning:
1608                 Debug.Log(statusCode + ". This client buffers many incoming messages. This is OK temporarily. With lots of these warnings, check if you send too much or execute messages too slow. " + (PhotonNetwork.isMessageQueueRunning? "":"Your isMessageQueueRunning is false. This can cause the issue temporarily.") );
1609                 break;
1610
1611             // // TCP "routing" is an option of Photon that's not currently needed (or supported) by PUN
1612             //case StatusCode.TcpRouterResponseOk:
1613             // break;
1614             //case StatusCode.TcpRouterResponseEndpointUnknown:
1615             //case StatusCode.TcpRouterResponseNodeIdUnknown:
1616             //case StatusCode.TcpRouterResponseNodeNotReady:
1617
1618             // this.DebugReturn(DebugLevel.ERROR, "Unexpected router response: " + statusCode);
1619             // break;
1620
1621             default:
1622
1623                 // this.mListener.serverErrorReturn(statusCode.value());
1624                 Debug.LogError("Received unknown status code: " + statusCode);
1625                 break;
1626         }
1627
1628         this.externalListener.OnStatusChanged(statusCode);
1629     }
File name: frmItems.cs Copy
27         private void select_navigation(string sql)
28         {
29             config.singleResult(sql);
30             maxrow = config.dt.Rows.Count;
31         }
File name: frmItems.cs Copy
32         public void navigate_records(int inc)
33         {
34             config.singleResult("SELECT * FROM `tblitems`");
35             txtitemid.Text =config.dt.Rows[inc].Field("ITEMID");
36             txtname.Text = config.dt.Rows[inc].Field("NAME");
37             txtdescription.Text = config.dt.Rows[inc].Field("DESCRIPTION");
38             txtprice.Text = config.dt.Rows[inc].Field("PRICE").ToString();
39             cbotype.Text = config.dt.Rows[inc].Field("TYPE");
40             //txtqty.Text = config.dt.Rows[inc].Field("Quantity").ToString();
41             //cbounit.Text = config.dt.Rows[inc].Field("Units");
42
43
44         }

Download file with original file name:Config

Config 640 lượt xem

Gõ tìm kiếm nhanh...