Implement Chat: send server, chat messages from consoleUI
This commit is contained in:
parent
c71d99d8aa
commit
6444ef441f
@ -454,7 +454,11 @@ class SyncplayClient(object):
|
|||||||
self.userlist.currentUser.room = roomName
|
self.userlist.currentUser.room = roomName
|
||||||
if resetAutoplay:
|
if resetAutoplay:
|
||||||
self.resetAutoPlayState()
|
self.resetAutoPlayState()
|
||||||
|
|
||||||
|
def sendChat(self,message):
|
||||||
|
if self._protocol and self._protocol.logged:
|
||||||
|
self._protocol.sendChatMessage(message)
|
||||||
|
|
||||||
def sendRoom(self):
|
def sendRoom(self):
|
||||||
room = self.userlist.currentUser.room
|
room = self.userlist.currentUser.room
|
||||||
if self._protocol and self._protocol.logged and room:
|
if self._protocol and self._protocol.logged and room:
|
||||||
|
|||||||
@ -60,6 +60,7 @@ FILENAME_STRIP_REGEX = u"[-~_\.\[\](): ]"
|
|||||||
CONTROL_PASSWORD_STRIP_REGEX = u"[^a-zA-Z0-9\-]"
|
CONTROL_PASSWORD_STRIP_REGEX = u"[^a-zA-Z0-9\-]"
|
||||||
ROOM_NAME_STRIP_REGEX = u"^(\+)(?P<roomnamebase>.*)(:)(\w{12})$"
|
ROOM_NAME_STRIP_REGEX = u"^(\+)(?P<roomnamebase>.*)(:)(\w{12})$"
|
||||||
COMMANDS_UNDO = ["u", "undo", "revert"]
|
COMMANDS_UNDO = ["u", "undo", "revert"]
|
||||||
|
COMMANDS_CHAT = ["ch","chat"]
|
||||||
COMMANDS_LIST = ["l", "list", "users"]
|
COMMANDS_LIST = ["l", "list", "users"]
|
||||||
COMMANDS_PAUSE = ["p", "play", "pause"]
|
COMMANDS_PAUSE = ["p", "play", "pause"]
|
||||||
COMMANDS_ROOM = ["r", "room"]
|
COMMANDS_ROOM = ["r", "room"]
|
||||||
|
|||||||
@ -358,6 +358,7 @@ en = {
|
|||||||
"server-salt-argument" : "random string used to generate managed room passwords",
|
"server-salt-argument" : "random string used to generate managed room passwords",
|
||||||
"server-disable-ready-argument" : u"disable readiness feature",
|
"server-disable-ready-argument" : u"disable readiness feature",
|
||||||
"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-chat-argument" : "Should chat be enabled?",
|
||||||
"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.",
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,8 @@ class JSONCommandProtocol(LineReceiver):
|
|||||||
self.handleState(message[1])
|
self.handleState(message[1])
|
||||||
elif command == "Error":
|
elif command == "Error":
|
||||||
self.handleError(message[1])
|
self.handleError(message[1])
|
||||||
|
elif command == "Chat":
|
||||||
|
self.handleChat(message[1])
|
||||||
else:
|
else:
|
||||||
self.dropWithError(getMessage("unknown-command-server-error").format(message[1])) # TODO: log, not drop
|
self.dropWithError(getMessage("unknown-command-server-error").format(message[1])) # TODO: log, not drop
|
||||||
|
|
||||||
@ -153,7 +155,8 @@ class SyncClientProtocol(JSONCommandProtocol):
|
|||||||
def sendFileSetting(self, file_):
|
def sendFileSetting(self, file_):
|
||||||
self.sendSet({"file": file_})
|
self.sendSet({"file": file_})
|
||||||
self.sendList()
|
self.sendList()
|
||||||
|
def sendChatMessage(self,chatMessage):
|
||||||
|
self.sendMessage({"Chat": chatMessage})
|
||||||
def handleList(self, userList):
|
def handleList(self, userList):
|
||||||
self._client.userlist.clearList()
|
self._client.userlist.clearList()
|
||||||
for room in userList.iteritems():
|
for room in userList.iteritems():
|
||||||
@ -326,7 +329,8 @@ class SyncServerProtocol(JSONCommandProtocol):
|
|||||||
self._factory.addWatcher(self, username, roomName)
|
self._factory.addWatcher(self, username, roomName)
|
||||||
self._logged = True
|
self._logged = True
|
||||||
self.sendHello(version)
|
self.sendHello(version)
|
||||||
|
def handleChat(self,chatMessage):
|
||||||
|
#TODO
|
||||||
def setWatcher(self, watcher):
|
def setWatcher(self, watcher):
|
||||||
self._watcher = watcher
|
self._watcher = watcher
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import argparse
|
|||||||
from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion
|
from syncplay.utils import RoomPasswordProvider, NotControlledRoom, RandomStringGenerator, meetsMinVersion
|
||||||
|
|
||||||
class SyncFactory(Factory):
|
class SyncFactory(Factory):
|
||||||
def __init__(self, password='', motdFilePath=None, isolateRooms=False, salt=None, disableReady=False):
|
def __init__(self, password='', motdFilePath=None, isolateRooms=False, salt=None, disableReady=False,chat =False):
|
||||||
print getMessage("welcome-server-notification").format(syncplay.version)
|
print getMessage("welcome-server-notification").format(syncplay.version)
|
||||||
if password:
|
if password:
|
||||||
password = hashlib.md5(password).hexdigest()
|
password = hashlib.md5(password).hexdigest()
|
||||||
@ -25,6 +25,7 @@ class SyncFactory(Factory):
|
|||||||
self._salt = salt
|
self._salt = salt
|
||||||
self._motdFilePath = motdFilePath
|
self._motdFilePath = motdFilePath
|
||||||
self.disableReady = disableReady
|
self.disableReady = disableReady
|
||||||
|
self.chat=chat
|
||||||
if not isolateRooms:
|
if not isolateRooms:
|
||||||
self._roomManager = RoomManager()
|
self._roomManager = RoomManager()
|
||||||
else:
|
else:
|
||||||
@ -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('--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('--chat', action='store_true', help=getMessage("server-chat-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"))
|
||||||
@ -134,6 +134,9 @@ class ConsoleUI(threading.Thread):
|
|||||||
self._syncplayClient.playerPositionBeforeLastSeek = tmp_pos
|
self._syncplayClient.playerPositionBeforeLastSeek = tmp_pos
|
||||||
elif command.group('command') in constants.COMMANDS_LIST:
|
elif command.group('command') in constants.COMMANDS_LIST:
|
||||||
self._syncplayClient.getUserList()
|
self._syncplayClient.getUserList()
|
||||||
|
elif command.group('command') in constants.COMMANDS_CHAT:
|
||||||
|
message= command.group('parameter')
|
||||||
|
self._syncplayClient.sendChat(message)
|
||||||
elif command.group('command') in constants.COMMANDS_PAUSE:
|
elif command.group('command') in constants.COMMANDS_PAUSE:
|
||||||
self._syncplayClient.setPaused(not self._syncplayClient.getPlayerPaused())
|
self._syncplayClient.setPaused(not self._syncplayClient.getPlayerPaused())
|
||||||
elif command.group('command') in constants.COMMANDS_ROOM:
|
elif command.group('command') in constants.COMMANDS_ROOM:
|
||||||
|
|||||||
@ -19,6 +19,5 @@ from syncplay.server import SyncFactory, ConfigurationGetter
|
|||||||
if __name__ == '__main__':
|
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,args.chat))
|
||||||
reactor.listenTCP(int(args.port), SyncFactory(args.password, args.motd_file, args.isolate_rooms, args.salt, args.disable_ready))
|
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user