Initial Release of IGNCore version 2.5

This commit is contained in:
2021-08-09 13:18:56 +02:00
commit a83d98c47e
910 changed files with 224171 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
{
"list_blob": {
"en_US": [
"<pagebreak>Name: <highlight>{char}</highlight>\n",
"Added: <highlight>{added_time}</highlight>\n",
"By: <highlight>{banner}</highlight>\n",
"Ends: <highlight>{end_time}</highlight>{left}\n",
"Reason: <highlight>{reason}</highlight>\n\n"
],
"de_DE": [
"<pagebreak>Name: <highlight>{char}</highlight>\n",
"Hinzugefuegt: <highlight>{added_time}</highlight>\n",
"Von: <highlight>{banner}</highlight>\n",
"Endet: <highlight>{end_time}</highlight>{left}\n",
"Grund: <highlight>{reason}</highlight>\n\n"
]
},
"list": {
"en_US": "Ban List ({amount})"
},
"not_banned": {
"en_US": "<highlight>{char}</highlight> is not banned.",
"de_DE": "<highlight>{char}</highlight> ist nicht gebannt."
},
"unbanned_target": {
"en_US": "You have been unbanned by <highlight>{char}</highlight>.",
"de_DE": "Du wurdest von <highlight>{char}</highlight> entbannt."
},
"unbanned_self": {
"en_US": "<highlight>{char}</highlight> has been removed from the ban list.",
"de_DE": "Du hast <highlight>{char}</highlight> entbannt."
},
"already_banned": {
"en_US": "<highlight>{char}</highlight> is already banned.",
"de_DE": "<highlight>{char}</highlight> ist bereits gebannt."
},
"banned_target_1": {
"en_US": "You have been banned by <highlight>{banner}</highlight> for reason: <highlight>{reason}</highlight>. Duration: <highlight>{duration}</highlight>.",
"de_DE": "Du wurdest von <highlight>{banner}</highlight> gebannt. Dauer: <highlight>{duration}</highlight>. Der Grund war: <highlight>{reason}</highlight>"
},
"banned_target_2": {
"en_US": "You have been banned by <highlight>{banner}</highlight>. Duration: <highlight>{duration}</highlight>.",
"de_DE": "Du wurdest von <highlight>{banner}</highlight> gebannt - Dauer: <highlight>{duration}</highlight> gebannt."
},
"banned_self": {
"en_US": "<highlight>{char}</highlight> has been added to the ban list.",
"de_DE": "<highlight>{char}</highlight> wurde gebannt."
}
}
+79
View File
@@ -0,0 +1,79 @@
import hjson
from core.aochat.BaseModule import BaseModule
from core.chat_blob import ChatBlob
from core.command_param_types import Any, Const, Options, Time, Character
from core.db import DB
from core.decorators import instance, command
from core.lookup.character_service import CharacterService
from core.translation_service import TranslationService
from core.tyrbot import Tyrbot
from modules.core.ban.ban_service import BanService
@instance()
class BanController(BaseModule):
# noinspection DuplicatedCode
def inject(self, registry):
self.bot: Tyrbot = registry.get_instance("bot")
self.db: DB = registry.get_instance("db")
self.text = registry.get_instance("text")
self.util = registry.get_instance("util")
self.ban_service: BanService = registry.get_instance("ban_service")
self.command_alias_service = registry.get_instance("command_alias_service")
self.ts: TranslationService = registry.get_instance("translation_service")
self.character_service: CharacterService = registry.get_instance("character_service")
self.getresp = self.ts.get_response
def start(self):
self.command_alias_service.add_alias("unban", "ban rem")
self.ts.register_translation("module/ban", self.load_ban_msg)
def load_ban_msg(self):
with open("modules/core/ban/ban.msg", mode="r", encoding="UTF-8") as f:
return hjson.load(f)
@command(command="ban", params=[Const("list", is_optional=True)], access_level="moderator",
description="Show the ban list")
def ban_list_cmd(self, _, _1):
query = self.db.query("SELECT a.*, p.*, b.reason, b.finished_at, b.created_at, b.sender_char_id from account a "
"left join player p on a.char_id = p.char_id "
"left join ban_list b on a.char_id = b.char_id "
"where main=a.char_id "
"and disabled=1 "
"and p.org_id NOT IN (SELECT org_id from ban_org_list)")
blob = ""
for row in query:
ends = "never" if (row.finished_at or -1) == -1 else self.util.format_datetime(row.finished_at)
blob += f"<highlight>{row.name}</highlight> by " \
f"{self.character_service.resolve_char_to_name(row.sender_char_id or self.bot.get_char_id())}\n"
if row.sender_char_id != 0 and row.sender_char_id is not None:
blob += f"<tab>Added at: <highlight>{self.util.format_datetime(row.created_at)}</highlight> " \
f"Ends: <highlight>{ends}</highlight>\n"
blob += f"<tab>Reason: {row.reason or 'None given'}\n"
blob += "\n"
return ChatBlob("Banned Accounts", blob)
@command(command="ban", params=[Options(["rem", "remove"]), Character("character")], access_level="moderator",
description="Remove a character from the ban list")
def ban_remove_cmd(self, _, _1, char):
if not char.char_id:
return self.getresp("global", "char_not_found", {"char": char.name})
elif not self.ban_service.get_ban(char.char_id):
return self.getresp("module/ban", "not_banned", {"char": char.name})
else:
self.ban_service.remove_ban(char.char_id)
return self.getresp("module/ban", "unbanned_self", {"char": char.name})
@command(command="ban",
params=[Const("add", is_optional=True), Character("character"), Time("duration", is_optional=True),
Any("reason", is_optional=True)], access_level="moderator",
description="Add a character to the ban list")
def ban_add_cmd(self, request, _, char, duration, reason):
if not char.char_id:
return self.getresp("global", "char_not_found", {"char": char.name})
elif self.ban_service.get_ban(char.char_id):
return f"<highlight>{char.name}</highlight> is already banned."
else:
self.ban_service.add_ban(char.char_id, request.sender.char_id, duration, reason)
request.reply(f"<highlight>{char.name}</highlight> has been added to the ban list.")
+101
View File
@@ -0,0 +1,101 @@
import time
from core.decorators import instance
from core.dict_object import DictObject
from core.logger import Logger
from modules.core.accounting.services.account_service import AccountService
@instance()
class BanService:
BAN_ADDED_EVENT = "ban_added"
BAN_REMOVED_EVENT = "ban_removed"
def __init__(self):
self.logger = Logger(__name__)
def inject(self, registry):
self.db = registry.get_instance("db")
self.event_service = registry.get_instance("event_service")
self.command_service = registry.get_instance("command_service")
self.account_service: AccountService = registry.get_instance("account_service")
def pre_start(self):
self.db.exec("CREATE TABLE IF NOT EXISTS ban_list (char_id INT NOT NULL, "
"sender_char_id INT NOT NULL, "
"created_at INT NOT NULL, "
"finished_at INT NOT NULL, "
"reason VARCHAR(255) NOT NULL, "
"ended_early SMALLINT NOT NULL, "
"INDEX `char_id` (`char_id`) USING BTREE, "
"INDEX `sender_char_id` (`sender_char_id`) USING BTREE)")
self.db.exec("CREATE TABLE IF NOT EXISTS ban_org_list (org_id INT NOT NULL, "
"sender_char_id INT NOT NULL, "
"created_at INT NOT NULL, "
"finished_at INT NOT NULL, "
"reason VARCHAR(255) NOT NULL, "
"ended_early SMALLINT NOT NULL, "
"INDEX `org_id` (`org_id`) USING BTREE, "
"INDEX `sender_char_id` (`sender_char_id`) USING BTREE)")
self.event_service.register_event_type(self.BAN_ADDED_EVENT)
self.event_service.register_event_type(self.BAN_REMOVED_EVENT)
def start(self):
self.command_service.register_command_pre_processor(self.check_for_banned)
def add_ban(self, char_id, sender_char_id, duration=None, reason=None):
reason = reason or ""
t = int(time.time())
if duration:
finished_at = t + duration
else:
finished_at = -1
num_rows = self.db.exec("INSERT INTO ban_list (char_id, sender_char_id, created_at, "
"finished_at, reason, ended_early) VALUES (?, ?, ?, ?, ?, 0)",
[char_id, sender_char_id, t, finished_at, reason])
if num_rows:
self.account_service.create_users([(char_id, char_id, 0, time.time(), time.time())])
self.db.exec("UPDATE account set disabled=1 where main=(SELECT main from account where char_id=?)",
[char_id])
self.event_service.fire_event(self.BAN_ADDED_EVENT, DictObject({"char_id": char_id,
"sender_char_id": sender_char_id,
"duration": duration,
"reason": reason}))
return num_rows
def remove_ban(self, char_id):
t = int(time.time())
num_rows = self.db.exec("UPDATE ban_list SET ended_early = 1 "
"WHERE char_id = ? AND (finished_at > ? OR finished_at = -1)", [char_id, t])
if num_rows:
self.db.exec("UPDATE account SET disabled = 0 "
"WHERE main = (SELECT main from account where char_id=?)", [char_id])
self.event_service.fire_event(self.BAN_REMOVED_EVENT, DictObject({"char_id": char_id}))
return num_rows
def get_ban(self, char_id):
return self.db.query_single("SELECT * FROM account "
"WHERE char_id = (SELECT main from account where char_id=?) and disabled=1",
[char_id])
def get_ban_list(self):
t = int(time.time())
return self.db.query("SELECT b.*, COALESCE(p1.name, b.char_id) AS name, p2.name AS sender_name FROM ban_list b "
"LEFT JOIN player p1 ON b.char_id = p1.char_id "
"LEFT JOIN player p2 ON b.sender_char_id = p2.char_id "
"WHERE ended_early != 1 AND (finished_at > ? OR finished_at = -1) "
"ORDER BY b.created_at DESC", [t])
def check_for_banned(self, context):
char_id = context.char_id
if self.get_ban(char_id):
# do nothing if character is banned
self.logger.info("ignoring banned character %d for command '%s'" % (char_id, context.message))
return False
else:
return True
+172
View File
@@ -0,0 +1,172 @@
import time
import hjson
import requests
from core.aochat.BaseModule import BaseModule
from core.chat_blob import ChatBlob
from core.command_param_types import Any, Const, Options, Int
from core.db import DB
from core.decorators import instance, command, timerevent
from core.logger import Logger
from core.lookup.character_service import CharacterService
from core.lookup.org_pork_service import OrgPorkService
from core.private_channel_service import PrivateChannelService
from core.translation_service import TranslationService
from core.tyrbot import Tyrbot
from modules.core.accounting.services.account_service import AccountService
from modules.core.ban.ban_service import BanService
@instance()
class OrgBanController(BaseModule):
single_org_uri = "https://people.anarchy-online.com/org/stats/d/5/name/%d/basicstats.xml?data_type=json"
def __init__(self):
self.logger = Logger(__name__)
def inject(self, registry):
self.bot: Tyrbot = registry.get_instance("bot")
self.db: DB = registry.get_instance("db")
self.text = registry.get_instance("text")
self.util = registry.get_instance("util")
self.ban_service: BanService = registry.get_instance("ban_service")
self.command_alias_service = registry.get_instance("command_alias_service")
self.ts: TranslationService = registry.get_instance("translation_service")
self.character_service: CharacterService = registry.get_instance("character_service")
self.pork: OrgPorkService = registry.get_instance("character_service")
self.getresp = self.ts.get_response
self.account_service: AccountService = registry.get_instance("account_service")
self.priv: PrivateChannelService = registry.get_instance("private_channel_service")
def start(self):
self.ts.register_translation("module/ban", self.load_ban_msg)
def load_ban_msg(self):
with open("modules/core/ban/ban.msg", mode="r", encoding="UTF-8") as f:
return hjson.load(f)
@command(command="orgban", params=[Const("list", is_optional=True)], access_level="admin",
description="Show the ban list")
def ban_list_cmd(self, _, _1):
query = self.db.query("SELECT * from ban_org_list b "
"left join all_orgs a on a.org_id = b.org_id")
blob = ""
for row in query:
blob += f"<highlight>{row.org_name}</highlight> (<highlight>{row.org_id}</highlight> " \
f"with <highlight>{row.member_count}</highlight> members) by " \
f"{self.character_service.resolve_char_to_name(row.sender_char_id)}\n"
if row.sender_char_id != 0 and row.sender_char_id is not None:
blob += f"<tab>Added at: <highlight>{self.util.format_datetime(row.created_at)}</highlight>\n"
blob += f"<tab>Reason: {row.reason or 'None given'}\n"
blob += "\n"
return ChatBlob("Banned Organisations", blob)
@command(command="orgban", params=[Options(["rem", "remove"]), Int("Organisation")], access_level="admin",
description="Remove an org from the ban list")
def ban_remove_cmd(self, _, _1, org):
if self.db.query("SELECT * from ban_org_list where org_id=?", [org]):
self.db.exec("DELETE FROM ban_org_list where org_id = ?", [org])
return f"Successfully unbanned org <highlight>{org}</highlight> - " \
f"Beware, all players are still banned using an account ban; " \
f"It can be lifted using !account add <name>"
@command(command="orgban", params=[Options(["rem", "remove"]), Any("Organisation")], access_level="admin",
description="Remove an org from the ban list")
def ban_remove_cmd_name(self, request, _, org: str):
orgs = self.db.query(
"SELECT * from all_orgs where org_name LIKE ? and org_id in (SELECT org_id from ban_org_list)",
["%" + org.replace(" ", "%") + "%"])
if len(orgs) == 1:
self.ban_remove_cmd(request, _, orgs[0].org_id)
elif len(orgs) == 0:
return "No orgs matching your search found."
elif len(orgs) > 1:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += "[%s] <highlight>%s<end> (<highlight>%s<end>) <%s>%s<end> [<highlight>%s<end> " \
"members]<br><pagebreak>" \
% (self.text.make_chatcmd("Unban", "/tell <myname> orgban remove %s" % org.org_id),
# self.text.make_chatcmd("More", "/tell <myname> org info %s" % org.org_id),
org.org_name, org.org_id, org.faction.lower(), org.faction, org.member_count)
return ChatBlob("Pick an Org", blob)
@command(command="orgban", params=[Const("add", is_optional=True), Int("Organisation"),
Any("reason", is_optional=True)], access_level="admin",
description="Add an org to the ban list")
def ban_add_cmd(self, request, _, org, reason):
if self.db.query("SELECT * from ban_org_list where org_id=?", [org]):
return f"Organisation with the ID <highlight>{org}</highlight> is already banned."
if self.db.exec(
"INSERT INTO ban_org_list(org_id, sender_char_id, created_at, finished_at, reason, ended_early) "
"VALUES (?, ?, ?, 0, ?, 0)",
[org, request.sender.char_id, time.time(), reason or ""]):
self.fetch_single(org, request)
# return f"Organisation with the ID <highlight>{org}</highlight> has been banned."
@command(command="orgban",
params=[Options(["add"], is_optional=True), Any("Organisation")],
access_level="admin",
description="Add an org from the ban list")
def ban_add_cmd_name(self, request, _, org: str):
orgs = self.db.query("SELECT * from all_orgs where org_name LIKE ? order by org_name",
["%" + org.replace(" ", "%") + "%"])
if len(orgs) == 1:
self.ban_add_cmd(request, _, orgs[0].org_id, "")
elif len(orgs) == 0:
return " No orgs matching your search found."
elif len(orgs) > 1:
blob = "Your search had multiple results; please pick an org:<br>"
for org in orgs:
blob += "[%s] <highlight>%s<end> (<highlight>%s<end>) <%s>%s<end> [<highlight>%s<end> " \
"members]<br><pagebreak>" \
% (self.text.make_chatcmd("Add Ban", "/tell <myname> orgban add %s" % org.org_id),
org.org_name, org.org_id, org.faction.lower(), org.faction, org.member_count)
return ChatBlob("Pick an Org", blob)
def fetch_single(self, org_id, sender: object):
start = time.time()
data = []
accounts = []
count = 0
result = requests.get(self.single_org_uri % org_id).json()
for char_info in result[1]:
data.append((char_info["CHAR_INSTANCE"], char_info["NAME"], char_info["FIRSTNAME"],
char_info["LASTNAME"],
char_info["LEVELX"], char_info["BREED"],
char_info["SEX"], result[0]["SIDE_NAME"], char_info["PROF"],
char_info["PROF_TITLE"], char_info["DEFENDER_RANK_TITLE"], char_info["ALIENLEVEL"],
result[0]["ORG_INSTANCE"], result[0]["NAME"], char_info["RANK_TITLE"],
char_info["RANK"], char_info["CHAR_DIMENSION"], char_info["HEADID"],
0, char_info["PVPTITLE"], "roster", int(time.time())))
accounts.append((char_info["CHAR_INSTANCE"], char_info["CHAR_INSTANCE"], -1, start, start))
self.priv.kick(char_info['CHAR_INSTANCE'])
count += 1
with self.db.pool.get_connection() as conn:
with conn.cursor() as cur:
cur.executemany(
"REPLACE INTO player(char_id, name, first_name, last_name, level, breed, gender, faction, "
"profession, profession_title, ai_rank, ai_level, org_id, org_name, org_rank_name, "
"org_rank_id, dimension, head_id, pvp_rating, pvp_title, source, last_updated) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
data)
self.account_service.create_users(accounts, disable=True)
if sender:
sender.reply(
f"Org with ID <highlight>{org_id}</highlight> has been banned. "
f"Runtime: {time.time() - start:.2f} seconds.")
@timerevent(budatime="24h", description="Refresh orgbans")
def refresh_orgban(self, _, _1):
banned_orgs = self.db.query("SELECT * from ban_org_list")
# for org in [1456129, 391173,1136642, 1011713]:
# if org not in banned_orgs:
# self.messagehub.send_message("system_logger", None, f"**WARN** Rebanning {org}",
# f"**WARN** Rebanning {org}")
# self.ban_add_cmd(None, None, org, 'AUTO-BAN')
# banned_orgs.append(org)
for org in banned_orgs:
self.fetch_single(org.org_id, None)
self.logger.info(f"Refreshed bans for org {org.org_id}")