一个问题是,在
结束时,某些东西崩溃试图调用createserver.batdel %USERPROFILE%\Desktop\TerrariaServer\filebin\serverparams.cmd
wget http://***/serverparams.cmd
call serverparams.cmd
IF name==default (
del %USERPROFILE%\Desktop\TerrariaServer\filebin\serverparams.cmd
call senderror.bat
) ELSE (
randomport -default -defaut -default
timeout /t 1
)
IF NOT name==default (
sysresourceoutput
timeout /t 5
call sysresources
IF %ram% GTR 1600 (
call %USERPROFILE%\Desktop\TerrariaServer\createserver.bat
)
)
虽然createserver.bat单独运行良好。
另一个问题是使用上面的方法来连接调用serverparams.cmd ..或者设置serverparams值的设置值,尽管通过下面的startserver中的一系列命令运行它是a-ok(在基本目录中) )。
call setname.cmd
call setvars.cmd
set path=%USERPROFILE%\desktop\TerrariaServer
ECHO set port=%var1% >%path%\%name%_set.cmd
ECHO set players=%var2% >>%path%\%name%_set.cmd
ECHO set autocreate=%var3% >>%path%\%name%_set.cmd
ECHO set worldname=%var4% >>%path%\%name%_set.cmd
ECHO set password=%var5% >>%path%\%name%_set.cmd
ECHO set motd=%var6% >>%path%\%name%_set.cmd
ECHO set lang=%var7% >>%path%\%name%_set.cmd
ECHO set priority=%var8% >>%path%\%name%_set.cmd
ECHO set name=%name% >>%path%\%name%_set.cmd
call %name%_set.cmd
ECHO maxplayers=%players% >%path%\%name%_config.txt
ECHO world=%USERPROFILE%\Documents\My Games\Terraria\Worlds\%worldname%.wld >>%path%\%name%_config.txt
ECHO port=%port% >>%path%\%name%_config.txt
ECHO password=%password% >>%path%\%name%_config.txt
ECHO motd=%motd% >>%path%\%name%_config.txt
ECHO worldpath=%USERPROFILE%\Documents\My Games\Terraria\Worlds\ >>%path%\%name%_config.txt
ECHO secure=1 >>%path%\%name%_config.txt
ECHO lang=%lang% >>%path%\%name%_config.txt
ECHO upnp=0 >>%path%\%name%_config.txt
ECHO #npcstream=60 >>%path%\%name%_config.txt
ECHO priority=%priority% >>%path%\%name%_config.txt
ECHO IF EXIST "%USERPROFILE%\Documents\My Games\Terraria\Worlds\%worldname%" ( >%path%\%name%_start.bat
ECHO TerrariaServer -config %path%\%name%_config.txt >>%path%\%name%_start.bat
ECHO ) ELSE ( >>%name%_start.bat
ECHO TerrariaServer -config %path%\%name%_config.txt -port %port% -players %players% -world "%USERPROFILE%\Documents\My Games\Terraria\Worlds\%worldname%.wld" -autocreate %autocreate% -worldname %worldname%.wld >>%path%\%name%_start.bat
ECHO ) >>%path%\%name%_start.bat
call %path%\%name%_start.bat
我的问题是,我有什么细微差别吗?我认为有一种更动态的方式来列出一组递增变量,而不是手动命名它们var01,var02
此外,它在%worldname%之后添加了一个空格,但我很满意。
答案 0 :(得分:1)
这样的行永远不会执行,因为没有要评估的%变量%,它正在比较不相同的静态字符串。
IF name==default (
当用户个人资料中包含空格或&字符。解决方案是将整个“path \ filename”括在双引号中:
del "%USERPROFILE%\Desktop\TerrariaServer\filebin\serverparams.cmd"
应该编辑这样的行以包括行开头的重定向。这解决了每一行末尾的空格。
ECHO set port=%var1% >%path%\%name%_set.cmd
以这种方式重写行并删除尾随空格
>"%path%\%name%_set.cmd" ECHO set port=%var1%
>>"%path%\%name%_set.cmd" ECHO set players=%var2%
包含双引号以满足长路径名\文件名元素,并将%path%name更改为其他名称,因为PATH
是系统变量,使用它会破坏所有内容。