예제 #1
0
 def write(self, line, display_line = True):
     if not isinstance(line, (basestring, Metaline)):
         line = str(line)
     if isinstance(line, basestring):
         metaline = simpleml(line, fg_code(WHITE, False), bg_code(BLACK))
         metaline.wrap = False
     else:
         metaline = line
     self.send_to_client('display_line', [metaline_to_json(metaline),int(display_line)])
예제 #2
0
 def lineReceived_recomposed(self, line):
     
         
     meth,rest = json.loads(line)
     if meth == "close":
         self.stop()
     elif meth == "ping":
         self.missed_heartbeats=-1
         
     elif meth == "hello":
         self.log.write('Hello received\n')
         name = rest[0]
         self.name = name
         
     elif meth == 'mud_line':
         metaline = json_to_metaline(rest[0])
         display_line = bool(rest[1])
         #self.match_triggers(metaline, display_line)
         #self.transport.write(json.dumps(['display_line', [metaline_to_json(metaline), 1]])+'\n')
         self.send_to_client('display_line', [metaline_to_json(metaline),1])
     elif meth == 'user_line':
         line = rest[0]
         self.log.write('User Line: %s\n'%line)
         #self.transport.write(json.dumps(['send_to_mud',line])+'\n')
         self.send_to_client('send_to_mud', line)
     elif meth == 'do_block':
         lines = json.loads(rest[0])
         block = []
         for l in lines:
             block.append(json_to_metaline(l))
         self.blockReceived(block)
     
     elif meth == 'do_triggers':
         metaline=json_to_metaline(rest[0])
         display_line = bool(rest[1])
         self.metalineReceived(metaline, display_line)
     
     elif meth == 'do_aliases':
         line = rest[0]
         self.server_echo = bool(rest[1])
         echo = bool(rest[2])
         self.parseSend(line, echo)
     elif meth == 'do_gmcp':
         pair = rest[0]
         gmcp_key,gmcp_data = pair
         self.gmcp[gmcp_key]=gmcp_data
         for gmcp_event in self.gmcp_events:
             gmcp_event(pair, self)
     else:
         raise ValueError("bad line: %s" % line)
     #self.transport.write(json.dumps(["ack", [meth,rest]]) + "\n")
     self.send_to_client('ack', [meth,rest])
예제 #3
0
 def do_triggers(self, metaline, display_line):
     self.send_to_client("do_triggers", [metaline_to_json(metaline), int(display_line)])
     if not self.messages_not_acknowledged:
         self.client_started_processing_at = time.time()
     self.messages_not_acknowledged += 1
예제 #4
0
 def do_block(self, block):
     self.send_to_client('do_block', [json.dumps([metaline_to_json(l) for l in block])])
     if not self.messages_not_acknowledged:
         self.client_started_processing_at = time.time()
     self.messages_not_acknowledged += 1
예제 #5
0
 def mud_line_received(self, metaline, display_line):
     self.send_to_client('mud_line', [metaline_to_json(metaline), int(display_line)])
     if not self.messages_not_acknowledged:
         self.client_started_processing_at = time.time()
     self.messages_not_acknowledged += 1