Exemple #1
0
int mercdb_txt_sync(void)
{
	FILE *fp;
	int lock;

	if( !merc_db )
		return 1;

	if( (fp = lock_fopen(merc_txt, &lock)) == NULL ) {
		printf("mercdb_txt_sync: can't write [%s] !!! data is lost !!!\n", merc_txt);
		return 1;
	}
	numdb_foreach(merc_db, mercdb_txt_sync_sub, fp);
	lock_fclose(fp, merc_txt, &lock);

#ifdef TXT_JOURNAL
	if( merc_journal_enable )
	{
		// コミットしたのでジャーナルを新規作成する
		journal_final( &merc_journal );
		journal_create( &merc_journal, sizeof(struct mmo_mercstatus), merc_journal_cache, merc_journal_file );
	}
#endif

	return 0;
}
Exemple #2
0
//---------------------------------------------------------
// 倉庫データを書き込む
int inter_storage_save()
{
	struct DBIterator* iter;
	DBKey key;
	struct storage_data* data;
	FILE *fp;
	int lock;
	if( (fp=lock_fopen(storage_txt,&lock))==NULL ){
		ShowError("int_storage: can't write [%s] !!! data is lost !!!\n",storage_txt);
		return 1;
	}

	iter = storage_db->iterator(storage_db);
	for( data = (struct storage_data*)iter->first(iter,&key); iter->exists(iter); data = (struct storage_data*)iter->next(iter,&key) )
	{
		int account_id = key.i;
		char line[65536];
		storage_tostr(line,account_id,data);
		fprintf(fp,"%s\n",line);
 	}
	iter->destroy(iter);

	lock_fclose(fp,storage_txt,&lock);
	return 0;
}
Exemple #3
0
int storagedb_txt_sync(void)
{
	FILE *fp;
	int lock;

	if( !storage_db )
		return 1;

	if( (fp = lock_fopen(storage_txt, &lock)) == NULL ) {
		printf("storagedb_txt_sync: can't write [%s] !!! data is lost !!!\n", storage_txt);
		return 1;
	}
	numdb_foreach(storage_db, storagedb_txt_sync_sub, fp);
	lock_fclose(fp, storage_txt, &lock);

#ifdef TXT_JOURNAL
	if( storage_journal_enable )
	{
		// コミットしたのでジャーナルを新規作成する
		journal_final( &storage_journal );
		journal_create( &storage_journal, sizeof(struct storage), storage_journal_cache, storage_journal_file );
	}
#endif
	return 0;
}
Exemple #4
0
//---------------------------------------------------------
// 倉庫データを書き込む
int inter_guild_storage_save()
{
	struct DBIterator* iter;
	struct guild_storage* data;
	FILE *fp;
	int  lock;
	if( (fp=lock_fopen(guild_storage_txt,&lock))==NULL ){
		ShowError("int_storage: can't write [%s] !!! data is lost !!!\n",guild_storage_txt);
		return 1;
	}

	iter = guild_storage_db->iterator(guild_storage_db);
	for( data = (struct guild_storage*)iter->first(iter,NULL); iter->exists(iter); data = (struct guild_storage*)iter->next(iter,NULL) )
	{
		char line[65536];
		if(inter_guild_search(data->guild_id) != NULL)
		{
			guild_storage_tostr(line,data);
			if(*line)
				fprintf(fp,"%s\n",line);
		}
	}
	iter->destroy(iter);

	lock_fclose(fp,guild_storage_txt,&lock);
	return 0;
}
// ギルドデ??のセ?ブ
int inter_guild_save()
{
	FILE *fp;
	int lock;
	DBIterator* iter;
	struct guild* g;
	struct guild_castle* gc;

	// save guild data
	if ((fp = lock_fopen(guild_txt, &lock)) == NULL) {
		ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", guild_txt);
		return 1;
	}

	iter = guild_db->iterator(guild_db);
	for( g = (struct guild*)iter->first(iter,NULL); iter->exists(iter); g = (struct guild*)iter->next(iter,NULL) )
	{
		char line[16384];
		inter_guild_tostr(line, g);
		fprintf(fp, "%s\n", line);
	}
	iter->destroy(iter);

//	fprintf(fp, "%d\t%%newid%%\n", guild_newid);
	lock_fclose(fp, guild_txt, &lock);

	// save castle data
	if ((fp = lock_fopen(castle_txt,&lock)) == NULL) {
		ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", castle_txt);
		return 1;
	}

	iter = castle_db->iterator(castle_db);
	for( gc = (struct guild_castle*)iter->first(iter,NULL); iter->exists(iter); gc = (struct guild_castle*)iter->next(iter,NULL) )
	{
		char line[16384];
		inter_guildcastle_tostr(line, gc);
		fprintf(fp, "%s\n", line);
	}
	iter->destroy(iter);

	lock_fclose(fp, castle_txt, &lock);

	return 0;
}
/*==========================================
 * Saves all scdata to the given filename.
 *------------------------------------------*/
