changeset 55:4a1b3c4f8ca5 server

Stubs for the server
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sun, 03 Jun 2007 00:59:56 -0400
parents 51f62586e6bc
children a793c2b15c71
files atcgame/server.py atcserver
diffstat 2 files changed, 99 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/atcgame/server.py	Sun Jun 03 00:59:56 2007 -0400
@@ -0,0 +1,72 @@
+#/*
+# * 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
+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):
+		self.map = mapname
+
+	def zero(self):
+		self.i += 1
+		return self.i
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/atcserver	Sun Jun 03 00:59:56 2007 -0400
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+#/*
+# * 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.
+# */
+
+import os, sys
+
+basedir = os.path.dirname(sys.argv[0])
+
+import atcgame.server
+
+# a hack to make things run from current dir without having to install
+sys.path.insert(0, os.path.join(basedir,"atcgame"))
+
+atcgame.server.main(os.path.join(basedir,"data"), "default")