Ejemplo n.º 1
0
 def SYSMessage(self, DBID, MessageID, Time, *arg):
     d_sysmessage = self.GetConfigSysMessage(MessageID)
     if d_sysmessage is None:
         return
     MessageType = d_sysmessage['Type']
     MesaageUUID = KBEngine.genUUID64()
     MessageInfo = {
         'MesaageUUID': MesaageUUID,
         'time': Time,
         'MessageID': MessageID,
         'Endtime': 0
     }
     MessageInfo['ArgList'] = ''
     for argValue in arg:
         Value = ''
         if isinstance(argValue, str):
             Value = argValue
         else:
             Value = str(argValue)
         AddSplitStr(MessageInfo, 'ArgList', Value)
     if DBID == 0:
         self.WriteSysMessage(MessageInfo, MessageType)
     else:
         Entity = self.GetFriendEntity(DBID)
         #在线
         if Entity is not None:
             Friends = Entity.getComponent("Friends")
             Friends.WriteSysMessage(MessageInfo, MessageType)
         else:  #离线
             self.BuildGenerator('onFriendSysMessage')
             KBEngine.createEntityFromDBID(
                 "Account", DBID,
                 Functor.Functor(self.onFriendSysMessage, MessageInfo,
                                 MessageType))
Ejemplo n.º 2
0
 def MasterYaoShuHandler(self, YaoEndTime=None):
     IsSuccess = True
     if YaoEndTime:
         self.YaoEndTime = YaoEndTime
     #收获自己
     playerNum = self.GetYaoShuPlayerNum()
     ItemIDList = self.Component("Land").GetItemListByStage('摇树')
     INFO_MSG("MasterYaoShuHandler:%s,%i" % (str(ItemIDList), playerNum))
     #摇树大于两个人
     if playerNum >= 2:
         IdList = ItemIDList[:]
         #自己收获
         for ItemType in IdList:
             if not self.MasterGet(ItemType, playerNum):
                 ItemIDList.remove(ItemType)
         #别人收获
         for ApplyInfo in self.ApplyList:
             if ApplyInfo['IsYao']:
                 KBEngine.createEntityFromDBID(
                     "Account", ApplyInfo['DBID'],
                     Functor.Functor(self.CallBackOtherYaoShu,
                                     self.YaoEndTime,
                                     self.owner.Data['name'], playerNum,
                                     ItemIDList))
     else:
         self.SYSMessage(0, 3014, self.YaoEndTime)
         IsSuccess = False
     #清空厂主的数据
     self.ClearMaster()
     return IsSuccess
Ejemplo n.º 3
0
 def Get(self):
     if self.UnitList:
         DBID = self.UnitList[0]['DBID']
         CallBack = self.UnitList[0]['CallBack']
         arglist = self.UnitList[0]['arglist']
         if len(arglist) == 0:
             KBEngine.createEntityFromDBID("Account", DBID,
                                           Functor.Functor(CallBack))
         elif len(arglist) == 1:
             KBEngine.createEntityFromDBID(
                 "Account", DBID, Functor.Functor(CallBack, arglist[0]))
         elif len(arglist) == 2:
             KBEngine.createEntityFromDBID(
                 "Account", DBID,
                 Functor.Functor(CallBack, arglist[0], arglist[1]))
         elif len(arglist) == 3:
             KBEngine.createEntityFromDBID(
                 "Account", DBID,
                 Functor.Functor(CallBack, arglist[0], arglist[1],
                                 arglist[2]))
         elif len(arglist) == 4:
             KBEngine.createEntityFromDBID(
                 "Account", DBID,
                 Functor.Functor(CallBack, arglist[0], arglist[1],
                                 arglist[2], arglist[3]))
         else:
             ERROR_MSG("超出范围,arglist 大于4 ")
         INFO_MSG("Generator Get:%s" % str(self.UnitList[0]))
         del self.UnitList[0]
Ejemplo n.º 4
0
    def loadGuarantee(self, guaranteeID, errorDeep=0):
        def callback(baseRef, dbid, wasActive):
            try:
                if wasActive:
                    raise RunException(
                        "PlayerManager::callback:(%i): this guarantee is in world now! %s, %s, %s, %s"
                        % (guaranteeID, self.id, baseRef, dbid, wasActive))
                if baseRef is None:
                    raise RunException(
                        "PlayerManager::callback:(%i): the guarantee you wanted to created is not exist! %s, %s, %s, %s"
                        % (guaranteeID, self.id, baseRef, dbid, wasActive))
                guarantee = KBEngine.entities.get(baseRef.id)
                if guarantee is None:
                    raise RunException(
                        "PlayerManager::callback:(%i): when guarantee was created, it died as well! %s, %s, %s, %s"
                        % (guaranteeID, self.id, baseRef, dbid, wasActive))
                if self.isDestroyed:
                    raise RunException(
                        "PlayerManager::callback:(%i): i dead! %s, %s, %s, %s"
                        % (guaranteeID, self.id, baseRef, dbid, wasActive))
            except RunException as e:
                ERROR_MSG(e.args[0])
                if errorDeep < self.errorDeepMax:
                    self.loadGuarantee(guaranteeID, errorDeep + 1)
                else:
                    ERROR_MSG(
                        "PlayerManager::loadGuarantee:(%i): load failed! %s, %s, %s, %s"
                        % (guaranteeID, self.id, baseRef, dbid, wasActive))
            else:
                guarantee.run(self.players.get(guarantee.databaseID),
                              self.products.pop(guarantee.databaseID))

        KBEngine.createEntityFromDBID('Guarantee', guaranteeID, callback)
Ejemplo n.º 5
0
 def reqAllPetInfo(self, DBID):
     if DBID == 0:
         self.SendAllPetInfo(self.owner.databaseID, self.PetData)
     else:
         self.BuildGenerator('CallBackAllPetInfo')
         KBEngine.createEntityFromDBID(
             "Account", DBID, Functor.Functor(self.CallBackAllPetInfo))
Ejemplo n.º 6
0
def createSingletonFromDB(entityName, globalname, dbid, props):
    def onCreateCallBack(baseRef, databaseID, wasActive):
        if baseRef:
            DEBUG_MSG(
                "createSingletonFromDB: %s create from DB success, databaseID:[%i]"
                % (entityName, databaseID))
            baseRef.writeToDB()
            # 向全局共享数据中注册这个管理器的mailbox以便在所有逻辑进程中可以方便的访问
            KBEngine.globalData[globalname] = baseRef
        else:
            WARNING_MSG("createSingletonFromDB: %s create from DB failed" %
                        entityName)
            singleton = KBEngine.createEntityLocally(entityName, props)

            def onWriteToDB(success, entity):
                if success:
                    DEBUG_MSG(
                        "createSingletonFromDB: %s writeToDB success, dbid:[%i]"
                        % (entityName, entity.databaseID))
                    entity.writeToDB(
                    )  # TODO, to delete if auto-writeToDB each 15 min
                    KBEngine.globalData[globalname] = entity
                else:
                    ERROR_MSG("createSingletonFromDB: %s writeToDB failed" %
                              entityName)

            singleton.writeToDB(onWriteToDB)

    KBEngine.createEntityFromDBID(entityName, dbid, onCreateCallBack)
Ejemplo n.º 7
0
    def loadClubs(self):
        club_list = list(self.clubList)
        if len(club_list) == 0:
            self.initFinish()
            return

        self.executor.set('c', 0)
        self.executor.set('c_ok', 0)
        self.executor.add_condition(lambda: self.executor.get('c_ok') >= 1,
                                    [self.initFinish, []])
        self.executor.add_condition(
            lambda: self.executor.get('c') >= len(club_list),
            [self.executor.inc1, ['c_ok']])

        for id in club_list:

            def create_cb(baseRef, databaseID, wasActive):
                self.executor.inc1('c')
                if baseRef:
                    self.clubs[baseRef.clubId] = baseRef
                else:
                    if databaseID in self.clubList:
                        self.clubList.remove(databaseID)
                    INFO_MSG("ClubStub load club failed. Club_%d not exist!" %
                             databaseID)

            KBEngine.createEntityFromDBID("Club", id, create_cb)
Ejemplo n.º 8
0
 def SendMailMessage2(self, DBID, MessageID, ArgList, timeinterval = 7*24*60*60):
     MessageType = '邮箱奖励'
     MesaageUUID = KBEngine.genUUID64()
     nowtime = int(time.time() )
     Endtime = nowtime + timeinterval
     MessageInfo = {'MesaageUUID':MesaageUUID, 'time':nowtime ,'MessageID':MessageID, 'Endtime':Endtime, 'ArgList':ArgList}  
     KBEngine.createEntityFromDBID("Account",DBID,Functor.Functor(self.onMailMessage,MessageInfo,MessageType))
     DEBUG_MSG('SendMailMessage2, MessageInfo:%s' % str(MessageInfo))    
Ejemplo n.º 9
0
 def reqBuyLand(self, DBID, LandType):
     INFO_MSG("reqBuyLand:%i,%i" % (DBID, LandType))
     #判断ID是否超出
     if DBID == 0:
         self.BuyLand(DBID, LandType, self)
     else:
         self.BuildGenerator('CallBackBuyLand')
         KBEngine.createEntityFromDBID(
             "Account", DBID, Functor.Functor(self.CallBackBuyLand,
                                              LandType))
Ejemplo n.º 10
0
 def enterGameRoom(self, dbid):
     if self.activeCharacter is None:
         if dbid in self.characters:
             KBEngine.createEntityFromDBID("Avatar", dbid,
                                           self.__onAvatarCreated)
         else:
             ERROR_MSG("Account[%i]::enterGameRoom: not found dbid(%i)" %
                       (self.id, dbid))
     else:
         ERROR_MSG(
             "Account[%i]::enterGameRoom: activeCharacter[%i] is exit" %
             (self.id, self.activeCharacter.id))
Ejemplo n.º 11
0
 def __init__(self):
     KBEngine.Entity.__init__(self)
     GameObject.__init__(self)
     self.createCellEntityInNewSpace(None)
     self.spaceUTypeB = self.cellData["spaceUType"]
     self.avatars = {}
     #self.spaceResName = d_spaces.datas.get(self.spaceUTypeB)['resPath']
     #self._city = list(d_city.datas.keys())
     for CityID in d_city.datas.keys():
         if d_city.datas[CityID]["SpaceID"] == self.spaceUTypeB:
             KBEngine.createEntityFromDBID("City", CityID,
                                           self._onCityCreatedFromDBIDCB)
Ejemplo n.º 12
0
 def reqAllLandInfo(self, DBID):
     self.client.onServerTime(int(time.time()))
     if DBID == 0:
         self.client.onAllLandInfo('成功', self.owner.databaseID,
                                   self.LandData)
         self.client.onGJInfo(self.owner.databaseID, self.GJData, False)
         self.Component("Pet").reqAllPetInfo(0)
         self.Component("bags").reqBags()
     else:
         self.BuildGenerator('CallBackLandInfo')
         KBEngine.createEntityFromDBID(
             "Account", DBID, Functor.Functor(self.CallBackLandInfo))
Ejemplo n.º 13
0
    def SelectRoomGame(self, RoomId):
        '''
		选择房间进入游戏
		:param RoomId: 房间id
		'''
        DEBUG_MSG("PtAccount[%i].SelectRoomGame: RoomId = %i , RoleId = %i" %
                  (self.id, RoomId, self.LastSelRole))
        # 保存房间id
        self.LastSelRoom = RoomId
        # 从数据库创建选中的角色
        KBEngine.createEntityFromDBID("PtRole", self.LastSelRole,
                                      self._OnRoleCreated)
Ejemplo n.º 14
0
def onBaseAppReady(isBootstrap):
	"""
	KBEngine method.
	baseapp已经准备好了
	@param isBootstrap: 是否为第一个启动的baseapp
	@type isBootstrap: BOOL
	"""
	INFO_MSG('onBaseAppReady: isBootstrap=%s, appID=%s, bootstrapGroupIndex=%s, bootstrapGlobalIndex=%s' % \
	 (isBootstrap, os.getenv("KBE_COMPONENTID"), os.getenv("KBE_BOOTIDX_GROUP"), os.getenv("KBE_BOOTIDX_GLOBAL")))
	if isBootstrap:
		KBEngine.createEntityFromDBID("Exchange",1)
		KBEngine.createEntityLocally("Chat",{})
		KBEngine.createEntityLocally( "Spaces", {} )
Ejemplo n.º 15
0
    def ReqSelectRole(self, Dbid):
        """
        请求选择角色
        :param Dbid:
        :return:
        """
        if Dbid in self.RoleList:
            self.client.OnSelectRole(0, Dbid)
        else:
            self.client.OnSelectRole(1, Dbid)

        DEBUG_MSG("ExAccount[%i].ReqSelectRole: RoomId = %i , RoleId = %i" %
                  (self.id, self.LastSelRoom, Dbid))
        KBEngine.createEntityFromDBID("Role", Dbid, self._OnRoleCreated)
Ejemplo n.º 16
0
 def reqAvatar(self):
     DEBUG_MSG("Account[%i].reqAvatar:%i" % (self.id, self.Character))
     if self.Character != 0:
         avatar = KBEngine.createEntityFromDBID("Avatar", self.Character,
                                                self.__onAvatarCreated)
     else:
         self.client.onReqAvatar(0)
Ejemplo n.º 17
0
 def reqSelectAvatar(self, dbid):
     # 注意:使用giveClientTo的entity必须是当前baseapp上的entity
     if self.activeAvatar is None:
         for avatar in self.avatars:
             if avatar.dbid == dbid:
                 self.lastSelectAvatar = dbid
                 KBEngine.createEntityFromDBID("Avatar", dbid,
                                               self.__onAvatarLoaded)
                 break
         else:
             ERROR_MSG("Account[%i]::reqSelectAvatar: not found dbid(%i)" %
                       (self.id, dbid))
     else:
         if self.client:
             self.activeAvatar.isReLogin = False
             self.giveClientTo(self.activeAvatar)
Ejemplo n.º 18
0
 def SendMailMessage(self, DBID, MessageID, awardTypelist, awardValuelist, MessageTEXT = '', timeinterval = 7*24*60*60):
     MessageType = '邮箱奖励'
     MesaageUUID = KBEngine.genUUID64()
     nowtime = int(time.time() )
     Endtime = nowtime + timeinterval
     MessageInfo = {'MesaageUUID':MesaageUUID, 'time':nowtime ,'MessageID':MessageID, 'Endtime':Endtime}
     MessageInfo['ArgList'] = ''
     if len(awardTypelist) != len(awardValuelist):
         ERROR_MSG('奖励表配置错误!:%s,%s' % (str(awardTypelist),str(awardValuelist)))
         return
     for index,awardType in enumerate(awardTypelist):
         AddSplitStr(MessageInfo,'ArgList',awardType)
         AddSplitStr(MessageInfo,'ArgList',awardValuelist[index])
     AddSplitStr(MessageInfo,'ArgList',MessageTEXT)
     KBEngine.createEntityFromDBID("Account",int(DBID),Functor.Functor(self.onMailMessage,MessageInfo,MessageType))
     DEBUG_MSG('SendMailMessage, MessageInfo:%s' % str(MessageInfo))
Ejemplo n.º 19
0
	def selectAvatarGame(self):
		"""
		exposed.
		客户端选择某个角色进行游戏
		"""
		DEBUG_MSG("Account[%i].selectAvatarGame:. self.activeAvatar=%s" % (self.id,  self.activeAvatar))
		# 注意:使用giveClientTo的entity必须是当前baseapp上的entity

		if self.activeAvatar is None:
			if len(self.characters) <= 0:
				ERROR_MSG("Account[%i]::selectAvatarGame: not found " % (self.id))
			else:
				for dbid in self.characters.keys():
					self.lastSelCharacter = dbid
					KBEngine.createEntityFromDBID("Avatar", dbid, self.__onAvatarCreated)
					break
		else:
			self.giveClientTo(self.activeAvatar)
Ejemplo n.º 20
0
	def selectAvatarGame(self, dbid):
		"""
		exposed.
		客户端选择某个角色进行游戏
		"""
		DEBUG_MSG("Account[%i].selectAvatarGame:%i. self.activeAvatar=%s" % (self.id, dbid, self.activeAvatar))
		# 注意:使用giveClientTo的entity必须是当前baseapp上的entity
		if self.activeAvatar is None:
			if dbid in self.characters:
				self.lastSelCharacter = dbid
				# 由于需要从数据库加载角色,因此是一个异步过程,加载成功或者失败会调用__onAvatarCreated接口
				# 当角色创建好之后,account会调用giveClientTo将客户端控制权(可理解为网络连接与某个实体的绑定)切换到Avatar身上,
				# 之后客户端各种输入输出都通过服务器上这个Avatar来代理,任何proxy实体获得控制权都会调用onClientEnabled
				# Avatar继承了Teleport,Teleport.onClientEnabled会将玩家创建在具体的场景中
				KBEngine.createEntityFromDBID("Avatar", dbid, self.__onAvatarCreated)
			else:
				ERROR_MSG("Account[%i]::selectAvatarGame: not found dbid(%i)" % (self.id, dbid))
		else:
			self.giveClientTo(self.activeAvatar)
Ejemplo n.º 21
0
    def selectAvatarGame(self, dbid):
        """
        exposed.
        客户端选择某个角色进行游戏
        """
        DEBUG_MSG("Account[%i].selectAvatarGame:%i. self.activeAvatar=%s" %
                  (self.id, dbid, self.activeAvatar))
        # 注意:使用giveClientTo的entity必须是当前baseapp上的entity

        if self.activeAvatar is None:
            if dbid in self.characters:
                self.lastSelCharacter = dbid
                KBEngine.createEntityFromDBID("Avatar", dbid,
                                              self.__onAvatarCreate)
            else:
                EROOR_MSG("Account[%i]::selectAvatarGame:not found dbid(%i)" %
                          (self.id, dbid))
        else:
            self.giveClientTo(self.activeAvatar)
Ejemplo n.º 22
0
    def BExs_reqEnterGame(self, serverID):
        """
        选择角色进入游戏
        参数1:选择的服务器ID
        """
        if self.curAvatar is None:
            if serverID in self.avatarDict:
                self.lastServerID = serverID
                avatarID = self.avatarDict[serverID]['avatarID']

                # 角色存在则从数据库创建
                KBEngine.createEntityFromDBID('Avatar', avatarID,
                                              self._onAvatarCreated)
            else:
                ERROR_MSG(
                    "Account(%i)::BExs_reqEnterGame: not found serverID(%i)." %
                    (self.id, serverID))
        else:
            # 控制权交给avatar
            self.giveClientTo(self.curAvatar)
Ejemplo n.º 23
0
 def reqRemoveAvatar(self, dbid):
     DEBUG_MSG("dbid:%i" % (dbid))
     for key in range(len(self.AvatarList)):
         DEBUG_MSG("self.AvatarList[key]:%i" % (self.AvatarList[key]))
         if self.AvatarList[key] == dbid:
             avatar = KBEngine.createEntityFromDBID(
                 "Avatar", self.AvatarList[key],
                 self.__onAvatarCreatedinRemove)
             self.AvatarList.pop(key)
             self.writeToDB(self._selfwritetodbinremove)
             return
