From ecc04ff675e29bce5fe9a35aab1bc0f7e234a778 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 9 Apr 2015 12:45:12 -0700 Subject: [PATCH] display message-of-the-day, if the server offers one --- src/wormhole/blocking/transcribe.py | 10 ++++++++++ src/wormhole/servers/relay.py | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/wormhole/blocking/transcribe.py b/src/wormhole/blocking/transcribe.py index f728239..1b0a288 100644 --- a/src/wormhole/blocking/transcribe.py +++ b/src/wormhole/blocking/transcribe.py @@ -96,9 +96,18 @@ class Common: url += "/" + msgnum return url + motd_displayed = False version_warning_displayed = False def handle_welcome(self, welcome): + if ("motd" in welcome and + not self.motd_displayed): + motd_lines = welcome["motd"].splitlines() + motd_formatted = "\n ".join(motd_lines) + print("Server (at %s) says:\n %s" % (self.relay, motd_formatted), + file=sys.stderr) + self.motd_displayed = True + # Only warn if we're running a release version (e.g. 0.0.6, not # 0.0.6-DISTANCE-gHASH). Only warn once. if ("-" not in __version__ and @@ -108,6 +117,7 @@ class Common: print("Server claims %s is current, but ours is %s" % (welcome["current_version"], __version__), file=sys.stderr) self.version_warning_displayed = True + if "error" in welcome: raise ServerError(welcome["error"], self.relay) diff --git a/src/wormhole/servers/relay.py b/src/wormhole/servers/relay.py index 57529a0..c64e6c2 100644 --- a/src/wormhole/servers/relay.py +++ b/src/wormhole/servers/relay.py @@ -48,7 +48,9 @@ class EventsProtocol: WELCOME = { "current_version": __version__, - "motd": "Welcome to the public relay.", + # adding .motd will cause all clients to display the message, then keep + # running normally + #"motd": "Welcome to the public relay.\nPlease enjoy this service.", # adding .error will cause all clients to fail, with this message #"error": "This server has been disabled, see URL for details.", }