Ejemplo n.º 1
0
def process_enter(session, msg):
    session.player = player_t()
    param = msg.ops.split('_')
    session.player.id = int(param[0])
    session.verify_id(session.player.id)

    session.player.x = int(param[1])
    session.player.y = int(param[2])
    session.player.name = param[3]
    print('process_enter', msg, session.socket_id)
Ejemplo n.º 2
0
def process_enter(session, msg):
    session.player = player_t()
    param = msg.ops.split('_')
    session.player.id = int(param[0])
    session.verify_id(session.player.id)
    
    session.player.x = int(param[1])
    session.player.y = int(param[2])
    session.player.name = param[3]
    print('process_enter', msg, session.socket_id)
Ejemplo n.º 3
0
    def callback(db_data):
        #异步载入数据库,需要验证session是否仍然有效,有可能下线了
        if session.is_valid() == False:
            return
        session.player = player_t()
        session.player.name = req_name
        if len(db_data) == 0:
            session.verify_id(ffext.alloc_id())

            session.player.id = session.get_id()
            session.player.x = 100 + random.randint(0, 100)
            session.player.y = 100 + random.randint(0, 100)

            #创建新角色
            new_data = {
                'UID': session.player.id,
                'NAME': session.player.name,
                'X': session.player.x,
                'Y': session.player.y,
            }
            db_service.insert_player(new_data)
            print('create new player =%s' % (session.player.name))
        else:
            #载入数据
            print(db_data)
            print('load player =%s' % (session.player.name))
            session.player.id = int(db_data['UID'])
            session.player.x = int(db_data['X'])
            session.player.y = int(db_data['Y'])
            session.verify_id(session.player.id)
        #发消息通知
        ret_msg = msg_def.login_ret_t()
        ret_msg.id = session.get_id()
        ret_msg.x = session.player.x
        ret_msg.y = session.player.y
        ret_msg.name = session.player.name
        ret_msg.speed = MOVE_SPEED

        session.broadcast(msg_def.server_cmd_e.LOGIN_RET, ret_msg)
        print('real_session_enter', ret_msg)

        def notify(tmp_session):
            if tmp_session != session:
                ret_msg.id = tmp_session.get_id()
                ret_msg.x = tmp_session.player.x
                ret_msg.y = tmp_session.player.y
                ret_msg.name = tmp_session.player.name
                session.send_msg(msg_def.server_cmd_e.LOGIN_RET, ret_msg)

        ffext.get_session_mgr().foreach(notify)
        return
Ejemplo n.º 4
0
    def callback(db_data):
        #异步载入数据库,需要验证session是否仍然有效,有可能下线了
        if session.is_valid() == False:
            return
        session.player = player_t()
        session.player.name = req_name
        if len(db_data) == 0:
            session.verify_id(ffext.alloc_id())

            session.player.id = session.get_id()
            session.player.x = 100 + random.randint(0, 100)
            session.player.y = 100 + random.randint(0, 100)

            #创建新角色
            new_data = {
                'UID':session.player.id,
                'NAME':session.player.name,
                'X':session.player.x,
                'Y':session.player.y,
            }
            db_service.insert_player(new_data)
            print('create new player =%s'%(session.player.name))
        else:
            #载入数据
            print(db_data)
            print('load player =%s'%(session.player.name))
            session.player.id = int(db_data['UID'])
            session.player.x = int(db_data['X'])
            session.player.y = int(db_data['Y'])
            session.verify_id(session.player.id)
        #发消息通知
        ret_msg = msg_def.login_ret_t()
        ret_msg.id = session.get_id()
        ret_msg.x  = session.player.x
        ret_msg.y  = session.player.y
        ret_msg.name = session.player.name
        ret_msg.speed = MOVE_SPEED
        
        session.broadcast(msg_def.server_cmd_e.LOGIN_RET, ret_msg)
        print('real_session_enter', ret_msg)
        
        def notify(tmp_session):
            if tmp_session != session:
                ret_msg.id = tmp_session.get_id()
                ret_msg.x  = tmp_session.player.x
                ret_msg.y  = tmp_session.player.y
                ret_msg.name = tmp_session.player.name
                session.send_msg(msg_def.server_cmd_e.LOGIN_RET, ret_msg)
        ffext.get_session_mgr().foreach(notify)
        return