summaryrefslogtreecommitdiff
path: root/herculeswrapper
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2022-10-23 23:45:19 -0300
committerJesusaves <cpntb1@ymail.com>2022-10-23 23:45:19 -0300
commitc2ccb14ffff0e45398365e19dfd2874307ddb943 (patch)
tree976eaea586fb8f1ee0ab8cae67c69071aed8b952 /herculeswrapper
downloadtools-c2ccb14ffff0e45398365e19dfd2874307ddb943.tar.gz
tools-c2ccb14ffff0e45398365e19dfd2874307ddb943.tar.bz2
tools-c2ccb14ffff0e45398365e19dfd2874307ddb943.tar.xz
tools-c2ccb14ffff0e45398365e19dfd2874307ddb943.zip
Initial commit
Diffstat (limited to 'herculeswrapper')
-rwxr-xr-xherculeswrapper/char.sh7
-rw-r--r--herculeswrapper/herc-map-wrapper-config.example77
-rw-r--r--herculeswrapper/include.sh56
-rwxr-xr-xherculeswrapper/login.sh7
-rwxr-xr-xherculeswrapper/map.sh52
5 files changed, 199 insertions, 0 deletions
diff --git a/herculeswrapper/char.sh b/herculeswrapper/char.sh
new file mode 100755
index 0000000..2b794d9
--- /dev/null
+++ b/herculeswrapper/char.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+export PIPE=./log/charpipe.tmp
+
+source ${dir}/include.sh
+
+server_logic ./char-server 2s
diff --git a/herculeswrapper/herc-map-wrapper-config.example b/herculeswrapper/herc-map-wrapper-config.example
new file mode 100644
index 0000000..67a70a0
--- /dev/null
+++ b/herculeswrapper/herc-map-wrapper-config.example
@@ -0,0 +1,77 @@
+## config for herc-map-wrapper
+
+echo "Copy this file to herc-map-wrapper-config" >&2
+echo "Then You need to either set the oauth secret" >&2
+echo "or use a hard-coded list instead of list_issues" >&2
+echo "Both github and gitlab methods are included.">&2
+echo "Make sure to comment out the method that isn't used" >&2
+echo "Update the <repo ids> with the ID number for gitlab" >&2
+echo "or the repo name if github i.e. themanaworld/server-data" >&2
+echo "Then, delete these lines" >&2
+exit 1
+
+server_data=../../server-data
+client_data=../client-data
+evol_music=../music
+tmw_tools=../tools
+
+#gitlab
+list_issues()
+{
+python -c '
+
+# replace this with one of your oauth keys from github (no permissions needed)
+oauth = "01234567890123456789"
+
+import requests
+issues = requests.get("https://git.themanaworld.org/api/v3/projects/%d/merge_requests" % '$1', params={"state": "opened"}, headers={"PRIVATE-TOKEN": "%s" % oauth, "Accept": "application/vnd.gitlab.v3+json"})
+issues.raise_for_status()
+for issue in issues.json():
+ if "test" in issue["labels"]:
+ print(issue["iid"])
+' | sort -n
+}
+
+#github
+list_issues()
+{
+python -c '
+
+# replace this with one of your oauth keys from github (no permissions needed)
+oauth = "0123456789abcdef0123456789abcdef01234567"
+
+import requests
+issues = requests.get("https://api.github.com/search/issues", params={"q": "repo:'$1' type:pr state:open label:test"}, headers={"Authorization": "token %s" % oauth, "Accept": "application/vnd.github.v3+json"})
+issues.raise_for_status()
+for issue in issues.json["items"]:
+ print(issue["number"])
+' | sort -n
+}
+
+
+server_main_branch=origin/master
+
+server_extra_branches=(
+ $(list_issues <repo id> | sed 's|^|origin/merge-requests/|;')
+)
+
+client_main_branch=origin/master
+
+client_extra_branches=(
+ $(list_issues <repo id> | sed 's|^|origin/merge-requests/|;')
+)
+
+music_main_branch=origin/master
+
+music_extra_branches=(
+ $(list_issues <repo id> | sed 's|^|origin/merge-requests/|;')
+)
+unset list_issues
+
+motd=../server-data/npc/commands/motd-debug-text.txt
+
+expected_life=60
+trouble_sleep=60
+normal_sleep=5
+
+ulimit -c unlimited
diff --git a/herculeswrapper/include.sh b/herculeswrapper/include.sh
new file mode 100644
index 0000000..97325f8
--- /dev/null
+++ b/herculeswrapper/include.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+
+function create_pipe {
+ trap "rm -f $PIPE" EXIT
+ if [[ ! -p $PIPE ]]; then
+ echo "Making pipe $PIPE"
+ rm -f $PIPE
+ mkfifo $PIPE
+ fi
+}
+
+# $1 - text
+function send_all_pipes {
+ echo $1 >$LOGIN_PIPE
+ echo $1 >$CHAR_PIPE
+}
+
+# $1 - text
+function send_char_pipe {
+ echo $1 >$CHAR_PIPE
+}
+
+# $1 - server binary name
+# $2 - sleep time
+function server_logic {
+ create_pipe
+ $1
+
+ while true
+ do
+ if read line <$PIPE; then
+ echo pipe: $line
+ if [[ "$line" == 'exit' ]]; then
+ exit
+ fi
+ if [[ "$line" == 'restart' ]]; then
+ sleep $2
+ $1
+ fi
+ fi
+ done
+}
+
+function pull_all {
+ ls
+ # Update Server Data
+ cd ../
+ ./pull.sh force
+ # Update Client Data
+ cd testserver
+ ./pseudo_update.sh
+ cd ..
+ # Return to server data
+ cd server-data
+}
+
diff --git a/herculeswrapper/login.sh b/herculeswrapper/login.sh
new file mode 100755
index 0000000..32085dd
--- /dev/null
+++ b/herculeswrapper/login.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+export PIPE=./log/loginpipe.tmp
+
+source ${dir}/include.sh
+
+server_logic ./login-server 0s
diff --git a/herculeswrapper/map.sh b/herculeswrapper/map.sh
new file mode 100755
index 0000000..67c5147
--- /dev/null
+++ b/herculeswrapper/map.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+export PIPE=./log/mappipe.tmp
+export LOGIN_PIPE=./log/loginpipe.tmp
+export CHAR_PIPE=./log/charpipe.tmp
+
+source ${dir}/include.sh
+
+create_pipe
+
+while [ 1 ] ; do
+ ./map-server
+ export ret=$?
+ case "${ret}" in
+ 0)
+ echo "Returned 0. Probably ctrl+c"
+ break
+ ;;
+ 1)
+ echo "Returned 1. Probably error in server"
+ break
+ ;;
+ 100)
+ echo "Terminating server"
+ send_all_pipes "exit"
+ break
+ ;;
+ 101)
+ echo "Restarting all servers..."
+ send_all_pipes "restart"
+ sleep 7s
+ ;;
+ 102)
+ echo "Restarting char and map servers..."
+ send_char_pipe "restart"
+ sleep 5s
+ ;;
+ 103)
+ echo "Restarting map server..."
+ ;;
+ 104)
+ echo "git pull..."
+ pull_all
+ echo "Restarting all servers..."
+ send_all_pipes "restart"
+ sleep 7s
+ ;;
+ esac
+done
+
+killall logmaster.py
+