@setlocal enableextensions
@cd /d "%~dp0"
@Echo off
title RW Windows Server Installer V4.0 - Java Installer
color 1b
echo ------------------------------------
echo -  RW Auto Server Installer v4.0   -
echo -           By Yahgiggle           -
echo -  Auto Update, Backup and reboot  -
echo ------------------------------------
timeout /t 5 /NOBREAK
Call Settings.bat


rem make all needed folder names and set them to the location
mkdir %Serverdrive%:\%ServerFolder%\Java
mkdir %Serverdrive%:\%ServerFolder%\vcredist
mkdir %Serverdrive%:\%ServerFolder%\steamcmd
mkdir %Serverdrive%:\%ServerFolder%\Server
mkdir %Serverdrive%:\%ServerFolder%\Server\RWVersion
mkdir %BackupDrive%:\%BackupFolder%
mkdir %Serverdrive%:\%ServerFolder%\Server\permissions
mkdir %Serverdrive%:\%ServerFolder%\Server\permissions\groups
mkdir %Serverdrive%:\%ServerFolder%\Server\RWServerSettings



rem copy all needed files
rem COPY files\default.permissions "%Serverdrive%:\%ServerFolder%\Server\permissions"
rem COPY files\admin.permissions "%Serverdrive%:\%ServerFolder%\Server\Permissions\groups"
COPY files\Boot.bat "%Serverdrive%:\%ServerFolder%\Server"
COPY files\java.exe "%Serverdrive%:\%ServerFolder%\Server"
COPY files\7z.exe "%Serverdrive%:\%ServerFolder%\Server"
COPY files\7z.dll "%Serverdrive%:\%ServerFolder%\Server"
COPY files\rebooter.cmd "%Serverdrive%:\%ServerFolder%\Server"
COPY files\updater.cmd "%Serverdrive%:\%ServerFolder%\Server"
COPY files\StartServer.cmd "%Serverdrive%:\%ServerFolder%\Server"
COPY files\Version "%Serverdrive%:\%ServerFolder%\Server\RWVersion"
Copy "permissions" "%Serverdrive%:\%ServerFolder%\Server\permissions"
Copy "permissions\groups" "%Serverdrive%:\%ServerFolder%\Server\permissions\groups"

rem installer settings file setup
(Echo :: version 2.0 RisingWorld Unity Server Installer By Yahgiggle yahgiggle@gmail.com) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: settings example) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: Set the drive example Serverdrive=C or Serverdrive=D or Serverdrive=E default C drive) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo set Serverdrive=%Serverdrive%) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: Set the folder example ServerFolder=RW-Server or ServerFolder=Myservers\test\whatever) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo set ServerFolder=%ServerFolder%) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: set the hard reboot and backup time interval between reboots, time in seconds default 24hours) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo set Reboot=%Reboot%) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: set the update time interval between looking for updates in seconds default every 5min) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo set Update=%Update%) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: set the drive letter for the backup folder) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo set BackupDrive=%BackupDrive%)>> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: set the folder name for the Backups to be backuped too) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat 
(Echo set BackupFolder=%BackupFolder%) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo :: set the lenth of time in days a backup is stored on the drive before its deleted default 30days) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat
(Echo set BackupStored=%BackupStored%) >> %Serverdrive%:\%ServerFolder%\Server\RWServerSettings\Settings.bat



rem set server new name from random names
SET /A word0=%RANDOM% * 10 / 32768 + 1
SET /A word1=%RANDOM% * 10 / 32768 + 1
SET /A word2=%RANDOM% * 7 / 32768 + 1
SET /A word3=%RANDOM% * 6 / 32768 + 1
SET /A word4=%RANDOM% * 10 / 32768 + 1

Echo %word1%
Echo %word2%
Echo %word3%
Echo %word4%


if "%word4%"=="1" (set word4=The ) else (set word4=)

