show server ip address and port: allow for opt-in to connect to synplcay.pl

This commit is contained in:
Abhay Raizada 2015-12-24 17:49:31 +05:30
parent 2d79d38bed
commit d68583f933
4 changed files with 17 additions and 12 deletions

View File

@ -343,10 +343,13 @@ en = {
"new-syncplay-available-motd-message" : "<NOTICE> You are using Syncplay {} but a newer version is available from http://syncplay.pl </NOTICE>", # ClientVersion "new-syncplay-available-motd-message" : "<NOTICE> You are using Syncplay {} but a newer version is available from http://syncplay.pl </NOTICE>", # ClientVersion
# Server notifications # 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-connected-room-server-notification" : "{0}({2}) connected to room '{1}'", # username, host, room
"client-left-server-notification" : "{0} left server", # name "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 "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 # Server arguments
@ -360,6 +363,7 @@ en = {
"server-motd-argument": "path to file from which motd will be fetched", "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-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-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 # Server errors
"unknown-command-server-error" : "Unknown command {}", # message "unknown-command-server-error" : "Unknown command {}", # message

View File

@ -14,15 +14,15 @@ import argparse
from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion,displayIP from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion,displayIP
class SyncFactory(Factory): class SyncFactory(Factory):
def __init__(self, password='', motdFilePath=None, isolateRooms=False, salt=None, disableReady=False): def __init__(self, port,password='', motdFilePath=None, isolateRooms=False, salt=None, disableReady=False,determineIP=False,):
print getMessage("welcome-server-notification").format(syncplay.version) print getMessage("welcome-server-notification").format(syncplay.version,port)
if password: if password:
password = hashlib.md5(password).hexdigest() password = hashlib.md5(password).hexdigest()
self.password = password self.password = password
if salt is None: if salt is None:
salt = RandomStringGenerator.generate_server_salt() salt = RandomStringGenerator.generate_server_salt()
print getMessage("no-salt-notification").format(salt) print getMessage("no-salt-notification").format(salt)
displayIP() displayIP(determineIP)
self._salt = salt self._salt = salt
self._motdFilePath = motdFilePath self._motdFilePath = motdFilePath
self.disableReady = disableReady 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('--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('--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('--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('--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")) self._argparser.add_argument('--motd-file', metavar='file', type=str, nargs='?', help=getMessage("server-motd-argument"))

View File

@ -115,13 +115,14 @@ def formatSize (bytes, precise=False):
def isASCII(s): def isASCII(s):
return all(ord(c) < 128 for c in s) return all(ord(c) < 128 for c in s)
def displayIP(): def displayIP(determineIP):
print "---------------------------" print "---------------------------"
print "Your Local IP's are:"
displayLocalIPs() displayLocalIPs()
print "---------------------------" print "---------------------------"
print "Your active network IP is." if determineIP:
displayNetworkIP() displayNetworkIP()
else:
print getMessage("no-ip-notification")
print "---------------------------" print "---------------------------"
@ -132,14 +133,14 @@ def displayLocalIPs():
for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}] ): 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') : if i['addr'] not in ('127.0.0.1','No IP addr') and not i['addr'].startswith('169.254') :
addresses.append(i['addr']) addresses.append(i['addr'])
for j in addresses: print (getMessage("local-ip-notification") + "\n"+"\n".join(addresses))
print j
def displayNetworkIP(): def displayNetworkIP():
import socket import socket
try: try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("syncplay.pl",80)) s.connect(("syncplay.pl",80))
print getMessage("network-ip-notification")
print(s.getsockname()[0]) print(s.getsockname()[0])
s.close() s.close()
except: except:

View File

@ -20,6 +20,5 @@ if __name__ == '__main__':
argsGetter = ConfigurationGetter() argsGetter = ConfigurationGetter()
args = argsGetter.getConfiguration() 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))
print "Your Port is.\n" + str(args.port)
reactor.run() reactor.run()