lobby manager

This commit is contained in:
Zach 2015-05-30 09:01:18 -05:00
parent 2b8298856f
commit e3832ffac7
11 changed files with 317 additions and 5 deletions

View file

@ -500,6 +500,7 @@ from toontown.safezone import DistributedChineseCheckers/AI
from toontown.safezone import DistributedCheckers/AI
from toontown.safezone import DistributedFindFour/AI
from toontown.uberdog.DistributedPartyManager/AI/UD import DistributedPartyManager/AI/UD
from toontown.uberdog.DistributedLobbyManager/AI/UD import DistributedLobbyManager/AI/UD
from toontown.coderedemption.TTCodeRedemptionMgr/AI import TTCodeRedemptionMgr/AI
from toontown.cogdominium import DistributedCogdoInterior/AI
from toontown.cogdominium import DistributedCogdoBattleBldg/AI
@ -516,6 +517,7 @@ from toontown.cogdominium import DistCogdoCrane/AI
from toontown.cogdominium import DistCogdoCraneMoneyBag/AI
from toontown.cogdominium import DistCogdoCraneCog/AI
from toontown.parties.GlobalPartyManager/AI/UD import GlobalPartyManager/AI/UD
from toontown.uberdog.GlobalLobbyManager/AI/UD import GlobalLobbyManager/AI/UD
from toontown.uberdog.ARGManager/AI/UD import ARGManager/AI/UD
struct GiftItem {
@ -557,6 +559,11 @@ struct activity {
uint8 h;
};
struct lobby {
uint64 lobbyId;
uint32 hostId;
};
struct party {
uint64 partyId;
uint32 hostId;
@ -3204,6 +3211,36 @@ dclass DistributedFindFour : DistributedNode {
tie() broadcast;
};
dclass DistributedLobbyManager : DistributedObject {
addLobby(uint32, uint32, string, string, int8, int8, activity [], decoration [], uint32[], uint16);
addLobbyRequest(uint32) airecv clsend;
addLobbyResponse(uint32, int8);
addLobbyResponseUdToAi(uint64, int8, lobby) airecv;
getLobbyZone(uint32, uint32, uint8) clsend airecv;
receiveLobbyZone(uint32, uint64, uint32);
freeZoneIdFromCreatedLobby(uint32, uint32) clsend airecv;
sendAvToPlayground(uint32, uint8);
exitParty(uint32) clsend airecv;
toonHasEnteredPartyAiToUd(uint32);
toonHasExitedPartyAiToUd(uint32);
lobbyManagerAIStartingUp(uint32, uint32);
lobbyManagerAIGoingDown(uint32, uint32);
lobbyHasFinishedUdToAllAi(uint64 lobbyId) airecv;
requestShardIdZoneIdForHostId(uint32) clsend airecv;
sendShardIdZoneIdToAvatar(uint32, uint32);
lobbyManagerUdStartingUp() airecv;
lobbyManagerUdLost() airecv;
receiveId(uint64 ids[]) airecv;
};
dclass DistributedPartyManager : DistributedObject {
addParty(uint32, uint32, string, string, int8, int8, activity [], decoration [], uint32[], uint16);
addPartyRequest(uint32, char [0-256], char [0-256], int8, int8, activity [], decoration [], uint32[]) airecv clsend;
@ -3258,6 +3295,17 @@ dclass DistributedPartyManager : DistributedObject {
dclass DistributedObjectGlobal : DistributedObject {
};
dclass GlobalLobbyManager : DistributedObjectGlobal {
lobbyManagerAIHello(uint32 channel);
queryLobby(uint32 hostId);
addLobby(DoId avId, uint64 lobbyId);
toonJoinedLobby(uint64 lobbyId, uint32 avId);
toonLeftLobby(uint64 lobbyId, uint32 avId);
requestLobbySlot(uint64 lobbyId, uint32 avId);
lobbyDone(uint64 lobbyId);
allocIds(uint16 count);
};
dclass GlobalPartyManager : DistributedObjectGlobal {
partyManagerAIHello(uint32 channel);
queryParty(uint32 hostId);

View file

@ -2,7 +2,7 @@
from pandac.PandaModules import *
hashVal = 210530844
hashVal = 3800363077L
from toontown.coghq import DistributedCashbotBossSafe, DistributedCashbotBossCrane, DistributedBattleFactory, DistributedCashbotBossTreasure, DistributedCogHQDoor, DistributedCogHQExteriorDoor, DistributedSellbotHQDoor, DistributedFactoryElevatorExt, DistributedMintElevatorExt, DistributedLawOfficeElevatorExt, DistributedLawOfficeElevatorInt, LobbyManager, DistributedMegaCorp, DistributedFactory, DistributedLawOffice, DistributedLawOfficeFloor, DistributedLift, DistributedDoorEntity, DistributedSwitch, DistributedButton, DistributedTrigger, DistributedCrushableEntity, DistributedCrusherEntity, DistributedStomper, DistributedStomperPair, DistributedLaserField, DistributedGolfGreenGame, DistributedSecurityCamera, DistributedMover, DistributedElevatorMarker, DistributedBarrelBase, DistributedGagBarrel, DistributedBeanBarrel, DistributedHealBarrel, DistributedGrid, ActiveCell, DirectionalCell, CrusherCell, DistributedCrate, DistributedSinkingPlatform, BattleBlocker, DistributedMint, DistributedMintRoom, DistributedMintBattle, DistributedStage, DistributedStageRoom, DistributedStageBattle, DistributedLawbotBossGavel, DistributedLawbotCannon, DistributedLawbotChair, DistributedCogKart, DistributedCountryClub, DistributedCountryClubRoom, DistributedMoleField, DistributedCountryClubBattle, DistributedMaze, DistributedFoodBelt, DistributedBanquetTable, DistributedGolfSpot
@ -30,9 +30,11 @@ from toontown.parties import DistributedParty, DistributedPartyActivity, Distrib
from toontown.pets.DistributedPet import *
from toontown.friends import TTSFriendsManager
from toontown.cogdominium import DistributedCogdoInterior, DistributedCogdoBattleBldg, DistributedCogdoElevatorExt, DistributedCogdoElevatorInt, DistributedCogdoBarrel, DistCogdoGame, DistCogdoLevelGame, DistCogdoBoardroomGame, DistCogdoCraneGame, DistCogdoMazeGame, DistCogdoFlyingGame, DistCogdoCrane, DistCogdoCraneMoneyBag, DistCogdoCraneCog
from toontown.uberdog.GlobalLobbyManager import GlobalLobbyManager
from toontown.uberdog.ARGManager import ARGManager
from otp.distributed import Account, DistributedDistrict, DistributedDirectory
from toontown.estate import DistributedCannon, DistributedTarget, EstateManager, DistributedEstate, DistributedHouse, DistributedHouseInterior, DistributedGarden, DistributedHouseDoor, DistributedMailbox, DistributedFurnitureManager, DistributedFurnitureItem, DistributedBank, DistributedCloset, DistributedTrunk, DistributedPhone, DistributedFireworksCannon, DistributedLawnDecor, DistributedGardenPlot, DistributedGardenBox, DistributedFlower, DistributedGagTree, DistributedStatuary, DistributedToonStatuary, DistributedChangingStatuary, DistributedAnimatedStatuary, DistributedPlantBase, DistributedLawnDecor
from toontown.uberdog.DistributedLobbyManager import DistributedLobbyManager
from toontown.toon import DistributedToon, DistributedNPCToonBase, DistributedNPCToon, DistributedSmartNPC, DistributedNPCSpecialQuestGiver, DistributedNPCFlippyInToonHall, DistributedNPCScientist, DistributedNPCClerk, DistributedNPCTailor, DistributedNPCBlocker, DistributedNPCFisherman, DistributedNPCPartyPerson, DistributedNPCPetclerk, DistributedNPCKartClerk, DistributedNPCGlove, DistributedNPCLaffRestock
from toontown.tutorial import DistributedBattleTutorial, TutorialManager
from toontown.pets import DistributedPetProxy

View file

@ -6,6 +6,7 @@ OTP_DO_ID_TTS_FRIENDS_MANAGER = 4666
OPT_DO_ID_GROUP_MANAGER = 4667
OTP_DO_ID_TTS_ARG_MANAGER = 4668
OTP_DO_ID_GLOBAL_PARTY_MANAGER = 4477
OTP_DO_ID_GLOBAL_LOBBY_MANAGER = 4478
OTP_DO_ID_CHAT_MANAGER = 4681
OTP_ZONE_ID_MANAGEMENT = 2
OTP_ZONE_ID_DISTRICTS = 3

View file

@ -52,7 +52,7 @@ from toontown.toon import NPCToons
from toontown.toonbase import ToontownGlobals
from toontown.tutorial.TutorialManagerAI import TutorialManagerAI
from toontown.uberdog.DistributedPartyManagerAI import DistributedPartyManagerAI
from toontown.uberdog.DistributedLobbyManagerAI import DistributedLobbyManagerAI
class ToontownAIRepository(ToontownInternalRepository):
def __init__(self, baseChannel, stateServerChannel, districtName):
@ -140,6 +140,10 @@ class ToontownAIRepository(ToontownInternalRepository):
self.partyManager.generateWithRequired(2)
self.globalPartyMgr = self.generateGlobalObject(
OTP_DO_ID_GLOBAL_PARTY_MANAGER, 'GlobalPartyManager')
self.lobbyManager = DistributedLobbyManagerAI(self)
self.lobbyManager.generateWithRequired(2)
self.globalLobbyMgr = self.generateGlobalObject(
OTP_DO_ID_GLOBAL_LOBBY_MANAGER, 'GlobalLobbyManager')
def createSafeZones(self):
NPCToons.generateZone2NpcDict()

View file

@ -71,6 +71,7 @@ class ToontownClientRepository(OTPClientRepository.OTPClientRepository):
self.newsManager = None
self.distributedDistrict = None
self.partyManager = None
self.lobbyManager = None
self.toontownTimeManager = ToontownTimeManager.ToontownTimeManager()

View file

@ -51,7 +51,7 @@ class DistributedLobbyManager(DistributedObject):
def receiveLobbyZone(self, hostId, lobbyId, zoneId):
if lobbyId != 0 and zoneId != 0:
if base.localAvatar.doId == hostId:
lobbyInfo = base.localAvatar.hostedLobby:
lobbyInfo = base.localAvatar.hostedLobby
if lobbyInfo.lobbyId == lobbyId:
lobbyInfo.status == LobbyGlobals.LobbyStatus.Open
messenger.send('requestLobbyZoneComplete', [hostId, lobbyId, zoneId])
@ -66,5 +66,4 @@ class DistributedLobbyManager(DistributedObject):
def sendShardIdZoneIdToAvatar(self, shardId, zoneId):
# Avatar goes through door.
pass

View file

@ -7,3 +7,54 @@ class DistributedLobbyManagerUD(DistributedObjectUD):
def announceGenerate(self):
DistributedObjectUD.announceGenerate(self)
self.sendUpdate('lobbyManagerUdStartingUp')
def addLobby(self, todo0, todo1, todo2, todo3):
pass
def addLobbyRequest(self, hostId):
pass
def addLobbyResponse(self, hostId, errorCode):
pass
def getLobbyZone(self, avId, zoneId, isAvAboutToCreateLobby):
pass
def receiveLobbyZone(self, todo0, todo1, todo2):
pass
def freeZoneIdFromCreatedLobby(self, avId, zoneId):
pass
def sendAvToPlayground(self, todo0, todo1):
pass
def exitParty(self, zoneIdOfAv):
pass
def lobbyManagerAIStartingUp(self, todo0, todo1):
pass
def lobbyManagerAIGoingDown(self, todo0, todo1):
pass
def lobbyHasStartedAiToUd(self, todo0, todo1, todo2, todo3, todo4):
pass
def requestShardIdZoneIdForHostId(self, hostId):
pass
def sendShardIdZoneIdToAvatar(self, shardId, zoneId):
pass
def toonHasEnteredPartyAiToUd(self, todo0):
pass
def toonHasExitedPartyAiToUd(self, todo0):
pass
def lobbyHasFinishedUdToAllAi(self, todo0):
pass
def lobbyManagerUdStartingUp(self):
pass

View file

@ -0,0 +1,6 @@
from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal
from direct.distributed.PyDatagram import *
from direct.directnotify.DirectNotifyGlobal import directNotify
class GlobalLobbyManager(DistributedObjectGlobal):
notify = directNotify.newCategory('GlobalLobbyManager')

View file

@ -0,0 +1,52 @@
from direct.distributed.DistributedObjectGlobalAI import DistributedObjectGlobalAI
from direct.distributed.PyDatagram import *
from direct.directnotify.DirectNotifyGlobal import directNotify
class GlobalLobbyManagerAI(DistributedObjectGlobalAI):
notify = directNotify.newCategory('GlobalLobbyManagerAI')
def announceGenerate(self):
DistributedObjectGlobalAI.announceGenerate(self)
self.sendUpdate('lobbyManagerAIHello', [simbase.air.lobbyManager.doId])
def sendAddLobby(self, avId, lobbyId):
self.sendUpdate('addLobby', [avId, lobbyId])
def queryLobbyForHost(self, hostId):
self.sendUpdate('queryLobby', [hostId])
def d_lobbyStarted(self, lobbyId, shardId, zoneId, hostName):
self.sendUpdate('lobbyHasStarted', [lobbyId, shardId, zoneId, hostName])
def lobbyStarted(self, lobbyId, shardId, zoneId, hostName):
pass
def d_lobbyDone(self, lobbyId):
self.sendUpdate('lobbyDone', [lobbyId])
def lobbyDone(self, lobbyId):
pass
def d_toonJoinedLobby(self, lobbyId, avId):
self.sendUpdate('toonJoinedLobby', [lobbyId, avId])
def toonJoinedLobby(self, lobbyId, avId):
pass
def d_toonLeftLobby(self, lobbyId, avId):
self.sendUpdate('toonLeftLobby', [lobbyId, avId])
def toonLeftLobby(self, lobbyId, avId):
pass
def d_requestLobbySlot(self, lobbyId, avId):
self.sendUpdate('requestLobbySlot', [lobbyId, avId])
def requestLobbySlot(self, lobbyId, avId):
pass
def d_allocIds(self, numIds):
self.sendUpdate('allocIds', [numIds])
def allocIds(self, numIds):
pass

View file

@ -0,0 +1,124 @@
from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobalUD
from direct.distributed.PyDatagram import *
from direct.directnotify.DirectNotifyGlobal import directNotify
from direct.task import Task
from LobbyGlobals import *
from datetime import datetime, timedelta
from pandac.PandaModules import *
class GlobalLobbyManagerUD(DistributedObjectGlobalUD):
notify = directNotify.newCategory('GlobalLobbyManagerUD')
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
self.notify.debug("GLMUD generated")
self.senders2Mgrs = {}
self.host2LobbyId = {}
self.id2Lobby = {}
self.lobby2PubInfo = {}
self.tempSlots = {}
self.lobbyAllocator = UniqueIdAllocator(0, 100000000)
def _makeAIMsg(self, field, values, recipient):
return self.air.dclassesByName['DistributedLobbyManagerUD'].getFieldByName(field).aiFormatUpdate(recipient, recipient, simbase.air.ourChannel, values)
def sendToAI(self, field, values, sender=None):
if not sender:
sender = self.air.getAvatarIdFromSender()
dg = self._makeAIMsg(field, values, self.senders2Mgrs.get(sender, sender + 8))
self.air.send(dg)
def _makeAvMsg(self, field, values, recipient):
return self.air.dclassesByName['DistributedToonUD'].getFieldByName(field).aiFormatUpdate(recipient, recipient, simbase.air.ourChannel, values)
def sendToAv(self, avId, field, values):
dg = self._makeAvMsg(field, values, avId)
self.air.send(dg)
def _formatLobby(self, lobbyDict):
return [lobbyDict['lobbyId'], lobbyDict['hostId']]
def avatarJoined(self, avId):
lobbyId = self.host2LobbyId.get(avId, None)
if lobbyId:
lobby = self.id2Lobby.get(lobbyId, None)
if not lobby:
return
self.sendToAv(avId, 'setHostedLobby', [[self._formatLobby(lobby)]])
def __updateLobbyCount(self, lobbyId):
for sender in self.senders2Mgrs.keys():
self.sendToAI('updateToPublicLobbyCountUdToAllAi', [self.lobby2PubInfo[lobbyId]['numGuests'], lobbyId], sender=sender)
def lobbyDone(self, lobbyId):
del self.lobby2PubInfo[lobbyId]
self.id2Lobby[lobbyId]['status'] = LobbyStatus.Finished
lobby = self.id2Lobby.get(lobbyId, None)
self.sendToAv(lobby['hostId'], 'setHostedLobby', [[self._formatLobby(lobby)]])
del self.id2Lobby[lobbyId]
self.air.writeServerEvent('lobby-done', '%s')
def toonJoinedLobby(self, lobbyId, avId):
if avId in self.tempSlots:
del self.tempSlots[avId]
return
self.lobby2PubInfo.get(lobbyId, {'numGuests': 0})['numGuests'] += 1
self.__updateLobbyCount(lobbyId)
def toonLeftLobby(self, lobbyId, avId):
self.lobby2PubInfo.get(lobbyId, {'numGuests': 0})['numGuests'] -= 1
self.__updateLobbyCount(lobbyId)
def lobbyManagerAIHello(self, channel):
print 'AI with base channel %s, will send replies to DPM %s' % (simbase.air.getAvatarIdFromSender(), channel)
self.senders2Mgrs[simbase.air.getAvatarIdFromSender()] = channel
self.sendToAI('lobbyManagerUdStartingUp', [])
self.air.addPostRemove(self._makeAIMsg('lobbyManagerUdLost', [], channel))
def addLobby(self, avId, lobbyId):
if avId in self.host2LobbyId:
self.sendToAI('addLobbyResponseUdToAi', [lobbyId, AddLobbyErrorCode.TooManyHostedLobbies, self._formatLobby(self.id2Lobby[lobbyId])])
self.id2Lobby[lobbyId] = {'lobbyId': lobbyId, 'hostId': avId}
self.host2LobbyId[avId] = lobbyId
self.sendToAI('addLobbyResponseUdToAi', [lobbyId, AddLobbyErrorCode.AllOk, self._formatLobby(self.id2Lobby[lobbyId])])
def queryLobby(self, hostId):
if hostId in self.host2LobbyId:
lobby = self.id2Lobby[self.host2LobbyId[hostId]]
self.sendToAI('lobbyInfoOfHostResponseUdToAi', [self._formatLobby(lobby)])
return
print 'query failed, av %s isnt hosting anything' % hostId
def requestLobbySlot(self, lobbyId, avId):
lobby = self.lobby2PubInfo[lobbyId]
if lobby['numGuests'] >= lobby['maxGuests']:
recipient = self.GetPuppetConnectionChannel(avId)
sender = simbase.air.getAvatarIdFromSender()
#dg = self.air.dclassesByName['DistributedPartyGateAI'].getFieldByName('partyRequestDenied').aiFormatUpdate(gateId, recipient, sender, [PartyGateDenialReasons.Full])
#self.air.send(dg)
return
lobby['numGuests'] += 1
self.__updateLobbyCount(lobbyId)
self.tempSlots[avId] = lobbyId
taskMgr.doMethodLater(60, self._removeTempSlot, 'lobbyManagerTempSlot%d' % avId, extraArgs=[avId])
info = [lobby['shardId'], lobby['zoneId'], lobby['numGuests'], lobby['hostName']]
hostId = self.id2Lobby[lobby['lobbyId']]['hostId']
recipient = self.GetPuppetConnectionChannel(avId)
sender = simbase.air.getAvatarIdFromSender()
#dg = self.air.dclassesByName['DistributedPartyGateAI'].getFieldByName('setParty').aiFormatUpdate(gateId, recipient, sender, [info, hostId])
#self.air.send(dg)
def _removeTempSlot(self, avId):
lobbyId = self.tempSlots.get(avId)
if lobbyId:
del self.tempSlots[avId]
self.lobby2PubInfo.get(lobbyId, {'numGuests': 0})['numGuests'] -= 1
self.__updateLobbyCount(lobbyId)
def allocIds(self, numIds):
ids = []
while len(ids) < numIds:
ids.append(self.lobbyAllocator.allocate())
self.sendToAI('receiveId', ids)

View file

@ -0,0 +1,24 @@
from pandac.PandaModules import BitMask32
from pandac.PandaModules import Point3, VBase4
from direct.showbase import PythonUtil
from toontown.toonbase import TTLocalizer
KICK_TO_PLAYGROUND_EVENT = 'lobbies_kickToPlayground'
UberdogCheckLobbyStartFrequency = 5.0
UberdogPurgeLobbyPeriod = 24.0
UberdogLobbiesSanityCheckFrequency = 60
MaxToonsAtALobby = 8
ActivityRequestStatus = PythonUtil.Enum(('Joining', 'Exiting'))
InviteStatus = PythonUtil.Enum(('NotRead',
'ReadButNotReplied',
'Accepted',
'Rejected'))
PartyStatus = PythonUtil.Enum(('Pending',
'Cancelled',
'Finished',
'CanStart',
'Started',
'NeverStarted'))
AddPartyErrorCode = PythonUtil.Enum(('AllOk',
'ValidationError',
'DatabaseError',
'TooManyHostedParties'))