def receive_message(inter_ob, data, txt): global call_catch_tell if call_catch_tell is None: symbol_ob = ldmud.Symbol('ob') symbol_txt = ldmud.Symbol('txt') call_catch_tell = ldmud.efuns.unbound_lambda( ldmud.Array(( symbol_ob, symbol_txt, )), ldmud.Array( (ldmud.Closure(ldmud.get_master(), "efun::call_resolved"), ldmud.Array((ldmud.Closure(ldmud.get_master(), '&'), ldmud.Symbol('result'))), symbol_ob, "catch_tell", symbol_txt))) current_ob = ldmud.efuns.this_object() if current_ob == inter_ob or not ldmud.efuns.bind_lambda( call_catch_tell, current_ob)(inter_ob, txt): data.call_control_ob("receive_message", inter_ob, txt) if data.snooper is not None: try: ldmud.efuns.tell_object(data.snooper, "%" + txt) except: pass
def efun_configure_interactive(inter_ob: ldmud.Object, what: int, value) -> None: data = control.interactives.get(inter_ob, None) if data is None: return ldmud.efuns.configure_interactive(inter_ob, what, value) else: current_ob = ldmud.efuns.this_object() if current_ob not in ( inter_ob, ldmud.get_master(), ldmud.get_simul_efun(), ): master = ldmud.get_master() result = util.lfun_call(master, "privilege_violation", "configure_interactive", current_ob, inter_ob, what, value) if not isinstance(result, int) or result < 0: raise RuntimeError( "Privilege violation: configure_interactive") elif result == 0: return data.options[what] = value
def efun_snoop(snooper: ldmud.Object, snoopee: ldmud.Object = 0) -> int: data = control.interactives.get(snoopee, None) if data is None: if snoopee == 0: result = ldmud.efuns.snoop(snooper) else: result = ldmud.efuns.snoop(snooper, snoopee) if (result > 0 or snoopee == 0) and snooper in snoopers: snoopers.pop(snooper)[1].snooper = None return 1 return result master = ldmud.get_master() result = util.lfun_call(master, "valid_snoop", snooper, snoopee) if not isinstance(result, int) or result == 0: return 0 if snooper in snoopers: snoopers[snooper][1].snooper = None snoopers[snooper] = (snoopee, data) data.snooper = snooper ldmud.efuns.snoop(snooper) return 1
def efun_exec(inter_ob1: ldmud.Object, inter_ob2: ldmud.Object) -> int: data1 = control.interactives.get(inter_ob1, None) data2 = control.interactives.get(inter_ob2, None) if data2 is None: if not ldmud.efuns.exec(inter_ob1, inter_ob2): return 0 elif data1 is None and ldmud.efuns.interactive(inter_ob1): if not ldmud.efuns.exec(inter_ob2, inter_ob1): return 0 else: master = ldmud.get_master() result = util.lfun_call(master, "valid_exec", ldmud.efuns.program_name(), inter_ob1, inter_ob2) if not isinstance(result, int) or result == 0: return 0 if data1 is not None: del control.interactives[inter_ob1] control.interactives[inter_ob2] = data1 data1.call_control_ob("interactive_exec", inter_ob1, inter_ob2) if data2 is not None: if data1 is None: del control.interactives[inter_ob2] control.interactives[inter_ob1] = data2 data2.call_control_ob("interactive_exec", inter_ob2, inter_ob1) return 1
def query_snooper(): master = ldmud.get_master() if master != ldmud.efuns.this_object(): result = util.lfun_call(master, "valid_query_snoop", inter_ob) if not isinstance(result, int) or result == 0: return 0 return data.snooper
def testLvalueStructItem(self): s = ldmud.Struct(ldmud.get_master(), "test_struct", (10, )) self.assertIsNotNone(s) lv = ldmud.Lvalue(s) self.assertEqual(lv.members.t_int.value, 10) lv.members.t_int.value = 100 self.assertEqual(s.members.t_int.value, 100) s.members.t_int.value = 1000 self.assertEqual(lv.members.t_int.value, 1000)
def check_privilege(name, *args): """ Calls master->privilege_violation(). Returns True if it is allowed. """ res = ldmud.get_master().functions.privilege_violation( name, ldmud.efuns.this_object(), *args) if res > 0: return True if res == 0: return False raise PermissionError("insufficient privileges")
def testMaster(self): ob = ldmud.Object("/master") self.assertEqual(ob, ldmud.get_master())
def setUp(self): self.master = ldmud.get_master()