Example #1
0
int   analizador_direccion( Analizador* z, Direccion* dir ) {

    Vinculo* v;
    Direccion* dir2;
    CHECK_STATUS;
#if  OUTOFBOARD_ISERROR
    if( !CASILLERO_VALIDO( z->cas ) ) return STATUS_OUTOFBOARD;
#else
    if( !CASILLERO_VALIDO( z->cas ) ) return STATUS_NORMAL;
#endif
    dir2 = tipojuego_dir_by_sym( z->pos.tjuego, dir, z->color );
    v = casillero_busca_vinculo_pororigen( z->cas, dir2 );
    if( !v ) {
        LOGPRINT( 7, "Estoy en %s moviendome hacia %s ... me voy del tablero", z->cas->nombre, dir2->nombre );
#if  OUTOFBOARD_ISERROR
        z->status = STATUS_OUTOFBOARD;
        z->cas    = OUTOFBOARD;
        return STATUS_OUTOFBOARD;
#else
        z->cas    = OUTOFBOARD;
        return STATUS_NORMAL;
#endif
    }

    LOGPRINT( 7, "Estoy en %s moviendome hacia %s ... mi destino es %s",
              z->cas->nombre, dir2->nombre, v->destino->nombre );
    z->cas = v->destino;
    if( z->pieza ) posicion_mueve_pieza( &z->pos, z->pieza, z->cas );
    return  STATUS_NORMAL;
}
Example #2
0
int      analizador_evalua_final  ( Regla* regla, Posicion* pos, Pieza* pieza, Casillero* cas, int color, int color_siguiente, char** resultado ) {

    Analizador* z = (Analizador*)malloc( sizeof( Analizador ) );
    int  ret;
    memset( z, 0, sizeof( Analizador ) );
    posicion_copy( &z->pos, pos );
    z->cas     = cas;
    z->cas_ori = cas;
    z->pieza = pieza;
    z->color = color;
    z->color_siguiente = color_siguiente;
    z->tipo_analisis = ANALISIS_FINAL;

    if( regla->tregla != END ) {
        LOGPRINT( 1, "Regla debe ser de final (%d)", regla->tregla );
        return STATUS_ERROR;
    }
    code_execute_rule( z, regla->pc );

    LOGPRINT( 6, "Fin del analisis de final status = %d", z->status );

    if( z->status == STATUS_EOG ) {
        if( resultado ) *resultado = strdup( z->resultado );
        ret =  z->color_ganador ? z->color_ganador : FINAL_EMPATE;
        LOGPRINT( 4, "Fin de partida detectado %d => %s", ret, z->resultado );
        if( z->resultado ) free( z->resultado );
    } else ret =  FINAL_ENJUEGO;
    posicion_free_data( ZPOSICION(z) );
    free( z );
    return ret;

}
Example #3
0
/*
 * Esta funcion revisa si en la zona especificada, se encuentra alguna pieza
 * del color pasado como parametro.
 * color: Dueño. Puede ser ENEMIGO, PROPIO, CUALQUIERA o un color
 * */
int    analizador_enzona( Analizador* z, int zona, int color, Tipopieza* tpieza ) {
    CHECK_STATUS;
    int  i;
    int  colorcheck = ( color == PROPIO ? z->color : color );

    if( z->tipo_analisis == ANALISIS_FINAL ) {
        for( i = 0; i < z->pos.piezas_count; i ++ ) {
            Pieza* ppp = &(z->pos.piezas[i]);
            if( !CASILLERO_VALIDO(ppp->casillero ) ) continue;
            if( ppp->color != colorcheck ) continue;
            if( tpieza && ppp->tpieza != tpieza ) continue;
            if(  tipojuego_casillero_en_zona( z->pos.tjuego, ppp->casillero, zona, colorcheck ) ) {
                LOGPRINT( 7, "En zona acertó! zona=%d color=%d cas=%s tpieza=%p", zona, colorcheck, ppp->casillero->nombre, tpieza );
                return 1;
            }
        }
    } else {
        if( tipojuego_casillero_en_zona( z->pos.tjuego, z->cas, zona, z->color ) ) {
            LOGPRINT( 6, "En zona acertó! zona=%d color=%d cas=%s tpieza=%p", zona, z->color, z->cas->nombre, tpieza );
            return 1;
        }
    }
    LOGPRINT( 6, "Zona salio por cero %d", zona );
    return 0;
}
Example #4
0
int    analizador_cuenta_piezas( Analizador* z, Casillero* cas, int owner, Tipopieza* tpieza ) {

    Pieza* p;
    int  total = 0, i;
    LOGPRINT( 6, "Pregunta por cuentapiezas al casillero %s owner = %d tipo pieza %s",
              ( cas ? cas->nombre : "Sin casillero" ),
              owner,
              ( tpieza ? tpieza->nombre : "Sin tpieza" ) );

    for( i = 0; i < z->pos.piezas_count; i ++ ) {
        p = &(z->pos.piezas[i] );
        // Controlo si me pasaron el casillero
        if( cas && cas != p->casillero ) continue;
        if( (!cas) && !CASILLERO_VALIDO( p->casillero ) ) continue;
        // Controlo si me pasaron el tipo de pieza
        if( tpieza  && tpieza != p->tpieza ) continue;
        // Controlo el tema del color
        if( owner != CUALQUIERA ) {
            if( owner == PROPIO && p->color != z->color ) continue;
            if( owner == ENEMIGO && p->color == z->color ) continue;
            if( owner >  0 && p->color != owner ) continue;
        }
        total ++;
    }
    LOGPRINT( 6, "Devuelve %d", total );

    return total;


}
Example #5
0
/*
 * Salva la sesion en la base de datos
 * */
