Browse Source

standardize user information handling

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
6d32b13210
  1. 7
      muco.py
  2. 55
      pyweb/mumble/MumbleCtlDbus.py
  3. 54
      pyweb/mumble/MumbleCtlIce.py
  4. 4
      pyweb/mumble/mmobjects.py
  5. 25
      pyweb/mumble/models.py

7
muco.py

@ -156,8 +156,11 @@ class WndSettings( BaseWindow ):
key = self.win.getch(); key = self.win.getch();
if key == curses.KEY_UP and self.selIdx > 0:
self.selIdx -= 1;
if key == curses.KEY_UP:
if self.selIdx > 0:
self.selIdx -= 1;
else:
return;
elif key == curses.KEY_DOWN and self.selIdx < self.selMax: elif key == curses.KEY_DOWN and self.selIdx < self.selMax:
self.selIdx += 1; self.selIdx += 1;

55
pyweb/mumble/MumbleCtlDbus.py

@ -87,7 +87,7 @@ class MumbleCtlDbus_118(MumbleCtlBase):
return self.meta.newServer() return self.meta.newServer()
def registerPlayer(self, srvid, name, email, password): def registerPlayer(self, srvid, name, email, password):
mumbleid = MumbleCtlDbus_118.convertDbusTypeToNative( self._getDbusServerObject(srvid).registerPlayer(name) );
mumbleid = int( self._getDbusServerObject(srvid).registerPlayer(name) );
self.setRegistration( srvid, mumbleid, name, email, password ); self.setRegistration( srvid, mumbleid, name, email, password );
return mumbleid; return mumbleid;
@ -95,44 +95,55 @@ class MumbleCtlDbus_118(MumbleCtlBase):
self._getDbusServerObject(srvid).unregisterPlayer(dbus.Int32( mumbleid )) self._getDbusServerObject(srvid).unregisterPlayer(dbus.Int32( mumbleid ))
def getChannels(self, srvid): def getChannels(self, srvid):
chans = MumbleCtlDbus_118.convertDbusTypeToNative(self._getDbusServerObject(srvid).getChannels())
chans = self._getDbusServerObject(srvid).getChannels()
ret = {}; ret = {};
for channel in chans: for channel in chans:
ret[ channel[0] ] = ObjectInfo( ret[ channel[0] ] = ObjectInfo(
id = channel[0],
name = channel[1],
parent = channel[2],
links = channel[3],
id = int(channel[0]),
name = str(channel[1]),
parent = int(channel[2]),
links = [ int(lnk) for lnk in channel[3] ],
); );
return ret; return ret;
def getPlayers(self, srvid): def getPlayers(self, srvid):
players = MumbleCtlDbus_118.convertDbusTypeToNative(self._getDbusServerObject(srvid).getPlayers());
players = self._getDbusServerObject(srvid).getPlayers();
ret = {}; ret = {};
for playerObj in players: for playerObj in players:
ret[ playerObj[0] ] = ObjectInfo(
session = playerObj[0],
mute = playerObj[1],
deaf = playerObj[2],
suppress = playerObj[3],
selfMute = playerObj[4],
selfDeaf = playerObj[5],
channel = playerObj[6],
userid = playerObj[7],
name = playerObj[8],
onlinesecs = playerObj[9],
bytespersec = playerObj[10]
ret[ int(playerObj[0]) ] = ObjectInfo(
session = int( playerObj[0] ),
mute = bool( playerObj[1] ),
deaf = bool( playerObj[2] ),
suppress = bool( playerObj[3] ),
selfMute = bool( playerObj[4] ),
selfDeaf = bool( playerObj[5] ),
channel = int( playerObj[6] ),
userid = int( playerObj[7] ),
name = str( playerObj[8] ),
onlinesecs = int( playerObj[9] ),
bytespersec = int( playerObj[10] )
); );
return ret; return ret;
def getRegisteredPlayers(self, srvid, filter = ''): def getRegisteredPlayers(self, srvid, filter = ''):
return MumbleCtlDbus_118.convertDbusTypeToNative(self._getDbusServerObject(srvid).getRegisteredPlayers( filter ) )
users = self._getDbusServerObject(srvid).getRegisteredPlayers( filter );
ret = {};
for user in users:
ret[int(user[0])] = ObjectInfo(
userid = int( user[0] ),
name = unicode( user[1] ),
email = unicode( user[2] ),
pw = unicode( user[3] )
);
return ret
def getACL(self, srvid, channelid): def getACL(self, srvid, channelid):
raw_acls, raw_groups, raw_inherit = self._getDbusServerObject(srvid).getACL(channelid) raw_acls, raw_groups, raw_inherit = self._getDbusServerObject(srvid).getACL(channelid)
@ -244,11 +255,11 @@ class MumbleCtlDbus_118(MumbleCtlBase):
return -2; return -2;
ok = MumbleCtlDbus_118.convertDbusTypeToNative( ok = MumbleCtlDbus_118.convertDbusTypeToNative(
self._getDbusServerObject(srvid).verifyPassword( dbus.Int32( player[0][0] ), password )
self._getDbusServerObject(srvid).verifyPassword( dbus.Int32( player[0].userid ), password )
); );
if ok: if ok:
return player[0][0];
return player[0].userid;
else: else:
return -1; return -1;

