async def init(self, *args, **kwargs): try: return await self._init(*args, **kwargs) except FatalError as e: # NOTE: e is already formatted with the type and stuff Logger.fatal("Fatal Error Detected. Stopping Server.", module="obsidian", printTb=False) Logger.fatal(f"{type(e).__name__}: {e}", module="main") except Exception as e: Logger.fatal("==================== FATAL ERROR! ====================", module="obsidian", printTb=False) Logger.fatal(f"Fatal Error While Initializing Server - {type(e).__name__}: {e}", module="obsidian", printTb=False) Logger.fatal("===================== Traceback ======================", module="obsidian", printTb=False) Logger.log(f"{traceback.format_exc()}") Logger.fatal("==================== FATAL ERROR! ====================", module="obsidian", printTb=False)
async def stop(self): try: # Setting initialized to false to prevent multiple ctl-c if self.stopping: # Ignoring Repetitive Ctl-Cs return None if not self.initialized: Logger.info("Trying to shut down server that is not initialized!", module="server-stop") Logger.info("Skipping Shutdown and Cleanup Procedure", module="server-stop") sys.exit(0) return None # Preparing to stop server! Logger.info("Stopping Server...", module="server-stop") self.initialized = False self.stopping = True # Sending Disconnect Packet To All Server Members Logger.info("Sending Disconnect Packet To All Members", module="server-stop") await self.playerManager.sendGlobalPacket( Packets.Response.DisconnectPlayer, "Disconnected: Server Shutting Down" ) # Stopping Connection Handler Logger.info("Stopping Connection Handler Loop", module="server-stop") if self.server is not None: self.server.close() # Saving Worlds Logger.info("Saving All Worlds", module="server-stop") self.worldManager.saveWorlds() # Closing Worlds Logger.info("Closing All Worlds", module="server-stop") self.worldManager.closeWorlds() # Closing Server Logger.info("Terminating Process", module="server-stop") Logger.log("Goodbye!") sys.exit(0) except Exception as e: # Server Stop Failed! Last Ditch Attempt To Clean Up # Not Using Logger Incase Thats What Breaks It print(f"Error occurred while stopping server - {type(e).__name__}: {e}") print("Force Terminating Server") sys.exit(0)
async def sendWorldMessage( self, message: Union[str, list], author: Union[None, str, Player] = None, # Information on the message author worldTag: bool = False, # Flag dictating if the [world] header should be added ignoreList: List[Player] = [] # List of players to not send the message not ): # If Message Is A List, Recursively Send All Messages Within if type(message) is list: Logger.debug("Sending List Of Messages!", module="world-message") for msg in message: await self.sendWorldMessage(msg, author=author, worldTag=worldTag, ignoreList=ignoreList) return None # Break Out of Function # Hacky Way To Get World Type # Format Message To Be Sent # Add Author Tag if isinstance(author, str): message = f"<&e{author}&f> {message}" elif isinstance(author, Player): # Special Formatting For OPs if author.opStatus: message = f"<&c{author.name}&f> {message}" else: message = f"<&a{author.name}&f> {message}" # Add World Tag (If Requested) if worldTag: message = f"[&7{self.world.name}&f] {message}" # Finally, send formatted message Logger.log( str(message), tags=[Logger._getTimestamp(), "chat", "world", self.world.name], colour=Colour.GREEN, textColour=Colour.WHITE ) await self.sendWorldPacket(Packets.Response.SendMessage, message, ignoreList=ignoreList)