LoginSignup
0
0

More than 3 years have passed since last update.

【Python】7DaysToDieをDiscordから管理したい! 1/3

Last updated at Posted at 2020-07-12

概要

【Python】7DaysToDieをDiscordから管理したい! 1/3 (環境構築)
【Python】7DaysToDieをDiscordから管理したい! 2/3 (Discordから管理できるBOTの作成)
【Python】7DaysToDieをDiscordから管理したい! 3/3 (動作チェック)

GitHubに保管しました。
https://github.com/Trusted-Dream/7DaysToDie_Launcher

経緯について

以前はMinecraftをDiscordから管理できるプログラムを書いていたいのですが、
今回はSteamの7Daysをやることになったので、7Daysでもできないかということで作りました。

元々面倒くさがりで、コンソール画面を開いて管理するのも面倒で、
自分以外の副管に操作を任せたい時がある。等々の理由で製作に至りました。

本プログラムについて

このプログラムはDiscord BotとDiscord Webhookを使用しています。
また現在も楽しよう楽しようの考えで Pythonの学習を続けています。
もっと良いプログラム書き方やブログの改善点等、他意見があれば是非コメント下さると励みになります。

前提条件

  • 基本的なUnix系の知識、コマンドを使用できること。
  • Pythonの基礎知識があること。(なくてもほぼコピペで動くようには書くつもり)
  • Discordを導入していること
  • DiscordのAPIが利用できること。(Bot導入済みであること)

動作環境

  • Python3.6.9 使用(3系なら動く)
  • CentOS Linux release 7.8.2003 (Core)

ディレクトリ構造


$HOME/
   ┝ python/
          ┕ discord/
                 ┝ sdtd_run.py
                 ┝ sdtd_start.sh
                 ┕ Sdtd/
                     ┕ command.py
   ┝ steamcmd
          ┝ linux32
          ┝ linux64 
          ┝ .... //以下デフォルトのディレクトリ群
          ┕ sdtd ← これが今回使用するディレクトリになります。

実装に必要なライブラリ等のインストール

//steamcmdで使用
# yum -y install glibc.i686 libstdc++.i686

//discordで使用
# yum -y install libffi-dev libnacl-dev python3-dev

//pythonプログラムで使用
# yum -y install screen lsof awk
# pip install discord.py requests

Firewalldの設定

使用するポートの穴あけを行ってください。

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

SteamCMDから7DaysToDieをDL&IN


//以下から一般ユーザーで作業を行います。
$ 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

7DaysToDieのstartserver.shの編集

$ 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

serverconfig.xmlの編集

vim serverconfig.xml

コンソール操作にTelnetを使用するので記述が必要です。(localhostだからパスなしでOK)
ポートは8081としてください。ポート開放の必要はありません。

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 -->

環境構築は以上です。続いてメインの実装を行っていきましょう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0