54
pyweb/mumble/MumbleCtlIce.py

@ -24,6 +24,8 @@ from django.conf import settings
from mctl import MumbleCtlBase from mctl import MumbleCtlBase
from utils import ObjectInfo
import Ice import Ice
@ -113,10 +115,15 @@ class MumbleCtlIce_118(MumbleCtlBase):
@protectDjangoErrPage @protectDjangoErrPage
def getRegisteredPlayers(self, srvid, filter = ''): def getRegisteredPlayers(self, srvid, filter = ''):
users = self._getIceServerObject(srvid).getRegisteredPlayers( filter.encode( "UTF-8" ) ) users = self._getIceServerObject(srvid).getRegisteredPlayers( filter.encode( "UTF-8" ) )
ret = []
ret = {};
for user in users: for user in users:
ret.append([user.playerid, self.setUnicodeFlag(user.name), self.setUnicodeFlag(user.email), self.setUnicodeFlag(user.pw)])
ret[user.playerid] = ObjectInfo(
userid = int( user.playerid ),
name = unicode( user.name, "utf8" ),
email = unicode( user.email, "utf8" ),
pw = unicode( user.pw, "utf8" )
);
return ret return ret
@ -126,7 +133,27 @@ class MumbleCtlIce_118(MumbleCtlBase):
@protectDjangoErrPage @protectDjangoErrPage
def getPlayers(self, srvid): def getPlayers(self, srvid):
return self._getIceServerObject(srvid).getPlayers()
users = self._getIceServerObject(srvid).getPlayers()
ret = {};
for useridx in users:
user = users[useridx];
ret[ user.session ] = ObjectInfo(
session = user.session,
userid = user.playerid,
mute = user.mute,
deaf = user.deaf,
suppress = user.suppressed,
selfMute = user.selfMute,
selfDeaf = user.selfDeaf,
channel = user.channel,
name = user.name,
onlinesecs = user.onlinesecs,
bytespersec = user.bytespersec
);
return ret;
@protectDjangoErrPage @protectDjangoErrPage
def getDefaultConf(self): def getDefaultConf(self):
@ -179,10 +206,12 @@ class MumbleCtlIce_118(MumbleCtlBase):
@protectDjangoErrPage @protectDjangoErrPage
def getRegistration(self, srvid, mumbleid): def getRegistration(self, srvid, mumbleid):
user = self._getIceServerObject(srvid).getRegistration(mumbleid) user = self._getIceServerObject(srvid).getRegistration(mumbleid)
return {
'name': user.name,
'email': user.email,
};
return ObjectInfo(
userid = mumbleid,
name = user.name,
email = user.email,
pw = '',
);
@protectDjangoErrPage @protectDjangoErrPage
def setRegistration(self, srvid, mumbleid, name, email, password): def setRegistration(self, srvid, mumbleid, name, email, password):
@ -292,10 +321,15 @@ class MumbleCtlIce_120(MumbleCtlIce_118):
@protectDjangoErrPage @protectDjangoErrPage
def getRegisteredPlayers(self, srvid, filter = ''): def getRegisteredPlayers(self, srvid, filter = ''):
users = self._getIceServerObject( srvid ).getRegisteredUsers( filter.encode( "UTF-8" ) ) users = self._getIceServerObject( srvid ).getRegisteredUsers( filter.encode( "UTF-8" ) )
ret = []
ret = {};
for id in users: for id in users:
ret.append( [ id, self.setUnicodeFlag( users[id] ) ] );
ret[id] = ObjectInfo(
userid = id,
name = unicode( users[id], "utf8" ),
email = '',
pw = ''
);
return ret return ret
@ -332,7 +366,7 @@ class MumbleCtlIce_120(MumbleCtlIce_118):
user['comment'] = reg[UserInfo.UserComment]; user['comment'] = reg[UserInfo.UserComment];
if UserInfo.UserHash in reg: if UserInfo.UserHash in reg:
user['hash'] = reg[UserInfo.UserHash]; user['hash'] = reg[UserInfo.UserHash];
return user;
return ObjectInfo( **user );
@protectDjangoErrPage @protectDjangoErrPage
def setRegistration(self, srvid, mumbleid, name, email, password): def setRegistration(self, srvid, mumbleid, name, email, password):

