From d68583f9336861ede811121a61f91ee358603c23 Mon Sep 17 00:00:00 2001 From: Abhay Raizada Date: Thu, 24 Dec 2015 17:49:31 +0530 Subject: [PATCH] show server ip address and port: allow for opt-in to connect to synplcay.pl --- syncplay/messages.py | 6 +++++- syncplay/server.py | 7 ++++--- syncplay/utils.py | 13 +++++++------ syncplayServer.py | 3 +-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/syncplay/messages.py b/syncplay/messages.py index 7a3349b..82ee1ac 100755 --- a/syncplay/messages.py +++ b/syncplay/messages.py @@ -343,10 +343,13 @@ en = { "new-syncplay-available-motd-message" : " You are using Syncplay {} but a newer version is available from http://syncplay.pl ", # ClientVersion # Server notifications - "welcome-server-notification" : "Welcome to Syncplay server, ver. {0}", # version + "welcome-server-notification" : "You are now running a Syncplay v{} server instance on port {}. Visit http://syncplay.pl/guide/server/ to learn more about running a server.", # version "client-connected-room-server-notification" : "{0}({2}) connected to room '{1}'", # username, host, room "client-left-server-notification" : "{0} left server", # name "no-salt-notification" : "PLEASE NOTE: To allow room operator passwords generated by this server instance to still work when the server is restarted, please add the following command line argument when running the Syncplay server in the future: --salt {}", #Salt + "local-ip-notification" : "Your local IPs are:", + "network-ip-notification" : "Your Active internet(network) IP is:", + "no-ip-notification" : "To know your network ip use --determine-ip, to know more use --help", # Server arguments @@ -360,6 +363,7 @@ en = { "server-motd-argument": "path to file from which motd will be fetched", "server-messed-up-motd-unescaped-placeholders": "Message of the Day has unescaped placeholders. All $ signs should be doubled ($$).", "server-messed-up-motd-too-long": "Message of the Day is too long - maximum of {} chars, {} given.", + "server-determine-ip-argument" : "Should synplay connect to syncplay.pl, to show your internet address?", # Server errors "unknown-command-server-error" : "Unknown command {}", # message diff --git a/syncplay/server.py b/syncplay/server.py index 39538dc..94d0017 100644 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -14,15 +14,15 @@ import argparse from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion,displayIP class SyncFactory(Factory): - def __init__(self, password='', motdFilePath=None, isolateRooms=False, salt=None, disableReady=False): - print getMessage("welcome-server-notification").format(syncplay.version) + def __init__(self, port,password='', motdFilePath=None, isolateRooms=False, salt=None, disableReady=False,determineIP=False,): + print getMessage("welcome-server-notification").format(syncplay.version,port) if password: password = hashlib.md5(password).hexdigest() self.password = password if salt is None: salt = RandomStringGenerator.generate_server_salt() print getMessage("no-salt-notification").format(salt) - displayIP() + displayIP(determineIP) self._salt = salt self._motdFilePath = motdFilePath self.disableReady = disableReady @@ -442,5 +442,6 @@ class ConfigurationGetter(object): self._argparser.add_argument('--password', metavar='password', type=str, nargs='?', help=getMessage("server-password-argument")) self._argparser.add_argument('--isolate-rooms', action='store_true', help=getMessage("server-isolate-room-argument")) self._argparser.add_argument('--disable-ready', action='store_true', help=getMessage("server-disable-ready-argument")) + self._argparser.add_argument('--determine-ip', action='store_true', help=getMessage("server-determine-ip-argument")) self._argparser.add_argument('--salt', metavar='salt', type=str, nargs='?', help=getMessage("server-salt-argument")) self._argparser.add_argument('--motd-file', metavar='file', type=str, nargs='?', help=getMessage("server-motd-argument")) \ No newline at end of file diff --git a/syncplay/utils.py b/syncplay/utils.py index 038afe2..367b331 100644 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -115,13 +115,14 @@ def formatSize (bytes, precise=False): def isASCII(s): return all(ord(c) < 128 for c in s) -def displayIP(): +def displayIP(determineIP): print "---------------------------" - print "Your Local IP's are:" displayLocalIPs() print "---------------------------" - print "Your active network IP is." - displayNetworkIP() + if determineIP: + displayNetworkIP() + else: + print getMessage("no-ip-notification") print "---------------------------" @@ -132,14 +133,14 @@ def displayLocalIPs(): for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}] ): if i['addr'] not in ('127.0.0.1','No IP addr') and not i['addr'].startswith('169.254') : addresses.append(i['addr']) - for j in addresses: - print j + print (getMessage("local-ip-notification") + "\n"+"\n".join(addresses)) def displayNetworkIP(): import socket try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("syncplay.pl",80)) + print getMessage("network-ip-notification") print(s.getsockname()[0]) s.close() except: diff --git a/syncplayServer.py b/syncplayServer.py index 159df2a..baf8178 100755 --- a/syncplayServer.py +++ b/syncplayServer.py @@ -20,6 +20,5 @@ if __name__ == '__main__': argsGetter = ConfigurationGetter() args = argsGetter.getConfiguration() - reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file, args.isolate_rooms, args.salt, args.disable_ready)) - print "Your Port is.\n" + str(args.port) + reactor.listenTCP(int(args.port), SyncFactory(args.port,args.password, args.motd_file, args.isolate_rooms, args.salt, args.disable_ready,args.determine_ip)) reactor.run()