cfgfile.em

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 095. Note: Core 095 is no longer officially supported.
Post Reply
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

cfgfile.em

Post by DevGIB »

i have the following in a cfg file that i want to read and check if the key exists and then returns a value

this is my cfg file

Code: Select all

Lists badwords
{
fuck
shit
arse
}
this is my script

Code: Select all

function checkname(name)

var hisname := lower(name);
var cfg := ReadConfigFile("::badnames");
var wordelem := FindConfigElem(cfg, "badwords");
var nameelem := FindConfigElem(cfg, "badnames");

foreach word in SplitWords(hisname)
var chk := GetConfigString( wordelem, word );
if (chk)
        return 0;
endif
endforeach

var nmchk := GetConfigString( nameelem, hisname );

if (!nmchk)
   return 1;
else
   return 0;
endif


endfunction
i cant seem to get it to work but :(
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

You have this line:
var nameelem := FindConfigElem(cfg, "badnames");
but where is the element "badnames"?

Also in the 'for' loop you are parsing through the multiple words in hisname but it doesn't appear that you are parsing through each word entry for wordelem.
DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Post by DevGIB »

next question is there a way to check if a string has number or non alpha numerics in it?
blah
New User
Posts: 12
Joined: Thu Feb 02, 2006 12:05 pm

Post by blah »

maby

Code: Select all

Lists badwords
{
    word fuck
    word shit
    word arse
}
and

Code: Select all


    GetConfigStringArray( element, property_name ) 

* Explanation :
For elements with multiple occurrences of a given property, returns an array containing each occurrence. 
For example, to get all the ingredients in the following element:  

Dessert applepie
{
    Cost 8
    Calories 1004
    MadeLike   grandma
    Ingredient flour
    Ingredient butter
    Ingredient apples
    Deliciousness 3.6
}

Use: 'var ingredients := GetConfigStringArray(element,"Ingredient");'
'ingredients' now contains 'flour', 'butter', and 'apples'.
 
Value of the properties are always returned as strings. If the values are ints or reals, use CInt() or CDbl() to cast the values to the correct type. 
 * Return values 
        An array of strings. 
 * Errors 
        "Invalid parameter type" 

DevGIB
Grandmaster Poster
Posts: 248
Joined: Mon Feb 06, 2006 6:12 am

Post by DevGIB »

i want it so if someone puts in Dev Gib is ok but if they put in Dev_Gib or devgib1 or 1234 they are all illegal
Bytehawk
Apprentice Poster
Posts: 56
Joined: Fri Feb 03, 2006 2:25 am

Post by Bytehawk »

This should do the job, tho there are ways to do it less complicated :)

Code: Select all

use uo;

program dummyprog(who)

  // Let the user enter a text
  var answer:= RequestInput (who, who.backpack, "Your answer?");

  // He entered nothing or the first char was a number
  if (!answer || (CInt (answer) > 0))
    SendSysMessage (who, "Cancelled");
    return 0;
  endif

  // Call the function to check the string
  if (check_string(answer))
    SendSysMessage (who, "String doesn't contain any invalid characters");
  else
    SendSysMessage (who, "String DOES contain invalid characters");
  endif

endprogram



/* checks <mystring> for invalid characters
 *
 * returns 1 if <mystring> contains no invalid characters
 *         0 if <mystring> has invalid characters 
*/
function check_string(mystring)

  // These are the unwanted characters
  var forbidden:= array {"_", "@", "-",
                         "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
  var i:= 0;

  // Check each single character of the string if it is contained in the array
  // of forbidden characters
  for (i:= 1; i <= len (mystring); i:= i + 1)
    if (mystring[i] in forbidden)
      return 0;
    endif
  endfor

  return 1;

endfunction
Post Reply