예제 #1
0
파일: chrif.c 프로젝트: malufett/Hercules
//Moves the sd character to the auth_db structure.
static bool chrif_sd_to_auth(TBL_PC* sd, enum sd_state state) {
	struct auth_node *node;
	
	if ( chrif_search(sd->status.account_id) )
		return false; //Already exists?

	node = ers_alloc(auth_db_ers, struct auth_node);
	
	memset(node, 0, sizeof(struct auth_node));
	
	node->account_id = sd->status.account_id;
	node->char_id = sd->status.char_id;
	node->login_id1 = sd->login_id1;
	node->login_id2 = sd->login_id2;
	node->sex = sd->status.sex;
	node->fd = sd->fd;
	node->sd = sd;	//Data from logged on char.
	node->node_created = gettick(); //timestamp for node timeouts
	node->state = state;

	sd->state.active = 0;
	
	idb_put(auth_db, node->account_id, node);
	
	return true;
}
예제 #2
0
/// Modifies the value of a string variable.
bool mapreg_setregstr (int uid, const char *str)
{
    int num = (uid & 0x00ffffff);
    int i   = (uid & 0xff000000) >> 24;
    const char *name = get_str (num);

    if (str == NULL || *str == 0) {
        if (name[1] != '@') {
            if (SQL_ERROR == Sql_Query (mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i))
                Sql_ShowDebug (mmysql_handle);
        }

        idb_remove (mapregstr_db, uid);
    } else {
        if (idb_put (mapregstr_db, uid, aStrdup (str)))
            mapreg_dirty = true;
        else if (name[1] != '@') { //put returned null, so we must insert.
            // Someone is causing a database size infinite increase here without name[1] != '@' [Lance]
            char tmp_str[32 * 2 + 1];
            char tmp_str2[255 * 2 + 1];
            Sql_EscapeStringLen (mmysql_handle, tmp_str, name, strnlen (name, 32));
            Sql_EscapeStringLen (mmysql_handle, tmp_str2, str, strnlen (str, 255));

            if (SQL_ERROR == Sql_Query (mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2))
                Sql_ShowDebug (mmysql_handle);
        }
    }

    return true;
}
예제 #3
0
/**
 * Player requesting to change map-serv
 * @param fd: wich fd to parse from
 * @return : 0 not enough data received, 1 success
 */
int chmapif_parse_reqchangemapserv(int fd){
	if (RFIFOREST(fd) < 39)
		return 0;
	{
		int map_id, map_fd = -1;
		struct mmo_charstatus* char_data;
		struct mmo_charstatus char_dat;
		DBMap* char_db_ = char_get_chardb();

		map_id = char_search_mapserver(RFIFOW(fd,18), ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28))); //Locate mapserver by ip and port.
		if (map_id >= 0)
			map_fd = map_server[map_id].fd;
		//Char should just had been saved before this packet, so this should be safe. [Skotlex]
		char_data = (struct mmo_charstatus*)uidb_get(char_db_,RFIFOL(fd,14));
		if (char_data == NULL) {	//Really shouldn't happen.
			char_mmo_char_fromsql(RFIFOL(fd,14), &char_dat, true);
			char_data = (struct mmo_charstatus*)uidb_get(char_db_,RFIFOL(fd,14));
		}

		if( runflag == CHARSERVER_ST_RUNNING &&
			session_isActive(map_fd) &&
			char_data )
		{	//Send the map server the auth of this player.
			struct online_char_data* data;
			struct auth_node* node;
			DBMap*  auth_db = char_get_authdb();
			DBMap* online_char_db = char_get_onlinedb();

			int aid = RFIFOL(fd,2);

			//Update the "last map" as this is where the player must be spawned on the new map server.
			char_data->last_point.map = RFIFOW(fd,18);
			char_data->last_point.x = RFIFOW(fd,20);
			char_data->last_point.y = RFIFOW(fd,22);
			char_data->sex = RFIFOB(fd,30);

			// create temporary auth entry
			CREATE(node, struct auth_node, 1);
			node->account_id = aid;
			node->char_id = RFIFOL(fd,14);
			node->login_id1 = RFIFOL(fd,6);
			node->login_id2 = RFIFOL(fd,10);
			node->sex = RFIFOB(fd,30);
			node->expiration_time = 0; // FIXME (this thing isn't really supported we could as well purge it instead of fixing)
			node->ip = ntohl(RFIFOL(fd,31));
			node->group_id = RFIFOL(fd,35);
			node->changing_mapservers = 1;
			idb_put(auth_db, aid, node);

			data = idb_ensure(online_char_db, aid, char_create_online_data);
			data->char_id = char_data->char_id;
			data->server = map_id; //Update server where char is.

			//Reply with an ack.
			chmapif_changemapserv_ack(fd,0);
		} else { //Reply with nak
			chmapif_changemapserv_ack(fd,1);
		}
		RFIFOSKIP(fd,39);
	}
예제 #4
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;
}
예제 #5
0
파일: mapreg_sql.c 프로젝트: D0ugl4s/Cronus
/// Modifies the value of an integer variable.
bool mapreg_setreg(int uid, int val) {
	struct mapreg_save *m;
	int num = (uid & 0x00ffffff);
	int i   = (uid & 0xff000000) >> 24;
	const char* name = get_str(num);

	if( val != 0 ) {
		if( (m = idb_get(mapreg_db,uid)) ) {
			m->u.i = val;
			if(name[1] != '@') {
				m->save = true;
				mapreg_i_dirty = true;
			}
		} else {
			m = ers_alloc(mapreg_ers, struct mapreg_save);

			m->u.i = val;
			m->uid = uid;
			m->save = false;

			if(name[1] != '@') {// write new variable to database
				char tmp_str[32*2+1];
				SQL->EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
				if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) )
					Sql_ShowDebug(mmysql_handle);
			}
			idb_put(mapreg_db, uid, m);
		}
	} else { // val == 0
		if( (m = idb_get(mapreg_db,uid)) ) {
예제 #6
0
/// Modifies the value of an integer variable.
bool mapreg_setreg(int uid, int val)
{
	int num = (uid & 0x00ffffff);
	int i   = (uid & 0xff000000) >> 24;
	const char* name = get_str(num);
	struct region_data* rd;

	if( !stricmp(name,"$Region") && i > 0 && i < SCRIPT_MAX_ARRAYSIZE && (rd = region_search(i)) != NULL )
		region_set_guild(i,val);

	if( val != 0 )
	{
		if( idb_put(mapreg_db,uid,(void*)(intptr_t)val) )
			mapreg_dirty = true; // already exists, delay write
		else if(name[1] != '@')
		{// write new wariable to database
			char tmp_str[32*2+1];
			Sql_EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
			if( SQL_ERROR == Sql_Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) )
				Sql_ShowDebug(mmysql_handle);
		}
	}
	else // val == 0
	{
		idb_remove(mapreg_db,uid);

		if( name[1] != '@' )
		{// Remove from database because it is unused.
			if( SQL_ERROR == Sql_Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) )
				Sql_ShowDebug(mmysql_handle);
		}
	}

	return true;
}
예제 #7
0
파일: clan.c 프로젝트: AtlantisRO/rathena
void clan_load_clandata( int count, struct clan* clans ){
	int i,j;

	nullpo_retv( clans );

	for( i = 0, j = 0; i < count; i++, clans++ ){
		struct clan* clan = clans;
		struct clan* clanCopy;

		clanCopy = (struct clan*)aMalloc( sizeof( struct clan ) );

		if( clanCopy == NULL ){
			ShowError("Memory could not be allocated for a clan.\n");
			break;
		}

		memcpy( clanCopy, clan, sizeof( struct clan ) );
		memset( clanCopy->members, 0, sizeof( clanCopy->members ) );

		idb_put( clan_db, clanCopy->id, clanCopy );
		j++;
	}

	ShowStatus( "Received '"CL_WHITE"%d"CL_RESET"' clans from char-server.\n", j );
}
예제 #8
0
파일: chat.c 프로젝트: c0nflicts/rathena
/**
 * Kick a member from a chat room.
 * @param sd : player requesting
 * @param kickusername : player name to be kicked
 * @retur 1:success, 0:failure
 */
