mirror of https://github.com/Syncplay/syncplay
Fixed sending motd and http reply
This commit is contained in:
parent
c2f493951f
commit
a938dabd7f
|
@ -58,3 +58,4 @@ UI_COMMAND_REGEX = r"^(?P<command>[^\ ]+)(?:\ (?P<parameter>.+))?"
|
|||
UI_OFFSET_REGEX = r"^(?:o|offset)\ ?(?P<sign>[/+-])?(?P<time>\d{1,4}(?:[^\d\.](?:\d{1,6})){0,2}(?:\.(?:\d{1,3}))?)$"
|
||||
UI_SEEK_REGEX = r"^(?:s|seek)?\ ?(?P<sign>[+-])?(?P<time>\d{1,4}(?:[^\d\.](?:\d{1,6})){0,2}(?:\.(?:\d{1,3}))?)$"
|
||||
PARSE_TIME_REGEX = r'(:?(?:(?P<hours>\d+?)[^\d\.])?(?:(?P<minutes>\d+?))?[^\d\.])?(?P<seconds>\d+?)(?:\.(?P<miliseconds>\d+?))?$'
|
||||
SERVER_MAX_TEMPLATE_LENGTH = 10000
|
||||
|
|
|
@ -106,7 +106,8 @@ en = {
|
|||
"server-password-argument" : 'server password',
|
||||
"server-isolate-room-argument" : 'should rooms be isolated?',
|
||||
"server-motd-argument": "path to file from which motd will be fetched",
|
||||
"server-messed-up-motd": "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-http-reply-argument": "path to file from which http reply will be fetched",
|
||||
"server-default-http-reply": "This server should not be requested with your browser, but with Syncplay software available from http://syncplay.pl",
|
||||
|
||||
|
|
|
@ -93,17 +93,17 @@ class SyncFactory(Factory):
|
|||
tmpl = codecs.open(self._motdFilePath, "r", "utf-8-sig").read()
|
||||
args = dict(version=syncplay.version, userIp=userIp, username=username, room=room)
|
||||
try:
|
||||
return Template(tmpl).substitute(args)
|
||||
motd = Template(tmpl).substitute(args)
|
||||
return motd if len(motd) < constants.SERVER_MAX_TEMPLATE_LENGTH else getMessage("en", "server-messed-up-motd-too-long").format(constants.SERVER_MAX_TEMPLATE_LENGTH, len(motd))
|
||||
except ValueError:
|
||||
print getMessage("en", "server-messed-up-motd")
|
||||
return ""
|
||||
return getMessage("en", "server-messed-up-motd-unescaped-placeholders")
|
||||
else:
|
||||
return ""
|
||||
|
||||
def gethttpRequestReply(self):
|
||||
if(self._httpReplyFilePath and os.path.isfile(self._httpReplyFilePath)):
|
||||
tmpl = codecs.open(self._httpReplyFilePath, "r", "utf-8-sig").read()
|
||||
return tmpl
|
||||
return tmpl.encode('utf-8')
|
||||
else:
|
||||
return getMessage("en", "server-default-http-reply")
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from syncplay.ui.ConfigurationGetter import ServerConfigurationGetter
|
|||
argsGetter = ServerConfigurationGetter()
|
||||
args = argsGetter.getConfiguration()
|
||||
if(not args.isolate_rooms):
|
||||
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file))
|
||||
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file, args.http_reply_file))
|
||||
else:
|
||||
reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password, args.motd_file, args.http_reply_file))
|
||||
reactor.run()
|
||||
|
|
Loading…
Reference in New Issue