Do not load settings which are not active (module not loaded)

Restart the bot, on heavy DB errors, with an 30 seconds delay (like: all connections terminated by DB, table_definition_cache exhausted)
Fix for channel prefixing (org <-> priv)
This commit is contained in:
2021-11-30 16:57:31 +01:00
parent c100b0ea76
commit bf6c1842d2
17 changed files with 57 additions and 29 deletions
+1 -2
View File
@@ -77,11 +77,10 @@ try:
# paths to search for instances: core + module_paths
paths = ["core"]
paths.extend(config.module_paths)
# load instances
logger.debug("Loading instances")
Registry.load_instances(paths)
Registry.inject_all()
Registry.inject_all(paths)
# configure database
db = Registry.get_instance("db")
+1 -2
View File
@@ -36,8 +36,7 @@ class BuddyService:
# verify that buddy does not exist on any other conn
for conn_id, conn_buddy_list in self.buddy_list.items():
if conn.id != conn_id:
buddy = conn_buddy_list.get(packet.char_id, None)
if buddy:
if buddy := conn_buddy_list.get(packet.char_id, None):
if buddy["online"] is None:
# remove from other conn list
del conn_buddy_list[packet.char_id]
+8
View File
@@ -76,6 +76,14 @@ class DB:
except Exception as e:
raise SqlException(f"SQL Error: '{str(e)}' for '{sql}' "
f"[{', '.join(map(lambda x: str(x), params))}]") from e
except mariadb.OperationalError as e:
self.logger.error("Please use 'FLUSH TABLES;' inside of the DB, and consider upping the 'table_definition_cache' value of the Database Server.", e)
time.sleep(30)
exit(-3)
except mariadb.PoolError as e:
self.logger.error("No Connections available for the Connection Pool. Restarting in 30 seconds...", e)
time.sleep(30)
exit(-2)
elapsed = time.time() - start_time
result = callback(cur)
if elapsed > 5:
+1 -1
View File
@@ -43,7 +43,7 @@ class IgnCore:
self.last_timer_event = 0
self.start_time = int(time.time())
self.major_version = "IGNCore v2.8"
self.minor_version = "0"
self.minor_version = "1"
self.incoming_queue = FifoQueue()
self.mass_message_queue = None
self.conns = DictObject()
+2 -2
View File
@@ -87,7 +87,7 @@ class PublicChannelService(BaseModule):
return
if self.is_org_channel_id(packet.channel_id):
if self.setting_service.get_value("log_org") == "1" and packet.char_id == self.bot.get_char_id():
if self.setting_service.get_value("log_org") == "1":
char_name = self.character_service.get_char_name(packet.char_id)
if packet.extended_message:
message = packet.extended_message.get_message()
@@ -96,7 +96,7 @@ class PublicChannelService(BaseModule):
self.logger.log_chat(conn.id, "Org Channel", char_name, message)
self.event_service.fire_event(self.ORG_CHANNEL_MESSAGE_EVENT, packet)
elif packet.channel_id == self.ORG_MSG_CHANNEL_ID:
if self.setting_service.get_value("log_org") == "1" and packet.char_id == self.bot.get_char_id():
if self.setting_service.get_value("log_org") == "1":
char_name = self.character_service.get_char_name(packet.char_id)
if packet.extended_message:
message = packet.extended_message.get_message()
+7 -2
View File
@@ -10,7 +10,7 @@ class Registry:
logger = None
@classmethod
def inject_all(cls):
def inject_all(cls, modules):
# inject registry so instance can get references to other instances
for key in cls._registry:
try:
@@ -23,7 +23,10 @@ class Registry:
@classmethod
def pre_start_all(cls):
# call pre_start() on instances so they can start any init() processes
mods = cls.get_instance("bot").modules
for key in cls._registry:
if str(cls._registry[key].module_name).split(".")[0] not in mods:
continue
try:
cls._registry[key].pre_start
except AttributeError:
@@ -34,7 +37,10 @@ class Registry:
@classmethod
def start_all(cls):
# call start() on instances so they can finish any init() processes
mods = cls.get_instance("bot").modules
for key in cls._registry:
if str(cls._registry[key].module_name).split(".")[0] not in mods:
continue
try:
cls._registry[key].start
except AttributeError:
@@ -60,7 +66,6 @@ class Registry:
inst.module_name = Registry.get_module_name(inst)
inst.module_dir = Registry.get_module_dir(inst)
if not override and name in cls._registry:
raise Exception("Overriding '%s' with new instance" % name)
elif override and name not in cls._registry:
+4
View File
@@ -24,6 +24,10 @@ class SettingService:
for _, inst in Registry.get_all_instances().items():
for name, method in get_attrs(inst).items():
if hasattr(method, "setting"):
key = Registry.get_module_name(inst).split(".")
# We dont want to load settings, if their modules not enabled in our config...
if key[0] not in self.bot.modules:
continue
setting_name, value, description, extended_description, obj = getattr(method, "setting")
self.register(inst.module_name, setting_name, value, obj, description, extended_description)
+2 -2
View File
@@ -53,7 +53,7 @@ class Text:
def inject(self, registry):
self.setting_service: SettingService = registry.get_instance("setting_service")
self.ban = registry.get_instance("ban_service")
self.ban = registry.get_instance("ban_service", is_optional=True)
self.bot = registry.get_instance("bot")
self.public_channel_service = registry.get_instance("public_channel_service")
@@ -153,7 +153,7 @@ class Text:
msg = f"<highlight>{char_info.name}</highlight>"
else:
msg = f"<highlight>CharId({char_info.char_id:d})</highlight>"
if check_ban:
if check_ban and self.ban:
banned = f" :: <red>Banned!</red>" if self.ban.get_ban(char_info.char_id) else ""
msg += banned
if online_status is not None:
@@ -159,7 +159,7 @@ class AccountController:
self.db.exec("DELETE FROM pending_accounts where main=? or alt=?", [account[0].main, account[0].main])
self.db.exec("DELETE FROM mail where recipient=? or sender=?", [account[0].main, account[0].main])
self.account_service.add_log(request.sender.char_id, "system",
f"Disabled Account of <highlight>{user.name}</highlight>.",
f"Purged the account of <highlight>{user.name}</highlight>.",
request.sender.char_id)
return f"Character <highlight>{user.name}'s</highlight> Account has been purged!"
else:
+2 -1
View File
@@ -6,6 +6,7 @@ from core.chat_blob import ChatBlob
from core.command_param_types import Const, Options, Character, Multiple, Any
from core.decorators import instance, command
from core.dict_object import DictObject
from core.sender_obj import SenderObj
from core.setting_service import SettingService
from core.text import Text
from core.translation_service import TranslationService
@@ -135,7 +136,7 @@ class AltsController:
for alt in alts:
char_id = self.character_service.resolve_char_to_id(alt)
if not char_id:
notfound.append(alt)
notfound.append(alt.name if type(alt) == SenderObj else alt)
continue
alt = DictObject({"char_id": char_id, "name": alt})
if main.char_id == alt.char_id:
@@ -78,7 +78,7 @@ class PrivateChannelController:
return hjson.load(f)
def handle_incoming_relay_message(self, ctx):
if not self.display_main().get_value() == "1" and ctx.source == "org_channel" and ctx.sender:
if self.display_main().get_value() and ctx.source == "private_channel" and ctx.sender:
name = f"{OrgChannelController.ORG_CHANNEL_PREFIX} <yellow>{ctx.sender.name}</yellow>"
if account := self.account_service.get_account(ctx.sender.char_id):
if account.main != ctx.sender.char_id:
@@ -92,9 +92,9 @@ class PrivateChannelController:
if not self.bot.is_ready():
if data.packet.char_id not in self.reinvite:
account = data.account
if account.disabled == 1:
if not self.account_service.simple_checks(account):
return
if self.pork.get_character_info(data.packet.char_id).org_id == self.bot.public_channel_service.org_id:
if self.account_service.get_entry(data.packet.char_id).get("member", self.bot.public_channel_service.org_id) == self.bot.public_channel_service.org_id:
return
if account.auto_invite == 1:
self.reinvite.append(data.packet.char_id)
@@ -102,12 +102,12 @@ class PrivateChannelController:
if self.private_channel_service.in_private_channel(data.packet.char_id):
return
account = data.account
if account.disabled == 1:
if not self.account_service.simple_checks(account):
return
if self.db.query_single("SELECT * from org_bots where char_id=?", [data.packet.char_id]):
return
if account.auto_invite == 1:
if self.pork.get_character_info(data.packet.char_id).org_id != self.bot.public_channel_service.org_id:
if self.account_service.get_entry(data.packet.char_id).get("member", self.bot.public_channel_service.org_id) != self.bot.public_channel_service.org_id:
self.private_channel_service.invite(data.packet.char_id)
self.bot.send_mass_message(data.packet.char_id, "You have been "
"<highlight>auto invited</highlight> "
+2 -2
View File
@@ -86,8 +86,8 @@ class CloakController:
timer_name = "Lower City Cloak"
else:
raise Exception(f"Unknown cloak action '{event_data.action}'")
self.timer_controller.add_timer(timer_name, event_data.sender.char_id, "org", int(time.time()), 3600)
if self.timer_controller:
self.timer_controller.add_timer(timer_name, event_data.sender.char_id, "org", int(time.time()), 3600)
def get_cloak_status(self, row):
one_hour = 3600
+5 -5
View File
@@ -40,14 +40,14 @@ class OrgChannelController:
def start(self):
self.message_hub_service.register_message_destination(
self.MESSAGE_SOURCE, self.handle_incoming_relay_message,
["private_channel", "websocket_relay", "cloak_reminder", "wave_counter", "shutdown_notice"],
[self.MESSAGE_SOURCE])
self.MESSAGE_SOURCE, self.handle_incoming_relay_message,
["private_channel", "websocket_relay", "cloak_reminder", "wave_counter", "shutdown_notice"],
[self.MESSAGE_SOURCE])
def handle_incoming_relay_message(self, ctx):
# {'source': 'org_channel', 'sender': {'char_id': 384018, 'name': 'Risianna'}, 'message': 'Sooo', 'formatted_message': "[<cyan>Org</cyan>] <a href='user://Risianna'>Risianna</a>: Sooo"}
if not self.display_main().get_value() == "1" and ctx.source == "private_channel" and ctx.sender:
name = f"{OrgChannelController.ORG_CHANNEL_PREFIX} <yellow>{ctx.sender.name}</yellow>"
if self.display_main().get_value() and ctx.source == "private_channel" and ctx.sender:
name = f"[<cyan>Priv</cyan>] <yellow>{ctx.sender.name}</yellow>"
if account := self.account_service.get_account(ctx.sender.char_id):
if account.main != ctx.sender.char_id:
name += f" (<yellow>{account.name}</yellow>)"
@@ -217,6 +217,8 @@ class OrgRosterController:
self.db.exec("INSERT INTO org_activity (message, time) VALUES(?, ?)", [ext_msg.get_message(), time.time()])
def process_org_msg(self, char_name, new_mode, actee=None):
# TODO: errors out on newly created chars, which do not show up on PoRK yet.
# self.pork.get_character_info(char_name)
char_id = self.character_service.resolve_char_to_id(char_name)
org_member = self.get_org_member(char_id)
self.process_update(char_id, org_member.member if org_member else None, new_mode, actee)
+2 -2
View File
@@ -356,9 +356,9 @@ class LootController:
if int(time.time()) - self.last_modify > 3600 and self.loot_list:
self.last_modify = None
self.loot_list = OrderedDict()
self.bot.send_org_message("Loot was last modified more than 1 hour ago, list has been cleared.")
self.bot.send_org_message("Loot was last modified more than 1 hour ago, list has been cleared.", fire_outgoing_event=False)
self.bot.send_private_channel_message(
"Loot was last modified more than 1 hour ago, list has been cleared.")
"Loot was last modified more than 1 hour ago, list has been cleared.", fire_outgoing_event=False)
def is_already_added(self, name: str):
for i, loot_item in self.loot_list.items():
+10
View File
@@ -1,6 +1,7 @@
from core.command_param_types import Any
from core.decorators import instance, command
from core.igncore import IgnCore
from core.text import Text
@instance()
@@ -8,6 +9,7 @@ class ChatController:
def inject(self, registry):
self.command_alias_service = registry.get_instance("command_alias_service")
self.bot: IgnCore = registry.get_instance("bot")
self.text: Text = registry.get_instance("text")
def start(self):
self.command_alias_service.add_alias("cmd", "shout")
@@ -20,3 +22,11 @@ class ChatController:
f"<yellow>────────────────</yellow>\n"
f"<highlight>{message}</highlight>\n"
f"<yellow>────────────────</yellow>")
@command(command="lft", params=[Any("message", is_optional=True)], access_level="member",
description="Show a highly visible message")
def shout_command(self, _, message):
lft = f"<a href='chatcmd:///lft <font color=#FFFF00>» {message or '<myname>'}<end>'>/lft {message or '<myname>'}</a>"
return self.text.format_page("Use this command for going LFT", "<yellow>────────────────</yellow>\n"
f"<highlight>{lft}</highlight>\n"
f"<yellow>────────────────</yellow>")
@@ -390,9 +390,9 @@ class SpecialsController:
inits_recharge = ((((init_result - 87.5) * 0.02) + 1 - weapon_attack + 4) * -900) + 1200
if inits_attack < inits_recharge:
return inits_recharge
return int(inits_recharge)
else:
return inits_attack
return int(inits_attack)
def get_aimed_shot_info(self, weapon_attack, weapon_recharge, aimed_shot_skill):
result = DictObject()