[CENTOS] [Python] I want to manage 7DaysToDie from Discord! 1/3

Overview

[Python] I want to manage 7DaysToDie from Discord! 1/3 (Environment construction) [Python] I want to manage 7DaysToDie from Discord! 2/3 (Creating a BOT that can be managed from Discord) [Python] I want to manage 7DaysToDie from Discord! 3/3 (operation check)

About the background

I used to want to write a program that can manage Minecraft from Discord, This time I decided to do 7 Days on Steam, so I made it as if I could do it on 7 Days.

Originally it was troublesome, and opening the console screen and managing it was also troublesome. There are times when you want to leave the operation to a sub-tube other than yourself. I came to the production for some reason.

About this program

This program uses Discord Bot and Discord Webhook. Also, I'm still learning Python ~~ with the idea of having fun ~~. If you have any other opinions such as better program writing or blog improvement points, please comment and it will be encouraging.

Prerequisites

--Basic Unix knowledge and command can be used. --Have a basic knowledge of Python. (I'm going to write it so that it works almost with copy and paste without it) -Discord must be installed --Discord's API must be available. (Must have Bot installed)

Operating environment

--Use Python3.6.9 (works for 3 series)

Directory structure


$HOME/
   ┝ python/
          ┕ discord/
                 ┝ sdtd_run.py
                 ┝ sdtd_start.sh
                 ┕ Sdtd/
                     ┕ command.py
   ┝ steamcmd
          ┝ linux32
          ┝ linux64 
          ┝ .... //The following default directories
┕ sdtd ← This is the directory used this time.

Installation of libraries required for implementation

//Used with steamcmd
# yum -y install glibc.i686 libstdc++.i686

//Used on discord
# yum -y install libffi-dev libnacl-dev python3-dev

//Used in python programs
# yum -y install screen lsof awk
# pip install discord.py requests

Firewalld settings

Make a hole in the port to be used.

# firewall-cmd --permanent --add-port=26900/tcp
# firewall-cmd --permanent --add-port=26900-2603/udp
# firewall-cmd --reload

DL & IN 7 Days To Die from SteamCMD


//Work as a general user from the following.
$ mkdir steamcmd
$ cd steamcmd/
$ curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxf -
$ ./steamcmd.sh
Steam>login anonymous
Steam>force_install_dir sdtd
Steam>app_update 294420 validate
Steam>quit

Edit startserver.sh for 7DaysToDie

$ cd sdtd
$ vim startserver.sh

startserver.sh


#!/bin/sh
SERVERDIR=`dirname "$0"`
cd "$SERVERDIR"

PARAMS=$@

CONFIGFILE=
while test $# -gt 0
do
    if [ `echo $1 | cut -c 1-12` = "-configfile=" ]; then
        CONFIGFILE=`echo $1 | cut -c 13-`
    fi
    shift
done

if [ "$CONFIGFILE" = "" ]; then
    PARAMS="-configfile=serverconfig.xml"
else
    if [ -f "$CONFIGFILE" ]; then
        echo Using config file: $CONFIGFILE
    else
        echo "Specified config file $CONFIGFILE does not exist."
        exit 1
    fi
fi

export LD_LIBRARY_PATH=.
#export MALLOC_CHECK_=0

if [ "$(uname -m)" = "x86_64" ]; then
    ./7DaysToDieServer.x86_64 -logfile $SERVERDIR/7DaysToDieServer_Data/logs/output_log__`date +%Y-%m-%d__%H-%M-%S`.txt -quit -batchmode -nographics -dedicated $PARAMS
else
    echo "7 Days to Die only supports 64 bit operating systems!"
    exit 1
fi

Edit serverconfig.xml

vim serverconfig.xml

Since Telnet is used for console operation, description is required. (Because it is localhost, it is OK without a path) The port should be 8081. There is no need to open the port.

serverconfig.xml


    <property name="TelnetEnabled"                  value="true"/>              <!-- Enable/Disable the telnet -->
    <property name="TelnetPort"                     value="8081"/>              <!-- Port of the telnet server -->
    <property name="TelnetPassword"                 value=""/>                  <!-- Password to gain entry to telnet interface. If no password is set the server will only listen on the local loopback interface -->

That is all for building the environment. Next, let's do Main Implementation!

Recommended Posts

[Python] I want to manage 7DaysToDie from Discord! 1/3
[Python] I want to manage 7DaysToDie from Discord! 2/3
I want to use jar from python
I want to email from Gmail using Python.
I want to use ceres solver from python
I want to make C ++ code from Python code!
[Python3] I want to generate harassment names from Japanese!
I want to debug with Python
I want to start a lot of processes from python
I want to send a message from Python to LINE Bot
I want to build a Python environment
I want to analyze logs with Python
I want to play with aws with python
I want to connect to PostgreSQL from various languages
I want to do Dunnett's test in Python
I want to use MATLAB feval with python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
I want to memoize including Python keyword arguments
I want to perform SageMaker inference from PHP
I want to make a game with Python
[Python memo] I want to get a 2-digit hexadecimal number from a decimal number
I want to merge nested dicts in Python
I want to make fits from my head
I want to manage systemd by time zone! !!
I want to use Temporary Directory with Python2
#Unresolved I want to compile gobject-introspection with Python3
I want to solve APG4b with Python (Chapter 2)
What I did when updating from Python 2.6 to 2.7
I want to sell Mercari by scraping python
I want to write to a file with Python
I want to display the progress in Python!
I want to get / execute variables / functions / classes of external files from Python
I want to write in Python! (1) Code format check
I want to see the file name from DataLoader
Even beginners want to say "I fully understand Python"
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to detect images of cats from Instagram
I want to iterate a Python generator many times
I want to generate a UUID quickly (memorandum) ~ Python ~
I want to handle optimization with python and cplex
[Python] I want to merge Excel files anyway (pandas.merge)
I want to write in Python! (2) Let's write a test
Even in JavaScript, I want to see Python `range ()`!
I wanted to use the Python library from MATLAB
I want to randomly sample a file in Python
I want to inherit to the back with python dataclass
I want to work with a robot in python.
[Python] I want to make a nested list a tuple
I want to write in Python! (3) Utilize the mock
I want to AWS Lambda with Python on Mac!
[ML Ops] I want to do multi-project with Python
I want to use the R dataset in python
I want to run a quantum computer with Python
I want to do something in Python when I finish
I want to manipulate strings in Kotlin like Python!
Post from Python to Slack
Cheating from PHP to Python
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
I want to solve Sudoku (Sudoku)