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 OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
         {
             if (this.DebugOut >= DebugLevel.INFO)
             {
                 this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
             }

             Dictionary op = new Dictionary();

             if (!string.IsNullOrEmpty(roomName))
             {
                 op[ParameterCode.RoomName] = roomName;
             }
             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; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties
                 }


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

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

                 gameProperties[GameProperties.IsOpen] = roomOptions.isOpen; // TODO: check default value. dont send this then
                 gameProperties[GameProperties.IsVisible] = roomOptions.isVisible; // TODO: check default value. dont send this then
                 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("CreateGame: " + SupportClass.DictionaryToString(op));
             return this.OpCustom(OperationCode.CreateGame, op, true);
         }