Browse Source

check for stale mumble instances/users when syncing and remove them from the database. fixes #120

Natenom/support-murmur-13-1446181288462
Michael Ziegler 14 years ago
parent
commit
a6fdd8be7c
  1. 14
      pyweb/mumble/management/server_detect.py
  2. 20
      pyweb/mumble/models.py

14
pyweb/mumble/management/server_detect.py

@ -20,7 +20,7 @@ import os, getpass
from django.db import DatabaseError
from django.conf import settings
from mumble.models import MumbleServer, Mumble
from mumble.models import MumbleServer, Mumble, signals
from mumble.mctl import MumbleCtlBase
@ -101,6 +101,7 @@ def find_existing_instances( **kwargs ):
print "Successfully connected to Murmur via connection string %s, using %s." % ( dbusName, ctl.method )
servIDs = ctl.getAllServers()
unseen_ids = [rec["srvid"] for rec in Mumble.objects.values( "srvid" )]
try:
meta = MumbleServer.objects.get( dbus=dbusName )
@ -111,6 +112,7 @@ def find_existing_instances( **kwargs ):
meta.save()
for id in servIDs:
unseen_ids.remove(id)
if v > 1:
print "Checking Murmur instance with id %d." % id
# first check that the server has not yet been inserted into the DB
@ -169,6 +171,16 @@ def find_existing_instances( **kwargs ):
elif v:
print "This server is not running, can't sync players."
signals.pre_delete.disconnect( Mumble.pre_delete_listener, sender=Mumble )
for srvid in unseen_ids:
mm = Mumble.objects.get( srvid=srvid )
if v:
print 'Found stale Mumble instance "%s".' % mm.name
mm.delete()
signals.pre_delete.connect( Mumble.pre_delete_listener, sender=Mumble )
print "Successfully finished Servers and Players detection."
print "To add more servers, run this command again."
return True

20
pyweb/mumble/models.py

@ -356,7 +356,7 @@ class Mumble( models.Model ):
raise SystemError( "This murmur instance is not currently running, can't sync." )
players = self.ctl.getRegisteredPlayers(self.srvid)
known_ids = [rec["mumbleid"]
unseen_ids = [rec["mumbleid"]
for rec in MumbleUser.objects.filter( server=self ).values( "mumbleid" )
]
@ -366,11 +366,11 @@ class Mumble( models.Model ):
if playerdata.userid == 0: # Skip SuperUsers
continue
if verbose > 1:
print "Checking Player with id %d." % playerdata.userid
print "Checking User with id %d." % playerdata.userid
if playerdata.userid not in known_ids:
if playerdata.userid not in unseen_ids:
if verbose:
print 'Found new Player "%s".' % playerdata.name
print 'Found new User "%s".' % playerdata.name
playerinstance = MumbleUser(
mumbleid = playerdata.userid,
@ -382,12 +382,22 @@ class Mumble( models.Model ):
else:
if verbose > 1:
print "Player '%s' is already known." % playerdata.name
print "User '%s' is already known." % playerdata.name
unseen_ids.remove(playerdata.userid)
playerinstance = MumbleUser.objects.get( server=self, mumbleid=playerdata.userid )
playerinstance.name = playerdata.name
playerinstance.save( dontConfigureMurmur=True )
signals.pre_delete.disconnect( MumbleUser.pre_delete_listener, sender=MumbleUser )
for uid in unseen_ids:
mu = MumbleUser.objects.get( mumbleid=uid )
if verbose:
print 'Found stale MumbleUser "%s".' % mu.name
mu.delete()
signals.pre_delete.connect( MumbleUser.pre_delete_listener, sender=MumbleUser )
def isUserAdmin( self, user ):
""" Determine if the given user is an admin on this server. """

Loading…
Cancel
Save