Updated the controlled room protocol to fit more needs

This commit is contained in:
Uriziel 2014-10-05 20:05:06 +02:00
parent cdce17b10b
commit 9506a80b9b
3 changed files with 15 additions and 16 deletions

View File

@ -431,14 +431,14 @@ class SyncplayClient(object):
self.ui.showMessage("Identifying as room controller with password '{}'...".format(controlPassword)) self.ui.showMessage("Identifying as room controller with password '{}'...".format(controlPassword))
self._protocol.requestControlledRoom(controlPassword) self._protocol.requestControlledRoom(controlPassword)
def controllerIdentificationError(self): def controllerIdentificationError(self, username):
self.ui.showErrorMessage("Failed to identify as a room controller.") self.ui.showErrorMessage("<{}> failed to identify as a room controller.".format(username))
def controllerIdentificationSuccess(self): def controllerIdentificationSuccess(self, username):
# TODO: More UI stuff # TODO: More UI stuff
self.ui.showErrorMessage("Authenticated as a room controller") self.ui.showErrorMessage("<{}> authenticated as a room controller".format(username))
# TODO: A person authenticated as a room controller # TODO: Mark person as a room controller
# TODO: Disable UI's "Create new Controlled Room when in Controlled Room" # TODO: Disable UI's "Create new Controlled Room when in Controlled Room"
# TODO: Disable authenticate when authenticated # TODO: Disable authenticate when authenticated

View File

@ -122,9 +122,9 @@ class SyncClientProtocol(JSONCommandProtocol):
self._SetUser(values) self._SetUser(values)
elif command == "controllerAuth": elif command == "controllerAuth":
if values['success']: if values['success']:
self._client.controllerIdentificationSuccess() self._client.controllerIdentificationSuccess(values["user"])
else: else:
self._client.controllerIdentificationError() self._client.controllerIdentificationError(values["user"])
elif command == "newControlledRoom": elif command == "newControlledRoom":
controlPassword = values['password'] controlPassword = values['password']
roomName = values['roomName'] roomName = values['roomName']
@ -341,17 +341,17 @@ class SyncServerProtocol(JSONCommandProtocol):
} }
}) })
def sendControlledRoomAuthStatus(self, success): def sendControlledRoomAuthStatus(self, success, username):
self.sendSet({ self.sendSet({
"controllerAuth": { "controllerAuth": {
"user": username,
"success": success "success": success
} }
}) })
def sendUserSetting(self, username, room, file_, event): def sendUserSetting(self, username, room, file_, event):
room = {"name": room.getName()} room = {"name": room.getName()}
user = {} user = {username: {}}
user[username] = {}
user[username]["room"] = room user[username]["room"] = room
if file_: if file_:
user[username]["file"] = file_ user[username]["file"] = file_
@ -388,7 +388,7 @@ class SyncServerProtocol(JSONCommandProtocol):
"paused": paused, "paused": paused,
"doSeek": doSeek, "doSeek": doSeek,
"setBy": setBy.getName() "setBy": setBy.getName()
} }
ping = { ping = {
"latencyCalculation": self._pingService.newTimestamp(), "latencyCalculation": self._pingService.newTimestamp(),
"serverRtt": self._pingService.getRtt() "serverRtt": self._pingService.getRtt()

View File

@ -110,13 +110,12 @@ class SyncFactory(Factory):
room = watcher.getRoom() room = watcher.getRoom()
try: try:
success = RoomPasswordProvider.check(room.getName(), password, self._salt) success = RoomPasswordProvider.check(room.getName(), password, self._salt)
# TODO: Authenticate watcher to make changes in the room self._roomManager.broadcastRoom(watcher, lambda w: w.sendControlledRoomAuthStatus(success, watcher.getName()))
watcher.sendControlledRoomAuthStatus(success)
except NotControlledRoom: except NotControlledRoom:
newName = RoomPasswordProvider.getControlledRoomName(room.getName(), password, self._salt) newName = RoomPasswordProvider.getControlledRoomName(room.getName(), password, self._salt)
watcher.sendNewControlledRoom(newName, password) watcher.sendNewControlledRoom(newName, password)
except ValueError: except ValueError:
watcher.sendControlledRoomAuthStatus(False) self._roomManager.broadcastRoom(watcher, lambda w: w.sendControlledRoomAuthStatus(False, watcher.getName()))
class RoomManager(object): class RoomManager(object):
@ -301,8 +300,8 @@ class Watcher(object):
def sendNewControlledRoom(self, roomName, password): def sendNewControlledRoom(self, roomName, password):
self._connector.sendNewControlledRoom(roomName, password) self._connector.sendNewControlledRoom(roomName, password)
def sendControlledRoomAuthStatus(self, success): def sendControlledRoomAuthStatus(self, success, username):
self._connector.sendControlledRoomAuthStatus(success) self._connector.sendControlledRoomAuthStatus(success, username)
def __lt__(self, b): def __lt__(self, b):
if self.getPosition() is None or self._file is None: if self.getPosition() is None or self._file is None: