def __init__(self, player: lib.Player): super().__init__() self.player = player self.target = lib.Target() self.bagitem = lib.BagItem(scanItems=True) self.mysql = Mysql().getClient() self.keyrecorder = lib.KeyRecorder()
def get_receive_msg(self, recever): sql = "select * from chat where used=0 and recever='" + recever + "' order by id desc" client = Mysql().getClient() cursor = client.cursor() cursor.execute(sql) msg = cursor.fetchall() client.close() cursor.close() return msg
def flow(db: Mysql, table_name, id_name, funcs: [FuncVoid], exclude_fields=None, database_name=None): source_fields = db.get_table_columns(table_name=table_name, database_name=database_name) fields = source_fields.copy() action = void.Action() for func in funcs: # type:FuncVoid action.add_func(func_object=func) fields.extend(fields) if exclude_fields: fields = list(set(fields) - set(exclude_fields)) else: fields = list(set(fields)) dp = mysql.DataProvide(db=db, table_name=table_name, id_name=id_name, database_name=database_name, fields=fields, read_page_size=2000, last_id=0) process.DispatchCenter.dispatch(dp=dp, actions=[action])
def send_msg(self, myname): receive_msg_data = self.get_receive_msg(myname) if len(receive_msg_data) == 0: print("没有待回复消息") return for data in receive_msg_data: reply_msg = self.get_reply_msg(data) channel = data[4] cmd = "" if channel == 'p': cmd = "/p" elif channel == 'w': cmd = "/w " + data[1] + " " # 选频道 if cmd is not "": self.control.driver.copy_paste_send(cmd, end_enter=True) time.sleep(0.1) # 发消息 if cmd == '/p': self.control.driver.copy_paste_send(reply_msg) else: self.control.driver.copy_paste_send(reply_msg, start_enter=False) # 将被回复消息的used更新为1 sql = "update chat set used=1 where id={a}".format(a=data[0]) Mysql().execute(sql) return True # 一次只说一句
def get_reply_msg(self, receive_msg): reply_content = self.httpPost(receive_msg[3], receive_msg[0]) # 回复消息的内容 sql = "insert into chat (`sender`,`recever`,`msg`,`channel`,`type`,`used`,`ctime`) values ({a},{b},{c},{d},{e},{f},{g})" \ .format( a="'" + receive_msg[2] + "'", # 原消息接收者为消息发送者 b="'" + receive_msg[1] + "'", # 原消息发送者为消息接收者 c="'" + reply_content + "'", d="'" + receive_msg[4] + "'", e=0, f=0, g="'" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time()))) + "'" ) Mysql().execute(sql) return reply_content
def flow(db: Mysql, table_name, tag_table_name, id_name, func: FuncTransfer, fields=None, fields_alias=None, exclude_fields=None, copy_alias=None, is_truncate=True, database_name=None): if fields is None: fields = db.get_table_columns(table_name=table_name, database_name=database_name) action_fields = fields.copy() if exclude_fields: action_fields = list(set(action_fields) - set(exclude_fields)) action = transfer.Action(db=db, table_name=tag_table_name, fields=action_fields, fields_alias=fields_alias, copy_alias=copy_alias, is_truncate=is_truncate, database_name=database_name, size=2000) action.add_func(func_object=func) fields.append(id_name) dp = mysql.DataProvide(db=db, table_name=table_name, id_name=id_name, database_name=database_name, fields=fields, read_page_size=2000, last_id=0) process.DispatchCenter.dispatch(dp=dp, actions=[action])
def hello_wisper(self, myname, recever): msg = self.starter[random.randint(0, len(self.starter) - 2)] cmd = "/w " + recever + " " self.control.driver.copy_paste_send(cmd, end_enter=True) time.sleep(0.5) self.control.driver.copy_paste_send(msg, start_enter=False) sql = "insert into chat (`sender`,`recever`,`msg`,`channel`,`type`,`used`,`ctime`) values ({a},{b},{c},{d},{e},{f},{g})" \ .format( a="'" + myname + "'", # 原消息接收者为消息发送者 b="'" + recever + "'", # 原消息发送者为消息接收者 c="'" + msg + "'", d="'w'", e=0, f=0, g="'" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time()))) + "'" ) Mysql().execute(sql)
def save(self, db: Mysql, table_name, is_truncate=True, is_replace=False): self._compare_diff_columns(db=db, table_name=table_name, df_columns=self._df.columns) data = [] for item in self._df.values: data.append(tuple(item)) if is_truncate: db.truncate(table_name=table_name) if is_replace: db.replace_many(table_name=table_name, fields=list(self._df.columns), data=data) else: db.insert_many(table_name=table_name, fields=list(self._df.columns), data=data) self._state() self._clean() print(f"xlsx import done: {table_name} {len(data)}\n\n")
#!/usr/bin/env python #coding:utf-8 from lib.db.mysql import Mysql hostname = 'http://localhost' debug = False dbuser = '******' dbpass = '******' dbname = 'pbscan' mydb = Mysql(dbuser, dbpass, dbname) scan_rules = { "burp":3, "poc":"sqlmapapi.py" } white_rules = [ ] black_rules = [ '*.baidu.com', '*.google.com', '*.github.com' ]
class Monitor(threading.Thread): def __init__(self, player: lib.Player): super().__init__() self.player = player self.target = lib.Target() self.bagitem = lib.BagItem(scanItems=True) self.mysql = Mysql().getClient() self.keyrecorder = lib.KeyRecorder() def info(self): player = self.player target = self.target bagitem = self.bagitem # 玩家信息 gold = player.getGold() cls = player.getClass() shape = player.getShapeForm() playtime = player.getPlaytime() status = player.getStatus() playerInfo = { "name": player.getName(), "level": player.getLevel(), "map": player.getArea(), "coordi": player.getCoordi().toString(), "life": format(player.getLiftPercent() * 100, '.0f') + "%", "mama": format(player.getManaPercent() * 100, '.0f') + "%", "gold": str(gold["gold"]) + "金" + str(gold['silver']) + "银" + str(gold['copper']) + "铜", # "playtime": str(playtime["hours"]) + "小时", "howManyAreAttackingMe": player.howManyAreAttackingMe(), "status": status } if isinstance(player, lib.Silithus_reputation_player): playerInfo['战地任务次数'] = player.counter if cls == "战士": # 战士 if shape == 1: playerInfo['姿态'] = "战斗姿态" if shape == 2: playerInfo['姿态'] = "防御姿态" if shape == 3: playerInfo['姿态'] = "狂暴姿态" if cls == "盗贼": # 盗贼 if shape == 1: playerInfo['姿态'] = "未潜行" if shape == 2: playerInfo['姿态'] = "潜行" # TODO 小德 牧师 # 目标信息 tt = target.IsTargetOfTargetPlayerAsNumber() tt_mapper = ["我看我", "我", "无目标", "其它", "我宠物"] targetInfo = { "UUID": target.getUUID(), "name": target.getName(), "class": target.getClass(), "level": target.getLevel(), "touchByOther": target.isTouchByAnoter(), "combatPoint": target.getCombatPoints(), "targettarget": "未知" if 0 > tt or tt > 4 else tt_mapper[tt], "life": format(target.getLiftPercent() * 100, ".0f") + "%", "mama": format(target.getManaPercent() * 100, ".0f") + "%", "status": target.getStatus() } ret = { "player": playerInfo, "t": targetInfo, "bag": bagitem.getAllItems() } return json.dumps(ret, ensure_ascii=False) # 键盘按键 def keys(self): return json.dumps(self.keyrecorder.getRecords()) def insert_or_update(self, info, keys): name = self.player.getName() cursor = self.mysql.cursor() if name is not None and name != "": cursor.execute("select id from monitor where `name`=%s", (name)) res = cursor.fetchone() t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time()))) if res is not None and res != 0: sql = "update monitor set `info`=%s,`keys`=%s,`ctime`=%s where id=%s" args = (info, keys, t, res[0]) else: sql = "insert into monitor (`name`,`info`,`keys`,`ctime`) values (%s,%s,%s,%s)" args = [name, info, keys, t] cursor.execute(sql, args) self.mysql.commit() cursor.close() return True return False def run(self) -> None: while True: info = self.info() keys = self.keys() self.insert_or_update(info, keys)
def pull(id): from lib.db.mysql import Mysql import json sql = "select * from AreaInfo where id="+str(id) client = Mysql().getClient() cursor = client.cursor() cursor.execute(sql) ret = cursor.fetchone() cursor.close() client.close() if ret == None: print("没有找到id为="+str(id)+"的数据") return mailbox_pos = json.loads(ret[10]) grave_path_dic = json.loads((ret[12])) repair_path_dic = json.loads((ret[13])) finder_path_dic = json.loads((ret[14])) grave_path = "[\n" for i in grave_path_dic: t = grave_path_dic[i] if i == '0': grave_path = grave_path + " ["+str(t[0])+", "+str(t[1])+", "+str(t[2])+", "+str(t[3])+", "+str(t[4])+", '"+t[5]+"']," else: grave_path = grave_path + "\n ["+str(t[0])+", "+str(t[1])+", "+str(t[2])+", "+str(t[3])+", "+str(t[4])+", '"+t[5]+"']," grave_path = grave_path + "\n ]" repair_path = "[\n" for i in repair_path_dic: t = repair_path_dic[i] if i == '0': repair_path = repair_path + " ["+str(t[0])+", "+str(t[1])+", "+str(t[2])+", "+str(t[3])+", "+str(t[4])+", '"+t[5]+"']," else: repair_path = repair_path + "\n ["+str(t[0])+", "+str(t[1])+", "+str(t[2])+", "+str(t[3])+", "+str(t[4])+", '"+t[5]+"']," repair_path = repair_path + "\n ]" findr_path = "[\n" for i in finder_path_dic: t = finder_path_dic[i] if i == '0': findr_path = findr_path + " [" + str(t[0]) + ", " + str(t[1]) + ", " + str(t[2]) + ", " + str(t[3]) + ", " + str(t[4]) + ", '" + t[5] + "']," else: findr_path = findr_path + "\n [" + str(t[0]) + ", " + str(t[1]) + ", " + str(t[2]) + ", " + str(t[3]) + ", " + str(t[4]) + ", '" + t[5] + "']," finder_path = findr_path + "\n ]" hander = open(SysConfig.record_path + "DynamicConfig.py", "w+", encoding="utf-8") python = "# -*- coding:utf8 -*-\n\n\n" python += "class DynamicConfig:\n" python += " map = \""+ret[1]+"\"\n" python += " level_min = "+str(ret[2])+" # 建议的区域最小等级\n" python += " level_max = "+str(ret[3])+" # 建议的区域最大等级\n" python += " mailbox_pos = ["+str(mailbox_pos['0'])+","+str(mailbox_pos['1'])+"] # 填写邮箱坐标\n" python += " fly_npc_name = \""+ret[4]+"\"\n" python += " fly_npc_gossip = "+str(ret[5])+" # 填写飞行管理员选择飞行点对话索引\n" python += " repair_npc_name = \""+ret[6]+"\"\n" python += " repair_npc_gossip = "+str(ret[7])+" # 填写修理员对话选项索引,如果没有对话选项就填0\n" python += " heartstone_npc_name = \""+ret[8]+"\"\n" python += " memo = \""+ret[9]+"\"\n" python += " area_fighting_pos = "+ret[11]+"# 区域打怪4角坐标\n" python += " grave_path = "+grave_path+"\n" python += " repair_path ="+repair_path+"\n" python += " finder_path ="+finder_path+"\n" print(python, file=hander) print("动态配置文件生成完成,请检查是否正确!")
def commit(self): if not os.path.exists(self.filename): print("配置文件不存在,请先使用create创建配置文件") return from run.record.path_data.DynamicConfig import DynamicConfig from lib.db.mysql import Mysql import json import numpy as np sql = "INSERT INTO AreaInfo (level_min,level_max,fly_npc_name,repair_npc_name,heartstone_npc_name,maibox_pos,area_pos,grave_path,reapir_path,`ctime`,`map`,`memo`,fly_npc_gossip,repair_npc_gossip,finder_path) " \ "VALUES ({a},{b},{c},{d},{e},{f},{g},{h},{i},{j},{k},{l},{m},{n},{o})".format( a=DynamicConfig.level_min, b=DynamicConfig.level_max, c="'" + DynamicConfig.fly_npc_name + "'", d="'" + DynamicConfig.repair_npc_name + "'", e="'" + DynamicConfig.heartstone_npc_name + "'", f="'" + json.dumps(dict(zip([str(x) for x in np.arange(len(DynamicConfig.mailbox_pos))], DynamicConfig.mailbox_pos)),ensure_ascii=False) + "'", g="'" + json.dumps(DynamicConfig.area_fighting_pos,ensure_ascii=False) + "'", h="'" + json.dumps(dict(zip([str(x) for x in np.arange(len(DynamicConfig.grave_path))], DynamicConfig.grave_path)),ensure_ascii=False) + "'", i="'" + json.dumps(dict(zip([str(x) for x in np.arange(len(DynamicConfig.repair_path))], DynamicConfig.repair_path)),ensure_ascii=False) + "'", j="'" + self.getFormatTime(True) + "'", k="'" + DynamicConfig.map + "'", l="'" + DynamicConfig.memo + "'", m=DynamicConfig.fly_npc_gossip, n=DynamicConfig.repair_npc_gossip, o="'" + json.dumps(dict(zip([str(x) for x in np.arange(len(DynamicConfig.finder_path))], DynamicConfig.finder_path)),ensure_ascii=False) + "'", ) #print(sql) client = Mysql().getClient() cursor = client.cursor() try: # 执行sql语句 cursor.execute(sql) # 提交到数据库执行 client.commit() except Exception as e: # 如果发生错误则回滚 client.rollback() client.close() cursor.close() print(e) print("数据提交失败") return # 关闭数据库连接 client.close() cursor.close() print("数据提交成功") return