import argparse import asyncio import logging import textwrap def main(args: argparse.Namespace) -> int: from sampy.config import Config config = Config(*args.config, logging_level=args.log) from sampy.network.protocol import Protocol from sampy.server import InteractiveServer server = InteractiveServer( Protocol, config=config, ) server.start() asyncio.get_event_loop().run_forever() return 0 if __name__ == "__main__": class Formatter( argparse.ArgumentDefaultsHelpFormatter, argparse.RawTextHelpFormatter ): pass parser = argparse.ArgumentParser( prog="sampy", description=textwrap.dedent( """ A SAMP server made in python SAMP (or SA-MP) is a free multiplayer mod for the PC port of GTA: San Andreas. GTA: San Andreas was developed by Rockstar North and released in 2005. SA-MP is an unofficial multiplayer mod made by the `SA-MP.com` team released @[sa-mp.com](https://www.sa-mp.com/) """ ), epilog=textwrap.dedent( """ example: %(prog)s --config default.ini secret.ini race.ini This will first load default.ini configuration, secret.ini might override the rcon- and server-password, race.ini might change the hostname and rules. example default.ini: [sampy] hostname = My SAMP Server password = rcon_password = VerySecretPassword [sampy.rules] lagcomp = off [logging.loggers] keys = root [logging.handlers] keys = console, file [logging.formatters] keys = simple, color [logging.logger_root] level = DEBUG handlers = console, file [logging.handler_console] class = StreamHandler formatter = color args = (sys.stdout,) [logging.handler_file] class = logging.handlers.TimedRotatingFileHandler formatter = simple args = ("logs/sampy.log", "d", 1, 7,) # Note that the logs folder has to exist [logging.formatter_simple] format = %%(asctime)s.%%(msecs)03d | %%(levelname)-8s | %%(message)s datefmt = %%Y-%%m-%%d %%H:%%M:%%S [logging.formatter_color] class = sampy.config.ColorFormatter format = §6%%(asctime)s.%%(msecs)03d §1| %%(levelname)-8s §1|§r %%(message)s datefmt = %%Y-%%m-%%d %%H:%%M:%%S """ ), formatter_class=Formatter, ) parser.add_argument( "--config", type=str, nargs="+", default=[], help="Config filenames", ) parser.add_argument( "--log", type=str, nargs="?", help="Global logging level (Overrides any config)", choices=logging._nameToLevel.keys(), ) args = parser.parse_args() raise SystemExit(main(args))