本文整理汇总了Python中sgLib.core.Gcore.sendmq方法的典型用法代码示例。如果您正苦于以下问题:Python Gcore.sendmq方法的具体用法?Python Gcore.sendmq怎么用?Python Gcore.sendmq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sgLib.core.Gcore
的用法示例。
在下文中一共展示了Gcore.sendmq方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: freed
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
def freed(self, huid, hsid): #玩家达到一定要求,被释放。
'''被释放 , 玩家使用调解卡时调用,释放自己
@param huid: 主人的用户ID
@param hsid: 主人的服务器ID
'''
if hsid == self.serverid: #占领者在本服
Data = Gcore.getMod('Building_resource',self.uid).collectAll() #将地里的资源以被占领的身份收集一次
Data['HoldEndTime'] = 0
Gcore.push(112, self.uid, Data,Type=0)
#查出进贡的钱
row = self.db.out_fields('tb_hold', ["JcoinGive", "GcoinGive"],\
'GiverId="%s" AND HolderId="%s"'%(self.uid, huid))
if row:
ja, ga = row["JcoinGive"], row["GcoinGive"]
modCoin = Gcore.getMod('Coin', huid)
j = modCoin.GainCoin(0, 2, ja, 'Building_holdMod.freed', {'hsid':hsid, 'huid':huid})
g = modCoin.GainCoin(0, 3, ga, 'Building_holdMod.freed', {'hsid':hsid, 'huid':huid})
dic = {'HolderId':0,'HolderServerId':0,'HoldEndTime':0}
self.db.update('tb_user', dic, 'UserId="%s"' % self.uid)
self.db.execute('DELETE FROM `tb_hold` WHERE GiverId="%s" AND HolderId="%s"' % (self.uid, huid))
self.db.execute('DELETE FROM `tb_hold_log` WHERE UserId="%s"' % self.uid)
self.db.execute('DELETE FROM `tb_hold_revenge` WHERE UserId="%s"' % self.uid)
else: #占领者不在本服
Gcore.sendmq(3, hsid, {'HolderId':huid,
'GiverServerId':self.serverid,
'GiverId':self.uid})
#删除自己的藩国redis
Gcore.redisM.hdel("sgHold", '%s.%s' % (self.serverid, self.uid))
return 1
示例2: free
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
def free(self, uid, sid, ts=None):
"""释放"""
if self.serverid == sid: # 本服
dic = {"HolderId": 0, "HolderServerId": 0, "HoldEndTime": 0}
self.db.update("tb_user", dic, 'UserId="%s"' % uid)
self.db.execute('DELETE FROM `tb_hold` WHERE GiverId="%s" AND HolderId="%s"' % (uid, self.uid))
self.db.execute('DELETE FROM `tb_hold_log` WHERE UserId="%s"' % uid)
self.db.execute('DELETE FROM `tb_hold_revenge` WHERE UserId="%s"' % uid)
else: # 非本服
Gcore.sendmq(2, sid, {"GiverId": uid})
Gcore.redisM.hdel("sgHold", "%s.%s" % (sid, uid))
return True
示例3: free
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
def free(self, uid, sid, ts=None):
'''主动释放别人'''
if self.serverid == sid: #本服
Data = Gcore.getMod('Building_resource',uid).collectAll() #被释放前,以被占领的身份收集一次
Data['HoldEndTime'] = 0
Gcore.push(112, uid, Data,Type=0)
dic = {'HolderId':0,'HolderServerId':0,'HoldEndTime':0}
self.db.update('tb_user', dic, 'UserId="%s"' % uid)
self.db.execute('DELETE FROM `tb_hold` WHERE GiverId="%s" AND HolderId="%s"' % (uid, self.uid))
self.db.execute('DELETE FROM `tb_hold_log` WHERE UserId="%s"' % uid)
self.db.execute('DELETE FROM `tb_hold_revenge` WHERE UserId="%s"' % uid)
else: #非本服
Gcore.sendmq(2, sid, {'GiverId':uid})
Gcore.redisM.hdel("sgHold", '%s.%s' % (sid, uid))
return True
示例4: freed
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
def freed(self, huid, hsid): # 玩家达到一定要求,被释放。
"""被释放"""
if hsid == self.serverid: # 占领者在本服
# 查出进贡的钱
row = self.db.out_fields(
"tb_hold", ["JcoinGive", "GcoinGive"], 'GiverId="%s" AND HolderId="%s"' % (self.uid, huid)
)
if not row:
return -1
ja, ga = row["JcoinGive"], row["GcoinGive"]
modCoin = Gcore.getMod("Coin", huid)
j = modCoin.GainCoin(0, 2, ja, "Building_holdMod.freed", {"hsid": hsid, "huid": huid})
g = modCoin.GainCoin(0, 3, ga, "Building_holdMod.freed", {"hsid": hsid, "huid": huid})
if j < -1 or g < -1:
return -2 # 占领者收钱失败
dic = {"HolderId": 0, "HolderServerId": 0, "HoldEndTime": 0}
self.db.update("tb_user", dic, 'UserId="%s"' % self.uid)
self.db.execute('DELETE FROM `tb_hold` WHERE GiverId="%s" AND HolderId="%s"' % (self.uid, huid))
self.db.execute('DELETE FROM `tb_hold_log` WHERE UserId="%s"' % self.uid)
self.db.execute('DELETE FROM `tb_hold_revenge` WHERE UserId="%s"' % self.uid)
else: # 占领者不在本服
Gcore.sendmq(3, hsid, {"HolderId": huid, "GiverServerId": self.serverid, "GiverId": self.uid})
return 1
示例5: setHold
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
def setHold(self, PeerUID, PeerSID):
'''设置别人成为藩国'''
#根据配置得出自动解除的天
HoldConfig = Gcore.loadCfg(Gcore.defined.CFG_BUILDING_HOLD)
RemoveRatio = HoldConfig['RemoveRatio']
d = None
for ind in range(1, len(RemoveRatio) + 1, 1):
r = random.random()
if r <= RemoveRatio[str(ind)]:
d = ind
break
#初始化元数据
BeginTime = int(time.time()) #开始时间
EndTime = BeginTime + int(d * 24 * 60 * 60) #预计结束时间(自动解除时间)
# + StopTime是真正结束的时间:默认是EndTime
# + LastCollectTime是最近一次奴隶的自动收集资源时间
StopTime, LastCollectTime = EndTime, BeginTime
Jcoin, Gcoin = 0, 0 #奴隶的贡献
print '是否是本服', PeerSID == self.serverid, PeerSID, self.serverid
if PeerSID == self.serverid: #本服
print '本服'
pMod = Gcore.getMod('Player', PeerUID)
protectHoldEndTime = pMod.getUserInfo('ProtectHoldEndTime')
if BeginTime < protectHoldEndTime:
return -1 #对方处于保护时间内,设置失败add by qiudx
Data = Gcore.getMod('Building_resource',PeerUID).collectAll() #将地里的资源以自由身的身份收集一次
Data['HoldEndTime'] = EndTime if not Gcore.TEST else int(time.time()+180)
Data['HolderName'] = Gcore.getUserData(self.uid,'NickName')
Data['GiveRatio'] = Gcore.loadCfg(1506).get('GiveRatio',0.05)
Gcore.push(112, PeerUID, Data,Type=1)
# + 更新用户表
arr = {'HolderId':self.uid,'HolderServerId':self.serverid,'HoldEndTime':EndTime}
self.db.update('tb_user', arr, 'UserId=%s' % PeerUID)
# + 插入本服藩国记录
arr = {"HolderId":self.uid, "GiverId":PeerUID, "LastCollectTime":LastCollectTime,
"JcoinGive":Jcoin, "GcoinGive":Gcoin, "StopTime":StopTime,
"BeginTime": BeginTime, "EndTime":EndTime}
#self.db.insert('tb_hold', arr)
self.db.insert_update('tb_hold', arr, {"GiverId":PeerUID} )
# + 插入纳贡记录
arr = {"UserId":PeerUID, "HolderId":self.uid, "Gcoin":0,
"HolderServerId":self.serverid, "Jcoin":0, "LastGiveTime":BeginTime}
self.db.insert_update('tb_hold_log', arr, {"UserId":PeerUID} )
# + 插入藩国反抗记录
date = datetime.date.strftime(datetime.date.fromtimestamp(BeginTime), "%Y-%m-%d")
arr = {"UserId":PeerUID, "HolderId":self.uid, "HolderServerId":self.serverid,
"ProcessTotal":0, "RevengeCount":0, "LastRevengeDate":date}
self.db.insert_update('tb_hold_revenge', arr, {"UserId":PeerUID} )
else: #非本服,发消息
peerKey = Gcore.redisKey(PeerUID)
protectHoldEndTime = Gcore.redisM.hget('sgProtectHold', peerKey)
if BeginTime < protectHoldEndTime:
return -1 #潘国保护时间内,设置失败
Gcore.sendmq(1, PeerSID, {'HolderId':self.uid,
'HolderServerId':self.serverid,
'GiverId':PeerUID,
'EndTime':int(EndTime)})
k = '%s.%s' % (PeerSID, PeerUID)
v = '%s.%s.%s.%s.%s.%s' % (self.serverid, self.uid, BeginTime, StopTime, EndTime, LastCollectTime)
Gcore.redisM.hset('sgHold', k, v) #货币相关已独立出来 by Lizr
k += Gcore.redisKey(self.uid)
Gcore.redisM.hset('sgHoldJcoin', k, 0) #1.1008.2.1001 前面是进贡的人 后面的纳贡的人
Gcore.redisM.hset('sgHoldGcoin', k, 0)
return True
示例6: setHold
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
def setHold(self, PeerUID, PeerSID):
"""设置别人成为藩国"""
# 根据配置得出自动解除的天
HoldConfig = Gcore.loadCfg(Gcore.defined.CFG_BUILDING_HOLD)
RemoveRatio = HoldConfig["RemoveRatio"]
d = None
for ind in range(1, len(RemoveRatio) + 1, 1):
r = random.random()
if r <= RemoveRatio[str(ind)]:
d = ind
break
# 初始化元数据
BeginTime = int(time.time()) # 开始时间
EndTime = BeginTime + int(d * 24 * 60 * 60) # 预计结束时间(自动解除时间)
# + StopTime是真正结束的时间:默认是EndTime
# + LastCollectTime是最近一次奴隶的自动收集资源时间
StopTime, LastCollectTime = EndTime, BeginTime
Jcoin, Gcoin = 0, 0 # 奴隶的贡献
print "是否是本服", PeerSID == self.serverid, PeerSID, self.serverid
if PeerSID == self.serverid: # 本服
print "本服"
# + 更新用户表
arr = {"HolderId": self.uid, "HolderServerId": self.serverid, "HoldEndTime": EndTime}
self.db.update("tb_user", arr, "UserId=%s" % PeerUID)
# + 插入本服藩国记录
arr = {
"HolderId": self.uid,
"GiverId": PeerUID,
"LastCollectTime": LastCollectTime,
"JcoinGive": Jcoin,
"GcoinGive": Gcoin,
"StopTime": StopTime,
"BeginTime": BeginTime,
"EndTime": EndTime,
}
self.db.insert("tb_hold", arr)
print self.db.sql
# + 插入纳贡记录
arr = {
"UserId": PeerUID,
"HolderId": self.uid,
"Gcoin": 0,
"HolderServerId": self.serverid,
"Jcoin": 0,
"LastGiveTime": BeginTime,
}
self.db.insert("tb_hold_log", arr)
# + 插入藩国反抗记录
date = datetime.date.strftime(datetime.date.fromtimestamp(BeginTime), "%Y-%m-%d")
arr = {
"UserId": PeerUID,
"HolderId": self.uid,
"HolderServerId": self.serverid,
"ProcessTotal": 0,
"RevengeCount": 0,
"LastRevengeDate": date,
}
self.db.insert("tb_hold_revenge", arr)
else: # 非本服,发消息
Gcore.sendmq(
1,
PeerSID,
{"HolderId": self.uid, "HolderServerId": self.serverid, "GiverId": PeerUID, "EndTime": int(EndTime)},
)
k = "%s.%s" % (PeerSID, PeerUID)
v = "%s.%s.%s.%s.%s.%s.%s.%s" % (
self.serverid,
self.uid,
BeginTime,
StopTime,
EndTime,
LastCollectTime,
Jcoin,
Gcoin,
)
Gcore.redisM.hset("sgHold", k, v)
# Gcore.redisM.hset('sgHoldJcoin', k, 0)
# Gcore.redisM.hset('sgHoldGcoin', k, 0)
return True
示例7: ensure_chan
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
chan = self.ensure_chan()
message = amqp.Message(str(msg))
message.properties['delivery_mode'] = 2
toServerId = msg['toServerId']
eid = toServerId % config.EXCHANGE_NUM
if eid==0:
eid = config.EXCHANGE_NUM
chan.basic_publish(message, exchange='sggameexchange%d'%eid, routing_key=str(toServerId))
def ensure_chan(self):
'''获取channel'''
if not isinstance(self.con, amqp.connection.Connection):
self.con = amqp.Connection(host=config.MQ_HOST, userid=config.MQ_UID, \
password=config.MQ_PWD, virtual_host=config.MQ_VHOST, insit=False)
else:
for k in self.con.channels:
if isinstance(self.con.channels[k], amqp.channel.Channel):
return self.con.channels[k]
return self.con.channel()
if '__main__' == __name__:
'''调试'''
r = Rabbit()
#print r.put({'toServerId':2, 'optId':15013})
#print r.loop()
Gcore.sendmq(15013, 1,{'jj':'sb'})
print 'before sleep'
time.sleep(10)
print 'end'
示例8: int
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import sendmq [as 别名]
#进贡记录
table = 'tb_hold_log'
where = 'UserId=' + ' OR UserId= '.join(map(str, uids))
jstr = 'CASE UserId '
gstr = ' CASE UserId'
for UserId in uids:
jstr += ' WHEN %d THEN %d' % (UserId, incdic.get(UserId, {}).get(1, 0))
gstr += ' WHEN %d THEN %d' % (UserId, incdic.get(UserId, {}).get(2, 0))
jstr += ' END '
gstr += ' END '
sql = 'UPDATE tb_hold_log SET Jcoin = Jcoin+%s, Gcoin = Gcoin+%s, LastGiveTime="%s" WHERE %s' \
% (jstr, gstr, curtime, where)
db.execute(sql)
print '进贡日志:',sql
#自动解除关系 (前台自己到时间,请求接口,自动更新资源情况)
for row in rows:
if row["HoldEndTime"] > curtime + 600: #提前10分钟释放
continue
if row["HolderServerId"] == Gcore.getServerId(): #本服
ui = Gcore.getUI('Building_hold', row["HolderId"])
ui.SlaveOperand({'typ':2, 'uid':row["UserId"], 'sid':Gcore.getServerId()})
else: #非本服,发消息
msg = {'HolderId':row["HolderId"], "GiverId":row["UserId"], "GiverServerId":Gcore.getServerId()}
Gcore.sendmq(3, int(row["HolderServerId"]), msg)
cnt += 1
runtime = time.time()-curtime
print 'Finish at:',Gcore.common.now()
print 'Total Runtime:', runtime