<game_config>
 <game_key>epochmod_win32</game_key>
 <installer>steamcmd</installer>
 <game_name>DayZ Epoch Mod</game_name>
 <server_exec_name>arma2oaserver.exe</server_exec_name>
 <cli_template>%MODLIST% -cfg=cfg\basic.cfg -config=cfg\server.cfg -name=dayz -profiles=cfg %IP% %PORT%</cli_template>
 <cli_params>
  <cli_param id="PORT" cli_string="-port=" />
  <cli_param id="IP" cli_string="-ip=" />
 </cli_params>
<reserve_ports>
    <port type="add" id="QUERY_PORT">1</port>
 </reserve_ports>
<cli_allow_chars>;</cli_allow_chars>

<console_log>cfg/arma2oaserver.RPT</console_log>
<max_user_amount>64</max_user_amount>
 <control_protocol>armabe</control_protocol>
 <mods>
 <mod>
   <name>none</name>
   <installer_name>33930</installer_name>
  </mod>
 </mods>
 <replace_texts>

  <text key="max_players">
   <default>(maxPlayers\s*=\s*)(.*)(;)</default>
   <var>maxPlayers = "%key%";</var>
   <filepath>cfg/server.cfg</filepath>
   <options>key-regex</options>
  </text>

 <text key="port">
    <default>Port =.*</default>
    <var>Port = %key% </var>
    <filepath>bec/config/config.cfg</filepath>
    <options>key-regex</options>
   </text>
 <text key="ip">
    <default>Ip =.*</default>
    <var>Ip = %key% </var>
    <filepath>bec/config/config.cfg</filepath>
    <options>key-regex</options>
   </text>
<text key="home_path">
    <default>BePath =.*</default>
    <var>BePath = %key%/cfg/Battleye</var>
    <filepath>bec/config/config.cfg</filepath>
    <options>key-regex</options>
   </text>

 </replace_texts>

<server_params>


 <param id="MODLIST" key="-mod=" type="text">
<default>@dayz_epoch;@epochserver;</default>
<option>ns</option>
 <caption>Mods ex: @dayz;@hive or @dayz_epoch;@dayz_epoch_server</caption>
 <desc>Semicolon after each mod and you MUST copy the KEY into your keys folder. 
Make sure if you install a MOD, you list the name here or else it wont get loaded.
 </desc>
 </param>
</server_params>

<post_install>
mkdir -p ./cfg
touch ./cfg/epochmod_win32.xml
wget http://files.iaregamer.com/gamefiles/arma2Addons.tar .
wget http://files.iaregamer.com/gamefiles/epochmod.tar .
tar -xvf arma2Addons.tar
tar -xvf epochmod.tar

#Create Database ---------------------------------------