int      session_save( Session* s ){
    if( s->id[0] == 0 ){
        session_generar_id( s->id );
    }
    struct timeval tv;
    gettimeofday( &tv, NULL );
    if( !s->created_at ) s->created_at = tv.tv_sec;
    s->last_seen_at = tv.tv_sec;

    void* data;
    int size = session_to_bin( s, &data );
    if( size ){
        if( !dbput_data( DBSESSION, s->id, 32, data, size ) ){
            LOGPRINT( 1, "Error salvando session %s", dbget_lasterror() );
            free( data );
            return 0;
        }
    } else {
        LOGPRINT( 1, "Error fatal al pasar a binario sesion", 0 );
        return 0;
    } 
    LOGPRINT( 5, "Sesion %s salvada", session_id( s ) );
    free( data );
    return 1;
}
Example #6
0
int   analizador_final( Analizador* z, int color, int res ) {
    CHECK_STATUS;
    CHECK_END_CODE;

    LOGPRINT( 6, "Se llama al final color %d, resultado %d", color, res );

    switch( res ) {
    case EMPATA:
        z->color_ganador = 0;
        z->status        = STATUS_EOG;
        z->resultado     = strdup( "Draw" );
        break;
    case GANA:
        z->color_ganador = ( color ? color : z->color );
        z->status        = STATUS_EOG;
        z->resultado     = malloc( 256 );
        sprintf( z->resultado, "%s Gana", tipojuego_get_colorname( z->pos.tjuego, z->color_ganador ) );
        break;
    case PIERDE:
        z->color_ganador = ( color ? tipojuego_get_coloroponente( z->pos.tjuego, color ) : z->color_siguiente );
        z->status        = STATUS_EOG;
        z->resultado     = malloc( 256 );
        sprintf( z->resultado, "%s Pierde", tipojuego_get_colorname( z->pos.tjuego, ( color ? color : z->color ) ) );
        break;
    default:
        LOGPRINT(1, "Resultado entrante %d incorrecto", res );
        return STATUS_ERROR;
    }
    return z->status;
}
Example #7
0
/*
 * Esta funcion establece el directorio por defecto donde estan las
 * imagenes de piezas por defecto
 * */
void   graph_image_dir( const char* imagedir ){
#if GRAPH_ENABLED
    LOGPRINT( 5, "Se esta seteando a %s el directorio de imagenes", imagedir );
    qgames_image_dir = (char*)imagedir;
#else
    LOGPRINT( 2, "Lo siento, no estan disponibles las funciones graficas (%s)", imagedir );
#endif
}
Example #8
0
/*
 * Esta funcion evalua si la movida anterior tuvo como destino
 * el casillero pasado como parametro
 * */
int    analizador_destino_ant( Analizador* z, Casillero* cas ) {
    Casillero* ccc = ( cas ? cas : z->cas );
    LOGPRINT( 6, "Viendo destino anterior en %s", ccc->nombre );
    if( !ccc ) return 0;
    if( !z->pos.mov_anterior ) return 0;
    Casillero* ret = movida_casillero_destino( z->pos.mov_anterior );
    LOGPRINT( 6, "Destino anterior fue %s", CASILLERO_VALIDO(ret)? ret->nombre : "(no se)" );
    return( ccc == ret );
}
Example #9
0
/*
 * smalloc should guarantee to return a useful pointer - Halibut
 * can do nothing except die when it's out of memory anyway.
 */
void *(smalloc) (LOGPARAMS int size) {
  void *p;
  LOGINC;
  LOGPRINT(("%s %d malloc(%ld)", file, line, (long) size));
  p = malloc(size);
  if (!p)
    fatal(err_nomemory);
  LOGPRINT((" returns %p\n", p));
  return p;
}
Example #10
0
/*
 * Esta funcion setea la marca pasada como parametro, con el casillero
 * definido. Si el casillero es nulo, entonces tomara el actual
 * */
int    analizador_gotomarca( Analizador* z, int marca) {
    CHECK_STATUS;
    if( !z->marcas ) {
        LOGPRINT( 1, "Marca no seteada %d", marca );
    }
    if( marca >= MARCAS_Q ) {
        LOGPRINT( 1, "Error cantidad de marcas pedidas %d >= %d", marca, MARCAS_Q );
        return  STATUS_ERROR;
    }
    if( z->marcas[marca] ) z->cas = z->marcas[marca];
    return  STATUS_NORMAL;
}
Example #11
0
int   session_del( Session* s ){
    if( s->id[0] == 0 ){
        LOGPRINT( 2, "Sesion que intenta borrar no tiene id %p", s );
        return 0;
    }
    if( !dbdel_data( DBSESSION, s->id, 32 ) ){
        LOGPRINT( 1, "Error borrando session %s %s", session_id(s), dbget_lasterror() );
        return 0;
    }
    return 1;
    
}
void xmpp_iq_broadcast_session_result_cb ( const char *msg_id,
										   const char *msg,
										   void *args )
{

	/*
	<iq from='k01.warface' to='22910345@warface/GameClient' type='get' id='1343823563'><query xmlns='urn:cryonline:k01'><data query_name='broadcast_session_result' compressedData='...' originalSize='4185'/></query></iq>
	*/

	/*
	<broadcast_session_result bcast_receivers='20511692@warface/GameClient,22910345@warface/GameClient,22061196@warface/GameClient,22911131@warface/GameClient,22911515@warface/GameClient'><player_result nickname='Tastan' experience='3900' pvp_rating_points='0' money='1800' gained_crown_money='0' no_crown_rewards='1' sponsor_points='0' bonus_experience='0' bonus_money='0' bonus_sponsor_points='0' experience_boost='0' money_boost='0' sponsor_points_boost='0' experience_boost_percent='0' money_boost_percent='0' sponsor_points_boost_percent='0' completed_stages='13' is_vip='0' score='44277' dynamic_multipliers_info='' dynamic_crown_multiplier='1'><profile_progression_update profile_id='1597755' mission_unlocked='none,trainingmission,easymission,normalmission,hardmission,survivalmission,zombieeasy,zombienormal,zombiehard,campaignsections,campaignsection1,campaignsection2,campaignsection3,volcanoeasy,volcanonormal,volcanohard,all' tutorial_unlocked='7' class_unlocked='29'/></player_result><player_result nickname='DevilsBitch6' experience='3900' pvp_rating_points='0' money='1800' gained_crown_money='0' no_crown_rewards='1' sponsor_points='0' bonus_experience='0' bonus_money='0' bonus_sponsor_points='0' experience_boost='0' money_boost='0' sponsor_points_boost='0' experience_boost_percent='0' money_boost_percent='0' sponsor_points_boost_percent='0' completed_stages='13' is_vip='0' score='44277' dynamic_multipliers_info='' dynamic_crown_multiplier='1'><profile_progression_update profile_id='2383428' mission_unlocked='none,trainingmission,easymission,normalmission,hardmission,survivalmission,zombieeasy,zombienormal,campaignsections,campaignsection1,campaignsection2,campaignsection3,volcanoeasy,volcanonormal,volcanohard,all' tutorial_unlocked='7' class_unlocked='5'/></player_result><player_result nickname='Nebel.' experience='3900' pvp_rating_points='0' money='2070' gained_crown_money='0' no_crown_rewards='1' sponsor_points='0' bonus_experience='0' bonus_money='0' bonus_sponsor_points='0' experience_boost='0' money_boost='270' sponsor_points_boost='0' experience_boost_percent='0' money_boost_percent='0.15' sponsor_points_boost_percent='0' completed_stages='13' is_vip='0' score='44277' dynamic_multipliers_info='' dynamic_crown_multiplier='1'><profile_progression_update profile_id='2108267' mission_unlocked='none,trainingmission,easymission,normalmission,hardmission,survivalmission,zombieeasy,zombienormal,zombiehard,campaignsections,campaignsection1,campaignsection2,campaignsection3,volcanoeasy,volcanonormal,volcanohard,all' tutorial_unlocked='7' tutorial_passed='7' class_unlocked='29'/></player_result><player_result nickname='DevilsBitch7' experience='3900' pvp_rating_points='0' money='1800' gained_crown_money='0' no_crown_rewards='1' sponsor_points='0' bonus_experience='0' bonus_money='0' bonus_sponsor_points='0' experience_boost='0' money_boost='0' sponsor_points_boost='0' experience_boost_percent='0' money_boost_percent='0' sponsor_points_boost_percent='0' completed_stages='13' is_vip='0' score='44277' dynamic_multipliers_info='' dynamic_crown_multiplier='1'><profile_progression_update profile_id='2383432' mission_unlocked='none,trainingmission,easymission,normalmission,hardmission,survivalmission,zombieeasy,zombienormal,campaignsections,campaignsection1,campaignsection2,campaignsection3,volcanoeasy,volcanonormal,volcanohard,all' tutorial_unlocked='7' class_unlocked='5'/></player_result><player_result nickname='DevilsBitch8' experience='3900' pvp_rating_points='0' money='1800' gained_crown_money='0' no_crown_rewards='1' sponsor_points='3000' bonus_experience='0' bonus_money='0' bonus_sponsor_points='0' experience_boost='0' money_boost='0' sponsor_points_boost='0' experience_boost_percent='0' money_boost_percent='0' sponsor_points_boost_percent='0' completed_stages='13' is_vip='0' score='44277' dynamic_multipliers_info='' dynamic_crown_multiplier='1'><profile_progression_update profile_id='2383439' mission_unlocked='none,trainingmission,easymission,normalmission,hardmission,zombieeasy,zombienormal,volcanoeasy,volcanonormal,volcanohard,all' tutorial_unlocked='7' class_unlocked='5'/></player_result></broadcast_session_result>
	*/

	char *data = wf_get_query_content ( msg );
	char *begin;
	FORMAT ( begin, "player_result nickname='%s'", session.profile.nickname );

	char *content = get_info ( data, begin, "</player_result>", NULL );

	int xp_gained = get_info_int ( content, "experience='", "'", NULL );
	int money_earned = get_info_int ( content, "money='", "'", NULL );
	int crowns_earned = get_info_int ( content, "gained_crown_money='", "'", NULL );
	int no_crowns = get_info_int ( content, "no_crown_rewards='", "'", NULL );
	int vp_gained = get_info_int ( content, "sponsor_points='", "'", NULL );
	int score = get_info_int ( content, "score='", "'", NULL );

	session.profile.experience += xp_gained;
	session.profile.money.game += money_earned;
	session.profile.money.crown += crowns_earned;

	char *rewards;
	FORMAT ( rewards, "SCORE = %-8d   XP = %-6d   MONEY = %-6d", score, xp_gained, money_earned );

	if ( vp_gained )
	{
		char *old_rewards = strdup ( rewards );
		FORMAT ( rewards, "%s   VP = %-6d", old_rewards, vp_gained );
		free ( old_rewards );
	}
	if ( !no_crowns )
	{
		char *old_rewards = strdup ( rewards );
		FORMAT ( rewards, "%s   CROWNS = %-6d", old_rewards, crowns_earned );
		free ( old_rewards );
	}

	LOGPRINT ( "%-20s " BOLD "%s\n", "GAME REWARDS", rewards );
	LOGPRINT ( "%-20s " BOLD "%d\n", "EXPERIENCE", session.profile.experience );
	LOGPRINT ( "%-20s " BOLD "%d\n", "MONEY", session.profile.money );

	free ( data );
	free ( content );
}
Example #13
0
int    analizador_transforma( Analizador* z, int owner, Tipopieza* tpieza, int flags ) {
    CHECK_STATUS;
    int color;

    if( !z->mov_actual ) z->mov_actual = movida_new( &z->pos, z->pieza, z->tmov );
    if( !flags ) {
        if( owner == ENEMIGO ) {
            color = z->color + 1;
            if( color > z->pos.tjuego->colores ) color = 1;
        } else if ( owner == CAMBIOCOLOR ) {
            color = z->pieza->color + 1;
            if( color > z->pos.tjuego->colores ) color = 1;
        } else if ( owner == PROPIO ) {
            color = z->color;
        } else if ( owner == NOCOLOR ) {
            color = z->color;
        } else if ( owner > 0 ) {
            color = owner;
        }
        z->flags |= CON_TRANSFORMACION;
        LOGPRINT( 6, "transformando %s en %s", z->pieza->tpieza->nombre, tpieza->nombre );
        movida_accion_transforma( z->mov_actual, z->pieza, color, tpieza );
    } else if( flags == FROM_AQUI ) {
        int i;
        for( i = 0; i < z->pos.piezas_count; i ++ ) {
            Pieza* pp = &(z->pos.piezas[i]);
            if( !pp ) continue;
            if( pp == z->pieza ) continue;
            if( pp->casillero == z->cas ) {
                if( owner == ENEMIGO ) {
                    color = z->color + 1;
                    if( color > z->pos.tjuego->colores ) color = 1;
                } else if ( owner == CAMBIOCOLOR ) {
                    color = pp->color + 1;
                    if( color > z->pos.tjuego->colores ) color = 1;
                } else if ( owner == PROPIO ) {
                    color = z->color;
                } else if ( owner == NOCOLOR ) {
                    color = z->color;
                } else if ( owner > 0 ) {
                    color = owner;
                }
                z->flags |= CON_TRANSFORMACION;
                movida_accion_transforma( z->mov_actual, pp, color, tpieza );
                LOGPRINT( 6, "transformando %s", pp->tpieza->nombre );
            }
        }
    } else {
        return  STATUS_ERROR;
    }
    return  STATUS_NORMAL;
}
Example #14
0
File: malloc.c Project: rdebath/sgt
/*
 * smalloc should guarantee to return a useful pointer - Halibut
 * can do nothing except die when it's out of memory anyway.
 */
