diff --git a/syncplay/messages.py b/syncplay/messages.py index 7a3349b..efb9974 100755 --- a/syncplay/messages.py +++ b/syncplay/messages.py @@ -343,11 +343,14 @@ 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 by connecting to syncplay.pl use --determine-ip, to know more use --help", + "connection-error-notification" : "Could not connect to syncplay.pl", # Server arguments "server-argument-description" : 'Solution to synchronize playback of multiple MPlayer and MPC-HC instances over the network. Server instance', @@ -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 @@ -713,10 +717,14 @@ ru = { "new-syncplay-available-motd-message" : u" Вы используете Syncplay версии {}. Доступна более новая версия на http://syncplay.pl/ . ", # ClientVersion # Server notifications - "welcome-server-notification" : u"Добро пожаловать на сервер Syncplay версии {0}", # version + "welcome-server-notification" :"" ,#TODO "client-connected-room-server-notification" : u"{0}({2}) подключился(-лась) к комнате '{1}'", # username, host, room "client-left-server-notification" : u"{0} покинул(а) сервер", # name "no-salt-notification" : u"ВНИМАНИЕ: Чтобы сгенерированные сервером пароли операторов комнат работали после перезагрузки сервера, необходимо указать следующий аргумент командной строки при запуске сервера Syncplay: --salt {}", #Salt + "local-ip-notification": "" ,#TODO + "network-ip-notification" : "" ,#TODO, + "no-ip-notification" : "",#TODO + "connection-error-notification" : "",#TODO # Server arguments "server-argument-description" : u'Решение для синхронного воспроизведения в VLC, MPlayer или MPC-HC через Интернет. Серверная часть', @@ -729,7 +737,7 @@ ru = { "server-motd-argument" : u"путь к файлу, из которого будет извлекаться MOTD-сообщение", "server-messed-up-motd-unescaped-placeholders" : u"MOTD-сообщение содержит неэкранированные спец.символы. Все знаки $ должны быть продублированы ($$).", "server-messed-up-motd-too-long" : u"MOTD-сообщение слишком длинное: максимальная длина - {} символ(ов), текущая длина - {} символ(ов).", - + "server-determine-ip-argument" : "", #TODO # Server errors "unknown-command-server-error" : u"Неизвестная команда: {}", # message "not-json-server-error" : u"Не является закодированной json-строкой: {}", # message @@ -1083,11 +1091,15 @@ de = { "new-syncplay-available-motd-message" : u" Du nutzt Syncplay Version {}, aber es gibt eine neuere Version auf http://syncplay.pl", # ClientVersion # Server notifications - "welcome-server-notification" : u"Willkommen zum Syncplay-Server, v. {0}", # version + "welcome-server-notification" : "",#TODO "client-connected-room-server-notification" : u"{0}({2}) hat den Raum '{1}' betreten", # username, host, room "client-left-server-notification" : u"{0} hat den Server verlassen", # name "no-salt-notification" : u"WICHTIGER HINWEIS: Damit von dem Server generierte Passwörter für geführte Räume auch nach einem Serverneustart funktionieren, starte den Server mit dem folgenden Parameter: --salt {}", #Salt - + "local-ip-notification" : "",#TODO + "network-ip-notification" : "",#TODO + "no-ip-notification" : "", #TODO + "connection-error-notification" : "",#TODO + # Server arguments "server-argument-description" : u'Anwendung, um mehrere MPlayer, MPC-HC und VLC-Instanzen über das Internet zu synchronisieren. Server', "server-argument-epilog" : u'Wenn keine Optionen angegeben sind, werden die _config-Werte verwendet', @@ -1099,7 +1111,8 @@ de = { "server-motd-argument": u"Pfad zur Datei, von der die Nachricht des Tages geladen wird", "server-messed-up-motd-unescaped-placeholders": u"Die Nachricht des Tages hat unmaskierte Platzhalter. Alle $-Zeichen sollten verdoppelt werden ($$).", "server-messed-up-motd-too-long": u"Die Nachricht des Tages ist zu lang - Maximal {} Zeichen, aktuell {}.", - + "server-determine-ip-argument" : "", #TODO + # Server errors "unknown-command-server-error" : u"Unbekannter Befehl {}", # message "not-json-server-error" : u"Kein JSON-String {}", # message diff --git a/syncplay/server.py b/syncplay/server.py index 3996311..94d0017 100644 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -11,17 +11,18 @@ import codecs import os from string import Template import argparse -from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion +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(determineIP) self._salt = salt self._motdFilePath = motdFilePath self.disableReady = disableReady @@ -441,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 fb629df..d48bd92 100644 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -115,6 +115,37 @@ def formatSize (bytes, precise=False): def isASCII(s): return all(ord(c) < 128 for c in s) +def displayIP(determineIP): + print "---------------------------" + displayLocalIPs() + print "---------------------------" + if determineIP: + displayNetworkIP() + else: + print getMessage("no-ip-notification") + print "---------------------------" + + +def displayLocalIPs(): + from netifaces import interfaces, ifaddresses, AF_INET + addresses=[] + for ifaceName in interfaces(): + 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']) + 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: + print getMessage("connection-error-notification") + def findWorkingDir(): frozen = getattr(sys, 'frozen', '') if not frozen: diff --git a/syncplayServer.py b/syncplayServer.py index b4456d7..baf8178 100755 --- a/syncplayServer.py +++ b/syncplayServer.py @@ -20,5 +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)) + 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()