Exemple #1
0
// 删除一个格子的道具
int item_deletebox( int actor_index, int item_offset, char type )
{
	char	szSQL[1024];
	char bigint[21];
	Item *pItem = NULL;
	if ( actor_index < 0 || actor_index >= g_maxactornum )
		return -1;
	if ( type == 0 )
	{
		if ( item_offset >= 0 && item_offset < MAX_ACTOR_ITEMNUM )
			pItem = &g_actors[actor_index].item[item_offset];
		else
			return -1;
	}
	else if ( type == 2 )
		pItem = &g_actors[actor_index].equip[item_offset - EQUIP_OFFSETBASE];

	// 数据库删除
	lltoa( pItem->m_itemid, bigint, 10 );
	sprintf( szSQL, "delete from actor_item where itemid='%s'", bigint );
	if ( mysql_query( myGame, szSQL ) )
	{
		printf( "Query failed (%s)\n", mysql_error( myGame ) );
		write_gamelog( "%s", szSQL );
		if ( mysql_ping( myGame ) != 0 )
			db_reconnect_game();
		return -1;
	}
	// 内存删除
	memset( pItem, 0, sizeof(Item) );
	return 0;
}
Exemple #2
0
void print_value( long long value )
{
    int base;
    char buffer[65];

    for( base = 2; base <= 16; base = base + 2 )
        printf( "%2d %s\n", base,
                lltoa( value, buffer, base ) );
}
Exemple #3
0
/* 战报详情 */
int fight_msg_read( int actor_index, i64 msgid )
{
	if ( actor_index < 0 || actor_index >= g_maxactornum )
		return -1;
	MYSQL_RES	*res;
	MYSQL_ROW	row;
	char	szSQL[1024];
	char bigint[21];
	lltoa( msgid, bigint, 10 );
	sprintf( szSQL, "SELECT posx, posy, target_type, target_id, target_posx, target_posy, wood, iron, food, recordid FROM fight_msg WHERE id='%s'", bigint );
	if ( mysql_query( myGame, szSQL ) )
	{
		printf( "Query failed (%s)\n", mysql_error( myGame ) );
		write_gamelog( "%s", szSQL );
		if ( mysql_ping( myGame ) != 0 )
			db_reconnect_game();
		return -1;
	}
	res = mysql_store_result( myGame );
	if ( (row = mysql_fetch_row( res )) )
	{
		// 发送详细信息
		int index = 0;
		SLK_NetS_FightMsgInfo info = { 0 };
		info.m_msgid = msgid;
		info.m_posx = (short)atoi( row[index++] );
		info.m_posy = (short)atoi( row[index++] );
		info.m_target_type = (char)atoi( row[index++] );
		info.m_target_id = atoi( row[index++] );
		info.m_target_posx = atoi( row[index++] );
		info.m_target_posy = atoi( row[index++] );
		info.m_wood = atoi( row[index++] );
		info.m_iron = atoi( row[index++] );
		info.m_food = atoi( row[index++] );
		info.m_recordid = atoi( row[index++] );
		info.m_read = 1;
		netsend_fightmsginfo_S( actor_index, SENDTYPE_ACTOR, &info );
	}
	mysql_free_result( res );

	// 设置已读状态
	sprintf( szSQL, "UPDATE fight_msg SET read='%d' WHERE id='%s'", 1, bigint );
	if ( mysql_query( myGame, szSQL ) )
	{
		printf( "Query failed (%s)\n", mysql_error( myGame ) );
		write_gamelog( "%s", szSQL );
		if ( mysql_ping( myGame ) != 0 )
			db_reconnect_game();
		return -1;
	}
	return 0;
}
Exemple #4
0
/* 删除战报 */
int fight_msg_delete( int actor_index, i64 msgid )
{
	char szSQL[1024];
	char bigint[21];
	lltoa( msgid, bigint, 10 );
	sprintf( szSQL, "DELETE FROM fight_msg WHERE id='%s'", bigint );
	if ( mysql_query( myGame, szSQL ) )
	{
		printf( "Query failed (%s) [%s](%d)\n", mysql_error( myGame ), __FUNCTION__, __LINE__ );
		write_gamelog( "%s", szSQL );
		if ( mysql_ping( myGame ) != 0 )
			db_reconnect_game();
		return -1;
	}
	return 0;
}
Exemple #5
0
/* 发送战报 */
int fight_msg_send( int actorid, SLK_NetS_FightMsgInfo *pValue )
{
	if ( !pValue )
		return -1;

	MYSQL_RES *res;
	MYSQL_ROW row;
	char szSQL[1024] = { 0 };
	int thistime = (int)time( NULL );
	char bigint_recordid[21];
	lltoa( pValue->m_recordid, bigint_recordid, 10 );
	pValue->m_recvtime = thistime;
	// 插入数据库
	sprintf( szSQL, "INSERT INTO fight_msg ( `actorid`,`title`,`read`,`recvtime`,`posx`,`posy`,`status`,`target_type`,`target_id`,`wood`,`iron`,`food`,`recordid` ) "
		"VALUES ('%d','%s','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%s')",
		actorid, pValue->m_title, pValue->m_read, pValue->m_recvtime, pValue->m_posx, pValue->m_posy, pValue->m_status, pValue->m_target_type, pValue->m_target_id, pValue->m_wood, pValue->m_iron, pValue->m_food, bigint_recordid );
	if ( mysql_query( myGame, szSQL ) )
	{
		printf( "Query failed (%s)\n", mysql_error( myGame ) );
		write_gamelog( "%s", szSQL );
		if ( mysql_ping( myGame ) != 0 )
			db_reconnect_game();
		return -1;
	}

	// 如收件人在线,通知有新的消息
	int actorindex = actor_getindex_withid( actorid );
	if ( actorindex >= 0 )
	{
		sprintf( szSQL, "SELECT LAST_INSERT_ID()" );
		if ( mysql_query( myGame, szSQL ) )
		{
			printf( "Query failed (%s)\n", mysql_error( myGame ) );
			write_gamelog( "%s", szSQL );
			return -1;
		}
		res = mysql_store_result( myGame );
		if ( (row = mysql_fetch_row( res )) )
		{
			pValue->m_msgid = atoll( row[0] );
			netsend_fightmsginfo_S( actorindex, SENDTYPE_ACTOR, pValue );
		}
		mysql_free_result( res );
	}
	return 0;
}
Exemple #6
0
//**************************************************************************************
//***
//***
//***
//**************************************************************************************
void serSendStringDebug(uchar *ch1, long val, uchar *ch2)
{
	uchar tmp[30];
	uchar *p1;
	
	if( ch1 != NULL )
		while( *ch1 != 0 )
			serSendByte(*ch1++);

	if( val != NUMERR_LONG )
	{
		p1 = (uchar *)lltoa((uchar *)&tmp,val);
		while( *p1 != NULL )
			serSendByte(*p1++);
	}

	if( ch2 != NULL )
		while( *ch2 != 0 )
			serSendByte(*ch2++);
}
Exemple #7
0
GString & GString::operator+=(__int64 _p)
{
	char  szBuffer[25];
//	sprintf(szBuffer, "%I64d", _p);
	lltoa ( _p,szBuffer,10);

	int nLen = strlen(szBuffer);
	for (int i = 0; i < nLen; i++, _len++)
	{
		if (_len >= _max)
			resize();
		_str[_len] = szBuffer[i];
	}

	if (_len >= _max)
		resize();
	_str[_len] = 0;

	return *this;
}
Exemple #8
0
// 用户锁定账号
int user_lock( int client_index, int authid, i64 player_userid, int lockmin )
{
	char *ptr;
	int queue_tail;

	if( client_index < 0 )
		player_userid = actor_getoffline_userid( authid );

	if( player_userid < 0 )
		return -1;

	// 锁住写队列缓冲
	mmux_lock( g_login_mmux );
	queue_tail = g_nLoginQueueTail + 1;
	if( queue_tail >= MAX_LOGINQUEUENUM )
	{
		queue_tail = 0;
	}
	if( g_nLoginQueueHead == queue_tail )
	{
		write_netlog("login queue full");
		mmux_unlock( g_login_mmux );
		// 通知登录线程得赶紧干活, 都满了啊
		mcond_broadcast( g_pthr_login );
		return -1;
	}
	// 将需要处理的客户放置到登录队列
	login_queue[g_nLoginQueueTail].client_index = client_index;
	login_queue[g_nLoginQueueTail].authid = authid;
	login_queue[g_nLoginQueueTail].command = USERCMDC_LOCKUSER;
	ptr = login_queue[g_nLoginQueueTail].data;

	char tmpBuf[MAX_PATH];
	sprintf( login_queue[g_nLoginQueueTail].data, "&v1=%s&v2=%d", lltoa(player_userid,tmpBuf,10), lockmin );

	g_nLoginQueueTail = queue_tail;
	mmux_unlock( g_login_mmux );
	// 通知登录线程干活
	mcond_broadcast( g_pthr_login );
	return 0;
}
Exemple #9
0
//
// see:
// github.com/radekp/qt/blob/master/src/corelib/tools/qlocale.cpp L:4000
//
static std::string longlongToString(long long int l, int precision,
                                    int /*width*/, unsigned flags)
{
    //    bool precision_not_specified = false;
    if (precision == -1) {
        //        precision_not_specified = true;
        precision = 1;
    }
    bool negative = l < 0;
    std::string num_str;
    num_str = lltoa(l);
    for (int i = num_str.length(); i < precision; ++i)
        num_str.insert(0, "0");
    if (negative)
        num_str.insert(0, "-");
    else if (flags & AlwaysShowSign)
        num_str.insert(0, "+");
    else if (flags & BlankBeforePositive)
        num_str.insert(0, " ");
    return num_str;
}
Exemple #10
0
/* 战报列表 */
int fight_msg_loadlist( int actor_index, i64 maxid )
{
	if ( actor_index < 0 || actor_index >= g_maxactornum )
		return -1;
	MYSQL_RES	*res;
	MYSQL_ROW	row;
	char	szSQL[1024];
	SLK_NetS_FightMsgList info = { 0 };
	char bigint[21];
	lltoa( maxid, bigint, 10 );
	sprintf( szSQL, "SELECT `id`, `read`, `recvtime`, `status`, `target_type`, `title` FROM fight_msg WHERE id>'%s' AND actorid='%d' AND recvtime>'%d' LIMIT 10", bigint, g_actors[actor_index].actorid, (int)time( NULL ) - MAX_FIGHTMSG_SAVETIME );
	if ( mysql_query( myGame, szSQL ) )
	{
		printf( "Query failed (%s)\n", mysql_error( myGame ) );
		write_gamelog( "%s", szSQL );
		if ( mysql_ping( myGame ) != 0 )
			db_reconnect_game();
		return -1;
	}
	res = mysql_store_result( myGame );
	while ( (row = mysql_fetch_row( res )) )
	{
		// 邮件简单信息列表
		info.m_list[info.m_count].m_msgid = atoll( row[0] );
		info.m_list[info.m_count].m_read = (char)atoi( row[1] );
		info.m_list[info.m_count].m_recvtime = atoi( row[2] );
		info.m_list[info.m_count].m_status = atoi( row[3] );
		info.m_list[info.m_count].m_target_type = atoi( row[4] );
		memcpy( info.m_list[info.m_count].m_title, row[5], 32 );
		info.m_list[info.m_count].m_title_length=strlen(info.m_list[info.m_count].m_title);
		info.m_count++;
		if ( info.m_count >= 10 )
			break;
	}
	mysql_free_result( res );
	netsend_fightmsglist_S( actor_index, SENDTYPE_ACTOR, &info );
	return 0;
}
Exemple #11
0
ostream &ostream::operator << ( signed __int64 i ) {
/**************************************************/
// Write a signed long integer to the stream.

    int         base;
    char        buffer[LONGEST_INT64 + 1];
    int         size;
    int         digit_offset;

    __lock_it( __i_lock );
    base = __FlagsToBase( flags() );
    if( base != 10 ) {
        return( *this << (unsigned __int64) i );
    }

    // Sign:
    if( i > 0  &&  (flags() & ios::showpos) ) {
        buffer[0] = '+';
        digit_offset = 1;
    } else {
        digit_offset = 0;
    }

    // Digits:
    lltoa( i, buffer + digit_offset, base );
    if( buffer[0] == '-' ) {
        digit_offset = 1;
    }
    size = ::strlen( buffer );

    // Write the number:
    if( opfx() ) {
        setstate( __WATCOM_ios::writeitem( *this, buffer, size, digit_offset ) );
        osfx();
    }
    return( *this );
}
Exemple #12
0
void test_css_util_other()
{
	char str[24];
	char test[10];
	char* s = NULL;
	char* t = NULL;
	assert(strcmp("922337203685477587",lltoa(922337203685477587,str,10)) == 0);

	strcpy(test," abc");
	str_trim(test);
	assert( 0 == strcmp(test,"abc"));

	strcpy(test," abc ");
	str_trim(test);
	assert( 0 == strcmp(test,"abc"));

	strcpy(test,"abc ");
	str_trim(test);
	assert( 0 == strcmp(test,"abc"));

	strcpy(test,"  a b c ");
	str_trim(test);
	assert( 0 == strcmp(test,"a b c"));

	strcpy(test,"   ");
	str_trim(test);
	assert( 0 == strcmp(test,""));

	strcpy(test," abc");
	str_ltrim(test);
	assert( 0 == strcmp(test,"abc"));

	strcpy(test," abc ");
	str_rtrim(test);
	assert( 0 == strcmp(test," abc"));

	strcpy(test," abc ");
	str_ltrim(test);
	assert( 0 == strcmp(test,"abc "));

	strcpy(test,"  a b c ");
	str_ltrim(test);
	assert( 0 == strcmp(test,"a b c "));

	strcpy(test,"   ");
	str_ltrim(test);
	assert( 0 == strcmp(test,""));

	strcpy(test,"   ");
	str_rtrim(test);
	assert( 0 == strcmp(test,""));

	memset(test,' ',10);
	strcpy(test,"a=b");
	get_split_str(test,"=",1,&s);
	assert( 0 == strcmp(s,"b"));
	FREE(s);
	get_split_str(test,"=",0,&s);
	assert( 0 == strcmp(s,"a"));
	FREE(s);
	get_split_strs(test,"=",&s,&t);
	assert( 0 == strcmp(s,"a"));
	assert( 0 == strcmp(t,"b"));
	FREE(s);
	FREE(t);

	memset(test,' ',10);
	strcpy(test," a = b ");
	get_split_str(test,"=",1,&s);
	str_trim(s);
	assert( 0 == strcmp(s,"b"));
	FREE(s);

	get_split_str(test,"=",0,&s);
	str_trim(s);
	assert( 0 == strcmp(s,"a"));
	FREE(s);

	get_split_strs(test,"=",&s,&t);
	str_trim(s);
	str_trim(t);
	assert( 0 == strcmp(s,"a"));
	assert( 0 == strcmp(t,"b"));
	FREE(s);
	FREE(t);

	assert(0 == ensure_dir("./test/dir"));
	assert(0 == ensure_dir("./test/dir/"));
}