void *(smalloc)(LOGPARAMS int size) {
    void *p;
    LOGINC;
    LOGPRINT(("%s %d malloc(%ld)",
	      file, line, (long)size));
    p = malloc(size);
    if (!p) {
	platform_fatal_error("out of memory");
	exit(1);
    }
    LOGPRINT((" returns %p\n", p));
    return p;
}
Example #15
0
/*
 * El analisis de ahogado es muy simple.
 * Tomo el proximo color (en el caso que haya alguno, armo una
 * nueva posicion e intento mover ... si hay alguna movida
 * entonces NO es ahogado!
 * */
int   analizador_ahogado( Analizador* z ) {
    Posicion* pos = posicion_dup( &z->pos );
    int i;
    if( !z->color_siguiente ) {
        LOGPRINT( 2, "Error, color siguiente no definido %p", z );
        return 0;
    }
    i = posicion_analiza_movidas( pos, ANALISIS_PRIMER_MOVIDA, z->color_siguiente, 0, NULL );
    LOGPRINT( 6, "Llamando a posicion_analiza_movidas, para obtener ahogado con color %d resultado %d", z->color_siguiente, i );
    posicion_free( pos );
    if( i == 0 ) LOGPRINT( 6, "Dio ahogado controlando en color %d", z->color_siguiente );
    return i > 0 ? 0 : 1;

}
Example #16
0
void play(char *fname)
{
    int fi[2];
    int fo[2];
    struct stat st;
    int i;
    i = 5;
    while( stat(fname, &st) == -1) //文件不存在
    {
        sleep(1);
        LOGPRINT("stat:%s\n", errstr());
        if(i-- == 0)
        {
            return;
        }
    }

    play_stop();

    pipe(fi);
    pipe(fo);

    signal(SIGCHLD, do_wait);
    playing = 1;

    if(fork() == 0)
    {
        dup2(fi[0], 0);
        dup2(fo[1], 1);

        close(fi[0]);
        close(fi[1]);
        close(fo[0]);
        close(fo[1]);

        close(2);

        LOGPRINT("play:%s\n", fname);
        execlp("mplayer", "mplayer", "-slave", "-quiet",
               fname, NULL);

        exit(-1);
    }

    close(fi[0]);
    close(fo[1]);
    fin = fi[1];
    fout = fo[0];
}
Example #17
0
/* 
 * 发送并等待应答包
 * 成功返回应答包大小, 失败返回-1
 */
