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:

         public virtual bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, bool createIfNotExists, Hashtable playerProperties, bool onGameServer)
         {
             Dictionary op = new Dictionary();

             if (!string.IsNullOrEmpty(roomName))
             {
                 op[ParameterCode.RoomName] = roomName;
             }
             if (createIfNotExists)
             {
                 op[ParameterCode.CreateIfNotExists] = true;
                 if (lobby != null)
                 {
                     op[ParameterCode.LobbyName] = lobby.Name;
                     op[ParameterCode.LobbyType] = (byte)lobby.Type;
                 }
             }

             if (onGameServer)
             {
                 if (playerProperties != null && playerProperties.Count > 0)
                 {
                     op[ParameterCode.PlayerProperties] = playerProperties;
                     op[ParameterCode.Broadcast] = true; // broadcast actor properties
                 }


                 if (createIfNotExists)
                 {
                     if (roomOptions == null)
                     {
                         roomOptions = new RoomOptions();
                     }

                     Hashtable gameProperties = new Hashtable();
                     op[ParameterCode.GameProperties] = gameProperties;
                     gameProperties.MergeStringKeys(roomOptions.customRoomProperties);

                     gameProperties[GameProperties.IsOpen] = roomOptions.isOpen;
                     gameProperties[GameProperties.IsVisible] = roomOptions.isVisible;
                     gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
                     if (roomOptions.maxPlayers > 0)
                     {
                         gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
                     }
                     if (roomOptions.cleanupCacheOnLeave)
                     {
                         op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
                         gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
                     }
                 }
             }

             // UnityEngine.Debug.Log("JoinGame: " + SupportClass.DictionaryToString(op));
             return this.OpCustom(OperationCode.JoinGame, op, true);
         }