class Chat_window(object): """ Chat window """ def __init__(self, frame): self.frame = Frame(frame) self.frame.pack() self.agent = Agent() self.login = Login(self) self.logout = None self.chat = None def init_chat(self, ): """ Initializes a chat widgets after login """ self.chat = Chat(self) def login_agent(self, firstname, lastname, password, start_location): self.agent.login("https://login.agni.lindenlab.com/cgi-bin/login.cgi", firstname=firstname, lastname=lastname, password=password, start_location=start_location, connect_region=True) while self.agent.connected == False: api.sleep(0) while self.agent.region.connected == False: api.sleep(0) while connected: api.sleep(0) def tear_down(self): """ Tears down chat widgets and logout widget after logout """ self.chat.frame.pack_forget()
def login(): """ login an to a login endpoint """ parser = OptionParser(usage="usage: %prog [options] firstname lastname") logger = logging.getLogger("client.example") parser.add_option( "-l", "--loginuri", dest="loginuri", default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi", help="specified the target loginuri") parser.add_option( "-r", "--region", dest="region", default=None, help="specifies the region (regionname/x/y/z) to connect to") parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false", help="enable verbose mode") parser.add_option( "-p", "--password", dest="password", default=None, help="specifies password instead of being prompted for one") (options, args) = parser.parse_args() if len(args) != 2: parser.error("Expected arguments: firstname lastname") if options.verbose: console = logging.StreamHandler() console.setLevel( logging.DEBUG) # seems to be a no op, set it for the logger formatter = logging.Formatter( '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console) # setting the level for the handler above seems to be a no-op # it needs to be set for the logger, here the root logger # otherwise it is NOTSET(=0) which means to log nothing. logging.getLogger('').setLevel(logging.DEBUG) else: print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)" # example from a pure agent perspective #grab a password! if options.password: password = options.password else: password = getpass.getpass() #First, initialize the agent client = Agent() # Now let's log it in client.login(options.loginuri, args[0], args[1], password, start_location=options.region) print '' print '' print 'At this point, we have only an Agent object' print 'Agent attributes:' for attr in client.__dict__: print attr, ':\t\t\t', client.__dict__[attr]
class TestAgent(unittest.TestCase): def setUp(self): self.legacy_loginuri = 'http://localhost:12345/cgi-bin/login.cgi' self.ogp_loginuri = 'http://localhost:12345/auth.cgi' self.firstname = 'firstname' self.lastname = 'lastname' self.password = '******' self.client = Agent() def tearDown(self): pass def test_agent_legacy_login_via_variables(self): # override the network client with the mock client pointed at the mock login handler self.loginhandler = MockXMLRPC(MockXMLRPCLogin(), self.legacy_loginuri) self.client.login(self.legacy_loginuri, self.firstname, self.lastname, self.password, start_location='start', handler=self.loginhandler, connect_region=False) self.assertEquals( self.client.login_response, { 'region_y': '256', 'region_x': '256', 'first_name': '"first"', 'secure_session_id': '00000000-0000-0000-0000-000000000000', 'sim_ip': '127.0.0.1', 'agent_access': 'M', 'circuit_code': '600000000', 'look_at': '[r0.9963859999999999939,r-0.084939700000000006863,r0]', 'session_id': '00000000-0000-0000-0000-000000000000', 'udp_blacklist': 'EnableSimulator,TeleportFinish,CrossedRegion', 'seed_capability': 'https://somesim:12043/cap/00000000-0000-0000-0000-000000000000', 'agent_id': '00000000-0000-0000-0000-000000000000', 'last_name': 'last', 'inventory_host': 'someinvhost', 'start_location': 'last', 'sim_port': '13001', 'message': 'message', 'login': '******', 'seconds_since_epoch': '1234567890' }) def test_agent_legacy_login_via_params(self): # override the network client with the mock client pointed at the mock login handler self.loginhandler = MockXMLRPC(MockXMLRPCLogin(), self.legacy_loginuri) login_params = LegacyLoginParams(self.firstname, self.lastname, self.password) self.client.login(self.legacy_loginuri, login_params=login_params, start_location='start', handler=self.loginhandler, connect_region=False) self.assertEquals( self.client.login_response, { 'region_y': '256', 'region_x': '256', 'first_name': '"first"', 'secure_session_id': '00000000-0000-0000-0000-000000000000', 'sim_ip': '127.0.0.1', 'agent_access': 'M', 'circuit_code': '600000000', 'look_at': '[r0.9963859999999999939,r-0.084939700000000006863,r0]', 'session_id': '00000000-0000-0000-0000-000000000000', 'udp_blacklist': 'EnableSimulator,TeleportFinish,CrossedRegion', 'seed_capability': 'https://somesim:12043/cap/00000000-0000-0000-0000-000000000000', 'agent_id': '00000000-0000-0000-0000-000000000000', 'last_name': 'last', 'inventory_host': 'someinvhost', 'start_location': 'last', 'sim_port': '13001', 'message': 'message', 'login': '******', 'seconds_since_epoch': '1234567890' }) def test_agent_ogp_login_via_variables(self): # override the network client with the mock client pointed at the mock login handler self.loginhandler = MockupClient(MockAgentDomainLogin()) self.client.login(self.ogp_loginuri, self.firstname, self.lastname, self.password, start_location='start', handler=self.loginhandler, connect_region=False) self.assertEquals( self.client.login_response, { 'agent_seed_capability': 'http://127.0.0.1:12345/seed_cap', 'authenticated': True }) def test_agent_ogp_login_via_params(self): # override the network client with the mock client pointed at the mock login handler self.loginhandler = MockupClient(MockAgentDomainLogin()) login_params = OGPLoginParams(self.firstname, self.lastname, self.password) self.client.login(self.ogp_loginuri, self.firstname, self.lastname, self.password, start_location='start', handler=self.loginhandler, connect_region=False) self.assertEquals( self.client.login_response, { 'agent_seed_capability': 'http://127.0.0.1:12345/seed_cap', 'authenticated': True }) def test_agent_login_no_account_info(self): self.assertRaises(LoginError, self.client.login, self.ogp_loginuri) def test_legacy_get_login_params(self): self.client.grid_type = 'Legacy' params = self.client._get_login_params(self.firstname, self.lastname, self.password) self.assertEquals( type(params), type( LegacyLoginParams(self.firstname, self.lastname, self.password))) def test_ogp_get_login_params(self): self.client.grid_type = 'OGP' params = self.client._get_login_params(self.firstname, self.lastname, self.password) self.assertEquals( type(params), type(OGPLoginParams(self.firstname, self.lastname, self.password))) ''' def test_failed_legacy_login(self): # ToDo: enable mne when you can get me working, it's 'correct', # but not raising the error properly? self.password = '******' # override the network client with the mock client pointed at the mock login handler self.loginhandler = MockXMLRPC(MockXMLRPCLogin(), self.legacy_loginuri) self.assertRaises(LoginError, self.client.login, self.legacy_loginuri, self.firstname, self.lastname, self.password, start_location = 'start', handler = self.loginhandler) ''' def test_agent_home_class(self): home_string = "{'region_handle':[r261120, r247040], 'position':[r171.622, r148.26, r79.3938], 'look_at':[r0, r1, r0]}" home = Home(home_string) # Note: have not yet worked out precision on floats. Kinda need to self.assertEquals(home.region_handle, [261120, 247040]) self.assertEquals(home.position.X, 171.62200000000001) self.assertEquals(home.position.Y, 148.25999999999999) self.assertEquals(home.position.Z, 79.393799999999999) self.assertEquals(home.look_at.X, 0) self.assertEquals(home.look_at.Y, 1) self.assertEquals(home.look_at.Z, 0) self.assertEquals(home.global_x, 261120) self.assertEquals(home.global_y, 247040)