N2DRC-BBS-mesh/server.py

94 lines
3.2 KiB
Python
Raw Normal View History

2024-06-25 05:50:52 -07:00
#!/usr/bin/env python3
"""
TC²-BBS Server for Meshtastic by TheCommsChannel (TC²)
2024-07-14 15:52:06 -07:00
Date: 07/14/2024
Version: 0.1.6
2024-06-25 05:50:52 -07:00
Description:
The system allows for mail message handling, bulletin boards, and a channel
directory. It uses a configuration file for setup details and an SQLite3
database for data storage. Mail messages and bulletins are synced with
other BBS servers listed in the config.ini file.
"""
import logging
2024-07-14 15:52:06 -07:00
import time
2024-06-25 05:50:52 -07:00
2024-06-28 13:35:45 -07:00
from config_init import initialize_config, get_interface, init_cli_parser, merge_config
2024-06-25 05:50:52 -07:00
from db_operations import initialize_database
2024-07-14 15:52:06 -07:00
from js8call_integration import JS8CallClient
2024-06-25 05:50:52 -07:00
from message_processing import on_receive
from pubsub import pub
2024-07-14 15:52:06 -07:00
# General logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
# JS8Call logging
js8call_logger = logging.getLogger('js8call')
js8call_logger.setLevel(logging.DEBUG)
js8call_handler = logging.StreamHandler()
js8call_handler.setLevel(logging.DEBUG)
js8call_formatter = logging.Formatter('%(asctime)s - JS8Call - %(levelname)s - %(message)s', '%Y-%m-%d %H:%M:%S')
js8call_handler.setFormatter(js8call_formatter)
js8call_logger.addHandler(js8call_handler)
2024-06-25 05:50:52 -07:00
def display_banner():
banner = """
Meshtastic Version
"""
print(banner)
def main():
display_banner()
2024-06-28 13:35:45 -07:00
args = init_cli_parser()
config_file = None
if args.config is not None:
config_file = args.config
system_config = initialize_config(config_file)
2024-06-28 13:35:45 -07:00
merge_config(system_config, args)
2024-06-28 13:35:45 -07:00
interface = get_interface(system_config)
interface.bbs_nodes = system_config['bbs_nodes']
interface.allowed_nodes = system_config['allowed_nodes']
2024-06-25 05:50:52 -07:00
2024-06-28 13:35:45 -07:00
logging.info(f"TC²-BBS is running on {system_config['interface_type']} interface...")
2024-06-25 05:50:52 -07:00
initialize_database()
2024-07-02 15:47:59 -07:00
def receive_packet(packet, interface):
2024-06-28 13:45:42 -07:00
on_receive(packet, interface)
2024-06-25 05:50:52 -07:00
2024-06-28 13:35:45 -07:00
pub.subscribe(receive_packet, system_config['mqtt_topic'])
2024-06-25 05:50:52 -07:00
2024-07-14 15:52:06 -07:00
# Initialize and start JS8Call Client if configured
js8call_client = JS8CallClient(interface)
js8call_client.logger = js8call_logger
if js8call_client.db_conn:
js8call_client.connect()
2024-06-25 05:50:52 -07:00
try:
while True:
2024-06-27 22:16:39 -07:00
time.sleep(1)
2024-06-25 05:50:52 -07:00
except KeyboardInterrupt:
logging.info("Shutting down the server...")
interface.close()
2024-07-14 15:52:06 -07:00
if js8call_client.connected:
js8call_client.close()
2024-06-25 05:50:52 -07:00
if __name__ == "__main__":
main()