added console support and fixed a small cosmetic bug
This commit is contained in:
146
iptracker.py
146
iptracker.py
@@ -11,85 +11,85 @@ iptrack_permission = "utils.iptrack"
|
|||||||
|
|
||||||
@hook.event("player.PlayerJoinEvent", "low")
|
@hook.event("player.PlayerJoinEvent", "low")
|
||||||
def on_player_join(event):
|
def on_player_join(event):
|
||||||
try:
|
player = event.getPlayer()
|
||||||
player = event.getPlayer()
|
ip = player.getAddress().getHostString()
|
||||||
ip = player.getAddress().getHostString()
|
uuid = uid(player)
|
||||||
uuid = uid(player)
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
curs = conn.cursor()
|
||||||
curs = conn.cursor()
|
curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid, ))
|
||||||
curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid, ))
|
results = curs.fetchall()
|
||||||
results = curs.fetchall()
|
if len(results) == 0:
|
||||||
if len(results) == 0:
|
ips = []
|
||||||
ips = []
|
else:
|
||||||
|
ips = json.loads(results[0][0])
|
||||||
|
curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (ip, ))
|
||||||
|
results = curs.fetchall()
|
||||||
|
if len(results) == 0:
|
||||||
|
uuids = []
|
||||||
|
else:
|
||||||
|
uuids = json.loads(results[0][0])
|
||||||
|
new_ip_entry = (len(ips) == 0)
|
||||||
|
new_uuid_entry = (len(uuids) == 0)
|
||||||
|
if ip not in ips:
|
||||||
|
ips.append(ip)
|
||||||
|
if new_ip_entry:
|
||||||
|
curs.execute("INSERT INTO iptrack_uuidtoips VALUES (?,?)", (uuid, json.dumps(ips), ))
|
||||||
else:
|
else:
|
||||||
ips = json.loads(results[0][0])
|
curs.execute("UPDATE iptrack_uuidtoips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), ))
|
||||||
curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (ip, ))
|
if uuid not in uuids:
|
||||||
results = curs.fetchall()
|
uuids.append(uuid)
|
||||||
if len(results) == 0:
|
if new_uuid_entry:
|
||||||
uuids = []
|
curs.execute("INSERT INTO iptrack_iptouuids VALUES (?,?)", (ip, json.dumps(uuids), ))
|
||||||
else:
|
else:
|
||||||
uuids = json.loads(results[0][0])
|
curs.execute("UPDATE iptrack_iptouuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), ))
|
||||||
new_ip_entry = (len(ips) == 0)
|
conn.commit()
|
||||||
new_uuid_entry = (len(uuids) == 0)
|
|
||||||
if ip not in ips:
|
|
||||||
ips.append(ip)
|
|
||||||
if new_ip_entry:
|
|
||||||
curs.execute("INSERT INTO iptrack_uuidtoips VALUES (?,?)", (uuid, json.dumps(ips), ))
|
|
||||||
else:
|
|
||||||
curs.execute("UPDATE iptrack_uuidtoips SET ips = ? WHERE uuid = ?", (uuid, json.dumps(ips), ))
|
|
||||||
if uuid not in uuids:
|
|
||||||
uuids.append(uuid)
|
|
||||||
if new_uuid_entry:
|
|
||||||
curs.execute("INSERT INTO iptrack_iptouuids VALUES (?,?)", (ip, json.dumps(uuids), ))
|
|
||||||
else:
|
|
||||||
curs.execute("UPDATE iptrack_iptouuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), ))
|
|
||||||
conn.commit()
|
|
||||||
except:
|
|
||||||
error(trace())
|
|
||||||
curs.close()
|
curs.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
@hook.command("getinfo")
|
@hook.command("getinfo")
|
||||||
def on_getinfo_command(sender, args):
|
def on_getinfo_command(sender, args):
|
||||||
try:
|
if(sender.hasPermission(iptrack_permission)):
|
||||||
if(sender.hasPermission(iptrack_permission)):
|
if not checkargs(sender, args, 1, 1):
|
||||||
if not checkargs(sender, args, 1, 1):
|
return false
|
||||||
return false
|
|
||||||
else:
|
|
||||||
if isIP(args[0]):
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (args[0], ))
|
|
||||||
results = curs.fetchall()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
if len(results) == 0:
|
|
||||||
msg(sender, "IP " + args[0] + " is not registered in the database, maybe you got a number wrong?")
|
|
||||||
else:
|
|
||||||
uuids = json.loads(results[0][0])
|
|
||||||
msg(sender, "IP " + args[0] + " was seen with " + str(len(uuids)) + " different Accounts:")
|
|
||||||
for i in range(0, len(uuids)):
|
|
||||||
p=Bukkit.getOfflinePlayer(UUID.fromString(uuids[i]))
|
|
||||||
send_JSON_message(sender.getName(), '["",{"text":"' + p.getName() + ' - (uuid: ' + uuids[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + p.getName() + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for ' + p.getName() + ' in the database, simply click the name!","color":"gold"}]}}}]')
|
|
||||||
else:
|
|
||||||
target = Bukkit.getOfflinePlayer(args[0])
|
|
||||||
uuid = target.getUniqueId()
|
|
||||||
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
|
||||||
curs = conn.cursor()
|
|
||||||
curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid.toString(), ))
|
|
||||||
results = curs.fetchall()
|
|
||||||
curs.close()
|
|
||||||
conn.close()
|
|
||||||
if len(results) == 0:
|
|
||||||
msg(sender, "Player " + args[0] + " is not registered in the database, maybe you misspelled the name?")
|
|
||||||
else:
|
|
||||||
ips = json.loads(results[0][0])
|
|
||||||
msg(sender, "Player " + sender.getName() + " was seen with " + str(len(ips)) + " different IPs:")
|
|
||||||
for i in range(0, len(ips)):
|
|
||||||
send_JSON_message(sender.getName(), '["",{"text":"' + ips[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + ips[i] + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for the IP ' + ips[i] + ' in the database, simply click the IP!","color":"gold"}]}}}]')
|
|
||||||
else:
|
else:
|
||||||
noperm(sender)
|
if isIP(args[0]):
|
||||||
return True
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
except:
|
curs = conn.cursor()
|
||||||
error(trace())
|
curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (args[0], ))
|
||||||
|
results = curs.fetchall()
|
||||||
|
curs.close()
|
||||||
|
conn.close()
|
||||||
|
if len(results) == 0:
|
||||||
|
msg(sender, "IP " + args[0] + " is not registered in the database, maybe you got a number wrong?")
|
||||||
|
else:
|
||||||
|
uuids = json.loads(results[0][0])
|
||||||
|
msg(sender, "IP " + args[0] + " was seen with " + str(len(uuids)) + " different Accounts:")
|
||||||
|
for i in range(0, len(uuids)):
|
||||||
|
p=Bukkit.getOfflinePlayer(UUID.fromString(uuids[i]))
|
||||||
|
if is_player(sender):
|
||||||
|
send_JSON_message(sender.getName(), '["",{"text":"' + p.getName() + ' - (uuid: ' + uuids[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + p.getName() + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for ' + p.getName() + ' in the database, simply click the name!","color":"gold"}]}}}]')
|
||||||
|
else:
|
||||||
|
msg(sender,p.getName() + " - (uuid: " + uuids[i] + ")")
|
||||||
|
else:
|
||||||
|
target = Bukkit.getOfflinePlayer(args[0])
|
||||||
|
uuid = target.getUniqueId()
|
||||||
|
conn = zxJDBC.connect(mysql_database, mysql_user, mysql_pass, "com.mysql.jdbc.Driver")
|
||||||
|
curs = conn.cursor()
|
||||||
|
curs.execute("SELECT ips FROM iptrack_uuidtoips WHERE uuid = ?", (uuid.toString(), ))
|
||||||
|
results = curs.fetchall()
|
||||||
|
curs.close()
|
||||||
|
conn.close()
|
||||||
|
if len(results) == 0:
|
||||||
|
msg(sender, "Player " + args[0] + " is not registered in the database, maybe you misspelled the name?")
|
||||||
|
else:
|
||||||
|
ips = json.loads(results[0][0])
|
||||||
|
msg(sender, "Player " + args[0] + " was seen with " + str(len(ips)) + " different IPs:")
|
||||||
|
for i in range(0, len(ips)):
|
||||||
|
if is_player(sender):
|
||||||
|
send_JSON_message(sender.getName(), '["",{"text":"' + ips[i] + '","color":"gold","clickEvent":{"action":"run_command","value":"/getinfo ' + ips[i] + '"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"To search for the IP ' + ips[i] + ' in the database, simply click the IP!","color":"gold"}]}}}]')
|
||||||
|
else:
|
||||||
|
msg(sender,ips[i])
|
||||||
|
else:
|
||||||
|
noperm(sender)
|
||||||
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user