Poodletooth-iLand/otp/friends/FriendManagerAI.py

120 lines
4.7 KiB
Python
Raw Normal View History

2015-03-03 22:10:12 +00:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
class FriendManagerAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("FriendManagerAI")
def __init__(self, air):
DistributedObjectAI.__init__(self, air)
self.air = air
self.currentContext = 0
self.requests = {}
def friendQuery(self, requested):
avId = self.air.getAvatarIdFromSender()
2015-05-31 08:56:15 +00:00
av = self.air.doId2do.get(avId)
if not av:
2015-03-03 22:10:12 +00:00
self.air.writeServerEvent('suspicious', avId, 'Player tried to friend a player that does not exist!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
context = self.currentContext
self.requests[context] = [ [ avId, requested ], 'friendQuery']
self.currentContext += 1
2015-05-31 08:56:15 +00:00
self.sendUpdateToAvatarId(requested, 'inviteeFriendQuery', [avId, av.getName(), av.getDNAString(), context])
2015-03-03 22:10:12 +00:00
def cancelFriendQuery(self, context):
avId = self.air.getAvatarIdFromSender()
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if not context in self.requests:
self.air.writeServerEvent('suspicious', avId, 'Player tried to cancel a request that doesn\'t exist!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if avId != self.requests[context][0][0]:
self.air.writeServerEvent('suspicious', avId, 'Player tried to cancel someone elses request!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
self.requests[context][1] = 'cancelled'
self.sendUpdateToAvatarId(self.requests[context][0][1], 'inviteeCancelFriendQuery', [context])
def inviteeFriendConsidering(self, yesNo, context):
avId = self.air.getAvatarIdFromSender()
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if not context in self.requests:
self.air.writeServerEvent('suspicious', avId, 'Player tried to consider a friend request that doesn\'t exist!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if avId != self.requests[context][0][1]:
self.air.writeServerEvent('suspicious', avId, 'Player tried to consider for someone else!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if self.requests[context][1] != 'friendQuery':
self.air.writeServerEvent('suspicious', avId, 'Player tried to reconsider friend request!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if yesNo != 1:
self.sendUpdateToAvatarId(self.requests[context][0][0], 'friendConsidering', [yesNo, context])
del self.requests[context]
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
self.requests[context][1] = 'friendConsidering'
self.sendUpdateToAvatarId(self.requests[context][0][0], 'friendConsidering', [yesNo, context])
def inviteeFriendResponse(self, response, context):
avId = self.air.getAvatarIdFromSender()
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if not context in self.requests:
self.air.writeServerEvent('suspicious', avId, 'Player tried to respond to a friend request that doesn\'t exist!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if avId != self.requests[context][0][1]:
self.air.writeServerEvent('suspicious', avId, 'Player tried to respond to someone else\'s request!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if self.requests[context][1] == 'cancelled':
self.air.writeServerEvent('suspicious', avId, 'Player tried to respond to non-active friend request!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
self.sendUpdateToAvatarId(self.requests[context][0][0], 'friendResponse', [response, context])
2015-05-31 08:56:15 +00:00
if response == 1:
2015-03-03 22:10:12 +00:00
requested = self.requests[context][0][1]
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if requested in self.air.doId2do:
requested = self.air.doId2do[requested]
else:
del self.requests[context]
return
requester = self.requests[context][0][0]
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if requester in self.air.doId2do:
requester = self.air.doId2do[requester]
else:
del self.requests[context]
return
2015-05-31 11:12:48 +00:00
requested.extendFriendsList(requester.getDoId())
requester.extendFriendsList(requested.getDoId())
2015-03-03 22:10:12 +00:00
requested.d_setFriendsList(requested.getFriendsList())
requester.d_setFriendsList(requester.getFriendsList())
2015-05-31 08:56:15 +00:00
del self.requests[context]
2015-03-03 22:10:12 +00:00
def inviteeAcknowledgeCancel(self, context):
avId = self.air.getAvatarIdFromSender()
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if not context in self.requests:
self.air.writeServerEvent('suspicious', avId, 'Player tried to acknowledge the cancel of a friend request that doesn\'t exist!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if avId != self.requests[context][0][1]:
self.air.writeServerEvent('suspicious', avId, 'Player tried to acknowledge someone else\'s cancel!')
return
2015-05-31 08:56:15 +00:00
2015-03-03 22:10:12 +00:00
if self.requests[context][1] != 'cancelled':
self.air.writeServerEvent('suspicious', avId, 'Player tried to cancel non-cancelled request!')
return
2015-06-20 09:24:08 +00:00
del self.requests[context]