Pryaxis / TShock

☕️⚡️TShock provides Terraria servers with server-side characters, anti-cheat, and community management tools.
GNU General Public License v3.0
2.43k stars 382 forks source link

server crashes on latest release immediately after start #965

Closed sariyamelody closed 9 years ago

sariyamelody commented 9 years ago

sorry for weird formatting, I grabbed this straight from docker logs

[TShock] Info Config path has been set to /opt/terraria/config/
[TShock] Info Log path has been set to /opt/terraria/logs
Port overridden by startup argument. Set to 7777
TShock 4.3.1.0 (Yoraiz0r R0cks) now running.
AutoSave Enabled
Backups Disabled
Welcome to TShock for Terraria. Initialization complete.
[Server API] Info Plugin TShock v4.3.1.0 (by The TShock Team) initiated.
^[[38;1R^[[26;1R^[[26;1R^[[20;1R^[[26;1R^[[26;1R[Server API] Error Server crashed due to an unhandled exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at Terraria.NPC.SetDefaults (Int32 Type, Single scaleOverride) [0x00000] in <filename unknown>:0
  at Terraria.NPC.SetDefaults (System.String Name) [0x00000] in <filename unknown>:0
  at Terraria.NPC.netDefaults (Int32 type) [0x00000] in <filename unknown>:0
  at Terraria.Main.InitLifeBytes () [0x00000] in <filename unknown>:0
  at Terraria.Main.Initialize () [0x00000] in <filename unknown>:0
  at Terraria.Main.DedServ () [0x00000] in <filename unknown>:0

running on what is effectively latest Ubuntu, Dockerfile is https://github.com/skyhighwings/dockerfiles/blob/master/games/terraria-tshock/Dockerfile and start script is https://github.com/skyhighwings/dockerfiles/blob/master/games/terraria-tshock/start-service

for convenience, the start script:

#!/bin/bash

TERRARIA_WORLD_SIZE=3
TERRARIA_WORLD_NAME=terraria.wld

cd /opt/terraria/
sudo -u terraria mono --server --gc=sgen -O=all TerrariaServer.exe -port 7777 -autocreate "$TERRARIA_WORLD_SIZE" -world "/opt/terraria/worlds/$TERRARIA_WORLD_NAME" -configpath /opt/terraria/config/ -logpath /opt/terraria/logs
sariyamelody commented 9 years ago

It seems like the issue is that -worldpath and -world are no longer respected. Because of this, the container was not able to know that TShock wanted the files to live in /home/terraria/My Games/Terraria/Worlds, and so it simply failed with a cryptic error.

Reproduction steps:

Is there any way to support the -worldpath command line option again?

sariyamelody commented 9 years ago

lol ignore the above it was stupid

Anyways, there's an actual issue in which the server will crash in two circumstances:

  1. -world is specified and there is nothing there, even if there -autocreate is specified
  2. everything is fine, but $HOME/My Games/Terraria/favorites.json cannot be created

(2) is a problem in my specific case because I'm not running it in a "normal desktop linux environment" but as a daemon run in Docker in a limited container that does not have a home directory for the user that mono (and, by extension, TerrariaServer.exe) are being run under. It would be really nice if favorites.json was defaulted to being searched for in the configpath instead, as that's where I'd expect to be able to edit a json file.

sariyamelody commented 9 years ago

the simplest repro possible for (1) above is:

Windows:

$ rm test.wld
$ TerrariaServer.exe -autocreate 3 -world test.wld

Linux:

$ mono --server --gc=sgen -O=all TerrariaServer.exe -world test.wld -autocreate 3

(argument order does not matter)

sariyamelody commented 9 years ago

current workaround:

$HOME/My Games/Terraria/ must exist and be editable by the user that the server will be run by

the world you want to run must exist, or must be manually created in the GUI (-autocreate will not work if you specify -world)

Ijwu commented 9 years ago

Suggestion: Add command line flag for config path or change its default path.

sariyamelody commented 9 years ago

@Ijwu there is actually -configpath which defaults to the directory of TerrariaServer.exe, I believe

src: https://tshock.atlassian.net/wiki/display/TSHOCKPLUGINS/Command+Line+Parameters

hakusaro commented 9 years ago

I just spent an hour or so debugging. I'm not sure how to resolve this either. This is caused when the server enters the DedServer() code path, and nulls out because for some reason it tries to read the difficulty of the world from the non-existent world.

            this.Initialize();
            Lang.setLang(false);
            for (int i = 0; i < 540; i++)
            {
                NPC nPC = new NPC();
                nPC.SetDefaults(i, -1f);
                Main.npcName[i] = nPC.name;
            }

I'm not sure where a good place to put that code is, and I'm not sure a good way around it.