Skip to content

Commit

Permalink
Added logic for testing if object is destroyed when polling mumble se…
Browse files Browse the repository at this point in the history
…rver.
  • Loading branch information
pallarim committed Dec 8, 2010
1 parent 8d6192f commit 16318d3
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions bin/ScriptEngines/PythonScript/mumble/voicechannel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import urllib
import rxactor

import System
'''
This script ensures that there is a mumble channel existing for the EC_VoiceChannel component.
Expand All @@ -13,30 +13,43 @@
CREATE_BASE_URL = "http://"+SERVER_ADDRESS+"/"+SECRET+"/CREATE_CHANNEL/" #todo get from ini
REMOVE_BASE_URL = "http://"+SERVER_ADDRESS+"/"+SECRET+"/REMOVE_CHANNEL/" #todo get from ini

POLL_TIMER_MS = 500

class ChannelChecker(rxactor.Actor):
@staticmethod
def GetScriptClassName():
return "voicechannel.ChannelChecker"

def EventCreated(self):
self._cleanup_url = None
self.SetTimer(0.5, True) # We poll EC_VoiceChannel for channelid attribute
self.SetTimer(0.001 * POLL_TIMER_MS, True) # We poll EC_VoiceChannel for channelid attribute
self.create_channel()
self._destroyed = False
# @todo replace polling with proper event handlers
#rex_objects = self.MyWorld.CS.World.EventManager.OnClientConnect += self.clientConnectedHandle

def EventDestroyed(self):
self._destroyed = True
self.SetTimer(1, False)
self.cleanup()

def create_channel(self):
ec = self.rexGetECAttributes("EC_VoiceChannel")
if ec is not None:
cleanup_url = REMOVE_BASE_URL + str( ec["channelid"] )
if self._cleanup_url != cleanup_url:
url = CREATE_BASE_URL + str( ec["channelid"] )
urllib.urlopen(url)
self.cleanup()
self._cleanup_url = cleanup_url
try:
if self._destroyed:
return
if self.MyWorld.CS.World.GetSceneObjectPart(System.Convert.ToUInt32(self.Id)) is None:
self.EventDestroyed() # HACK since we do not receive the EventDestroyed event !
return
ec = self.rexGetECAttributes("EC_VoiceChannel")
if ec is not None:
cleanup_url = REMOVE_BASE_URL + str( ec["channelid"] )
if self._cleanup_url != cleanup_url:
self.cleanup()
self._cleanup_url = cleanup_url
create_url = CREATE_BASE_URL + str( ec["channelid"] )
urllib.urlopen(create_url)
except:
self.EventDestroyed()

def EventTimer(self):
self.create_channel()
Expand Down

0 comments on commit 16318d3

Please sign in to comment.