def __init__(self): Component.__init__(self) self.worldstream = None #self.worldstream = r.getServerConnection() self.queue = Queue.Queue() self.window = EstateManagementWindow(self, self.queue) self.uievents = UIEventManagement(self.window) self.rexlogic = r.getRexLogic() self.appdatafolder = "" try: self.appdatafolder = r.getApplicationDataDirectory() except: r.logInfo("Unexpected error:", sys.exc_info()[0]) self.rexlogic.connect("OnIncomingEstateOwnerMessage(QVariantList)", self.onEstateOwnerMessage) self.ents = [] self.managers = {} self.banned = {} self.accesslist = {} self.publicestate = True self.nameToUuidMapCache = {} self.savedusers = {} #self.estatesettings = EstateSettings(self.worldstream, self) self.estatesettings = None
class EstateManagement(Component): ESTATE_DATA_FOLDER = "estatedata" SAVED_USERS_FILE = "savedusers.txt" def __init__(self): Component.__init__(self) self.worldstream = None #self.worldstream = r.getServerConnection() self.queue = Queue.Queue() self.window = EstateManagementWindow(self, self.queue) self.uievents = UIEventManagement(self.window) self.rexlogic = r.getRexLogic() self.appdatafolder = "" try: self.appdatafolder = r.getApplicationDataDirectory() except: r.logInfo("Unexpected error:", sys.exc_info()[0]) self.rexlogic.connect("OnIncomingEstateOwnerMessage(QVariantList)", self.onEstateOwnerMessage) self.ents = [] self.managers = {} self.banned = {} self.accesslist = {} self.publicestate = True self.nameToUuidMapCache = {} self.savedusers = {} #self.estatesettings = EstateSettings(self.worldstream, self) self.estatesettings = None def on_exit(self): r.logInfo("EstateManagement exiting...") self.rexlogic.disconnect("OnIncomingEstateOwnerMessage(QVariantList)", self.onEstateOwnerMessage) self.uievents.isrunning = False self.window.on_exit() r.logInfo("EstateManagement done exiting...") def on_hide(self, shown): pass def update(self, time): pass def on_sceneadded(self, name): r.logInfo("Estate management scene added.") # self.loadEstate() # cant get caps at this time, should have some on_login_region_finished event pass def on_logout(self, id): r.logInfo("Estate management Logout.") def on_login(self): r.logInfo("Estate management on login.") pass def tryGetNameFromSceneEntities(self, uuid): for e in self.ents: if(e.opensimpresence.QGetUUIDString()==uuid): return e.opensimpresence.QGetFullName() return "unknown" def tryGetNameFromNameToUuidMapCache(self, uuid): for key, val in self.nameToUuidMapCache.items(): if key==uuid: return self.nameToUuidMapCache.pop(key) return "unknown" def tryGetNameFromSavedUsers(self, uuid): for key, val in self.savedusers.items(): if val==uuid: return key #return d.pop(key) return "unknown" def loadEstate(self): self.worldstream = r.getServerConnection() if self.worldstream==None: self.queue.put(("displayerror", "No worldstream, check if you're connected to server")) else: self.estatesettings = EstateSettings(self.worldstream, self) s = naali.getScene("World") self.ents = s.GetEntitiesWithComponentRaw("EC_OpenSimPresence") self.window.setRegionUsers(self.ents) #self.worldstream.SendEstateInfoRequestpacket() #!! self.worldstream.SendEstateOwnerMessage("getinfo", ()) self.updateSavedUsers() #self.updateSavedUsersTab() #test if rights to modify access cap = self.worldstream.GetCapability('EstateRegionSettingsModification') if cap==None or cap=="": self.window.setNoCapInfo() else: self.estatesettings.fetchEstates() self.window.resetCapInfo() pass def toBan(self, pos): self.sendEstateaccessdelta(pos, 64) def toAccess(self, pos): self.sendEstateaccessdelta(pos, 4) def toManagers(self, pos): self.sendEstateaccessdelta(pos, 256) def removeBan(self, pos): self.sendEstateaccessdeltaRemove(pos, 128, self.banned) pass def removeAccess(self, pos): self.sendEstateaccessdeltaRemove(pos, 8, self.accesslist) pass def removeManager(self, pos): self.sendEstateaccessdeltaRemove(pos, 512, self.managers) pass def kickUser(self, pos): pass def sendEstateaccessdelta(self, pos, estateAccessType): if len(self.ents) > pos: e = self.ents[pos] uuid = e.opensimpresence.QGetUUIDString() #if ((estateAccessType & 256) != 0) // Manager add method = "estateaccessdelta" self.worldstream.SendEstateOwnerMessage(method, ("", estateAccessType, uuid)) def sendEstateaccessdeltaRemove(self, pos, estateAccessType, dict): if(dict.__len__()>pos): #if ((estateAccessType & 256) != 0) // Manager add uuid = dict.keys()[pos] method = "estateaccessdelta" self.worldstream.SendEstateOwnerMessage(method, ("", estateAccessType, uuid)) def requestGodLikePowers(self): self.worldstream.SendRequestGodlikePowersPacket(True) def sendKick(self, pos, message): if len(self.ents) > pos: e = self.ents[pos] uuid = e.opensimpresence.QGetUUIDString() self.worldstream.SendGodKickUserPacket(uuid, message) def saveUserInfo(self, pos): if len(self.ents) > pos: e = self.ents[pos] info = e.opensimpresence.QGetFullName() + "|" + e.opensimpresence.QGetUUIDString() + "\n" filepath = self.appdatafolder + os.sep + EstateManagement.ESTATE_DATA_FOLDER + os.sep + EstateManagement.SAVED_USERS_FILE if(os.access(self.appdatafolder + os.sep + EstateManagement.ESTATE_DATA_FOLDER, os.F_OK)==False): # create folder os.mkdir(self.appdatafolder + os.sep + EstateManagement.ESTATE_DATA_FOLDER) f = open(filepath, 'a') f.write(info) f.close() self.updateSavedUsers() #self.updateSavedUsersTab() def updateSavedUsers(self): #def updateSavedUsersTab(self): filepath = self.appdatafolder + os.sep + EstateManagement.ESTATE_DATA_FOLDER + os.sep + EstateManagement.SAVED_USERS_FILE if(os.access(filepath, os.F_OK)): f = open(filepath, 'r') lines = f.readlines() self.window.setSavedUsers(lines) i = 0 while(i<lines.__len__()): line = lines[i].replace('\n','') self.savedusers[line.split('|')[0]] = line.split('|')[1] i=i+1 f.close() def removeSaved(self, line): filepath = self.appdatafolder + os.sep + EstateManagement.ESTATE_DATA_FOLDER + os.sep + EstateManagement.SAVED_USERS_FILE newlines = [] if(os.access(filepath, os.F_OK)): f = open(filepath, 'r') lines = f.readlines() f.close() #os.remove(filepath) # need to remove old data for sline in lines: if sline.strip() == line.strip(): #skip pass else: newlines.append(sline) f = open(filepath, 'w') f.writelines(newlines) f.close() def fromSavedToAccess(self, uuid, name): self.nameToUuidMapCache[uuid]=name self.worldstream.SendEstateOwnerMessage("estateaccessdelta", ("", 4, uuid)) def fromSavedToBan(self, uuid, name): self.nameToUuidMapCache[uuid]=name self.worldstream.SendEstateOwnerMessage("estateaccessdelta", ("", 64, uuid)) def fromSavedToManagers(self, uuid, name): self.nameToUuidMapCache[uuid]=name self.worldstream.SendEstateOwnerMessage("estateaccessdelta", ("", 256, uuid)) def setEstateAccessMode(self, mode): self.estatesettings.setAccessMode(mode) def onEstateOwnerMessage(self, args): method = args[3] if(method=='estateupdateinfo'): self.handleEstateUpdateMessage(args) if(method=='setaccess'): self.handleSetAccess(args) def handleEstateUpdateMessage(self, args): agentid, sessionid, transactionid, method, invoice, paramlist = args len = paramlist.__len__() if(len!=10): r.logInfo('malformed estateupdateinfo') return self.queue.put(('EstateUpdate', paramlist)) def handleSetAccess(self, args): paramlist = args[5] code = int(paramlist[1]) if(code==1): # AccessOptions = 1, self.handleAccessOptions(args) if(code==2): # AllowedGroups = 2, self.handleAllowedGroups(args) if(code==4): # EstateBans = 4, self.handleEstateBans(args) if(code==8): # EstateManagers = 8 self.handleEstateManagers(args) def handleAccessOptions(self, args): self.processIncomingList(args, 'setEsteteAccessList', self.accesslist) pass def handleAllowedGroups(self, args): pass def handleEstateBans(self, args): self.processIncomingList(args, 'setEstateBans', self.banned) def handleEstateManagers(self, args): self.processIncomingList(args, 'setEstateManagers', self.managers) def processIncomingList(self, args, uiUpdateCommand, updateList): updateList.clear() agentid, sessionid, transactionid, method, invoice, paramlist = args if(paramlist.__len__()>6): for i in range(6, paramlist.__len__()): # decode for uuids one by one uuid = self.uuidFromHex(paramlist[i]) name = self.tryGetNameFromSceneEntities(uuid) if name == "unknown": name = self.tryGetNameFromNameToUuidMapCache(uuid) if name == "unknown": name = self.tryGetNameFromSavedUsers(uuid) updateList[uuid] = name self.queue.put((uiUpdateCommand, updateList)) pass def uuidFromHex(self, hexarray): result = "" for j in range(0,hexarray.__len__()): hex = "%X"%ord(hexarray[j]) if hex.__len__()==1: hex = "0" + hex result = result + hex result = result.lower() uuid = result[:8] + "-" + result[8:12] + "-" + result[12:16] + "-" + result[16:20] + "-" + result[20:] return uuid