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.

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