def start_game(self, manager): log.info("game started") stats({ 'event': 'start_game', 'attributes': { 'gametype': manager.gamecls.__name__ } }) manager.start_game() self.refresh_status()
def _run(g): from server.core.lobby import lobby g.synctag = 0 g.game = getcurrent() lobby.start_game(g.manager) try: g.process_action(g.bootstrap(g.manager.game_params)) except GameEnded: pass finally: lobby.end_game(g.manager) assert g.ended stats(*g.get_stats())
def _run(g): g.synctag = 0 g.event_observer = ServerEventHooks() g.game = getcurrent() mgr = GameManager.get_by_game(g) Subsystem.lobby.start_game(mgr) try: g.process_action(g.bootstrap(mgr.game_params, mgr.consumed_game_items)) except GameEnded: pass finally: Subsystem.lobby.end_game(mgr) assert g.ended stats(*g.get_stats())
def _run(g): g.synctag = 0 g.event_observer = ServerEventHooks() g.game = getcurrent() mgr = GameManager.get_by_game(g) Subsystem.lobby.start_game(mgr) try: g.process_action( g.bootstrap(mgr.game_params, mgr.consumed_game_items)) except GameEnded: pass finally: Subsystem.lobby.end_game(mgr) assert g.ended stats(*g.get_stats())
def _incr_stats(route_name, method, status_code=None): """ Increments relevant stats counters. """ if status_code: stats().incr("responses.status.{}.{}.status.{}".format( route_name, method, status_code)) stats().incr("responses.{}".format(route_name)) stats().incr("responses.{}.{}".format(route_name, method))
def _wrapped(*args, **kwargs): route_name = request.path if request.path else 'unknown_route' method = request.method try: with stats().timer('timer.{}'.format(route_name)): response = func(*args, **kwargs) response = make_response(response) _incr_stats(route_name, method, response.status_code) return response except HTTPException as e: _incr_stats(route_name, method, e.code) raise except Exception: # assume internal server error _incr_stats(route_name, method, 500) raise
def kickob(uid): stats({"event": "kick_ob"}) Executive.kick_observer(uid) # reply by server message later return u""
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import crashreport parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument("--no-update", action="store_true") parser.add_argument("--with-gl-errcheck", action="store_true") parser.add_argument("--freeplay", action="store_true") parser.add_argument("--fastjoin", action="store_true") parser.add_argument("--dump-gameobj", action="store_true") parser.add_argument("--log", default="INFO") parser.add_argument("--color-log", action="store_true") parser.add_argument("--no-crashreport", action="store_true") parser.add_argument("--show-hidden-modes", action="store_true") options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, "uname") and os.uname()[:2] == ("Linux", "Proton") crashreport.install_tee(options.log.upper()) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate if IS_PROTON or options.color_log: from colorlog import ColoredFormatter formatter = ColoredFormatter( "%(log_color)s%(message)s%(reset)s", log_colors={"CRITICAL": "bold_red", "ERROR": "red", "WARNING": "yellow", "INFO": "green", "DEBUG": "blue"}, ) logging.getLogger().handlers[0].setFormatter(formatter) log = logging.getLogger("start_client") from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init("Client") import pyglet pyglet.options["shadow_window"] = False if not options.with_gl_errcheck: pyglet.options["debug_gl"] = False from pyglet.gl import gl_info if gl_info.get_renderer() == "GDI Generic": ctypes.windll.user32.MessageBoxW(0, u"你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!", u"需要显卡驱动", 16) sys.exit(0) if sys.platform.startswith("linux") and options.dump_gameobj: import atexit import game atexit.register(game.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() if not options.no_crashreport: log.error(u"游戏崩溃,正在报告bug,请稍等下……") from utils.stats import stats stats({"event": "crash"}) from crashreport import do_crashreport do_crashreport() raise
def kickob(uid): stats({'event': 'kick_ob'}) Executive.kick_observer(uid) # reply by server message later return u''
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import crashreport parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', action='store_true') parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--no-crashreport', action='store_true') parser.add_argument('--show-hidden-modes', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') crashreport.install_tee(options.log.upper()) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate if IS_PROTON or options.color_log: from colorlog import ColoredFormatter formatter = ColoredFormatter("%(log_color)s%(message)s%(reset)s", log_colors={ 'CRITICAL': 'bold_red', 'ERROR': 'red', 'WARNING': 'yellow', 'INFO': 'green', 'DEBUG': 'blue', }) logging.getLogger().handlers[0].setFormatter(formatter) log = logging.getLogger('start_client') from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game atexit.register(game.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() if not options.no_crashreport: log.error(u'游戏崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) from crashreport import do_crashreport do_crashreport() raise
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import utils.logging parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', type=int, default=None) parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--zoom', type=float, default=1.0) parser.add_argument('--show-hidden-modes', action='store_true') parser.add_argument('--multiple-instances', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') import settings utils.logging.init(options.log.upper(), settings.SENTRY_DSN, settings.VERSION, IS_PROTON or options.color_log) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate log = logging.getLogger('start_client') if sys.platform.startswith('win32') and not options.multiple_instances: from utils.mutex import NamedMutex thb_mutex = NamedMutex('thbattle-mutex') if not thb_mutex.acquire(0): log.error('Multiple instances detected, exiting') ctypes.windll.user32.MessageBoxW( 0, u'请遵守社区规范,素质游戏,不要开启多个游戏实例!', u'东方符斗祭', 16, ) sys.exit(0) opmodule.mutex = thb_mutex else: opmodule.mutex = None from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game.base atexit.register(game.base.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.base.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui # PIL compat from PIL import Image try: Image.frombytes Image.Image.tobytes except AttributeError: log.info('Patching PIL {from,to}bytes') Image.frombytes = Image.fromstring Image.Image.tobytes = Image.Image.tostring # ---------- try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() log.exception(u'UI线程崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) raise
def command_stats(message): user_action_log(message, 'called ' + message.text) stats.stats(message)
def start_game(self, manager): log.info("game started") stats({'event': 'start_game', 'attributes': {'gametype': manager.gamecls.__name__}}) manager.start_game() self.refresh_status()
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import utils.logging parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', type=int, default=None) parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--zoom', type=float, default=1.0) parser.add_argument('--show-hidden-modes', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') import settings utils.logging.init(options.log.upper(), settings.SENTRY_DSN, settings.VERSION, IS_PROTON or options.color_log) if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate log = logging.getLogger('start_client') from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game.base atexit.register(game.base.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.base.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui # PIL compat from PIL import Image try: Image.frombytes Image.Image.tobytes except AttributeError: log.info('Patching PIL {from,to}bytes') Image.frombytes = Image.fromstring Image.Image.tobytes = Image.Image.tostring # ---------- try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() log.exception(u'UI线程崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) raise
def start_client(): import ctypes try: ctypes.cdll.avbin # force avbin load except: pass import logging import os import argparse import utils.logging parser = argparse.ArgumentParser(prog=sys.argv[0]) parser.add_argument('--no-update', action='store_true') parser.add_argument('--with-gl-errcheck', action='store_true') parser.add_argument('--freeplay', action='store_true') parser.add_argument('--fastjoin', action='store_true') parser.add_argument('--dump-gameobj', action='store_true') parser.add_argument('--log', default='INFO') parser.add_argument('--color-log', action='store_true') parser.add_argument('--show-hidden-modes', action='store_true') options = parser.parse_args() import options as opmodule opmodule.options = options IS_PROTON = hasattr(os, 'uname') and os.uname()[:2] == ('Linux', 'Proton') import settings utils.logging.init(options.log.upper(), settings.SENTRY_DSN, IS_PROTON or options.color_log) utils.logging.patch_gevent_hub_print_exception() if options.no_update: import autoupdate autoupdate.Autoupdate = autoupdate.DummyAutoupdate log = logging.getLogger('start_client') from gevent import monkey monkey.patch_socket() monkey.patch_os() monkey.patch_select() monkey.patch_ssl() from game import autoenv autoenv.init('Client') import pyglet pyglet.options['shadow_window'] = False if not options.with_gl_errcheck: pyglet.options['debug_gl'] = False from pyglet.gl import gl_info if gl_info.get_renderer() == 'GDI Generic': ctypes.windll.user32.MessageBoxW( 0, u'你好像没有安装显卡驱动……?这样游戏是跑不起来的。快去安装!', u'需要显卡驱动', 16, ) sys.exit(0) if sys.platform.startswith('linux') and options.dump_gameobj: import atexit import game atexit.register(game.GameObjectMeta._dump_gameobject_hierarchy) atexit.register(game.EventHandler._dump_eh_dependency_graph) from client.ui.entry import start_ui try: start_ui() except KeyboardInterrupt: import pyglet pyglet.app.exit() raise except: import pyglet pyglet.app.exit() if options.fastjoin: import pdb pdb.post_mortem() log.exception(u'UI线程崩溃,正在报告bug,请稍等下……') from utils.stats import stats stats({'event': 'crash'}) raise