int chat_kickchat(struct map_session_data* sd, const char* kickusername)
{
	struct chat_data* cd;
	int i;

	nullpo_retr(1, sd);

	cd = (struct chat_data *)map_id2bl(sd->chatID);

	if( cd == NULL || (struct block_list *)sd != cd->owner )
		return -1;

	ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
	if( i == cd->users )
		return -1;

	if (pc_has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
		return 0; //gm kick protection [Valaris]

	idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1);

	chat_leavechat(cd->usersd[i],1);

	return 0;
}
예제 #9
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;
}
예제 #10
0
파일: party.c 프로젝트: JulioCF/cronus-txt
void party_booking_register(struct map_session_data *sd, short level, short mapid, short* job)
{
    struct party_booking_ad_info *pb_ad;
    int i;

    pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, sd->status.char_id);

    if( pb_ad == NULL )
    {
        pb_ad = create_party_booking_data();
        idb_put(party_booking_db, sd->status.char_id, pb_ad);
    }
    else
    {   // already registered
        clif_PartyBookingRegisterAck(sd, 2);
        return;
    }

    memcpy(pb_ad->charname,sd->status.name,NAME_LENGTH);
    pb_ad->starttime = (int)time(NULL);
    pb_ad->p_detail.level = level;
    pb_ad->p_detail.mapid = mapid;

    for(i=0; i<PARTY_BOOKING_JOBS; i++)
        if(job[i] != 0xFF)
            pb_ad->p_detail.job[i] = job[i];
        else pb_ad->p_detail.job[i] = -1;

    clif_PartyBookingRegisterAck(sd, 0);
    clif_PartyBookingInsertNotify(sd, pb_ad); // Notice
}
예제 #11
0
파일: channel.c 프로젝트: xdgimf/Renewal
/**
 * Bans a character from the given channel.
 *
 * @param chan The channel.
 * @param ssd  The source character, if any.
 * @param tsd  The target character.
 * @retval HCS_STATUS_OK if the operation succeeded.
 * @retval HCS_STATUS_ALREADY if the target character is already banned.
 * @retval HCS_STATUS_NOPERM if the source character doesn't have enough permissions.
 * @retval HCS_STATUS_FAIL in case of generic failure.
 */
enum channel_operation_status channel_ban(struct channel_data *chan, const struct map_session_data *ssd, struct map_session_data *tsd)
{
	struct channel_ban_entry *entry = NULL;

	nullpo_retr(HCS_STATUS_FAIL, chan);
	nullpo_retr(HCS_STATUS_FAIL, tsd);

	if (ssd && chan->owner != ssd->status.char_id && !pc_has_permission(ssd, PC_PERM_HCHSYS_ADMIN))
		return HCS_STATUS_NOPERM;

	if (pc_has_permission(tsd, PC_PERM_HCHSYS_ADMIN))
		return HCS_STATUS_FAIL;

	if (chan->banned && idb_exists(chan->banned, tsd->status.account_id))
		return HCS_STATUS_ALREADY;

	if (!chan->banned)
		chan->banned = idb_alloc(DB_OPT_BASE|DB_OPT_ALLOW_NULL_DATA|DB_OPT_RELEASE_DATA);

	CREATE(entry, struct channel_ban_entry, 1);
	safestrncpy(entry->name, tsd->status.name, NAME_LENGTH);
	idb_put(chan->banned, tsd->status.account_id, entry);

	channel->leave(chan, tsd);

