Some proper messages

This commit is contained in:
Uriziel 2012-12-10 21:11:49 +01:00
parent c567ce3c99
commit c89732e564
3 changed files with 13 additions and 12 deletions

View File

@ -5,6 +5,7 @@ import time
from twisted.internet.protocol import ClientFactory from twisted.internet.protocol import ClientFactory
from twisted.internet import reactor, task from twisted.internet import reactor, task
from syncplay.protocols import SyncClientProtocol from syncplay.protocols import SyncClientProtocol
import traceback
class SyncClientFactory(ClientFactory): class SyncClientFactory(ClientFactory):
def __init__(self, client, retry = 10): def __init__(self, client, retry = 10):
@ -18,22 +19,23 @@ class SyncClientFactory(ClientFactory):
def startedConnecting(self, connector): def startedConnecting(self, connector):
destination = connector.getDestination() destination = connector.getDestination()
self._client.ui.showMessage('Connecting to {}:{}'.format(destination.host, destination.port)) self._client.ui.showMessage('Attempting to connect to {}:{}'.format(destination.host, destination.port))
def clientConnectionLost(self, connector, reason): def clientConnectionLost(self, connector, reason):
traceback.print_stack()
if self._timesTried < self.retry: if self._timesTried < self.retry:
self._timesTried += 1 self._timesTried += 1
message = 'Connection lost, reconnecting' message = 'Connection with server lost, attempting to reconnecting'
self._client.ui.showMessage(message) self._client.ui.showMessage(message)
self.reconnecting = True self.reconnecting = True
reactor.callLater(0.1*(2**self._timesTried), connector.connect) reactor.callLater(0.1*(2**self._timesTried), connector.connect)
else: else:
message = 'Disconnected' message = 'Disconnected from server'
self._client.ui.showMessage(message) self._client.ui.showMessage(message)
def clientConnectionFailed(self, connector, reason): def clientConnectionFailed(self, connector, reason):
if not self.reconnecting: if not self.reconnecting:
message = 'Connection failed' message = 'Connection with server failed'
self._client.ui.showMessage(message) self._client.ui.showMessage(message)
self._client.stop(True) self._client.stop(True)
else: else:
@ -411,7 +413,7 @@ class SyncplayUserlist(object):
if(self.currentUser.file): if(self.currentUser.file):
fileHasSameSizeAsYour = user.file['size'] == self.currentUser.file['size'] fileHasSameSizeAsYour = user.file['size'] == self.currentUser.file['size']
fileHasSameNameYour = user.file['name'] == self.currentUser.file['name'] fileHasSameNameYour = user.file['name'] == self.currentUser.file['name']
differentFileMessage = " (but their file size is different from yours!)" differentFileMessage = " (their file size is different from yours!)"
message += differentFileMessage if not fileHasSameSizeAsYour and fileHasSameNameYour else "" message += differentFileMessage if not fileHasSameSizeAsYour and fileHasSameNameYour else ""
return message return message

View File

@ -124,9 +124,7 @@ class MPCHCAPIPlayer(BasePlayer):
self.__client.updatePlayerStatus(self.__client.getGlobalPaused(), self.__client.getGlobalPosition()) self.__client.updatePlayerStatus(self.__client.getGlobalPaused(), self.__client.getGlobalPosition())
def __forcePause(self, paused): def __forcePause(self, paused):
i = 0 while(paused <> self._mpcApi.isPaused()):
while(paused <> self._mpcApi.isPaused() and i < 35):
i += 1
self.setPaused(paused) self.setPaused(paused)
time.sleep(0.1) time.sleep(0.1)
time.sleep(0.1) time.sleep(0.1)

View File

@ -18,16 +18,16 @@ class JSONCommandProtocol(LineReceiver):
elif command == "State": elif command == "State":
self.handleState(message[1]) self.handleState(message[1])
elif command == "Error": elif command == "Error":
self.handleState(message[1]) self.handleError(message[1])
else: else:
self.dropWithError("Unknown Command\n" + message[1]) #TODO: log, not drop self.dropWithError("Unknown Command\n" + message[1]) #TODO: log, not drop
def printReceived(self, line): #TODO: remove def printReceived(self, line): #TODO: remove
# print ">>i", line #print ">>i", line
pass pass
def printSent(self, line): def printSent(self, line):
# print "o<<", line #print "o<<", line
pass pass
def lineReceived(self, line): def lineReceived(self, line):
@ -68,7 +68,6 @@ class SyncClientProtocol(JSONCommandProtocol):
self._client.destroyProtocol() self._client.destroyProtocol()
def dropWithError(self, error): def dropWithError(self, error):
print error
self._client.ui.showErrorMessage(error) self._client.ui.showErrorMessage(error)
self._client.protocolFactory.stopRetrying() self._client.protocolFactory.stopRetrying()
self.drop() self.drop()
@ -89,6 +88,7 @@ class SyncClientProtocol(JSONCommandProtocol):
self._client.setUsername(username) self._client.setUsername(username)
self._client.setRoom(roomName) self._client.setRoom(roomName)
self.logged = True self.logged = True
self._client.ui.showMessage("Successfully connected to server")
self._client.sendFile() self._client.sendFile()
def sendHello(self): def sendHello(self):
@ -237,6 +237,7 @@ class SyncServerProtocol(JSONCommandProtocol):
def dropWithError(self, error): def dropWithError(self, error):
print "Client drop: %s -- %s" % (self.transport.getPeer().host, error) print "Client drop: %s -- %s" % (self.transport.getPeer().host, error)
self.sendError(error)
self.drop() self.drop()
def connectionLost(self, reason): def connectionLost(self, reason):