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.

710 lines
25 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009, withgod <withgod@sourceforge.net>
  5. * 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  6. *
  7. * Mumble-Django is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This package is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. """
  17. from time import time
  18. from functools import wraps
  19. from StringIO import StringIO
  20. from os.path import exists, join
  21. from os import unlink, name as os_name
  22. from PIL import Image
  23. from struct import pack, unpack
  24. from zlib import compress, decompress, error
  25. from mctl import MumbleCtlBase
  26. from utils import ObjectInfo
  27. import Ice, IcePy, tempfile
  28. def loadSlice( slicefile ):
  29. """ Load the slice file with the correct include dir set, if possible. """
  30. if hasattr( Ice, "getSliceDir" ):
  31. icepath = Ice.getSliceDir()
  32. else:
  33. icepath = None
  34. # Ice returns '' in getSliceDir() sometimes. (I kid you not.)
  35. if not icepath:
  36. from django.conf import settings
  37. icepath = settings.SLICEDIR
  38. if not exists( join( icepath, "Ice", "SliceChecksumDict.ice" ) ):
  39. icepath = None
  40. if not icepath:
  41. # last resort when getSliceDir fails AND settings are wrong, won't work for >=1.2.3
  42. Ice.loadSlice( slicefile )
  43. else:
  44. Ice.loadSlice( '', ['-I' + icepath, slicefile ] )
  45. def protectDjangoErrPage( func ):
  46. """ Catch and reraise Ice exceptions to prevent the Django page from failing.
  47. Since I need to "import Murmur", Django would try to read a murmur.py file
  48. which doesn't exist, and thereby produce an IndexError exception. This method
  49. erases the exception's traceback, preventing Django from trying to read any
  50. non-existant files and borking.
  51. """
  52. @wraps(func)
  53. def protection_wrapper( self, *args, **kwargs ):
  54. """ Call the original function and catch Ice exceptions. """
  55. try:
  56. return func( self, *args, **kwargs )
  57. except Ice.Exception, err:
  58. raise err
  59. protection_wrapper.innerfunc = func
  60. return protection_wrapper
  61. @protectDjangoErrPage
  62. def MumbleCtlIce( connstring, slicefile=None, icesecret=None ):
  63. """ Choose the correct Ice handler to use (1.1.8 or 1.2.x), and make sure the
  64. Murmur version matches the slice Version.
  65. Optional parameters are the path to the slice file and the Ice secret
  66. necessary to authenticate to Murmur.
  67. The path can be omitted only if running Murmur 1.2.3 or later, which
  68. exports a getSlice method to retrieve the Slice from.
  69. """
  70. prop = Ice.createProperties([])
  71. prop.setProperty("Ice.ImplicitContext", "Shared")
  72. idd = Ice.InitializationData()
  73. idd.properties = prop
  74. ice = Ice.initialize(idd)
  75. if icesecret:
  76. ice.getImplicitContext().put( "secret", icesecret.encode("utf-8") )
  77. prx = ice.stringToProxy( connstring.encode("utf-8") )
  78. try:
  79. prx.ice_ping()
  80. except Ice.Exception:
  81. raise EnvironmentError( "Murmur does not appear to be listening on this address (Ice ping failed)." )
  82. try:
  83. import Murmur
  84. except ImportError:
  85. # Try loading the Slice from Murmur directly via its getSlice method.
  86. # See scripts/testdynamic.py in Mumble's Git repository.
  87. try:
  88. slice = IcePy.Operation( 'getSlice',
  89. Ice.OperationMode.Idempotent, Ice.OperationMode.Idempotent,
  90. True, (), (), (), IcePy._t_string, ()
  91. ).invoke(prx, ((), None))
  92. except (TypeError, Ice.OperationNotExistException):
  93. if not slicefile:
  94. raise EnvironmentError(
  95. "You didn't configure a slice file. Please set the SLICE variable in settings.py." )
  96. if not exists( slicefile ):
  97. raise EnvironmentError(
  98. "The slice file does not exist: '%s' - please check the settings." % slicefile )
  99. if " " in slicefile:
  100. raise EnvironmentError(
  101. "You have a space char in your Slice path. This will confuse Ice, please check." )
  102. if not slicefile.endswith( ".ice" ):
  103. raise EnvironmentError( "The slice file name MUST end with '.ice'." )
  104. try:
  105. loadSlice( slicefile )
  106. except RuntimeError:
  107. raise RuntimeError( "Slice preprocessing failed. Please check your server's error log." )
  108. else:
  109. if os_name == "nt":
  110. # It weren't Windows if it didn't need to be treated differently. *sigh*
  111. temppath = join( tempfile.gettempdir(), "Murmur.ice" )
  112. slicetemp = open( temppath, "w+b" )
  113. try:
  114. slicetemp.write( slice )
  115. finally:
  116. slicetemp.close()
  117. try:
  118. loadSlice( temppath )
  119. except RuntimeError:
  120. raise RuntimeError( "Slice preprocessing failed. Please check your server's error log." )
  121. finally:
  122. unlink(temppath)
  123. else:
  124. slicetemp = tempfile.NamedTemporaryFile( suffix='.ice' )
  125. try:
  126. slicetemp.write( slice )
  127. slicetemp.flush()
  128. loadSlice( slicetemp.name )
  129. except RuntimeError:
  130. raise RuntimeError( "Slice preprocessing failed. Please check your server's error log." )
  131. finally:
  132. slicetemp.close()
  133. import Murmur
  134. meta = Murmur.MetaPrx.checkedCast(prx)
  135. murmurversion = meta.getVersion()[:3]
  136. if murmurversion == (1, 1, 8):
  137. return MumbleCtlIce_118( connstring, meta )
  138. elif murmurversion[:2] == (1, 2):
  139. if murmurversion[2] < 2:
  140. return MumbleCtlIce_120( connstring, meta )
  141. elif murmurversion[2] == 2:
  142. return MumbleCtlIce_122( connstring, meta )
  143. elif murmurversion[2] == 3:
  144. return MumbleCtlIce_123( connstring, meta )
  145. raise NotImplementedError( "No ctl object available for Murmur version %d.%d.%d" % tuple(murmurversion) )
  146. class MumbleCtlIce_118(MumbleCtlBase):
  147. method = "ICE"
  148. def __init__( self, connstring, meta ):
  149. self.proxy = connstring
  150. self.meta = meta
  151. @protectDjangoErrPage
  152. def _getIceServerObject(self, srvid):
  153. return self.meta.getServer(srvid)
  154. @protectDjangoErrPage
  155. def getBootedServers(self):
  156. ret = []
  157. for x in self.meta.getBootedServers():
  158. ret.append(x.id())
  159. return ret
  160. @protectDjangoErrPage
  161. def getVersion( self ):
  162. return self.meta.getVersion()
  163. @protectDjangoErrPage
  164. def getAllServers(self):
  165. ret = []
  166. for x in self.meta.getAllServers():
  167. ret.append(x.id())
  168. return ret
  169. @protectDjangoErrPage
  170. def getRegisteredPlayers(self, srvid, filter = ''):
  171. users = self._getIceServerObject(srvid).getRegisteredPlayers( filter.encode( "UTF-8" ) )
  172. ret = {}
  173. for user in users:
  174. ret[user.playerid] = ObjectInfo(
  175. userid = int( user.playerid ),
  176. name = unicode( user.name, "utf8" ),
  177. email = unicode( user.email, "utf8" ),
  178. pw = unicode( user.pw, "utf8" )
  179. )
  180. return ret
  181. @protectDjangoErrPage
  182. def getChannels(self, srvid):
  183. return self._getIceServerObject(srvid).getChannels()
  184. @protectDjangoErrPage
  185. def getPlayers(self, srvid):
  186. users = self._getIceServerObject(srvid).getPlayers()
  187. ret = {}
  188. for useridx in users:
  189. user = users[useridx]
  190. ret[ user.session ] = ObjectInfo(
  191. session = user.session,
  192. userid = user.playerid,
  193. mute = user.mute,
  194. deaf = user.deaf,
  195. suppress = user.suppressed,
  196. selfMute = user.selfMute,
  197. selfDeaf = user.selfDeaf,
  198. channel = user.channel,
  199. name = user.name,
  200. onlinesecs = user.onlinesecs,
  201. bytespersec = user.bytespersec
  202. )
  203. return ret
  204. @protectDjangoErrPage
  205. def getDefaultConf(self):
  206. return self.setUnicodeFlag(self.meta.getDefaultConf())
  207. @protectDjangoErrPage
  208. def getAllConf(self, srvid):
  209. conf = self.setUnicodeFlag(self._getIceServerObject(srvid).getAllConf())
  210. info = {}
  211. for key in conf:
  212. if key == "playername":
  213. info['username'] = conf[key]
  214. else:
  215. info[str(key)] = conf[key]
  216. return info
  217. @protectDjangoErrPage
  218. def newServer(self):
  219. return self.meta.newServer().id()
  220. @protectDjangoErrPage
  221. def isBooted( self, srvid ):
  222. return bool( self._getIceServerObject(srvid).isRunning() )
  223. @protectDjangoErrPage
  224. def start( self, srvid ):
  225. self._getIceServerObject(srvid).start()
  226. @protectDjangoErrPage
  227. def stop( self, srvid ):
  228. self._getIceServerObject(srvid).stop()
  229. @protectDjangoErrPage
  230. def deleteServer( self, srvid ):
  231. if self._getIceServerObject(srvid).isRunning():
  232. self._getIceServerObject(srvid).stop()
  233. self._getIceServerObject(srvid).delete()
  234. @protectDjangoErrPage
  235. def setSuperUserPassword(self, srvid, value):
  236. self._getIceServerObject(srvid).setSuperuserPassword( value.encode( "UTF-8" ) )
  237. @protectDjangoErrPage
  238. def getConf(self, srvid, key):
  239. if key == "username":
  240. key = "playername"
  241. return self._getIceServerObject(srvid).getConf( key )
  242. @protectDjangoErrPage
  243. def setConf(self, srvid, key, value):
  244. if key == "username":
  245. key = "playername"
  246. if value is None:
  247. value = ''
  248. self._getIceServerObject(srvid).setConf( key, value.encode( "UTF-8" ) )
  249. @protectDjangoErrPage
  250. def registerPlayer(self, srvid, name, email, password):
  251. mumbleid = self._getIceServerObject(srvid).registerPlayer( name.encode( "UTF-8" ) )
  252. self.setRegistration( srvid, mumbleid, name, email, password )
  253. return mumbleid
  254. @protectDjangoErrPage
  255. def unregisterPlayer(self, srvid, mumbleid):
  256. self._getIceServerObject(srvid).unregisterPlayer(mumbleid)
  257. @protectDjangoErrPage
  258. def getRegistration(self, srvid, mumbleid):
  259. user = self._getIceServerObject(srvid).getRegistration(mumbleid)
  260. return ObjectInfo(
  261. userid = mumbleid,
  262. name = user.name,
  263. email = user.email,
  264. pw = '',
  265. )
  266. @protectDjangoErrPage
  267. def setRegistration(self, srvid, mumbleid, name, email, password):
  268. import Murmur
  269. user = Murmur.RegisteredPlayer()
  270. user.playerid = mumbleid
  271. user.name = name.encode( "UTF-8" )
  272. user.email = email.encode( "UTF-8" )
  273. user.pw = password.encode( "UTF-8" )
  274. # update*r*egistration r is lowercase...
  275. return self._getIceServerObject(srvid).updateregistration(user)
  276. @protectDjangoErrPage
  277. def getACL(self, srvid, channelid):
  278. # need to convert acls to say "userid" instead of "playerid". meh.
  279. raw_acls, raw_groups, raw_inherit = self._getIceServerObject(srvid).getACL(channelid)
  280. acls = [ ObjectInfo(
  281. applyHere = rule.applyHere,
  282. applySubs = rule.applySubs,
  283. inherited = rule.inherited,
  284. userid = rule.playerid,
  285. group = rule.group,
  286. allow = rule.allow,
  287. deny = rule.deny,
  288. )
  289. for rule in raw_acls
  290. ]
  291. return acls, raw_groups, raw_inherit
  292. @protectDjangoErrPage
  293. def setACL(self, srvid, channelid, acls, groups, inherit):
  294. import Murmur
  295. ice_acls = []
  296. for rule in acls:
  297. ice_rule = Murmur.ACL()
  298. ice_rule.applyHere = rule.applyHere
  299. ice_rule.applySubs = rule.applySubs
  300. ice_rule.inherited = rule.inherited
  301. ice_rule.playerid = rule.userid
  302. ice_rule.group = rule.group
  303. ice_rule.allow = rule.allow
  304. ice_rule.deny = rule.deny
  305. ice_acls.append(ice_rule)
  306. return self._getIceServerObject(srvid).setACL( channelid, ice_acls, groups, inherit )
  307. @protectDjangoErrPage
  308. def getTexture(self, srvid, mumbleid):
  309. texture = self._getIceServerObject(srvid).getTexture(mumbleid)
  310. if len(texture) == 0:
  311. raise ValueError( "No Texture has been set." )
  312. # this returns a list of bytes.
  313. try:
  314. decompressed = decompress( texture )
  315. except error, err:
  316. raise ValueError( err )
  317. # iterate over 4 byte chunks of the string
  318. imgdata = ""
  319. for idx in range( 0, len(decompressed), 4 ):
  320. # read 4 bytes = BGRA and convert to RGBA
  321. # manual wrote getTexture returns "Textures are stored as zlib compress()ed 600x60 32-bit RGBA data."
  322. # http://mumble.sourceforge.net/slice/Murmur/Server.html#getTexture
  323. # but return values BGRA X(
  324. bgra = unpack( "4B", decompressed[idx:idx+4] )
  325. imgdata += pack( "4B", bgra[2], bgra[1], bgra[0], bgra[3] )
  326. # return an 600x60 RGBA image object created from the data
  327. return Image.fromstring( "RGBA", ( 600, 60 ), imgdata )
  328. @protectDjangoErrPage
  329. def setTexture(self, srvid, mumbleid, infile):
  330. # open image, convert to RGBA, and resize to 600x60
  331. img = infile.convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) )
  332. # iterate over the list and pack everything into a string
  333. bgrastring = ""
  334. for ent in list( img.getdata() ):
  335. # ent is in RGBA format, but Murmur wants BGRA (ARGB inverse), so stuff needs
  336. # to be reordered when passed to pack()
  337. bgrastring += pack( "4B", ent[2], ent[1], ent[0], ent[3] )
  338. # compress using zlib
  339. compressed = compress( bgrastring )
  340. # pack the original length in 4 byte big endian, and concat the compressed
  341. # data to it to emulate qCompress().
  342. texture = pack( ">L", len(bgrastring) ) + compressed
  343. # finally call murmur and set the texture
  344. self._getIceServerObject(srvid).setTexture(mumbleid, texture)
  345. @protectDjangoErrPage
  346. def verifyPassword(self, srvid, username, password):
  347. return self._getIceServerObject(srvid).verifyPassword(username, password)
  348. @staticmethod
  349. def setUnicodeFlag(data):
  350. ret = ''
  351. if isinstance(data, tuple) or isinstance(data, list) or isinstance(data, dict):
  352. ret = {}
  353. for key in data.keys():
  354. ret[MumbleCtlIce_118.setUnicodeFlag(key)] = MumbleCtlIce_118.setUnicodeFlag(data[key])
  355. else:
  356. ret = unicode(data, 'utf-8')
  357. return ret
  358. def getUptime(self, srvid):
  359. return None
  360. @protectDjangoErrPage
  361. def getBans( self, srvid ):
  362. return self._getIceServerObject(srvid).getBans()
  363. @protectDjangoErrPage
  364. def getLog( self, srvid, first=0, last=100 ):
  365. return self._getIceServerObject(srvid).getLog( first, last )
  366. @protectDjangoErrPage
  367. def addChannel( self, srvid, name, parentid ):
  368. return self._getIceServerObject(srvid).addChannel( name.encode( "UTF-8" ), parentid )
  369. @protectDjangoErrPage
  370. def removeChannel( self, srvid, channelid ):
  371. return self._getIceServerObject(srvid).removeChannel( channelid )
  372. @protectDjangoErrPage
  373. def renameChannel( self, srvid, channelid, name, description ):
  374. srv = self._getIceServerObject(srvid)
  375. state = srv.getChannelState(channelid)
  376. state.name = name.encode("UTF-8")
  377. srv.setChannelState(state)
  378. @protectDjangoErrPage
  379. def moveChannel(self, srvid, channelid, parentid):
  380. srv = self._getIceServerObject(srvid)
  381. state = srv.getChannelState(channelid)
  382. state.parent = parentid
  383. srv.setChannelState(state)
  384. @protectDjangoErrPage
  385. def moveUser(self, srvid, sessionid, channelid):
  386. srv = self._getIceServerObject(srvid)
  387. state = srv.getState(sessionid)
  388. state.channel = channelid
  389. srv.setState(state)
  390. @protectDjangoErrPage
  391. def muteUser(self, srvid, sessionid, mute=True):
  392. srv = self._getIceServerObject(srvid)
  393. state = srv.getState(sessionid)
  394. state.mute = mute
  395. srv.setState(state)
  396. @protectDjangoErrPage
  397. def deafenUser(self, srvid, sessionid, deaf=True):
  398. srv = self._getIceServerObject(srvid)
  399. state = srv.getState(sessionid)
  400. state.deaf = deaf
  401. srv.setState(state)
  402. @protectDjangoErrPage
  403. def kickUser(self, srvid, userid, reason=""):
  404. return self._getIceServerObject(srvid).kickPlayer( userid, reason.encode("UTF-8") )
  405. @protectDjangoErrPage
  406. def sendMessage(self, srvid, sessionid, message):
  407. return self._getIceServerObject(srvid).sendMessage( sessionid, message.encode( "UTF-8" ) )
  408. @protectDjangoErrPage
  409. def sendMessageChannel(self, srvid, channelid, tree, message):
  410. return self._getIceServerObject(srvid).sendMessageChannel( channelid, tree, message.encode( "UTF-8" ) )
  411. class MumbleCtlIce_120(MumbleCtlIce_118):
  412. @protectDjangoErrPage
  413. def getRegisteredPlayers(self, srvid, filter = ''):
  414. users = self._getIceServerObject( srvid ).getRegisteredUsers( filter.encode( "UTF-8" ) )
  415. ret = {}
  416. for id in users:
  417. ret[id] = ObjectInfo(
  418. userid = id,
  419. name = unicode( users[id], "utf8" ),
  420. email = '',
  421. pw = ''
  422. )
  423. return ret
  424. @protectDjangoErrPage
  425. def getPlayers(self, srvid):
  426. userdata = self._getIceServerObject(srvid).getUsers()
  427. for key in userdata:
  428. if isinstance( userdata[key], str ):
  429. userdata[key] = userdata[key].decode( "UTF-8" )
  430. return userdata
  431. @protectDjangoErrPage
  432. def getState(self, srvid, sessionid):
  433. userdata = self._getIceServerObject(srvid).getState(sessionid)
  434. for key in userdata.__dict__:
  435. attr = getattr( userdata, key )
  436. if isinstance( attr, str ):
  437. setattr( userdata, key, attr.decode( "UTF-8" ) )
  438. return userdata
  439. @protectDjangoErrPage
  440. def registerPlayer(self, srvid, name, email, password):
  441. # To get the real values of these ENUM entries, try
  442. # Murmur.UserInfo.UserX.value
  443. import Murmur
  444. user = {
  445. Murmur.UserInfo.UserName: name.encode( "UTF-8" ),
  446. Murmur.UserInfo.UserEmail: email.encode( "UTF-8" ),
  447. Murmur.UserInfo.UserPassword: password.encode( "UTF-8" ),
  448. }
  449. return self._getIceServerObject(srvid).registerUser( user )
  450. @protectDjangoErrPage
  451. def unregisterPlayer(self, srvid, mumbleid):
  452. self._getIceServerObject(srvid).unregisterUser(mumbleid)
  453. @protectDjangoErrPage
  454. def getRegistration(self, srvid, mumbleid):
  455. reg = self._getIceServerObject( srvid ).getRegistration( mumbleid )
  456. user = ObjectInfo( userid=mumbleid, name="", email="", comment="", hash="", pw="" )
  457. import Murmur
  458. if Murmur.UserInfo.UserName in reg: user.name = reg[Murmur.UserInfo.UserName]
  459. if Murmur.UserInfo.UserEmail in reg: user.email = reg[Murmur.UserInfo.UserEmail]
  460. if Murmur.UserInfo.UserComment in reg: user.comment = reg[Murmur.UserInfo.UserComment]
  461. if Murmur.UserInfo.UserHash in reg: user.hash = reg[Murmur.UserInfo.UserHash]
  462. return user
  463. @protectDjangoErrPage
  464. def setRegistration(self, srvid, mumbleid, name, email, password):
  465. import Murmur
  466. user = {
  467. Murmur.UserInfo.UserName: name.encode( "UTF-8" ),
  468. Murmur.UserInfo.UserEmail: email.encode( "UTF-8" ),
  469. Murmur.UserInfo.UserPassword: password.encode( "UTF-8" ),
  470. }
  471. return self._getIceServerObject( srvid ).updateRegistration( mumbleid, user )
  472. @protectDjangoErrPage
  473. def getAllConf(self, srvid):
  474. conf = self.setUnicodeFlag(self._getIceServerObject(srvid).getAllConf())
  475. info = {}
  476. for key in conf:
  477. if key == "playername" and conf[key]:
  478. # Buggy database transition from 1.1.8 -> 1.2.0
  479. # Store username as "username" field and set playername field to empty
  480. info['username'] = conf[key]
  481. self.setConf( srvid, "playername", "" )
  482. self.setConf( srvid, "username", conf[key] )
  483. else:
  484. info[str(key)] = conf[key]
  485. return info
  486. @protectDjangoErrPage
  487. def getConf(self, srvid, key):
  488. return self._getIceServerObject(srvid).getConf( key )
  489. @protectDjangoErrPage
  490. def setConf(self, srvid, key, value):
  491. if value is None:
  492. value = ''
  493. self._getIceServerObject(srvid).setConf( key, value.encode( "UTF-8" ) )
  494. @protectDjangoErrPage
  495. def getACL(self, srvid, channelid):
  496. return self._getIceServerObject(srvid).getACL(channelid)
  497. @protectDjangoErrPage
  498. def setACL(self, srvid, channelid, acls, groups, inherit):
  499. return self._getIceServerObject(srvid).setACL( channelid, acls, groups, inherit )
  500. @protectDjangoErrPage
  501. def getBans(self, srvid):
  502. return self._getIceServerObject(srvid).getBans()
  503. @protectDjangoErrPage
  504. def setBans(self, srvid, bans):
  505. return self._getIceServerObject(srvid).setBans(bans)
  506. @protectDjangoErrPage
  507. def addBanForSession(self, srvid, sessionid, **kwargs):
  508. session = self.getState(srvid, sessionid)
  509. if "bits" not in kwargs:
  510. kwargs["bits"] = 128
  511. if "start" not in kwargs:
  512. kwargs["start"] = int(time())
  513. if "duration" not in kwargs:
  514. kwargs["duration"] = 3600
  515. return self.addBan(srvid, address=session.address, **kwargs)
  516. @protectDjangoErrPage
  517. def addBan(self, srvid, **kwargs):
  518. for key in kwargs:
  519. if isinstance( kwargs[key], unicode ):
  520. kwargs[key] = kwargs[key].encode("UTF-8")
  521. from Murmur import Ban
  522. srvbans = self.getBans(srvid)
  523. srvbans.append( Ban( **kwargs ) )
  524. return self.setBans(srvid, srvbans)
  525. @protectDjangoErrPage
  526. def removeBan(self, srvid, **kwargs):
  527. return self.setBans(srvid, [
  528. # keep all bans which don't match exactly the one we're looking for
  529. ban for ban in self.getBans(srvid)
  530. # if one of those attr checks fails (-> False), min() is False -> keep the thing
  531. if not min([ getattr(ban, kw) == kwargs[kw] for kw in kwargs ])
  532. ])
  533. @protectDjangoErrPage
  534. def kickUser(self, srvid, userid, reason=""):
  535. return self._getIceServerObject(srvid).kickUser( userid, reason.encode("UTF-8") )
  536. @protectDjangoErrPage
  537. def renameChannel( self, srvid, channelid, name, description ):
  538. srv = self._getIceServerObject(srvid)
  539. state = srv.getChannelState(channelid)
  540. state.name = name.encode("UTF-8")
  541. state.description = description.encode("UTF-8")
  542. srv.setChannelState(state)
  543. @protectDjangoErrPage
  544. def getUptime(self, srvid):
  545. return None
  546. class MumbleCtlIce_122(MumbleCtlIce_120):
  547. @protectDjangoErrPage
  548. def getTexture(self, srvid, mumbleid):
  549. raise ValueError( "This method is buggy in 1.2.2, sorry dude." )
  550. @protectDjangoErrPage
  551. def setTexture(self, srvid, mumbleid, infile):
  552. buf = StringIO()
  553. infile.save( buf, "PNG" )
  554. buf.seek(0)
  555. self._getIceServerObject(srvid).setTexture(mumbleid, buf.read())
  556. @protectDjangoErrPage
  557. def getUptime(self, srvid):
  558. return self._getIceServerObject(srvid).getUptime()
  559. class MumbleCtlIce_123(MumbleCtlIce_120):
  560. @protectDjangoErrPage
  561. def getRawTexture(self, srvid, mumbleid):
  562. return self._getIceServerObject(srvid).getTexture(mumbleid)
  563. @protectDjangoErrPage
  564. def getTexture(self, srvid, mumbleid):
  565. texture = self.getRawTexture(srvid, mumbleid)
  566. if len(texture) == 0:
  567. raise ValueError( "No Texture has been set." )
  568. from StringIO import StringIO
  569. try:
  570. return Image.open( StringIO( texture ) )
  571. except IOError, err:
  572. raise ValueError( err )
  573. @protectDjangoErrPage
  574. def setTexture(self, srvid, mumbleid, infile):
  575. buf = StringIO()
  576. infile.save( buf, "PNG" )
  577. buf.seek(0)
  578. self._getIceServerObject(srvid).setTexture(mumbleid, buf.read())
  579. @protectDjangoErrPage
  580. def getUptime(self, srvid):
  581. return self._getIceServerObject(srvid).getUptime()