	return HCS_STATUS_OK;
}
예제 #12
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 = (struct scdata*)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);
}
예제 #13
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;
}
예제 #14
0
파일: party.c 프로젝트: Chocolate31/eamod
void party_booking_register(struct map_session_data *sd, short level, short mapid, short* job)
{
	struct party_booking_ad_info *pb_ad;
	struct party_data *p=party_search(sd->status.party_id);
	int i;

	if (!check_party_leader(sd, p)) {
		clif_PartyBookingRegisterAck(sd, 1);
		return;
	}
	
	pb_ad = (struct party_booking_ad_info*)idb_get(party_booking_db, p->party.party_id);

	if( pb_ad == NULL )
	{
		pb_ad = create_party_booking_data(p->party.party_id);
		idb_put(party_booking_db, pb_ad->index, pb_ad);
	}
	
	memcpy(pb_ad->charname,sd->status.name,NAME_LENGTH);
	pb_ad->starttime = (int)time(NULL);
	pb_ad->p_detail.level = level;
	pb_ad->p_detail.mapid = mapid;

	for(i=0;i<6;i++)
		if(job[i] != 0xFF)
			pb_ad->p_detail.job[i] = job[i];
		else pb_ad->p_detail.job[i] = -1;

	clif_PartyBookingRegisterAck(sd, 0);
	clif_PartyBookingInsertNotify(sd, pb_ad); // Notice
	clif_PartyBookingSearchAck(sd->fd, &pb_ad->index, 1, false); // Update Client!
	return;
}
예제 #15
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;
}
예제 #16
0
int bg_create(unsigned short mapindex, short rx, short ry, int guild_index, const char *ev, const char *dev)
{
	struct battleground_data *bg;
	int i;
	if( ++bg_team_counter <= 0 ) bg_team_counter = 1;

	CREATE(bg, struct battleground_data, 1);
	bg->bg_id = bg_team_counter;
	bg->creation_tick = 0;
	bg->count = 0;
	bg->g = &bg_guild[guild_index];
	bg->mapindex = mapindex;
	bg->x = rx;
	bg->y = ry;
	safestrncpy(bg->logout_event, ev, sizeof(bg->logout_event));
	safestrncpy(bg->die_event, dev, sizeof(bg->die_event));
	for( i = 0; i < MAX_GUILDSKILL; i++ )
		bg->skill_block_timer[i] = INVALID_TIMER;

	memset(&bg->members, 0, sizeof(bg->members));
	bg->color = bg_colors[guild_index];
	bg->pf_id = 0;

	idb_put(bg_team_db, bg_team_counter, bg);

	return bg->bg_id;
}
예제 #17
0
unsigned int auction_create(struct auction_data *auction)
{
	int j;
	StringBuf buf;
	SqlStmt* stmt;

	if( !auction )
		return false;

	auction->timestamp = time(NULL) + (auction->hours * 3600);

	StringBuf_Init(&buf);
	StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`unique_id`", auction_db);
	for( j = 0; j < MAX_SLOTS; j++ )
		StringBuf_Printf(&buf, ",`card%d`", j);
	StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'",
		auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.unique_id);
	for( j = 0; j < MAX_SLOTS; j++ )
		StringBuf_Printf(&buf, ",'%d'", auction->item.card[j]);
	StringBuf_AppendStr(&buf, ")");

	//Unique Non Stackable Item ID
	updateLastUid(auction->item.unique_id);
	dbUpdateUid(sql_handle);

	stmt = SqlStmt_Malloc(sql_handle);
	if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
	||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
	||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 1, SQLDT_STRING, auction->buyer_name, strnlen(auction->buyer_name, NAME_LENGTH))
	||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 2, SQLDT_STRING, auction->item_name, strnlen(auction->item_name, ITEM_NAME_LENGTH))
	||  SQL_SUCCESS != SqlStmt_Execute(stmt) )
	{
		SqlStmt_ShowDebug(stmt);
		auction->auction_id = 0;
	}
	else
	{
		struct auction_data *auction_;
		unsigned int tick = auction->hours * 3600000;

		auction->item.amount = 1;
		auction->item.identify = 1;
		auction->item.expire_time = 0;

		auction->auction_id = (unsigned int)SqlStmt_LastInsertId(stmt);
		auction->auction_end_timer = add_timer( gettick() + tick , auction_end_timer, auction->auction_id, 0);
		ShowInfo("New Auction %u | time left %u ms | By %s.\n", auction->auction_id, tick, auction->seller_name);

		CREATE(auction_, struct auction_data, 1);
		memcpy(auction_, auction, sizeof(struct auction_data));
		idb_put(auction_db_, auction_->auction_id, auction_);
	}

	SqlStmt_Free(stmt);
	StringBuf_Destroy(&buf);

	return auction->auction_id;
}
예제 #18
0
/// Loads permanent variables from database
static void script_load_mapreg(void)
{
	/*
	        0        1       2
	   +-------------------------+
	   | varname | index | value |
	   +-------------------------+
	                                */
	SqlStmt* stmt = SqlStmt_Malloc(mmysql_handle);
	char varname[32+1];
	int index;
	char value[255+1];
	uint32 length;

	if ( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg_table)
	  || SQL_ERROR == SqlStmt_Execute(stmt)
	  ) {
		SqlStmt_ShowDebug(stmt);
		SqlStmt_Free(stmt);
		return;
	}

	SqlStmt_BindColumn(stmt, 0, SQLDT_STRING, &varname[0], sizeof(varname), &length, NULL);
	SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &index, 0, NULL, NULL);
	SqlStmt_BindColumn(stmt, 2, SQLDT_STRING, &value[0], sizeof(value), NULL, NULL);
	
	while ( SQL_SUCCESS == SqlStmt_NextRow(stmt) )
	{
		int s = add_str(varname);
		int i = index;

		if( varname[length-1] == '$' )
			idb_put(mapregstr_db, (i<<24)|s, aStrdup(value));
		else
		{
			idb_put(mapreg_db, (i<<24)|s, (void *)atoi(value));
			if( !strcmp(varname, "$Region") && i > 0 && i < MAX_REGIONS )
				region[i].guild_id = atoi(value); // Regional Control
		}
	}
	
	SqlStmt_Free(stmt);

	mapreg_dirty = false;
}
예제 #19
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;
}
예제 #20
0
파일: mapreg_txt.c 프로젝트: Drakkus/eamod
/// Modifies the value of an integer variable.
bool mapreg_setreg(int uid, int val)
{
	if( val != 0 )
		idb_put(mapreg_db,uid,(void*)val);
	else
		idb_remove(mapreg_db,uid);

	mapreg_dirty = true;
	return true;
}
예제 #21
0
파일: mapreg_txt.c 프로젝트: Drakkus/eamod
/// Modifies the value of a string variable.
bool mapreg_setregstr(int uid, const char* str)
{
	if( str == NULL || *str == 0 )
		idb_remove(mapregstr_db,uid);
	else
		idb_put(mapregstr_db,uid,aStrdup(str));

	mapreg_dirty = true;
	return true;
}
예제 #22
0
// パ?ティ
int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct party_member *leader)
{
	struct party_data *p;
	int i;

	//FIXME: this should be removed once the savefiles can handle all symbols
	for(i = 0; i < NAME_LENGTH && name[i]; i++) {
		if (!(name[i] & 0xe0) || name[i] == 0x7f) {
			ShowInfo("int_party: illegal party name [%s]\n", name);
			mapif_party_created(fd, leader->account_id, leader->char_id, NULL);
			return 0;
		}
	}

	if ((p = search_partyname(name)) != NULL) {
		ShowInfo("int_party: same name party exists [%s]\n", name);
		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(sizeof(struct party_data), 1);
	if (p == NULL) {
		ShowFatalError("int_party: out of memory !\n");
		mapif_party_created(fd,leader->account_id,leader->char_id,NULL);
		return 0;
	}
	p->party.party_id = party_newid++;
	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;
	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);

	return 0;
}
예제 #23
0
파일: channel.c 프로젝트: Chocolate31/eamod
bool channel_create(struct map_session_data *sd, const char* name, const char* pass, short type, short color, int op)
{
	struct channel_data *cd;
	int i = 0;

	if( !name || strlen(name) < 2 || strlen(name) >= NAME_LENGTH || name[0] != '#' )
	{
		if( sd ) clif_displaymessage(sd->fd, msg_txt(801));
		return false;
	}
	if( type == CHN_USER && !sd )
		return false; // Operator required for user channels
	if( sd && type == CHN_USER && (i = channel_slot_free(sd)) < 0 )
	{
		clif_displaymessage(sd->fd, msg_txt(800));
		return false;
	}
	if( (cd = (struct channel_data *)strdb_get(channel_db, name)) != NULL )
	{
		if( sd ) clif_displaymessage(sd->fd, msg_txt(802));
		return false; // Already exists
	}

	CREATE(cd, struct channel_data, 1);
	cd->channel_id = ++channel_counter;
	safestrncpy(cd->name, name, sizeof(cd->name));
	safestrncpy(cd->pass, pass, sizeof(cd->pass));
	cd->type = type;
	cd->color = channel_color[cap_value(color,0,38)];
	cd->users = 0;
	cd->op = 0;
	cd->users_db = idb_alloc(DB_OPT_BASE);

	if( type == CHN_USER )
	{
		char output[128];
		sprintf(output, msg_txt(803), cd->name, sd->status.name);
		
		sd->cd[i] = cd;
		cd->op = sd->bl.id;
		idb_put(cd->users_db, sd->bl.id, sd);
		cd->users++;
		clif_channel_message(cd, output, -1);
	}
	else if( type < CHN_USER )
	{
		server_channel[type] = cd; // Quick access to main channels
		ShowInfo("Channel System : New channel %s created.\n", cd->name);
	}
	else
		cd->op = op; // Server Channel

	strdb_put(channel_db, cd->name, cd);
	return true;
}
예제 #24
0
/**
 * Player Requesting char-select from map_serv
 * @param fd: wich fd to parse from
 * @return : 0 not enough data received, 1 success
 */
