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:

     private void GameEnteredOnGameServer(OperationResponse operationResponse)
     {
         if (operationResponse.ReturnCode != 0)
         {
             switch (operationResponse.OperationCode)
             {
                 case OperationCode.CreateGame:
                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
                     {
                         Debug.Log("Create failed on GameServer. Changing back to MasterServer. Msg: " + operationResponse.DebugMessage);
                     }
                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonCreateRoomFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
                     break;
                 case OperationCode.JoinGame:
                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
                     {
                         Debug.Log("Join failed on GameServer. Changing back to MasterServer. Msg: " + operationResponse.DebugMessage);
                         if (operationResponse.ReturnCode == ErrorCode.GameDoesNotExist)
                         {
                             Debug.Log("Most likely the game became empty during the switch to GameServer.");
                         }
                     }
                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonJoinRoomFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
                     break;
                 case OperationCode.JoinRandomGame:
                     if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
                     {
                         Debug.Log("Join failed on GameServer. Changing back to MasterServer. Msg: " + operationResponse.DebugMessage);
                         if (operationResponse.ReturnCode == ErrorCode.GameDoesNotExist)
                         {
                             Debug.Log("Most likely the game became empty during the switch to GameServer.");
                         }
                     }
                     SendMonoMessage(PhotonNetworkingMessage.OnPhotonRandomJoinFailed, operationResponse.ReturnCode, operationResponse.DebugMessage);
                     break;
             }

             this.DisconnectToReconnect();
             return;
         }

         this.State = global::PeerState.Joined;
         this.mRoomToGetInto.isLocalClientInside = true;

         Hashtable actorProperties = (Hashtable)operationResponse[ParameterCode.PlayerProperties];
         Hashtable gameProperties = (Hashtable)operationResponse[ParameterCode.GameProperties];
         this.ReadoutProperties(gameProperties, actorProperties, 0);

         // the local player's actor-properties are not returned in join-result. add this player to the list
         int localActorNr = (int)operationResponse[ParameterCode.ActorNr];

         this.ChangeLocalID(localActorNr);
         this.CheckMasterClient(-1);

         if (this.mPlayernameHasToBeUpdated)
         {
             this.SendPlayerName();
         }

         switch (operationResponse.OperationCode)
         {
             case OperationCode.CreateGame:
                 SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom);
                 break;
             case OperationCode.JoinGame:
             case OperationCode.JoinRandomGame:
                 // the mono message for this is sent at another place
                 break;
         }
     }