Batch File and AutoIT Script designed to work together. The AutoIT Script is not required, but they work better together. There is a stand alone AutoIT Script below that doesn't require the Batch file. Finally, I have included a AutoIT Script to remotely restart the server when used with one of the Server Scripts.

The remote restart will require you edit the source of the AutoIT scripts if you wish to change the listening IP, port, and password required for restart. They should work together by default, but you will need to open port 54321 on the Server.

::V1.1-Added Task Kill of AutoIT Script to be used along side batch----------::::V1.0-Initial Version Created. Simple Loop Script for Server Crashes--------::::-----Also added ability to log server to file------------------------------::

Batch File:

@ECHO OFFtitle Cube Server Loop Utility::By Dateranoth - July 7, 2013::Used by http://www.gamercide.org on their server.::Feel free to change, adapt, and distribute::Download batch file here-::http://www.dateranoth.com/gamercide/CWServerUtility.zip::V1.1-Added Task Kill of AutoIT Script to be used along side batch----------::::V1.0-Initial Version Created. Simple Loop Script for Server Crashes--------::::-----Also added ability to log server to file------------------------------::::-----------------------------------------------------------------------------------::::--------------------User Variables--------------------------------- ----------------::::-----------------------------------------------------------------------------------::::Set Server.exe Directory (Be sure to include Trailing Slash)SET ServerPath=C:\Games\Cube World\::Set Time between server Failed or Stopped and Server Restarted (in seconds)SET Timer=10::-----------------------------------------------------------------------------------::::----------------Logging Options - Enable Logging Here------------------------------::::-----------------------------------------------------------------------------------::::If Logging is enabled, the Console will not output current server status. ::All status will be written to file. You can check current status through the log file.::Log Server to file containing todays date. (yes or no)set EnableLog=no::LogPath is the path to the folder where the log file will be saved (Be sure to include Trailing Slash)set LogPath=C:\Games\Cube World\Logs\::LogFileExt is the extension to be used set LogFileExt=.log::LogFile is a descriptive name that will be added after the dateset LogFile=CubeWorldServerLog::Include Time In Log File Name? (yes or no)::Including time will create a log file on each Server.exe start. Not including time will create Daily Log files.set IncludeTime=no::Set the format you would like the date to appear on log files. Default is year(%%g)-month(%%e)-day(%%f). Your windows time format may differ.:: If it does or you would like something different then rearrange the parameters below until satisfied. Results will be format1-format2-format3set dateformat1=%%gset dateformat2=%%eset dateformat3=%%f::------------------------------------------------------------------------------------------------------------------------------::::!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!No Setting Changes Below Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!::::------------------------------------------------------------------------------------------------------------------------------:::Start::start /wait /min /d "%ServerPath%" Server.exeIF /i %EnableLog%==yes (goto LoggingStart) ELSE (goto NoLogStart):NoLogStartECHO.ECHO Starting Server Loop.ECHO.cd /d "%ServerPath%""%ServerPath%"Server.exegoto RemainingLoop:LoggingStartsetlocalset LogFileName=%LogFile%%LogFileExt%for /f "tokens=1-5 delims=/\ " %%d in ("%date%") do SET Date1=%dateformat1%-%dateformat2%-%dateformat3%for /f "tokens=1-5 delims=: " %%d in ("%time%") do SET Time1=%%d%%eIF /i %IncludeTime%==yes (set MyLogFile=%Date1%--%Time1%) ELSE (set MyLogFile=%Date1%)set MyLogFile=%LogPath%%MyLogFile%_%LogFileName%If NOT Exist "%LogPath%" (goto makelogdirectory) ELSE (goto checknewlog):makelogdirectorymd "%LogPath%"goto checknewlog::Note that the quotes are REQUIRED around %MyLogFIle% in case it contains a space:checknewlogIf NOT Exist "%MyLogFile%" (goto noseparator)Echo.>>"%MyLogFile%"Echo.===================>>"%MyLogFile%":noseparatorecho.%Date% >>"%MyLogFile%"echo.%Time% >>"%MyLogFile%":startbatchECHO.ECHO Starting Server Loop and Logging.ECHO.ECHO.ECHO Server will not display to Console while logging to file is enabled.ECHO.ECHO To check server status, open:ECHO %MyLogFile%ECHO.ECHO Type q to quit.ECHO.cd /d "%ServerPath%""%ServerPath%"Server.exe >> "%MyLogFile%"goto RemainingLoop::Checks if timer has counted down to 0. If so restarts backup:RemainingLoopsetlocal enableDelayedExpansionfor /l %%N in (%Timer% -1 1) do ( set /a "min=%%N/60, sec=%%N%%60, n-=1" if !sec! lss 10 set sec=0!sec! cls choice /c:CR1 /n /m "Server Restart in !min!:!sec! - Press R to Restart Server Now, or C to Cancel. " /t:1 /d:1 if not errorlevel 3 goto :CheckAnswer):CheckAnswerif errorlevel 2 (goto Start) else (goto End)::Shut Down The Batch File.:Endchoice /c:YN /m "Do you really want to quit"If Errorlevel 2 goto StartIf Errorlevel 1 goto Shutdown:Shutdowntaskkill /f /im "CWServerUtility.exe"Exit::Here in case of any major errors.:CatchAllEndpauseExit

Recommended Comments

Share this comment

Link to comment

Share on other sites

Well, turns out Cube World likes to crash hard and leave a nice windows message that won't close. Here's an Autoit script to close it automatically. Need to run it along side the Cube World Utility to make sure your server will restart unattended.

Share this comment

Link to comment

Share on other sites

I updated the AutoIT script and added a stand alone for those who don't want to use the batch. This is a trial run with the AutoIT script. It will be closing the server anytime memory usage goes above 400MB. This seems to be when the crashes are occuring.

When running the batch and AutoIT scripts together, use the AutoIT exe to start the server and quit through the command window. The AutoIT starts the batch file and the batch file kills the AutoIT scripts. The AutoIT prompt will automatically close after 60 seconds and start with a default of 10am.

Share this comment

Link to comment

Share on other sites

Share this comment

Link to comment

Share on other sites

Ok, so the automatic restart when the memory limit was made wasn't working. The game definitely has a problem when memory usage gets too high, but it isn't consistent enough. There is no limit I can set that doesn't seem to sometimes close the server when it doesn't need to. So, I removed that option, and I am simply logging memory usage when it rises above 600MB. I left the code commented out that would close the server at a certain memory limit for anyone who wants to use it.

Since there is no reliable way to detect a locked up server I decided to go the remote restart route. There is now a separate file you can download that allows the server to be remotely restarted. I suggest you download AutoIT and edit the source files to your liking. It would be wise to change the port and password required to reset the server remotely. By default the Port is 54321 and Password is Restart.