if "%word1%"=="1" (set word1=kingdom of) else (echo not used)
if "%word1%"=="2" (set word1=Lands of) else (echo not used)
if "%word1%"=="3" (set word1=Empire of) else (echo not used)
if "%word1%"=="4" (set word1=worlds of) else (echo not used)
if "%word1%"=="5" (set word1=No Mans land of) else (echo not used)
if "%word1%"=="6" (set word1=Federation of) else (echo not used)
if "%word1%"=="7" (set word1=Realm of) else (echo not used)
if "%word1%"=="8" (set word1=Commonwealth of) else (echo not used)
if "%word1%"=="9" (set word1=Republic of) else (echo not used)
if "%word1%"=="10" (set word1=Alliance of) else (echo not used)


if "%word2%"=="1" (set word2=death and) else (echo not used)
if "%word2%"=="2" (set word2=life and) else (echo not used)
if "%word2%"=="3" (set word2=torcher and) else (echo not used)
if "%word2%"=="4" (set word2=building and) else (echo not used)
if "%word2%"=="5" (set word2=hunting and) else (echo not used)
if "%word2%"=="6" (set word2=kinship and) else (echo not used)
if "%word2%"=="7" (set word2=territory and) else (echo not used)


if "%word3%"=="1" (set word3=killing) else (echo not used)
if "%word3%"=="2" (set word3=exile) else (echo not used)
if "%word3%"=="3" (set word3=eviction) else (echo not used)
if "%word3%"=="4" (set word3=victory) else (echo not used)
if "%word3%"=="5" (set word3=triumphant) else (echo not used)
if "%word3%"=="6" (set word3=conquering) else (echo not used)

set NewName=%word4%%word1% %word2% %word3%
if "%server_name%"=="RisingWorld" (set server_name=%NewName%) else (echo User Server Name Set)



rem Server settings file
(Echo #date) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo admins=%admins%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo contact=%contact%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo database_mysql_connections=%database_mysql_connections%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo database_mysql_database=%database_mysql_database%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo database_mysql_password=%database_mysql_password%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo database_mysql_server_ip=%database_mysql_server_ip%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo database_mysql_server_port=%database_mysql_server_port%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo database_mysql_user=%database_mysql_user%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo database_type=%database_type%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo plugins_enabled=%plugins_enabled%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo plugins_error_threshold=%plugins_error_threshold%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo plugins_jdk_path=%plugins_jdk_path%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo rcon_enabled=%rcon_enabled%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo rcon_password=%rcon_password%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo rcon_port=%rcon_port%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_custom_logo=%server_custom_logo%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties 
(Echo server_force_shutdown=%server_force_shutdown%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_ip=%server_ip%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_lan_mode=%server_lan_mode%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_list_visible=%server_list_visible%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties 
(Echo server_memory=%server_memory%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties 
(Echo server_name=%server_name%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_password=%server_password%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_port=%server_port%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_query_ip=%server_query_ip%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_redirect_stdout=%server_redirect_stdout%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_restart_script=%server_restart_script%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_screen_title=%server_screen_title%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_steam_port=%server_steam_port%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_use_temp_dir=%server_use_temp_dir%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_disabled_dungeons=%server_world_disabled_dungeons%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_disabled_npcs=%server_world_disabled_npcs%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_disabled_watersources=%server_world_disabled_watersources%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_generatecaves=%server_world_generatecaves%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_generatevegetations=%server_world_generatevegetations%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_name=%server_world_name%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_oreamount=%server_world_oreamount%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_seed=%server_world_seed%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_startbiome=%server_world_startbiome%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo server_world_type=%server_world_type%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_admins_allpermissions=%settings_admins_allpermissions%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_blacklisted=%settings_blacklisted%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_check_version=%settings_check_version%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_chests_drop_items=%settings_chests_drop_items%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_clear_cache=%settings_clear_cache%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_create_serverlog=%settings_create_serverlog%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_create_worldbackup=%settings_create_worldbackup%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_deadnpc_despawntime=%settings_deadnpc_despawntime%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_deadplayers_creategrave=%settings_deadplayers_creategrave%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_deadplayers_despawntime=%settings_deadplayers_despawntime%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_default_gamemode=%settings_default_gamemode%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_default_newplayer_group=%settings_default_newplayer_group%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_delete_old_serverlogs_hours=%settings_delete_old_serverlogs_hours%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_illegal_state_limit=%settings_illegal_state_limit%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_item_despawntime=%settings_item_despawntime%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_max_npcs=%settings_max_npcs%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_max_players=%settings_max_players%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_npc_bandits_spawn_day=%settings_npc_bandits_spawn_day%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_npc_respawn_cooldown=%settings_npc_respawn_cooldown%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_npc_spawnrate_animals=%settings_npc_spawnrate_animals%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_npc_spawnrate_enemies=%settings_npc_spawnrate_enemies%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_npc_spawnrate_enemies_dungeon=%settings_npc_spawnrate_enemies_dungeon%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_peacefulmode_enabled=%settings_peacefulmode_enabled%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_prioritize_new_players=%settings_prioritize_new_players%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_pvp_enabled=%settings_pvp_enabled%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_rcon_forward_commands=%settings_rcon_forward_commands%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_rcon_forward_lua=%settings_rcon_forward_lua%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_reserved_names=%settings_reserved_names%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_save_world=%settings_save_world%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_show_luaplugins=%settings_show_luaplugins%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_show_playerdistance=%settings_show_playerdistance%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_show_playerplaytime=%settings_show_playerplaytime%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_show_restart_notification=%settings_show_restart_notification%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_spawn_protection=%settings_spawn_protection%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_stamina_enabled=%settings_stamina_enabled%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_start_weather=%settings_start_weather%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_time_speed=%settings_time_speed%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_tnt_spawn_items=%settings_tnt_spawn_items%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_weather_enabled=%settings_weather_enabled%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_weather_preset=%settings_weather_preset%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo settings_whitelisted=%settings_whitelisted%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties
(Echo webadmin=%webadmin%) >> %Serverdrive%:\%ServerFolder%\Server\server.properties




Set port=%server_port%

set /a port0=%port%-2
set /a port1=%port%-1
set /a port2=%port%
set /a port3=%port%+1
set /a port4=%port%+2
set /a port5=%port%+3
set /a port6=%port%+4

echo port:%port0% set
echo port:%port1% set
echo port:%port2% set
echo port:%port3% set
echo port:%port4% set
echo port:%port5% set
echo port:%port6% set





set RULE_NAME="RisingWorld Open Server Ports TCP %port0%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall TCP port:%PORT0% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT0%
	echo Rule %RULE_NAME% for port:%port0% TCP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)


set RULE_NAME="RisingWorld Open Server Ports TCP %port1%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall TCP port:%PORT1% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT1%
	echo Rule %RULE_NAME% for port:%port1% TCP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)



set RULE_NAME="RisingWorld Open Server Ports TCP %port2%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall TCP port:%PORT2% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT2%
	echo Rule %RULE_NAME% for port:%port2% TCP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)



set RULE_NAME="RisingWorld Open Server Ports TCP %port3%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall TCP port:%PORT3% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT3%
	echo Rule %RULE_NAME% for port:%port3% TCP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)



set RULE_NAME="RisingWorld Open Server Ports TCP %port4%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall TCP port:%PORT4% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT4%
	echo Rule %RULE_NAME% for port:%port4% TCP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)



set RULE_NAME="RisingWorld Open Server Ports TCP %port5%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall TCP port:%PORT5% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT5%
	echo Rule %RULE_NAME% for port:%port5% TCP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)




set RULE_NAME="RisingWorld Open Server Ports TCP %port6%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall TCP port:%PORT6% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT6%
	echo Rule %RULE_NAME% for port:%port6% TCP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)






set RULE_NAME="RisingWorld Open Server Ports UDP %port0%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall UDP port:%PORT0% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=UDP localport=%PORT0%
	echo Rule %RULE_NAME% for port:%port0% UDP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)



set RULE_NAME="RisingWorld Open Server Ports UDP %port1%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall UDP port:%PORT1% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=UDP localport=%PORT1%
	echo Rule %RULE_NAME% for port:%port1% UDP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)




set RULE_NAME="RisingWorld Open Server Ports UDP %port2%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall UDP port:%PORT2% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=UDP localport=%PORT2%
	echo Rule %RULE_NAME% for port:%port2% UDP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)



set RULE_NAME="RisingWorld Open Server Ports UDP %port3%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall UDP port:%PORT3% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=UDP localport=%PORT3%
	echo Rule %RULE_NAME% for port:%port3% UDP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)




set RULE_NAME="RisingWorld Open Server Ports UDP %port4%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall UDP port:%PORT4% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=UDP localport=%PORT4%
	echo Rule %RULE_NAME% for port:%port4% UDP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)



set RULE_NAME="RisingWorld Open Server Ports UDP %port5%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall UDP port:%PORT5% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=UDP localport=%PORT5%
	echo Rule %RULE_NAME% for port:%port5% UDP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) 


set RULE_NAME="RisingWorld Open Server Ports UDP %port6%"

netsh advfirewall firewall show rule name=%RULE_NAME% >nul
if not ERRORLEVEL 1 (
    rem Rule %RULE_NAME% already exists.
    echo You already unblocked your RisingWorld Firewall!
	echo you already have unblocked your RisingWorld Firewall UDP port:%PORT6% >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
) else (
    echo Rule %RULE_NAME% does not exist. Creating... >> %CD%\report.txt
    netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=UDP localport=%PORT6%
	echo Rule %RULE_NAME% for port:%port6% UDP successfully added >> %CD%\report.txt
	echo ----------------------------------------------------------------- >> %CD%\report.txt
)





Echo Installed setting files now will install the server after 5sec  DO NOT CLOSE THIS BOX, THE AUTO SERVER INSTALLER WILL AUTO CLOSE WHEN 100% FINISHED
timeout /t 10 /NOBREAK



rem install Microsoft Visual
bitsadmin /transfer wcb /priority high  https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe %Serverdrive%:\%ServerFolder%\vcredist\vcredist_x64.exe
start %Serverdrive%:\%ServerFolder%\vcredist\vcredist_x64.exe /install /quiet /norestart
Echo Installed Microsoft Visual 13 x64
timeout /t 10 /NOBREAK

rem install Microsoft Visual
bitsadmin /transfer wcb /priority high  https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe %Serverdrive%:\%ServerFolder%\vcredist\vcredist_x86.exe
start %Serverdrive%:\%ServerFolder%\vcredist\vcredist_x86.exe /install /quiet /norestart
Echo Installed Microsoft Visual 13 x86
timeout /t 10 /NOBREAK



rem install java 8
bitsadmin /transfer wcb /priority high  https://javadl.oracle.com/webapps/download/AutoDL?BundleId=246474_2dee051a5d0647d5be72a7c0abff270e %Serverdrive%:\%ServerFolder%\Java\jre-8u333-windows-x64.exe
start /w %Serverdrive%:\%ServerFolder%\Java\jre-8u333-windows-x64.exe /s
Echo installed java
timeout /t 10 /NOBREAK


rem install steamcmd and the server
bitsadmin /transfer wcb /priority high https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip %Serverdrive%:\%ServerFolder%\steamcmd\steamcmd.zip
%Serverdrive%:\%ServerFolder%\Server\7z.exe x %Serverdrive%:\%ServerFolder%\steamcmd\steamcmd.zip -o%Serverdrive%:\%ServerFolder%\steamcmd -aos
%Serverdrive%:\%ServerFolder%\steamcmd\steamcmd.exe +login anonymous +force_install_dir %Serverdrive%:\%ServerFolder%\Server +app_update 339010 validate +quit
Echo Installed steamcmd and the server now booting the server in 5 seconds
timeout /t 10 /NOBREAK



cd/
Start %Serverdrive%:\%ServerFolder%\Server\StartServer.cmd
COPY Version "%Serverdrive%:\%ServerFolder%\Server\RWVersion"
echo server is now installed in location %Serverdrive%:\%ServerFolder%\Server
timeout /t 10 /NOBREAK
exit




