This code seems not to work because loginTest locks up the system. loginVerified works but not until after loginTest return. How can this be done?
class Network(DirectObject.DirectObject): # we only need one instance of this!!
client = PandaNetworkingClient('journeytothestars.webhop.net', 9095)
while not client.startNetwork() : print 'init failed connect, retrying'
#messenger.toggleVerbose()
#print messenger
playerCount=0
print "hi network"
def __init__(self, avatarsAll, player, gameNode):
self.gameNode = gameNode
#self.terrain = terrain
self.playerDict = {}
self.avatarAll = avatarsAll # a list of Avatar instances
self.player = player
# need to check for errors here, I think
# SET UP broadcasting of data at set times.
self.accept(PLAYERMOVE, self.playerDataIn)
self.accept(STARTPLAYERS, self.startPlayersIn) # STARTPLAYERS
self.accept(REMOVEPLAYER, self.removePlayerIn)
self.accept(LOGINSTATUS, self.loginVerified)
def loginTest(self, email, password):
print '316 email, password', email, password
self.answer = 99
dataOut = {}
dataOut[PACKETTYPE] = LOGIN
dataOut[PLAYERID] = self.client.ID
dataOut[RECEIVER] = SERVER
dataOut[PASSWORD] = password
dataOut[EMAIL] = email
self.client.sendData(dataOut)
print 'waiting in while'
time = globalClock.getRealTime()
print time
while globalClock.getRealTime()-time < 10 :
pass
#print globalClock.getRealTime()-time # wait for network answer to come back, add time out here.
print 'out of while, answer', self.answer
return self.answer
def loginVerified(self, packet):
#print 'packet 326', packet
#packet[PACKETTYPE] = LOGIN
#packet[SENDER] = SERVER
#packet[LOGINSTATUS] = REJECTED
# maybe print checking message
#bad name try again
#bad password try again
#ok go to pickCharacter
print "got the packet 337"
self.answer = packet
if packet == ACCEPTED:
print 'logInStatus ACCEPTED'
else :
print 'login Status REJECTED'