Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

     /// - Invalid AppId (calls: OnFailedToConnectToPhoton(). check exact AppId value)
     /// - Network issues (calls: OnFailedToConnectToPhoton())
     /// - Invalid region (calls: OnConnectionFail() with DisconnectCause.InvalidRegion)
     /// - Subscription CCU limit reached (calls: OnConnectionFail() with DisconnectCause.MaxCcuReached. also calls: OnPhotonMaxCccuReached())
     public static bool ConnectToMaster(string masterServerAddress, int port, string appID, string gameVersion)
     {
         if (networkingPeer.PeerState != PeerStateValue.Disconnected)
         {
             Debug.LogWarning("ConnectToMaster() failed. Can only connect while in state 'Disconnected'. Current state: " + networkingPeer.PeerState);
             return false;
         }

         if (offlineMode)
         {
             offlineMode = false; // Cleanup offline mode
             Debug.LogWarning("ConnectToMaster() disabled the offline mode. No longer offline.");
         }

         if (!isMessageQueueRunning)
         {
             isMessageQueueRunning = true;
             Debug.LogWarning("ConnectToMaster() enabled isMessageQueueRunning. Needs to be able to dispatch incoming messages.");
         }

         networkingPeer.SetApp(appID, gameVersion);
         networkingPeer.IsUsingNameServer = false;
         networkingPeer.IsInitialConnect = true;
         networkingPeer.MasterServerAddress = (port == 0) ? masterServerAddress : masterServerAddress + ":" + port;

         return networkingPeer.Connect(networkingPeer.MasterServerAddress, ServerConnection.MasterServer);
     }