2021-09-08 23:38:34 +08:00
|
|
|
# -------------------------------
|
|
|
|
# Difficult Rocket
|
2023-01-20 14:08:12 +08:00
|
|
|
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
2021-09-08 23:38:34 +08:00
|
|
|
# All rights reserved
|
|
|
|
# -------------------------------
|
|
|
|
|
2021-02-16 00:15:29 +08:00
|
|
|
"""
|
2020-12-05 21:24:54 +08:00
|
|
|
writen by shenjackyuanjie
|
2021-09-08 23:38:34 +08:00
|
|
|
mail: 3695888@qq.com
|
|
|
|
github: @shenjackyuanjie
|
|
|
|
gitee: @shenjackyuanjie
|
2021-02-16 00:15:29 +08:00
|
|
|
"""
|
2020-12-05 21:24:54 +08:00
|
|
|
|
2021-03-24 23:37:10 +08:00
|
|
|
import os
|
2021-02-16 00:08:11 +08:00
|
|
|
import sys
|
2021-01-25 12:22:55 +08:00
|
|
|
import time
|
2021-09-22 06:21:48 +08:00
|
|
|
import logging
|
|
|
|
import logging.config
|
|
|
|
import multiprocessing
|
2021-01-24 22:00:31 +08:00
|
|
|
|
2021-08-24 22:31:52 +08:00
|
|
|
if __name__ == '__main__': # been start will not run this
|
|
|
|
sys.path.append('/bin/libs')
|
|
|
|
sys.path.append('/bin')
|
2021-01-23 21:43:04 +08:00
|
|
|
|
2022-12-25 23:15:49 +08:00
|
|
|
from Difficult_Rocket import client, server, DR_option
|
2023-01-31 22:07:18 +08:00
|
|
|
|
2022-06-18 17:53:35 +08:00
|
|
|
from Difficult_Rocket.utils import tools
|
|
|
|
from Difficult_Rocket.utils.translate import tr
|
2020-12-05 21:24:54 +08:00
|
|
|
|
2022-08-12 21:07:36 +08:00
|
|
|
|
2021-08-24 22:31:52 +08:00
|
|
|
class Game:
|
2020-12-05 21:24:54 +08:00
|
|
|
def __init__(self):
|
2021-01-25 17:01:54 +08:00
|
|
|
# basic config
|
2021-02-16 11:35:10 +08:00
|
|
|
self.on_python_v_info = sys.version_info
|
2021-02-26 19:05:24 +08:00
|
|
|
self.on_python_v = sys.version.split(' ')[0]
|
2021-02-15 23:52:56 +08:00
|
|
|
self.start_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time()))
|
2021-02-20 21:46:14 +08:00
|
|
|
# lang_config
|
2022-12-22 10:54:28 +08:00
|
|
|
self.language = tools.load_file('configs/main.toml', 'runtime')['language']
|
2022-08-12 21:07:36 +08:00
|
|
|
DR_option.language = self.language
|
2021-09-22 06:21:48 +08:00
|
|
|
# logging config
|
2022-06-18 17:53:35 +08:00
|
|
|
log_config = tools.load_file('configs/logger.toml')
|
2021-09-22 06:21:48 +08:00
|
|
|
file_name = log_config['handlers']['file']['filename']
|
|
|
|
del log_config['handlers']['file']['datefmt']
|
2021-09-22 06:32:10 +08:00
|
|
|
log_config['handlers']['file']['filename'] = f'logs/{file_name.format(self.start_time)}'
|
|
|
|
try:
|
|
|
|
logging.config.dictConfig(log_config)
|
|
|
|
self.logger = logging.getLogger('main')
|
2021-09-22 20:51:30 +08:00
|
|
|
except ValueError: # it should be no 'logs/' folder
|
2021-09-22 06:32:10 +08:00
|
|
|
os.mkdir('logs')
|
|
|
|
logging.config.dictConfig(log_config)
|
|
|
|
self.logger = logging.getLogger('main')
|
2023-02-03 20:31:44 +08:00
|
|
|
self.logger.info(tr().main.logger.mkdir())
|
|
|
|
self.logger.info(tr().main.logger.created())
|
2021-02-16 11:35:10 +08:00
|
|
|
# version check
|
2021-02-16 00:08:11 +08:00
|
|
|
self.python_version_check()
|
2021-08-13 12:25:29 +08:00
|
|
|
self.setup()
|
|
|
|
|
2021-08-24 22:31:52 +08:00
|
|
|
def setup(self) -> None:
|
2021-09-22 06:21:48 +08:00
|
|
|
self.client = client.Client(net_mode='local')
|
2022-12-25 23:15:49 +08:00
|
|
|
self.server = server.Server(net_mode='local')
|
2021-02-06 16:41:54 +08:00
|
|
|
|
2021-08-24 22:31:52 +08:00
|
|
|
def python_version_check(self) -> None: # best 3.8+ and write at 3.8.10
|
2023-02-03 20:31:44 +08:00
|
|
|
self.logger.info(f"{tr().main.version.now_on()} {self.on_python_v}")
|
2021-02-16 11:35:10 +08:00
|
|
|
if self.on_python_v_info[0] == 2:
|
2023-02-03 20:31:44 +08:00
|
|
|
self.logger.critical(tr().main.version.need3p())
|
|
|
|
raise SystemError(tr().main.version.need3p())
|
2021-08-13 12:25:29 +08:00
|
|
|
elif self.on_python_v_info[1] < 8:
|
2023-02-03 20:31:44 +08:00
|
|
|
warning = tools.name_handler(tr.main.version.best38p())
|
2021-09-22 06:21:48 +08:00
|
|
|
self.logger.warning(warning)
|
2021-02-16 00:08:11 +08:00
|
|
|
|
2021-09-05 00:50:05 +08:00
|
|
|
# @new_thread('main')
|
2021-09-22 06:21:48 +08:00
|
|
|
def _start(self):
|
2022-12-25 23:15:49 +08:00
|
|
|
self.server.run()
|
2023-01-24 23:59:07 +08:00
|
|
|
if DR_option.use_multiprocess:
|
2021-09-22 06:21:48 +08:00
|
|
|
try:
|
|
|
|
game_process = multiprocessing.Process(target=self.client.start(), name='pyglet app')
|
|
|
|
game_process.start()
|
|
|
|
game_process.join()
|
2023-01-27 21:09:37 +08:00
|
|
|
except Exception:
|
2021-09-22 06:21:48 +08:00
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
2021-09-05 00:50:05 +08:00
|
|
|
else:
|
2021-09-22 06:21:48 +08:00
|
|
|
self.client.start()
|
2021-09-05 00:50:05 +08:00
|
|
|
|
|
|
|
def start(self) -> None:
|
|
|
|
self._start()
|