Difficult-Rocket/bin/main.py

72 lines
2.8 KiB
Python
Raw Normal View History

2021-02-14 20:22:29 +08:00
'''
2020-12-05 21:24:54 +08:00
writen by shenjackyuanjie
mail: 3695888@qq.com
2021-02-14 20:22:29 +08:00
'''
2020-12-05 21:24:54 +08:00
2021-01-25 12:22:55 +08:00
# share memory
2021-01-21 15:05:29 +08:00
from multiprocessing import Manager as share
2020-12-05 21:24:54 +08:00
2021-02-16 00:08:11 +08:00
import sys
2021-01-25 12:22:55 +08:00
import time
import logging
2021-02-06 16:41:54 +08:00
try:
from bin import tools
from bin import client
from bin import server
2021-02-14 19:03:36 +08:00
from bin import configs
2021-02-14 11:07:02 +08:00
except (ModuleNotFoundError, ImportError, ImportWarning):
2021-02-14 10:24:38 +08:00
import tools
import client
import server
2021-02-14 19:03:36 +08:00
import configs
2020-12-05 21:24:54 +08:00
2021-02-06 16:41:54 +08:00
class Game:
2020-12-21 18:46:20 +08:00
2020-12-05 21:24:54 +08:00
def __init__(self):
2021-01-25 17:01:54 +08:00
# basic config
2021-02-15 23:52:56 +08:00
self.start_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time()))
2021-01-25 17:01:54 +08:00
# share memory
2021-01-25 19:23:16 +08:00
self.dicts = share().dict()
2021-01-21 15:05:29 +08:00
self.lists = share().list()
2021-01-25 17:01:54 +08:00
# logger
2021-02-14 23:15:54 +08:00
self.log_config = tools.config('configs/logging.json5', 'file')
2021-02-16 00:08:11 +08:00
self.log_filename = configs.name_handler(self.log_config['filename']['main'],
self.log_config['filename']['formats'])
self.root_logger_fmt = logging.Formatter(self.log_config['fmt'], self.log_config['date_fmt'])
2021-02-15 21:45:20 +08:00
self.root_logger_stream_handler = logging.StreamHandler()
self.root_logger_stream_handler.setLevel(self.log_config['level'])
self.root_logger_stream_handler.setFormatter(self.root_logger_fmt)
2021-02-15 23:48:13 +08:00
self.root_logger_stream_handler.setLevel(tools.log_level(self.log_config['level']))
2021-02-15 21:45:20 +08:00
self.root_logger_file_handler = logging.FileHandler(self.log_filename)
self.root_logger_file_handler.setFormatter(self.root_logger_fmt)
2021-02-15 23:48:13 +08:00
self.root_logger_file_handler.setLevel(tools.log_level(self.log_config['level']))
2021-02-16 00:08:11 +08:00
# root logger setup
2021-02-15 23:48:13 +08:00
logging.getLogger().setLevel(tools.log_level(self.log_config['level']))
2021-02-15 21:45:20 +08:00
logging.getLogger().addHandler(self.root_logger_stream_handler)
logging.getLogger().addHandler(self.root_logger_file_handler)
2021-02-16 00:08:11 +08:00
# create logger
self.main_logger = logging.getLogger().getChild('main')
2021-02-15 21:45:20 +08:00
self.server_logger = logging.getLogger().getChild('server')
self.client_logger = logging.getLogger().getChild('client')
2021-02-14 23:15:54 +08:00
self.client_logger.info('client logger and server logger done')
2021-02-16 00:08:11 +08:00
self.python_version_check()
2021-01-25 17:01:54 +08:00
# client and server
2021-02-14 19:03:36 +08:00
self.client = client.RenderThread(
self.client_logger, self.dicts, self.lists, net_mode='local')
self.server = server.server(
self.lists, self.dicts, self.server_logger, net_mode='local')
2021-02-15 23:52:56 +08:00
# //todo log configs
2021-02-06 16:41:54 +08:00
2021-02-16 00:08:11 +08:00
def python_version_check(self) -> None:
py_v_info = sys.version_info
py_v = str('%d.%d.%d' % (py_v_info[0], py_v_info[1], py_v_info[2]))
self.main_logger.info('Simple Rocket is running on Python Vision %s' % py_v)
if py_v_info[0] == 2:
raise Exception('Simple Rocket need python vision 3+ but not %s ' % (py_v))
def start(self):
2021-02-06 16:41:54 +08:00
# start
self.client.startGame()