void inter_status_save()
{
	FILE *fp;
	int lock;

	if ((fp = lock_fopen(scdata_txt, &lock)) == NULL) {
		ShowError("int_status: can't write [%s] !!! data is lost !!!\n", scdata_txt);
		return;
	}
	scdata_db->foreach(scdata_db, inter_status_save_sub, fp);
	lock_fclose(fp,scdata_txt, &lock);
}
// パ?ティ?デ?タのセ?ブ
int inter_party_save() {
	FILE *fp;
	int lock;

	if ((fp = lock_fopen(party_txt, &lock)) == NULL) {
		ShowError("int_party: can't write [%s] !!! data is lost !!!\n", party_txt);
		return 1;
	}
	party_db->foreach(party_db, inter_party_save_sub, fp);
	lock_fclose(fp,party_txt, &lock);
	return 0;
}
/*==========================================
 * Saves all scdata to the given filename.
 *------------------------------------------
 */
void inter_status_save()
{
	FILE *fp;
	int lock;

	if ((fp = lock_fopen(scdata_txt, &lock)) == NULL) {
		ShowError("int_status: impossivel escrever [%s] !!! arquivo corrompido !!!\n", scdata_txt);
		return;
	}
	numdb_foreach(scdata_db, inter_status_save_sub, fp);
	lock_fclose(fp,scdata_txt, &lock);
}
Exemple #9
0
/// Saves permanent variables to savefile
static void script_save_mapreg(void)
{
	FILE *fp;
	int lock;
	DBIterator* iter;
	void* data;
	DBKey key;

	fp = lock_fopen(mapreg_txt,&lock);
	if( fp == NULL )
	{
		ShowError("script_save_mapreg: Unable to lock-open file [%s]!\n", mapreg_txt);
		return;
	}

	iter = mapreg_db->iterator(mapreg_db);
	for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
	{
		int num = (key.i & 0x00ffffff);
		int i   = (key.i & 0xff000000) >> 24;
		const char* name = get_str(num);

		if( name[1] == '@' )
			continue;

		if( i == 0 )
			fprintf(fp, "%s\t%d\n", name, (int)data);
		else
			fprintf(fp, "%s,%d\t%d\n", name, i, (int)data);
	}
	iter->destroy(iter);

	iter = mapregstr_db->iterator(mapregstr_db);
	for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
	{
		int num = (key.i & 0x00ffffff);
		int i   = (key.i & 0xff000000) >> 24;
		const char* name = get_str(num);

		if( name[1] == '@' )
			continue;

		if( i == 0 )
			fprintf(fp, "%s\t%s\n", name, (char *)data);
		else
			fprintf(fp, "%s,%d\t%s\n", name, i, (char *)data);
	}
	iter->destroy(iter);

	lock_fclose(fp,mapreg_txt,&lock);

	mapreg_dirty = false;
}
Exemple #10
0
int inter_homun_save()
{
	FILE *fp;
	int lock;
	if( (fp=lock_fopen(homun_txt,&lock))==NULL ){
		ShowError("int_homun: can't write [%s] !!! data is lost !!!\n",homun_txt);
		return 1;
	}
	homun_db->foreach(homun_db,inter_homun_save_sub,fp);
	lock_fclose(fp,homun_txt,&lock);
	return 0;
}
// ギルドデータのセーブ
int inter_guild_save() {
	FILE *fp;
	int lock;

	if ((fp = lock_fopen(guild_txt, &lock)) == NULL) {
		ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", guild_txt);
		return 1;
	}
	guild_db->foreach(guild_db, inter_guild_save_sub, fp);
//	fprintf(fp, "%d\t%%newid%%\n", guild_newid);
	lock_fclose(fp, guild_txt, &lock);
//	printf("int_guild: %s saved.\n", guild_txt);

	if ((fp = lock_fopen(castle_txt,&lock)) == NULL) {
		ShowError("int_guild: can't write [%s] !!! data is lost !!!\n", castle_txt);
		return 1;
	}
	castle_db->foreach(castle_db, inter_castle_save_sub, fp);
	lock_fclose(fp, castle_txt, &lock);

	return 0;
}
//---------------------------------------------------------
// 倉庫データを書き込む
int inter_storage_save()
{
	FILE *fp;
	int lock;
	if( (fp=lock_fopen(storage_txt,&lock))==NULL ){
		ShowError("int_storage: can't write [%s] !!! data is lost !!!\n",storage_txt);
		return 1;
	}
	storage_db->foreach(storage_db,inter_storage_save_sub,fp);
	lock_fclose(fp,storage_txt,&lock);
//	printf("int_storage: %s saved.\n",storage_txt);
	return 0;
}
Exemple #13
0
// パーティーデータのセーブ
int inter_party_save()
{
	FILE *fp;
	int  lock;
	if( (fp=lock_fopen(party_txt,&lock))==NULL ){
		printf("int_party: cant write [%s] !!! data is lost !!!\n",party_txt);
		return 1;
	}
	numdb_foreach(party_db,inter_party_save_sub,fp);
//	fprintf(fp,"%d\t%%newid%%\n",party_newid);
	lock_fclose(fp,party_txt,&lock);
//	printf("int_party: %s saved.\n",party_txt);
	return 0;
}
Exemple #14
0
//---------------------------------------------------------
// 倉庫データを書き込む
int inter_storage_save(void)
{
    FILE *fp;
    int lock;

    if ((fp = lock_fopen(storage_txt, &lock)) == NULL)
    {
        PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n",
                storage_txt);
        return 1;
    }
    for (auto& pair : storage_db)
        inter_storage_save_sub(&pair.second, fp);
    lock_fclose(fp, storage_txt, &lock);
