-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from agentsofthesystem/develop
Refactor files & Add Palworld game support
- Loading branch information
Showing
43 changed files
with
251 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Intentially import here unused | ||
from application import games # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import os | ||
import time | ||
|
||
from jinja2 import Environment, FileSystemLoader | ||
|
||
from application.common import logger, constants | ||
from application.common.game_argument import GameArgument | ||
from application.common.game_base import BaseGame | ||
from application.common.toolbox import _get_proc_by_name, get_resources_dir | ||
from application.extensions import DATABASE | ||
from application.models.games import Games | ||
|
||
|
||
class PalworldGame(BaseGame): | ||
def __init__(self, defaults_dict: dict = {}) -> None: | ||
super(PalworldGame, self).__init__(defaults_dict) | ||
|
||
self._game_name = "palworld" | ||
self._game_pretty_name = "Palworld" | ||
self._game_executable = "PalServer.exe" | ||
self._game_steam_id = "2394010" | ||
self._game_info_url = ( | ||
"https://www.gtxgaming.co.uk/palworld-dedicated-server-setup-guide/" | ||
) | ||
|
||
# if self._game_default_install_dir: | ||
# default_persistent_data_path = os.path.join( | ||
# self._game_default_install_dir, | ||
# constants.GAME_INSTALL_FOLDER, | ||
# self._game_name, | ||
# ) | ||
# else: | ||
# default_persistent_data_path = None | ||
|
||
# Add Args here, can update later. | ||
self._add_argument( | ||
GameArgument( | ||
"-ServerName", | ||
value="loverland's place", | ||
required=True, | ||
use_quotes=True, | ||
is_permanent=True, | ||
) | ||
) | ||
self._add_argument( | ||
GameArgument( | ||
"-AdminPasssword", | ||
value="WithGreatPowerComesGreatResponsibility", | ||
required=True, | ||
use_quotes=True, | ||
is_permanent=True, | ||
) | ||
) | ||
self._add_argument( | ||
GameArgument( | ||
"-ServerPassword", | ||
value="teamrocket", | ||
required=True, | ||
use_quotes=True, | ||
is_permanent=True, | ||
) | ||
) | ||
self._add_argument( | ||
GameArgument( | ||
"-MaxPlayers", | ||
value="12", | ||
required=True, | ||
use_quotes=True, | ||
is_permanent=True, | ||
) | ||
) | ||
# Default is 27015 | ||
self._add_argument( | ||
GameArgument( | ||
"-serverPort", | ||
value=8211, | ||
required=True, | ||
use_quotes=True, | ||
is_permanent=True, | ||
) | ||
) | ||
|
||
def startup(self) -> None: | ||
# Run base class checks | ||
super().startup() | ||
|
||
# Format command string. | ||
command = self._game_executable | ||
|
||
arguments = self._get_argument_dict() | ||
|
||
logger.debug("************************************") | ||
logger.debug(arguments) | ||
logger.debug("************************************") | ||
|
||
# Create a formatted batch file. | ||
env = Environment(loader=FileSystemLoader(get_resources_dir(__file__))) | ||
|
||
bat_template = env.get_template("start_palworld_server_template.bat.j2") | ||
output_from_parsed_bat_template = bat_template.render( | ||
GAME_STEAM_ID=self._game_steam_id, | ||
GAME_NAME=self._game_name, | ||
GAME_COMMAND=command, | ||
) | ||
|
||
# server_port = arguments['-serverPort'] | ||
|
||
ini_template = env.get_template("DefaultPalWorldSettings.ini.j2") | ||
output_from_parsed_ini_template = ini_template.render( | ||
PUBLIC_PORT=arguments["-serverPort"]._value, | ||
SERVER_NAME=arguments["-ServerName"]._value, | ||
MAX_PLAYER_COUNT=arguments["-MaxPlayers"]._value, | ||
ADMIN_PASSWORD=arguments["-AdminPasssword"]._value, | ||
SERVER_PASSWORD=arguments["-ServerPassword"]._value, | ||
) | ||
|
||
# Print the formatted jinja | ||
logger.debug(output_from_parsed_bat_template) | ||
logger.debug(output_from_parsed_ini_template) | ||
|
||
# In theory, the software has already check that the game is installed, so no check/guard | ||
# needed. | ||
game_qry = Games.query.filter_by(game_steam_id=self._game_steam_id) | ||
game_obj = game_qry.first() | ||
game_install_dir = game_obj.game_install_dir | ||
|
||
# Need game install location to write batch file. | ||
full_path_startup_script = os.path.join( | ||
game_install_dir, constants.STARTUP_BATCH_FILE_NAME | ||
) | ||
|
||
full_path_game_ini_config = os.path.join( | ||
game_install_dir, | ||
"Pal", | ||
"Saved", | ||
"Config", | ||
"WindowsServer", | ||
"PalWorldSettings.ini", | ||
) | ||
|
||
# If file exists, remove it. | ||
if os.path.exists(full_path_startup_script): | ||
os.remove(full_path_startup_script) | ||
if os.path.exists(full_path_game_ini_config): | ||
os.remove(full_path_game_ini_config) | ||
|
||
# Write the batch file. | ||
with open(full_path_startup_script, "w") as myfile: | ||
myfile.write(output_from_parsed_bat_template) | ||
|
||
with open(full_path_game_ini_config, "w") as myfile: | ||
myfile.write(output_from_parsed_ini_template) | ||
|
||
# Call the batch file on another process as to not block this one. | ||
command = f'START /MIN CMD.EXE /C "{full_path_startup_script}"' | ||
result = self._run_game(command, game_install_dir) | ||
|
||
time.sleep(1) | ||
|
||
process = _get_proc_by_name(self._game_executable) | ||
|
||
logger.info(result) | ||
logger.info("Process:") | ||
logger.info(process) | ||
|
||
update_dict = {"game_pid": int(process.pid)} | ||
|
||
game_qry.update(update_dict) | ||
DATABASE.session.commit() | ||
|
||
def shutdown(self) -> None: | ||
game_qry = Games.query.filter_by(game_steam_id=self._game_steam_id) | ||
game_obj = game_qry.first() | ||
game_pid = game_obj.game_pid | ||
|
||
process = _get_proc_by_name(self._game_executable) | ||
|
||
if process: | ||
logger.info(process) | ||
logger.info(game_pid) | ||
|
||
process.terminate() | ||
process.wait() | ||
|
||
update_dict = {"game_pid": None} | ||
game_qry.update(update_dict) | ||
DATABASE.session.commit() | ||
|
||
# Pal server throws in an extra executable that needs to be shutdown. | ||
process = _get_proc_by_name("PalServer-Win64-Test-Cmd.exe") | ||
|
||
if process: | ||
logger.info(process) | ||
process.terminate() | ||
process.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; This configuration file is a sample of the default server settings. | ||
; Changes to this file will NOT be reflected on the server. | ||
; To change the server settings, modify Pal/Saved/Config/WindowsServer/PalWorldSettings.ini. | ||
[/Script/Pal.PalGameWorldSettings] | ||
OptionSettings=(Difficulty=None,DayTimeSpeedRate=1.000000,NightTimeSpeedRate=1.000000,ExpRate=1.000000,PalCaptureRate=1.000000,PalSpawnNumRate=1.000000,PalDamageRateAttack=1.000000,PalDamageRateDefense=1.000000,PlayerDamageRateAttack=1.000000,PlayerDamageRateDefense=1.000000,PlayerStomachDecreaceRate=1.000000,PlayerStaminaDecreaceRate=1.000000,PlayerAutoHPRegeneRate=1.000000,PlayerAutoHpRegeneRateInSleep=1.000000,PalStomachDecreaceRate=1.000000,PalStaminaDecreaceRate=1.000000,PalAutoHPRegeneRate=1.000000,PalAutoHpRegeneRateInSleep=1.000000,BuildObjectDamageRate=1.000000,BuildObjectDeteriorationDamageRate=1.000000,CollectionDropRate=1.000000,CollectionObjectHpRate=1.000000,CollectionObjectRespawnSpeedRate=1.000000,EnemyDropItemRate=1.000000,DeathPenalty=All,bEnablePlayerToPlayerDamage=False,bEnableFriendlyFire=False,bEnableInvaderEnemy=True,bActiveUNKO=False,bEnableAimAssistPad=True,bEnableAimAssistKeyboard=False,DropItemMaxNum=3000,DropItemMaxNum_UNKO=100,BaseCampMaxNum=128,BaseCampWorkerMaxNum=15,DropItemAliveMaxHours=1.000000,bAutoResetGuildNoOnlinePlayers=False,AutoResetGuildTimeNoOnlinePlayers=72.000000,GuildPlayerMaxNum=20,PalEggDefaultHatchingTime=72.000000,WorkSpeedRate=1.000000,bIsMultiplay=False,bIsPvP=False,bCanPickupOtherGuildDeathPenaltyDrop=False,bEnableNonLoginPenalty=True,bEnableFastTravel=True,bIsStartLocationSelectByMap=True,bExistPlayerAfterLogout=False,bEnableDefenseOtherGuildPlayer=False,CoopPlayerMaxNum={{MAX_PLAYER_COUNT}},ServerPlayerMaxNum={{MAX_PLAYER_COUNT}},ServerName="{{SERVER_NAME}}",ServerDescription="",AdminPassword="{{ADMIN_PASSWORD}}",ServerPassword="{{SERVER_PASSWORD}}",PublicPort={{PUBLIC_PORT}},PublicIP="",RCONEnabled=False,RCONPort=25575,Region="",bUseAuth=True,BanListURL="https://api.palworldgame.com/api/banlist.txt") | ||
|
||
|
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
application/games/resources/start_vrising_server_template.bat.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@echo off | ||
set SteamAppId={{GAME_STEAM_ID}} | ||
echo "Starting {{GAME_NAME}} Dedicated Server - PRESS CTRL-C to exit" | ||
|
||
@echo on | ||
{{GAME_COMMAND}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.