login: avatar list retrieval

This commit is contained in:
Open Toontown 2019-11-15 21:15:38 -05:00
parent ce212e83d2
commit 239de4ae62
6 changed files with 135 additions and 8 deletions

View file

@ -226,7 +226,7 @@ dclass DistributedAvatar : DistributedSmoothNode, TalkPath_owner, TalkPath_whisp
confirmAvOnShard(uint32, int8); confirmAvOnShard(uint32, int8);
}; };
struct friendEntry { struct FriendEntry {
uint32 friendId; uint32 friendId;
uint8 friendCode; uint8 friendCode;
} }
@ -244,7 +244,7 @@ dclass DistributedPlayer : DistributedAvatar {
setWhitelistChatFlags(uint8) broadcast ownrecv ram airecv; setWhitelistChatFlags(uint8) broadcast ownrecv ram airecv;
setSC(uint16) broadcast ownsend airecv; setSC(uint16) broadcast ownsend airecv;
setSCCustom(uint16) broadcast ownsend airecv; setSCCustom(uint16) broadcast ownsend airecv;
setFriendsList(friendEntry[]) ownrecv required db airecv; setFriendsList(FriendEntry[]) ownrecv required db airecv;
setDISLname(string) broadcast ownrecv ram; setDISLname(string) broadcast ownrecv ram;
setDISLid(uint32) broadcast ownrecv ram db airecv required; setDISLid(uint32) broadcast ownrecv ram db airecv required;
OwningAccount(uint32); OwningAccount(uint32);
@ -521,7 +521,17 @@ dclass CallbackObject {
callback(uint32, bool, uint8); callback(uint32, bool, uint8);
}; };
struct PotentialAvatar {
uint32 avNum;
string avName;
string avDNA;
uint8 avPosition;
uint8 nameState;
};
dclass AstronLoginManager : DistributedObject { dclass AstronLoginManager : DistributedObject {
requestLogin(string) clsend; requestLogin(string) clsend;
loginResponse(blob); loginResponse(blob);
requestAvatarList() clsend;
avatarListResponse(PotentialAvatar[]);
}; };

View file

@ -459,7 +459,7 @@ dclass DistributedToon : DistributedPlayer {
setTrackBonusLevel(int8[]) required broadcast ownrecv db; setTrackBonusLevel(int8[]) required broadcast ownrecv db;
setInventory(blob) required ownrecv db; setInventory(blob) required ownrecv db;
setMaxNPCFriends(uint16) required ownrecv db; setMaxNPCFriends(uint16) required ownrecv db;
setNPCFriendsDict(friendEntry[]) required ownrecv db; setNPCFriendsDict(FriendEntry[]) required ownrecv db;
setDefaultShard(uint32) required ownrecv db; setDefaultShard(uint32) required ownrecv db;
setDefaultZone(uint32) required ownrecv db; setDefaultZone(uint32) required ownrecv db;
setShtickerBook(blob) required ownrecv db; setShtickerBook(blob) required ownrecv db;
@ -3269,4 +3269,3 @@ dclass DistributedTrashcanZeroMgr : DistributedPhaseEventMgr {
dclass DistributedSillyMeterMgr : DistributedPhaseEventMgr { dclass DistributedSillyMeterMgr : DistributedPhaseEventMgr {
}; };

View file

@ -959,10 +959,7 @@ class OTPClientRepository(ClientRepositoryBase):
if not self.astronSupport: if not self.astronSupport:
self.sendGetAvatarsMsg() self.sendGetAvatarsMsg()
else: else:
# TODO SET UP PROPERLY self.astronLoginManager.sendRequestAvatarList()
#self.astronLoginManager.sendRequestAvatarList()
self.avList = []
self.loginFSM.request('chooseAvatar', [self.avList])
self.waitForDatabaseTimeout(requestName='WaitForAvatarList') self.waitForDatabaseTimeout(requestName='WaitForAvatarList')
self.acceptOnce(OtpAvatarManager.OtpAvatarManager.OnlineEvent, self._requestAvatarList) self.acceptOnce(OtpAvatarManager.OtpAvatarManager.OnlineEvent, self._requestAvatarList)
@ -2356,6 +2353,28 @@ class OTPClientRepository(ClientRepositoryBase):
# We're done. # We're done.
dclass.stopGenerate() dclass.stopGenerate()
def handleAvatarListResponse(self, avatarList):
avList = []
for avNum, avName, avDNA, avPosition, nameState in avatarList:
avNames = ['',
'',
'',
'']
avNames[0] = avName
if nameState == 2: # Pending
avNames[1] = avName
elif nameState == 3: # Approved
avNames[2] = avName
elif nameState == 4: # Rejected
avNames[3] = avName
aname = int(nameState == 1)
potAv = PotentialAvatar(avNum, avNames, avDNA, avPosition, aname)
avList.append(potAv)
self.avList = avList
self.loginFSM.request('chooseAvatar', [self.avList])
def handleGenerateWithRequiredOtherOwner(self, di): def handleGenerateWithRequiredOtherOwner(self, di):
classId = di.getUint16() classId = di.getUint16()
doId = di.getUint32() doId = di.getUint32()

View file

@ -12,3 +12,6 @@ class OTPInternalRepository(AstronInternalRepository):
def handleConnected(self): def handleConnected(self):
AstronInternalRepository.handleConnected(self) AstronInternalRepository.handleConnected(self)
def getAccountIdFromSender(self):
return (self.getMsgSender() >> 32) & 0xFFFFFFFF

View file

@ -5,6 +5,7 @@ import time
from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from otp.uberdog.AccountDetailRecord import AccountDetailRecord from otp.uberdog.AccountDetailRecord import AccountDetailRecord
from otp.distributed.PotentialAvatar import PotentialAvatar
class AstronLoginManager(DistributedObjectGlobal): class AstronLoginManager(DistributedObjectGlobal):
notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManager') notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManager')
@ -113,3 +114,9 @@ class AstronLoginManager(DistributedObjectGlobal):
self.notify.warning('account days is negative %s' % accountDays) self.notify.warning('account days is negative %s' % accountDays)
self.notify.debug('result=%s' % result) self.notify.debug('result=%s' % result)
return result return result
def sendRequestAvatarList(self):
self.sendUpdate('requestAvatarList')
def avatarListResponse(self, avatarList):
self.cr.handleAvatarListResponse(avatarList)

View file

@ -163,6 +163,7 @@ class LoginOperation:
} }
responseBlob = json.dumps(responseData) responseBlob = json.dumps(responseData)
self.loginManager.sendUpdateToChannel(self.sender, 'loginResponse', [responseBlob]) self.loginManager.sendUpdateToChannel(self.sender, 'loginResponse', [responseBlob])
del self.loginManager.sender2loginOperation[self.sender]
def getLastLoggedInStr(self): def getLastLoggedInStr(self):
return '' # TODO return '' # TODO
@ -186,6 +187,79 @@ class LoginOperation:
return accountDays return accountDays
class GetAvatarsOperation:
def __init__(self, loginManager, sender):
self.loginManager = loginManager
self.sender = sender
self.account = None
self.avList = []
self.pendingAvatars = None
self.avatarFields = None
def start(self):
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.sender, self.__handleAccountRetrieved)
def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu
return
self.account = fields
self.avList = self.account['ACCOUNT_AV_SET']
self.avList = self.avList[:6]
self.avList += [0] * (6 - len(self.avList))
self.__handleQueryAvatars()
def __handleQueryAvatars(self):
self.pendingAvatars = set()
self.avatarFields = {}
for avId in self.avList:
if avId:
self.pendingAvatars.add(avId)
def response(dclass, fields, avId=avId):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# mayonnaise
return
self.avatarFields[avId] = fields
self.pendingAvatars.remove(avId)
if not self.pendingAvatars:
self.__handleSendAvatars()
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, avId, response)
if not self.pendingAvatars:
self.__handleSendAvatars()
def __handleSendAvatars(self):
potentialAvatars = []
for avId, fields in self.avatarFields.items():
index = self.avList.index(avId)
wishNameState = fields.get('WishNameState', [''])[0]
name = fields['setName'][0]
nameState = 0
if wishNameState == 'OPEN':
nameState = 1
elif wishNameState == 'PENDING':
nameState = 2
elif wishNameState == 'APPROVED':
nameState = 3
name = fields['WishName'][0]
elif wishNameState == 'REJECTED':
nameState = 4
elif wishNameState == 'LOCKED':
nameState = 0
else:
# unknown name state.
nameState = 0
potentialAvatars.append([avId, name, fields['setDNAString'][0], index, nameState])
self.loginManager.sendUpdateToAccountId(self.sender, 'avatarListResponse', [potentialAvatars])
del self.loginManager.account2operation[self.sender]
class AstronLoginManagerUD(DistributedObjectGlobalUD): class AstronLoginManagerUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManagerUD') notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManagerUD')
@ -193,6 +267,7 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
DistributedObjectGlobalUD.__init__(self, air) DistributedObjectGlobalUD.__init__(self, air)
self.accountDb = None self.accountDb = None
self.sender2loginOperation = {} self.sender2loginOperation = {}
self.account2operation = {}
def announceGenerate(self): def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self) DistributedObjectGlobalUD.announceGenerate(self)
@ -212,3 +287,17 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
newLoginOperation = LoginOperation(self, sender) newLoginOperation = LoginOperation(self, sender)
self.sender2loginOperation[sender] = newLoginOperation self.sender2loginOperation[sender] = newLoginOperation
newLoginOperation.start(playToken) newLoginOperation.start(playToken)
def requestAvatarList(self):
sender = self.air.getAccountIdFromSender()
if not sender:
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = GetAvatarsOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start()