CustomGame.SetJoinSetting(Join setting);
Syntax
public void SetJoinSetting(
    Join setting
)

setting
Change who can join to.
Type: CustomGameOW.Join

Changes who can join.
Join.Everyone: Everyone from your region can join.
Join.FriendsOnly: Everyone from your friends list can join.
Join.InviteOnly: No one can join unless you invite them with CustomGame.InvitePlayer().

using System;
using CustomGameOW;

...

static void Main(string[] args)
{
    // Set game to friends only when maximum player count has been reached. Set back to public when slots open up.
    CustomGame cg = new CustomGame();
    bool public = true;
    const int maxplayercount = 10; // Maximum player count
    while (true) 
    {
        int playercount = cg.playercount; // Get player count
        if (playercount < maxplayercount && public == false) 
        {
            // if the player count is less than the maximum player count and lobby is private, make lobby public.
            cg.SetJoinSetting(Join.Everyone);
            public = true;
        }
        else if (playercount >= maxplayercount && public == true) 
        {
            // if the player count is equal to or greater than the maximum player count and lobby is public, make lobby private.
            cg.SetJoinSetting(Join.FriendsOnly);
            public = false;
        }
    }
}