Пример #1
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_iput(mapreg_db,uid,val) )
			mapreg_dirty = true; // already exists, delay write
		else 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);
		}
	}
	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;
}
Пример #2
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_iput(mapreg_db, (i<<24)|s, atoi(value));
	}
	
	SqlStmt_Free(stmt);

	mapreg_dirty = false;
}
Пример #3
0
/*==========================================
 * Kick an user from a chatroom
 * Return:
 *  0: User cannot be kicked (is gm)/Missing data
 *  1: Success
 *------------------------------------------*/
bool chat_kickchat(struct map_session_data* sd, const char* kickusername) {
    struct chat_data* cd;
    int i;

    nullpo_ret(sd);

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

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

    ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
    if( i == cd->users ) // User not found
        return false;

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

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

    chat->leave(cd->usersd[i], true);
    return true;
}