From f5df50e353e1755eb19f404b37aa0dd9587db3e8 Mon Sep 17 00:00:00 2001 From: NEMESIS13cz Date: Wed, 14 Oct 2015 21:14:40 +0200 Subject: [PATCH 01/10] Added Dico to pythoners --- misc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/misc.py b/misc.py index 5ac4e54..da7e2cc 100644 --- a/misc.py +++ b/misc.py @@ -279,7 +279,8 @@ def eval_thread(sender, code): pythoners = [ "e452e012-2c82-456d-853b-3ac8e6b581f5", # Nemes "ae795aa8-6327-408e-92ab-25c8a59f3ba1", # jomo -"305ccbd7-0589-403e-a45b-d791dcfdee7d" # PanFritz +"305ccbd7-0589-403e-a45b-d791dcfdee7d", # PanFritz +"51f2ad3c-6cc8-40ea-aa2b-f25970316921" # Dico ] @simplecommand("pyeval", From ed27cdf561f2ac4fa35909e689d024a6de04c1fe Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 17:20:17 +0300 Subject: [PATCH 02/10] Added the chat aliasing plugin --- chatalias.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 2 ++ 2 files changed, 102 insertions(+) create mode 100755 chatalias.py diff --git a/chatalias.py b/chatalias.py new file mode 100755 index 0000000..09eaf7e --- /dev/null +++ b/chatalias.py @@ -0,0 +1,100 @@ +# Chat Aliasing plugin by Curs3d # +################################## +# Allows users to alias words, +# so that when they send a +# message in chat, it gets +# replaced by their specified +# word. Configuration of this +# plugin is in the "gnl" +# (general) tag of the JSON +# file named "aliases". The +# file is generated if not +# present. Set values to -1 +# for unlimited values. + +from helpers import * + + +def safe_open_json(): + data = open_json_file("aliases") + if data is None: + data = {"gnl":{"max_len":"35","max_entries":"10"}} + save_json_file("aliases", data) + return data + + +@hook.command("alias", usage = "/ [to_alias] [alias...]", desc = "Aliases words in chat") +def on_alias_command(sender, cmd, label, args): + if not is_player(sender): + msg(sender, "Sorry, Console cannot alias words") + return False + + if len(args) == 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "This is a plugin that allows you to type in chat and have words replaced by other ones automatically!") + msg(sender, "\nCommands:") + msg(sender, "/alias : removes from aliased words. Use * to remove all aliased words.") + msg(sender, "/alias : Will change to in chat") + msg(sender, "\nYour Aliases:") + data = safe_open_json() + try: + for alias, value in data[sender.getName()].items(): + msg(sender, "%s ==> %s" % (alias, value)) + except KeyError: + pass + return True + + elif len(args) == 1: + data = safe_open_json() + if args[0] == "*": + data[sender.getName()].clear() + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "ALL alias data successfuly removed!") + return True + + if data[sender.getName()].pop(args[0], None) is None: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Could not remove: alias not present!") + return True + + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Alias for %s successfuly removed" % args[0]) + return True + + elif len(args) >= 2: + data = safe_open_json() + alias = " ".join(args[1:]) + try: + if len(alias) > int(data["gnl"]["max_len"]) and data["gnl"]["max_len"] > 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Please do not alias long words/sentences.") + return True + + if len(data[sender.getName()]) >= int(data["gnl"]["max_entries"]) and data["gnl"]["max_entries"] > 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "You have reached the maximum amount of alias entries! Sorry!") + return True + except KeyError: + data[sender.getName()] = {} + + data[sender.getName()][args[0]] = alias + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Chat Alias %s ==> %s successfully created!" % (args[0], alias)) + return True + + else: + return False + + + +@hook.event("player.AsyncPlayerChatEvent", "High") +def on_player_chat(e): + if e.isCancelled(): + return + + data = safe_open_json() + for alias, value in data[e.getPlayer().getName()].items(): + e.setMessage(e.getMessage().replace(alias, value)) diff --git a/main.py b/main.py index 65948b8..2138216 100644 --- a/main.py +++ b/main.py @@ -42,6 +42,8 @@ shared["load_modules"] = [ "blockplacemods", # Adds /calc, toggles automatic solving of Math expressions in chat "calc", + # Adds aliasing of chat words + "chatalias", # Plugin to locate laggy chunks. /lc lists chunks with more than n entities "lagchunks", # Adds /report and /rp, Stores reports with time and location From b9293d7be2d595e1da0489024055924b01f531f2 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 17:37:52 +0300 Subject: [PATCH 03/10] Updated event variable --- chatalias.py | 200 +++++++++++++++++++++++++-------------------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/chatalias.py b/chatalias.py index 09eaf7e..3d9cf31 100755 --- a/chatalias.py +++ b/chatalias.py @@ -1,100 +1,100 @@ -# Chat Aliasing plugin by Curs3d # -################################## -# Allows users to alias words, -# so that when they send a -# message in chat, it gets -# replaced by their specified -# word. Configuration of this -# plugin is in the "gnl" -# (general) tag of the JSON -# file named "aliases". The -# file is generated if not -# present. Set values to -1 -# for unlimited values. - -from helpers import * - - -def safe_open_json(): - data = open_json_file("aliases") - if data is None: - data = {"gnl":{"max_len":"35","max_entries":"10"}} - save_json_file("aliases", data) - return data - - -@hook.command("alias", usage = "/ [to_alias] [alias...]", desc = "Aliases words in chat") -def on_alias_command(sender, cmd, label, args): - if not is_player(sender): - msg(sender, "Sorry, Console cannot alias words") - return False - - if len(args) == 0: - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "This is a plugin that allows you to type in chat and have words replaced by other ones automatically!") - msg(sender, "\nCommands:") - msg(sender, "/alias : removes from aliased words. Use * to remove all aliased words.") - msg(sender, "/alias : Will change to in chat") - msg(sender, "\nYour Aliases:") - data = safe_open_json() - try: - for alias, value in data[sender.getName()].items(): - msg(sender, "%s ==> %s" % (alias, value)) - except KeyError: - pass - return True - - elif len(args) == 1: - data = safe_open_json() - if args[0] == "*": - data[sender.getName()].clear() - save_json_file("aliases", data) - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "ALL alias data successfuly removed!") - return True - - if data[sender.getName()].pop(args[0], None) is None: - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "Could not remove: alias not present!") - return True - - save_json_file("aliases", data) - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "Alias for %s successfuly removed" % args[0]) - return True - - elif len(args) >= 2: - data = safe_open_json() - alias = " ".join(args[1:]) - try: - if len(alias) > int(data["gnl"]["max_len"]) and data["gnl"]["max_len"] > 0: - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "Please do not alias long words/sentences.") - return True - - if len(data[sender.getName()]) >= int(data["gnl"]["max_entries"]) and data["gnl"]["max_entries"] > 0: - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "You have reached the maximum amount of alias entries! Sorry!") - return True - except KeyError: - data[sender.getName()] = {} - - data[sender.getName()][args[0]] = alias - save_json_file("aliases", data) - plugin_header(recipient = sender, name = "Chat Alias") - msg(sender, "Chat Alias %s ==> %s successfully created!" % (args[0], alias)) - return True - - else: - return False - - - -@hook.event("player.AsyncPlayerChatEvent", "High") -def on_player_chat(e): - if e.isCancelled(): - return - - data = safe_open_json() - for alias, value in data[e.getPlayer().getName()].items(): - e.setMessage(e.getMessage().replace(alias, value)) +# Chat Aliasing plugin by Curs3d # +################################## +# Allows users to alias words, +# so that when they send a +# message in chat, it gets +# replaced by their specified +# word. Configuration of this +# plugin is in the "gnl" +# (general) tag of the JSON +# file named "aliases". The +# file is generated if not +# present. Set values to -1 +# for unlimited values. + +from helpers import * + + +def safe_open_json(): + data = open_json_file("aliases") + if data is None: + data = {"gnl":{"max_len":"35","max_entries":"10"}} + save_json_file("aliases", data) + return data + + +@hook.command("alias", usage = "/ [to_alias] [alias...]", desc = "Aliases words in chat") +def on_alias_command(sender, cmd, label, args): + if not is_player(sender): + msg(sender, "Sorry, Console cannot alias words") + return False + + if len(args) == 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "This is a plugin that allows you to type in chat and have words replaced by other ones automatically!") + msg(sender, "\nCommands:") + msg(sender, "/alias : removes from aliased words. Use * to remove all aliased words.") + msg(sender, "/alias : Will change to in chat") + msg(sender, "\nYour Aliases:") + data = safe_open_json() + try: + for alias, value in data[sender.getName()].items(): + msg(sender, "%s ==> %s" % (alias, value)) + except KeyError: + pass + return True + + elif len(args) == 1: + data = safe_open_json() + if args[0] == "*": + data[sender.getName()].clear() + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "ALL alias data successfuly removed!") + return True + + if data[sender.getName()].pop(args[0], None) is None: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Could not remove: alias not present!") + return True + + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Alias for %s successfuly removed" % args[0]) + return True + + elif len(args) >= 2: + data = safe_open_json() + alias = " ".join(args[1:]) + try: + if len(alias) > int(data["gnl"]["max_len"]) and data["gnl"]["max_len"] > 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Please do not alias long words/sentences.") + return True + + if len(data[sender.getName()]) >= int(data["gnl"]["max_entries"]) and data["gnl"]["max_entries"] > 0: + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "You have reached the maximum amount of alias entries! Sorry!") + return True + except KeyError: + data[sender.getName()] = {} + + data[sender.getName()][args[0]] = alias + save_json_file("aliases", data) + plugin_header(recipient = sender, name = "Chat Alias") + msg(sender, "Chat Alias %s ==> %s successfully created!" % (args[0], alias)) + return True + + else: + return False + + + +@hook.event("player.AsyncPlayerChatEvent", "High") +def on_player_chat(event): + if event.isCancelled(): + return + + data = safe_open_json() + for alias, value in data[event.getPlayer().getName()].items(): + event.setMessage(event.getMessage().replace(alias, value)) From 28da124088ac754354d4353054003702734d4ff7 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 22:54:44 +0300 Subject: [PATCH 04/10] Changed names to UUID, fixed empty dicts --- chatalias.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/chatalias.py b/chatalias.py index 3d9cf31..ddc45e9 100755 --- a/chatalias.py +++ b/chatalias.py @@ -38,7 +38,7 @@ def on_alias_command(sender, cmd, label, args): msg(sender, "\nYour Aliases:") data = safe_open_json() try: - for alias, value in data[sender.getName()].items(): + for alias, value in data[str(sender.getUniqueId())].items(): msg(sender, "%s ==> %s" % (alias, value)) except KeyError: pass @@ -47,13 +47,13 @@ def on_alias_command(sender, cmd, label, args): elif len(args) == 1: data = safe_open_json() if args[0] == "*": - data[sender.getName()].clear() + del data[str(sender.getUniqueId())] save_json_file("aliases", data) plugin_header(recipient = sender, name = "Chat Alias") msg(sender, "ALL alias data successfuly removed!") return True - if data[sender.getName()].pop(args[0], None) is None: + if data[str(sender.getUniqueId())].pop(args[0], None) is None: plugin_header(recipient = sender, name = "Chat Alias") msg(sender, "Could not remove: alias not present!") return True @@ -72,14 +72,14 @@ def on_alias_command(sender, cmd, label, args): msg(sender, "Please do not alias long words/sentences.") return True - if len(data[sender.getName()]) >= int(data["gnl"]["max_entries"]) and data["gnl"]["max_entries"] > 0: + if len(data[str(sender.getUniqueId())]) >= int(data["gnl"]["max_entries"]) and data["gnl"]["max_entries"] > 0: plugin_header(recipient = sender, name = "Chat Alias") msg(sender, "You have reached the maximum amount of alias entries! Sorry!") return True except KeyError: - data[sender.getName()] = {} + data[str(sender.getUniqueId())] = {} - data[sender.getName()][args[0]] = alias + data[str(sender.getUniqueId())][args[0]] = alias save_json_file("aliases", data) plugin_header(recipient = sender, name = "Chat Alias") msg(sender, "Chat Alias %s ==> %s successfully created!" % (args[0], alias)) @@ -96,5 +96,5 @@ def on_player_chat(event): return data = safe_open_json() - for alias, value in data[event.getPlayer().getName()].items(): + for alias, value in data[str(event.getPlayer().getUniqueId())].items(): event.setMessage(event.getMessage().replace(alias, value)) From b8ab9a2fc7a828fafb3f4009ae31355dbdaaa8d0 Mon Sep 17 00:00:00 2001 From: PixelSergey Date: Fri, 16 Oct 2015 23:32:19 +0300 Subject: [PATCH 05/10] Added permission check, fixed negative setting --- chatalias.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/chatalias.py b/chatalias.py index ddc45e9..9eb8037 100755 --- a/chatalias.py +++ b/chatalias.py @@ -10,7 +10,7 @@ # file named "aliases". The # file is generated if not # present. Set values to -1 -# for unlimited values. +# for "unlimited" setting. from helpers import * @@ -25,9 +25,14 @@ def safe_open_json(): @hook.command("alias", usage = "/ [to_alias] [alias...]", desc = "Aliases words in chat") def on_alias_command(sender, cmd, label, args): + if not is_player(sender): msg(sender, "Sorry, Console cannot alias words") - return False + return True + + if not sender.hasPermission("utils.alias.allowed"): + plugin_header(recipient = sender, name = "Chat Alias") + noperm(sender) if len(args) == 0: plugin_header(recipient = sender, name = "Chat Alias") @@ -67,12 +72,12 @@ def on_alias_command(sender, cmd, label, args): data = safe_open_json() alias = " ".join(args[1:]) try: - if len(alias) > int(data["gnl"]["max_len"]) and data["gnl"]["max_len"] > 0: + if len(alias) > int(data["gnl"]["max_len"]) and int(data["gnl"]["max_len"]) >= 0: plugin_header(recipient = sender, name = "Chat Alias") msg(sender, "Please do not alias long words/sentences.") return True - if len(data[str(sender.getUniqueId())]) >= int(data["gnl"]["max_entries"]) and data["gnl"]["max_entries"] > 0: + if len(data[str(sender.getUniqueId())]) >= int(data["gnl"]["max_entries"]) and int(data["gnl"]["max_entries"]) >= 0: plugin_header(recipient = sender, name = "Chat Alias") msg(sender, "You have reached the maximum amount of alias entries! Sorry!") return True From 2811f74888e2cc5f759e455a605549ea9e43a551 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 18 Oct 2015 01:33:03 +0300 Subject: [PATCH 06/10] Fixed missing return statement --- chatalias.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chatalias.py b/chatalias.py index 9eb8037..69ac343 100755 --- a/chatalias.py +++ b/chatalias.py @@ -33,6 +33,7 @@ def on_alias_command(sender, cmd, label, args): if not sender.hasPermission("utils.alias.allowed"): plugin_header(recipient = sender, name = "Chat Alias") noperm(sender) + return True if len(args) == 0: plugin_header(recipient = sender, name = "Chat Alias") From 9a93cd3203d1f515b1ce518ccc7e0c841088f09b Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 15:36:08 +0200 Subject: [PATCH 07/10] Added two functions for the iptracker --- helpers.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/helpers.py b/helpers.py index 4aba904..0cb7cbc 100644 --- a/helpers.py +++ b/helpers.py @@ -255,4 +255,27 @@ def toggle(player, ls, name = "Toggle", add = None): msg(player, "&a%s turned off!" % name) elif add != False: ls.append(pid) - msg(player, "&a%s turned on!" % name) \ No newline at end of file + msg(player, "&a%s turned on!" % name) + +def send_JSON_message(playername, message): + bukkit.Bukkit.getServer().dispatchCommand(bukkit.Bukkit.getServer().getConsoleSender(), "tellraw " + playername + " " + message) + + +def isIP(tocheck): + subsets = ["","","",""] + i = 0 + for j in range(0,len(tocheck)): + if not (tocheck[j] in "0123456789."): + return False + elif tocheck[j] == ".": + i += 1 + if (i >= 4): + return False + else: + subsets[i] += tocheck[j] + if not (i == 3): + return False + for j in range(0,3): + if not ((int(subsets[j]) >= 0) & (int(subsets[j]) <= 255)): + return False + return True From d2204d9706f929d71becdd428ac6604c11bfd568 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 15:36:50 +0200 Subject: [PATCH 08/10] Initial iptracker commit allowing username - IP lookups and vice versa --- iptracker.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 iptracker.py diff --git a/iptracker.py b/iptracker.py new file mode 100644 index 0000000..824f829 --- /dev/null +++ b/iptracker.py @@ -0,0 +1,95 @@ +import mysqlhack +import org.bukkit as bukkit +import json +from java.util import UUID as UUID +from helpers import * +from org.bukkit import * +from traceback import format_exc as trace + +iptrack_permission = "utils.iptrack" + + +@hook.event("player.PlayerJoinEvent", "low") +def on_player_join(event): + try: + player = event.getPlayer() + ip = player.getAddress().getHostString() + uuid = uid(player) + 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, )) + results = curs.fetchall() + if len(results) == 0: + 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: + 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() + conn.close() + + +@hook.command("getinfo") +def on_getinfo_command(sender, args): + try: + if(sender.hasPermission(iptrack_permission)): + if not checkargs(sender, args, 1, 1): + 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: + noperm(sender) + return True + except: + error(trace()) From 70662bdd0b006642466adec9c92a0f08b1744f10 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 15:37:17 +0200 Subject: [PATCH 09/10] Added support for an infinite amount of mentio keywords --- mentio.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mentio.py b/mentio.py index dbcd4ce..936b424 100644 --- a/mentio.py +++ b/mentio.py @@ -4,7 +4,7 @@ from traceback import format_exc as print_traceback mentions = open_json_file("mentio", {}) # contains a list of keywords for each player (uuid) -max_amount = 3 +max_amount = -1 arrow = colorify(u"&r&7\u2192&r") colors_reg = reg_compile(u"\u00A7[\\da-fk-or]") # finds color codes @@ -70,7 +70,7 @@ def add_keyword(sender, args): keywords = get_keywords(sender) new_word = stripcolors(args[1].lower()) - if len(keywords) >= max_amount: + if (len(keywords) >= max_amount) and (max_amount >= 0): msg(sender, "&cYou are already listening for %s words! Try &6/mentio del " % max_amount) return True @@ -146,4 +146,4 @@ def onListenCommand(sender, command, label, args): show_help(sender) else: show_help(sender) - return True \ No newline at end of file + return True From fbbbad1853ac7bd377fa68b374bf40caa72e7432 Mon Sep 17 00:00:00 2001 From: Pepich Date: Sun, 18 Oct 2015 16:06:09 +0200 Subject: [PATCH 10/10] added console support and fixed a small cosmetic bug --- iptracker.py | 146 +++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/iptracker.py b/iptracker.py index 824f829..a25dcce 100644 --- a/iptracker.py +++ b/iptracker.py @@ -11,85 +11,85 @@ iptrack_permission = "utils.iptrack" @hook.event("player.PlayerJoinEvent", "low") def on_player_join(event): - try: - player = event.getPlayer() - ip = player.getAddress().getHostString() - uuid = uid(player) - 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, )) - results = curs.fetchall() - if len(results) == 0: - ips = [] + player = event.getPlayer() + ip = player.getAddress().getHostString() + uuid = uid(player) + 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, )) + results = curs.fetchall() + if len(results) == 0: + 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: - ips = json.loads(results[0][0]) - curs.execute("SELECT uuids FROM iptrack_iptouuids WHERE ip = ?", (ip, )) - results = curs.fetchall() - if len(results) == 0: - uuids = [] + 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: - 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: - 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.execute("UPDATE iptrack_iptouuids SET uuids = ? WHERE uuid = ?", (ip, json.dumps(uuids), )) + conn.commit() curs.close() conn.close() @hook.command("getinfo") def on_getinfo_command(sender, args): - try: - if(sender.hasPermission(iptrack_permission)): - if not checkargs(sender, args, 1, 1): - 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"}]}}}]') + if(sender.hasPermission(iptrack_permission)): + if not checkargs(sender, args, 1, 1): + return false else: - noperm(sender) - return True - except: - error(trace()) + 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])) + 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