Пример #1
0
def read_data(data):
    ba = ByteArray(data)
    #大端模式标准对齐方式
    ba.endian = "!"
    length = ba.readInt()

    print "length", length

    print "bytesAvailable", ba.bytesAvailable()

    #只用了1位字节存储 长度-128 - 127
    #业务大类
    actionName = ba.readByte()
    #具体业务类型
    type = ba.readByte()

    print "actionName", actionName
    print "type", type

    str = ba.readUTFBytes(3)
    print str


    i = ba.readInt()
    print i
Пример #2
0
 def dataReceived(self, data):
     ba = ByteArray(data)
     print ba.bytesAvailable()
     s = ba.readUnsignedInt()
     print ba.bytesAvailable()
     print s
     s = ba.readUTFBytes(ba.bytesAvailable())
     print s
Пример #3
0
 def writeData(self, id, data):
     length = len(data)
     #print id, length, data
     ba = ByteArray()
     ba.endian = '!'
     ba.writeInt(id)
     ba.writeInt(length)
     ba.writeUTFBytes(data)
     return ba.data
Пример #4
0
 def lineReceived(self, line):
     print line
     ba = ByteArray(line)
     print ba.bytesAvailable()
     s = ba.readInt()
     print s
     s = ba.readUTFBytes(ba.bytesAvailable())
     print s
     self.factory.sendAll(self, line)
Пример #5
0
def write_data(id, data):
    #获取协议号 + 内容 以后的长度
    length = get_bytes_len(id) + get_bytes_len(data)
    print id, length, data
    ba = ByteArray()
    ba.endian = "!"
    ba.writeInt(length)
    ba.writeInt(id)
    #print type(data)
    #根据data类型 写入ba
    write_data_in_bytes(ba, data)
    return ba.data
Пример #6
0
 def decode(self, data):
     ba = ByteArray(data)
     ba.endian = "!"
     #判断长度
     #print 'self.tempDataBuffer', self.tempDataBuffer
     if self.tempDataBuffer == "":
         self.id = ba.readInt()
         print self.id
         length = ba.readInt()
         s = ba.readUTFBytes(ba.bytesAvailable())
         print 'length', length, len(s)
         #判断长度
         if len(s) < length:
             self.tempDataBuffer = s
         else:
             print "content", s
             return {"id":self.id, "content":s}
     else:
         s = self.tempDataBuffer + ba.readUTFBytes(ba.bytesAvailable())
         print 'hebing', s
         return {"id":self.id, "content":s}
Пример #7
0
def write_multi_data(id, params):
    length = get_bytes_len(id)
    for i in range(0, len(params)):
        length += get_bytes_len(params[i])
    ba = ByteArray()
    #大端模式标准对齐方式
    ba.endian = "!"
    ba.writeInt(length)
    ba.writeInt(id)
    #根据data类型 写入ba
    for i in range(0, len(params)):
        data = params[i]
        write_data_in_bytes(ba, data)
    return ba.data
Пример #8
0
def get_bytes_len(data):
    b = ByteArray()
    b.endian = "!"
    write_data_in_bytes(b, data)
    return len(b.data)
 def changeReportStatusBanned(self, playerName, banhours, banreason,
                              bannedby):
     self.client.sendPacket(
         Identifiers.send.Modopwet_Banned,
         ByteArray().writeUTF(playerName).writeUTF(bannedby).writeInt(
             int(banhours)).writeUTF(banreason).toByteArray())
 def changeReportStatusDeleted(self, playerName, deletedby):
     self.client.sendPacket(
         Identifiers.send.Modopwet_Deleted,
         ByteArray().writeUTF(playerName).writeUTF(deletedby).toByteArray())
 def changeReportStatusDisconnect(self, playerName):
     self.client.sendPacket(Identifiers.send.Modopwet_Disconnected,
                            ByteArray().writeUTF(playerName).toByteArray())
    def openModoPwet(self,
                     isOpen=False,
                     modopwetOnlyPlayerReports=False,
                     sortBy=False):
        if isOpen:
            if len(self.server.reports) <= 0:
                self.client.sendPacket(Identifiers.send.Modopwet_Open, 0)
            else:
                self.client.sendPacket(Identifiers.send.Modopwet_Open, 0)
                reports, bannedList, deletedList, disconnectList = self.sortReports(
                    self.server.reports, sortBy), {}, {}, []
                sayi = 0
                p = ByteArray()
                for i in reports:
                    isim = i[0]
                    v = self.server.reports[isim]
                    if self.client.modoPwetLangue == 'ALL' or v[
                            "dil"] == self.client.modoPwetLangue:
                        oyuncu = self.server.players.get(isim)
                        saat = math.floor(oyuncu.playerTime /
                                          3600) if oyuncu else 0
                        odaisim = oyuncu.roomName if oyuncu else "0"
                        sayi += 1
                        self.client.lastReportID += 1
                        if sayi >= 255:
                            break
                        p.writeByte(sayi)
                        p.writeShort(self.client.lastReportID)
                        p.writeUTF(v["dil"])
                        p.writeUTF(isim)
                        p.writeUTF(odaisim)
                        p.writeByte(1)  # alttaki modname uzunlugu ile alakali
                        p.writeUTF(self.getRoomMods(odaisim))
                        p.writeInt(saat)  #idk
                        p.writeByte(int(len(v["reporters"])))
                        for name in v["reporters"]:
                            r = v["reporters"][name]
                            p.writeUTF(name)
                            p.writeShort(self.getPlayerKarma(name))  #karma
                            p.writeUTF(r[1])
                            p.writeByte(r[0])
                            p.writeShort(int(Utils.getSecondsDiff(r[2]) /
                                             60))  #05m felan rep suresi

                        mute = v["isMuted"]
                        p.writeBoolean(mute)  #isMute
                        if mute:
                            p.writeUTF(v["mutedBy"])
                            p.writeShort(v["muteHours"])
                            p.writeUTF(v["muteReason"])

                        if v['durum'] == 'banned':
                            x = {}
                            x['banhours'] = v['banhours']
                            x['banreason'] = v['banreason']
                            x['bannedby'] = v['bannedby']
                            bannedList[isim] = x
                        if v['durum'] == 'deleted':
                            x = {}
                            x['deletedby'] = v['deletedby']
                            deletedList[isim] = x
                        if v['durum'] == 'disconnected':
                            disconnectList.append(isim)

                self.client.sendPacket(
                    Identifiers.send.Modopwet_Open,
                    ByteArray().writeByte(int(len(reports))).writeBytes(
                        p.toByteArray()).toByteArray())
                for user in disconnectList:
                    self.changeReportStatusDisconnect(user)

                for user in deletedList.keys():
                    self.changeReportStatusDeleted(
                        user, deletedList[user]['deletedby'])

                for user in bannedList.keys():
                    self.changeReportStatusBanned(
                        user, bannedList[user]['banhours'],
                        bannedList[user]['banreason'],
                        bannedList[user]['bannedby'])