Ejemplo n.º 24
0
    def reqGiveLand(self, DBID, LandID):
        INFO_MSG("reqGiveLand:%i,%i" % (DBID, LandID))
        #判断是否已经有这个块土地
        Maxid = len(self.LandData)
        if LandID > Maxid or LandID == 1:
            self.client.onGiveLand('没有这块土地')
            return -1
        #土地有种子也不能送
        LandInfo = self.GetLandInfo(LandID)

        if LandInfo['ItemType'] != 0:
            self.client.onGiveLand('种植中的土地不能赠送')
            return -2
        if LandInfo['LandType'] == 0:
            self.client.onGiveLand('未购买')
            return -3
        self.BuildGenerator('CallFriendGiveLand')
        KBEngine.createEntityFromDBID(
            "Account", DBID, Functor.Functor(self.CallFriendGiveLand,
                                             LandInfo))
        return 0
Ejemplo n.º 25
0
    def ReqRemoveRole(self, Name):
        """
        客户端请求删除一个角色,此处使用角色名来选择,可能不太严谨,之后可以增加或修改为根据ID来选择
        """
        DEBUG_MSG("PtAccount[%i].ReqRemoveRole: %s" % (self.id, Name))

        # 数据库Id
        Dbid = -1

        for key, info in self.RoleList.items():
            # 如果角色存在, 保存key到数据库Id
            if info[1] == Name:
                Dbid = key
                break

        # 如果Dbid为负, 说明不存在对应角色, 直接返回
        if Dbid == -1:
            return

        # 从数据库生成该角色, 生成该角色后,再调用该角色的destroy(True)从数据库删除
        KBEngine.createEntityFromDBID("PtRole", Dbid, self._OnRoleRemoved)
Ejemplo n.º 26
0
    def callback():
        def callback(name, baseRef, dbid, wasActive):
            if wasActive:
                ERROR_MSG(
                    "equalization::callback: this equalization obj is online! %s, %s, %s, %s"
                    % (name, baseRef, dbid, wasActive))
                return
            if baseRef is None:
                ERROR_MSG(
                    "equalization::callback: the equalization obj you wanted to created is not exist! %s, %s, %s, %s"
                    % (name, baseRef, dbid, wasActive))
                return
            KBEngine.globalData["EqualizationEntity"].addAutoLoaded(name, dbid)

        need_created = []
        for name, idList in Equalization_.autoLoadedIDMap.items():
            for i in range(index - 1, len(idList),
                           settings.BaseApp.equalizationBaseappAmount):
                KBEngine.createEntityFromDBID(name, idList[i],
                                              partial(callback, name))
            if not idList:
                if settings.get(name).autoLoadedOrCreate:
                    need_created.append(name)
                elif sender.groupIndex == 1:
                    KBEngine.globalData["EqualizationEntity"].addAutoLoaded(
                        name, 0)

        need_created.sort()
        for i in range(index - 1, len(need_created),
                       settings.BaseApp.equalizationBaseappAmount):
            name = need_created[i]
            KBEngine.createEntityLocally(name, dict(entityNeedSave=True))
            KBEngine.globalData["EqualizationEntity"].addAutoLoaded(name, 0)

        if not Equalization_.autoLoadedIDMap and sender.groupIndex == 1:
            KBEngine.globalData["EqualizationEntity"].addAutoLoaded("", 0)
Ejemplo n.º 27
0
 def updataeAvatarListInfo(self):
     self.AvatarListInfo = []
     for key in range(len(self.AvatarList)):
         avatar = KBEngine.createEntityFromDBID("Avatar",
                                                self.AvatarList[key],
                                                self.__onAvatarCreated)
Ejemplo n.º 28
0
 def ReChange(self, DBID, errMsg, moneyType, moneyValue):
     KBEngine.createEntityFromDBID("Account",DBID,Functor.Functor(self.onReChange,errMsg,moneyType,moneyValue))
Ejemplo n.º 29
0
 def startgame(self, dbid):
     avatar = KBEngine.createEntityFromDBID(
         "Avatar", dbid, self.__onAvatarCreatedinstartgame)
Ejemplo n.º 30
0
 def ReqEnterGame(self, code):
     ERROR_MSG("Account[%i].ReqEnterGame: Code = %i" % (self.id, code))
     # 从数据库创建选中的角色
     KBEngine.createEntityFromDBID("Role", self.CurrentRoleID,
                                   self._OnRoleCreated)