本地服务器管理器

用于在本机安装和管理 Windows 版《Valheim》专用服务器的批处理文件。菜单提供安装 SteamCMD、安装或更新服务器、启动与停止服务器等操作;默认使用私有服务器,并在每次启动时备份角色和世界数据。

0浏览
0下载点击
0点赞
0收藏

关于这个 Mod

这是一个用于在本机安装和管理 Windows 版《Valheim》专用服务器的自定义批处理文件,适合与朋友共享本地世界时改善游戏体验,也可用于运行或测试专用服务器。请阅读菜单提示并按步骤操作;它并非全自动的黑箱工具。

菜单操作

  • [0] 安装 SteamCMD(首次安装时需要;完成后按提示退出)
  • [1] 安装或更新本地《Valheim》专用服务器
  • [2] 启动服务器
  • [3] 停止服务器
  • [9] 退出

功能与默认设置

  • 批处理文件可放在系统任意位置运行。
  • 默认使用私有服务器;需要将 IP 和端口 2456 告知朋友。若要改为公开服务器,可将 public 0 改为 public 1。
  • 可编辑文件以运行不同的本地世界,也可在不同世界间切换。
  • 每次启动批处理文件时,会将角色和世界数据备份到“文档”目录。作者说明可编辑脚本移除此备份,并建议查看其帖子中的备份说明。
  • 菜单提供停止服务器的选项。若需要手动停止,可选中服务器终端窗口并按 Alt+F4。
  • 默认将 SteamCMD 安装到用户目录下的 steamcmd 文件夹;服务器安装到系统盘的 Program Files (x86)\Steam\steamapps\common\Valheim dedicated server\。
  • 使用说明写在脚本注释或菜单中。

测试本地服务器无需先修改文件,但作者建议至少修改密码、世界名称和服务器名称;这些设置也可以在测试后修改。默认密码为 12345,世界名称为 Dedicated,服务器名称为 MyServer。若找不到指定世界,脚本会以随机种子创建世界。

服务器也可以像客户端一样安装模组。

脚本内容与注意事项

以下为原文提供的批处理脚本。脚本注释说明,未处理路由器或防火墙上 2456-2458 端口范围的开放问题。启动服务器时,脚本会备份角色与世界数据;停止服务器的流程提示为软停止并保存。

:: 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
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
  • 版本:V0.1
  • 作者:Astrolan

来源与文件

  • 原作者:Astrolan
  • 原项目:ServerMgr Local
  • 文件:ServerMgrV0.1.zip(ID:7398)
  • 来源上传者:astrolan

文件说明

Please read the description for all the details, and see the code for usage!

前往 N 网打开所选文件。安装与下载要求以原作者及平台说明为准。

<!-- aoe-mods-source:nexusmods:valheim:1614 -->