Valheim
0 of 0

File information

Last updated

Original upload

Created by

Astrolan

Uploaded by

astrolan

Virus scan

Some manually verified files

Tags for this mod

About this mod

Batch Manager file/application to install and manage a local windows Valheim Server.

From beginning to end, SteamCMD installer and Server Setup and Management.

While a lot of this can be done in the Steam Application client, this is more hands on and in some ways cleaner.

Permissions and credits
Changelogs
Who might need or want this batch file to “install and manage” a local Windows Valheim Server on your machine?

Well, if you have shared your local world with a friend or two and experienced the less that optimal game play, then you should consider this
solution instead. Or maybe you just want to run or test a dedicated windows Valheim server, but you did not want to take the time to figure out all the nuances
of setting it up!   (*I for example use it to run a 8 man team every Thursday game night, 5 brothers and other family!*)

So, this very custom batch file installs the Steamcmd.exe server installer, and then installs your local server.

This is not all automatic/black box stuff, READ the menu, it will take you through the process!!!
    [0] ... Install SteamCMD (Server Installer/updater - Required First/Once)-(press quit at end)
    [1] ... Install / Update local Valheim Dedicated Server (Required/As needed)
    [2] ... Start the Server
    [9] ... EXIT

Features:
Batch file can be placed and ran from anywhere in your system. (Shortcuts are your friend)
Defaults to a private server you will need to tell your friends your IP# and Port #2456
(To change to a public server edit "public 0" to public 1" )
Edit the file at will and mount/run any of your local worlds (swapping between worlds)
Each time the batch is started it backs up your character and world data to your Documents (edit to remove if desired)
*** (See my NOTES in POSTS for more related backup information!)
Provides a simple menu option to STOP your server without manual intervention in the terminal window
* (If you do need to stop the server manually for some reason, select the terminal window and press AltF4) *

By default:
Installs steamcmd.exe in your user directory as directory "steamcmd" (and builds the application there)

Installs the server valheim_server.exe in your system drive “Program Files (x86)\Steam\steamapps\common\Valheim dedicated server\”

All usage directions are in the comments or given direct in the menu’s

You can test a local server without making any changes to the file, but you should edit as a minimum:
(They can be edited after a test with no issues!)

* password - (default password is 12345)
* worldname – (default is Dedicated) -(if not found, creates with random seed)
* servername – (default is MyServer)

As with all Valheim servers, yours can be modded just as you would any other
server, using 99% of the same techniques you do to mod the client.
The entire batch file is below as text or you can down load the zip file.

:: Valheim Server Manager v0.1 (11-3-2021), idea and some resource information found on internet (Thanks People)
:: Not addressed: Opening the required port range 2456-2458 on your router/firewall
::
::Change GameServed name below:optional
SET GameServed=Valheim
::
:: Use Menu Option 0 or Manually install/download SteamCMD for Windows: https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip
:: Issues See: (https://developer.valvesoftware.com/wiki/SteamCMD)
:: Update/Change the line below to your steamcmd.exe location if you manually installed steamcmd.exe
SET steamCMDPath=%USERPROFILE%\steamcmd\ 
::
:: Change the line below to your server location if different: (this is steam default)
SET runcmd="%SYSTEMDRIVE%\Program Files (x86)\Steam\steamapps\common\Valheim dedicated server\"
::
::Update required below: To anything other than password
SET ThisServerName=MyServer
::
::Update required below: if the world does not exist it will be created with random seed (Tip: you can create local in Valheim app and use that world)
SET gameWorldName=Dedicated
::
::Update required below (minium 5 characters, must not be in the name)
SET gameServerPassword=12345
:: Do not change anything below unless you know what your doing!
SET thisfilename=Srv Mgr v0.1
SET ValheimStatus=off
SET steamgameId=896660
SET SteamAppId=892970
SET steamUsername=anonymous
SET steamPassword=
SET logName=%GameServed%_%ThisServerName%_server.log
SET kinputerror=
SET appstatus=
@echo off
title %thisfilename% - %GameServed%
cls
color 1f
IF exist "%SYSTEMDRIVE%\Program Files (x86)\Steam\steamapps\common\Valheim dedicated server\" CD /d "%runcmd%"
>> "%logName%" echo (%date%)(%time%) **************************************************
>> "%logName%" echo (%date%)(%time%) (%thisfilename%) - Server: %ThisServerName% Serving: %GameServed%
>> "%logName%" echo (%date%)(%time%) **************************************************
:menu
echo      (%date%)(%time%) (%thisfilename%) - Server: %ThisServerName% - Serving: %GameServed%
tasklist /fi "ImageName eq valheim_server.exe" /fo csv 2>NUL | find /I "valheim_server.exe" >NUL
:: Server is running
if "%ERRORLEVEL%"=="0" (SET ValheimStatus=on)
echo:
echo:
echo      888     888     d8888 888      888    888 8888888888 8888888 888b     d888 
echo      888     888    d88888 888      888    888 888          888   8888b   d8888 
echo      888     888   d88P888 888      888    888 888          888   88888b.d88888 
echo      Y88b   d88P  d88P 888 888      8888888888 8888888      888   888Y88888P888 
echo       Y88b d88P  d88P  888 888      888    888 888          888   888 Y888P 888 
echo        Y88o88P  d88P   888 888      888    888 888          888   888  Y8P  888 
echo         Y888P  d8888888888 888      888    888 888          888   888   "   888 
echo          Y8P  d88P     888 88888888 888    888 8888888888 8888888 888       888 
echo:
echo      %GameServed% Dedicated Server: %ThisServerName%
IF %ValheimStatus%==off echo      Server Status: STOPPED
IF %ValheimStatus%==on  echo      Server Status: RUNNING
IF %ValheimStatus%==on COLOR 2f
echo:
echo      COMMAND MENU
echo      ____________
IF %ValheimStatus%==off echo     [0] ... Install SteamCMD (Server Installer/Updater - Required First/Once)-(type quit at end!)
IF %ValheimStatus%==off echo     [1] ... Install / Update local Valheim Dedicated Server (Required/As needed)
IF %ValheimStatus%==off echo     [2] ... Start the Server
IF %ValheimStatus%==on  echo     [3] ... Stop the Server
echo     [9] ... EXIT
echo:
IF DEFINED kinputerror echo   %kinputerror%
IF DEFINED appstatus echo   %appstatus%
IF %ValheimStatus%==on  echo      WARNING - DO NOT EXIT UNTIL SERVER IS STOPPED
SET "K="
SET /P K=     Select Menu Command: 
echo:
IF %K%==0 IF %ValheimStatus%==off GOTO installsteamcmd
IF %K%==1 IF %ValheimStatus%==off GOTO update
IF %K%==2 IF %ValheimStatus%==off GOTO start
IF %K%==3 IF %ValheimStatus%==on  GOTO stop
IF %K%==8 GOTO taskkill
IF %K%==9 GOTO goodbye
:: SET ValheimStatus=off
SET kinputerror=Error: -- Unknown Input Key %K%
cls
GOTO menu
:: ---------------------
:installsteamcmd
set failtext="Did not make steamcmd Directory"
if not exist "%USERPROFILE%\steamcmd" mkdir "%USERPROFILE%\steamcmd"
if not exist "%USERPROFILE%\steamcmd" goto fail
::Download the zip
echo      Downloading zipfile...
%SystemRoot%\system32\bitsadmin.exe /transfer "SteamCMD-Install" https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip "%USERPROFILE%\steamcmd\steamcmd.zip"
echo      zip extraction...
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -nologo -noprofile -command "& { $shell = New-Object -COM Shell.Application; $target = $shell.NameSpace('%USERPROFILE%\steamcmd'); $zip = $shell.NameSpace('%USERPROFILE%\steamcmd\steamcmd.zip'); $target.CopyHere($zip.Items(), 16); }"
set failtext="Did not find steamcmd.exe, extraction failure"
if not exist "%USERPROFILE%\steamcmd\steamcmd.exe" goto fail
call %USERPROFILE%\steamcmd\steamcmd.exe
SET appstatus=SteamCMD.EXE installed!
color 1f
cls
GOTO menu
:: ---------------------
:update
::Start steamcmd install and update screen
echo      (%date%)(%time%) Run %GameServed% update via Steam using SteamCMD
>> "%logName%" echo (%date%)(%time%) Run %GameServed% update via Steam using SteamCMD
CD /d %steamCMDPath%
call %USERPROFILE%\steamcmd\steamcmd.exe +login anonymous  +force_install_dir "C:\Program Files (x86)\Steam\steamapps\common\Valheim dedicated server" +app_update 896660 validate +quit
:: alternate way? start /wait %USERPROFILE%\steamcmd\steamcmd.exe +login anonymous  +force_install_dir "C:\Program Files (x86)\Steam\steamapps\common\Valheim dedicated server" +app_update 896660 validate +quit
SET appstatus=Dedicated Server installed!
color 1f
cls
GOTO menu
:: ---------------------
:start
::Start the game server
echo      (%date%)(%time%) Start %GameServed% server - name: %ThisServerName% - world: %gameWorldName% - password: %gameServerPassword%
>> "%logName%" echo (%date%)(%time%) Start %GameServed% server - name: %ThisServerName% - world: %gameWorldName% - password: %gameServerPassword%
:: Backup local World & Charcter Data to your Documents (You can remove or comment out the next 13 lines if you don't want a backup!)
echo      "First we are Backing up World & Charcter Data to %USERPROFILE%\Documents\"
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
     set dow=%%i
     set month=%%j
     set day=%%k
     set year=%%l
)
for /f "tokens=1-5 delims=:" %%d in ("%time%") do (
 set hour=%%d
 set minute=%%e
)
set datestr=%month%_%day%_%year%_%hour%_%minute%
%SystemRoot%\System32\xcopy.exe "%USERPROFILE%\AppData\LocalLow\IronGate\Valheim\*" "%USERPROFILE%\Documents\Valheim_GameData_BAC%datestr%" /C /H /I /K /Q /R /S /Y >nul
::Start the Server
SET ValheimStatus=on
CD /d "%runcmd%"
start /high valheim_server.exe -nographics -batchmode -name %ThisServerName% -port 2456 -world %gameWorldName% -password %gameServerPassword% public 0
::Test::  valheim_server /high -nographics -batchmode -name "5Brothers on Valheim" -port 2456 -world "xxxxxx" -password "xxxx" public 0
cls
SET appstatus=Server is running!
COLOR 2f
GOTO menu
:: ---------------------
:stop
cls
echo:
echo:
echo:
echo:
tasklist /fi "ImageName eq valheim_server.exe" /fo csv 2>NUL | find /I "valheim_server.exe">NUL
:: Server is running
if not "%ERRORLEVEL%"=="0" goto menu
>> "%logName%" echo (%date%)(%time%) Attempting SOFT Stop %GameServed% server - name: %ThisServerName%
echo      Attempting SOFT STOP - Watch your terminal server window to see if it closes
echo      If it does not, exit this batch file and select your terminal server window and press AltF4
taskkill /IM "valheim_server.exe">NUL
timeout /t 10
>> "%logName%" echo [Server] (%date%)(%time%) %ThisServerName% in %GameServed%
>> "%logName%" echo [Server] (%date%)(%time%) Exit! %thisfilename% for server %ThisServerName% in %GameServed%
>> "%logName%" echo [Server] (%date%)(%time%) %ThisServerName% in %GameServed%
SET ValheimStatus=off
SET appstatus=Server is Shutdown softly with SAVE!
color 4f
cls
goto menu
:: ---------------------
:goodbye
>> "%logName%" echo (%date%)(%time%) Normal MENU Exit %thisfilename% for server %ThisServerName% in %GameServed%
echo      Exit from %thisfilename% (this console) is now OK
timeout /t 4 >null
EXIT
:fail
cls
echo:
echo:
echo Failure: %failtext%
echo or
echo something else went wrong, check your install folders at
echo  %steamCMDPath%        
:: %USERPROFILE%\steamcmd
echo %runcmd%
:: "%SystemRoot%\Program Files (x86)\Steam\steamapps\common\"
::
echo Press any key to exit!
pause
exit 0