Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8
  3.  
  4. ''' CALLBACK TESTING'''
  5. import Ice
  6. import sys
  7.  
  8. # id of server, starts at 1 for some reason
  9. serverid = 1
  10. iceslice = '/home/dev/murmur/ice/Murmur.ice'
  11. port = 6502
  12. secret = ''
  13. # load library (?) from Murmur.ice
  14. Ice.loadSlice( "", ["-I" + Ice.getSliceDir(), iceslice])
  15.  
  16. import Murmur
  17.  
  18. class MetaCallbackI(Murmur.MetaCallback):
  19. def started(self, s, current=None):
  20. print("started")
  21. serverR=Murmur.ServerCallbackPrx.uncheckedCast(adapter.addWithUUID(ServerCallbackI(server, current.adapter)))
  22. s.addCallback(serverR)
  23.  
  24. def stopped(self, s, current=None):
  25. print("stopped")
  26.  
  27. class ServerCallbackI(Murmur.ServerCallback):
  28. def __init__(self, server, adapter):
  29. self.server = server
  30. self.contextR=Murmur.ServerContextCallbackPrx.uncheckedCast(adapter.addWithUUID(ServerContextCallbackI(server)))
  31.  
  32. def userConnected(self, p, current=None):
  33. print("connected")
  34. print(p)
  35. self.server.addContextCallback(p.session, "flubber", "Power up the T", self.contextR, Murmur.ContextChannel | Murmur.ContextUser)
  36. if (self.server.hasPermission(p.session, 0, Murmur.PermissionWrite)):
  37. print("Is a global admin")
  38. certlist=self.server.getCertificateList(p.session)
  39.  
  40. def userDisconnected(self, p, current=None):
  41. print("disconnected")
  42. print(p)
  43.  
  44. def userStateChanged(self, p, current=None):
  45. print("stateChanged")
  46. print(self.server)
  47. print(p)
  48.  
  49. def userTextMessage(self, p, msg, current=None):
  50. print("userTextMessage")
  51. print(self.server)
  52. print(p)
  53. print(msg)
  54.  
  55.  
  56.  
  57. def channelCreated(self, c, current=None):
  58. print("created")
  59. print(c)
  60.  
  61. def channelRemoved(self, c, current=None):
  62. print("removed")
  63. print(c)
  64.  
  65. def channelStateChanged(self, c, current=None):
  66. print("stateChanged")
  67. print(c)
  68.  
  69. class ServerContextCallbackI(Murmur.ServerContextCallback):
  70. def __init__(self, server):
  71. self.server = server
  72.  
  73. def contextAction(self, action, p, session, chanid, current=None):
  74. print("aaand ACTION")
  75. print(action)
  76. print(p)
  77. print(session)
  78. print(chanid)
  79. if (session != 0):
  80. server.sendMessage(session, "Bouncy")
  81. elif (chanid >= 0):
  82. server.sendMessageChannel(chanid, 0, "Channel Bouncy")
  83.  
  84. if __name__ == "__main__":
  85. global contextR
  86.  
  87. prop = Ice.createProperties(sys.argv)
  88. prop.setProperty("Ice.ImplicitContext", "Shared")
  89.  
  90. idd = Ice.InitializationData()
  91. idd.properties = prop
  92.  
  93. ice = Ice.initialize(idd)
  94.  
  95. print("Creating callbacks...")
  96.  
  97. # If icesecret is set, we need to set it here as well.
  98. # ice.getImplicitContext().put("secret", "fourtytwo")
  99.  
  100. proxy = ice.stringToProxy('Meta -e 1.0:tcp -p ' + str(port))
  101. meta = Murmur.MetaPrx.checkedCast(proxy)
  102. adapter = ice.createObjectAdapterWithEndpoints("Callback.Client", "tcp -h 127.0.0.1")
  103.  
  104. metaR=Murmur.MetaCallbackPrx.uncheckedCast(adapter.addWithUUID(MetaCallbackI()))
  105. adapter.activate()
  106.  
  107. meta.addCallback(metaR)
  108.  
  109. for server in meta.getBootedServers():
  110. serverR=Murmur.ServerCallbackPrx.uncheckedCast(adapter.addWithUUID(ServerCallbackI(server, adapter)))
  111. server.addCallback(serverR)
  112.  
  113. print("Done")
  114. print('Script running (press CTRL-C to abort)')
  115. try:
  116. ice.waitForShutdown()
  117. except KeyboardInterrupt:
  118. print('CTRL-C caught, aborting')
  119.  
  120. meta.removeCallback(metaR)
  121. ice.shutdown()
  122. print("Goodbye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement