forked from spektral/havencore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
havencore.py
executable file
·90 lines (73 loc) · 2.62 KB
/
havencore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python2
# -*- coding: utf8 -*-
"""
Script for launching the game in different modes.
"""
import logging
import argparse
import os
import time
from server.gameengine import gameengine as serverengine
from client.gameengine import gameengine as clientengine
__author__ = "Christofer Odén"
__copyright__ = "Copyright 2011 Daladevelop"
__license__ = "GPL"
def start_singleplayer(name, addr):
if os.fork():
serverengine.initialize(addr[1])
serverengine.start()
else:
time.sleep(0.2)
clientengine.initialize(name, addr)
clientengine.start()
def setup_logging(debug):
if debug:
output = logging.DEBUG
else:
output = logging.INFO
logging.basicConfig(filename='havencore.log', filemode='w', level=output)
console = logging.StreamHandler()
formatter = logging.Formatter(
'%(levelname)s:%(name)s:%(lineno)s: %(message)s')
console.setFormatter(formatter)
console.setLevel(output)
logging.getLogger().addHandler(console)
def parse_args():
parser = argparse.ArgumentParser(
description='Haven Core, the most awesomest game ever to be '
'written by humans!')
mode = parser.add_mutually_exclusive_group()
output = parser.add_mutually_exclusive_group()
mode.add_argument('host', nargs='?', default='127.0.0.1',
help='server hostname or IP address to connect to')
mode.add_argument('-s', '--single-player', action='store_true',
help='start a local server and connect to it as a client')
parser.add_argument('-l', '--listen', action='store_true',
help='start as server')
parser.add_argument('-p', '--port', type=int, default=60000,
help='the port to listen on or connect to')
parser.add_argument('-n', '--name', default="Player",
help='sets your player name')
output.add_argument('-v', '--verbose', action='store_true',
help='show debug output')
parser.add_argument
return parser.parse_args()
def main():
args = parse_args()
setup_logging(args.verbose)
if args.single_player:
logging.info("Running in single player mode...")
start_singleplayer(args.name, (args.host, args.port))
return
gameengine = None
if args.listen:
logging.info("Running in server mode...")
serverengine.initialize(args.port)
gameengine = serverengine
else:
logging.info("Running in client mode...")
clientengine.initialize(args.name, (args.host, args.port))
gameengine = clientengine
gameengine.start()
main()
# vim: ts=4 et tw=79 cc=+1