Jump to content

ControlSend() issue with Minecraft Server Console - (Locked)


Recommended Posts

The issue:

I wrote a script, that uses ControlSend() for stopping the server and sometimes announce the next server restart.

So far everything works fine, except that when I leave the remote desktop connection to my server, then the strings are not case-sensitive anymore. For the commands, that does not matter too much, as it send 7 instead of / and in the MC Console you can run commands without slash, so I just removed those.

As for the messages though:
NEXT SERVER RESTART AT 06:30 CEST
becomes
next server restart at 06.30 cest

 

I searched a lot about this particular issue, but have found no solution so far. I am kinda like an advanced beginner, I have some roots in scripting/programming, but I never followed that path enough, to become advanced in it. Recently I found AutoIt and fell in love with its simplicity and that it just works for simple things, which it does for me. (almost ;D)

Any tiny bit could help me create this reliable script, which I would want to post somewhere for fellow Crafters around the world, so that they can use this for themselves.

 

Thanks for any help in advance and here is my script:

Pls dont judge my beginner skills 😅

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         Thalez

 Script Function:
    Automatically restart a Minecraft Server on a Daily basis. (every 8 hours)

#ce ----------------------------------------------------------------------------

; Execute .au3 file from AutoIt Script
; ShellExecuteWait(@ProgramFilesDir & '\AutoIt3\Aut2Exe\Aut2exe.exe', ' /in C:\RunningScripts\Minecraft\MC AutoRestart 5MIN.au3')








; Live Variables

Global $IsServerRestarting = False
Global $RestartAdCounter = 0








; Variables for customizing the script  <--------

; Minecraft Server Console Window
Global $ConsoleWindowName = "Minecraft DnDnS Server 1.12.2" ; It is required that you have this set correct

; Misc
Global $RestartAdText = "NEXT SERVER RESTART AT"

; Restart Advertisements
Global $RestartAdToggle = True ; Turn the restard advertisements on or off
Global $RestartAdInterval = 20 ; Minutes | How often you want to advertise the next restart
Global $TimeFormat = "CEST" ; The current time format

; Turn a restart scheduler on or off (Potentially breaks the restart advertisements)
Global $Restarter1 = True
Global $Restarter2 = True
Global $Restarter3 = True

;Restarter 1
Global $Restarter1TimeH = '06' ; Hour/24
Global $Restarter1TimeM = '25' ; Minute (MINUS 5)

;Restarter 2
Global $Restarter2TimeH = '14' ; Hour/24
Global $Restarter2TimeM = '25' ; Minute (MINUS 5)

;Restarter 3
Global $Restarter3TimeH = '22' ; Hour/24
Global $Restarter3TimeM = '25' ; Minute (MINUS 5)

; Variables for customizing the script  <--------





;Confirm Initiation
ControlFocus($ConsoleWindowName, "", "")
ControlSend($ConsoleWindowName, "", "", "say AUTO-RESTART SCRIPT LOADED")
ControlSend($ConsoleWindowName, "", "", "{ENTER}")

; Running Script
While 1


    ; A scheduled announcement for the next restart (Has to be rewritten, depending on the restart schedulers, that are turned on)
    If $RestartAdCounter = $RestartAdInterval * 4 and $IsServerRestarting = False Then

        $RestartAdCounter = 0

        ; Next Restarter 1
        If @HOUR >= 23 or @HOUR < 7 Then
                AnnounceRestart("06", "30")
        EndIf

        ; Next Restarter 2
        If @HOUR >= 7 and @HOUR < 15 Then
                AnnounceRestart("14", "30")
        EndIf

        ; Next Restarter 3
        If @HOUR >= 15 and @HOUR < 23 Then
                AnnounceRestart("22", "30")
        EndIf

    EndIf

    ; Actual Server Restart 1
    If $RestartAdToggle = True and $Restarter1 = True and @HOUR = $Restarter1TimeH and @MIN = $Restarter1TimeM and $IsServerRestarting = False Then
        $IsServerRestarting = True
        RestartServer()
    EndIf
    ; Actual Server Restart 2
    If $RestartAdToggle = True and $Restarter2 = True and @HOUR = $Restarter2TimeH and @MIN = $Restarter2TimeM and $IsServerRestarting = False Then
        $IsServerRestarting = True
        RestartServer()
    EndIf
    ; Actual Server Restart 3
    If $RestartAdToggle = True and $Restarter3 = True and @HOUR = $Restarter3TimeH and @MIN = $Restarter3TimeM and $IsServerRestarting = False Then
        $IsServerRestarting = True
        RestartServer()
    EndIf

$RestartAdCounter += 1
Sleep(15000) ; Update interval = 15 seconds

WEnd








;Functions

; /stop the server after 5 minutes, with announcements
Func RestartServer()

    ControlFocus($ConsoleWindowName, "", "")

    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 5 MINUTES")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    Sleep(180000)
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 2 MINUTES")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    Sleep(60000)
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 1 MINUTE")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    Sleep(30000)
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 30 SECONDS")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    Sleep(20000)
    ControlSend($ConsoleWindowName, "", "", "say SERVER RESTART IN 10 SECONDS")
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 9..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 8..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 7..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 6..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 5..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 4..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 3..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 2..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "say 1..{ENTER}")
    Sleep(1000)
    ControlSend($ConsoleWindowName, "", "", "stop{ENTER}")

        ResetIsServerRestarting()

EndFunc

Func ResetIsServerRestarting() ; After 5 minutes delay
    Sleep(300000)
    $IsServerRestarting = False
EndFunc


; Announce the next restart, with Hour and Minute input
Func AnnounceRestart($H, $M)

    ControlFocus($ConsoleWindowName, "", "")

    ControlSend($ConsoleWindowName, "", "", "say ")
    ControlSend($ConsoleWindowName, "", "", $RestartAdText)
    ControlSend($ConsoleWindowName, "", "", " ")
    ControlSend($ConsoleWindowName, "", "", $H)
    ControlSend($ConsoleWindowName, "", "", ":")
    ControlSend($ConsoleWindowName, "", "", $M)
    ControlSend($ConsoleWindowName, "", "", " ")
    ControlSend($ConsoleWindowName, "", "", $TimeFormat)
    ControlSend($ConsoleWindowName, "", "", "{ENTER}")

EndFunc


; Just a function to put in, whenever you want to test something
Func TestFunc()

    ControlFocus($ConsoleWindowName, "", "")

    ControlSend($ConsoleWindowName, "", "", "discord tps{ENTER}")

EndFunc

 

Link to comment
Share on other sites

  • Moderators

Welcome to the AutoIt forum.

Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked.

See you soon with a legitimate question I hope.

The Moderation team

 

@badcoder123 Maybe take some time to read the forum rules yourself before responding in the future. 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...