def playing_slaughter_house_on_event_playing_create(message_type, channel, channel_type, serialize):
  message = ccevent.playing.ttypes.EventPlayingCreate()
  TSerialization.deserialize(message, serialize)

  playing_config = slaughter_house_types.Config.get(message.template_)
  if playing_config == None:
    proxy.Logging.error("[slaughter_house] slaughter_house_types.Config.get(%d) failed."\
        % message.template_)
    return None

  playing = slaughter_house_types.Playing(message.playing_, message.template_, message.scene_)
  slaughter_house_types.PlayingManager.add(playing)

  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,\
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,\
      "playing_slaughter_house_on_event_playing_actor_enter")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,\
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,\
      "playing_slaughter_house_on_event_playing_actor_leave")

  # 副本开始后进行30秒倒计时
  proxy.Timer.add(message.playing_, 30 * 1000, 1, "playing_slaughter_house_on_timer_start")
  proxy.Timer.add(message.playing_, 3000, -1, "playing_slaughter_house_on_timer_sync_ranking")

  proxy.Logging.debug("[slaughter_house] playing(%d,%d,%d) create"\
      % (message.playing_, message.template_, message.scene_))
def playing_monsters_on_event_actor_kill_npc(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.actor.ttypes.EventActorKillNpc()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 获取玩家所在副本ID
  playing_id = monsters_types.PlayingManager.get_actor_playing(message.actor_)
  if playing_id == None or playing_id == 0:
    proxy.Logging.error("[monsters] PlayingManager.get_actor_playing(%d) failed" % message.actor_)
    return None

  # 获取副本对象
  playing = monsters_types.PlayingManager.get(playing_id)
  if playing == None:
    proxy.Logging.error("[monsters] PlayingManager.get(%d) failed" % playing_id)
    return None

  # 获取当前的怪物笼子
  current_cage = playing.get_current_cage()
  if current_cage == None:
    proxy.Logging.error("[monsters] playing.get_current_cage failed.")
    return None

  # 增加杀死NPC数量
  current_cage.add_kill_npc_num(1)

  if current_cage.check_finish_cage() == True:
	def message_handler(self, msg):	# CHECK: IS IT NECESSARY TO HAVE IT DECLARED IN THE SUPERCLASS IF YOU HAVE IT IN THE SUBCLASS?
		logging.debug ("Entered function")
		if len(msg) < 3:
			logging.error("ERROR", "Received message is incomplete (topic, header or bodymsg may be missing)")
			# ERROR
		else:
			topic = msg[0]
			msg_header = TSerialization.deserialize(thrift.MsgHeader(), msg[1])
	
			messagetype = ('CREATE', 'CONFIGURE', 'REQUEST', 'RELEASE', 'INFORM')	## DEBUGGING ONLY. ERASE AFTERWARDS!
			logging.info("Got a message of type:%s", messagetype[msg_header.mtype])
			function_mapper = ('CreateMsg', 'ConfigMsg', 'RequestMsg', 'ReleaseMsg')
			# decoding_base = globals()["thrift."+function_mapper[msg_header.mtype]] ## REMOVE. This would produce a key error
			decoding_base = getattr(thrift, function_mapper[msg_header.mtype])
			bodymsg = TSerialization.deserialize(decoding_base(), msg[2])	
			coded_attachments = msg[3:len(msg)]
			if topic != self.name and topic in self.topics: # Then it should be addressed to a group the node is member of
				group = topic.split(".#")[0]	# Since all topics end in ".#", it must be removed to get the group name.
			else:
				group = None
			# TODO: Keep working on making it more generic later
			if msg_header.mtype == thrift.MessageType.CREATE:
				self.create (bodymsg.child_type, group, coded_attachments)
			elif msg_header.mtype == thrift.MessageType.CONFIGURE:	
				self.configure(bodymsg)
			elif msg_header.mtype == thrift.MessageType.REQUEST:	#MOCKUP
				body_base = thrift.RequestMsg()
			elif msg_header.mtype == thrift.MessageType.RELEASE:	#MOCKUP
				body_base = thrift.ReleaseMsg()
			else:
				logging.error("ERROR", "Wrong MessageType: {0}".format(msg_header.mtype))
def playing_slaughter_house_on_event_playing_actor_leave(message_type, channel, channel_type, serialize):
  message = ccevent.playing.ttypes.EventPlayingActorLeave()
  TSerialization.deserialize(message, serialize)

  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_slaughter_house_on_event_actor_killed")
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_slaughter_house_on_event_actor_kill_npc")

  playing = slaughter_house_types.PlayingManager.get(message.playing_)
  if playing == None:
    return None

  actor = playing.get_actor(message.actor_)
  if actor == None:
    proxy.Logging.error("[slaughter_house] playing.get_actor(%d) failed." % message.actor_)
    return None

  actor.leaving_ = True;

  slaughter_house_types.PlayingManager.remove_actor(message.actor_)

  proxy.Logging.debug("[slaughter_house] actor(%d) leave from playing" % message.actor_)
Example #5
0
def playing_on_event_playing_request_update_record(message_type, channel, channel_type, serialize):
  # 事件对象
  message = ccevent.playing.ttypes.EventPlayingRequestUpdateRecord()
  # 反序列化
  TSerialization.deserialize(message, serialize)
  if message.template_ >= 1 and message.template_ <= 6:
    plot.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  elif message.template_ >= 7 and message.template_ <= 14:
    idol.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  elif message.template_ == 15:
    slime.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  elif message.template_ == 16:
    coliseum.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  elif message.template_ == 17:
    unreal_soul.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  elif message.template_ == 18 and message.template_ <= 21:
    slaughter_house.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  elif message.template_ >= 100 and message.template_ <= 107:
    team.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  elif message.template_ >= 201 and message.template_ <= 224:
    guild.update_record(message.actor_, message.template_,
        message.result_, message.record_)
  else:
    None
Example #6
0
def playing_slime_on_event_playing_actor_leave(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorLeave()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 取消关注玩家杀死NPC事件
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_slime_on_event_actor_kill_npc")
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_slime_on_event_playing_actor_request_complete")

  # 副本管理器中删除玩家ID和副本ID的映射关系
  slime_types.PlayingManager.remove_actor(message.actor_)

  # 移除临时技能
  facade_request.remove_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, 100)
  facade_request.remove_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, 200)
  facade_request.remove_temp_skill(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, 300)
  # 转为普通技能形态
  facade_request.change_skill_form(ccentity.entity.ttypes.EntityType.TYPE_ACTOR,\
      message.actor_, ccentity.skill.ttypes.SkillFormType.COMMON)

  proxy.Logging.debug("[slime] actor(%d) leave from playing" % message.actor_)
Example #7
0
def playing_coliseum_on_event_playing_destroy(message_type, channel, channel_type, serialize):
    # 事件消息
    message = ccevent.playing.ttypes.EventPlayingDestory()
    # 反序列化
    TSerialization.deserialize(message, serialize)

    # 移除定时器
    proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_playing_start")
    proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_summon_next_wave")
    proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_remove_rune")
    proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_expired")

    # 取消关注玩家进入/退出副本
    proxy.Communicator.unfollow(
        ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,
        message.template_,
        ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
        "playing_coliseum_on_event_playing_actor_enter",
    )
    proxy.Communicator.unfollow(
        ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,
        message.template_,
        ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
        "playing_coliseum_on_event_playing_actor_leave",
    )

    # 从副本管理器中删除副本对象
    coliseum_types.PlayingManager.remove(message.playing_)

    proxy.Logging.debug("[coliseum] playing(%d,%d) destroy" % (message.playing_, message.template_))
Example #8
0
def playing_coliseum_on_event_playing_create(message_type, channel, channel_type, serialize):
    # 事件消息
    message = ccevent.playing.ttypes.EventPlayingCreate()
    # 反序列化
    TSerialization.deserialize(message, serialize)

    # 关注玩家进入/退出副本事件
    proxy.Communicator.follow(
        ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,
        message.template_,
        ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
        "playing_coliseum_on_event_playing_actor_enter",
    )
    proxy.Communicator.follow(
        ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,
        message.template_,
        ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
        "playing_coliseum_on_event_playing_actor_leave",
    )

    # 创建副本对象并加入副本管理器
    playing = coliseum_types.Playing(message.playing_, message.template_, message.scene_)
    coliseum_types.PlayingManager.add(playing)

    proxy.Logging.debug("[coliseum] playing(%d,%d,%d) create" % (message.playing_, message.template_, message.scene_))
def playing_coliseum_on_event_playing_destroy(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingDestory()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 移除定时器
  proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_playing_start")
  proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_summon_next_wave")
  proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_remove_rune")
  proxy.Timer.remove(message.playing_, "playing_coliseum_on_timer_expired")

  # 取消关注玩家进入/退出副本
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
      "playing_coliseum_on_event_playing_actor_enter")
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
      "playing_coliseum_on_event_playing_actor_leave")

  # 从副本管理器中删除副本对象
  coliseum_types.PlayingManager.remove(message.playing_)

  proxy.Logging.debug("[coliseum] playing(%d,%d) destroy"
      % (message.playing_, message.template_))
Example #10
0
def read_thrift_from_file(thrift_obj, filename):
    """Instantiate Thrift object from contents of named file

    The Thrift file is assumed to be encoded using TCompactProtocol

    **WARNING** - Thrift deserialization tends to fail silently.  For
    example, the Thrift libraries will not complain if you try to
    deserialize data from the file `/dev/urandom`.

    Args:

    - `thrift_obj`: A Thrift object (e.g. a Communication object)
    - `filename`:  A filename string

    Returns:

    -  The Thrift object that was passed in as an argument
    """
    thrift_file = open(filename, "rb")
    thrift_bytes = thrift_file.read()
    TSerialization.deserialize(
        thrift_obj, thrift_bytes,
        protocol_factory=factory.protocolFactory)
    thrift_file.close()
    return thrift_obj
Example #11
0
def playing_team_on_event_playing_create(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingCreate()
  TSerialization.deserialize(message, serialize)

  playing_config = team_types.Config.get(message.template_)
  if playing_config == None:
    proxy.Logging.error("[team] team_types.Config.get(%d) failed." % message.template_)
    return None

  playing = team_types.Playing(message.playing_, message.template_, message.scene_)
  team_types.PlayingManager.add(playing)

  if playing_config.summon_next_npc(message.scene_, playing.get_next_pos()) == False:
    proxy.Logging.error("[team] playing_config.summon_next_npc(%d) failed." % message.scene_)
    return None

  playing.next_pos()

  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,\
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,\
      "playing_team_on_event_playing_actor_enter")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,\
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,\
      "playing_team_on_event_playing_actor_leave")

  # 定时器,副本时间
  proxy.Timer.add(message.playing_, playing_config.get_playing_time() * 1000, 1,\
      "playing_team_on_timer_playing")

  proxy.Timer.add(message.playing_, 2000, -1, "playing_team_on_timer_sync_ranking")

  proxy.Logging.debug("[team] playing(%d,%d,%d) create"\
      % (message.playing_, message.template_, message.scene_))
def summon_npc(scene_id,
               npc_template,
               x,
               y,
               width=0,
               heigth=0,
               delay_secs=0,
               dir=ccentity.direction.ttypes.DirectionType.NONE):
    # 构造消息
    message = ccrequest.scene.ttypes.RequestSceneSummonNpc()
    message.scene_ = scene_id
    message.template_id_ = npc_template
    message.x_ = x
    message.y_ = y
    message.dir_ = dir
    message.width_ = width
    message.heigth_ = heigth
    message.npc_id_ = 0
    message.delay_secs_ = delay_secs
    # 发送请求
    if proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_SUMMON_NPC,\
        message) == False:
        return 0
    # 得到结果
    result = ccrequest.scene.ttypes.RequestSceneSummonNpc()
    TSerialization.deserialize(result, proxy.Request.get_result())
    return result.npc_id_
Example #13
0
def playing_guild_on_event_skill_attack_hit(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.skill.ttypes.EventSkillAttackHit()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  if message.dest_type_ != ccentity.entity.ttypes.EntityType.TYPE_NPC:
    return
  if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR:
    return
  if message.hurt_type_ != ccentity.skill.ttypes.SkillHurtType.PHYSICS_ATTACK and \
     message.hurt_type_ != ccentity.skill.ttypes.SkillHurtType.MAGIC_ATTACK and \
     message.hurt_type_ != ccentity.skill.ttypes.SkillHurtType.REDUCE_HP:
    return

  # 获取玩家所在副本对象
  playing = guild_types.PlayingManager.get_actor_playing(message.id_)
  if playing is None:
    proxy.Logging.error("[guild] PlayingManager.get_actor_playing(%d) failed" % message.id_)
    return

  # 获取副本玩家对象
  actor = playing.get_actor(message.id_)
  if actor is None:
    proxy.Logging.error("[guild] playing.get_actor(%d) failed" % message.id_)
    return

  # 增加伤害
  actor.add_damage(message.value_)
  # 同步伤害排行
  playing.broadcast_damage_ranking()
Example #14
0
def playing_guild_on_event_playing_actor_leave(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorLeave()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 取消关注事件
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,
      "playing_guild_on_event_actor_kill_npc")
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_SKILL_ATTACK_HIT,
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,
      "playing_guild_on_event_skill_attack_hit")

  # 获取副本对象
  playing = guild_types.PlayingManager.get(message.playing_)
  if playing is None:
    proxy.Logging.error("[guild] PlayingManager.get(%d) failed" % message.playing_)
    return

  # 获取副本玩家对象
  actor = playing.get_actor(message.actor_)
  if actor is None:
    proxy.Logging.error("[guild] playing.get_actor(%d) failed" % message.actor_)
    return

  # 设置玩家离线
  actor.set_leave(True)
  # 副本管理器中删除玩家ID和副本ID的映射关系
  guild_types.PlayingManager.remove_actor(message.actor_)

  proxy.Logging.debug("[guild] actor(%d) leave from playing" % message.actor_)
Example #15
0
def playing_soul_on_event_playing_actor_enter(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorEnter()
  TSerialization.deserialize(message, serialize)

  # 关注玩家杀死NPC事件、请求完成副本事件
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_soul_on_event_actor_kill_npc")

  playing = soul_types.PlayingManager.get(message.playing_)
  if playing == None:
    return None

  actor = playing.get_actor(message.actor_)
  if actor == None:
    actor = soul_types.Actor(message.actor_)
    playing.add_actor(actor)

  # 副本管理器中建立一个玩家ID和副本ID的映射关系
  soul_types.PlayingManager.add_actor(message.actor_, message.playing_)

  now = time.time()

  # 请求初始化玩家
  request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
  request.actor_ = message.actor_
  request.spend_time_ = now - playing.get_start_time()
  request.datas_ = []
  request.scores_ = []
  # 发送请求
  proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR,\
      request)

  proxy.Logging.debug("[soul] actor(%d) enter into playing" % message.actor_)
def playing_slaughter_house_on_event_actor_killed(message_type, channel, channel_type, serialize):
  message = ccevent.role.ttypes.EventRoleKilled()
  TSerialization.deserialize(message, serialize)

  if message.attacker_type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR:
    return None;

  playing_id = slaughter_house_types.PlayingManager.get_actor_playing(message.id_)
  if playing_id == None or playing_id == 0:
    proxy.Logging.error("[slaughter_house] PlayingManager.get_actor_playing(%d) failed."\
        % message.id_)
    return None

  playing = slaughter_house_types.PlayingManager.get(playing_id)
  if playing == None:
    proxy.Logging.error("[slaughter_house] PlayingManager.get(%d) failed." % playing_id)
    return None

  playing_config = slaughter_house_types.Config.get(playing.get_template())
  if playing_config == None:
    proxy.Logging.error("[slaughter_house] slaughter_house_types.Config.get(%d) failed."\
        % playing.get_template())
    return None

  attacker_actor = playing.get_actor(message.attacker_id_)
  if attacker_actor == None:
    proxy.Logging.error("[slaughter_house] playing.get_actor(%d) failed."\
        % message.attacker_id_)
    return None

  attacker_actor.score_ += playing_config.kill_actor_score_
  playing.ranking_.add_score(message.attacker_id_, playing_config.kill_actor_score_)

  proxy.Logging.debug("[slaughter_house] actor(%d) killed by actor(%d)"\
      % (message.id_, message.attacker_id_))