static int 
_sendto(int sd, void *buf, size_t len, struct sockaddr_in *peer)
{
	struct pollfd fds;
	int ret, i;

	fds.fd = sd;
	fds.events = POLLIN;

	for(i=3; i>0; i--)
	{
		ret = sendto(sd, buf, len, 0, (struct sockaddr*)peer, 
				sizeof(struct sockaddr_in));
		if(ret == -1)
		{
			LOGPRINT("send:%s\n", errstr());
			return -1;
		}

		poll(&fds, 1, 1000);
		if(fds.revents & POLLIN)
		{
			break;
		}
	}

	if(i == 0)		//timeout
	{
		return -1;
	}

	ioctl(sd, FIONREAD, &ret);

	return ret;
}
Example #18
0
/*
 * Devuelve uno o cero, dependiendo si el casillero pasado como parametro
 * esta siendo atacado por el "enemigo" (o sea, todos los colores que no
 * son el actual).
 * Para ello se ejecutan las movidas posibles por el adversario.
 * */
int    analizador_atacado( Analizador* z, Casillero* cas ) {
    Casillero* ccc = cas ? cas : z->cas;
    Pieza *p;
    int i;
    if( z->tipo_analisis == ANALISIS_ATAQUE ) return 0;
    CHECK_STATUS ;
    if( !CASILLERO_VALIDO(ccc) ) return 0;
    Posicion* pos = posicion_dup( &z->pos );
    if( TIPOJUEGO_CAPTURAIMPLICITA(z->pos.tjuego ) ) {
        for( i = 0; i < pos->piezas_count; i ++ ) {
            p = & pos->piezas[i];
            if( p->number != z->pieza->number && p->casillero == ccc ) p->casillero = OUTOFBOARD ;
        }
    }
    for( i = 1; i <= z->pos.tjuego->colores; i ++ ) {
        if( z->color == i ) continue;
        Movida* mov;
        LOGPRINT( 6, "Inico de analisis para color %d en %s", i, ccc->nombre );
        posicion_analiza_movidas( pos, ANALISIS_ATAQUE, i, 0, NULL );
        list_inicio( pos->movidas );
        while( mov = (Movida*) list_siguiente( pos->movidas ) ) {
            if( movida_casillero_destino( mov ) == ccc ) {
                posicion_free( pos );
                return 1;
            }
        }
    }
    posicion_free( pos );
    return 0;
}
Example #19
0
/*
 * Crea una nueva pieza
 * */
