예제 #1
0
 def parseListChannelsResponse(self, data):
     if len(data) <= 8:
         logging.error('No channels found')
         self.stateChannelIsLoaded = True
         return
     status1, data = Protocol.extractInt(data)
     status2, data = Protocol.extractInt(data)
     logging.debug("Load channels header " + repr(status1) + repr(status2))
     while len(data) > 4:
         room, data = Protocol.extractTLV(data)
         romname, data = Protocol.extractTLV(data)
         title, data = Protocol.extractTLV(data)
         users, data = Protocol.extractInt(data)
         port, data = Protocol.extractInt(data)
         index, data = Protocol.extractInt(data)
         channel = {
             'rom': romname.decode("utf-8").split(':')[0],
             'room': room.decode("utf-8"),
             'title': title.decode("utf-8"),
             'users': users,
             'port': port,
         }
         self.channels[room.decode("utf-8")] = channel
     logging.debug(repr(self.channels))
     self.stateChannelIsLoaded = True
     if len(data) > 0:
         logging.error('Channel REMAINING DATA len {} {}'.format(
             len(data), repr(data))
         )
예제 #2
0
 def parseMotdResponse(self, data):
     if not data:
         return
     status, data = Protocol.extractInt(data)
     channel, data = Protocol.extractTLV(data)
     topic, data = Protocol.extractTLV(data)
     msg, data = Protocol.extractTLV(data)
     self.emitList.append(
         {
             'state': 'motdReceived',
             'channel': str(channel),
             'topic': str(topic),
             'message': str(msg)
         }
     )
예제 #3
0
 def parseChatResponse(self, data):
     name, data = Protocol.extractTLV(data)
     msg, data = Protocol.extractTLV(data)
     try:
         msg = msg.decode('utf-8')
         name = name.decode('utf-8')
     except ValueError:
         pass
     logging.debug(u"<{}> {}".format(name, msg))
     self.emitList.append(
         {
             'state': 'chatReceived',
             'message': str(msg),
             'name': str(name)
         }
     )
예제 #4
0
 def parseListUsersResponse(self, data):
     self.resetPlayers()
     if not data:
         return
     status, data = Protocol.extractInt(data)
     status2, data = Protocol.extractInt(data)
     while len(data) > 8:
         p1, data = Protocol.extractTLV(data)
         # if len(data) <= 4: break
         state, data = Protocol.extractInt(data)
         p2, data = Protocol.extractTLV(data)
         ip, data = Protocol.extractTLV(data)
         unk1, data = Protocol.extractInt(data)
         unk2, data = Protocol.extractInt(data)
         city, data = Protocol.extractTLV(data)
         cc, data = Protocol.extractTLV(data)
         if cc:
             cc = cc.lower()
         country, data = Protocol.extractTLV(data)
         port, data = Protocol.extractInt(data)
         spectators, data = Protocol.extractInt(data)
         self.addUser(
             player=p1,
             ip=ip,
             port=port,
             city=city,
             cc=cc,
             country=country,
             spectators=spectators+1,
         )
         if state == PlayerStates.AVAILABLE:
             self.available[p1] = True
         elif state == PlayerStates.AFK:
             self.awayfromkb[p1] = True
         elif state == PlayerStates.PLAYING:
             if not p2:
                 p2 = 'null'
             self.playing[p1] = p2
     self.emitList.append(
         {
             'state': 'playersLoaded',
         }
     )
     if len(data) > 0:
         logging.error(
             'List users - REMAINING DATA len {} {}'.format(len(data), repr(data))
         )
예제 #5
0
 def extractStateChangesResponse(data):
     if len(data) >= 4:
         code, data = Protocol.extractInt(data)
         p1, data = Protocol.extractTLV(data)
         if code == 0:
             p2 = ''
             return PlayerStates.QUIT, p1, p2, None, data
         elif code != 1:
             logging.error(
                 "Unknown player state change code {}".format(code)
             )
         state, data = Protocol.extractInt(data)
         p2, data = Protocol.extractTLV(data)
         if not p2:
             p2 = "null"
         ip, data = Protocol.extractTLV(data)
         # \xff\xff\xff\x9f
         # \x00\x00\x00&
         unknown1, data = Protocol.extractInt(data)
         unknown2, data = Protocol.extractInt(data)
         city, data = Protocol.extractTLV(data)
         cc, data = Protocol.extractTLV(data)
         if cc:
             cc = cc.lower()
         country, data = Protocol.extractTLV(data)
         # \x00\x00\x17y
         marker, data = Protocol.extractInt(data)
         playerinfo = dict(
             player=p1,
             ip=ip,
             city=city,
             cc=cc,
             country=country,
             spectators=0,
         )
         return state, p1, p2, playerinfo, data