//  PRINTF("int_storage: %s saved.\n",storage_txt);
    return 0;
}
Exemple #15
0
// パーティーデータのセーブ
int inter_party_save(void)
{
    FILE *fp;
    int lock;

    if ((fp = lock_fopen(party_txt, &lock)) == NULL)
    {
        PRINTF("int_party: cant write [%s] !!! data is lost !!!\n",
                party_txt);
        return 1;
    }
    for (auto& pair : party_db)
        inter_party_save_sub(&pair.second, fp);
//  FPRINTF(fp, "%d\t%%newid%%\n", party_newid);
    lock_fclose(fp, party_txt, &lock);
//  PRINTF("int_party: %s saved.\n", party_txt);

    return 0;
}
/// dump the entire account db to disk
static void mmo_auth_sync(AccountDB_TXT* db)
{
	int lock;
	FILE *fp;
	struct DBIterator* iter;
	struct mmo_account* acc;

	fp = lock_fopen(db->account_db, &lock);
	if( fp == NULL )
	{
		return;
	}

	fprintf(fp, "%d\n", ACCOUNT_TXT_DB_VERSION); // savefile version

	fprintf(fp, "// Accounts file: here are saved all information about the accounts.\n");
	fprintf(fp, "// Structure: account ID, username, password, sex, email, level, state, unban time, expiration time, # of logins, last login time, last (accepted) login ip, repeated(register key, register value)\n");
	fprintf(fp, "// where:\n");
	fprintf(fp, "//   sex             : M or F for normal accounts, S for server accounts\n");
	fprintf(fp, "//   level           : this account's gm level\n");
	fprintf(fp, "//   state           : 0: account is ok, 1 to 256: error code of packet 0x006a + 1\n");
	fprintf(fp, "//   unban time      : 0: no ban, <other value>: banned until the date (unix timestamp)\n");
	fprintf(fp, "//   expiration time : 0: unlimited account, <other value>: account expires on the date (unix timestamp)\n");

	//TODO: sort?

	iter = db->accounts->iterator(db->accounts);
	for( acc = (struct mmo_account*)iter->first(iter,NULL); iter->exists(iter); acc = (struct mmo_account*)iter->next(iter,NULL) )
	{
		char buf[2048]; // ought to be big enough ^^
		mmo_auth_tostr(acc, buf);
		fprintf(fp, "%s\n", buf);
	}
	fprintf(fp, "%d\t%%newid%%\n", db->next_account_id);
	iter->destroy(iter);

	lock_fclose(fp, db->account_db, &lock);

	// reset save counter
	db->auths_before_save = AUTHS_BEFORE_SAVE;
}