From: <Blu...@us...> - 2010-09-01 21:01:28
|
Revision: 388 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=388&view=rev Author: BlueWolf_ Date: 2010-09-01 21:01:21 +0000 (Wed, 01 Sep 2010) Log Message: ----------- * Added a config to the client * Stuff like FPS and host is now configurable * Client now stores the login information and uses that (no way to log out yet) * 'Effects' option doesn't do anything yet Modified Paths: -------------- trunk/client/VP.py trunk/client/functions.py trunk/client/playground.py Added Paths: ----------- trunk/client/configspec Property Changed: ---------------- trunk/client/ Property changes on: trunk/client ___________________________________________________________________ Added: svn:ignore + config.conf Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-09-01 18:20:17 UTC (rev 387) +++ trunk/client/VP.py 2010-09-01 21:01:21 UTC (rev 388) @@ -29,9 +29,12 @@ class Main(): def __init__(self): + load_config() + sh['filetable'] = {} sh['timer'] = Timer() sh['downloader'] = Downloader() + sh['login_info'] = None # Fire up pygame os.environ['SDL_VIDEO_CENTERED']='1' @@ -70,7 +73,8 @@ "status": "login", "where": "connecting" }) - sh['client'].connect(*SERVER) + sh['client'].connect(sh['config']['host']['host'], \ + sh['config']['host']['port']) # Wait for all the events to come @@ -104,6 +108,7 @@ try: sh['client'].close() except: pass sh['downloader'].stop() + sh['config'].write() sys.exit() @@ -144,10 +149,10 @@ class Timer(): """ - This timer will update every frame as defined in UPDATE_FPS @ functions.py + This timer will update every frame as defined in the config """ def __init__(self): - self.speed = 1/float(UPDATE_FPS) + self.speed = 1/float(sh['config']['graphics']['fps']) self.callers = {} self.timer = None @@ -210,16 +215,33 @@ "where": "logging in" }) else: - sh['main'].call("status", { - "status": "login", - "where": "waiting" - }) + # Do we need to log in automatically? + if sh['config']['user']['username'] != "": + sh['main'].call("status", { + "status": "login", + "where": "logging in" + }) + sh['client'].login(sh['config']['user']['username'], \ + sh['config']['user']['password']) + + else: + sh['main'].call("status", { + "status": "login", + "where": "waiting" + }) def logged_in(self, username, cid, owner): sh['main'].call("status", { "status": "login", "where": "downloading" }) + + # Save the login + if sh['login_info'] != None: + sh['config']['user']['username'] = sh['login_info'][0] + sh['config']['user']['password'] = sh['login_info'][1] + sh['login_info'] = None + sh['config'].write() def failed_logging_in(self, reason): # [TODO] Send the reason in some way @@ -228,10 +250,18 @@ "status": "login", "where": "waiting" }) + + sh['config']['user']['username'] = "" + sh['config']['user']['password'] = "" + sh['login_info'] = None + sh['config'].write() + def disconnected(self, reason): print " !!! \tConnection closed: " + reason + sh['login_info'] = None + if reason == "manual": return # [TODO] Send the reason in some way @@ -249,8 +279,16 @@ "status": "login", "where": "connecting" }) - sh['client'].connect(*SERVER) + # But don't reconnect when we where a duplicate + if reason == "duplicate": + sh['config']['user']['username'] = "" + sh['config']['user']['password'] = "" + sh['config'].write() + + sh['client'].connect(sh['config']['host']['host'], \ + sh['config']['host']['port']) + else: # Not doing anything at all # [TODO] Show popup or something, without reconnecting? Added: trunk/client/configspec =================================================================== --- trunk/client/configspec (rev 0) +++ trunk/client/configspec 2010-09-01 21:01:21 UTC (rev 388) @@ -0,0 +1,11 @@ +[user] +username = string(default="") +password = string(default="") + +[graphics] +fps = integer(min=1, default=50) +effects = boolean(default=True) + +[host] +host = string(default=vp.bluewolf.nl) +port = integer(default=6653) Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-09-01 18:20:17 UTC (rev 387) +++ trunk/client/functions.py 2010-09-01 21:01:21 UTC (rev 388) @@ -18,14 +18,12 @@ import pygame, os, sys, threading, time, math from pygame.locals import * from hashlib import sha1, md5 +import configobj +from validate import Validator import core VERSION = "0.0.1" -SERVER = ("vp.bluewolf.nl", 6653) - -UPDATE_FPS = 50 - # This will be used to [sh]are all variables, functions and classes across the # code sh = {} @@ -64,7 +62,31 @@ checksum.update(data) return checksum.hexdigest() + +def load_config(): + # Load the config file and apply the default values to it if needed + + try: + sh['config'] = configobj.ConfigObj(real_path("config.conf"), \ + configspec = real_path("configspec")) + except configobj.ParseError: + print "Config: The config-file is malformed. Please check the file " + \ + "or remove it to create a new default one" + sys.exit() + + validator = Validator() + result = sh['config'].validate(validator, copy = True) + + if result != True: + for (section_list, key, _) in configobj.flatten_errors(sh['config'], \ + result): + if key is not None: + print "Config: Something is wrong with the " + \ + "'%s/%s' key. Please check" % (section_list[0], key) + else: + print "Config: The '%s' section is missing" % section_list[0] + sys.exit() Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-01 18:20:17 UTC (rev 387) +++ trunk/client/playground.py 2010-09-01 21:01:21 UTC (rev 388) @@ -342,6 +342,9 @@ "where": "logging in" }) + # Save the info so it can be saved it the login succeeds + sh['login_info'] = (usr,pwd) + sh['client'].login(usr, pwd) elif obj.name == "signup": This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |