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.

179 lines
4.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # mumble-django contributed by withgod@sourceforge.net
  3. from PIL import Image
  4. from struct import pack, unpack
  5. from zlib import compress, decompress
  6. from mctl import MumbleCtlBase
  7. import Ice
  8. class MumbleCtlIce(MumbleCtlBase):
  9. proxy = 'Meta:tcp -h 127.0.0.1 -p 6502'
  10. slice = '/usr/share/slice/Murmur.ice'
  11. meta = None
  12. def __init__(self):
  13. self.meta = self._getIceMeta()
  14. def _getIceMeta(self):
  15. Ice.loadSlice(self.slice)
  16. ice = Ice.initialize()
  17. import Murmur
  18. prx = ice.stringToProxy(self.proxy)
  19. return Murmur.MetaPrx.checkedCast(prx)
  20. def _getIceServerObject(self, srvid):
  21. return self.meta.getServer(srvid);
  22. def getBootedServers(self):
  23. ret = []
  24. for x in self.meta.getBootedServers():
  25. ret.append(x.id())
  26. return ret
  27. def getAllServers(self):
  28. ret = []
  29. for x in self.meta.getAllServers():
  30. ret.append(x.id())
  31. return ret
  32. def getRegisteredPlayers(self, srvid):
  33. users = self._getIceServerObject(srvid).getRegisteredPlayers('')
  34. ret = []
  35. for user in users:
  36. ret.append([user.playerid, unicode(user.name), unicode(user.email), unicode(user.pw)])
  37. return ret
  38. def getChannels(self, srvid):
  39. chans = self._getIceServerObject(srvid).getChannels()
  40. ret = []
  41. for x in chans:
  42. chan = chans[x]
  43. ret.append([chan.id, unicode(chan.name), chan.parent, chan.links])
  44. return ret
  45. def getPlayers(self, srvid):
  46. users = self._getIceServerObject(srvid).getPlayers()
  47. ret = []
  48. for x in users:
  49. user = users[x]
  50. ret.append([user.session, user.mute, user.deaf, user.suppressed, user.selfMute, user.selfDeaf, user.channel, user.playerid, unicode(user.name), user.onlinesecs, user.bytespersec])
  51. return ret
  52. def getACL(self, srvid, identifier):
  53. import Murmur
  54. acls = self._getIceServerObject(srvid).getACL(identifier)
  55. ret = []
  56. for x in acls:
  57. if isinstance(x, list):
  58. tmp = []
  59. for y in x:
  60. if y.__class__ is Murmur.ACL:
  61. tmp.append([y.applyHere, y.applySubs, y.inherited, y.playerid, unicode(y.group), y.allow, y.deny])
  62. elif y.__class__ is Murmur.Group:
  63. tmp.append([unicode(y.name), y.inherited, y.inherit, y.inheritable, y.add, y.remove, y.members])
  64. ret.append(tmp)
  65. else:
  66. ret.append(x)
  67. return ret
  68. def getDefaultConf(self):
  69. return MumbleCtlIce.setUnicodeFlag(self.meta.getDefaultConf())
  70. def getAllConf(self, srvid):
  71. return MumbleCtlIce.setUnicodeFlag(self._getIceServerObject(srvid).getAllConf())
  72. def newServer(self):
  73. return self.meta.newServer().id()
  74. def deleteServer( self, srvid ):
  75. if self._getIceServerObject(srvid).isRunning():
  76. self._getIceServerObject(srvid).stop()
  77. self._getIceServerObject(srvid).delete()
  78. def setSuperUserPassword(self, srvid, value):
  79. self.meta.setSuperUserPassword(srvid, value)
  80. def setConf(self, srvid, key, value):
  81. #print "%s server %s/%s" % (srvid, key, value)
  82. self._getIceServerObject(srvid).setConf(key, value)
  83. def registerPlayer(self, srvid, name):
  84. return self._getIceServerObject(srvid).registerPlayer(name)
  85. def unregisterPlayer(self, srvid, mumbleid):
  86. self._getIceServerObject(srvid).unregisterPlayer(mumbleid)
  87. def setRegistration(self, srvid, mumbleid, name, email, password):
  88. user = self._getIceServerObject(srvid).getRegistration(mumbleid)
  89. user.name = name
  90. user.email = email
  91. user.pw = password
  92. #print user
  93. # update*r*egistration r is lowercase...
  94. return self._getIceServerObject(srvid).updateregistration(user)
  95. def setACL(self, srvid, acl):
  96. '''
  97. print "xxxx"
  98. print srvid
  99. print acl
  100. print "--"
  101. print acl.pack()
  102. print "xxxx"
  103. '''
  104. import Murmur
  105. tmp = acl.pack()
  106. id = tmp[0]
  107. _acls = tmp[1]
  108. acls = []
  109. _groups = tmp[2]
  110. groups = []
  111. inherit = tmp[3]
  112. for x in _acls:
  113. acl = Murmur.ACL()
  114. acl.applyHere = x[0]
  115. acl.applySubs = x[1]
  116. acl.inherited = x[2]
  117. acl.playerid = x[3]
  118. acl.group = x[4]
  119. acl.allow = x[5]
  120. acl.deny = x[6]
  121. acls.append(acl)
  122. for x in _groups:
  123. group = Murmur.Group()
  124. group.name = x[0]
  125. group.inherited = x[1]
  126. group.inherit = x[2]
  127. group.inheritable = x[3]
  128. group.add = x[4]
  129. group.remove = x[5]
  130. group.members = x[6]
  131. groups.append(group)
  132. self._getIceServerObject(srvid).setACL(id, acls, groups, inherit)
  133. def getTexture(self, srvid, mumbleid):
  134. print self._getIceServerObject(srvid).getTexture(mumbleid)
  135. #return Image.fromstring( "RGBA", ( 600, 60 ), self._getIceServerObject(srvid).getTexture(mumbleid));
  136. @staticmethod
  137. def setUnicodeFlag(data):
  138. ret = {}
  139. for key in data.keys():
  140. ret[unicode(key)] = unicode(data[key])
  141. return ret