def sendLookChange(self): try: p = ByteArray() look = self.client.playerLook.split(";") p.writeByte(int(look[0])) for item in look[1].split(","): if "_" in item: itemSplited = item.split("_") realItem = itemSplited[0] custom = itemSplited[1] if len(itemSplited) >= 2 else "" realCustom = [] if custom == "" else custom.split("+") p.writeInt(int(realItem)).writeByte(len(realCustom)) x = 0 while x < len(realCustom): p.writeInt(int(realCustom[x], 16)) x += 1 else: p.writeInt(int(item)).writeByte(0) p.writeInt(int(self.client.mouseColor, 16)) self.client.sendPacket(Identifiers.send.Look_Change, p.toByteArray()) except: pass
def sendLookChange(this): packet = ByteArray() skinID, clothes = this.client.playerLook.split(";") clothes = clothes.split(",") packet.writeByte(int(skinID)) for item in clothes: if "_" in item: itemID, custom = item.split("_") custom = custom.split("+") if custom else [] packet.writeInt(int(itemID)) packet.writeByte(len(custom)) x = 0 while x < len(custom): packet.writeInt(int(custom[x], 16)) x += 1 else: packet.writeInt(int(item)).writeByte(0) packet.writeInt(int(this.client.MouseColor, 16)) this.client.sendPacket(Identifiers.send.Look_Change, packet.toByteArray(), True)
def sendShamanItems(this): packet = ByteArray() shamanItems = [] if this.client.shamanItems == "" else this.client.shamanItems.split( ",") packet.writeShort(len(shamanItems)) for item in shamanItems: if "_" in item: itemSplited = item.split("_") realItem = itemSplited[0] custom = itemSplited[1] if len(itemSplited) >= 2 else "" realCustom = [] if custom == "" else custom.split("+") packet.writeShort(int(realItem)) packet.writeBool(item in this.client.shamanLook.split(",")) packet.writeByte(len(realCustom) + 1) x = 0 while x < len(realCustom): packet.writeInt(int(realCustom[x], 16)) x += 1 else: packet.writeShort(int(item)).writeBool( item in this.client.shamanLook.split(",")).writeByte(0) this.client.sendPacket(Identifiers.send.Shaman_Items, packet.toByteArray(), True)
def ForumsList(self): p = ByteArray("\x02\x02") p.writeUTF(self.langue) dbcur.execute("SELECT * FROM forum_forums where id < 1000") threads = dbcur.fetchall() for thread in threads: if str(thread[1]) in self.pf and self.priv < 4: pass else: p.writeInt(int(thread[1])) p.writeUTF(str(thread[0])) p.writeShort(int(thread[2])) if self.login: dbcur.execute("SELECT tribe FROM users where name = ?", [self.username]) td = dbcur.fetchone() if not td[0] == None: tdc = td[0].split("#")[1] dbcur.execute("SELECT * FROM tribu where Code = ?", [tdc]) ntd = dbcur.fetchone() p.writeInt(int(tdc) + 2000) p.writeUTF("xx") p.writeShort(9) p.writeByte(False) p.writeUTF(ntd[1], True) self.transport.write(p.toPack())
def openThread(self, thread_id, page): if page == -1: page = 0 if page != 0: limit1, limit2 = (page * 20) - 1, page * 40 else: limit1, limit2 = 0, 20 dbcur.execute("SELECT * FROM forum_threads where thread_id = ?", [thread_id]) topicData = dbcur.fetchone() dbcur.execute( "SELECT * FROM forum_comments where thread_id = ? ORDER BY time LIMIT ?, ?;", [thread_id, limit1, limit2]) topicStartMessage = dbcur.fetchall()[0] forum_id = topicData[0] self.forum_id = forum_id self.thread_id = thread_id p = ByteArray("\x02\x05") # [FORUM INFO] # p.writeInt(forum_id) # forumEnCours p.writeInt(thread_id) # sujetEnCours canEdit = self.user_type in self.userTypeNeededForPeutModerer if canEdit: canEdit = 10 elif self.username == topicStartMessage[3]: canEdit = 1 p.writeByte(canEdit) # edition p.writeBoolean(self.user_type != 19) # peutSuppr peutReponder = self.username != "" if bool(topicData[7]): peutReponder = False if not self.login: openthread = False if self.username in om: peutReponder = False p.writeBoolean(peutReponder) # peutRepondre p.writeBoolean(bool(topicData[7])) # fin p.writeBoolean(self.user_type != 19) # modTribu p.writeUTF(topicData[2]) # titre p.writeInt(page) # pageEnCours p.writeInt(int( len(self.getcommentsbythread(thread_id, forum_id)) / 20)) # nobrePage dbcur.execute( "SELECT * FROM forum_comments where thread_id = ? ORDER BY time LIMIT ?, ?", [thread_id, limit1, limit2]) messages = dbcur.fetchall() p.writeByte(len(messages) - 1) # message for message in messages: p.writeInt(message[2]) # id p.writeByte(self.getJoueurType( message[3].encode("cp1251"))) # typeAuteurMessage p.writeUTF(message[3]) # auteur p.writeByte(self.getJoueurType( message[3].encode("cp1251"))) # typeAuteurCourant p.writeInt(10000) # avatar p.writeInt(message[6]) # date p.writeUTF(message[5]) # texte p.writeByte(message[7]) # etat p.writeUTF(message[8].encode('utf-8', 'replace')) # nomModerateur p.writeUTF(message[9].encode('utf-8', 'replace')) # raisonEtat p.writeUTF("") # infos p.writeBoolean(True) # multiLangues p.writeBoolean(False) # etatSignalement #p.writeUTF("TEST Title") self.transport.write(p.toPack())
def sendShamanSkills(self, refresh): packet = ByteArray().writeByte(len(self.client.playerSkills)) for skill in self.client.playerSkills.items(): packet.writeByte(skill[0]).writeByte(skill[1]) packet.writeBoolean(refresh) self.client.sendPacket(Identifiers.send.Shaman_Skills, packet.toByteArray())
def openModoPwet(this): if len(this.server.reports["names"]) <= 0: this.client.sendPacket(Identifiers.send.Open_Modopwet, chr(0)) else: reports = 0 totalReports = len(this.server.reports["names"]) count = 0 bannedList = {} deletedList = {} disconnectList = [] p = ByteArray() while reports < totalReports: playerName = this.server.reports["names"][reports] reports += 1 if this.client.modoPwetLangue == "ALL" or this.server.reports[playerName]["langue"] == this.client.modoPwetLangue.upper(): count += 1 if count >= 255: break p.writeByte(count).writeUTF(this.server.reports[playerName]["langue"].upper()).writeUTF(playerName).writeUTF(this.getPlayerRoomName(playerName)).writeInt(this.getProfileCheeseCount(playerName)) reporters = 0 totalReporters = len(this.server.reports[playerName]["types"]) p.writeByte(totalReporters) while reporters < totalReporters: p.writeUTF(this.server.reports[playerName]["reporters"][reporters]).writeShort(this.getProfileCheeseCount(this.server.reports[playerName]["reporters"][reporters])).writeUTF(this.server.reports[playerName]["comments"][reporters]).writeByte(this.server.reports[playerName]["types"][reporters]).writeShort(reporters) reporters += 1 if this.server.reports[playerName]["status"] == "banned": x = {} x["banhours"] = this.server.reports[playerName]["banhours"] x["banreason"] = this.server.reports[playerName]["banreason"] x["bannedby"] = this.server.reports[playerName]["bannedby"] bannedList[playerName] = x if this.server.reports[playerName]["status"] == "deleted": x = {} x["deletedby"] = this.server.reports[playerName]["deletedby"] deletedList[playerName] = x if this.server.reports[playerName]["status"] == "disconnected": disconnectList.append(playerName) this.client.sendPacket(Identifiers.send.Open_Modopwet, ByteArray().writeByte(count).writeBytes(p.toByteArray()).toByteArray()) for user in disconnectList: this.changeReportStatusDisconnect(user) for user in deletedList.keys(): this.changeReportStatusDeleted(user, deletedList[user]["deletedby"]) for user in bannedList.keys(): this.changeReportStatusBanned(user, bannedList[user]["banhours"], bannedList[user]["banreason"], bannedList[user]["bannedby"])
def writeIHDR(mem: ByteArray, width: int, height: int, bits: int, colors: int): chunk = ByteArray() chunk.writeUnsignedInt(0x49484452) chunk.writeUnsignedInt(width) chunk.writeUnsignedInt(height) chunk.writeByte(bits) chunk.writeByte(colors) chunk.writeByte(0x00) chunk.writeByte(0x00) chunk.writeByte(0x00) PNGEncoder.writeChunk(mem, chunk)
def exportMessage(self): byte = ByteArray() for c in list(self.bytes): if c in range(2): byte.writeByte(1) byte.writeByte(3 if c == 0 else 2) else: byte.writeByte(c) return byte
def sendShamanSkills(this, newBoolean): p = ByteArray().writeByte(len(this.client.playerSkills)) for skill in this.client.playerSkills.items(): p.writeByte(skill[0]).writeByte(skill[1]) this.client.sendPacket(Identifiers.send.Shaman_Skills, p.writeBool(newBoolean).toByteArray(), True)
def sendShopList(this, sendItems=True): shopItems = [] if this.client.shopItems == "" else this.client.shopItems.split( ",") packet = ByteArray().writeInt(this.client.shopCheeses).writeInt( this.client.shopFraises).writeUTF(this.client.playerLook).writeInt( len(shopItems)) for item in shopItems: if "_" in item: itemSplited = item.split("_") realItem = itemSplited[0] custom = itemSplited[1] if len(itemSplited) >= 2 else "" realCustom = [] if custom == "" else custom.split("+") packet.writeByte(len(realCustom) + 1).writeInt(int(realItem)) x = 0 while x < len(realCustom): packet.writeInt(int(realCustom[x], 16)) x += 1 else: packet.writeByte(0).writeInt(int(item)) shop = this.server.shopList if sendItems else [] packet.writeInt(len(shop)) for item in shop: value = item.split(",") packet.writeShort(value[0]).writeShort(value[1]).writeByte( value[2]).writeByte(value[3]).writeByte(value[4]).writeInt( value[5]).writeInt(value[6]).writeShort(0) visuais = this.server.newVisuList packet.writeByte(len(visuais)) i = len(visuais) visu = [] for visual in visuais.items(): visu.append(visual[1]) if visual[1] in visu: visu.remove(visual[1]) packet.writeShort(visual[0]) a = visual[1] packet.writeUTF(''.join(a)) packet.writeByte(2 if visual[0] in [52] else 1 if visual[0] in [53] else 2) i -= 1 packet.writeShort(len(this.client.clothes)) for clothes in this.client.clothes: clotheSplited = clothes.split("/") packet.writeUTF(clotheSplited[1] + ";" + clotheSplited[2] + ";" + clotheSplited[3]) shamanItems = [] if this.client.shamanItems == "" else this.client.shamanItems.split( ",") packet.writeShort(len(shamanItems)) for item in shamanItems: if "_" in item: itemSplited = item.split("_") realItem = itemSplited[0] custom = itemSplited[1] if (len(itemSplited) >= 2) else "" realCustom = [] if custom == "" else custom.split("+") packet.writeShort(int(realItem)).writeBoolean( item in this.client.shamanLook.split(",")).writeByte( len(realCustom) + 1) x = 0 while x < len(realCustom): packet.writeInt(int(realCustom[x], 16)) x += 1 else: packet.writeShort(int(item)).writeBoolean( item in this.client.shamanLook.split(",")).writeByte(0) shamanShop = this.server.shamanShopList if sendItems else [] packet.writeShort(len(shamanShop)) for item in shamanShop: value = item.split(",") packet.writeInt(value[0]).writeByte(value[1]).writeByte( value[2]).writeByte(value[3]).writeInt(value[4]).writeShort( value[5]) this.client.sendPacket(Identifiers.send.Shop_List, packet.toByteArray())
def sendShamanSkills(this): p = ByteArray().writeByte(len(this.client.playerSkills)) for skill in this.client.playerSkills.items(): p.writeByte(skill[0]).writeByte(skill[1]) p.writeBool(this.client.isSkill) this.client.sendPacket(Identifiers.send.Shaman_Skills, p.toByteArray())
def sendShopList(this, sendItems=True): shopItems = [] if this.client.shopItems == "" else this.client.shopItems.split( ",") packet = ByteArray().writeInt(this.client.shopCheeses).writeInt( this.client.shopFraises).writeUTF(this.client.playerLook).writeInt( len(shopItems)) for item in shopItems: if "_" in item: itemSplited = item.split("_") realItem = itemSplited[0] custom = itemSplited[1] if len(itemSplited) >= 2 else "" realCustom = [] if custom == "" else custom.split("+") packet.writeByte(len(realCustom) + 1).writeInt(int(realItem)) x = 0 while x < len(realCustom): packet.writeInt(int(realCustom[x], 16)) x += 1 else: packet.writeByte(0).writeInt(int(item)) shop = this.server.shopList if sendItems else [] packet.writeInt(len(shop)) for item in shop: value = item.split(",") packet.writeShort(int(value[0])).writeShort(int( value[1])).writeByte(int(value[2])).writeByte( int(value[3])).writeByte(int(value[4])).writeInt( int(value[5])).writeInt(int(value[6])).writeShort(0) looks = [] packet.writeByte(len(looks)) for look in looks: packet.writeShort(look[0]) packet.writeUTF(look[1]) packet.writeByte(look[2]) packet.writeShort(len(this.client.clothes)) for clothe in this.client.clothes: clotheSplited = clothe.split("/") packet.writeUTF(clotheSplited[1] + ";" + clotheSplited[2] + ";" + clotheSplited[3]) shamanItems = [] if this.client.shamanItems == "" else this.client.shamanItems.split( ",") packet.writeShort(len(shamanItems)) for item in shamanItems: if "_" in item: itemSplited = item.split("_") realItem = itemSplited[0] custom = itemSplited[1] if len(itemSplited) >= 2 else "" realCustom = [] if custom == "" else custom.split("+") packet.writeShort(int(realItem)) packet.writeBoolean(item in this.client.shamanLook.split( ",")).writeByte(len(realCustom) + 1) x = 0 while x < len(realCustom): packet.writeInt(int(realCustom[x], 16)) x += 1 else: packet.writeShort(int(item)).writeBoolean( item in this.client.shamanLook.split(",")).writeByte(0) shamanShop = this.server.shamanShopList if sendItems else [] packet.writeShort(len(shamanShop)) for item in shamanShop: value = item.split(",") packet.writeInt(int(value[0])).writeByte(int(value[1])).writeByte( int(value[2])).writeByte(int(value[3])).writeInt(int( value[4])).writeShort(int(value[5])) this.client.sendPacket(Identifiers.send.Shop_List, packet.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'])
def dataReceived(self, data): # 446, 44442, 5557, 3726, 6114 print data if data == "<policy-file-request/>\x00": self.transport.write( """<cross-domain-policy><allow-access-from domain="127.0.0.1" to-ports="443,44444,44440,5555,3724,6112" /></cross-domain-policy>\x00""" ) else: opcode1 = data[4:5] opcode2 = data[5:6] opcodes = bytes([opcode1, opcode2]) data = data[6:len(data)] print repr(opcodes) if opcode1 == "\x1c": if opcode2 == "\x01": #Version p = ByteArray(data) v = p.readInt() print v if v == self.version: #ForaList self.versionValidated = True self.online() self.ForumsList() else: self.transport.connectionLost() elif opcode2 == "\x1c": # Moderating Functions self.RequireLevel(self.userTypeNeededForPeutModerer) p = ByteArray(data) params = p.readUTF().split(",") if params[0] == "[E]renommer_sujet": # Thread Rename thread_id, message_id, new_title = params[ 1], p.readShort(), p.readUTF() dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, message_id, "Konu İsmi", new_title, "Olarak Değiştirildi." ]) dbcur.execute( "UPDATE forum_threads SET topic = ? WHERE thread_id = ?", [new_title, thread_id]) self.openThread(int(thread_id), 0) elif params[0] == "[E]mute": # Kullanıcı susturma mm = int(params[1]) ms = int(params[3]) mn = str(params[2]) fi = int(params[4]) ki = int(params[5]) mi = int(params[6]) p = ByteArray(data.split("\x01")[1]) sebep = p.readUTF() if ms == 0: if mn in om: om.remove(mn) dbcur.execute( "DELETE FROM forum_mute where isim = ?", [mn]) self.message_forum( mn + " Adlı Kullanıcının Mute'si Kaldırıldı.") else: if mm == 1: dbcur.execute( 'select * from forum_mute where isim = ?', [mn]) rrf = dbcur.fetchone() if rrf is None: mod = "isim" if mn in nlol.online: md = "Online" om.append(mn) else: md = "Offline" self.message_forum( mn + " Adlı Kullanıcı " + str(ms) + " Saat Boyunca Mutelendi.") dbcur.execute( "INSERT INTO forum_mute VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [ self.username, mn, fi, ki, mi, sebep, "ip", time.time(), ms, md ]) else: self.message_forum( rrf[1] + " " + rrf[0] + " Tarafından Mutelenmiş Zaten") else: self.message_forum( "Şimdilik Sadece Oyuncu Mutelenebiliyor ^_^" ) elif params[0] == "deplacer_sujet": # Thread Replace thread_id, forum_id = int(params[1]), int(params[2]) dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, "", "Konu " + forum_id + " Forumuna Taşındı." ]) dbcur.execute( "UPDATE forum_threads SET forum_id = ? WHERE thread_id = ?", [forum_id, thread_id]) dbcur.execute( "UPDATE forum_comments SET forum_id = ? WHERE thread_id = ?", [forum_id, thread_id]) self.openForums(forum_id, 0) self.openThread(thread_id, 0) elif self.versionValidated: print opcode1 + " - " + opcode2 if opcode1 == "\x02": if opcode2 == "\x03": # REQUEST_FORUMS_LIST self.online() self.ForumsList() elif opcode2 == "\x04": # REQUEST_THREAD_LIST p = ByteArray(data) forum_id = p.readInt() page = p.readInt() self.forum_id = forum_id self.openForums(forum_id, page) elif opcode2 == "\x05": print "rophl" # REQUEST_MESSAGE_LIST p = ByteArray(data) thread_id = p.readInt() page = p.readShort() self.page = page self.thread_id = thread_id self.openThread(thread_id, page) elif opcode1 == "\x04": if opcode2 == "\x02": # New Thread p = ByteArray(data) forum_id = p.readInt() self.forum_id = forum_id if self.forum_id == 1: self.RequireLevel( self.userTypeNeededForPeutModerer) threadTitle = str(p.readUTF()).decode( 'utf-8', 'replace') message_utf = str(p.readLongString()).decode( 'utf-8', 'replace') dbcur.execute( "INSERT INTO forum_threads VALUES (?, NULL, ?, ?, ?, ?, 0, 0)", [ int(forum_id), threadTitle, str(time.time()).replace('.', '')[:10], self.username, self.username ]) thread_id = dbcur.lastrowid self.thread_id = thread_id dbcur.execute( "INSERT INTO forum_comments VALUES (?, ?, NULL, ?, ?, ?, ?, 0, '', '')", [ int(forum_id), thread_id, self.username, threadTitle, message_utf, str(time.time()).replace('.', '')[:10] ]) self.openForums(self.forum_id, 0) self.openThread(thread_id, 0) elif opcode2 == "\x04": # Repondre Sujet p = ByteArray(data) thread_id = p.readInt() message_utf = str(p.readLongString()).decode( 'utf-8', 'replace') dbcur.execute( "INSERT INTO forum_comments VALUES (?, ?, NULL, ?, ' ', ?, ?, 0, '', '')", [ self.forum_id, thread_id, self.username, message_utf, str(time.time()).replace('.', '')[:10] ]) self.openThread(thread_id, 0) elif opcode2 == "\x06": # Message Edit # needed edit for long string self.RequireLevel(self.userTypeNeededForPeutModerer) p = ByteArray(data) thread_id = p.readInt() message_id = p.readInt() message_utf = str(p.readLongString()).decode( 'utf-8', 'replace') dbcur.execute( "SELECT * FROM forum_comments WHERE thread_id = ? AND message_id = ? AND username = ?", [thread_id, message_id, self.username]) if len(dbcur.fetchall()) == 0: self.RequireLevel( self.userTypeNeededForPeutModerer) dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, message_id, message_utf ]) dbcur.execute( "UPDATE forum_comments SET message = ? WHERE thread_id = ? AND message_id = ?;", [message_utf, thread_id, message_id]) self.openThread(thread_id, 0) elif opcode1 == "\x28": if opcode2 == "\x02": # Auth p = ByteArray(data) username, passwordHash = p.readUTF(), p.readUTF() p = ByteArray("\x28\x02") #print passwordHash valid, forumPriv, validUsername = self.authenticate( username, hashlib.sha512(passwordHash).hexdigest()) p.writeByte(valid) if valid != 0: username = username.lower() username = username.capitalize() dbcur.execute( "SELECT isim FROM forum_sentinel WHERE isim = ?", [username]) sd = dbcur.fetchone() try: za = sd[0] self.sentinel = True forumPriv = 11 except: pass self.username = str(validUsername) self.user_type = forumPriv p.writeUTF(self.username) p.writeInt(10000) p.writeInt(forumPriv) nlol.online.append(self.username) self.login = True self.mc() #Mute Controller self.transport.write(p.toPack()) self.online() elif opcode2 == "\x16": p = ByteArray(data) ri, fa, fi, ti, ci, rml = p.readUTF(), p.readUTF( ), p.readInt(), p.readInt(), p.readInt(), p.readUTF() print ri, fa, fi, ti, ci, rml self.message_forum( "Raporlama Sistemi Daha Hazır Değil ^_^") #### Bu Kod Rapor Kodudur Ancak Daha Bitmemiştir.#### elif opcode2 == "\n": file = open("avatars/" + self.username + ".png", 'wb') file.write(data) file = open("avatars/" + self.username + ".png", 'rb') img = Image.open(file) img.load() img.thumbnail((100, 100), Image.ANTIALIAS) img.save("./avatars/" + self.username + "_Resize.png") data = open("avatars/" + self.username + "_Resize.png", "rb") upload.upload_file(self.username + ".png", data) elif opcode2 == "\x0a": # Avatar Change try: pass ## file = open("avatars/"+self.username+".png", 'wb') ## file.write(data) ## basewidth = 100 ## img = Image.open(StringIO.StringIO(file)) ## wpercent = (basewidth/float(img.size[0])) ## hsize = int((float(img.size[1])*float(wpercent))) ## img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS) ## img.save("avatars/"+self.username+".png") except: pass elif opcode2 == "\x0b": # Close Theme if not self.sentinel: self.RequireLevel( self.userTypeNeededForPeutModerer) else: if not str(self.forum_id) in self.sf: self.RequireLevel( self.userTypeNeededForPeutModerer) p = ByteArray(data) thread_id, closed = p.readInt(), p.readBoolean() dbcur.execute( "SELECT closed FROM forum_threads where thread_id=?", [thread_id]) if int(dbcur.fetchone()[0]) == 0: dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, "", "Konu Kilitlendi." ]) dbcur.execute( "UPDATE forum_threads SET closed=1 WHERE thread_id = ?", [thread_id]) else: dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, "", "Konu Kilidi Kaldırıldı." ]) dbcur.execute( "UPDATE forum_threads SET closed=0 WHERE thread_id = ?", [thread_id]) if closed: dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, "", "Konu Arşive Taşındı." ]) dbcur.execute( "UPDATE forum_threads SET forum_id = ? WHERE thread_id = ?", [611, thread_id]) dbcur.execute( "UPDATE forum_comments SET forum_id = ? WHERE thread_id = ?", [611, thread_id]) self.forum_id = 611 self.openForums(self.forum_id, 0) self.openThread(thread_id, 0) elif opcode2 == "\x0c": # Stick Theme if not self.sentinel: self.RequireLevel( self.userTypeNeededForPeutModerer) else: if not str(self.forum_id) in self.sf: self.RequireLevel( self.userTypeNeededForPeutModerer) p = ByteArray(data) thread_id = p.readInt() dbcur.execute( "SELECT sticky FROM forum_threads where thread_id=?", [thread_id]) if int(dbcur.fetchone()[0]) == 0: dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, "", "Konu Sabitlendi." ]) dbcur.execute( "UPDATE forum_threads SET sticky=1 WHERE thread_id = ?", [thread_id]) else: dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, "", "Konu Sabit'ten Çıkarıldı." ]) dbcur.execute( "UPDATE forum_threads SET sticky=0 WHERE thread_id = ?", [thread_id]) self.openForums(self.forum_id, 0) self.openThread(thread_id, 0) elif opcode2 == "\x0f": # Moderate theme self.RequireLevel(self.userTypeNeededForPeutModerer) p = ByteArray(data) thread_id = p.readInt() message_id = p.readInt() type_modere = p.readInt() comment = p.readUTF() dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [ self.username, self.forum_id, thread_id, message_id, comment ]) if type_modere == 0: # Unsupperme Message dbcur.execute( "UPDATE forum_comments SET deleted=0, nomModerateur='', reason='' WHERE thread_id = ? AND message_id = ?", [thread_id, message_id]) if type_modere == 1: # Supperme Message dbcur.execute( "UPDATE forum_comments SET deleted=1, nomModerateur=?, reason=? WHERE thread_id = ? AND message_id = ?", [ self.username, comment, thread_id, message_id ]) if type_modere == 2: # Delete Message dbcur.execute( "UPDATE forum_comments SET deleted=2, nomModerateur=?, reason=? WHERE thread_id = ? AND message_id = ?", [ self.username, comment, thread_id, message_id ]) self.openForums(self.forum_id, 0) self.openThread(thread_id, 0) elif opcode2 == "\x10": # Moderer > 1 message self.RequireLevel(self.userTypeNeededForPeutModerer) p = ByteArray(data) username = p.readUTF() type_modere = p.readInt() comment = p.readUTF() dbcur.execute( "INSERT INTO forum_log VALUES(?, ?, ?, ?, ?)", [self.username, self.forum_id, "", "", comment]) if type_modere == 0: # Unsupperme Message dbcur.execute( "UPDATE forum_comments SET deleted=0, nomModerateur='', reason='' WHERE username = ?", [username]) if type_modere == 1: # Supperme Message dbcur.execute( "UPDATE forum_comments SET deleted=1, nomModerateur=?, reason=? WHERE username = ?", [self.username, comment, username]) if type_modere == 2: # Delete Message dbcur.execute( "UPDATE forum_comments SET deleted=2, nomModerateur=?, reason=? WHERE username = ?", [self.username, comment, username]) elif opcode2 == "\x17": # Sanctions # In progress... self.message_forum("You has no sanctions.") elif opcode2 == "\x28": # Online threading.Timer(15.0, self.online).start() #self.online() elif opcode1 == "(": print repr(opcode2) print repr(data) else: pass #print repr(data) else: self.transport.connectionLost()
def openForums(self, forum_id, page): if page == -1: page = 0 self.forum_id = forum_id if page != 0: limit1, limit2 = page * 20, page * 40 else: limit1, limit2 = 0, 20 p = ByteArray("\x02\x04") if forum_id == 1: openthread = self.user_type in [17, 18, 14, 20] else: openthread = True if self.username in om: openthread = False if not self.login: openthread = False p.writeBoolean(openthread) # peutCreerSujet # [FORUM INFO] # ###Tribe Forums### if forum_id > 2000: dbcur.execute("SELECT * FROM forum_forums where id = ?", [int(forum_id)]) td = dbcur.fetchone() if not td == None: pass else: dbcur.execute("INSERT INTO forum_forums VALUES (?,?,?)", ["xx", (forum_id), "9"]) dbcur.execute("SELECT * FROM tribu where Code = ?", [int(forum_id) - 2000]) ntd = dbcur.fetchone() p.writeInt(forum_id) p.writeUTF("xx") p.writeShort(9) p.writeByte(False) p.writeUTF(ntd[1], True) dbcur.execute("SELECT * FROM forum_forums where id=?", [forum_id]) forum = dbcur.fetchone() else: dbcur.execute("SELECT * FROM forum_forums where id=?", [forum_id]) forum = dbcur.fetchone() p.writeInt(int(forum[1])) # forumId p.writeUTF(str(forum[0])) # forumCountry p.writeShort(int(forum[2])) # forumIcon p.writeInt(page) # pageCurrent p.writeInt(self.generateThreadsPage(forum_id) + 1) # pageTotal # p.writeBoolean( False) # masquerSujetCourrant # публичный форум : boolean dbcur.execute( "SELECT * FROM forum_threads where forum_id=? ORDER BY sticky DESC, date DESC LIMIT ?, ?", [forum_id, limit1, limit2]) threads = dbcur.fetchall() threadNum = 0 for row in threads: z = row[1] # [InfoServeurSujet] # dbcur.execute( "SELECT * FROM forum_comments where thread_id=? ORDER BY time DESC", [z]) topicLastMessage = dbcur.fetchall()[0] p.writeInt(row[1]) # code p.writeUTF(row[2]) # titre p.writeInt(int(row[3])) # date p.writeUTF(row[4].encode("cp1251")) # auteur p.writeByte(self.getJoueurType( row[4].encode("cp1251"))) # typeAuteur p.writeUTF(topicLastMessage[3].encode("cp1251")) # last_posteur p.writeInt(len(self.getcommentsbythread(row[1], forum[1]))) # numMessage typeThread = 0 if bool(row[7]): typeThread = 2 p.writeByte(typeThread) # type p.writeBoolean(bool(row[6])) # postIt p.writeInt(threadNum) # nombreSignalements threadNum += 1 self.transport.write(p.toPack())