Telnet fixes and banner

This commit is contained in:
Ian Renton
2026-09-12 08:40:50 +01:00
parent 7c458a8c5b
commit 29eea1edc0
9 changed files with 61 additions and 24 deletions
+46 -9
View File
@@ -4,6 +4,7 @@ import threading
from datetime import datetime
import pytz
from pyhamtools import callinfo
from core.config import SERVER_OWNER_CALLSIGN
from core.constants import SOFTWARE_VERSION
@@ -12,6 +13,33 @@ from data.spot import Spot
logger = logging.getLogger(__name__)
BANNER = (
"""
==
==== ##### ##### ####
== == ..### ..### ..###
== ###==######## ###### ####### .####### ###### .### ######
==###.. ..###..### ###..###...###. .###..### ###..### .### ###..###
==###.### .### .###.### .### .### .### .### .### .### .### .#######
== .###.###.### .###.### .### .### ### .### .### .### .### .### .###...
== ...### .####### ..###### ..##### #### #####..###### #####..######
== .###. .###=.. ...... ..... .... ..... ...... ..... ......
== %% ... %%%%###==
== %%%%%%%%%%%#####== \r\n"""
+ "== ..... =="
+ f"Welcome to Spothole v{SOFTWARE_VERSION}".rjust(56)
+ "\r\n"
+ "========================"
+ f"This server is run by {SERVER_OWNER_CALLSIGN}".rjust(56)
)
MOTD = (
"Spothole's telnet server is a new feature and may not work properly in all\r\n"
+ "loggers. Please give it a try in your logger of choice and let me know if it\r\n"
+ "(or doesn't!) Please note that DXSpider-like commands are not yet supported\r\n"
+ "so you are not yet able to filter spots server-side or log in at all."
)
class TelnetServer:
"""A telnet server designed to provide spots in the same format as DXSpider, for compatibility with desktop loggers."""
@@ -56,15 +84,22 @@ class TelnetServer:
logger.debug("Telnet client connected")
self._clients.add(writer)
# Print MOTD
# Print banner and MOTD
try:
motd = (
f"Welcome to Spothole v{SOFTWARE_VERSION}.\r\nThis server is run by {SERVER_OWNER_CALLSIGN}.\r\n===\r\n"
text = (
BANNER
+ "\r\n\r\n"
+ "================================================================================"
+ "\r\n"
+ MOTD
+ "\r\n"
+ "================================================================================"
+ "\r\n\r\n"
)
writer.write(motd.encode("ascii"))
writer.write(text.encode("ascii"))
await writer.drain()
except Exception:
pass
logger.exception("Exception printing telnet motd")
# Set up buffer for user input
input_buffer = ""
@@ -163,12 +198,14 @@ class TelnetServer:
@staticmethod
def _format_dxspider_spot(spot: Spot) -> str:
"""Formats a spot into the format DXspider uses:
DX de CALLSIGN: FREQUENCY DX_CALLSIGN COMMENTS TIME_UTC"""
DX de CALLSIGN: FREQUENCY DX_CALLSIGN COMMENTS TIME_UTC.
Always use the base call for the spotter to save space. Everything must align properly to parse in clients,
and everything must be renderable in ASCII."""
de_call = f"{spot.de_call + ':' if spot.de_call else '???:'!s:<9}"
frequency = f"{(spot.freq / 1000.0):8.1f}"
de_call = f"{callinfo.Callinfo.get_homecall(spot.de_call)[:6] + ':' if spot.de_call else '???:'!s:<7}"
frequency = f"{(spot.freq / 1000.0):10.1f}"
dx_call = f"{spot.dx_call!s:<12}"
comment = f"{spot.comment[:29]:<30}"
comment = f"{spot.comment.encode('ascii', errors='ignore').decode()[:29]:<30}"
if spot.time:
timestamp = datetime.fromtimestamp(spot.time, tz=pytz.utc).strftime("%H%M") + "Z"
else: