def pvp_award_tick(): tick_time = game_configs.base_config.get('arena_shorttime_points_time') reactor.callLater(tick_time, pvp_award_tick) try: pvp_award() except Exception, e: logger.exception(e)
def printMem(): ### 强制进行垃圾回收 print gc.collect() print "###################MEM#####################" print gc.garbage print "###########################################" reactor.callLater(2, printMem)
def serverStop(): """停止服务进程""" logger.info('stop') if GlobalObject().stophandler: GlobalObject().stophandler() reactor.callLater(0.5, reactor.stop) return True
def stop(): '''stop service ''' for child in GlobalObject().root.childsmanager._childs.values(): child.callbackChildNotForResult('serverStop') reactor.callLater(0.5, reactor.stop) return "stop"
def tick(): result = GlobalObject().remote['login'].server_sync_remote( name, front_ip, front_port, 'recommend') if result is False: reactor.callLater(1, tick) else: reactor.callLater(60, tick)
def recharge(self): result = self._get_balance_m() if not result: return False balance, gen_balance = result # 充值结果:balance 当前值, gen_balance 赠送 # add gen balance gen_balance_add = gen_balance - self._owner.base_info.gen_balance self._owner.finance.gold += gen_balance_add self._owner.finance.save_data() recharge_balance = balance - self._owner.finance.gold # 累计充值数量 self._owner.base_info.gen_balance = gen_balance self._owner.base_info.save_data() if recharge_balance > 0: #self._owner.recharge.charge(recharge_balance) # 充值活动 #self._owner.base_info.recharge += recharge_balance #self._owner.base_info.set_vip_level(self._owner.base_info.recharge) self._owner.finance.gold = balance #self._owner.base_info.save_data() self._owner.finance.save_data() self.loop_times = 0 response = GetGoldResponse() response.res.result = True response.gold = self._owner.finance.gold response.vip_level = self._owner.base_info.vip_level remote_gate.push_object_remote(2001, response.SerializePartialToString(), self._owner.base_info.id) else: self.loop_times += 1 reactor.callLater(30*self.loop_times, self.recharge)
def loop_update(self): # notice notice_item = game_configs.notes_config.get(1001) current_time = time.time() #logger.debug("current_time:%s, target_time:%s" % (current_time, str_time_to_timestamp(notice_item.parameter1[0]))) # 幸运武将更新 if self._lucky_hero_start > current_time or self._lucky_hero_end < current_time: #logger.debug("lucky_hero_start %s, current_time %s, lucky_hero_end %s" % (self._lucky_hero_start, current_time, self._lucky_hero_end)) self._lucky_heros, self._lucky_hero_start, self._lucky_hero_end = update_lucky_hero(1) time1 = str_time_to_timestamp(notice_item.parameter1[0]) time2 = str_time_to_timestamp(notice_item.parameter1[1]) if (current_time < time1 and current_time > time1-1) or (current_time < time2 and current_time > time2-1): response = NoticeResponse() response.notice_id = 1001 push_all_object_message(2000, response.SerializePartialToString()) if self._stage_id and self.in_the_time_period() and self._state == 0: self.start_boss() self._state = 1 if self._stage_id and self._state == 1 and (not self.in_the_time_period()): self.update_boss() self._state = 0 reactor.callLater(1, self.loop_update)
def serverStop(): """供master调用的接口:关闭服务器 """ logger.info('stop') if GlobalObject().stophandler: GlobalObject().stophandler() reactor.callLater(0.5, reactor.stop) return True
def serverstart(): '''服务配置 ''' log.startLogging(sys.stdout) factory.addServiceChannel(service) reactor.callLater(10,factory.pushObject,111,'asdfe',[0]) reactor.callLater(15,factory.loseConnection,0) reactor.listenTCP(1000,factory) reactor.run()
def tick(): result = GlobalObject().remote['login'].server_sync_remote( name, front_ip, front_port, '1', server_no) if result is False: reactor.callLater(1, tick) else: reactor.callLater(60, tick) logger.info('server online num:%s', UsersManager().get_online_num()) tlog_action.log('OnlineNum', UsersManager().get_online_num())
def checkSync(self, timeout=TIMEOUT): """检测同步 """ ntime = time.time() objtime = MemObject.get(self, '_time') if ntime - objtime >= timeout and timeout: self.mdelete() else: reactor.callLater(0, self.syncDB)
def tick(): result = GlobalObject().remote['login'].server_sync_remote(name, front_ip, front_port, '1', server_no) if result is False: reactor.callLater(1, tick) else: reactor.callLater(60, tick) logger.info('server online num:%s', UsersManager().get_online_num()) tlog_action.log('OnlineNum', UsersManager().get_online_num())
def __init__(self, boss_name, rank_instance, config_name): super(WorldBoss, self).__init__(boss_name, rank_instance, config_name, tb_boss) self._stage_id_am = 0 # 关卡id am self._stage_id_pm = 0 # 关卡id pm self._lucky_hero_start = 0 # 当前幸运武将时间 self._lucky_hero_end = 0 # 当前幸运武将时间 self._state = 0 # boss状态:用于boss到期, 重置状态 self.init_data() #self.init_time() reactor.callLater(1, self.loop_update)
def looptask(self, current_task): """ loop 化任务 :param current_task: :return: """ current_task.task() if current_task.isloop: reactor.callLater(current_task.t, self.looptask, current_task) else: reactor.callLater(self.getLater(everytime=current_task.t), self.looptask, current_task)
def loop_update(self): if self._stage_id and self.in_the_time_period() and self._state == 0: self._state = 1 if self._stage_id and self._state == 1 and self._hp<=0 and self.in_the_time_period(): self._state = 2 if self._stage_id and self._state!=0 and (not self.in_the_time_period()): self.update_boss() self._state = 0 reactor.callLater(1, self.loop_update)
def pvp_daily_award_tick(): award_time_x = game_configs.base_config.get('arena_day_points_time') award_time = time.strftime("%Y-%m-%d %X", time.localtime())[0:-8] award_time += award_time_x now_time = int(time.time()) award_strptime = time.strptime(award_time, "%Y-%m-%d %X") award_mktime = time.mktime(award_strptime) time_long = award_mktime - now_time if time_long >= 0: time_interval = time_long else: time_interval = 60*60*24 + time_long logger.debug('pvp daily award -tick interval time:%s', time_interval) reactor.callLater(time_interval, do_pvp_daily_award_tick)
def net_conn_lost_remote_noresult(dynamic_id): """客户端断开连接时的处理 @param dynamic_id: int 客户端的动态ID """ vcharacter = VCharacterManager().get_by_dynamic_id(dynamic_id) print "net lost1++++++++++++++++", dynamic_id if vcharacter and vcharacter.node: vcharacter.locked = True # 锁定角色 vcharacter.state = 0 # 设置掉线状态 reactor.callLater(const.KEEP_USER_AFTER_DROP, net_conn_lost, dynamic_id) else: UsersManager().drop_by_dynamic_id(dynamic_id)
def pvp_daily_award_tick(): award_time_x = game_configs.base_config.get('arena_day_points_time') award_time = time.strftime("%Y-%m-%d %X", time.localtime())[0:-8] award_time += award_time_x now_time = int(time.time()) award_strptime = time.strptime(award_time, "%Y-%m-%d %X") award_mktime = time.mktime(award_strptime) time_long = award_mktime - now_time if time_long >= 0: time_interval = time_long else: time_interval = 60 * 60 * 24 + time_long logger.debug('pvp daily award -tick interval time:%s', time_interval) reactor.callLater(time_interval, do_pvp_daily_award_tick)
def __init__(self): super(WorldBoss, self).__init__() self._lucky_high_heros = [] # 高级幸运武将 self._lucky_middle_heros = [] # 中级幸运武将 self._lucky_low_heros = [] # 低级幸运武将 self._debuff_skill_no = 0 # debuff id self._last_shot_item = {} # 最后击杀 self._stage_id_am = 0 # 关卡id am self._stage_id_pm = 0 # 关卡id pm self._stage_id = 0 # 关卡id self._hp = 0 # 剩余血量 self._state = 0 # boss状态:用于boss到期, 重置状态 self.init_data() self.init_time() reactor.callLater(1, self.loop_update)
def deal_event(self, the_time=0): now = int(time.time()) next_time = 0 for x, _ in self._events.items(): if x <= now or x > now + 60: continue if not next_time: next_time = x continue if x < next_time: next_time = x t = time.localtime(now) time0 = int( time.mktime( time.strptime(time.strftime('%Y-%m-%d 00:00:00', t), '%Y-%m-%d %H:%M:%S'))) for x, _ in self._day_events.items(): x_time = time0 + x if x_time <= now or x_time > now + 60: continue if not next_time: next_time = x_time continue if x_time < next_time: next_time = x_time if next_time: reactor.callLater(next_time - now, self.deal_event, the_time=next_time) else: reactor.callLater(60, self.deal_event, the_time=next_time) if not the_time: return day_time = the_time - time0 if not day_time: day_time = 60 * 60 * 24 events = self._events.get(the_time, []) for event in events: event() events = self._day_events.get(day_time, []) for event in events: event()
def run(self, current_task): """ 入口 :return: """ if current_task.isloop: current_task.task() if type(current_task.t) not in [int, float]: raise Exception("invalid loop task time. %s" % current_task.t) reactor.callLater(current_task.t, self.looptask, current_task) else: #定时任务 if current_task.isstartcall: #服务器开启时执行一次 current_task.task() if type(current_task.t) != str: raise Exception("invalid cron task time. %s" % current_task.t) reactor.callLater(self.getLater(everytime=current_task.t), self.looptask, current_task)
def deal_event(self, the_time=0): now = int(time.time()) next_time = 0 for x, _ in self._events.items(): if x <= now or x > now+60: continue if not next_time: next_time = x continue if x < next_time: next_time = x t = time.localtime(now) time0 = int(time.mktime(time.strptime( time.strftime('%Y-%m-%d 00:00:00', t), '%Y-%m-%d %H:%M:%S'))) for x, _ in self._day_events.items(): x_time = time0 + x if x_time <= now or x_time > now+60: continue if not next_time: next_time = x_time continue if x_time < next_time: next_time = x_time if next_time: reactor.callLater(next_time-now, self.deal_event, the_time=next_time) else: reactor.callLater(60, self.deal_event, the_time=next_time) if not the_time: return day_time = the_time - time0 if not day_time: day_time = 60 * 60 * 24 events = self._events.get(the_time, []) for event in events: event() events = self._day_events.get(day_time, []) for event in events: event()
def startClient(): reactor.callLater(3,apptest,'printData1',u"node测试1",u"node测试2") remote.connect(addr)#连接远程主机 reactor.run()
#coding:utf8 import action from gfirefly.server.logobj import logger from gtwisted.core import reactor from gfirefly.server.globalobject import GlobalObject from shared.utils.ranking import Ranking front_ip = GlobalObject().json_config['front_ip'] front_port = GlobalObject().json_config['front_port'] name = GlobalObject().json_config['name'] def tick(): result = GlobalObject().remote['login'].server_sync_remote( name, front_ip, front_port, 'recommend') if result is False: reactor.callLater(1, tick) else: reactor.callLater(60, tick) reactor.callLater(1, tick) # 初始化工会排行 Ranking.init('GuildLevel', 9999)
def CheckMemDB(delta): ''' ''' MAdminManager().checkAdmins() reactor.callLater(delta,CheckMemDB,delta)
def sendHeatData(self): self.ping_st = time.time() self.sendMsg({"type": "ping"}) reactor.callLater(28, self.sendHeatData)
from shared.utils.const import const import time from gfirefly.dbentrust.redis_mode import RedisObject tb_guild_info = RedisObject('tb_guild_info') #from app.game.redis_mode import tb_guild_info front_ip = GlobalObject().json_config['front_ip'] front_port = GlobalObject().json_config['front_port'] name = GlobalObject().json_config['name'] server_no = GlobalObject().allconfig['server_no'] guild_incr = tb_guild_info.getObj('incr') if not guild_incr.exists(): guild_incr.incr(amount=10000) def tick(): result = GlobalObject().remote['login'].server_sync_remote(name, front_ip, front_port, '1', server_no) if result is False: reactor.callLater(1, tick) else: reactor.callLater(60, tick) logger.info('server online num:%s', UsersManager().get_online_num()) tlog_action.log('OnlineNum', UsersManager().get_online_num()) reactor.callLater(3, tick)
def tick_rank(): do_tick_rank() need_time1 = 24 * 60 * 60 reactor.callLater(need_time1, tick_rank)
print "Hello World!" class MyPBClientFactory(PBClientFactory): protocol = MyPBClientProtocl client = MyPBClientFactory() def printok(): print "ok" reactor.callLater(1, printok) def callRemote(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult1',8,9) print result def callRemote2(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult',8,9) print 'result',result reactor.connectTCP('localhost', 1000, client) # reactor.callLater(3, callRemote) reactor.callLater(5, callRemote2) # reactor.callLater(1, printok) log.startLogging(sys.stdout) reactor.run()
@param target: func Object ''' ser.mapTarget(target) @serviceHandle def printData1(data,data1): print data,data1 print "############################" # d = root.callChild("test_node",1,u'Root测试') return data @serviceHandle def printData2(data,data1): print data,data1 print "############################" d = root.callChild("test_node",1,u'Root测试') return data def printMem(): ### 强制进行垃圾回收 print gc.collect() print "###################MEM#####################" print gc.garbage print "###########################################" reactor.callLater(2, printMem) if __name__=='__main__': reactor.listenTCP(9090, BilateralFactory(root)) reactor.callLater(2, printMem) reactor.run()
protocol = MyPBClientProtocl client = MyPBClientFactory() def printok(): print "ok" reactor.callLater(1, printok) def callRemote(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult1', 8, 9) print result def callRemote2(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult', 8, 9) print 'result', result reactor.connectTCP('localhost', 1000, client) # reactor.callLater(3, callRemote) reactor.callLater(5, callRemote2) # reactor.callLater(1, printok) log.startLogging(sys.stdout) reactor.run()
def check_mem_db(delta): """同步内存数据到数据库 """ new_character_ids = tb_character_info.smem('new') new_character_ids = filter(lambda x: x >= 10000, new_character_ids) for char_id in new_character_ids: character_obj = tb_character_info.getObj(char_id) character_info = character_obj.hgetall() character_equipments = character_obj.getObj('equipments').hgetall() character_mails = character_obj.getObj('mails').hgetall() character_heroes = character_obj.getObj('heroes').hgetall() user_data = dict(id=char_id, base_info=cPickle.dumps(character_info), heroes=cPickle.dumps(character_heroes), mails=cPickle.dumps(character_mails), equipments=cPickle.dumps(character_equipments)) insert_result = util.InsertIntoDB(CHARACTER_TABLE_NAME, user_data) if not insert_result: logger.error('insert id:%s error', char_id) result = util.GetOneRecordInfo(CHARACTER_TABLE_NAME, dict(id=char_id), ['id']) if result: tb_character_info.sadd('all', char_id) tb_character_info.srem('new', char_id) else: tb_character_info.sadd('all', char_id) tb_character_info.srem('new', char_id) logger.info('new character:%s', char_id) break global ALL_CHARACTER_IDS if not ALL_CHARACTER_IDS: ALL_CHARACTER_IDS = tb_character_info.smem('all') for char_id in ALL_CHARACTER_IDS: character_obj = tb_character_info.getObj(char_id) character_info = character_obj.hgetall() character_equipments = character_obj.getObj('equipments').hgetall() character_mails = character_obj.getObj('mails').hgetall() character_heroes = character_obj.getObj('heroes').hgetall() user_data = dict(base_info=cPickle.dumps(character_info), heroes=cPickle.dumps(character_heroes), mails=cPickle.dumps(character_mails), equipments=cPickle.dumps(character_equipments)) pwere = dict(id=char_id) result = util.GetOneRecordInfo(CHARACTER_TABLE_NAME, pwere, ['id']) if not result: logger.error('all insert id:%s error', char_id) tb_character_info.sadd('new', char_id) else: result = util.UpdateWithDict(CHARACTER_TABLE_NAME, user_data, pwere) if not result: logger.error('update id:%s error', char_id) # else: # logger.info('save character:%s', char_id) ALL_CHARACTER_IDS.remove(char_id) break if not new_character_ids and not ALL_CHARACTER_IDS: reactor.callLater(delta*10, check_mem_db, delta) else: reactor.callLater(delta, check_mem_db, delta)
# -*- coding:utf-8 -*- import action from gtwisted.core import reactor from app.push.core.pusher import pusher # from gfirefly.server.logobj import logger def do_push(): pusher.gen_task() pusher.process() reactor.callLater(10, do_push) # logger.info('push data num:%s', 1) reactor.callLater(10, do_push)
def PushActionMessage(openid): from gtwisted.core import reactor reactor.callLater(0.1, popROleMessage,openid)
@serviceHandle def printData1(data, data1): print data, data1 print "############################" # d = root.callChild("test_node",1,u'Root测试') return data @serviceHandle def printData2(data, data1): print data, data1 print "############################" d = root.callChild("test_node", 1, u"Root测试") return data def printMem(): ### 强制进行垃圾回收 print gc.collect() print "###################MEM#####################" print gc.garbage print "###########################################" reactor.callLater(2, printMem) if __name__ == "__main__": reactor.listenTCP(9090, BilateralFactory(root)) reactor.callLater(2, printMem) reactor.run()
class MyPBClientFactory(PBClientFactory): protocol = MyPBClientProtocl client = MyPBClientFactory() def printok(): print "ok" reactor.callLater(1, printok) def callRemote(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult',8,9) print result def callRemote2(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult',8,9) print 'result',result reactor.connectTCP('localhost', 10000, client) reactor.callLater(3, callRemote) # reactor.callLater(5, callRemote2) # reactor.callLater(1, printok) # log.startLogging(sys.stdout) reactor.run()
def tick_rank(): do_tick_rank() need_time1 = 24*60*60 reactor.callLater(need_time1, tick_rank)
def printok(): print "ok" reactor.callLater(1, printok)
protocol = MyPBClientProtocl client = MyPBClientFactory() def printok(): print "ok" reactor.callLater(1, printok) def callRemote(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult', 8, 9) print result def callRemote2(): dd = client.getRootObject() result = dd.callRemoteForResult('getResult', 8, 9) print 'result', result reactor.connectTCP('localhost', 10000, client) reactor.callLater(3, callRemote) # reactor.callLater(5, callRemote2) # reactor.callLater(1, printok) # log.startLogging(sys.stdout) reactor.run()
# -*- coding:utf-8 -*- """ created by sphinx on """ import message from pvp_award import do_pvp_daily_award_tick from gtwisted.core import reactor from shared.time_event_manager.te_manager import te_manager from shared.db_opear.configs_data import game_configs reactor.callLater(600, pvp_award.pvp_award_tick) award_time = game_configs.base_config.get('arena_day_points_time').split(':') # pvp_award.pvp_daily_award_tick() the_time = int(award_time[0])*60*60 + int(award_time[1])*60 + int(award_time[2]) te_manager.add_event(the_time, 2, do_pvp_daily_award_tick) te_manager.deal_event()
def startClient(): reactor.callLater(3, apptest, 'printData1', u"node测试1", u"node测试2") reactor.callLater(5, apptest, 'printData1', u"node测试1", u"node测试2") remote.connect(addr) #连接远程主机 reactor.run()
def do_push(): pusher.gen_task() pusher.process() reactor.callLater(10, do_push)
def check_mem_db(delta): """同步内存数据到数据库 """ MAdminManager().checkAdmins() reactor.callLater(delta, check_mem_db, delta)