dbPass=$(&lt;/dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8)
srvID=${PWD##*/}
dbID=server_${srvID}
mysqlServerID=2

# Panel DB connection (where gsp_mysql_servers / gsp_mysql_databases live)
panelDB=panel
panelPrefix=gsp_
panelHost=mysql.iaregamer.com
panelPort=3306
panelUser=remoteuser
panelPass=Pkloyn7yvpht!

# Resolve target game DB server/profile from panel metadata (default: mysql_server_id=2 -> MySQL 5.7)
mysqlProfile=$(mysql -N -B -u${panelUser} -p${panelPass} -h${panelHost} -P${panelPort} -e "SELECT mysql_ip,mysql_port,COALESCE(NULLIF(mysql_admin_user,''),'root'),mysql_root_passwd FROM ${panelDB}.${panelPrefix}mysql_servers WHERE mysql_server_id = ${mysqlServerID} LIMIT 1")

if [ -z "${mysqlProfile}" ]; then
   echo "ERROR: Could not resolve mysql server profile id ${mysqlServerID} from ${panelDB}.${panelPrefix}mysql_servers"
   exit 1
fi

IFS=$'\t' read -r mysqlHost mysqlPort mysqlAdminUser mysqlAdminPass &lt;&lt;EOF
${mysqlProfile}
EOF

mysqlPort=${mysqlPort:-3306}

sed -i "s/dayzhivemind/${dbID}/g" epoch.sql

sed -i "s/Host = .*/Host = ${mysqlHost}/g" cfg/hiveext.ini
sed -i "s/Database = .*/Database = ${dbID}/g" cfg/hiveext.ini
sed -i "s/Username = .*/Username = ${dbID}/g" cfg/hiveext.ini
sed -i "s/Password = .*/Password = ${dbPass}/g" cfg/hiveext.ini
sed -i "s/Port = .*/Port = ${mysqlPort}/g" cfg/hiveext.ini

mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -e "CREATE DATABASE IF NOT EXISTS \`${dbID}\`"

# MySQL 5.7/8 compatible user creation + grants
mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -e "CREATE USER IF NOT EXISTS '${dbID}'@'localhost' IDENTIFIED BY '${dbPass}'"
mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -e "CREATE USER IF NOT EXISTS '${dbID}'@'%' IDENTIFIED BY '${dbPass}'"
mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -e "GRANT ALL ON \`${dbID}\`.* TO '${dbID}'@'localhost'"
mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -e "GRANT ALL ON \`${dbID}\`.* TO '${dbID}'@'%'"
mysql -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -e "FLUSH PRIVILEGES;"

# Import with compatibility flags for routines/events under binary logging
# Keep stderr in a file to avoid flooding panel output with non-fatal import warnings.
mysql --force --init-command="SET SESSION sql_mode=''; SET SESSION log_bin_trust_function_creators=1;" -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -D ${dbID} &lt; epoch.sql 2> ./cfg/mysql_import_errors.log
mysql --force --init-command="SET SESSION sql_mode=''; SET SESSION log_bin_trust_function_creators=1;" -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -D ${dbID} &lt; add_events.sql 2>> ./cfg/mysql_import_errors.log
mysql --force --init-command="SET SESSION sql_mode=''; SET SESSION log_bin_trust_function_creators=1;" -u${mysqlAdminUser} -p${mysqlAdminPass} -h${mysqlHost} -P${mysqlPort} -D ${dbID} &lt; update1071.sql 2>> ./cfg/mysql_import_errors.log

mysql -u${panelUser} -p${panelPass} -h${panelHost} -P${panelPort} -e "DELETE FROM ${panelDB}.${panelPrefix}mysql_databases WHERE db_user = '${dbID}'"

# Backward-compatible insert: new schema with snapshot columns OR legacy schema.
hasSnapshotCols=$(mysql -N -B -u${panelUser} -p${panelPass} -h${panelHost} -P${panelPort} -e "SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='${panelDB}' AND TABLE_NAME='${panelPrefix}mysql_databases' AND COLUMN_NAME IN ('db_mysql_ip','db_mysql_port','db_admin_user','db_admin_passwd')")
if [ "${hasSnapshotCols}" = "4" ]; then
   mysql -u${panelUser} -p${panelPass} -h${panelHost} -P${panelPort} -e "INSERT INTO ${panelDB}.${panelPrefix}mysql_databases(mysql_server_id, home_id, db_user, db_passwd, db_name, enabled, db_mysql_ip, db_mysql_port, db_admin_user, db_admin_passwd) VALUES (${mysqlServerID},${srvID},'${dbID}','${dbPass}','${dbID}',1,'${mysqlHost}','${mysqlPort}','${mysqlAdminUser}','${mysqlAdminPass}')"
else
   mysql -u${panelUser} -p${panelPass} -h${panelHost} -P${panelPort} -e "INSERT INTO ${panelDB}.${panelPrefix}mysql_databases(mysql_server_id, home_id, db_user, db_passwd, db_name, enabled) VALUES (${mysqlServerID},${srvID},'${dbID}','${dbPass}','${dbID}',1)"
fi

rm *.sh
rm *.gz
rm +.tar
rm *.sql

printf '%s\r\n' \
'@echo off' \
'del /q "..\_alsoRun.pid" 2>nul' \
'cd bec \
'start "BEC" bec.exe --dsc --dec -f config.cfg' \
'cd .. \
'timeout /t 1 /nobreak >nul' \
'for /f "tokens=2 delims==" %%P in ('"'"'wmic process where "ExecutablePath='"'"'%cd:\=\\%\\bec.exe'"'"'" get ProcessId /value ^| find "="'"'"') do >"..\_alsoRun.pid" echo %%P' \
> _alsoRun.bat

</post_install>
<pre_start>
</pre_start>

<lock_files>
Arma2Server.exe
Arma2Server_x64.exe
</lock_files>

<configuration_files>
 <file description="Server settings">cfg\server.cfg</file>
 <file description="Basic Network settings" >cfg\basic.cfg</file>
 <file description="BattlEye Rcon Password" >cfg\battleye\beserver.cfg</file>
 <file description="DB settings and Date/Time">cfg\hiveext.ini</file>
 <file description="Difficulty Settings">cfg\users\dayz\dayz.arma2oaprofile</file>
 <file description="For DayZmod: 224580 All others: 33930">steam_appid.txt</file>
 <file description="BEC Scheduler">bec\config\scheduler.xml</file>
 <file description="BEC Admins">bec\config\admins.xml</file>
 <file description="BEC Whitelist">bec\config\whitelist.xml</file>
 <file description="BEC Message List">bec\config\fortune.txt</file>

</configuration_files>

</game_config>
