def handle_read(self): """ handle a read """ Telnet.handle_read(self) data = self.getdata() if data: ndata = self.lastmsg + data alldata = ndata.replace("\r", "") ndatal = alldata.split('\n') self.lastmsg = ndatal[-1] for i in ndatal[:-1]: tosend = i try: tnoansi = self.api('colors.stripansi')(tosend) except AttributeError: tnoansi = tosend try: tconvertansi = self.api('colors.convertansi')(tosend) except AttributeError: tconvertansi = tosend if tosend != tconvertansi: self.api('send.msg')('converted %s to %s' % (repr(tosend), tconvertansi), 'ansi') newdata = self.api('events.eraise')('from_mud_event', { 'original': tosend, 'dtype': 'frommud', 'noansi': tnoansi, 'convertansi': tconvertansi }) if 'original' in newdata: tosend = newdata['original'] if 'omit' in newdata and newdata['omit']: tosend = None if tosend != None: #data cannot be transformed here if self.api('api.has')('colors.stripansi'): tnoansi = self.api('colors.stripansi')(tosend) else: tnoansi = tosend if self.api('api.has')('colors.convertansi'): tconvertansi = self.api('colors.convertansi')(tosend) else: tconvertansi = tosend self.api('events.eraise')('to_client_event', { 'original': tosend, 'dtype': 'frommud', 'noansi': tnoansi, 'convertansi': tconvertansi })
def handle_read(self): """ handle a read """ Telnet.handle_read(self) data = self.getdata() if data: ndata = "".join([self.lastmsg, data]) # don't care about \r alldata = ndata.replace("\r", "") # split on \n ndatal = alldata.split('\n') self.lastmsg = ndatal[-1] for i in ndatal[:-1]: tosend = i try: tnoansi = self.api('colors.stripansi')(tosend) except AttributeError: tnoansi = tosend try: tconvertansi = self.api('colors.convertansi')(tosend) except AttributeError: tconvertansi = tosend if tosend != tconvertansi: self.api('send.msg')('converted %s to %s' % (repr(tosend), tconvertansi), 'ansi') trace = {} trace['dtype'] = 'frommud' trace['original'] = tosend trace['changes'] = [] data = {'original':tosend, 'data':tosend, 'dtype':'frommud', 'noansi':tnoansi, 'convertansi':tconvertansi, 'trace':trace} self.api('events.eraise')('muddata_trace_started', data, calledfrom='proxy') # this event can be used to transform the data newdata = self.api('events.eraise')('from_mud_event', data, calledfrom="mud") self.api('events.eraise')('muddata_trace_finished', data, calledfrom='proxy') # use the original key in the returned dictionary # TODO: make this so that it uses a key just named data if 'original' in newdata: tosend = newdata['original'] # omit the data if it has been flagged if 'omit' in newdata and newdata['omit']: tosend = None if tosend != None: #data cannot be transformed here, it goes straight to the client if self.api('api.has')('colors.stripansi'): tnoansi = self.api('colors.stripansi')(tosend) else: tnoansi = tosend if self.api('api.has')('colors.convertansi'): tconvertansi = self.api('colors.convertansi')(tosend) else: tconvertansi = tosend self.api('send.client')(tosend, dtype='frommud')
def handle_read(self): """ handle a read """ if not self.connected: return Telnet.handle_read(self) data = self.getdata() if data: if self.state == CONNECTED: if self.viewonly: self.addtooutbufferevent({ 'todata': self.api('colors.convertcolors')( '@R#BP@w: @RYou are in view mode!@w') }) else: if data: self.api('send.execute')(data, fromclient=True) elif self.state == PASSWORD: data = data.strip() proxyp = self.api('plugins.getp')('proxy') dpw = proxyp.api('proxy.proxypw')() vpw = proxyp.api('proxy.proxypwview')() if dpw and data == dpw: self.api('send.msg')('Successful password from %s : %s' % \ (self.host, self.port), 'net') self.state = CONNECTED self.api('events.eraise')('client_connected', { 'client': self }, calledfrom="client") self.api('send.client')("%s - %s: Client Connected" % \ (self.host, self.port)) elif vpw and data == vpw: self.api('send.msg')('Successful view password from %s : %s' % \ (self.host, self.port), 'net') self.state = CONNECTED self.viewonly = True self.addtooutbufferevent({ 'original': self.api('colors.convertcolors')( '@R#BP@W: @GYou are connected in view mode@w') }) self.api('events.eraise')('client_connected_view', { 'client': self }, calledfrom="client") self.api('send.client')( "%s - %s: Client Connected (View Mode)" % \ (self.host, self.port)) else: self.pwtries += 1 if self.pwtries == 5: self.addtooutbufferevent({ 'original': self.api('colors.convertcolors') ('@R#BP@w: @RYou have been BANNED for 10 minutes:@w' ), 'dtype': 'passwd' }) self.api('send.msg')('%s has been banned.' % self.host, 'net') self.api('clients.addbanned')(self.host) self.handle_close() else: self.addtooutbufferevent({ 'original': self.api('colors.convertcolors') ('@R#BP@w: @RPlease try again! Proxy Password:@w'), 'dtype': 'passwd' })
def handle_read(self): """ handle a read """ if not self.connected: return Telnet.handle_read(self) data = self.getdata() if data: if self.state == CONNECTED: if self.viewonly: self.addtooutbufferevent( {'todata':self.api('colors.convertcolors')( '@R#BP@w: @RYou are in view mode!@w')}) else: if data: self.api('send.execute')(data, fromclient=True) elif self.state == PASSWORD: data = data.strip() proxyp = self.api('plugins.getp')('proxy') dpw = proxyp.api('proxy.proxypw')() vpw = proxyp.api('proxy.proxypwview')() if dpw and data == dpw: self.api('send.msg')('Successful password from %s : %s' % \ (self.host, self.port), 'net') self.state = CONNECTED self.api('events.eraise')('client_connected', {'client':self}, calledfrom="client") self.api('send.client')("%s - %s: Client Connected" % \ (self.host, self.port)) elif vpw and data == vpw: self.api('send.msg')('Successful view password from %s : %s' % \ (self.host, self.port), 'net') self.state = CONNECTED self.viewonly = True self.addtooutbufferevent( {'original':self.api('colors.convertcolors')( '@R#BP@W: @GYou are connected in view mode@w')}) self.api('events.eraise')('client_connected_view', {'client':self}, calledfrom="client") self.api('send.client')( "%s - %s: Client Connected (View Mode)" % \ (self.host, self.port)) else: self.pwtries += 1 if self.pwtries == 5: self.addtooutbufferevent( {'original':self.api('colors.convertcolors')( '@R#BP@w: @RYou have been BANNED for 10 minutes:@w'), 'dtype':'passwd'}) self.api('send.msg')('%s has been banned.' % self.host, 'net') self.api('clients.addbanned')(self.host) self.handle_close() else: self.addtooutbufferevent( {'original':self.api('colors.convertcolors')( '@R#BP@w: @RPlease try again! Proxy Password:@w'), 'dtype':'passwd'})
def handle_read(self): """ handle a read """ Telnet.handle_read(self) data = self.getdata() if data: ndata = "".join([self.lastmsg, data]) # don't care about \r alldata = ndata.replace("\r", "") # split on \n ndatal = alldata.split('\n') self.lastmsg = ndatal[-1] for i in ndatal[:-1]: tosend = i try: tnoansi = self.api('colors.stripansi')(tosend) except AttributeError: tnoansi = tosend try: tconvertansi = self.api('colors.convertansi')(tosend) except AttributeError: tconvertansi = tosend if tosend != tconvertansi: self.api('send.msg')('converted %s to %s' % (repr(tosend), tconvertansi), 'ansi') trace = {} trace['dtype'] = 'frommud' trace['original'] = tosend trace['changes'] = [] data = { 'original': tosend, 'data': tosend, 'dtype': 'frommud', 'noansi': tnoansi, 'convertansi': tconvertansi, 'trace': trace } self.api('events.eraise')('muddata_trace_started', data, calledfrom='proxy') # this event can be used to transform the data newdata = self.api('events.eraise')('from_mud_event', data, calledfrom="mud") self.api('events.eraise')('muddata_trace_finished', data, calledfrom='proxy') # use the original key in the returned dictionary # TODO: make this so that it uses a key just named data if 'original' in newdata: tosend = newdata['original'] # omit the data if it has been flagged if 'omit' in newdata and newdata['omit']: tosend = None if tosend != None: #data cannot be transformed here, it goes straight to the client if self.api('api.has')('colors.stripansi'): tnoansi = self.api('colors.stripansi')(tosend) else: tnoansi = tosend if self.api('api.has')('colors.convertansi'): tconvertansi = self.api('colors.convertansi')(tosend) else: tconvertansi = tosend self.api('send.client')(tosend, dtype='frommud')