Results 1 to 7 of 7

Thread: [Solved]Dedicated Server - Enable/Disable password through script?

  1. #1
    Superkart Pilot
    Join Date
    May 2015
    Posts
    105
    Platform
    PC

    [Solved]Dedicated Server - Enable/Disable password through script?

    Hello,
    Is it possible to enable and disable the need use a password to enter the server with a script? There are times when I'd like the password to be enabled and others when anyone can join.
    Last edited by Laserbeak43; 11-05-2018 at 10:32.
    PSN Laserbeak43
    Steam Laserbeak43

  2. #2
    Superkart Pilot
    Join Date
    May 2016
    Posts
    192
    Platform
    PC
    On Linux? Just set your Password like

    Code:
    password : yourpassword
    In the config file and use sed to comment it out when not needed:

    Code:
    sed -i "s/^password/\/\/password/" server.cfg
    And vice versa:

    Code:
    sed -i "s/^\/\/password/password/" server.cfg
    In a bit more sophisticated script it could look like this:

    Code:
    #!/bin/bash
    
    usage() {
    cat <<EOF
    
    Usage: $0 [options]
    
    Options:
      on              enable password
      off             disable password
    
    EOF
    }
    
    pwswitch(){
      if [ $1 == "on" ]; then
        sed -i "s/^\/\/password/password/" server.cfg
      elif [ $1 == "off" ]; then
        sed -i "s/^password/\/\/password/" server.cfg
      else
        usage
      fi
    }
    
    if [ $# -gt 0 ]; then 
      for i in "$@"; do
        case $i in
          on)
          pwswitch on
          shift
          ;;
          off)
          pwswitch off
          shift
          ;;
          *)
          usage
          ;;
        esac
      done
    else
      usage
    fi
    Keep in mind that the server has to be restarted after that. But I'm sure that you can do that within the script with the examples above.

    Edit:

    While I was on it already and waiting for finishing time at the office, I added a restart function and the possibility to set the password. Here you go:

    Code:
    #!/bin/bash
    
    usage() {
    cat <<EOF
    
    Usage: $0 [options]
    
    Options:
      -on           enable password
      -off          disable password
      -pw PASSWORD  set password to value
      -restart      restart server after changing the config
    
    EOF
    }
    
    pwswitch(){
      if [ $1 == "on" ]; then
        sed -i "s/^\/\/password/password/" server.cfg
      elif [ $1 == "off" ]; then
        sed -i "s/^password/\/\/password/" server.cfg
      fi
    }
    
    pwset(){
        sed -i "s/password :.*$/password : $1/" server.cfg
    }
    
    restartserver(){
      PID=$(pidof DedicatedServerCmd.elf)
      kill -15 $PID
      ./DedicatedServerCmd.elf -c server.cfg
    }
    
    if [ $# -eq 0 ]; then
      usage
    else
      while [ $# -gt 0 ]; do 
          case $1 in
            -pw)
            password="$2"
            shift 2
            ;;
            -on)
            pwswitch on
            shift
            ;;
            -off)
            pwswitch off
            shift
            ;;
            -restart)
            restart=yes
            shift
            ;;
            -*)
            usage
            exit 1
            ;;
            *)
            usage
            exit 1
            ;;
          esac
      done
    fi
    
    if [ -n $password ]; then
      pwset $password
    fi
    
    if [ $restart == yes ]; then
      restartserver
    fi
    Note that the script has to be located in the folder of the DedicatedServerCmd.elf binary and the server.cfg. Otherwise you would have to change the paths. Other than that the restart function only works well if only one server is running on the host.
    Last edited by m00lean; 09-05-2018 at 15:54.
    The following user likes this Post: Laserbeak43


  3. #3
    Superkart Pilot
    Join Date
    May 2015
    Posts
    105
    Platform
    PC
    Holy moly that's golden!
    Thing is, my server is hosted on a windows server. I'm not sure that I could do something like this on that. maybe I could create a script based off of this if the host would allow me to see the desktop and run cmd.
    PSN Laserbeak43
    Steam Laserbeak43

  4. #4
    Superkart Pilot
    Join Date
    May 2016
    Posts
    192
    Platform
    PC
    It should be possible with a batch script and/or powershell. But I bet it would be less painful to just setup up a server on a small Linux host

  5. #5
    GT5 Pilot Charger's Avatar
    Join Date
    May 2015
    Posts
    1,639
    Platform
    PC
    Quite easy, run one server with and one without, you can run more than one dedi ;-)

  6. #6
    WMD Member Asturbo's Avatar
    Join Date
    Jun 2012
    Location
    Asturias / Spain
    Posts
    712
    Platform
    PC
    Quote Originally Posted by Charger View Post
    Quite easy, run one server with and one without, you can run more than one dedi ;-)
    That was also my option. I have a server with all the options fixed, and other one that can be edited on the fly by the host user.
    Last edited by Asturbo; 10-05-2018 at 06:56.
    CPU: Intel i7-8700K | GPU: nVidia GTX 1080 | RAM: Gskill 2x8GB DDR4 3200 | MB: Asus ROG Strix Z370 | SSD: Samsung 951 PCI 250GB | Monitor: Asus VG248 144Hz | Wheel: Fanatec CSL | SO: Windows 10 Pro 64bits
    WMD1 & WMD2 Gold Member /// Steam Profile /// Unofficial Issue List /// Button Box Label Template /// DS Flags Calculator

  7. #7
    Superkart Pilot
    Join Date
    May 2015
    Posts
    105
    Platform
    PC
    I'm using a hosting service that seems to just give me a directory with the server in it. So that's not an option for me.
    PSN Laserbeak43
    Steam Laserbeak43

Similar Threads

  1. Replies: 3
    Last Post: 10-06-2018, 16:03
  2. How do you disable AI on a dedicated server?
    By Bad_Dan in forum Multiplayer
    Replies: 5
    Last Post: 02-12-2017, 16:39
  3. How do you disable AI on a dedicated server?
    By Bad_Dan in forum Multiplayer
    Replies: 1
    Last Post: 12-11-2017, 12:40
  4. Reporting MP bug server name and password not saving when setting up servers.
    By Hotdognz in forum Technical Help & Support (PC)
    Replies: 0
    Last Post: 26-09-2017, 22:07
  5. Enable/Disable cameras available in cycle camera
    By PureMalt77 in forum Feature Suggestions
    Replies: 1
    Last Post: 24-07-2015, 00:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •