|
From: <umg...@us...> - 2007-07-22 15:49:47
|
Revision: 487
http://svn.sourceforge.net/pybridge/?rev=487&view=rev
Author: umgangee
Date: 2007-07-22 08:49:44 -0700 (Sun, 22 Jul 2007)
Log Message:
-----------
Simplify some remote-invokable methods.
Modified Paths:
--------------
trunk/pybridge/pybridge/network/client.py
trunk/pybridge/pybridge/server/server.py
trunk/pybridge/pybridge/server/user.py
Modified: trunk/pybridge/pybridge/network/client.py
===================================================================
--- trunk/pybridge/pybridge/network/client.py 2007-07-20 17:35:23 UTC (rev 486)
+++ trunk/pybridge/pybridge/network/client.py 2007-07-22 15:49:44 UTC (rev 487)
@@ -188,12 +188,11 @@
self.notify('joinTable', tableid=tableid, table=table)
return table
+ params = {}
if host:
- # TODO: why not just joinTable, host=True?
- gamename = gameclass.__name__
- d = self.avatar.callRemote('hostTable', tableid, gamename)
- else:
- d = self.avatar.callRemote('joinTable', tableid)
+ params['gamename'] = gameclass.__name__
+
+ d = self.avatar.callRemote('joinTable', tableid, host, **params)
d.addCallback(success)
return d
Modified: trunk/pybridge/pybridge/server/server.py
===================================================================
--- trunk/pybridge/pybridge/server/server.py 2007-07-20 17:35:23 UTC (rev 486)
+++ trunk/pybridge/pybridge/server/server.py 2007-07-22 15:49:44 UTC (rev 487)
@@ -33,10 +33,9 @@
onlineUsers = LocalUserManager()
-def getServerInfo():
- return {'compatibleVersions': (version, version), # minimum, maximum
- 'supportedGames': 'bridge', # TODO
- 'version': version}
+serverData = {'compatibleClients': (version, version), # minimum, maximum
+ 'supportedGames': SUPPORTED_GAMES.keys(),
+ 'version': version}
def registerUser(username, password):
@@ -54,8 +53,8 @@
log.msg("New user %s registered" % username)
-def changeUserPassword(username, password):
- """Sets the password of user's account.
+def setUserPassword(username, password):
+ """Changes the password of user's account.
@param username: the user identifier.
@param password: the new password for user.
@@ -67,11 +66,12 @@
raise DeniedRequest, "User account does not exist"
-def createTable(tableid, gamename):
+def createTable(tableid, gamename, **tableOptions):
"""Create a new table for the specified game type.
@param tableid: a unique identifier for the table.
- @param gametype: a game identifier.
+ @param gamename: a game class identifier.
+ @param tableOptions: optional parameters for table initialisation.
"""
# TODO: convert gametype string to corresponding class.
@@ -87,5 +87,6 @@
# Provide table instance with a means of closing itself.
table.close = lambda: availableTables.closeTable(table)
availableTables.openTable(table)
+
return table
Modified: trunk/pybridge/pybridge/server/user.py
===================================================================
--- trunk/pybridge/pybridge/server/user.py 2007-07-20 17:35:23 UTC (rev 486)
+++ trunk/pybridge/pybridge/server/user.py 2007-07-22 15:49:44 UTC (rev 487)
@@ -28,7 +28,8 @@
class RegisteredUser(pb.Avatar):
- info = property(lambda self: {}) # TODO: Send profile data?
+ # Static for duration of connection.
+ info = property(lambda self: {'registered': True})
def __init__(self, name):
@@ -56,11 +57,6 @@
# Perspective methods, accessible by client.
- def perspective_getServerInfo(self):
- """Provides a dict of information about the server."""
- return server.getServerInfo()
-
-
def perspective_getRoster(self, name):
"""Provides roster requested by client."""
if name == 'tables':
@@ -71,44 +67,59 @@
raise DeniedRequest, "Unknown roster name \'%s\'" % name
- def perspective_getUserProfile(self, username):
- """Provides profile information for user with specified username."""
- pass
+ def perspective_getServerData(self):
+ """Provides a dict of information about the server."""
+ return server.serverData
+ def perspective_getUserInformation(self, username=None):
+ """Returns public information for user with specified username.
+
+ If username is unspecified, returns user's own profile.
+ """
+ if username is None:
+ username = self.name
+
+ try:
+ user = db.UserAccount.selectBy(username=username)[0]
+ except IndexError:
+ raise DeniedRequest, "Specified user does not exist"
+
+ return {'realname': user.realname, 'email': user.email,
+ 'profile': user.profile}
+
+
+# def perspective_setProfile(self, **kwargs):
+# """Sets avatar's user account profile information to that specified."""
+# pass
+
+
def perspective_changePassword(self, password):
"""Sets avatar's user account password to that specified."""
if not isinstance(password, str):
raise IllegalRequest, "Invalid parameter for password"
- try:
- server.changeUserPassword(self.name, password)
+ try: # Validate password before it is changed.
+ server.setUserPassword(self.name, password)
except ValueError, err: # Password validation failed.
raise DeniedRequest, err
- def perspective_hostTable(self, tableid, gametype):
- """Creates a new table."""
+ def perspective_joinTable(self, tableid, host=False, **hostParams):
+ """Joins an existing table, or creates and joins a new table."""
if not isinstance(tableid, str):
raise IllegalRequest, "Invalid parameter for table identifier"
- if not isinstance(gametype, str):
- raise IllegalRequest, "Invalid parameter for game type"
-
- table = server.createTable(tableid, gametype)
- # Force client to join table.
- return self.perspective_joinTable(tableid)
+ elif tableid in self.joinedTables:
+ raise DeniedRequest, "Already joined table"
+ if host:
+ table = server.createTable(tableid, **hostParams)
+ else:
+ try:
+ table = server.availableTables[tableid]
+ except KeyError:
+ raise DeniedRequest, "No such table"
- def perspective_joinTable(self, tableid):
- """Joins an existing table."""
- if not isinstance(tableid, str):
- raise IllegalRequest, "Invalid parameter for table identifier"
- elif tableid not in server.availableTables:
- raise DeniedRequest, "No such table"
- elif tableid in self.joinedTables:
- raise DeniedRequest, "Already joined table"
-
- table = server.availableTables[tableid]
self.joinedTables[tableid] = table
return table
@@ -135,3 +146,4 @@
server.registerUser(username, password)
except ValueError, err: # Username/password validation failed.
raise DeniedRequest, err
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|