Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux gsm #49

Closed
finalsolarflare opened this issue Feb 20, 2021 · 14 comments
Closed

Linux gsm #49

finalsolarflare opened this issue Feb 20, 2021 · 14 comments

Comments

@finalsolarflare
Copy link

When the game server is installed using Linux gsm it passes arguments to a defined executable, so it would be useful for run_bepinex.sh to correctly intercept them.

Hope this can be implemented for the next linux server release, or it helps anyone searching for guidance for v+ with linuxgsm.

Remove/modify the code which takes an argument to be executable name:
## Special case: if there is an arg, use that as executable path ...

Add this switch:

do
	case $arg in
	-name)
	argName=$2
	shift 2
	;;
	-password)
	argPassword=$2
	shift 2
	;;
	-port)
	argPort=$2
	shift 2
	;;
	-world)
	argWorld=$2
	shift 2
	;;
	-public)
	argPublic=$2
	shift 2
	;;
	esac
done

Replacing the following line allows us to start the server with the expected arguments passed by gsm:
"${PWD}/${executable_name}" -name "servername" -password "serverpassword" -nographics -batchmode -port 2456 -world "world"

Change to:
"${PWD}/${executable_name}" -name "${argName}" -password "${argPassword}" -port "${argPort}" -world "${argWorld}" -public "${argPublic}"

Update gsm config file located at:
~/lgsm/config-lgsm/vhserver/vhserver.cfg

Add
executable="./run_bepinex.sh"

Now ./vhserver start works as expected

Connect to the console if needed with:
tmux a -t vhserver

@That3DPrinterGuy
Copy link

That3DPrinterGuy commented Feb 20, 2021

Could you share what your file looks like? I've tried a few edits after " ## Special case: if there is an arg, use that as executable path ..." but nothing seems to be working so having a copy to look at and compare would be super helpful. Also could you share what your vhserver.cfg looks like?

Thank you for making this post btw, was pulling my hair out on how to add it to gsm, now only if i could get it to run. (Server starts but doesn't stay running and I'm not sure why)

@finalsolarflare
Copy link
Author

Could you share what " ## Special case: if there is an arg, use that as executable path ..." looks like on yours?

Thank you for making this post btw, was pulling my hair out on how to add it to gsm, now only if i could get it to run. (Server starts but doesn't stay running and I'm not sure why)

This is what I commented out:

## Special case: if there is an arg, use that as executable path
## Linux: arg is path to the executable
## MacOS: arg is path to the .app folder which we need to resolve to the exectuable
#if [ -n "$1" ]; then
#    case $os_type in
#        Linux*)
#            executable_path="$1"
#            #echo "executeable_path ${executable_path}"
#	    #exit 1
#            ;;
#        Darwin*)
#            # Special case: allow to specify path to the executable within .app
#            full_path_part=`echo "$1" | grep "\.app/Contents/MacOS"`
#            if [ -z "$full_path_part" ]; then
#                executable_name=`basename "$1" .app`
#                real_executable_name=`defaults read "$1/Contents/Info" CFBundleExecutable`
#                executable_path="$1/Contents/MacOS/${real_executable_name}"
#            else
#                executable_path="$1"
#            fi
#            ;;
#    esac
#fi

@That3DPrinterGuy
Copy link

That3DPrinterGuy commented Feb 20, 2021

I've done that/removed it at one point, what I'm having trouble with is what to do / where to put

"do
case $arg in
-name)
argName=$2
shift 2
;;
-password)
argPassword=$2
shift 2
;;
-port)
argPort=$2
shift 2
;;
-world)
argWorld=$2
shift 2
;;
-public)
argPublic=$2
shift 2
;;
esac
done "
When I add the above code (with Do/Done) and try to start the server it says (In red) Fail no server running on /tmp/tmux-1005/default

If I add the above code without the (Do/Done ((Leaving the rest of the Case code)) ) and start the server I get (in green) OK and looks to start. If I run details it'll show offline, looking at the log file I see "password to short" (zodm1) but I've tried "ThisLongPass" and still it quits on me with the same password to short error, I can share my log file if needed.

@finalsolarflare
Copy link
Author

Probably easier if I share the whole file

#!/bin/sh
# BepInEx running script
#
# This script is used to run a Unity game with BepInEx enabled.
#
# Usage: Configure the script below and simply run this script when you want to run your game modded.

# -------- SETTINGS --------
# ---- EDIT AS NEEDED ------

# EDIT THIS: The name of the executable to run
# LINUX: This is the name of the Unity game executable 
# MACOS: This is the name of the game app folder, including the .app suffix
executable_name="valheim_server.x86_64"

# The rest is automatically handled by BepInEx

# Whether or not to enable Doorstop. Valid values: TRUE or FALSE
export DOORSTOP_ENABLE=TRUE

# What .NET assembly to execute. Valid value is a path to a .NET DLL that mono can execute.
export DOORSTOP_INVOKE_DLL_PATH="${PWD}/BepInEx/core/BepInEx.Preloader.dll"

# ----- DO NOT EDIT FROM THIS LINE FORWARD  ------
# ----- (unless you know what you're doing) ------

if [ ! -x "$1" -a ! -x "$executable_name" ]; then
    echo "Please open run.sh in a text editor and configure executable name."
    exit 1
fi

doorstop_libs="${PWD}/doorstop_libs"
arch=""
executable_path=""
lib_postfix=""

os_type=`uname -s`
case $os_type in
    Linux*)
        executable_path="${PWD}/${executable_name}"
        lib_postfix="so"
        ;;
    Darwin*)
        executable_name=`basename "${executable_name}" .app`
        real_executable_name=`defaults read "${PWD}/${executable_name}.app/Contents/Info" CFBundleExecutable`
        executable_path="${PWD}/${executable_name}.app/Contents/MacOS/${real_executable_name}"
        lib_postfix="dylib"
        ;;
    *)
        echo "Cannot identify OS (got $(uname -s))!"
        echo "Please create an issue at https://github.com/BepInEx/BepInEx/issues."
        exit 1
        ;;
esac

## Special case: if there is an arg, use that as executable path
## Linux: arg is path to the executable
## MacOS: arg is path to the .app folder which we need to resolve to the exectuable
#if [ -n "$1" ]; then
#    case $os_type in
#        Linux*)
#            executable_path="$1"
#            #echo "executeable_path ${executable_path}"
#	    #exit 1
#            ;;
#        Darwin*)
#            # Special case: allow to specify path to the executable within .app
#            full_path_part=`echo "$1" | grep "\.app/Contents/MacOS"`
#            if [ -z "$full_path_part" ]; then
#                executable_name=`basename "$1" .app`
#                real_executable_name=`defaults read "$1/Contents/Info" CFBundleExecutable`
#                executable_path="$1/Contents/MacOS/${real_executable_name}"
#            else
#                executable_path="$1"
#            fi
#            ;;
#    esac
#fi

executable_type=`LD_PRELOAD="" file -b "${executable_path}"`;

case $executable_type in
    *64-bit*)
        arch="x64"
        ;;
    *32-bit*|*i386*)
        arch="x86"
        ;;
    *)
        echo "Cannot identify executable type (got ${executable_type})!"
        echo "Please create an issue at https://github.com/BepInEx/BepInEx/issues."
        exit 1
        ;;
esac

doorstop_libname=libdoorstop_${arch}.${lib_postfix}
export LD_LIBRARY_PATH="${doorstop_libs}":${LD_LIBRARY_PATH}
export LD_PRELOAD=$doorstop_libname:$LD_PRELOAD
export DYLD_LIBRARY_PATH="${doorstop_libs}"
export DYLD_INSERT_LIBRARIES="${doorstop_libs}/$doorstop_libname"

export templdpath=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH
export SteamAppId=892970

### finalsolarflare modifcation ###
argName="Valheim+"
argPassword="password"
argPort=2456
argWorld="world"
argPublic=1

for arg in "$@"
do
	case $arg in
	-name)
	argName=$2
	shift 2
	;;
	-password)
	argPassword=$2
	shift 2
	;;
	-port)
	argPort=$2
	shift 2
	;;
	-world)
	argWorld=$2
	shift 2
	;;
	-public)
	argPublic=$2
	shift 2
	;;
	esac
done

## "${PWD}/${executable_name}" -name "servername" -password "serverpassword" -nographics -batchmode -port 2456 -world "world"

"${PWD}/${executable_name}" -name "${argName}" -password "${argPassword}" -port "${argPort}" -world "${argWorld}" -public "${argPublic}"

export LD_LIBRARY_PATH=$templdpath

@That3DPrinterGuy
Copy link

Thank you so much for posting this, everything's working and v+ is working wonderfully.

@supermxn
Copy link

https://i.imgur.com/U06Octo.png

Seems like this appears on me

@finalsolarflare
Copy link
Author

finalsolarflare commented Feb 21, 2021

https://i.imgur.com/U06Octo.png

Seems like this appears on me

I think that error is related to binding the server port.
What does the file: ~/lgsm/config-lgsm/vhserver/vhserver.cfg look like? Should look similar to this

#### Game Server Settings ####
## Predefined Parameters | https://docs.linuxgsm.com/configuration/start-parameters
servername="Valheim+"
# Minimum password length is 5.
serverpassword="serverpassword"
port=2456
gameworld="${selfname}"
public=1

executable="./run_bepinex.sh"

@supermxn
Copy link

Same error with putting that as well. I am using Ubuntu 20.04.

@finalsolarflare
Copy link
Author

I used the following script to try and debug any problems with arguments that were being passed
new file: ~/serverfiles/run_test.sh

#!/bin/sh
for arg in "$@"
do
        case $arg in
                -name)
                servername=$2
                shift 2
                ;;
                -password)
                serverpassword=$2
                shift 2
                ;;
                -port)
                serverport=$2
                shift 2
                ;;
                -world)
                serverworld=$2
                -port)
                serverport=$2
                shift 2
                ;;
                -world)
                serverworld=$2
                shift 2
                ;;
                -public)
                serverpublic=$2
                shift 2
                ;;
        esac
done
echo "vars passed... \n"
echo " -name '${servername}' -password '${serverpassword}' -port '${serverport}' -world '${serverworld}' -public '${serverpublic}'"
while :; do sleep 3600; done;

change lgsm config lgsm/config-lgsm/vhserver/vhserver.cfg
commenting bepinex executable to run_test.sh instead

# executable="./run_bepinex.sh"
executable="./run_test.sh"
  • ./vhserver start
  • tmux a -t vhserver

shows what arguments are being passed

@gOOvER
Copy link

gOOvER commented Feb 22, 2021

-public 1 was removed and is not longer used

@sirskunkalot
Copy link
Contributor

sirskunkalot commented Feb 22, 2021

Hey, I am writing on a PR that is incorporating am automatic publish system for V+ builds, UnixServer included. I did something similar to this with run_bepinex.sh and would deploy that script on release. I will also add some code which tries to identify (or guess ;)) if it is run within LGSM and act accordingly.

All one needs to do is changing the default.cfg or instance.cfg in LGSM. But maybe we can get them to include some magic into LGSM, too...

@finalsolarflare
Copy link
Author

I was making it more complicated than it needs to be.
Updated for version 0.8.5 - update the file start_server_bepinex.sh with the following (comment for reference)...

#./valheim_server.x86_64 -name "My server" -port 2456 -world "Dedicated" -password "secret"
./valheim_server.x86_64 "${@}"

Change lgsm config located at ~/lgsm/config-lgsm/vhserver/vhserver.cfg add the following

executable="./start_server_bepinex.sh"

@sirskunkalot
Copy link
Contributor

Your version is fine if you want to be LGSM-neutral. Add your params to the run-script or get any of them fomr the arguments.

@nxPublic
Copy link
Member

Our start.sh for 0.9.6 should be working on any system now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants