From 0b5b8811b41e17c7041b0b4507f5fad3b5585257 Mon Sep 17 00:00:00 2001 From: Uriziel Date: Sat, 19 Apr 2014 11:39:17 +0200 Subject: [PATCH] Dropped HTTP reply support (not working) --- syncplay/messages.py | 2 -- syncplay/protocols.py | 20 +++++--------------- syncplay/server.py | 11 +---------- syncplayServer.py | 4 ++-- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/syncplay/messages.py b/syncplay/messages.py index 9f29701..b305031 100644 --- a/syncplay/messages.py +++ b/syncplay/messages.py @@ -177,8 +177,6 @@ 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-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", "server-irc-verbose": "Should server actively report changes in rooms", "server-irc-config": "Path to irc bot config files", diff --git a/syncplay/protocols.py b/syncplay/protocols.py index f83cfa0..6feaef4 100644 --- a/syncplay/protocols.py +++ b/syncplay/protocols.py @@ -32,11 +32,7 @@ class JSONCommandProtocol(LineReceiver): try: messages = json.loads(line) except: - if ("GET / HTTP/1." in line): - self.handleHttpRequest(line) - self.drop() - else: - self.dropWithError(getMessage("en", "not-json-server-error").format(line)) + self.dropWithError(getMessage("en", "not-json-server-error").format(line)) return self.handleMessages(messages) @@ -190,9 +186,6 @@ class SyncClientProtocol(JSONCommandProtocol): position, paused, doSeek, stateChange = self._client.getLocalState() self.sendState(position, paused, doSeek, latencyCalculation, stateChange) - def handleHttpRequest(self, request): - pass - def sendState(self, position, paused, doSeek, latencyCalculation, stateChange=False): state = {} positionAndPausedIsSet = position is not None and paused is not None @@ -234,7 +227,7 @@ class SyncServerProtocol(JSONCommandProtocol): self._pingService = PingService() self._clientLatencyCalculation = 0 self._clientLatencyCalculationArrivalTime = 0 - + def __hash__(self): return hash('|'.join(( self.transport.getPeer().host, @@ -364,7 +357,7 @@ class SyncServerProtocol(JSONCommandProtocol): } ping = { "latencyCalculation": self._pingService.newTimestamp(), - "serverRtt": self._pingService.getRtt() + "serverRtt": self._pingService.getRtt() } if(self._clientLatencyCalculation): ping["clientLatencyCalculation"] = self._clientLatencyCalculation + processingTime @@ -413,9 +406,6 @@ class SyncServerProtocol(JSONCommandProtocol): if(self.serverIgnoringOnTheFly == 0): self._factory.updateWatcherState(self, position, paused, doSeek, self._pingService.getLastForwardDelay()) - def handleHttpRequest(self, request): - self.sendLine(self._factory.gethttpRequestReply()) - def handleError(self, error): self.dropWithError(error["message"]) # TODO: more processing and fallbacking @@ -443,9 +433,9 @@ class PingService(object): self._avrRtt = self._rtt self._avrRtt = self._avrRtt * PING_MOVING_AVERAGE_WEIGHT + self._rtt * (1 - PING_MOVING_AVERAGE_WEIGHT) if(senderRtt < self._rtt): - self._fd = self._avrRtt/2 + (self._rtt - senderRtt) + self._fd = self._avrRtt / 2 + (self._rtt - senderRtt) else: - self._fd = self._avrRtt/2 + self._fd = self._avrRtt / 2 def getLastForwardDelay(self): return self._fd diff --git a/syncplay/server.py b/syncplay/server.py index c8f96a6..723582b 100644 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -14,13 +14,12 @@ from string import Template import argparse class SyncFactory(Factory): - def __init__(self, password='', motdFilePath=None, httpReplyFilePath=None): + def __init__(self, password='', motdFilePath=None): print getMessage("en", "welcome-server-notification").format(syncplay.version) if(password): password = hashlib.md5(password).hexdigest() self.password = password self._motdFilePath = motdFilePath - self._httpReplyFilePath = httpReplyFilePath self._rooms = {} self._roomStates = {} self._roomUpdate = threading.RLock() @@ -108,13 +107,6 @@ class SyncFactory(Factory): 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.encode('utf-8') - else: - return getMessage("en", "server-default-http-reply") - def sendState(self, watcherProtocol, doSeek=False, forcedUpdate=False): watcher = self.getWatcher(watcherProtocol) if(not watcher): @@ -296,4 +288,3 @@ class ConfigurationGetter(object): self._argparser.add_argument('--password', metavar='password', type=str, nargs='?', help=getMessage("en", "server-password-argument")) self._argparser.add_argument('--isolate-rooms', action='store_true', help=getMessage("en", "server-isolate-room-argument")) self._argparser.add_argument('--motd-file', metavar='file', type=str, nargs='?', help=getMessage("en", "server-motd-argument")) - self._argparser.add_argument('--http-reply-file', metavar='file', type=str, nargs='?', help=getMessage("en", "server-http-reply-argument")) diff --git a/syncplayServer.py b/syncplayServer.py index d74aa16..d59233a 100755 --- a/syncplayServer.py +++ b/syncplayServer.py @@ -13,7 +13,7 @@ argsGetter = ConfigurationGetter() args = argsGetter.getConfiguration() if(not args.isolate_rooms): - reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file, args.http_reply_file)) + reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file)) else: - reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password, args.motd_file, args.http_reply_file)) + reactor.listenTCP(int(args.port), SyncIsolatedFactory(args.password, args.motd_file)) reactor.run()