Beispiel #1
0
def real_session_enter(session, from_scene, extra_data):
    session.player = player_t()
    session.player.id = session.get_id()
    session.player.name = 'С' + g_alloc_names[session.get_id() %
                                               (len(g_alloc_names))]
    session.player.x = 100 + random.randint(0, 300)
    session.player.y = 100 + random.randint(0, 300)

    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
Beispiel #2
0
def real_session_enter(session, from_scene, extra_data):
    session.player = player_t()
    session.player.id = session.get_id()
    session.player.name = 'С' + g_alloc_names[session.get_id() % (len(g_alloc_names))]
    session.player.x = 100 + random.randint(0, 300)
    session.player.y = 100 + random.randint(0, 300)
    
    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
Beispiel #3
0
def process_login(session, msg): #session_key,
    print('real_session_verify')
    session.verify_id(ffext.alloc_id())
    
    session.player = player_t()
    session.player.id = session.get_id()
    session.player.name = '小' + g_alloc_names[session.get_id() % (len(g_alloc_names))]
    session.player.x = 100 + random.randint(0, 100)
    session.player.y = 100 + random.randint(0, 100)
    
    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 []
Beispiel #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
Beispiel #5
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