Example #17
0
def playing_team_on_event_playing_actor_leave(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorLeave()
  TSerialization.deserialize(message, serialize)

  # 取消关注玩家杀死NPC事件
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_team_on_event_actor_kill_npc")
  proxy.Communicator.unfollow(ccevent.ttypes.EventType.EVENT_SKILL_ATTACK_HIT,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_team_on_event_skill_attack_hit")

  playing = team_types.PlayingManager.get(message.playing_)
  if playing == None:
    return None

  actor = playing.get_actor(message.actor_)
  if actor == None:
    proxy.Logging.debug("[team] playing.get_actor(%d) failed." % message.actor_)
    return None

  actor.set_leave(True)

  # 副本管理器中删除玩家ID和副本ID的映射关系
  team_types.PlayingManager.remove_actor(message.actor_)

  proxy.Logging.debug("[team] actor(%d) leave from playing" % message.actor_)
Example #18
0
def playing_idol_on_event_playing_actor_enter(message_type, channel,
                                              channel_type, serialize):
    # 获取事件交互代理
    communicator_proxy = variable_table.get_variable(
        ccvariable.ttypes.Variable.COMMUNICATOR_PROXY)

    # 获取请求代理
    request_proxy = variable_table.get_variable(
        ccvariable.ttypes.Variable.REQUEST_PROXY)

    # 事件消息
    message = ccevent.playing.ttypes.EventPlayingActorEnter()
    # 反序列化
    TSerialization.deserialize(message, serialize)

    # 关注玩家杀死NPC事件、角色被杀死事件
    communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \
        message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
        "playing_idol_on_event_actor_kill_npc")
    communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \
        message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
        "playing_idol_on_event_actor_killed")
    communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\
        message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
        "playing_idol_on_event_playing_actor_request_complete")

    # 获取副本对象
    playing = idol_types.PlayingManager.get(message.playing_)
    if playing == None:
        log.log_error("idol副本 获取 playing(%d) 失败" % message.playing_)
        return None

    now = time.time()

    # 获取玩家对象
    actor = playing.get_actor(message.actor_)
    if actor == None:
        # 玩家不存在时,创建并加入副本管理器中
        actor = idol_types.Actor(message.actor_, now)
        playing.add_actor(actor)

    # 副本管理器中加入一个玩家ID到副本ID的对应关系
    idol_types.PlayingManager.add_actor(message.actor_, message.playing_)

    # 请求初始化玩家
    request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
    request.actor_ = message.actor_
    request.spend_time_ = now - actor.get_start_time()
    request.scores_ = []
    request.datas_ = []

    # 序列化消息
    request_data = TSerialization.serialize(request)

    # 发送请求
    request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, \
        request_data, len(request_data))

    log.log_debug("玩家(%d) 进入 idol副本(id=%d,template=%d)" % \
        (message.actor_, message.playing_, message.template_))
Example #19
0
def playing_unreal_soul_on_event_playing_actor_enter(message_type, channel, channel_type, serialize):
    message = ccevent.playing.ttypes.EventPlayingActorEnter()
    TSerialization.deserialize(message, serialize)

    proxy.Communicator.follow(
        ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,
        message.actor_,
        ccevent.ttypes.ChannelType.CHANNEL_ACTOR,
        "playing_unreal_soul_on_event_actor_kill_npc",
    )

    playing = unreal_soul_types.PlayingManager.get(message.playing_)
    if playing == None:
        proxy.Logging.error("[unreal_soul] PlayingManager.get(%d) failed." % message.playing_)
        return None

    actor = playing.get_actor(message.actor_)
    if actor == None:
        actor = unreal_soul_types.Actor(message.actor_)
        playing.add_actor(actor)
        increase_actor_playing_complete(message.actor_, playing.template_)

    actor.set_leave(False)

    unreal_soul_types.PlayingManager.add_actor(message.actor_, message.playing_)

    now = time.time()

    # 初始化玩家
    request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
    request.actor_ = message.actor_
    request.spend_time_ = now - playing.start_time_
    request.datas_ = []
    request.scores_ = []
    proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, request)
def main():

	myapp = thrift.App(ap_name="iperf", binary_path="/usr/bin/iperf", description="Hello World Application")
	myapp.parameters =  ([thrift.Parameter(name="server", cmd='-s', type= "Flag", default_value="False"), 
		thrift.Parameter(name="client", cmd='-c', type= "String")] )


	send('def_application', TSerialization.serialize(myapp))
	send('def_group', "Servers", "kali")


	app_inst = thrift.AppInstance()
	app_inst.inst_name = "iperf_client"
	app_inst.app_name = "iperf"
	# app_inst.arguments = {"server": ""}
	app_inst.arguments = {"client": "192.168.1.37"}
	# app_inst.environment =
	# app_inst.clean_env =					
	# app_inst.map_err_to_out =

	# my_iface = thrift.Iface(if_name= "wlan0") 	# MOCKUP: This is obviously incomplete

	send('add_application', "kali", TSerialization.serialize(app_inst))
	# api_server.add_application("kali", app_inst)

	event_trigger = thrift.EventTrigger(name="kali_installed" ,enabled=True)
	event_trigger.conditions = {'kali.iperf_client': 'Installed'}

	send('def_event',TSerialization.serialize(event_trigger))


	send('start_experiment')

	# 
	time.sleep(60)
Example #21
0
def playing_unreal_soul_on_event_playing_actor_leave(message_type, channel, channel_type, serialize):
    message = ccevent.playing.ttypes.EventPlayingActorLeave()
    TSerialization.deserialize(message, serialize)

    proxy.Communicator.unfollow(
        ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,
        message.actor_,
        ccevent.ttypes.ChannelType.CHANNEL_ACTOR,
        "playing_unreal_soul_on_event_actor_kill_npc",
    )

    unreal_soul_types.PlayingManager.remove_actor(message.actor_)

    playing = unreal_soul_types.PlayingManager.get(message.playing_)
    if playing == None:
        proxy.Logging.error("[unreal_soul] PlayingManager.get(%d) failed." % message.playing_)
        return None

    actor = playing.get_actor(message.actor_)
    if actor == None:
        proxy.Logging.error("[unreal_soul] Playing.get_actor(%d) failed." % message.actor_)
        return None

    actor.set_leave(True)

    proxy.Logging.debug("[unreal_soul] actor(%d) leave from playing" % message.actor_)
Example #22
0
def playing_idol_on_event_playing_actor_leave(message_type, channel, channel_type, serialize):
  # 获取事件交互代理
  communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY)

  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorLeave()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 取消关注玩家杀死NPC事件、角色被杀死事件
  communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
      "playing_idol_on_event_actor_killed")
  communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
      "playing_idol_on_event_actor_kill_npc")
  communicator_proxy.unfollow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_idol_on_event_playing_actor_request_complete")

  # 副本管理器中删除玩家对象
  idol_types.PlayingManager.remove_actor(message.actor_)

  log.log_debug("玩家(%d) 离开 idol副本(id=%d,template=%d)" % \
      (message.actor_, message.playing_, message.template_))
Example #23
0
def playing_unreal_soul_on_event_role_leave_fighting_status(message_type, channel, channel_type, serialize):
    message = ccevent.role.ttypes.EventRoleLeaveFightingStatus()
    TSerialization.deserialize(message, serialize)

    proxy.Logging.debug("[unreal_soul] EventRoleLeaveFightingStatus")

    if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_NPC:
        return None

    playing_id = unreal_soul_types.PlayingManager.get_monster_playing(message.id_)
    if playing_id == 0:
        proxy.Logging.error("[unreal_soul] PlayingManager.get_monster_playing(%d) failed." % message.id_)
        return None

    playing = unreal_soul_types.PlayingManager.get(playing_id)
    if playing == None:
        proxy.Logging.error("[unreal_soul] PlayingManager.get(%d) failed." % playing_id)
        return None

    monster = playing.get_monster(message.id_)
    if monster == None:
        proxy.Logging.error("[unreal_soul] Playing.get_monster(%d) failed." % message.id_)
        return None

    monster.fighting_status_ = False

    proxy.Logging.debug("[unreal_soul] monster(%d) out of fighting status" % message.id_)
Example #24
0
def playing_idol_on_event_playing_create(message_type, channel, channel_type, serialize):
  # 获取事件交互代理
  communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY)

  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingCreate()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 关注玩家进入/退出副本事件
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER, \
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \
      "playing_idol_on_event_playing_actor_enter")
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE, \
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING, \
      "playing_idol_on_event_playing_actor_leave")

  # 创建副本对象并加入管理器中
  playing = idol_types.Playing(message.playing_, message.template_, message.scene_)
  idol_types.PlayingManager.add(playing)

  # 获取副本配置
  playing_config = idol_types.Config.get(message.template_)
  if playing_config == None:
    log.log_error("获取 副本配置失败(%d)" % message.template_)
    return None

  # 召唤一个BOSS
  facade_request.summon_npc(message.scene_, playing_config.get_pass_kill_npc(),\
      playing_config.get_pass_npc_x(), playing_config.get_pass_npc_y());

  log.log_debug("idol副本(id=%d,template=%d) 创建成功" % (message.playing_, message.template_))
Example #25
0
def playing_plot_on_event_actor_killed(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.role.ttypes.EventRoleKilled()

  # 消息反序列化
  TSerialization.deserialize(message, serialize)

  # 主角类型只能是玩家
  if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR:
    return None

  # 根据玩家ID获取所在副本ID
  playing_id = plot_types.PlayingManager.get_actor_playing(message.id_)
  if playing_id == None or playing_id == 0:
    proxy.Logging.error("plot_types.PlayingManager.get_actor_playing(%d) failed." % message.id_)
    return None

  # 获取副本对象
  playing = plot_types.PlayingManager.get(playing_id)
  if playing == None:
    proxy.Logging.error("plot_types.PlayingManager.get(%d) failed." % playing_id)
    return None

  # 获取玩家对象
  actor = playing.get_actor(message.id_)
  if actor == None:
    proxy.Logging.error("playing.get_actor(%d) failed." % message.id_)
    return None

  # 玩家死亡次数增加
  actor.inc_dead_count(1)

  log.log_debug("玩家(%d) 死亡次数(%d)" % (message.id_, actor.get_dead_count()))
Example #26
0
    def test_validate_received_token(self):
        token = self.client.user_info(DN, "", "SecurityClientTest")
        nt.assert_true(self.client.validateReceivedToken(token))

        b = tser.serialize(token)
        token = EzSecurityToken()
        tser.deserialize(token, b)
        nt.assert_true(self.client.validateReceivedToken(token))
Example #27
0
def playing_unreal_soul_on_event_playing_create(message_type, channel, channel_type, serialize):
    message = ccevent.playing.ttypes.EventPlayingCreate()
    TSerialization.deserialize(message, serialize)

    proxy.Communicator.follow(
        ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,
        message.template_,
        ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
        "playing_unreal_soul_on_event_playing_actor_enter",
    )
    proxy.Communicator.follow(
        ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,
        message.template_,
        ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
        "playing_unreal_soul_on_event_playing_actor_leave",
    )
    proxy.Communicator.follow(
        ccevent.ttypes.EventType.EVENT_ROLE_ENTER_FIGHTING_STATUS,
        0,
        ccevent.ttypes.ChannelType.CHANNEL_NPC,
        "playing_unreal_soul_on_event_role_enter_fighting_status",
    )
    proxy.Communicator.follow(
        ccevent.ttypes.EventType.EVENT_ROLE_LEAVE_FIGHTING_STATUS,
        0,
        ccevent.ttypes.ChannelType.CHANNEL_NPC,
        "playing_unreal_soul_on_event_role_leave_fighting_status",
    )

    playing = unreal_soul_types.Playing()
    playing.initialize(message.playing_, message.template_, message.scene_)

    unreal_soul_types.PlayingManager.add(playing)

    now = time.time()
    playing.start_time_ = now

    proxy.Timer.add(
        message.playing_,
        unreal_soul_types.Config.PLAYING_MAX_TIME_ * 1000,
        1,
        "playing_unreal_soul_on_timer_playing_timeout",
    )
    # 设置石像变换的定时器
    proxy.Timer.add(
        message.playing_,
        unreal_soul_types.Config.UNREAL_TRANSFER_INTERVAL * 1000,
        -1,
        "playing_unreal_soul_on_timer_transfer",
    )
    # 设置战斗状态的怪物二级属性增强
    proxy.Timer.add(message.playing_, 60 * 1000, -1, "playing_unreal_soul_on_time_monster_strengthen")

    playing.goto_next_unreal()

    proxy.Logging.debug(
        "[unreal_soul] playing(%d,%d,%d) create" % (message.playing_, message.template_, message.scene_)
    )
Example #28
0
def playing_idol_on_event_actor_killed(message_type, channel, channel_type,
                                       serialize):
    # 事件消息
    message = ccevent.role.ttypes.EventRoleKilled()

    # 消息反序列化
    TSerialization.deserialize(message, serialize)

    # 主角类型只能是玩家
    if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR:
        return None

    # 根据玩家ID获取所在副本ID
    playing_id = idol_types.PlayingManager.get_actor_playing(message.id_)
    if playing_id == None or playing_id == 0:
        return None

    # 获取副本对象
    playing = idol_types.PlayingManager.get(playing_id)
    if playing == None:
        return None

    # 获取玩家对象
    actor = playing.get_actor(message.id_)
    if actor == None:
        return None

    # 玩家死亡次数增加
    actor.inc_dead_count()

    log.log_debug("idol副本 玩家(%d) 死亡次数(%d)" %
                  (message.id_, actor.get_dead_count()))

    # 获取请求代理
    request_proxy = variable_table.get_variable(
        ccvariable.ttypes.Variable.REQUEST_PROXY)

    # 先复活玩家
    request = ccrequest.scene.ttypes.RequestSceneRevive()
    request.actor_ = message.id_
    request.stay_revive_ = True
    # 序列化
    request_data = TSerialization.serialize(request)
    # 发送请求
    request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_REVIVE, \
        request_data, len(request_data))

    # 请求失败消息
    request = ccrequest.playing.ttypes.RequestPlayingFailure()
    request.playing_ = playing_id
    # 序列化
    request_data = TSerialization.serialize(request)
    # 发送请求
    request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_FAILURE, \
        request_data, len(request_data))

    log.log_debug("idol副本 玩家(%d) 失败" % message.id_)
Example #29
0
def playing_idol_on_event_playing_actor_enter(message_type, channel, channel_type, serialize):
  # 获取事件交互代理
  communicator_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.COMMUNICATOR_PROXY)

  # 获取请求代理
  request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY)

  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorEnter()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 关注玩家杀死NPC事件、角色被杀死事件
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC, \
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
      "playing_idol_on_event_actor_kill_npc")
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_ROLE_KILLED, \
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR, \
      "playing_idol_on_event_actor_killed")
  communicator_proxy.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,\
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,\
      "playing_idol_on_event_playing_actor_request_complete")

  # 获取副本对象
  playing = idol_types.PlayingManager.get(message.playing_)
  if playing == None:
    log.log_error("idol副本 获取 playing(%d) 失败" % message.playing_)
    return None

  now = time.time()

  # 获取玩家对象
  actor = playing.get_actor(message.actor_)
  if actor == None:
    # 玩家不存在时,创建并加入副本管理器中
    actor = idol_types.Actor(message.actor_, now)
    playing.add_actor(actor)

  # 副本管理器中加入一个玩家ID到副本ID的对应关系
  idol_types.PlayingManager.add_actor(message.actor_, message.playing_)

  # 请求初始化玩家
  request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
  request.actor_ = message.actor_
  request.spend_time_ = now - actor.get_start_time()
  request.scores_ = []
  request.datas_ = []

  # 序列化消息
  request_data = TSerialization.serialize(request)

  # 发送请求
  request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR, \
      request_data, len(request_data))

  log.log_debug("玩家(%d) 进入 idol副本(id=%d,template=%d)" % \
      (message.actor_, message.playing_, message.template_))
Example #30
0
def playing_plot_on_event_role_change_hp(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.role.ttypes.EventRoleChangeHp()

  # 消息反序列化
  TSerialization.deserialize(message, serialize)

  # 主角类型只能是玩家
  if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR:
    return None

  # 根据玩家ID获取所在副本ID
  playing_id = plot_types.PlayingManager.get_actor_playing(message.id_)
  if playing_id == None or playing_id == 0:
    proxy.Logging.error("plot_types.PlayingManager.get_actor_playing(%d) failed." % message.id_)
    return None

  # 获取副本对象
  playing = plot_types.PlayingManager.get(playing_id)
  if playing == None:
    proxy.Logging.error("plot_types.PlayingManager.get(%d) failed." % playing_id)
    return None

  # 获取玩家对象
  playing_actor = playing.get_actor(message.id_)
  if playing_actor == None:
    proxy.Logging.error("plot_types.PlayingManager.get_actor(%d) failed." % message.id_)
    return None

  # 隐藏NPC是否已召唤
  if playing_actor.get_hide_npc() > 0:
    return None

  # 获得玩家交互对象
  actor = proxy.EntityManager.get_actor(message.id_)
  if actor == None:
    proxy.Logging.error("proxy.EntityManager.get_actor(%d) failed." % message.id_)
    return None

  max_hp = actor.get_attr_role_aoi(ccentity.role.ttypes.RoleAoiFields.MAX_HP)
  current_hp = actor.get_attr_role_aoi(ccentity.role.ttypes.RoleAoiFields.CURRENT_HP)

  if current_hp > (max_hp * 20 / 100):
    return None

  playing_config = plot_types.Config.get(playing.get_template())
  if playing_config == None:
    proxy.Logging.error("获取 副本配置失败(%d)" % playing.get_template())
    return None

  playing_actor.inc_hide_npc(1)

  facade_request.summon_npc(playing.get_scene(), playing_config.get_hide_npc(),\
      actor.get_pos_x(), actor.get_pos_y(), 5, 5)

  proxy.Logging.debug("玩家血量改变,触发隐藏BOSS");
Example #31
0
    def decode(self, input):
      if self._base is None:
        raise ThriftRecordIO.ThriftUnsuppliedException(
          "ThriftCodec cannot deserialize because no thrift_base supplied!")

      base = self._base()
      try:
        _SER.deserialize(base, input)
      except EOFError, e:
        raise RecordIO.PrematureEndOfStream(e)
Example #32
0
def read_communication_from_file(communication_filename):
    """
    Takes the filename of a serialized Concrete Communication file,
    reads the Communication from the file and returns an instantiated
    Communication instance.
    """
    comm = Communication()
    comm_bytestring = open(communication_filename).read()
    TSerialization.deserialize(comm, comm_bytestring)
    return comm
Example #33
0
def playing_guild_on_event_playing_create(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingCreate()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 获取副本配置
  playing_config = guild_types.Config.get(message.template_)
  if playing_config is None:
    proxy.Logging.error("[guild] guild_types.Config.get(%d) failed" % message.template_)
    return

  # 创建副本对象并加入副本管理器
  playing = guild_types.Playing(message.playing_, message.template_,
      message.scene_, playing_config)
  guild_types.PlayingManager.add(playing)

  # 关注玩家进入/退出副本事件
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_ENTER,
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
      "playing_guild_on_event_playing_actor_enter")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_LEAVE,
      message.template_, ccevent.ttypes.ChannelType.CHANNEL_PLAYING,
      "playing_guild_on_event_playing_actor_leave")

  # 设置副本开始时间
  playing.set_start_time(time.time())
  # 设置副本超时定时器
  proxy.Timer.add(message.playing_, playing_config.get_time_limit() * 1000, 1,
      "playing_guild_on_timer_expired")

  # 召唤boss
  playing.summon_boss()
  # 副本管理器中建立一个BOSS_NPC_ID和副本ID的映射关系
  guild_types.PlayingManager.add_boss(playing.get_boss_npc_id(), playing.get_id())
  # 关注BOSS属性变化事件
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_CHANGE_HP,
      playing.get_boss_npc_id(), ccevent.ttypes.ChannelType.CHANNEL_NPC,
      "playing_guild_on_event_boss_attr_change")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_CHANGE_MAX_HP,
      playing.get_boss_npc_id(), ccevent.ttypes.ChannelType.CHANNEL_NPC,
      "playing_guild_on_event_boss_attr_change")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_CHANGE_MP,
      playing.get_boss_npc_id(), ccevent.ttypes.ChannelType.CHANNEL_NPC,
      "playing_guild_on_event_boss_attr_change")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_CHANGE_MAX_MP,
      playing.get_boss_npc_id(), ccevent.ttypes.ChannelType.CHANNEL_NPC,
      "playing_guild_on_event_boss_attr_change")
  # 关注BOSS脱离战斗事件
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ROLE_LEAVE_FIGHTING_STATUS,
      playing.get_boss_npc_id(), ccevent.ttypes.ChannelType.CHANNEL_NPC,
      "playing_guild_on_event_role_leave_fighting_status")

  proxy.Logging.debug("[guild] playing(%d,%d,%d) create"
      % (message.playing_, message.template_, message.scene_))
def playing_coliseum_on_event_playing_actor_enter(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.playing.ttypes.EventPlayingActorEnter()
  # 反序列化
  TSerialization.deserialize(message, serialize)

  # 关注玩家杀死NPC事件、玩家被杀死事件、请求完成副本事件
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_ACTOR_KILL_NPC,
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,
      "playing_coliseum_on_event_actor_kill_npc")
  proxy.Communicator.follow(ccevent.ttypes.EventType.EVENT_PLAYING_ACTOR_REQUEST_COMPLETE,
      message.actor_, ccevent.ttypes.ChannelType.CHANNEL_ACTOR,
      "playing_coliseum_on_event_playing_actor_request_complete")

  playing = coliseum_types.PlayingManager.get(message.playing_)
  if playing is None:
    proxy.Logging.error("[coliseum] PlayingManager.get(%d) failed" % message.playing_)
    return

  now = time.time()

  actor = playing.get_actor()
  if actor == 0:
    playing.set_start_time(now)
    playing.set_actor(message.actor_)
    # 消耗玩家副本次数
    request = ccrequest.playing.ttypes.RequestPlayingIncreaseComplete()
    request.playing_ = message.playing_
    proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INCREASE_COMPLETE,
        request)
    # 设置副本开始定时器
    proxy.Timer.add(message.playing_, coliseum_types.Config.get_start_countdown() * 1000, 1,
        "playing_coliseum_on_timer_playing_start")
    # 设置副本超时定时器
    proxy.Timer.add(message.playing_, coliseum_types.Config.get_time_limit() * 1000, 1,
        "playing_coliseum_on_timer_expired")

  # 副本管理器中建立一个玩家ID和副本ID的映射关系
  coliseum_types.PlayingManager.add_actor(message.actor_, message.playing_)

  # 请求初始化玩家
  request = ccrequest.playing.ttypes.RequestPlayingInitializeActor()
  request.actor_ = message.actor_
  request.spend_time_ = now - playing.get_start_time()
  # datas = [祭坛激活顺序(6个数字)]
  request.datas_ = []
  request.datas_.extend(playing.get_circle_seq())
  request.scores_ = []
  request.scores_.append(ccentity.playing.ttypes.PlayingScoreField(
      ccentity.playing.ttypes.PlayingScoreType.STAGE, 0, playing.get_current_stage()))
  proxy.Request.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_INITIALIZE_ACTOR,
      request)

  proxy.Logging.debug("[coliseum] actor(%d) enter into playing" % message.actor_)
	def __configure (self, topic, ctype, field, field2=None): 	# ctype must be thrift.ConfigType = {SUBSCRIBE, SET_STATE, ASSIGN_NAME}
		# Create message header:
		msg_id = random.randint(0, 2147483647)
		timestamp = time.time()
		msg_header = thrift.MsgHeader(version=1, mtype=thrift.MessageType.CONFIGURE, msg_id=msg_id, source="ec", ts=timestamp )
		# Create message body:
		body_msg = thrift.ConfigMsg(ctype=ctype, field=field, field2=field2)
		# self.pub_socket.send(topic+'.#', zmq.SNDMORE)	
		# self.pub_socket.send(TSerialization.serialize(msg_header), zmq.SNDMORE)
		# self.pub_socket.send(TSerialization.serialize(body_msg))
		self.__send(topic+'.#', TSerialization.serialize(msg_header), TSerialization.serialize(body_msg))
Example #36
0
def playing_idol_on_event_actor_killed(message_type, channel, channel_type, serialize):
  # 事件消息
  message = ccevent.role.ttypes.EventRoleKilled()

  # 消息反序列化
  TSerialization.deserialize(message, serialize)

  # 主角类型只能是玩家
  if message.type_ != ccentity.entity.ttypes.EntityType.TYPE_ACTOR:
    return None

  # 根据玩家ID获取所在副本ID
  playing_id = idol_types.PlayingManager.get_actor_playing(message.id_)
  if playing_id == None or playing_id == 0:
    return None

  # 获取副本对象
  playing = idol_types.PlayingManager.get(playing_id)
  if playing == None:
    return None

  # 获取玩家对象
  actor = playing.get_actor(message.id_)
  if actor == None:
    return None

  # 玩家死亡次数增加
  actor.inc_dead_count()

  log.log_debug("idol副本 玩家(%d) 死亡次数(%d)" % (message.id_, actor.get_dead_count()))

  # 获取请求代理
  request_proxy = variable_table.get_variable(ccvariable.ttypes.Variable.REQUEST_PROXY)

  # 先复活玩家
  request = ccrequest.scene.ttypes.RequestSceneRevive()
  request.actor_ = message.id_
  request.stay_revive_ = True
  # 序列化
  request_data = TSerialization.serialize(request)
  # 发送请求
  request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_SCENE_REVIVE, \
      request_data, len(request_data))

  # 请求失败消息
  request = ccrequest.playing.ttypes.RequestPlayingFailure()
  request.playing_ = playing_id
  # 序列化
  request_data = TSerialization.serialize(request)
  # 发送请求
  request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_FAILURE, \
      request_data, len(request_data))

  log.log_debug("idol副本 玩家(%d) 失败" % message.id_)
Example #37
0
def playing_idol_on_event_actor_kill_npc(message_type, channel, channel_type,
                                         serialize):
    # 获取请求代理
    request_proxy = variable_table.get_variable(
        ccvariable.ttypes.Variable.REQUEST_PROXY)

    # 事件消息
    message = ccevent.actor.ttypes.EventActorKillNpc()
    # 反序列化
    TSerialization.deserialize(message, serialize)

    # 获取玩家所在副本ID
    playing_id = idol_types.PlayingManager.get_actor_playing(message.actor_)
    if playing_id == None or playing_id == 0:
        return None

    # 获取副本对象
    playing = idol_types.PlayingManager.get(playing_id)
    if playing == None:
        return None

    # 获取副本配置
    playing_config = idol_types.Config.get(playing.get_template_id())
    if playing_config == None:
        log.log_error("获取 副本配置失败(%d)" % playing.get_template_id())
        return None

    # 获取玩家通关需要杀死的NPC
    pass_kill_npc = playing_config.get_pass_kill_npc()
    if message.npc_template_ != pass_kill_npc:
        log.log_error("玩家(%d) 杀死npc(%d) 不是通关npc(%d)" % \
            (message.actor_, message.npc_template_, pass_kill_npc))
        return None

    # 获取副本玩家对象
    actor = playing.get_actor(message.actor_)
    if actor == None:
        log.log_error("idol副本 获取actor(%d) 失败" % message.actor_)
        return None

    if actor.get_finish() == 0 and actor.get_dead_count() <= 0:
        actor.set_finish()
        # 请求同步玩家得分
        request = ccrequest.playing.ttypes.RequestPlayingSynchronizeScore()
        request.actor_ = message.actor_
        request.score_ = ccentity.playing.ttypes.PlayingScoreField(ccentity.playing.ttypes.PlayingScoreType.KILL_NPC, \
            message.npc_template_, 1)
        # 序列化消息
        request_data = TSerialization.serialize(request)
        # 发送请求
        request_proxy.request(ccrequest.ttypes.RequestType.REQUEST_PLAYING_SYNCHRONIZE_SCORE, \
            request_data, len(request_data))