Example #1
0
/**
 * Lookup (and possibly create) a new set of patterns by the set id
 */
static struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid)
{
	struct pcrematch_set *pcreset;
	struct npc_parse *npcParse = (struct npc_parse *) nd->chatdb;
	if (npcParse == NULL)
		nd->chatdb = npcParse = (struct npc_parse *) aCalloc(sizeof(struct npc_parse), 1);

	pcreset = npcParse->active;

	while (pcreset != NULL) {
		if (pcreset->setid == setid)
		break;
		pcreset = pcreset->next;
	}
	if (pcreset == NULL)
		pcreset = npcParse->inactive;

	while (pcreset != NULL) {
		if (pcreset->setid == setid)
		break;
		pcreset = pcreset->next;
	}

	if (pcreset == NULL) {
		pcreset = (struct pcrematch_set *) aCalloc(sizeof(struct pcrematch_set), 1);
		pcreset->next = npcParse->inactive;
		if (pcreset->next != NULL)
			pcreset->next->prev = pcreset;
		pcreset->prev = 0;
		npcParse->inactive = pcreset;
		pcreset->setid = setid;
	}

	return pcreset;
}
Example #2
0
//---------------------------------------------------------
// storage data initialize
int inter_storage_sql_init(void)
{

	//memory alloc
	ShowDebug("interserver storage memory initialize....(%d byte)\n",sizeof(struct storage));
	storage_pt = (struct storage*)aCalloc(sizeof(struct storage), 1);
	guild_storage_pt = (struct guild_storage*)aCalloc(sizeof(struct guild_storage), 1);

	return 1;
}
Example #3
0
//---------------------------------------------------------
// storage data initialize
int inter_storage_sql_init(void) {

    //memory alloc
    ShowDebug("interserver storage memory initialize....(%d byte)\n",sizeof(struct storage));
    storage_pt = (struct storage*)aCalloc(sizeof(struct storage), 1);
    guild_storage_pt = (struct guild_storage*)aCalloc(sizeof(struct guild_storage), 1);
//	memset(storage_pt,0,sizeof(struct storage)); //Calloc sets stuff to 0 already. [Skotlex]
//	memset(guild_storage_pt,0,sizeof(struct guild_storage));

    return 1;
}
Example #4
0
//character selected, insert into auth db
void chrif_authok(int fd)
{
	struct auth_node *auth_data;
	TBL_PC* sd;
	//Check if we don't already have player data in our server
	//(prevents data that is to be saved from being overwritten by
	//this received status data if this auth is later successful) [Skotlex]
	if ((sd = map_id2sd(RFIFOL(fd, 4))) != NULL)
	{
		struct mmo_charstatus *status = (struct mmo_charstatus *)RFIFOP(fd, 20);
		//Auth check is because this could be the very same sd that is waiting char-server authorization.
		if (sd->state.auth && sd->status.char_id == status->char_id)
			return;
	}
	
	if ((auth_data =uidb_get(auth_db, RFIFOL(fd, 4))) != NULL)
	{	//Is the character already awaiting authorization?
		if (auth_data->sd)
		{
			//First, check to see if the session data still exists (avoid dangling pointers)
			if(session[auth_data->fd] && session[auth_data->fd]->session_data == auth_data->sd)
			{	
				if (auth_data->char_dat == NULL &&
					auth_data->account_id == RFIFOL(fd, 4) &&
					auth_data->login_id1 == RFIFOL(fd, 8))
				{ //Auth Ok
					pc_authok(auth_data->sd, RFIFOL(fd, 16), RFIFOL(fd, 12), (struct mmo_charstatus*)RFIFOP(fd, 20));
				} else { //Auth Failed
					pc_authfail(auth_data->sd);
					chrif_char_offline(auth_data->sd); //Set him offline, the char server likely has it set as online already.
				}
			} //else: Character no longer exists, just go through.
		}
		//Delete the data of this node...
		if (auth_data->char_dat)
			aFree (auth_data->char_dat);
		uidb_remove(auth_db, RFIFOL(fd, 4));
		return;
	}
	// Awaiting for client to connect.
	auth_data = (struct auth_node *)aCalloc(1,sizeof(struct auth_node));
	auth_data->char_dat = (struct mmo_charstatus *) aCalloc(1,sizeof(struct mmo_charstatus));

	auth_data->account_id=RFIFOL(fd, 4);
	auth_data->login_id1=RFIFOL(fd, 8);
	auth_data->connect_until_time=RFIFOL(fd, 12);
	auth_data->login_id2=RFIFOL(fd, 16);
	memcpy(auth_data->char_dat,RFIFOP(fd, 20),sizeof(struct mmo_charstatus));
	auth_data->node_created=gettick();
	uidb_put(auth_db, RFIFOL(fd, 4), auth_data);
}
Example #5
0
/**
 * Load achievements for a character.
 * @param char_id: Character ID
 * @param count: Pointer to return the number of found entries.
 * @return Array of found entries. It has *count entries, and it is care of the caller to aFree() it afterwards.
 */
struct achievement *mapif_achievements_fromsql(uint32 char_id, int *count)
{
	struct achievement *achievelog = NULL;
	struct achievement tmp_achieve;
	SqlStmt *stmt;
	StringBuf buf;
	int i;

	if (!count)
		return NULL;

	memset(&tmp_achieve, 0, sizeof(tmp_achieve));

	StringBuf_Init(&buf);
	StringBuf_AppendStr(&buf, "SELECT `id`, COALESCE(UNIX_TIMESTAMP(`completed`),0), COALESCE(UNIX_TIMESTAMP(`rewarded`),0)");
	for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
		StringBuf_Printf(&buf, ", `count%d`", i + 1);
	StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id` = '%u'", schema_config.achievement_table, char_id);

	stmt = SqlStmt_Malloc(sql_handle);
	if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
	||  SQL_ERROR == SqlStmt_Execute(stmt) )
	{
		SqlStmt_ShowDebug(stmt);
		SqlStmt_Free(stmt);
		StringBuf_Destroy(&buf);
		*count = 0;
		return NULL;
	}

	SqlStmt_BindColumn(stmt, 0, SQLDT_INT,  &tmp_achieve.achievement_id, 0, NULL, NULL);
	SqlStmt_BindColumn(stmt, 1, SQLDT_INT,  &tmp_achieve.completed, 0, NULL, NULL);
	SqlStmt_BindColumn(stmt, 2, SQLDT_INT,  &tmp_achieve.rewarded, 0, NULL, NULL);
	for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; ++i)
		SqlStmt_BindColumn(stmt, 3 + i, SQLDT_INT, &tmp_achieve.count[i], 0, NULL, NULL);

	*count = (int)SqlStmt_NumRows(stmt);
	if (*count > 0) {
		i = 0;

		achievelog = (struct achievement *)aCalloc(*count, sizeof(struct achievement));
		while (SQL_SUCCESS == SqlStmt_NextRow(stmt)) {
			if (i >= *count) // Sanity check, should never happen
				break;
			memcpy(&achievelog[i++], &tmp_achieve, sizeof(tmp_achieve));
		}
		if (i < *count) {
			// Should never happen. Compact array
			*count = i;
			achievelog = (struct achievement *)aRealloc(achievelog, sizeof(struct achievement) * i);
		}
	}

	SqlStmt_Free(stmt);
	StringBuf_Destroy(&buf);

	ShowInfo("achievement load complete from DB - id: %d (total: %d)\n", char_id, *count);

	return achievelog;
}
Example #6
0
/*==========================================
 * Loads all scdata from the given filename.
 *------------------------------------------
 */
void status_load_scdata(const char* filename)
{
	FILE *fp;
	int sd_count=0, sc_count=0;
	char line[8192];
	struct scdata *sc;

	if ((fp = fopen(filename, "r")) == NULL) {
		ShowError("status_load_scdata: Nao se pode abrir o arquivo %s!\n", filename);
		return;
	}

	while(fgets(line, sizeof(line) - 1, fp)) {
		sc = (struct scdata*)aCalloc(1, sizeof(struct scdata));
		if (inter_scdata_fromstr(line, sc)) {
			numdb_insert(scdata_db, sc->char_id, sc);
			sd_count++;
			sc_count+= sc->count;
		} else {
			ShowError("status_load_scdata: Arquivo de linha quebrada: %s\n", line);
			aFree(sc);
		}
	}
	fclose(fp);
	ShowStatus("Carregado %d salvo mudança de status %d personagem.\n", sc_count, sd_count);
}
Example #7
0
// 作成可否
int party_created(int account_id,int char_id,int fail,int party_id,char *name)
{
	struct map_session_data *sd;
	sd=map_id2sd(account_id);

	nullpo_retr(0, sd);
	if (sd->status.char_id != char_id)
		return 0; //unlikely failure...
	
	if(fail==0){
		struct party *p;
		sd->status.party_id=party_id;
		if(idb_get(party_db,party_id)!=NULL){
			ShowFatalError("party: id already exists!\n");
			exit(1);
		}
		p=(struct party *)aCalloc(1,sizeof(struct party));
		p->party_id=party_id;
		memcpy(p->name, name, NAME_LENGTH);
		idb_put(party_db,party_id,p);
		clif_party_created(sd,0); //Success message
		clif_charnameupdate(sd); //Update other people's display. [Skotlex]
	}else{
		clif_party_created(sd,1);
	}
	return 0;
}
Example #8
0
int inter_homun_init()
{
	char line[8192];
	struct s_homunculus *p;
	FILE *fp;
	int c=0;

	homun_db= idb_alloc(DB_OPT_RELEASE_DATA);

	if( (fp=fopen(homun_txt,"r"))==NULL )
		return 1;
	while(fgets(line, sizeof(line), fp))
	{
		p = (struct s_homunculus*)aCalloc(sizeof(struct s_homunculus), 1);
		if(p==NULL){
			ShowFatalError("int_homun: out of memory!\n");
			exit(EXIT_FAILURE);
		}
		if(inter_homun_fromstr(line,p)==0 && p->hom_id>0){
			if( p->hom_id >= homun_newid)
				homun_newid=p->hom_id+1;
			idb_put(homun_db,p->hom_id,p);
		}else{
			ShowError("int_homun: broken data [%s] line %d\n",homun_txt,c);
			aFree(p);
		}
		c++;
	}
	fclose(fp);
	return 0;
}
Example #9
0
/*==========================================
 * new auth system [Kevin]
 *------------------------------------------*/
void chrif_authreq(struct map_session_data *sd)
{
	struct auth_node *auth_data;
	auth_data=idb_get(auth_db, sd->bl.id);

	if(auth_data) {
		if(auth_data->char_dat &&
			auth_data->account_id== sd->bl.id &&
			auth_data->login_id1 == sd->login_id1)
		{	//auth ok
			pc_authok(sd, auth_data->login_id2, auth_data->connect_until_time, auth_data->char_dat);
		} else { //auth failed
			pc_authfail(sd);
			chrif_char_offline(sd); //Set him offline, the char server likely has it set as online already.
		}
		if (auth_data->char_dat)
			aFree(auth_data->char_dat);
		idb_remove(auth_db, sd->bl.id);
	} else { //data from char server has not arrived yet.
		auth_data = aCalloc(1,sizeof(struct auth_node));
		auth_data->sd = sd;
		auth_data->fd = sd->fd;
		auth_data->account_id = sd->bl.id;
		auth_data->login_id1 = sd->login_id1;
		auth_data->node_created = gettick();
		uidb_put(auth_db, sd->bl.id, auth_data);
	}
	return;
}
Example #10
0
int inter_pet_init()
{
	char line[8192];
	struct s_pet *p;
	FILE *fp;
	int c=0;

	pet_db= idb_alloc(DB_OPT_RELEASE_DATA);

	if( (fp=fopen(pet_txt,"r"))==NULL )
		return 1;
	while(fgets(line, sizeof(line), fp))
	{
		p = (struct s_pet*)aCalloc(sizeof(struct s_pet), 1);
		if(p==NULL){
			ShowFatalError("int_pet: out of memory!\n");
			exit(EXIT_FAILURE);
		}
		memset(p,0,sizeof(struct s_pet));
		if(inter_pet_fromstr(line,p)==0 && p->pet_id>0){
			if( p->pet_id >= pet_newid)
				pet_newid=p->pet_id+1;
			idb_put(pet_db,p->pet_id,p);
		}else{
			ShowError("int_pet: broken data [%s] line %d\n",pet_txt,c);
			aFree(p);
		}
		c++;
	}
	fclose(fp);
	return 0;
}
Example #11
0
// パーティデータのロード
int inter_party_init()
{
	char line[8192];
	struct party *p;
	FILE *fp;
	int c=0;
	
	party_db=numdb_init();
	
	if( (fp=fopen(party_txt,"r"))==NULL )
		return 1;
	while(fgets(line,sizeof(line),fp)){
		int i,j=0;
		if( sscanf(line,"%d\t%%newid%%\n%n",&i,&j)==1 && j>0 && party_newid<=i){
			party_newid=i;
			continue;
		}
	
		p=(struct party *)aCalloc(1,sizeof(struct party));
		if(inter_party_fromstr(line,p)==0 && p->party_id>0){
			if( p->party_id >= party_newid)
				party_newid=p->party_id+1;
			numdb_insert(party_db,p->party_id,p);
			party_check_empty(p);
		}
		else{
			printf("int_party: broken data [%s] line %d\n",party_txt,c+1);
			free(p);
		}
		c++;
	}
	fclose(fp);
//	printf("int_party: %s read done (%d parties)\n",party_txt,c);
	return 0;
}
Example #12
0
int acquire_timer (void)
{
	int i;

	if (free_timer_list_pos) {
		do {
			i = free_timer_list[--free_timer_list_pos];
		} while(i >= timer_data_num && free_timer_list_pos > 0);
	} else
		i = timer_data_num;

	if (i >= timer_data_num)
		for (i = timer_data_num; i < timer_data_max && timer_data[i].type; i++);
	if (i >= timer_data_num && i >= timer_data_max) {
		if (timer_data_max == 0) {
			timer_data_max = 256;
			timer_data = (struct TimerData*) aCalloc( sizeof(struct TimerData) , timer_data_max);
		} else {
			timer_data_max += 256;
			timer_data = (struct TimerData *) aRealloc( timer_data, sizeof(struct TimerData) * timer_data_max);
			memset(timer_data + (timer_data_max - 256), 0, sizeof(struct TimerData) * 256);
		}
	}

	return i;
}
Example #13
0
/*======================================
 * 	CORE : Timer Heap
 *--------------------------------------
 */
static void push_timer_heap(int index)
{
	int i, j;
	int min, max, pivot; // for sorting

	// check number of element
	if (timer_heap_num >= timer_heap_max) {
		if (timer_heap_max == 0) {
			timer_heap_max = 256;
			timer_heap = (int *) aCalloc( sizeof(int) , 256);
		} else {
			timer_heap_max += 256;
			timer_heap = (int *) aRealloc( timer_heap, sizeof(int) * timer_heap_max);
			memset(timer_heap + (timer_heap_max - 256), 0, sizeof(int) * 256);
		}
	}

	// do a sorting from higher to lower
	j = timer_data[index].tick; // speed up
	// with less than 4 values, it's speeder to use simple loop
	if (timer_heap_num < 4) {
		for(i = timer_heap_num; i > 0; i--)
//			if (j < timer_data[timer_heap[i - 1]].tick) //Plain comparisons break on bound looping timers. [Skotlex]
			if (DIFF_TICK(j, timer_data[timer_heap[i - 1]].tick) < 0)
				break;
			else
				timer_heap[i] = timer_heap[i - 1];
		timer_heap[i] = index;
	// searching by dichotomie
	} else {
		// if lower actual item is higher than new
//		if (j < timer_data[timer_heap[timer_heap_num - 1]].tick) //Plain comparisons break on bound looping timers. [Skotlex]
		if (DIFF_TICK(j, timer_data[timer_heap[timer_heap_num - 1]].tick) < 0)
			timer_heap[timer_heap_num] = index;
		else {
			// searching position
			min = 0;
			max = timer_heap_num - 1;
			while (min < max) {
				pivot = (min + max) / 2;
//				if (j < timer_data[timer_heap[pivot]].tick) //Plain comparisons break on bound looping timers. [Skotlex]
				if (DIFF_TICK(j, timer_data[timer_heap[pivot]].tick) < 0)
					min = pivot + 1;
				else
					max = pivot;
			}
			// move elements - do loop if there are a little number of elements to move
			if (timer_heap_num - min < 5) {
				for(i = timer_heap_num; i > min; i--)
					timer_heap[i] = timer_heap[i - 1];
			// move elements - else use memmove (speeder for a lot of elements)
			} else
				memmove(&timer_heap[min + 1], &timer_heap[min], sizeof(int) * (timer_heap_num - min));
			// save new element
			timer_heap[min] = index;
		}
	}

	timer_heap_num++;
}
Example #14
0
static void* create_guildstorage(DBKey key, va_list args)
{
	struct guild_storage *gs = NULL;
	gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1);
	gs->guild_id=key.i;
	return gs;
}
Example #15
0
/**
 * @see DBCreateData
 */
static DBData create_guildstorage(DBKey key, va_list args)
{
	struct guild_storage *gs = NULL;
	gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1);
	gs->guild_id=key.i;
	return db_ptr2data(gs);
}
Example #16
0
/**
 * Inter-serv has sent us the elemental data from sql, fill it in map-serv memory
 * @param ele : The elemental data received from char-serv
 * @param flag : 0:not created, 1:was saved/loaded
 * @return 0:failed, 1:sucess
 */
int elemental_data_received(struct s_elemental *ele, bool flag) {
	struct map_session_data *sd;
	struct elemental_data *ed;
	struct s_elemental_db *db;
	int i = elemental_search_index(ele->class_);

	if( (sd = map_charid2sd(ele->char_id)) == NULL )
		return 0;

	if( !flag || i < 0 ) { // Not created - loaded - DB info
		sd->status.ele_id = 0;
		return 0;
	}

	db = &elemental_db[i];
	if( !sd->ed ) {	// Initialize it after first summon.
		sd->ed = ed = (struct elemental_data*)aCalloc(1,sizeof(struct elemental_data));
		ed->bl.type = BL_ELEM;
		ed->bl.id = npc_get_new_npc_id();
		ed->master = sd;
		ed->db = db;
		memcpy(&ed->elemental, ele, sizeof(struct s_elemental));
		status_set_viewdata(&ed->bl, ed->elemental.class_);
		ed->vd->head_mid = 10; // Why?
		status_change_init(&ed->bl);
		unit_dataset(&ed->bl);
		ed->ud.dir = sd->ud.dir;

		ed->bl.m = sd->bl.m;
		ed->bl.x = sd->bl.x;
		ed->bl.y = sd->bl.y;
		unit_calc_pos(&ed->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
		ed->bl.x = ed->ud.to_x;
		ed->bl.y = ed->ud.to_y;

		map_addiddb(&ed->bl);
		status_calc_elemental(ed,SCO_FIRST);
		ed->last_spdrain_time = ed->last_thinktime = gettick();
		ed->summon_timer = INVALID_TIMER;
		ed->masterteleport_timer = INVALID_TIMER;
		elemental_summon_init(ed);
	} else {
		memcpy(&sd->ed->elemental, ele, sizeof(struct s_elemental));
		ed = sd->ed;
	}

	sd->status.ele_id = ele->elemental_id;

	if( ed->bl.prev == NULL && sd->bl.prev != NULL ) {
		if(map_addblock(&ed->bl))
			return 0;
		clif_spawn(&ed->bl);
		clif_elemental_info(sd);
		clif_elemental_updatestatus(sd,SP_HP);
		clif_hpmeter_single(sd->fd,ed->bl.id,ed->battle_status.hp,ed->battle_status.max_hp);
		clif_elemental_updatestatus(sd,SP_SP);
	}

	return 1;
}
Example #17
0
// ==========================================
// アカウント変数のジャーナルのロールフォワード用コールバック関数
// ------------------------------------------
int accregdb_journal_rollforward( int key, void* buf, int flag )
{
	struct accreg* reg = (struct accreg *)numdb_search( accreg_db, key );

	// 念のためチェック
	if( flag == JOURNAL_FLAG_WRITE && key != ((struct accreg*)buf)->account_id )
	{
		printf("inter: accreg_journal: key != account_id !\n");
		return 0;
	}

	// データの置き換え
	if( reg )
	{
		if( flag == JOURNAL_FLAG_DELETE ) {
			numdb_erase( accreg_db, key );
			aFree( reg );
		} else {
			memcpy( reg, buf, sizeof(struct accreg) );
		}
		return 1;
	}

	// 追加
	if( flag != JOURNAL_FLAG_DELETE )
	{
		reg = (struct accreg*) aCalloc( 1, sizeof( struct accreg ) );
		memcpy( reg, buf, sizeof(struct accreg) );
		numdb_insert( accreg_db, key, reg );
		return 1;
	}

	return 0;
}
/// public constructor
AccountDB* account_db_txt(void)
{
	AccountDB_TXT* db = (AccountDB_TXT*)aCalloc(1, sizeof(AccountDB_TXT));

	// set up the vtable
	db->vtable.init         = &account_db_txt_init;
	db->vtable.destroy      = &account_db_txt_destroy;
	db->vtable.get_property = &account_db_txt_get_property;
	db->vtable.set_property = &account_db_txt_set_property;
	db->vtable.save         = &account_db_txt_save;
	db->vtable.create       = &account_db_txt_create;
	db->vtable.remove       = &account_db_txt_remove;
	db->vtable.load_num     = &account_db_txt_load_num;
	db->vtable.load_str     = &account_db_txt_load_str;
	db->vtable.iterator     = &account_db_txt_iterator;

	// initialize to default values
	db->accounts = NULL;
	db->next_account_id = START_ACCOUNT_NUM;
	db->auths_before_save = AUTHS_BEFORE_SAVE;
	db->save_timer = INVALID_TIMER;
	safestrncpy(db->account_db, "save/account.txt", sizeof(db->account_db));
	db->case_sensitive = false;

	return &db->vtable;
}
Example #19
0
/*==========================================
 * Loads all scdata from the given filename.
 *------------------------------------------*/
void status_load_scdata(const char* filename)
{
	FILE *fp;
	int sd_count=0, sc_count=0;
	char line[8192];
	struct scdata *sc;

	if ((fp = fopen(filename, "r")) == NULL) {
		ShowError("status_load_scdata: Cannot open file %s!\n", filename);
		return;
	}

	while(fgets(line, sizeof(line), fp))
	{
		sc = (struct scdata*)aCalloc(1, sizeof(struct scdata));
		if (inter_scdata_fromstr(line, sc)) {
			sd_count++;
			sc_count+= sc->count;
			sc = idb_put(scdata_db, sc->char_id, sc);
			if (sc) {
				ShowError("Duplicate entry in %s for character %d\n", filename, sc->char_id);
				if (sc->data) aFree(sc->data);
				aFree(sc);
			}
		} else {
			ShowError("status_load_scdata: Broken line data: %s\n", line);
			aFree(sc);
		}
	}
	fclose(fp);
	ShowStatus("Loaded %d saved status changes for %d characters.\n", sc_count, sd_count);
}
Example #20
0
/// public constructor
AccountDB* account_db_sql(void) {
	AccountDB_SQL* db = (AccountDB_SQL*)aCalloc(1, sizeof(AccountDB_SQL));

	// set up the vtable
	db->vtable.init         = &account_db_sql_init;
	db->vtable.destroy      = &account_db_sql_destroy;
	db->vtable.get_property = &account_db_sql_get_property;
	db->vtable.set_property = &account_db_sql_set_property;
	db->vtable.save         = &account_db_sql_save;
	db->vtable.create       = &account_db_sql_create;
	db->vtable.remove       = &account_db_sql_remove;
	db->vtable.load_num     = &account_db_sql_load_num;
	db->vtable.load_str     = &account_db_sql_load_str;
	db->vtable.iterator     = &account_db_sql_iterator;

	// initialize to default values
	db->accounts = NULL;
	// local sql settings
	safestrncpy(db->db_hostname, "127.0.0.1", sizeof(db->db_hostname));
	db->db_port = 3306;
	safestrncpy(db->db_username, "ragnarok", sizeof(db->db_username));
	safestrncpy(db->db_password, "ragnarok", sizeof(db->db_password));
	safestrncpy(db->db_database, "ragnarok", sizeof(db->db_database));
	safestrncpy(db->codepage, "", sizeof(db->codepage));
	// other settings
	db->case_sensitive = false;
	safestrncpy(db->account_db, "login", sizeof(db->account_db));
	safestrncpy(db->accreg_db, "global_reg_value", sizeof(db->accreg_db));

	return &db->vtable;
}
Example #21
0
// 作成可否
int party_created(int account_id,int fail,int party_id,char *name)
{
	struct map_session_data *sd;
	sd=map_id2sd(account_id);

	nullpo_retr(0, sd);
	
	if(fail==0){
		struct party *p;
		sd->status.party_id=party_id;
		if((p=(struct party *) numdb_search(party_db,party_id))!=NULL){
			ShowFatalError("party: id already exists!\n");
			exit(1);
		}
		p=(struct party *)aCalloc(1,sizeof(struct party));
		p->party_id=party_id;
		memcpy(p->name, name, NAME_LENGTH-1);
		numdb_insert(party_db,party_id,p);
		clif_party_created(sd,0);
		clif_charnameupdate(sd); //Update other people's display. [Skotlex]
	}else{
		clif_party_created(sd,1);
	}
	return 0;
}
Example #22
0
static void* create_scdata(DBKey key, va_list args) {
	struct scdata *data;
	data = aCalloc(1, sizeof(struct scdata));
	data->account_id = va_arg(args, int);
	data->char_id = key.i;
	return data;
}
Example #23
0
/**
 * create a new pattern entry
 */
static struct pcrematch_entry* create_pcrematch_entry(struct pcrematch_set* set)
{
	struct pcrematch_entry * e =  (struct pcrematch_entry *) aCalloc(sizeof(struct pcrematch_entry), 1);
	struct pcrematch_entry * last = set->head;

	// Normally we would have just stuck it at the end of the list but
	// this doesn't sink up with peoples usage pattern.  They wanted
	// the items defined first to have a higher priority then the
	// items defined later. as a result, we have to do some work up front.

	/*  if we are the first pattern, stick us at the end */
	if (last == NULL) {
		set->head = e;
		return e;
	}

	/* Look for the last entry */
	while (last->next != NULL)
		last = last->next;

	last->next = e;
	e->next = NULL;

	return e;
}
Example #24
0
// アカウント変数の読み込み
int inter_accreg_init(void) {
	char line[8192];
	FILE *fp;
	int c = 0;
	struct accreg *reg;

	accreg_db = idb_alloc(DB_OPT_RELEASE_DATA);

	if( (fp = fopen(accreg_txt, "r")) == NULL)
		return 1;
	while(fgets(line, sizeof(line), fp))
	{
		reg = (struct accreg*)aCalloc(sizeof(struct accreg), 1);
		if (reg == NULL) {
			ShowFatalError("inter: accreg: out of memory!\n");
			exit(EXIT_FAILURE);
		}
		if (inter_accreg_fromstr(line, reg) == 0 && reg->account_id > 0) {
			idb_put(accreg_db, reg->account_id, reg);
		} else {
			ShowError("inter: accreg: broken data [%s] line %d\n", accreg_txt, c);
			aFree(reg);
		}
		c++;
	}
	fclose(fp);

	return 0;
}
Example #25
0
/**
 * Received mercenary data from char-serv
 * @param merc : mercenary datas
 * @param flag : if inter-serv request was sucessfull
 * @return false:failure, true:sucess
 */
bool mercenary_recv_data(struct s_mercenary *merc, bool flag)
{
	struct map_session_data *sd;
	struct mercenary_data *md;
	struct s_mercenary_db *db;
	int i = mercenary_search_index(merc->class_);

	if( (sd = map_charid2sd(merc->char_id)) == NULL )
		return false;
	if( !flag || i < 0 ) { // Not created - loaded - DB info
		sd->status.mer_id = 0;
		return false;
	}

	db = &mercenary_db[i];
	if( !sd->md ) {
		sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data));
		md->bl.type = BL_MER;
		md->bl.id = npc_get_new_npc_id();
		md->devotion_flag = 0;

		md->master = sd;
		md->db = db;
		memcpy(&md->mercenary, merc, sizeof(struct s_mercenary));
		status_set_viewdata(&md->bl, md->mercenary.class_);
		status_change_init(&md->bl);
		unit_dataset(&md->bl);
		md->ud.dir = sd->ud.dir;

		md->bl.m = sd->bl.m;
		md->bl.x = sd->bl.x;
		md->bl.y = sd->bl.y;
		unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
		md->bl.x = md->ud.to_x;
		md->bl.y = md->ud.to_y;

		map_addiddb(&md->bl);
		status_calc_mercenary(md, SCO_FIRST);
		md->contract_timer = INVALID_TIMER;
		md->masterteleport_timer = INVALID_TIMER;
		merc_contract_init(md);
	} else {
		memcpy(&sd->md->mercenary, merc, sizeof(struct s_mercenary));
		md = sd->md;
	}

	if( sd->status.mer_id == 0 )
		mercenary_set_calls(md, 1);
	sd->status.mer_id = merc->mercenary_id;

	if( md && md->bl.prev == NULL && sd->bl.prev != NULL ) {
		if(map_addblock(&md->bl))
			return false;
		clif_spawn(&md->bl);
		clif_mercenary_info(sd);
		clif_mercenary_skillblock(sd);
	}

	return true;
}
Example #26
0
static void* create_item_data(DBKey key, va_list args) {
	struct item_data *id;
	id=(struct item_data *)aCalloc(1,sizeof(struct item_data));
	id->nameid = key.i;
	id->weight=1;
	id->type=IT_ETC;
	return id;
}
Example #27
0
// Create Party
int mapif_parse_CreateParty (int fd, char *name, int item, int item2, struct party_member *leader)
{
	struct party_data *p;
	int i;

	if ( (p = search_partyname (name)) != NULL)
	{
		mapif_party_created (fd, leader->account_id, leader->char_id, NULL);
		return 0;
	}

	// Check Authorised letters/symbols in the name of the character
	if (char_name_option == 1)   // only letters/symbols in char_name_letters are authorised
	{
		for (i = 0; i < NAME_LENGTH && name[i]; i++)
			if (strchr (char_name_letters, name[i]) == NULL)
			{
				mapif_party_created (fd, leader->account_id, leader->char_id, NULL);
				return 0;
			}
	}
	else if (char_name_option == 2)     // letters/symbols in char_name_letters are forbidden
	{
		for (i = 0; i < NAME_LENGTH && name[i]; i++)
			if (strchr (char_name_letters, name[i]) != NULL)
			{
				mapif_party_created (fd, leader->account_id, leader->char_id, NULL);
				return 0;
			}
	}

	p = (struct party_data *) aCalloc (1, sizeof (struct party_data));
	memcpy (p->party.name, name, NAME_LENGTH);
	p->party.exp = 0;
	p->party.item = (item ? 1 : 0) | (item2 ? 2 : 0);
	memcpy (&p->party.member[0], leader, sizeof (struct party_member));
	p->party.member[0].leader = 1;
	p->party.member[0].online = 1;
	p->party.party_id = -1; //New party.

	if (inter_party_tosql (&p->party, PS_CREATE | PS_ADDMEMBER, 0))
	{
		//Add party to db
		int_party_calc_state (p);
		idb_put (party_db_, p->party.party_id, p);
		mapif_party_info (fd, &p->party, 0);
		mapif_party_created (fd, leader->account_id, leader->char_id, &p->party);
	}
	else     //Failed to create party.
	{
		aFree (p);
		mapif_party_created (fd, leader->account_id, leader->char_id, NULL);
	}

	return 0;
}
Example #28
0
/**
 * Create a guild_storage stucture and add it into the db
 * @see DBCreateData
 * @param key
 * @param args
 * @return 
 */
static DBData create_guildstorage(DBKey key, va_list args)
{
	struct s_storage *gs = NULL;

	gs = (struct s_storage *) aCalloc(sizeof(struct s_storage), 1);
	gs->type = TABLE_GUILD_STORAGE;
	gs->id = key.i;

	return db_ptr2data(gs);
}
Example #29
0
int mapif_account_reg(int fd,unsigned char *src)
{
//	unsigned char buf[WBUFW(src,2)]; <- Hey, can this really be done? [Skotlex]
	unsigned char *buf = aCalloc(1,WBUFW(src,2)); // [Lance] - Skot... Dynamic allocation is better :D
	memcpy(WBUFP(buf,0),src,WBUFW(src,2));
	WBUFW(buf, 0)=0x3804;
	mapif_sendallwos(fd, buf, WBUFW(buf,2));
	aFree(buf);
	return 0;
}
Example #30
0
/*==========================================
 * npcチャットルーム作成
 *------------------------------------------
 */
int chat_createnpcchat(
	struct npc_data *nd,int limit,int pub,int trigger,const char* title,int titlelen,const char *ev,
	int zeny,int lowlv,int highlv,unsigned int job,int upper)
{
	int change_flag = 0;
	struct chat_data *cd;

	nullpo_retr(1, nd);

	// 既にチャットを持っているなら状態変更するだけ
	if( nd->chat_id && (cd = map_id2cd(nd->chat_id)) ) {
		change_flag = 1;
		memset(cd->npc_event, 0, sizeof(cd->npc_event));
	} else {
		cd = (struct chat_data *)aCalloc(1,sizeof(struct chat_data));
		cd->pass[0] = 0;
		cd->users   = 0;
		cd->bl.type = BL_CHAT;
		cd->owner_  = &nd->bl;
		cd->owner   = &cd->owner_;
		cd->bl.id   = map_addobject(&cd->bl);
		if(cd->bl.id == 0) {
			aFree(cd);
			return 0;
		}
		nd->chat_id = cd->bl.id;
	}

	cd->limit   = (unsigned char)limit;
	cd->trigger = (trigger > 0)? trigger: limit;
	cd->pub     = pub;

	if(titlelen >= (int)(sizeof(cd->title) - 1)) {
		titlelen = (int)(sizeof(cd->title) - 1);
	}
	memcpy(cd->title,title,titlelen);
	cd->title[titlelen] = 0;

	cd->bl.m   = nd->bl.m;
	cd->bl.x   = nd->bl.x;
	cd->bl.y   = nd->bl.y;
	cd->zeny   = zeny;
	cd->lowlv  = lowlv;
	cd->highlv = highlv;
	cd->job    = job;
	cd->upper  = upper;
	memcpy(cd->npc_event,ev,sizeof(cd->npc_event));
	cd->npc_event[sizeof(cd->npc_event)-1] = '\0';

	if(change_flag)
		clif_changechatstatus(cd);
	clif_dispchat(cd,-1);

	return 0;
}