-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (56 loc) · 2.27 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import socket
import Ice, sys
import Murmur
from pymongo import MongoClient
cache = {}
class ServerCallbackI(Murmur.ServerCallback):
def __init__(self, server, adapter, database):
self.adapter = adapter
self.server = server
self.database = database
def setUserLinkedState(self, name, linked):
self.database.players.find_one_and_update({"name": name}, {"$set": {"linked": linked}})
def userStateChanged(self, p, current=None):
print("State of " + p.name + " changed")
linked = p.identity != ""
if p.session in cache:
if cache[p.session] == linked:
return
else:
cache[p.session] = linked
self.setUserLinkedState(p.name, linked)
if __name__ == "__main__":
print("Creating Mongo connection...")
mongo = MongoClient(host=os.getenv("MONGO_URI"))
print("Initialization of Ice...")
prop = Ice.createProperties(sys.argv)
prop.setProperty("Ice.ImplicitContext", "Shared")
idd = Ice.InitializationData()
idd.properties = prop
ice = Ice.initialize(idd)
if os.getenv("ICE_SECRET") is not None:
ice.getImplicitContext().put("secret", os.getenv("ICE_SECRET"))
print("Creation of TCP connections via Ice...")
iceHost = os.getenv("ICE_HOST")
if os.getenv("ICE_DOCKER") is not None:
iceHost = socket.gethostbyname(iceHost)
icePort = os.getenv("ICE_PORT")
iceCallbackHost = os.getenv("ICE_CALLBACK_HOST")
meta = Murmur.MetaPrx.checkedCast(ice.stringToProxy("Meta:tcp -h %s -p %s" % (iceHost, icePort)))
adapter = ice.createObjectAdapterWithEndpoints("Callback.Client", "tcp -h %s" % iceCallbackHost)
adapter.activate()
print("Finding started Mumble servers and adding callbacks to them...")
for server in meta.getBootedServers():
print("- Server discovered:")
print(server)
serverR = Murmur.ServerCallbackPrx.uncheckedCast(
adapter.addWithUUID(ServerCallbackI(server, adapter, mongo.get_database("tigrouland"))))
server.addCallback(serverR)
print("MumbleManager started successfully.")
try:
ice.waitForShutdown()
except KeyboardInterrupt:
print("Aborting...")
ice.shutdown()
print("Ice connection successfully terminated.")