int    analizador_crea   ( Analizador* z, int owner, Tipopieza* tp, Casillero* cas ) {
    CHECK_STATUS ;
    Casillero* ccc = ( cas ? cas : z->cas );
    int color;
#if(OUTOFBOARD_ISERROR)
    if( !CASILLERO_VALIDO( ccc ) ) return STATUS_OUTOFBOARD;
#else
    if( !CASILLERO_VALIDO( ccc ) ) return STATUS_NORMAL;
#endif
    if( !z->movidas ) z->movidas = list_nueva( NULL );
    if( !z->mov_actual ) z->mov_actual = movida_new( &z->pos, z->pieza, z->tmov );
    if( owner == ENEMIGO ) {
        color = z->color + 1;
        if( color > z->pos.tjuego->colores ) color = 1;
    } else if ( owner == PROPIO ) {
        color = z->color;
    } else if ( owner > 0 ) {
        color = owner;
    } else {
        LOGPRINT( 1, "Color (Owner) incorrectamente definido %d ", owner );
        return STATUS_ERROR;
    }
    movida_accion_crea( z->mov_actual, tp, color, ccc );
    return  STATUS_NORMAL;
}
/*
** Function: Si3217x_RevB_SelectPatch
**
** Select patch based on general parameters
**
** Input Parameters: 
** pProslic: pointer to PROSLIC object array
** fault: error code
** patch:    Pointer to proslicPatch pointer
**
** Return:
** error code
*/
int Si3217x_RevB_SelectPatch(proslicChanType_ptr pProslic, const proslicPatch **patch)
{

#ifdef SIVOICE_MULTI_BOM_SUPPORT
	if(Si3217x_General_Configuration.bom_option == BO_DCDC_FLYBACK)
	{
		*patch = &(SI3217X_PATCH_B_FLBK);
	}
	else if(Si3217x_General_Configuration.bom_option == BO_DCDC_BUCK_BOOST)
	{
		*patch = &(SI3217X_PATCH_B_BKBT);
	}
	else if(Si3217x_General_Configuration.bom_option == BO_DCDC_PMOS_BUCK_BOOST)
	{
		*patch = &(SI3217X_PATCH_B_PBB);
	}
	else
	{
        #ifdef ENABLE_DEBUG
		if (pProslic->debugMode)
		{
			LOGPRINT("%sChannel %d : Invalid Patch\n", LOGPRINT_PREFIX, pProslic->channel);
		}
        #endif
		pProslic->channelEnable = 0;
		pProslic->error = RC_INVALID_PATCH;
		return RC_INVALID_PATCH;
	}
#else
	*patch = &(SI3217X_PATCH_B_DEFAULT);
#endif

    return RC_NONE;
}
Example #21
0
//从fout中读一行
static char *get_line(char *buf, int len)
{
    char ch;
    char *p = buf;
    int ret;

    while(1)
    {
        ret = read(fout, &ch, 1);
        if(ret != 1)
        {
            LOGPRINT("read:%d\n", ret);
            return NULL;
        }
        if(ch == '\n')
            break;

        if(len > 0)
        {
            len--;
            *p++ = ch;
        }
    }

    *p = 0;

    return buf;
}
Example #22
0
/*
 * Bueno, vamos a ver si podemos obtener la pieza
 * */