int chmapif_parse_authok(int fd){
	if( RFIFOREST(fd) < 19 )
		return 0;
	else{
		uint32 account_id = RFIFOL(fd,2);
		uint32 login_id1 = RFIFOL(fd,6);
		uint32 login_id2 = RFIFOL(fd,10);
		uint32 ip = RFIFOL(fd,14);
		int version = RFIFOB(fd,18);
		RFIFOSKIP(fd,19);

		if( runflag != CHARSERVER_ST_RUNNING ){
			WFIFOHEAD(fd,7);
			WFIFOW(fd,0) = 0x2b03;
			WFIFOL(fd,2) = account_id;
			WFIFOB(fd,6) = 0;// not ok
			WFIFOSET(fd,7);
		}else{
			struct auth_node* node;
			DBMap*  auth_db = char_get_authdb();
			DBMap* online_char_db = char_get_onlinedb();

			// create temporary auth entry
			CREATE(node, struct auth_node, 1);
			node->account_id = account_id;
			node->char_id = 0;
			node->login_id1 = login_id1;
			node->login_id2 = login_id2;
			//node->sex = 0;
			node->ip = ntohl(ip);
			node->version = version; //upd version for mapserv
			//node->expiration_time = 0; // unlimited/unknown time by default (not display in map-server)
			//node->gmlevel = 0;
			idb_put(auth_db, account_id, node);

			//Set char to "@ char select" in online db [Kevin]
			char_set_charselect(account_id);
			{
				struct online_char_data* character = (struct online_char_data*)idb_get(online_char_db, account_id);
				if( character != NULL ){
					character->pincode_success = true;
				}
			}

			WFIFOHEAD(fd,7);
			WFIFOW(fd,0) = 0x2b03;
			WFIFOL(fd,2) = account_id;
			WFIFOB(fd,6) = 1;// ok
			WFIFOSET(fd,7);
		}
	}
	return 1;
}
예제 #25
0
/*==========================================
 * Loads (and creates if not found) an item from the db.
 *------------------------------------------
 */
