Browse Source

move user detection code to Mumble model, see #55

Natenom/support-murmur-13-1446181288462
fdai2875 15 years ago
parent
commit
390e1ba972
  1. 30
      pyweb/mumble/management/server_detect.py
  2. 37
      pyweb/mumble/models.py

30
pyweb/mumble/management/server_detect.py

@ -114,34 +114,12 @@ def find_existing_instances( **kwargs ):
instance.save( dontConfigureMurmur=True );
# Now search for players on this server that have not yet been registered
if v > 1:
print "Looking for registered Players on Server id %d." % id;
if instance.booted:
players = ctl.getRegisteredPlayers(id);
for playerdata in players:
if playerdata[0] == 0:
continue;
if v > 1:
print "Checking Player with id %d and name '%s'." % ( int(playerdata[0]), playerdata[1] );
try:
models.MumbleUser.objects.get( server=instance, mumbleid=playerdata[0] );
except models.MumbleUser.DoesNotExist:
if v:
print 'Found new Player "%s".' % playerdata[1];
playerinstance = models.MumbleUser(
mumbleid = playerdata[0],
name = playerdata[1],
password = '',
server = instance,
owner = None
);
playerinstance.isAdmin = playerinstance.getAdmin();
playerinstance.save( dontConfigureMurmur=True );
else:
if v > 1:
print "This player is already listed in the database.";
print "Looking for registered Players on Server id %d." % id;
instance.readUsersFromMurmur( verbose=v );
elif v > 1:
print "This server is not running, can't sync players.";
if v > 1:
print "Successfully finished Servers and Players detection.";

37
pyweb/mumble/models.py

@ -227,6 +227,43 @@ class Mumble( models.Model ):
self.save( dontConfigureMurmur=True );
def readUsersFromMurmur( self, verbose=0 ):
if not self.booted:
raise SystemError( "This murmur instance is not currently running, can't sync." );
players = self.ctl.getRegisteredPlayers(id);
for playerdata in players:
if playerdata[0] == 0: # Skip SuperUsers
continue;
if verbose > 1:
print "Checking Player with id %d and name '%s'." % ( int(playerdata[0]), playerdata[1] );
try:
playerinstance = MumbleUser.objects.get( server=instance, mumbleid=playerdata[0] );
except MumbleUser.DoesNotExist:
if verbose:
print 'Found new Player "%s".' % playerdata[1];
playerinstance = models.MumbleUser(
mumbleid = playerdata[0],
name = playerdata[1],
password = '',
server = instance,
owner = None
);
else:
if verbose > 1:
print "This player is already listed in the database.";
playerinstance.name = playerdata[1];
playerinstance.isAdmin = playerinstance.getAdmin();
playerinstance.save( dontConfigureMurmur=True );
def isUserAdmin( self, user ):
"""Determine if the given user is an admin on this server."""
if user.is_authenticated():

Loading…
Cancel
Save