int    tipojuego_get_tpieza_png( Tipojuego* tj, char* color, char* tpieza, int flags, void** png, int* width, int* height ){
#if GRAPH_ENABLED
    Tipopieza* tp = tj->tipo_piezas->data[ GETTIPOPIEZA(tj,tpieza) ];
    int  col      = GETCOLOR(tj,color);
    gdImagePtr gd = graph_tpieza_get_gd( tp, col );
    int  size = 0;

    if( flags == GETPNG_PIEZA_CAPTURADA ){
        gdImagePtr gd2 = gdImageCreate( gdImageSX( gd ) / 2, gdImageSY( gd ) / 2 );

        int transp = gdImageColorAllocate( gd2, 0, 255, 0 );
        gdImageColorTransparent( gd2, transp );
        gdImageFill( gd2, 0, 0 , transp );

        gdImageCopyResized( gd2, gd, 0, 0, 0, 0,
          gdImageSX(gd2), gdImageSY(gd2),
          gdImageSX(gd), gdImageSY(gd) );
        
        if( png ) *png = gdImagePngPtr( gd2, &size );
        if( width ) *width = gdImageSX( gd2 );
        if( height ) *height = gdImageSY( gd2 );
        gdImageDestroy( gd2 );
        return size;
    } else {
        if( png ) *png = gdImagePngPtr( gd, &size );
        if( width ) *width = gdImageSX( gd );
        if( height ) *height = gdImageSY( gd );
        return size;
    }
#endif
    LOGPRINT( 2, "No compilado con el modulo GD tpieza = %s", tpieza );
    return 0;
}
Example #23
0
/*
** Function: stopRingingGoOnHk (transition)
**
** Description:
** called when ringing to stop ringing and change state to on hook
**
** Input Parameters:
** pState: pointer to channel state data structure
**
** Return:
**
*/
static void stopRingingGoOnHk (chanState *pState) {
#if (DEBUG)
    LOGPRINT ("Stop Ring\n");
#endif
    ProSLIC_RingStop(pState->ProObj);
    pState->currentState = OnHook;
}
Example #24
0
void cmd_open ( const char *mission_name )
{
	if ( mission_name == NULL )
		mission_name = "trainingmission";

	if ( strlen ( mission_name ) != 36 ) /* not an uuid */
	{
		struct mission *m = mission_list_get ( mission_name );

		if ( m != NULL )
		{
			int is_pvp = strstr ( m->mode, "pvp" ) != NULL;
			int were_in_pvp = strstr ( session.online.channel, "pvp" ) != NULL;

			if ( is_pvp && !were_in_pvp )
				xmpp_iq_join_channel ( "pvp_pro_5", NULL, NULL );
			else if ( !is_pvp && were_in_pvp )
				xmpp_iq_join_channel ( "pve_2", NULL, NULL );

			if ( is_pvp )
				xmpp_iq_gameroom_open ( m->mission_key, ROOM_PVP_PUBLIC, NULL, NULL );
			else
				xmpp_iq_gameroom_open ( m->mission_key, ROOM_PVE_PRIVATE, NULL, NULL );
		}
		else
		{
			LOGPRINT ( KRED "NO SUCH MAP OR MISSION\n" );
		}
	}
	else
	{
		xmpp_iq_gameroom_open ( mission_name, ROOM_PVE_PRIVATE, NULL, NULL );
	}
}
Example #25
0
File: malloc.c Project: rdebath/sgt
/*
 * sfree should guaranteeably deal gracefully with freeing NULL
 */
