Пример #1
0
    def findRoom(self, entityID, roomKey, notFoundCreate=False):
        """
		查找一个指定房间,如果找不到允许创建一个新的
		"""
        DEBUG_MSG("Halls::findRoom:roomKey:%s,roomDatas:%s" %
                  (roomKey, str(self.rooms)))
        roomDatas = self.rooms.get(roomKey)

        # 如果房间没有创建,则将其创建
        if not roomDatas:
            if not notFoundCreate:
                return FIND_ROOM_NOT_FOUND

            # 如果最后创建的房间没有满员,则使用最后创建的房间key,否则产生一个新的房间唯一Key
            #roomDatas = self.rooms.get(self.lastNewRoomKey)
            #if roomDatas is not None and roomDatas["PlayerCount"] < GameConfigs.ROOM_MAX_PLAYER:
            #return roomDatas

            self.lastNewRoomKey = KBEngine.genUUID64()

            # 将房间base实体创建在任意baseapp上
            # 此处的字典参数中可以对实体进行提前def属性赋值
            KBEngine.createEntityAnywhere("Room", \
                  {
                  "roomKey" : self.lastNewRoomKey,	\
                  }, \
                  Functor.Functor(self.onRoomCreatedCB, self.lastNewRoomKey))

            roomDatas = {
                "roomEntityCall": None,
                "PlayerCount": 0,
                "enterRoomReqs": [],
                "roomKey": self.lastNewRoomKey,
                "creater": entityID
            }
            self.rooms[self.lastNewRoomKey] = roomDatas
            return roomDatas

        return roomDatas
Пример #2
0
 def InitFriendList(self, Result):
     if Result is None:
         self.FriendState = 4
         return
     #删除定时器
     self.delTimer(self.TimerIDFriend)
     if Result['status'] == 1:
         self.FriendState = 1
         self.FriendList = []
         CurCount = 0
         for k, v in enumerate(Result['content']):
             CurCount += 1
             sql = """select accountName,entityDBID,sm_Data_name,sm_Data_Icon,sm_Data_gender  
             from kbe_accountinfos,tbl_Account where accountName ='""" + v[
                 'uid_friend'] + "' and entityDBID = id;"
             KBEngine.executeRawDatabaseCommand(
                 sql,
                 Functor.Functor(self.sqlcallback, CurCount,
                                 len(Result['content'])))
     else:
         INFO_MSG("获得好友列表失败 error:%s" % (Result['error']))
         self.FriendState = 3
         self.OpenFriendList('没有好友')
Пример #3
0
    def __init__(self):
        BaseEntity.__init__(self)
        self.base_info = h1global.rc.sportDict[const.SPORT_DAILY][self.sportId]
        self.tem_list = []
        self.history_list = []
        self.wait_pool = OrderedDict()
        self.record_list = []
        self.Timer_list = []
        self.rankingId = 0
        self.botUserId = 0
        for x in range(const.DAILY_SPORT_PLAYER_ROUND):
            self.record_list.append([])
            self.Timer_list.append(None)
            self.tem_list.append([])

        # 活动开始重置排行榜
        s_t = time.localtime()
        for t_p in self.base_info["time"]:
            # 赛事开始
            h, m, s = t_p[0].split(":")
            d_t = ((int(h) * 3600 + int(m) * 60 + int(s)) -
                   (s_t.tm_hour * 3600 + s_t.tm_min * 60 + s_t.tm_sec) +
                   86400) % 86400
            self.add_repeat_timer(
                d_t, 24 * 3600,
                Functor.Functor(self.refreshRank, self.base_info["time"][t_p]))
            b_t = (int(h) * 3600 + int(m) * 60 + int(s)) - (
                s_t.tm_hour * 3600 + s_t.tm_min * 60 + s_t.tm_sec)

            h, m, s = t_p[1].split(":")
            l_t = (int(h) * 3600 + int(m) * 60 + int(s)) - (
                s_t.tm_hour * 3600 + s_t.tm_min * 60 + s_t.tm_sec)

            if b_t < 0 and l_t > 0:
                self.refreshRank(self.base_info["time"][t_p])

        return
Пример #4
0
    def reqCreateRoom(self, entityCall, name, intro, password):
        """
		请求创建房间
		"""
        DEBUG_MSG("Hall::reqCreateRoom:name:%s,intro:%s,password:%s" %
                  (name, intro, password))
        self.newRoomKey = KBEngine.genUUID64()

        KBEngine.createEntityAnywhere("Room", \
               {
               "roomKey"     : self.newRoomKey,
               "name"        : name,
               "intro"       : intro,
               "password"    : password
               }, \
               Functor.Functor(self.onRoomCreatedCB, self.newRoomKey))
        if password == "":
            hasPassword = 1
        else:
            hasPassword = 2

        roomDatas = {
            "roomEntityCall": None,
            "playerCount": 0,
            "roomKey": self.newRoomKey,
            "name": name,
            "intro": intro,
            "password": password,
            "isPlaying": 1,
            "hasPassword": hasPassword,
            "enterRoomReqs": []
        }
        self.rooms[self.newRoomKey] = roomDatas
        DEBUG_MSG("Hall::reqCreateRoom:rooms:%s" % self.rooms)

        entityCall.reqJoinRoom(self.newRoomKey, password)
Пример #5
0
 def drawTile(self, tile, is_first=False):
     """ 摸牌 """
     DEBUG_MSG("Player{0} drawTile: {1}, left = {2}, state = {3}".format(
         self.idx, tile, len(self.owner.tiles), self.discard_state))
     self.last_draw = tile
     self.tiles.append(tile)
     self.op_r.append((const.OP_DRAW, [
         tile,
     ], self.idx))
     self.owner.op_record.append((const.OP_DRAW, self.idx, self.idx, [
         tile,
     ]))
     self.last_op = const.OP_DRAW
     if not is_first:
         self.owner.broadcastOperation2(self.idx, const.OP_DRAW, [
             0,
         ])
         self.mb.postOperation(self.idx, const.OP_DRAW, [
             tile,
         ])
     if self.discard_state == const.DISCARD_FORCE:
         is_win, score, result = self.owner.can_win(list(self.tiles), tile,
                                                    const.OP_DRAW_WIN,
                                                    self.idx)
         if is_win:
             # self.owner.add_timer(1, Functor.Functor(self.draw_win, tile, score, result))
             self.draw_win(tile, score, result)
         elif self.owner.can_continue_kong(self, tile):
             # self.owner.add_timer(1, Functor.Functor(self.continueKong, tile))
             self.continueKong(tile)
         else:
             self.owner.add_timer(
                 1, Functor.Functor(self.forceDiscard, const.DISCARD_FORCE))
             # self.forceDiscard()
     elif self.discard_state == const.DISCARD_FREE:
         self.owner.addDiscardTimer()
Пример #6
0
	def doPSOperation(self, avt_mb, aid, value, auto_op):
		if self.state != const.ROOM_PLAYING:
			return
		idx = self._get_player_idx(avt_mb)
		DEBUG_MSG("{} doPSOperation idx:{} aid:{} value:{} poker_state:{} min_stack:{} auto_op:{}".format(self.prefixLogStr, idx, aid, value, avt_mb.poker_state, self.min_stack, auto_op))
		# 观察者 弃牌玩家 比牌失败玩家 和 非当前玩家 无法进行操作
		if self.current_bout_num >= self.bout_num \
			or avt_mb.identity == const_ps.GAME_VIEWER \
			or avt_mb.poker_state == const_ps.POKER_FAIL \
			or avt_mb.poker_state == const_ps.POKER_FOLD:
			DEBUG_MSG("{} doPSOperation error current_bout_num:{} bout_num:{} identity:{} poker_state:{}".format(self.prefixLogStr, self.current_bout_num, self.bout_num, avt_mb.identity,  avt_mb.poker_state))
			return
		if aid == const_ps.SEE_CARDS:
			# 必蒙 不能看牌
			if self.current_bout_num < self.stuffy_num or avt_mb.poker_state == const_ps.POKER_SEEN:
				DEBUG_MSG("{} doPSOperation error current_bout_num:{} poker_state:{}".format(self.prefixLogStr, self.current_bout_num, avt_mb.poker_state))
				return
			self.op_record.append([idx, aid, value])
			avt_mb.poker_state = const_ps.POKER_SEEN
			self.psBroadcastOperation3(idx, aid, avt_mb.pokers)
			return

		# 非当前玩家不能进行 除看牌外其他操作
		if self.current_idx != idx:
			DEBUG_MSG("{} dealer_idx:{}  current_idx:{} != idx:{}".format(self.prefixLogStr, self.dealer_idx, self.current_idx, idx))
			return

		# 自动跟注状态不允许 除 看牌外其他任何操作
		if not auto_op and avt_mb.auto_follow == const_ps.AUTO_FOLLOW:
			DEBUG_MSG("{} idx:{} auto op can't active op but see cards".format(self.prefixLogStr, idx))
			return

		if aid == const_ps.FOLLOW_CHIP:
			self.cancel_op_timer()
			# 看牌跟注加倍
			score = self.min_stack if avt_mb.poker_state == const_ps.POKER_BLIND else self.min_stack * 2
			self.op_record.append([idx, aid, score])
			avt_mb.score -= score
			self.score += score
			self.current_idx = self._get_next_play_idx(self.current_idx)
			DEBUG_MSG("{} idx:{} FOLLOW_CHIP value:{}".format(self.prefixLogStr, idx, score))
			if score in const_ps.STACKS:
				self.stacks[idx][const_ps.STACKS.index(score)] += 1
			if auto_op:
				self.psBroadcastOperation(idx, aid, [score])
			else:
				self.psBroadcastOperation2(idx, aid, [score])
			if idx == self._get_end_play_idx():
				self.current_bout_num += 1
			# 游戏 达到最大轮数结束
			if self.current_bout_num >= self.bout_num:
				self.finalCompare()
			elif self.players_list[self.current_idx].auto_follow == const_ps.AUTO_FOLLOW:
				# self.doPSOperation(self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1)
				self.add_timer(1, Functor.Functor(self.doPSOperation, self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1))
			else:
				self.add_op_timer()
		elif aid == const_ps.RAISE_CHIP:
			if (avt_mb.poker_state == const_ps.POKER_BLIND and (value not in self.inject_stack or value <= self.min_stack)) \
				or (avt_mb.poker_state == const_ps.POKER_SEEN and (value/2 not in self.inject_stack or value/2 <= self.min_stack)):
				return
			self.op_record.append([idx, aid, value])
			self.cancel_op_timer()
			avt_mb.score -= value
			self.score += value
			self.min_stack = value if avt_mb.poker_state == const_ps.POKER_BLIND else int(value/2)
			self.current_idx = self._get_next_play_idx(self.current_idx)
			DEBUG_MSG("{} idx:{} RAISE_CHIP value:{}".format(self.prefixLogStr, idx, value))
			if value in const_ps.STACKS:
				self.stacks[idx][const_ps.STACKS.index(value)] += 1
			if auto_op:
				self.psBroadcastOperation(idx, aid, [value])
			else:
				self.psBroadcastOperation2(idx, aid, [value])
			if idx == self._get_end_play_idx():
				self.current_bout_num += 1
			# 游戏 达到最大轮数结束
			if self.current_bout_num >= self.bout_num:
				self.finalCompare()
			elif self.players_list[self.current_idx].auto_follow == const_ps.AUTO_FOLLOW:
				# self.doPSOperation(self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1)
				self.add_timer(1, Functor.Functor(self.doPSOperation, self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1))
			else:
				self.add_op_timer()
		elif aid == const_ps.CMP_CARDS:
			if value >= len(self.players_list) \
				or idx == value \
				or self.current_bout_num <= 0 \
				or self.players_list[value] is None \
				or self.players_list[value].identity == const_ps.GAME_VIEWER \
				or self.players_list[value].poker_state == const_ps.POKER_FAIL \
				or self.players_list[value].poker_state == const_ps.POKER_FOLD:
				return
			self.op_record.append([idx, aid, value])
			self.cancel_op_timer()
			# 已看牌下注加倍
			score = self.min_stack if avt_mb.poker_state == const_ps.POKER_BLIND else self.min_stack * 2
			# 比牌下注加倍
			if self.compare_double:
				score = score * 2
			avt_mb.score -= score
			self.score += score
			if score in const_ps.STACKS:
				self.stacks[idx][const_ps.STACKS.index(score)] += 1
			# 比牌
			cmp = utility_ps.compare(avt_mb.pokers, self.players_list[value].pokers, self.serial_circle)
			DEBUG_MSG("{} CMP_CARDS {}={}={}".format(self.prefixLogStr, idx, value, cmp))
			if cmp:	# 胜利
				self.act_cmp.append([idx, value, 1])
				self.players_list[value].poker_state = const_ps.POKER_FAIL
				self.psBroadcastOperation(idx, aid, [value, 1])
			else:	# 失败
				self.act_cmp.append([idx, value, 0])
				avt_mb.poker_state = const_ps.POKER_FAIL
				self.psBroadcastOperation(idx, aid, [value, 0])
			# 牌局提前结束
			if sum([1 for _p in self.players_list \
				if _p is not None \
				and _p.identity == const_ps.GAME_PLAYER \
				and (_p.poker_state == const_ps.POKER_BLIND or _p.poker_state == const_ps.POKER_SEEN)]) == 1:
				self.winGame(idx if cmp else value)
			else:
				self.current_idx = self._get_next_play_idx(self.current_idx)
				if idx == self._get_end_play_idx():
					self.current_bout_num += 1
				# 游戏 达到最大轮数结束
				if self.current_bout_num >= self.bout_num:
					self.finalCompare()
				elif self.players_list[self.current_idx].auto_follow == const_ps.AUTO_FOLLOW:
					# self.doPSOperation(self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1)
					self.add_timer(4, Functor.Functor(self.doPSOperation, self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1))
				else:
					self.add_op_timer()
		elif aid == const_ps.FOLD_CARDS:
			# 必蒙 不能弃牌
			if self.current_bout_num < self.stuffy_num:
				return
			e_idx = self._get_end_play_idx()
			self.op_record.append([idx, aid, value])
			self.cancel_op_timer()
			avt_mb.fold_cards(auto_op)
			DEBUG_MSG("{} idx:{} FOLD_CARDS ".format(self.prefixLogStr, idx))
			# 牌局提前结束
			if sum([1 for _p in self.players_list \
				if _p is not None \
					and (_p.poker_state == const_ps.POKER_BLIND or _p.poker_state == const_ps.POKER_SEEN)]) == 1:
				self.winGame(self._get_next_play_idx(self.current_idx))
			else:
				self.current_idx = self._get_next_play_idx(self.current_idx)
				if idx == e_idx:
					self.current_bout_num += 1
				# 游戏 达到最大轮数结束
				if self.current_bout_num >= self.bout_num:
					self.finalCompare()
				elif self.players_list[self.current_idx].auto_follow == const_ps.AUTO_FOLLOW:
					# self.doPSOperation(self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1)
					self.add_timer(1, Functor.Functor(self.doPSOperation, self.players_list[self.current_idx], const_ps.FOLLOW_CHIP, 0, 1))
				else:
					self.add_op_timer()
Пример #7
0
 def reqSteal(self, DBID, Name, MesaageUUID):
     INFO_MSG("reqSteal:%i,%s" % (DBID, Name))
     self.BuildGenerator('CallBackSteal')
     KBEngine.createEntityFromDBID(
         "Account", DBID, Functor.Functor(self.CallBackSteal, Name))
     self.ChangeMessageState(MesaageUUID, 3)
Пример #8
0
 def ReChange(self, DBID, errMsg, moneyType, moneyValue):
     KBEngine.createEntityFromDBID("Account",DBID,Functor.Functor(self.onReChange,errMsg,moneyType,moneyValue))
Пример #9
0
	def GetHFL(self, uid, callBack):
		Value = (uid+'ZLNC123').encode(encoding='utf-8')
		url = 'http://121.201.80.40:7070/v3/game/getphc?uid=%s&sign=%s' % (uid,md5Value(Value))
		KBEngine.urlopen(url,  Functor.Functor(self.onGetHFL, callBack))
		DEBUG_MSG("GetHFL:"+url)
 def onAccept(self, fileno):
     if self._sock.fileno() == fileno:
         sock, addr = self._sock.accept()
         KBEngine.registerReadFileDescriptor(
             sock.fileno(), Functor.Functor(self.onRecv, sock, addr))
Пример #11
0
def functor(func, *args):
    return Functor.Functor(func, *args)
Пример #12
0
	def systemCreateRoom(self,playerNum):
		playerEntityList=[]
		for i in range(playerNum):
			playerEntityList.append(self.matchPlayerEntity.pop(0))

		roomId=KBEngine.genUUID64()										#服务器自动生成64位的ID
		while roomId in self.allRoomEntity:								#检测房间ID是否重复
			roomId=KBEngine.genUUID64()

		#创建房间实体
		KBEngine.createEntityAnywhere("Room",{"roomId":roomId,"roomType":0,"playerList":playerEntityList},Functor.Functor(self.systemCreateRoomCB,roomId))
Пример #13
0
	def playerCreateRoom(self,roomId,entityCall):
		playerEntityList=[]
		playerEntityList.append(entityCall)
		KBEngine.createEntityAnywhere("Room",{"roomId":roomId,"roomType":1,"playerList":playerEntityList},Functor.Functor(self.playerCreateRoomCB,roomId))
Пример #14
0
	def	GetFriendList(self, uid, callBack):
		url = 'http://user.zgzlwy.top:9090/v1/user/friendlist?uid=' + uid
		KBEngine.urlopen(url, Functor.Functor(self.onGetFriendList, callBack))
		DEBUG_MSG("GetFriendList:"+url)
Пример #15
0
	def ZLLogin(self, loginName, password, datas, callBack):
		url = 'http://user.zgzlwy.top:9090/v1/user/loginnew?'
		param = "account="+ loginName + "&password=" + password
		KBEngine.urlopen(url, Functor.Functor(self.onZLLoginResult, loginName, callBack, datas), param.encode())
Пример #16
0
	def CheckBindWeChat(self, uid, callBack):
		url = 'http://120.79.192.49:80/weixinmp/querysub?uid=%s' % uid
		KBEngine.urlopen(url, Functor.Functor(self.onCheckBindWeChatd, callBack))
		DEBUG_MSG("CheckBindWeChat:"+url)
Пример #17
0
	def	CheckAccount(self, AccountName, Password, callBack):
		url = 'http://user.zgzlwy.top:9090/v1/user/validateaccount?account=%s&passwd=%s' % (AccountName, Password) 
		KBEngine.urlopen(url, Functor.Functor(self.onCheckAccount, callBack))
		DEBUG_MSG("CheckAccount:"+url)
Пример #18
0
	def	GetRechargeOrder(self, device_type, diamond, RMB,uid,callBack):
		url = 'http://120.79.192.49:80/pay/wxpayrecharge?'
		param = 'device_type=%d&gain_amount=%d&pay_amount_fee=%d&remark=%s&uid=%s' % (device_type, diamond, RMB,'', uid)
		KBEngine.urlopen(url, Functor.Functor(self.onRechargeOrderd, callBack), param.encode())
		DEBUG_MSG("GetRechargeOrder:"+url+param)
Пример #19
0

except ValueError:
    print(consts.VALUE_ERROR_COMUNCAT)
    input(consts.END)
    sys.exit()
except FileNotFoundError:
    print(consts.FILE_NOT_FOUND_COMUNICAT)
    input(consts.END)
    sys.exit()
if(file[0]=="" or file[1] == ""):
    input(consts.END)
    sys.exit()


func = Functor.functor(known_points[0], known_points[1])
interpolated_x_points = []
interpolated_y_points = []
parms = IOF.read_parms(file[0])
for i in numpy.arange(parms[0],parms[1],parms[2]):
    interpolated_x_points.append(i)
    interpolated_y_points.append( func(i))
        

pylab.plot(known_points[0],known_points[1],'o')
pylab.xlim(known_points[0][0]-known_points[0][len(known_points[0])-1]*0.5, known_points[0][len(known_points[0])-1]*1.5)
pylab.ylim(numpy.min(known_points[1])- numpy.max(known_points[1])*0.1, numpy.max(known_points[1])*1.5)

pylab.plot(interpolated_x_points,interpolated_y_points)

pylab.show()
Пример #20
0
 def reqYaoShu(self, DBID, MesaageUUID):
     DEBUG_MSG("reqYaoShu:%i" % (DBID))
     self.BuildGenerator('CallbackYaoShu')
     KBEngine.createEntityFromDBID("Account", DBID,
                                   Functor.Functor(self.CallbackYaoShu))
     self.ChangeMessageState(MesaageUUID, 3)
Пример #21
0
 def UpdatePetMapConfig(self):
     sql = "select * from tbl_Hall_PetMapConfigList; "
     KBEngine.executeRawDatabaseCommand(sql, Functor.Functor(self.sqlcallback))
Пример #22
0
 def reqCheckMessageCanSteal(self, DBID, ByDBID, MesaageUUID):
     self.CheckCanSteal(
         DBID, ByDBID,
         Functor.Functor(self.CheckMessageCanStealCallback, MesaageUUID))
Пример #23
0
 def GetTaskAward(self, FinishNum):
     #发送公众号验证
     self.owner.poller.CheckBindWeChat(
         self._TaskCom.owner.AccountName(),
         Functor.Functor(self.OnGetTaskAward, FinishNum))
Пример #24
0
	def	GetKglod(self, uid, callBack):
		Value = (uid+'ZLNC123').encode(encoding='utf-8')
		url = 'http://trade.zgzlwy.top:7070/v3/game/getkcoin?uid=%s&sign=%s' % (uid,md5Value(Value))
		KBEngine.urlopen(url, Functor.Functor(self.onGetKglod, callBack))
		DEBUG_MSG("GetKglod:"+url)