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.

130 lines
3.7 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright (C) 2009, 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 os
  16. from mumble import models
  17. from mumble.mctl import *
  18. def find_in_dicts( keys, conf, default, valueIfNotFound=None ):
  19. if not isinstance( keys, tuple ):
  20. keys = ( keys, );
  21. for keyword in keys:
  22. if keyword in conf:
  23. return conf[keyword];
  24. for keyword in keys:
  25. keyword = keyword.lower();
  26. if keyword in default:
  27. return default[keyword];
  28. return valueIfNotFound;
  29. def find_existing_instances( **kwargs ):
  30. if "verbosity" in kwargs:
  31. v = kwargs['verbosity'];
  32. else:
  33. v = 1;
  34. if v > 1:
  35. print "Starting Mumble servers and players detection now.";
  36. triedEnviron = False;
  37. online = False;
  38. while not online:
  39. if not triedEnviron and 'MURMUR_CONNSTR' in os.environ:
  40. dbusName = os.environ['MURMUR_CONNSTR'];
  41. triedEnviron = True;
  42. if v > 1:
  43. print "Trying environment setting", dbusName;
  44. else:
  45. print "--- Murmur connection info ---"
  46. print " 1) DBus -- net.sourceforge.mumble.murmur"
  47. print " 2) ICE -- Meta:tcp -h 127.0.0.1 -p 6502"
  48. print "Enter 1 or 2 for the defaults above, nothing to skip Server detection,"
  49. print "and if the defaults do not fit your needs, enter the correct string."
  50. print "Whether to use DBus or ICE will be detected automatically from the"
  51. print "string's format."
  52. print
  53. dbusName = raw_input( "Service string: " ).strip();
  54. if not dbusName:
  55. if v:
  56. print 'Be sure to run "python manage.py syncdb" with Murmur running before trying to use this app! Otherwise, existing Murmur servers won\'t be configurable!';
  57. return False;
  58. elif dbusName == "1":
  59. dbusName = "net.sourceforge.mumble.murmur";
  60. elif dbusName == "2":
  61. dbusName = "Meta:tcp -h 127.0.0.1 -p 6502";
  62. try:
  63. ctl = MumbleCtlBase.newInstance( dbusName );
  64. except Exception, instance:
  65. if v:
  66. print "Unable to connect using name %s. The error was:" % dbusName;
  67. print instance;
  68. print
  69. else:
  70. online = True;
  71. if v > 1:
  72. print "Successfully connected to Murmur via connection string %s, using %s." % ( dbusName, ctl.method );
  73. servIDs = ctl.getAllServers();
  74. for id in servIDs:
  75. if v > 1:
  76. print "Checking Murmur instance with id %d." % id;
  77. # first check that the server has not yet been inserted into the DB
  78. try:
  79. instance = models.Mumble.objects.get( dbus=dbusName, srvid=id );
  80. except models.Mumble.DoesNotExist:
  81. values = {
  82. "srvid": id,
  83. "dbus": dbusName,
  84. }
  85. if v > 1:
  86. print "Found new Murmur instance %d on bus '%s'... " % ( id, dbusName ),
  87. # now create a model for the record set.
  88. instance = models.Mumble( **values );
  89. else:
  90. if v > 1:
  91. print "Syncing Murmur instance... ",
  92. instance.configureFromMurmur();
  93. if v > 1:
  94. print instance.name;
  95. instance.save( dontConfigureMurmur=True );
  96. # Now search for players on this server that have not yet been registered
  97. if instance.booted:
  98. if v > 1:
  99. print "Looking for registered Players on Server id %d." % id;
  100. instance.readUsersFromMurmur( verbose=v );
  101. elif v > 1:
  102. print "This server is not running, can't sync players.";
  103. if v > 1:
  104. print "Successfully finished Servers and Players detection.";
  105. return True;