From: <ch...@us...> - 2010-08-28 13:36:17
|
Revision: 377 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=377&view=rev Author: chozone Date: 2010-08-28 13:36:11 +0000 (Sat, 28 Aug 2010) Log Message: ----------- Added landscapes to server (retrieving them from database + sending them to client upon login) Modified Paths: -------------- trunk/server/VPS.py trunk/server/callback.py trunk/server/database trunk/server/filetable.py trunk/server/functions.py Added Paths: ----------- trunk/server/landscapes.py Modified: trunk/server/VPS.py =================================================================== --- trunk/server/VPS.py 2010-08-27 21:40:53 UTC (rev 376) +++ trunk/server/VPS.py 2010-08-28 13:36:11 UTC (rev 377) @@ -43,7 +43,7 @@ # Users table has no admins create_account_setup() - print "Database check done..." + print "Database check done." def create_account_setup(): # Ask user if he wants to create an account (1st one, admin) @@ -81,6 +81,8 @@ check_database() file_table.update_from_database() +landscapes.update_from_database() + server = core.Server(config, Callback()) server.start_server() Modified: trunk/server/callback.py =================================================================== --- trunk/server/callback.py 2010-08-27 21:40:53 UTC (rev 376) +++ trunk/server/callback.py 2010-08-28 13:36:11 UTC (rev 377) @@ -41,6 +41,8 @@ # download what they need. self.clients[cid]['con'].custom_send("filetable", file_table.table) + self.clients[cid]['con'].custom_send("landscapes", landscapes.list) + def leaves_vp(self, cid): print " < %s: %s"%(cid, self.clients[cid]['con'].ip) Modified: trunk/server/database =================================================================== --- trunk/server/database 2010-08-27 21:40:53 UTC (rev 376) +++ trunk/server/database 2010-08-28 13:36:11 UTC (rev 377) @@ -26,3 +26,12 @@ PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;''' +landscapes = '''CREATE TABLE IF NOT EXISTS `landscapes` ( + `id` int(11) NOT NULL auto_increment, + `type` varchar(255) NOT NULL, + `direction` varchar(255) NOT NULL, + `position` int(11) NOT NULL, + `transition` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1;''' + Modified: trunk/server/filetable.py =================================================================== --- trunk/server/filetable.py 2010-08-27 21:40:53 UTC (rev 376) +++ trunk/server/filetable.py 2010-08-28 13:36:11 UTC (rev 377) @@ -21,6 +21,8 @@ self.db = db def update_from_database(self): + print "Retrieving file table from database..." + self.table = {} self.db.execute("SELECT `filename`, `url`, `checksum` FROM `files`") @@ -31,6 +33,8 @@ self.table[file['filename']] = {'url': fullurl, 'checksum': file['checksum']} + + print "Done, found %s entries in file table." % len(self.table) return self.table def add(self, filename, url, checksum): Modified: trunk/server/functions.py =================================================================== --- trunk/server/functions.py 2010-08-27 21:40:53 UTC (rev 376) +++ trunk/server/functions.py 2010-08-28 13:36:11 UTC (rev 377) @@ -20,6 +20,7 @@ import database from filetable import FileTable +from landscapes import LandscapeManager try: from configobj import ConfigObj except: sys.exit("ERROR: You need the configobj-module for this to work!") @@ -70,6 +71,7 @@ config['database']['host']) file_table = FileTable(db) +landscapes = LandscapeManager(db) \ No newline at end of file Added: trunk/server/landscapes.py =================================================================== --- trunk/server/landscapes.py (rev 0) +++ trunk/server/landscapes.py 2010-08-28 13:36:11 UTC (rev 377) @@ -0,0 +1,34 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009-2010 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## 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. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +class LandscapeManager(): + def __init__(self, db): + self.list = () + self.db = db + + def update_from_database(self): + print "Retrieving landscapes from database..." + + self.list = {} + + self.db.execute("SELECT `type`, `direction`, `position`, 'transition' \ + FROM `landscapes` ORDER BY `id` ASC") # Order in DB = order in world + self.list = self.db.fetchall() + + print "Done, found %s landscapes." % len(self.list) + + return self.list \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |