mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2025-01-09 17:53:50 +00:00
Implement name accepting using login server
This commit is contained in:
parent
3eb20db6da
commit
2a2e325a92
1 changed files with 34 additions and 18 deletions
|
@ -47,6 +47,24 @@ def executeHttpRequest(url, **extras):
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def executeHttpRequestAndLog(url, **extras):
|
||||||
|
response = executeHttpRequest(url, extras)
|
||||||
|
|
||||||
|
if response is None:
|
||||||
|
self.notify.error('A request to ' + url + ' went wrong.')
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
json = json.loads(response)
|
||||||
|
except:
|
||||||
|
self.notify.error('Malformed response from ' + url + '.')
|
||||||
|
return None
|
||||||
|
|
||||||
|
if json['error']:
|
||||||
|
self.notify.warning('Error from ' + url + ':' + json['error'])
|
||||||
|
return None
|
||||||
|
|
||||||
|
return json
|
||||||
|
|
||||||
#blacklist = executeHttpRequest('names/blacklist.json')
|
#blacklist = executeHttpRequest('names/blacklist.json')
|
||||||
#if blacklist:
|
#if blacklist:
|
||||||
|
@ -85,13 +103,13 @@ class AccountDB:
|
||||||
self.dbm = anydbm.open(filename, 'c')
|
self.dbm = anydbm.open(filename, 'c')
|
||||||
|
|
||||||
def addNameRequest(self, avId, name):
|
def addNameRequest(self, avId, name):
|
||||||
return 'Success'
|
return True
|
||||||
|
|
||||||
def getNameStatus(self, avId):
|
def getNameStatus(self, avId):
|
||||||
return 'APPROVED'
|
return 'APPROVED'
|
||||||
|
|
||||||
def removeNameRequest(self, avId):
|
def removeNameRequest(self, avId):
|
||||||
return 'Success'
|
pass
|
||||||
|
|
||||||
def lookup(self, username, callback):
|
def lookup(self, username, callback):
|
||||||
pass # Inheritors should override this.
|
pass # Inheritors should override this.
|
||||||
|
@ -112,7 +130,6 @@ class DeveloperAccountDB(AccountDB):
|
||||||
def lookup(self, username, callback):
|
def lookup(self, username, callback):
|
||||||
# Let's check if this user's ID is in your account database bridge:
|
# Let's check if this user's ID is in your account database bridge:
|
||||||
if str(username) not in self.dbm:
|
if str(username) not in self.dbm:
|
||||||
|
|
||||||
# Nope. Let's associate them with a brand new Account object! We
|
# Nope. Let's associate them with a brand new Account object! We
|
||||||
# will assign them with 700 access just because they are a
|
# will assign them with 700 access just because they are a
|
||||||
# developer:
|
# developer:
|
||||||
|
@ -122,31 +139,32 @@ class DeveloperAccountDB(AccountDB):
|
||||||
'accountId': 0,
|
'accountId': 0,
|
||||||
'accessLevel': max(700, minAccessLevel)
|
'accessLevel': max(700, minAccessLevel)
|
||||||
}
|
}
|
||||||
callback(response)
|
|
||||||
return response
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# We have an account already, let's return what we've got:
|
# We have an account already, let's return what we've got:
|
||||||
response = {
|
response = {
|
||||||
'success': True,
|
'success': True,
|
||||||
'userId': username,
|
'userId': username,
|
||||||
'accountId': int(self.dbm[str(username)]),
|
'accountId': int(self.dbm[str(username)]),
|
||||||
}
|
}
|
||||||
callback(response)
|
callback(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
class RemoteAccountDB(AccountDB):
|
class RemoteAccountDB(AccountDB):
|
||||||
notify = directNotify.newCategory('RemoteAccountDB')
|
notify = directNotify.newCategory('RemoteAccountDB')
|
||||||
|
|
||||||
def addNameRequest(self, avId, name):
|
def addNameRequest(self, avId, name):
|
||||||
return None#executeHttpRequest('names/append', ID=str(avId), Name=name)
|
executeHttpRequestAndLog('nameadd', id=avId, name=name)
|
||||||
|
|
||||||
def getNameStatus(self, avId):
|
def getNameStatus(self, avId):
|
||||||
return None#executeHttpRequest('names/status/?Id=' + str(avId))
|
json = executeHttpRequestAndLog('nameget', id=avId)
|
||||||
|
|
||||||
|
if json is None:
|
||||||
|
return 'PENDING'
|
||||||
|
|
||||||
|
return json['state']
|
||||||
|
|
||||||
def removeNameRequest(self, avId):
|
def removeNameRequest(self, avId):
|
||||||
return None#executeHttpRequest('names/remove', ID=str(avId))
|
executeHttpRequestAndLog('nameremove', id=avId)
|
||||||
|
|
||||||
def lookup(self, token, callback):
|
def lookup(self, token, callback):
|
||||||
if (not token) or (len(token) != 36):
|
if (not token) or (len(token) != 36):
|
||||||
|
@ -171,12 +189,11 @@ class RemoteAccountDB(AccountDB):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
username = str(cookie['username'])
|
username = str(cookie['username'])
|
||||||
accessLevel = max(cookie['accessLevel'], minAccessLevel)
|
|
||||||
response = {
|
response = {
|
||||||
'success': True,
|
'success': True,
|
||||||
'userId': username,
|
'userId': username,
|
||||||
'accountId': int(self.dbm[username]) if username in self.dbm else 0,
|
'accountId': int(self.dbm[username]) if username in self.dbm else 0,
|
||||||
'accessLevel': accessLevel
|
'accessLevel': max(cookie['accessLevel'], minAccessLevel)
|
||||||
}
|
}
|
||||||
callback(response)
|
callback(response)
|
||||||
return response
|
return response
|
||||||
|
@ -654,16 +671,15 @@ class SetNameTypedFSM(AvatarOperationFSM):
|
||||||
status = judgeName(self.name)
|
status = judgeName(self.name)
|
||||||
|
|
||||||
if self.avId and status:
|
if self.avId and status:
|
||||||
resp = self.csm.accountDB.addNameRequest(self.avId, self.name)
|
if self.csm.accountDB.addNameRequest(self.avId, self.name):
|
||||||
if resp != 'Success':
|
|
||||||
status = False
|
|
||||||
else:
|
|
||||||
self.csm.air.dbInterface.updateObject(
|
self.csm.air.dbInterface.updateObject(
|
||||||
self.csm.air.dbId,
|
self.csm.air.dbId,
|
||||||
self.avId,
|
self.avId,
|
||||||
self.csm.air.dclassesByName['DistributedToonUD'],
|
self.csm.air.dclassesByName['DistributedToonUD'],
|
||||||
{'WishNameState': ('PENDING',),
|
{'WishNameState': ('PENDING',),
|
||||||
'WishName': (self.name,)})
|
'WishName': (self.name,)})
|
||||||
|
else:
|
||||||
|
status = False
|
||||||
|
|
||||||
if self.avId:
|
if self.avId:
|
||||||
self.csm.air.writeServerEvent('avatarWishname', self.avId, self.name)
|
self.csm.air.writeServerEvent('avatarWishname', self.avId, self.name)
|
||||||
|
|
Loading…
Reference in a new issue