Esempio n. 1
0
    def __init__(self, server):
        self.server = server
        self.redis = redis_instance.getInst(PUBLIC_DB)

        self.work_robot_uids = []
        self.free_robots = []
        self.work_robots = []
        self.uid_to_robot = {}

        self.taskmaster()
Esempio n. 2
0
 def addGame(self, game, gameId):
     redis = redis_instance.getInst(PUBLIC_DB)
     gameTable = GAME_TABLE%(gameId)
     gameName = redis.hget(gameTable,'name')
     if gameName:
         game.roomName = gameName
     game.roomId = self.getRoomNum()
     game.gameName = gameName
     self.num2game[game.roomId] = game
     self.gameList.append(game)
     return True
Esempio n. 3
0
def restart(gameid, name, ip):

    redis = redis_instance.getInst(1)
    sendProtocol2GameService(redis, gameid, HEAD_SERVICE_PROTOCOL_GAME_CLOSE,
                             ip)
    print("start close gameid %s name %s" % (gameid, name))
    while True:
        code = checkProcess(name)
        if code == 0:
            break
        time.sleep(3)
        print("restart %s... %s ... %s" % (gameid, name, code))
    print("Success")
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        super(Server, self).__init__(*args, **kwargs)
        self.peers = {}
        self.peerList = []
        self.tickPeerIdx = 0
        self.initNetManager()
        self.tickTimer = LoopingCall(self.onTick)
        self.tickTimer.start(0.2, False)
        self.lastCheckTimestamp = self.getTimestamp()

        self.msgBuffers = []

        self.monitor()
        self.redis = redis_instance.getInst(PUBLIC_DB)
    def OnRefresh(self):
        """ 设置SID的超时时间

        :return:
        """
        print(u"开始设置超时时间:%s" % self.nickname)
        privateRedis = redis_instance.getInst(8)
        publicRedis = redis_instance.getInst(PUBLIC_DB)

        sid = self.operatorSessionId
        up_time = privateRedis.get("session:%s:timeout" % sid)
        if up_time:
            up_time = int(up_time)
            curTime = int(time.time())
            if (curTime - up_time) < 300:
                print(u"还没有到达超时时间:%s" % self.nickname)
                return
        SessionTable = FORMAT_USER_HALL_SESSION % (sid)
        print(u"设置超时时间的SESSIONTABLE=%s" % SessionTable)
        if publicRedis.exists(SessionTable):
            print(u"增加超时时间:%s" % self.nickname)
            publicRedis.expire(SessionTable, 60 * 10)
            privateRedis.set("session:%s:timeout" % sid, int(time.time()))
        print(u"设置超时时间结束:%s" % self.nickname)
    def loadDB(self, playerTable, isInit=True, account=None):
        #配置信息
        redis = redis_instance.getInst(PUBLIC_DB)

        if isInit:
            self.table = playerTable
            self.uid = self.table.split(':')[-1]
            self.account, self.passwd, self.nickname, self.money,\
                    self.parentAg, self.currency, self.valid, self.sex, self.headImgUrl, self.maxScore = redis.hmget(playerTable,
                        ('account', 'password', 'nickname', 'money', 'parentAg', 'currency', 'valid', 'sex', 'headImgUrl', 'maxScore'))

            self.coin, self.money = int(self.coin), round(float(self.money), 2)
            self.sex = int(self.sex) if self.sex else 0
            self.maxScore = int(self.maxScore) if self.maxScore and int(
                self.maxScore) >= 1 else 1
            self.headImgUrl = self.headImgUrl if self.headImgUrl else ''
            self.isGM = bool(int(redis.sismember(GM_SET, self.account)))

            roomCards = redis.get(USER4AGENT_CARD % (self.parentAg, self.uid))
            if roomCards and int(roomCards) > 0:
                self.roomCards = int(roomCards)
            else:
                self.roomCards = 0
            try:
                self.nickname = self.nickname.decode('utf-8')
            except:
                pass
        else:
            self.passwd, self.money, self.valid, self.sex, self.headImgUrl = redis.hmget(
                playerTable,
                ('password', 'money', 'valid', 'sex', 'headImgUrl'))

            self.money = round(float(self.money), 2)

            self.sex = int(self.sex) if self.sex else 0
            self.headImgUrl = self.headImgUrl if self.headImgUrl else ''

            roomCards = redis.get(USER4AGENT_CARD % (self.parentAg, self.uid))
            if roomCards and int(roomCards) > 0:
                self.roomCards = int(roomCards)
            else:
                self.roomCards = 0
Esempio n. 7
0
    def addGame(self, game, gameId,house_no):
        redis = redis_instance.getInst(PUBLIC_DB)
        gameTable = GAME_TABLE%(gameId)
        gameName = redis.hget(gameTable,'name')
        if gameName:
            game.roomName = gameName

        # 指定玩家加入某个房间 flag
        if house_no:
            game.roomId = house_no
        else:
            game.roomId = self.getRoomNum()

        redis.sadd('fish:%s:house:set'%self.sever.ID,game.roomId)
        redis.hset('fish:%s:house:%s:info'%(self.sever.ID,game.roomId),'player_num',1)

        game.gameName = gameName
        self.num2game[game.roomId] = game
        self.gameList.append(game)
        return True
Esempio n. 8
0
"""

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

from optparse import OptionParser
_cmd_parser = OptionParser(usage="usage: %prog [options]")
_opt = _cmd_parser.add_option
_opt("-n",
     "--name",
     action="store",
     type="string",
     default='',
     help="Service find string.")
_opt("-g",
     "--gameId",
     action="store",
     type="string",
     default='',
     help="Game id.")
_cmd_options, _cmd_args = _cmd_parser.parse_args()

from common.common_db_define import *
from common.db_utils import sendProtocol2GameService
import redis_instance

redis = redis_instance.getInst(1)
sendProtocol2GameService(redis, _cmd_options.gameId,
                         HEAD_SERVICE_PROTOCOL_GAME_CLOSE, _cmd_options.name)
Esempio n. 9
0
    def loadDB(self, playerTable, isInit=True, account = None):
        #配置信息
        redis = redis_instance.getInst(PUBLIC_DB)

        if isInit:
            self.table = playerTable
            self.uid = self.table.split(':')[-1]
            self.account, self.passwd, self.nickname, self.money, self.parentAg, self.currency,\
                    self.valid, self.sex, self.headImgUrl, self.maxScore, self.coin, self.ticketCount,\
                    self.totalProfitCoin4Ticket, self.cannonSkin = redis.hmget(playerTable,\
                    ('account', 'password', 'nickname', 'money', 'parentAg',\
                    'currency', 'valid', 'sex', 'headImgUrl', 'maxScore', 'coin', 'exchange_ticket', 'ticket_profit', 'cannonSkin'))

            try:
                self.coin = int(float(self.coin))
            except:
                self.coin = 0
            try:
                self.ticketCount = int(self.ticketCount)
            except:
                self.ticketCount = 0
            try:
                self.totalProfitCoin4Ticket = int(self.totalProfitCoin4Ticket)
            except:
                self.totalProfitCoin4Ticket = 0
            self.coin, self.money = int(self.coin), round(float(self.money), 2)
            self.initCoin = self.coin
            redis.hincrbyfloat(playerTable, 'coin', -self.coin)
            # self.coin = 99999
            self.sex = int(self.sex) if self.sex else 0
            self.maxScore = int(self.maxScore) if self.maxScore and int(self.maxScore) >= 1 else 1
            self.headImgUrl = self.headImgUrl if self.headImgUrl else ''
            self.isGM = bool(int(redis.sismember(GM_SET, self.account)))

            roomCards = redis.get(USER4AGENT_CARD%(self.parentAg, self.uid))
            if roomCards and int(roomCards) > 0:
                self.roomCards = int(roomCards)
            else:
                self.roomCards = 0
            try:
                self.nickname = self.nickname.decode('utf-8')
            except:
                pass

            self.cannonSkin = int(self.cannonSkin) if self.cannonSkin else 0

        else:
            self.passwd, self.money, self.valid, self.sex, self.headImgUrl, coin, self.cannonSkin = redis.hmget(playerTable, ('password', 'money', 'valid', 'sex', 'headImgUrl', 'coin', 'cannonSkin'))

            coin = int(coin)
            self.coin += coin
            self.addCoin += coin
            redis.hincrbyfloat(playerTable, 'coin', -coin)
            if self.game:
                coinRefresh = S_C_CoinRefresh()
                coinRefresh.side = self.chair
                coinRefresh.deltaCoin = coin
                self.game.sendExclude((self,), coinRefresh)

            self.sex = int(self.sex) if self.sex else 0
            self.headImgUrl = self.headImgUrl if self.headImgUrl else ''

            roomCards = redis.get(USER4AGENT_CARD%(self.parentAg, self.uid))
            if roomCards and int(roomCards) > 0:
                self.roomCards = int(roomCards)
            else:
                self.roomCards = 0
            self.cannonSkin = int(self.cannonSkin) if self.cannonSkin else 0
Esempio n. 10
0
    def __init__(self):
        super(CommonPlayer, self).__init__()

        self.game = None
        self.endType = None
        self.chair = consts.SIDE_UNKNOWN
        self.isControlByOne = False

        self.uid = 0
        self.account = ""
        self.passwd = ""
        self.nickname = ""
        self.money = 0
        self.coin = 0
        self.initCoin = 0
        self.addCoin = 0
        self.parentAg = ''
        self.sex = 0
        self.roomCards = 0
        self.headImgUrl = ''
        self.region = ''
        self.valid = '1'
        self.isGM = False
        # 总分数
        self.totalGameScore = 0
        self.maxScore = 1

        #微信
        self.openID = None
        self.refreshToken = None
        self.accessToken = None
        self.unionID = None

        self.table = ''

        #用户sessionId
        self.operatorSessionId = ""
        #本次登录session
        self.sessionId = ""
        self.cacheTable = ''

        self.lastSessionTimestamp = int(time.time() * 1000)
        self.lastGetRankTimestamp = 0
        self.gameLastPacketTimestamp = 0
        self.loginTime = 0

        # 玩家在线状态相关参数
        self.lastPingTimestamp = int(time.time() * 1000)
        self.lastOnlineState = False
        self.isOnline = True

        self.totalGameScore = 0
        #投注及得分信息缓存
        self.betCoin = 0
        self.profitCoin = 0
        self.totalBetCoin = 0
        self.totalProfitCoin = 0
        self.oldCoinDelta = 0
        self.oldMostHighFishLevel = self.mostHighFishLevel = 0
        self.oldMostHighFishCount = self.mostHighFishCount = 0
        self.isBetInfoDBCommiting = False
        self.coinDelta = 0
        self.coinRunning = 0
        self.taxCoin = 0

        #奖票
        self.addTicketCount = 0
        self.ticketCount = 0
        self.totalProfitCoin4Ticket = 0
        self.nextGetTicketTimestamp = 0

        #奖池
        self.curPrizePool = 0  # 用户当前的奖池
        self.curDivied = 0

        # 炮类型
        self.cannonSkin = 0

        # 弹头
        self.warhead = 0
        self.warhead_bonus = 0
        self.server = None
        self.redis = redis_instance.getInst(PUBLIC_DB)

        self.vip_level = 0