Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

697 lines
23 KiB

16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
15 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  4. *
  5. * Mumble-Django is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This package is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. """
  15. import socket, Ice, re
  16. from sys import stderr
  17. from django.utils.translation import ugettext_noop, ugettext_lazy as _
  18. from django.contrib.auth.models import User
  19. from django.db import models
  20. from django.db.models import signals
  21. from django.conf import settings
  22. from mumble.mmobjects import mmChannel, mmPlayer
  23. from mumble.mctl import MumbleCtlBase
  24. def mk_config_property( field, doc="", get_coerce=None, get_none=None, set_coerce=unicode, set_none='' ):
  25. """ Create a property for the given config field. """
  26. def get_field( self ):
  27. if self.id is not None:
  28. val = self.getConf( field );
  29. if val is None or val == '':
  30. return get_none
  31. if callable(get_coerce):
  32. return get_coerce( val )
  33. return val
  34. return None
  35. def set_field( self, value ):
  36. if value is None:
  37. self.setConf( field, set_none )
  38. elif callable(set_coerce):
  39. self.setConf( field, set_coerce(value) )
  40. else:
  41. self.setConf( field, value )
  42. return property( get_field, set_field, doc=doc )
  43. def mk_config_bool_property( field, doc="" ):
  44. return mk_config_property( field, doc=doc,
  45. get_coerce = lambda value: value == "true",
  46. set_coerce = lambda value: str(value).lower()
  47. );
  48. class MumbleServer( models.Model ):
  49. """ Represents a Murmur server installation. """
  50. dbus = models.CharField( _('DBus or ICE base'), max_length=200, unique=True, default=settings.DEFAULT_CONN, help_text=_(
  51. "Examples: 'net.sourceforge.mumble.murmur' for DBus or 'Meta:tcp -h 127.0.0.1 -p 6502' for Ice.") );
  52. secret = models.CharField( _('Ice Secret'), max_length=200, blank=True );
  53. class Meta:
  54. verbose_name = _('Mumble Server');
  55. verbose_name_plural = _('Mumble Servers');
  56. def __init__( self, *args, **kwargs ):
  57. models.Model.__init__( self, *args, **kwargs );
  58. self._ctl = None;
  59. self._conf = None;
  60. def __unicode__( self ):
  61. return self.dbus;
  62. # Ctl instantiation
  63. def getCtl( self ):
  64. """ Instantiate and return a MumbleCtl object for this server.
  65. Only one instance will be created, and reused on subsequent calls.
  66. """
  67. if not self._ctl:
  68. self._ctl = MumbleCtlBase.newInstance( self.dbus, settings.SLICE, self.secret );
  69. return self._ctl;
  70. ctl = property( getCtl, doc="Get a Control object for this server. The ctl is cached for later reuse." );
  71. def isMethodDbus(self):
  72. """ Return true if this instance uses DBus. """
  73. rd = re.compile( r'^(\w+\.)*\w+$' );
  74. return bool(rd.match(self.dbus))
  75. method_dbus = property( isMethodDbus )
  76. method_ice = property( lambda self: not self.isMethodDbus(), doc="Return true if this instance uses Ice." )
  77. def getDefaultConf( self, field=None ):
  78. """ Get a field from the default conf dictionary, or None if the field isn't set. """
  79. if self._conf is None:
  80. self._conf = self.ctl.getDefaultConf()
  81. if field is None:
  82. return self._conf
  83. if field in self._conf:
  84. return self._conf[field]
  85. return None
  86. def isOnline( self ):
  87. """ Return true if this server process is running. """
  88. possibleexceptions = []
  89. try:
  90. from Ice import ConnectionRefusedException
  91. except ImportError, err:
  92. if self.method_ice:
  93. print >> stderr, err
  94. return None
  95. else:
  96. possibleexceptions.append( ConnectionRefusedException )
  97. try:
  98. from dbus import DBusException
  99. except ImportError, err:
  100. if self.method_dbus:
  101. print >> stderr, err
  102. return None
  103. else:
  104. possibleexceptions.append( DBusException )
  105. try:
  106. self.ctl
  107. except tuple(possibleexceptions), err:
  108. print >> stderr, err
  109. return False
  110. except (EnvironmentError, RuntimeError), err:
  111. print >> stderr, err
  112. return None
  113. else:
  114. return True
  115. online = property( isOnline )
  116. defaultconf = property( getDefaultConf, doc="The default config dictionary." )
  117. class Mumble( models.Model ):
  118. """ Represents a Murmur server instance.
  119. All configurable settings are represented by a field in this model. To change the
  120. settings, just update the appropriate field and call the save() method.
  121. To set up a new server instance, instanciate this Model. The first field you should
  122. define is the "dbus" field, which tells the connector subsystem how to connect to
  123. the Murmurd master process. Set this to the appropriate DBus service name or the
  124. Ice proxy string.
  125. When an instance of this model is deleted, the according server instance will be
  126. deleted as well.
  127. """
  128. server = models.ForeignKey( MumbleServer );
  129. name = models.CharField( _('Server Name'), max_length=200 );
  130. srvid = models.IntegerField( _('Server ID'), editable=False );
  131. addr = models.CharField( _('Server Address'), max_length=200, blank=True, help_text=_(
  132. "Hostname or IP address to bind to. You should use a hostname here, because it will appear on the "
  133. "global server list.") );
  134. port = models.IntegerField( _('Server Port'), blank=True, null=True, help_text=_(
  135. "Port number to bind to. Leave empty to auto assign one.") );
  136. display = models.CharField( _('Server Display Address'), max_length=200, blank=True, help_text=_(
  137. "This field is only relevant if you are located behind a NAT, and names the Hostname or IP address "
  138. "to use in the Channel Viewer and for the global server list registration. If not given, the addr "
  139. "and port fields are used. If display and bind ports are equal, you can omit it here.") );
  140. supw = property( lambda self: '',
  141. lambda self, value: ( value and self.ctl.setSuperUserPassword( self.srvid, value ) ) or None,
  142. doc=_('Superuser Password')
  143. )
  144. url = mk_config_property( "registerurl", ugettext_noop("Website URL") )
  145. motd = mk_config_property( "welcometext", ugettext_noop("Welcome Message") )
  146. passwd = mk_config_property( "password", ugettext_noop("Server Password") )
  147. users = mk_config_property( "users", ugettext_noop("Max. Users"), get_coerce=int )
  148. bwidth = mk_config_property( "bandwidth", ugettext_noop("Bandwidth [Bps]"), get_coerce=int )
  149. sslcrt = mk_config_property( "certificate", ugettext_noop("SSL Certificate") )
  150. sslkey = mk_config_property( "key", ugettext_noop("SSL Key") )
  151. player = mk_config_property( "username", ugettext_noop("Player name regex") )
  152. channel = mk_config_property( "channelname", ugettext_noop("Channel name regex") )
  153. defchan = mk_config_property( "defaultchannel", ugettext_noop("Default channel"), get_coerce=int )
  154. timeout = mk_config_property( "timeout", ugettext_noop("Timeout"), get_coerce=int )
  155. obfsc = mk_config_bool_property( "obfuscate", ugettext_noop("IP Obfuscation") )
  156. certreq = mk_config_bool_property( "certrequired", ugettext_noop("Require Certificate") )
  157. textlen = mk_config_bool_property( "textmessagelength", ugettext_noop("Maximum length of text messages") )
  158. html = mk_config_bool_property( "allowhtml", ugettext_noop("Allow HTML to be used in messages") )
  159. bonjour = mk_config_bool_property( "bonjour", ugettext_noop("Publish this server via Bonjour") )
  160. autoboot= mk_config_bool_property( "boot", ugettext_noop("Boot Server when Murmur starts") )
  161. def getBooted( self ):
  162. if self.id is not None:
  163. if self.server.online:
  164. return self.ctl.isBooted( self.srvid )
  165. else:
  166. return None
  167. else:
  168. return False
  169. def setBooted( self, value ):
  170. if value != self.getBooted():
  171. if value:
  172. self.ctl.start( self.srvid );
  173. else:
  174. self.ctl.stop( self.srvid );
  175. booted = property( getBooted, setBooted, doc=ugettext_noop("Boot Server") )
  176. online = property( getBooted, setBooted, doc=ugettext_noop("Boot Server") )
  177. class Meta:
  178. unique_together = ( ( 'server', 'srvid' ), );
  179. verbose_name = _('Server instance');
  180. verbose_name_plural = _('Server instances');
  181. def __unicode__( self ):
  182. if not self.id:
  183. return u'Murmur "%s" (NOT YET CREATED)' % self.name;
  184. return u'Murmur "%s" (%d)' % ( self.name, self.srvid );
  185. def save( self, dontConfigureMurmur=False ):
  186. """ Save the options configured in this model instance not only to Django's database,
  187. but to Murmur as well.
  188. """
  189. if dontConfigureMurmur:
  190. return models.Model.save( self );
  191. if self.id is None:
  192. self.srvid = self.ctl.newServer();
  193. self.ctl.setConf( self.srvid, 'registername', self.name );
  194. if self.addr and self.addr != '0.0.0.0':
  195. self.ctl.setConf( self.srvid, 'host', socket.gethostbyname(self.addr) );
  196. else:
  197. self.ctl.setConf( self.srvid, 'host', '' );
  198. if self.port and self.port != settings.MUMBLE_DEFAULT_PORT + self.srvid - 1:
  199. self.ctl.setConf( self.srvid, 'port', str(self.port) );
  200. else:
  201. self.ctl.setConf( self.srvid, 'port', '' );
  202. if self.netloc:
  203. self.ctl.setConf( self.srvid, 'registerhostname', self.netloc );
  204. else:
  205. self.ctl.setConf( self.srvid, 'registerhostname', '' );
  206. return models.Model.save( self );
  207. def __init__( self, *args, **kwargs ):
  208. models.Model.__init__( self, *args, **kwargs );
  209. self._channels = None;
  210. self._rootchan = None;
  211. users_regged = property( lambda self: self.mumbleuser_set.count(), doc="Number of registered users." );
  212. users_online = property( lambda self: len(self.ctl.getPlayers(self.srvid)), doc="Number of online users." );
  213. channel_cnt = property( lambda self: len(self.ctl.getChannels(self.srvid)), doc="Number of channels." );
  214. is_public = property( lambda self: not self.passwd,
  215. doc="False if a password is needed to join this server." );
  216. is_server = True;
  217. is_channel = False;
  218. is_player = False;
  219. ctl = property( lambda self: self.server.ctl );
  220. def getConf( self, field ):
  221. return self.ctl.getConf( self.srvid, field )
  222. def setConf( self, field, value ):
  223. return self.ctl.setConf( self.srvid, field, value )
  224. def configureFromMurmur( self ):
  225. conf = self.ctl.getAllConf( self.srvid );
  226. if "registername" not in conf or not conf["registername"]:
  227. self.name = "noname";
  228. else:
  229. self.name = conf["registername"];
  230. if "registerhostname" in conf and conf["registerhostname"]:
  231. if ':' in conf["registerhostname"]:
  232. regname, regport = conf["registerhostname"].split(':')
  233. regport = int(regport)
  234. else:
  235. regname = conf["registerhostname"]
  236. regport = None
  237. else:
  238. regname = None
  239. regport = None
  240. if "host" in conf and conf["host"]:
  241. addr = conf["host"]
  242. else:
  243. addr = None
  244. if "port" in conf and conf["port"]:
  245. self.port = int(conf["port"])
  246. else:
  247. self.port = None
  248. if regname and addr:
  249. if regport == self.port:
  250. if socket.gethostbyname(regname) == socket.gethostbyname(addr):
  251. self.display = ''
  252. self.addr = regname
  253. else:
  254. self.display = regname
  255. self.addr = addr
  256. else:
  257. self.display = conf["registerhostname"]
  258. self.addr = addr
  259. elif regname and not addr:
  260. self.display = regname
  261. self.addr = ''
  262. elif addr and not regname:
  263. self.display = ''
  264. self.addr = addr
  265. else:
  266. self.display = ''
  267. self.addr = ''
  268. self.save( dontConfigureMurmur=True );
  269. def readUsersFromMurmur( self, verbose=0 ):
  270. if not self.booted:
  271. raise SystemError( "This murmur instance is not currently running, can't sync." );
  272. players = self.ctl.getRegisteredPlayers(self.srvid);
  273. known_ids = [rec["mumbleid"]
  274. for rec in MumbleUser.objects.filter( server=self ).values( "mumbleid" )
  275. ]
  276. for idx in players:
  277. playerdata = players[idx];
  278. if playerdata.userid == 0: # Skip SuperUsers
  279. continue;
  280. if verbose > 1:
  281. print "Checking Player with id %d." % playerdata.userid;
  282. if playerdata.userid not in known_ids:
  283. if verbose:
  284. print 'Found new Player "%s".' % playerdata.name;
  285. playerinstance = MumbleUser(
  286. mumbleid = playerdata.userid,
  287. name = playerdata.name,
  288. password = '',
  289. server = self,
  290. owner = None
  291. );
  292. else:
  293. if verbose > 1:
  294. print "Player '%s' is already known." % playerdata.name;
  295. playerinstance = MumbleUser.objects.get( server=self, mumbleid=playerdata.userid );
  296. playerinstance.name = playerdata.name;
  297. playerinstance.save( dontConfigureMurmur=True );
  298. def isUserAdmin( self, user ):
  299. """ Determine if the given user is an admin on this server. """
  300. if user.is_authenticated():
  301. if user.is_superuser:
  302. return True;
  303. try:
  304. return self.mumbleuser_set.get( owner=user ).getAdmin();
  305. except MumbleUser.DoesNotExist:
  306. return False;
  307. return False;
  308. # Deletion handler
  309. def deleteServer( self ):
  310. """ Delete this server instance from Murmur. """
  311. self.ctl.deleteServer(self.srvid)
  312. @staticmethod
  313. def pre_delete_listener( **kwargs ):
  314. kwargs['instance'].deleteServer();
  315. # Channel list
  316. def getChannels( self ):
  317. """ Query the channels from Murmur and create a tree structure.
  318. Again, this will only be done for the first call to this function. Subsequent
  319. calls will simply return the list created last time.
  320. """
  321. if self._channels is None:
  322. self._channels = {};
  323. chanlist = self.ctl.getChannels(self.srvid).values();
  324. links = {};
  325. # sometimes, ICE seems to return the Channel list in a weird order.
  326. # itercount prevents infinite loops.
  327. itercount = 0;
  328. maxiter = len(chanlist) * 3;
  329. while len(chanlist) and itercount < maxiter:
  330. itercount += 1;
  331. for theChan in chanlist:
  332. # Channels - Fields: 0 = ID, 1 = Name, 2 = Parent-ID, 3 = Links
  333. if( theChan.parent == -1 ):
  334. # No parent
  335. self._channels[theChan.id] = mmChannel( self, theChan );
  336. elif theChan.parent in self.channels:
  337. # parent already known
  338. self._channels[theChan.id] = mmChannel( self, theChan, self.channels[theChan.parent] );
  339. else:
  340. continue;
  341. chanlist.remove( theChan );
  342. self._channels[theChan.id].serverId = self.id;
  343. # process links - if the linked channels are known, link; else save their ids to link later
  344. for linked in theChan.links:
  345. if linked in self._channels:
  346. self._channels[theChan.id].linked.append( self._channels[linked] );
  347. else:
  348. if linked not in links:
  349. links[linked] = list();
  350. links[linked].append( self._channels[theChan.id] );
  351. # check if earlier round trips saved channel ids to be linked to the current channel
  352. if theChan.id in links:
  353. for targetChan in links[theChan.id]:
  354. targetChan.linked.append( self._channels[theChan.id] );
  355. self._channels[0].name = self.name;
  356. self.players = {};
  357. for thePlayer in self.ctl.getPlayers(self.srvid).values():
  358. # Players - Fields: 0 = UserID, 6 = ChannelID
  359. self.players[ thePlayer.session ] = mmPlayer( self, thePlayer, self._channels[ thePlayer.channel ] );
  360. self._channels[0].sort();
  361. return self._channels;
  362. channels = property( getChannels, doc="A convenience wrapper for getChannels()." );
  363. rootchan = property( lambda self: self.channels[0], doc="A convenience wrapper for getChannels()[0]." );
  364. def getNetloc( self ):
  365. """ Return the address from the Display field (if any), or the server address.
  366. Users from outside a NAT will need to use the Display address to connect
  367. to this server instance.
  368. """
  369. if self.display:
  370. if ":" in self.display:
  371. return self.display;
  372. else:
  373. daddr = self.display;
  374. else:
  375. daddr = self.addr;
  376. if self.port and self.port != settings.MUMBLE_DEFAULT_PORT:
  377. return "%s:%d" % (daddr, self.port);
  378. else:
  379. return daddr;
  380. netloc = property( getNetloc );
  381. def getURL( self, forUser = None ):
  382. """ Create an URL of the form mumble://username@host:port/ for this server. """
  383. if not self.netloc:
  384. return None
  385. from urlparse import urlunsplit
  386. versionstr = "version=%d.%d.%d" % tuple(self.version[:3]);
  387. if forUser is not None:
  388. netloc = "%s@%s" % ( forUser.name, self.netloc );
  389. return urlunsplit(( "mumble", netloc, "", versionstr, "" ))
  390. else:
  391. return urlunsplit(( "mumble", self.netloc, "", versionstr, "" ))
  392. connecturl = property( getURL );
  393. version = property( lambda self: self.ctl.getVersion(), doc="The version of Murmur." );
  394. def asDict( self ):
  395. return { 'name': self.name,
  396. 'id': self.id,
  397. 'root': self.rootchan.asDict()
  398. };
  399. def asXml( self ):
  400. from xml.etree.cElementTree import Element
  401. root = Element("root")
  402. self.rootchan.asXml(root)
  403. return root
  404. # "server" field protection
  405. def __setattr__( self, name, value ):
  406. if name == 'server':
  407. if self.id is not None and self.server != value:
  408. raise AttributeError( _( "This field must not be updated once the record has been saved." ) );
  409. models.Model.__setattr__( self, name, value );
  410. def kickUser( self, sessionid, reason="" ):
  411. return self.ctl.kickUser( self.srvid, sessionid, reason );
  412. def banUser( self, sessionid, reason="" ):
  413. return self.ctl.addBanForSession( self.srvid, sessionid, reason=reason );
  414. def mk_registration_property( field, doc="" ):
  415. """ Create a property for the given registration field. """
  416. def get_field( self ):
  417. if "comment" in self.registration:
  418. return self.registration["comment"];
  419. else:
  420. return None;
  421. return property( get_field, doc=doc )
  422. class MumbleUser( models.Model ):
  423. """ Represents a User account in Murmur.
  424. To change an account, simply set the according field in this model and call the save()
  425. method to update the account in Murmur and in Django's database. Note that, once saved
  426. for the first time, the server field must not be changed. Attempting to do this will
  427. result in an AttributeError. To move an account to a new server, recreate it on the
  428. new server and delete the old model.
  429. When you delete an instance of this model, the according user account will be deleted
  430. in Murmur as well, after revoking the user's admin privileges.
  431. """
  432. mumbleid = models.IntegerField( _('Mumble player_id'), editable = False, default = -1 );
  433. name = models.CharField( _('User name and Login'), max_length = 200 );
  434. password = models.CharField( _('Login password'), max_length = 200, blank=True );
  435. server = models.ForeignKey( Mumble, verbose_name=_('Server instance'), related_name="mumbleuser_set" );
  436. owner = models.ForeignKey( User, verbose_name=_('Account owner'), related_name="mumbleuser_set", null=True, blank=True );
  437. comment = mk_registration_property( "comment", doc=ugettext_noop("The user's comment.") );
  438. hash = mk_registration_property( "hash", doc=ugettext_noop("The user's hash.") );
  439. class Meta:
  440. unique_together = ( ( 'server', 'owner' ), ( 'server', 'mumbleid' ) );
  441. verbose_name = _( 'User account' );
  442. verbose_name_plural = _( 'User accounts' );
  443. is_server = False;
  444. is_channel = False;
  445. is_player = True;
  446. def __unicode__( self ):
  447. return _("Mumble user %(mu)s on %(srv)s owned by Django user %(du)s") % {
  448. 'mu': self.name,
  449. 'srv': self.server,
  450. 'du': self.owner
  451. };
  452. def save( self, dontConfigureMurmur=False ):
  453. """ Save the settings in this model to Murmur. """
  454. if dontConfigureMurmur:
  455. return models.Model.save( self );
  456. ctl = self.server.ctl;
  457. if self.owner:
  458. email = self.owner.email;
  459. else:
  460. email = settings.DEFAULT_FROM_EMAIL;
  461. if self.id is None:
  462. # This is a new user record, so Murmur doesn't know about it yet
  463. if len( ctl.getRegisteredPlayers( self.server.srvid, self.name ) ) > 0:
  464. raise ValueError( _( "Another player already registered that name." ) );
  465. if not self.password:
  466. raise ValueError( _( "Cannot register player without a password!" ) );
  467. self.mumbleid = ctl.registerPlayer( self.server.srvid, self.name, email, self.password );
  468. # Update user's registration
  469. elif self.password:
  470. ctl.setRegistration(
  471. self.server.srvid,
  472. self.mumbleid,
  473. self.name,
  474. email,
  475. self.password
  476. );
  477. # Don't save the users' passwords, we don't need them anyway
  478. self.password = '';
  479. return models.Model.save( self );
  480. def __init__( self, *args, **kwargs ):
  481. models.Model.__init__( self, *args, **kwargs );
  482. self._registration = None;
  483. # Admin handlers
  484. def getAdmin( self ):
  485. """ Get ACL of root Channel, get the admin group and see if this user is in it. """
  486. if self.mumbleid == -1:
  487. return False;
  488. else:
  489. return self.server.rootchan.acl.group_has_member( "admin", self.mumbleid );
  490. def setAdmin( self, value ):
  491. """ Set or revoke this user's membership in the admin group on the root channel. """
  492. if self.mumbleid == -1:
  493. return False;
  494. if value:
  495. self.server.rootchan.acl.group_add_member( "admin", self.mumbleid );
  496. else:
  497. self.server.rootchan.acl.group_remove_member( "admin", self.mumbleid );
  498. self.server.rootchan.acl.save();
  499. return value;
  500. aclAdmin = property( getAdmin, setAdmin, doc=ugettext_noop('Admin on root channel') );
  501. # Registration fetching
  502. def getRegistration( self ):
  503. """ Retrieve a user's registration from Murmur as a dict. """
  504. if not self._registration:
  505. self._registration = self.server.ctl.getRegistration( self.server.srvid, self.mumbleid );
  506. return self._registration;
  507. registration = property( getRegistration );
  508. # Texture handlers
  509. def getTexture( self ):
  510. """ Get the user texture as a PIL Image. """
  511. return self.server.ctl.getTexture(self.server.srvid, self.mumbleid);
  512. def setTexture( self, image ):
  513. """ Install the given image as the user's texture. """
  514. self.server.ctl.setTexture(self.server.srvid, self.mumbleid, image)
  515. texture = property( getTexture, setTexture,
  516. doc="Get the texture as a PIL Image or set the Image as the texture."
  517. );
  518. def hasTexture( self ):
  519. """ Check if this user has a texture set. """
  520. try:
  521. self.getTexture();
  522. except ValueError:
  523. return False;
  524. else:
  525. return True;
  526. def getTextureUrl( self ):
  527. """ Get a URL under which the texture can be retrieved. """
  528. from views import showTexture
  529. from django.core.urlresolvers import reverse
  530. return reverse( showTexture, kwargs={ 'server': self.server.id, 'userid': self.id } );
  531. textureUrl = property( getTextureUrl );
  532. # Deletion handler
  533. @staticmethod
  534. def pre_delete_listener( **kwargs ):
  535. kwargs['instance'].unregister();
  536. def unregister( self ):
  537. """ Delete this user account from Murmur. """
  538. if self.getAdmin():
  539. self.setAdmin( False );
  540. self.server.ctl.unregisterPlayer(self.server.srvid, self.mumbleid)
  541. # "server" field protection
  542. def __setattr__( self, name, value ):
  543. if name == 'server':
  544. if self.id is not None and self.server != value:
  545. raise AttributeError( _( "This field must not be updated once the record has been saved." ) );
  546. models.Model.__setattr__( self, name, value );
  547. signals.pre_delete.connect( Mumble.pre_delete_listener, sender=Mumble );
  548. signals.pre_delete.connect( MumbleUser.pre_delete_listener, sender=MumbleUser );