Difficult-Rocket/bin/main.py

75 lines
2.6 KiB
Python
Raw Normal View History

2020-12-05 21:24:54 +08:00
"""
writen by shenjackyuanjie
mail: 3695888@qq.com
"""
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-06 16:41:54 +08:00
# import bin
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-14 19:03:36 +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
self.configs = ''
# 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 19:03:36 +08:00
# log config
self.log_config = tools.configs('configs/logging.json5')
self.log_file_config = self.log_config['file']
self.log_file_handler = logging.FileHandler(configs.name_handler(
self.log_file_config['filename']['main'], self.log_file_config['filename']['formats']))
# logger
# all logger
# client logger
self.client_log_config = self.log_config['client']
2021-01-25 12:22:55 +08:00
self.client_logger = logging.getLogger('client')
2021-02-14 19:03:36 +08:00
self.client_fmt = logging.Formatter(
2021-02-14 19:58:39 +08:00
fmt=self.client_log_config['fmt'],
2021-02-14 19:03:36 +08:00
datefmt=self.client_log_config['date_fmt'])
2021-02-06 16:41:54 +08:00
self.client_stream_handler = logging.StreamHandler()
2021-02-14 19:03:36 +08:00
self.client_stream_handler.setLevel(self.client_log_config['level'])
self.client_stream_handler.setFormatter(self.client_fmt)
self.client_logger.addHandler(self.client_stream_handler)
# server logger
self.server_log_config = self.log_config['server']
2021-02-06 16:41:54 +08:00
self.server_logger = logging.getLogger('server')
2021-02-14 19:03:36 +08:00
self.server_fmt = logging.Formatter(
2021-02-14 19:58:39 +08:00
fmt=self.server_log_config['fmt'],
2021-02-14 19:03:36 +08:00
datefmt=self.server_log_config['date_fmt'])
2021-02-06 16:41:54 +08:00
self.server_stream_handler = logging.StreamHandler()
2021-02-14 19:03:36 +08:00
self.server_stream_handler.setLevel(self.server_log_config['level'])
self.server_stream_handler.setFormatter(self.server_fmt)
self.server_logger.addHandler(self.server_stream_handler)
# file logger
self.log_formatter = logging.Formatter(
2021-02-14 19:58:39 +08:00
fmt=self.log_file_config['fmt'],
datefmt=self.log_file_config['date_fmt'])
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-06 16:41:54 +08:00
# start
self.client.startGame()