struct item_data* itemdb_load(int nameid)
{
	struct item_data *id = idb_ensure(item_db,nameid,create_item_data);
	if (id == &dummy_item)
  	{	//Remove dummy_item, replace by real data.
		DBKey key;
		key.i = nameid;
		idb_remove(item_db,nameid);
		id = create_item_data(key, NULL);
		idb_put(item_db,nameid,id);
	}
	return id;
}
예제 #26
0
파일: guild.c 프로젝트: casioza/server000
// ギルド城情報所得時イベント追加
int guild_addcastleinfoevent(int castle_id,int index,const char *name)
{
	struct eventlist *ev;
	int code=castle_id|(index<<16);

	if( name==NULL || *name==0 )
		return 0;

	ev = (struct eventlist *)aMalloc(sizeof(struct eventlist));
	strncpy(ev->name,name,ARRAYLENGTH(ev->name));
	//The next event becomes whatever was currently stored.
	ev->next = (struct eventlist *)idb_put(guild_castleinfoevent_db,code,ev);
	return 0;
}
예제 #27
0
파일: mapreg_txt.c 프로젝트: Drakkus/eamod
/// Loads permanent variables from savefile
static void script_load_mapreg(void)
{
	FILE* fp;
	char line[1024];

	fp = fopen(mapreg_txt,"rt");
	if( fp == NULL )
		return;

	while( fgets(line,sizeof(line),fp) )
	{
		char varname[32+1];
		char value[255+1];
		int n,s,i;

		// read name and index
		if( sscanf(line, "%32[^,],%d\t%n", varname,&i,&n) != 2 &&
			(i = 0, sscanf(line,"%[^\t]\t%n", varname,&n) != 1) )
			continue;

		// read value
		if( sscanf(line + n, "%[^\n\r]", value) != 1 )
		{
			ShowError("%s: %s broken data !\n", mapreg_txt, varname);
			continue;
		}

		s = add_str(varname);
		if( varname[strlen(varname)-1] == '$' )
			idb_put(mapregstr_db, (i<<24)|s, aStrdup(value));
		else
			idb_put(mapreg_db, (i<<24)|s, (void*)atoi(value));
	}
	fclose(fp);

	mapreg_dirty = false;
}
예제 #28
0
파일: guild.c 프로젝트: casioza/server000
static bool guild_read_castledb(char* str[], int columns, int current)
{// <castle id>,<map name>,<castle name>,<castle event>[,<reserved/unused switch flag>]
	struct guild_castle *gc;

	CREATE(gc, struct guild_castle, 1);
	gc->castle_id = atoi(str[0]);
	gc->mapindex = mapindex_name2id(str[1]);
	safestrncpy(gc->castle_name, str[2], sizeof(gc->castle_name));
	safestrncpy(gc->castle_event, str[3], sizeof(gc->castle_event));

	idb_put(castle_db,gc->castle_id,gc);

	//intif_guild_castle_info(gc->castle_id);

	return true;
}
예제 #29
0
int mapif_create_homun(int fd)
{
	struct s_homunculus *p;
	p= (struct s_homunculus *) aCalloc(sizeof(struct s_homunculus), 1);
	if(p==NULL){
		ShowFatalError("int_homun: out of memory !\n");
		//Sending the received data will pass hom_id == 0 <- fail.
		mapif_homun_created(fd,RFIFOL(fd,4),(struct s_homunculus*)RFIFOP(fd,8));
		return 0;
	}
	memcpy(p, RFIFOP(fd,8), sizeof(struct s_homunculus));
	p->hom_id = homun_newid++; //New ID
	idb_put(homun_db,p->hom_id,p);
	mapif_homun_created(fd,RFIFOL(fd,4),p);
	return 0;
}
예제 #30
0
파일: guild.c 프로젝트: monimonih/eathena
static int guild_read_castledb(void)
{
	FILE *fp;
	char line[1024];
	int j,ln=0;
	char *str[32],*p;
	struct guild_castle *gc;

	sprintf(line, "%s/castle_db.txt", db_path);
	if( (fp=fopen(line,"r"))==NULL){
		ShowError("can't read %s\n", line);
		return -1;
	}

	while(fgets(line, sizeof(line), fp))
	{
		if(line[0]=='/' && line[1]=='/')
			continue;
		memset(str,0,sizeof(str));
		for(j=0,p=line;j<6 && p;j++){
			str[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if (j < 4) //Insufficient data for castle. [Skotlex]
		{
			ShowError("castle_db.txt: invalid line '%s'\n", line);
			continue;
		}

		gc=(struct guild_castle *)aCalloc(1,sizeof(struct guild_castle));
		gc->castle_id=atoi(str[0]);
		gc->mapindex = mapindex_name2id(str[1]);
		safestrncpy(gc->castle_name,str[2],NAME_LENGTH);
		safestrncpy(gc->castle_event,str[3],NAME_LENGTH);

		idb_put(castle_db,gc->castle_id,gc);

		//intif_guild_castle_info(gc->castle_id);

		ln++;
	}
	fclose(fp);
	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"castle_db.txt");
	return 0;
}