4
pyweb/mumble/mmobjects.py

@ -24,6 +24,7 @@ from django.utils.http import urlquote
from django.conf import settings from django.conf import settings
def cmp_names( a, b ): def cmp_names( a, b ):
""" Compare two objects by their name property. """
return cmp( a.name, b.name ); return cmp( a.name, b.name );
@ -222,7 +223,7 @@ class mmPlayer( object ):
class mmACL:
class mmACL( object ):
"""Represents an ACL for a certain channel.""" """Represents an ACL for a certain channel."""
def __init__( self, channel, aclObj ): def __init__( self, channel, aclObj ):
@ -271,6 +272,7 @@ class mmACL:
group.remove.append( userid ); group.remove.append( userid );
def save( self ): def save( self ):
""" Send this ACL to Murmur. """
return self.channel.server.ctl.setACL( return self.channel.server.ctl.setACL(
self.channel.server.srvid, self.channel.server.srvid,
self.channel.chanid, self.channel.chanid,

25
pyweb/mumble/models.py

@ -237,22 +237,24 @@ class Mumble( models.Model ):
players = self.ctl.getRegisteredPlayers(self.srvid); players = self.ctl.getRegisteredPlayers(self.srvid);
for playerdata in players:
if playerdata[0] == 0: # Skip SuperUsers
for idx in players:
playerdata = players[idx];
if playerdata.userid == 0: # Skip SuperUsers
continue; continue;
if verbose > 1: if verbose > 1:
print "Checking Player with id %d and name '%s'." % ( int(playerdata[0]), playerdata[1] );
print "Checking Player with id %d and name '%s'." % ( playerdata.userid, playerdata.name );
try: try:
playerinstance = MumbleUser.objects.get( server=self, mumbleid=playerdata[0] );
playerinstance = MumbleUser.objects.get( server=self, mumbleid=playerdata.userid );
except MumbleUser.DoesNotExist: except MumbleUser.DoesNotExist:
if verbose: if verbose:
print 'Found new Player "%s".' % playerdata[1];
print 'Found new Player "%s".' % playerdata.name;
playerinstance = MumbleUser( playerinstance = MumbleUser(
mumbleid = playerdata[0],
name = playerdata[1],
mumbleid = playerdata.userid,
name = playerdata.name,
password = '', password = '',
server = self, server = self,
owner = None owner = None
@ -262,7 +264,7 @@ class Mumble( models.Model ):
if verbose > 1: if verbose > 1:
print "This player is already listed in the database."; print "This player is already listed in the database.";
playerinstance.name = playerdata[1];
playerinstance.name = playerdata.name;
playerinstance.isAdmin = playerinstance.getAdmin(); playerinstance.isAdmin = playerinstance.getAdmin();
playerinstance.save( dontConfigureMurmur=True ); playerinstance.save( dontConfigureMurmur=True );
@ -290,10 +292,10 @@ class Mumble( models.Model ):
# Channel list # Channel list
def getChannels( self ): def getChannels( self ):
"""Query the channels from Murmur and create a tree structure.
""" Query the channels from Murmur and create a tree structure.
Again, this will only be done for the first call to this function. Subsequent
calls will simply return the list created last time.
Again, this will only be done for the first call to this function. Subsequent
calls will simply return the list created last time.
""" """
if self._channels is None: if self._channels is None:
self._channels = {}; self._channels = {};
@ -507,6 +509,7 @@ class MumbleUser( models.Model ):
texture = property( getTexture, setTexture, doc="Get the texture as a PIL Image or read from a file (pass the path)." ); texture = property( getTexture, setTexture, doc="Get the texture as a PIL Image or read from a file (pass the path)." );
def hasTexture( self ): def hasTexture( self ):
""" Check if this user has a texture set. """
try: try:
self.getTexture(); self.getTexture();
except ValueError: except ValueError:

Loading…
Cancel
Save