MinecraftServerControl / mscs

Powerful command-line control for UNIX and Linux powered Minecraft servers
https://minecraftservercontrol.github.io
BSD 2-Clause "Simplified" License
485 stars 62 forks source link

Add notice when attempting to start/stop an already started/stopped world #248

Closed Roflicide closed 4 years ago

Roflicide commented 4 years ago

Attempting to start an already started world or stop an already stopped world will only display a period ("."), such as below:

$ mscs status
Minecraft Server Status:
  test: running version 1.15.2 (2 of 20 users online).
    Process ID: 5160.
    Memory used: 2538068 kB.
  cannon: not running.

$ mscs start test
The cached copy of the version manifest is up to date.
Use the force-update option to ensure a new copy is downloaded.
Starting Minecraft Server:.

$ mscs stop cannon
Stopping Minecraft Server:.

This patch notifies the user when they attempt to start or stop an already started/stopped world. If the user tries to start/stop multiple worlds and one already is started/stopped, then the entire command will exit and no worlds will be started or stopped (same behavior when user tries to start/stop/restart worlds and one world doesn't exist).

$ mscs status
Minecraft Server Status:
  test: running version 1.15.2 (2 of 20 users online).
    Process ID: 5160.
    Memory used: 2538068 kB.
  cannon: not running.

$ mscs start test
The cached copy of the version manifest is up to date.
Use the force-update option to ensure a new copy is downloaded.
Unable to start the requested worlds: world 'test' already running.

$ mscs stop cannon
Unable to stop the requested worlds: world 'cannon' already stopped.

$ mscs start test cannon
The cached copy of the version manifest is up to date.
Use the force-update option to ensure a new copy is downloaded.
Unable to start the requested worlds: world 'test' already running.

$ mscs stop test cannon
Unable to stop the requested worlds: world 'cannon' already stopped.

Additionally, right now when a user tries to start/stop/restart a world that doesn't exist, it will say "World not recognized . I changed the warnings to "World not recognized or disabled" since disabled worlds won't be recognized either (since the worlds are being checked with the isWorldEnabled function).

zanix commented 4 years ago

Having the force-* variants skip this check might be a good idea.

Roflicide commented 4 years ago

Having the force-* variants skip this check might be a good idea.

oh, good point. i totally forgot about those commands

zanix commented 4 years ago

I don't think there is a force-start though

sandain commented 4 years ago

I like this, good idea.

sandain commented 4 years ago

Nice. Thanks @Roflicide. I'll accept the PR.

Roflicide commented 4 years ago

Woops -- I accidently had in code there that i was gonna put in another PR that warns the user before checking to delete a world (bold is what I added to the delete command)

do you want me revert this back?

delete | remove)
    # Get list of enabled worlds.
    if ! isWorldAvailable "$1"; then
      printf "World not found, unable to delete world '$1'.\n"
      exit 1
    fi
    **printf "Are you sure you wish to delete world '$1'? (y/n): "
    read answer
    if [ "$answer" = "${answer#[Yy]}" ]; then
        printf "Aborted.\n"
        exit 1
    else**
      printf "Deleting Minecraft world: $1"
      if serverRunning "$1"; then
        # If the world server has users logged in, announce that the world is
        # being deleted.
        if [ $(queryNumUsers "$1") -gt 0 ]; then
          sendCommand "$1" "say The server admin is deleting this world."
          sendCommand "$1" "say The server will be deleted in 1 minute..."
          sleep 60
          sendCommand "$1" "say The server is now shutting down."
        fi
        # Stop the world server.
        stop "$1"
        sleep 5
      fi
      # Delete the world.
      deleteWorld "$1"
      printf ".\n"
    fi
sandain commented 4 years ago

That is a good idea. Don't worry about it being in this PR