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
@@ -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: