Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mgeitz
Last active March 30, 2024 00:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgeitz/aa295061c51b26d53dd818d0ebb3e37a to your computer and use it in GitHub Desktop.
Save mgeitz/aa295061c51b26d53dd818d0ebb3e37a to your computer and use it in GitHub Desktop.
Linux Project 1999 Launch Manager
#! /bin/bash
#
# Linux Project 1999 Launch Manager
# * Manage logs
# * Launch eqemu-login-helper
# * Launch Project 1999
# * Cleanup
# Dependecies:
# - https://github.com/Zaela/eqemu-login-helper/
#
# Things worth changing
EQEMU_SERVER="P1999Green"
CORES="0-1"
MAXLOGLEN=100000
EQEMU_PATH=$HOME/.wine/drive_c/Program\ Files/Sony/EverQuest
EQEMU_LOGIN=$HOME/app/eqemu-login-helper/bin/eqemu-login-helper
# Colors
CYAN='\e[0;36m'
LIGHT_GREEN='\e[1;32m'
LIGHT_RED='\e[1;31m'
YELLOW='\e[1;33m'
NC='\e[0m'
# Functions
## Ctrl+C safety
function ctrlc() {
echo -e "\n${CYAN}Emergency Shutdown${NC} ..."
popd &>/dev/null
### Stop eqemu-login-helper
if pgrep -f eqemu-login-helper > /dev/null; then
echo -e "\n ${CYAN}Stopping Login Server${NC} ..."
/bin/kill -6 $(pgrep -f eqemu-login-helper) &>/dev/null
echo -e " ${LIGHT_RED}DOWN${NC}"
fi
### Stop EverQuest
if pgrep -f eqgame.exe > /dev/null; then
echo -e " ${CYAN}Stopping EverQuest${NC} ..."
/bin/kill -6 $(pgrep -f eqgame.exe) &>/dev/null
echo -e " ${LIGHT_RED}DOWN${NC}"
else
echo -e " ${CYAN}EverQuest Already Stopped${NC} ..."
echo -e " ${LIGHT_RED}DOWN${NC}"
fi
echo -e "\n ${LIGHT_GREEN}DONE${NC}"
echo -e "\n${CYAN}Exiting${NC} ...\n"
exit 0
}
trap ctrlc SIGINT
## P99 ASCII Splash
function p99_ascii() {
echo -e "${CYAN}Launching${NC} ..."
echo -e " _ _ ${YELLOW} __ ___ ___ ___${NC}"
echo -e " (_) | | ${YELLOW}/_ |/ _ \\ / _ \\ / _ \\ ${NC}"
echo -e " _ __ _ __ ___ _ ___ ___| |_ ${YELLOW}| | (_) | (_) | (_) |${NC}"
echo -e " | '_ \\| '__/ _ \\| |/ _ \/ __| __| ${YELLOW} | |\\__, |\\__, |\\__, |${NC}"
echo -e " | |_) | | | (_) | | __/ (__| |_ ${YELLOW} | | / / / / / /${NC}"
echo -e " | .__/|_| \\___/| |\\___|\\___|\\__| ${YELLOW} |_| /_/ /_/ /_/${NC}"
echo -e " | | _/ |"
echo -e " |_| |__/\n\n"
}
## Manage Logs
function manage_logs() {
echo -e "${CYAN}Log Summary${NC} ...\n"
for log_file in $(IFS=$'\n' find "$EQEMU_PATH"/Logs/ -type f -name "eqlog_*_${EQEMU_SERVER}.txt" -printf '%f\n')
do
### Read the log file
char_server=$(echo $log_file | sed 's .\{6\} ;s/.\{4\}$//')
char=$(echo $char_server | cut -d '_' -f1)
log_lines=$(wc -l < "$EQEMU_PATH/Logs/$log_file")
printf -v log_lines "%06d" $log_lines
### If the log is long,
if [ $log_lines -gt $MAXLOGLEN ]; then
#### create a user directory
if [ ! -d "$EQEMU_PATH/Logs/archived/$EQEMU_SERVER/$char" ]; then
mkdir -p "$EQEMU_PATH/Logs/archived/$EQEMU_SERVER/$char"
fi
#### and archive the log
mv "$EQEMU_PATH/Logs/$log_file" "$EQEMU_PATH/Logs/archived/${EQEMU_SERVER}/$char/$char_server-$(date +%Y-%m-%d)"
touch "$EQEMU_PATH/Logs/$log_file"
echo -e " ${CYAN}»${NC} $log_lines ${YELLOW}$char${NC} ${LIGHT_RED}∑ Archived${NC}"
else
echo -e " ${CYAN}»${NC} $log_lines ${YELLOW}$char${NC}"
fi
done
}
## Launch eqemu-login-helper
function start_login_helper() {
### If eqemu-login-helper is already running, do nothing
if pgrep -f eqemu-login-helper > /dev/null; then
echo -e "\n${LIGHT_RED}Login Server Already Running${NC} ..."
### otherwise start eqemu-login-helper
else
echo -e "\n${CYAN}Starting Login Server${NC} ..."
/bin/bash -c "$EQEMU_LOGIN &"
echo -e " ${LIGHT_GREEN}UP${NC}\n"
fi
}
## Stop eqemu-login-helper
function stop_login_helper() {
### If eqemu-login-helper is already running, stop it
if pgrep -f eqemu-login-helper > /dev/null; then
echo -e "${CYAN}Stopping Login Server${NC} ..."
/bin/kill -6 $(pgrep -f eqemu-login-helper) &>/dev/null
echo -e " ${LIGHT_RED}DOWN${NC}"
### otherwise do nothing
else
echo -e "${LIGHT_RED}Login Server Already Stopped${NC} ..."
echo -e " ${LIGHT_RED}DOWN${NC}"
fi
}
## Launch EverQuest
function start_p99() {
### If EQ is already running, do nothing
if pgrep -f eqgame.exe > /dev/null; then
echo -e "${LIGHT_RED}EverQuest Already Running${NC} ..."
### otherwise start p99 with a splash
else
p99_ascii
pushd "$EQEMU_PATH" &>/dev/null
taskset -c $CORES wine eqgame.exe patchme &>/dev/null
popd &>/dev/null
fi
}
## Clean Up
function clean_up() {
echo -e "${CYAN}Cleaning up${NC} ...\n"
stop_login_helper
}
# Launch Manager
clear
echo -e "${CYAN}Starting up${NC} ...\n"
manage_logs
start_login_helper
start_p99
clean_up
echo -e "\n${CYAN}Exiting${NC} ...\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment