view atcgame/server.py @ 56:a793c2b15c71 server

server: load a specified map from fs
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sun, 03 Jun 2007 01:18:28 -0400
parents 4a1b3c4f8ca5
children 35999e551d7a
line wrap: on
line source

#/*
# * ATC - Air Traffic Controller simulation game
# *
# * Copyright (C) 2004-2007 Josef "Jeff" Sipek <jeffpc@josefsipek.net>
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License version 2 as
# * published by the Free Software Foundation.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU General Public License for more details.
# */

try:
	import os
	import sys
	import threading
	import time
	from SimpleXMLRPCServer import SimpleXMLRPCServer
	
	import config
	import utils
	import maps
except ImportError, err:
	print "Couldn't load module %s" % (err)
	sys.exit()


try:
	from __version__ import version
except ImportError, err:
	version = "?"

def main(datadir_arg, mapname):
	""" Main fn to run the main thread """
	def server_helper():
		while not ShutDown:
			server.handle_request()

	ShutDown = False
	
	config.datadir = datadir_arg

	state = ATCServer(mapname)

	server = SimpleXMLRPCServer(("localhost", 9000))
	server.register_introspection_functions()
	server.allow_reuse_address = True

	server.register_instance(state)

	server_thread = threading.Timer(0, server_helper)
	server_thread.start()

	try:
		while True:
			print "X"
			time.sleep(5)
			pass
	except KeyboardInterrupt:
		print "Shutting down..."
		ShutDown = True

class ATCServer:
	def __init__(self, mapname):
		# Find the map
		self.map = maps.getmap(mapname)
		self.map.bootstrap_navs()

		# List of all planes in the world
		self.planes = []

	def __run(self):
		for p in self.planes:
			p.update()

	def zero(self):
		return 0