diff --git a/pyweb/mumble/management/server_detect.py b/pyweb/mumble/management/server_detect.py index d7c902c..e77a62a 100644 --- a/pyweb/mumble/management/server_detect.py +++ b/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."; + if v > 1: + 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."; diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 40aa343..69c369b 100644 --- a/pyweb/mumble/models.py +++ b/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():