void (sfree)(LOGPARAMS void *p) {
    if (p) {
	LOGINC;
	LOGPRINT(("%s %d free(%p)\n",
		  file, line, p));
	free(p);
    }
}
Example #26
0
static void  trap(int a){
    static int closing = 0;
    LOGPRINT( 4, "Cerrando aplicacion %d", a );
    if( a == SIGSEGV ){ 
        dbact_close( );
        exit( EXIT_FAILURE );
    }
    if( closing ){
        LOGPRINT( 4, "App closing", 0 );
        return;
    }
    closing = 1;
    stop_webservice( );
    LOGPRINT( 4, "Cerrando bases %d", a );
    dbact_close( );
    game_type_share_clean();
    exit( EXIT_SUCCESS );
}
Example #27
0
/* *********************************** */
int ProSLIC_testInPCMLpbkEnable(proslicChanType *pProslic, proslicTestInObjType *pTstin)
{
uInt8 regData;

	/* Valid device check */
	if(TSTIN_INVALID_PART_NUM)
	{
		return RC_UNSUPPORTED_FEATURE;
	}

	/* Check if enabled */
	if(!pTstin->pcmLpbkTest.testEnable)
	{
		return RC_TEST_DISABLED;
	}
	/* Return if already enabled */
	if(pTstin->pcmLpbkTest.pcmLpbkEnabled)
	{
		return RC_NONE;
	}

	/* Store PCM Settings */
	pTstin->pcmLpbkTest.pcmModeSave = ProSLIC_ReadReg(pProslic,11); /* PCMMODE */


	/* Disable PCM bus before changing format */
	regData = pTstin->pcmLpbkTest.pcmModeSave & ~0x10; /* PCM_EN = 0 */
	ProSLIC_WriteReg(pProslic,11,regData);

	/* Configure for either 8 or 16bit linear */
	if(pTstin->pcmLpbkTest.pcm8BitLinear == PCM_8BIT)
	{
		regData |= 0x02;   /* PCM_FMT[1] = 1 */
		regData &= ~0x01;  /* PCM_FMT[0] = 0 */
	}
	else /* PCM_16BIT */
	{
		regData |= 0x03;  /* PCM_FMT[1:0] = 11 */
	}

	ProSLIC_WriteReg(pProslic,11,regData);

	/* Enable PCM Loopback */
	ProSLIC_WriteReg(pProslic,43,0x01);  /* LOOPBACK */

	/* Re-enable PCM Bus */
	ProSLIC_WriteReg(pProslic,11,regData|0x10);  /* PCMMODE */

    pTstin->pcmLpbkTest.pcmLpbkEnabled = 1;
#ifdef ENABLE_DEBUG
	if(pProslic->debugMode)
	{
		LOGPRINT("ProSLIC : TestIn : pcmLpbk : ENABLED\n");
	}
#endif
	return RC_NONE;
}
Example #28
0
/*
 * srealloc should guaranteeably be able to realloc NULL
 */
void *(srealloc) (LOGPARAMS void *p, int size) {
  void *q;
  if (p)
  {
    LOGINC;
    LOGPRINT(("%s %d realloc(%p,%ld)", file, line, p, (long) size));
    q = realloc(p, size);
    LOGPRINT((" returns %p\n", q));
  } else
  {
    LOGINC;
    LOGPRINT(("%s %d malloc(%ld)", file, line, (long) size));
    q = malloc(size);
    LOGPRINT((" returns %p\n", q));
  }
  if (!q)
    fatal(err_nomemory);
  return q;
}
Example #29
0
/* *********************************** */
static int logStatus(proslicChanType *pProslic, int status,const char *label)
{
#ifdef ENABLE_DEBUG
	if(pProslic->debugMode)
	{
		LOGPRINT("ProSLIC : TestIn : %-14s = %d\n", label,status);
	}
#endif
	return RC_NONE;
}
Example #30
0
int   analizador_casillero( Analizador* z, Casillero* cas ) {
    CHECK_STATUS;

    LOGPRINT( 7, "Estoy en %s moviendome hacia %s%s",
              (CASILLERO_VALIDO(z->cas) ? z->cas->nombre : "?" ),
              (cas ? cas->nombre : z->cas_ori->nombre ),
              (cas ? ""  : " (original)" ) );
    z->cas = cas ? cas : z->cas_ori;
    if( z->pieza && CASILLERO_VALIDO( z->cas ) ) posicion_mueve_pieza( &z->pos, z->pieza, z->cas );
    return  STATUS_NORMAL;
}