nevite nekdo prosim jak v tomhle kodu zaridit aby to nerozlisovalo bitch a Bitch a biTch... ale aby to porste nekoukalo na velikost pismen? proste nekdo vleze do chatu a posle zpravu (szString) a ono to checkne jestli tam je neco z tech slov a pokud ano vrati to jenom LTFALSE a tu zpravu to skartuje, ale ted mi to funguje PRESNE a JEN na ty slova tak jak jsou napsany v kodu s malyma pismenama :( a vypisovat vsechny moznosti kombinace by bya prace na tydny :(
diky
if(m_bSwearningFilter==LTTRUE)
{
const char *nastywords[] = { "bitch", "arse", "queer", "cunt", "scruber", "fuck", "whore", "slag", "slut", "shit", "bastard", "asshole", "shithole", NULL };
uint32 i = 0;
while (nastywords[i] != NULL)
{
if (strstr(szString, nastywords[i]))
{
return LTFALSE;
}
i++;
}
}
Fórum › C / C++
UNcase sensitive strstr

vsetky slova preved na velke, aj tie ktore mas v tom poli, a aj tie ktore si nacital od uzivatela. a potom uz len porovnaj.
pripadne aj naopak - slvoa nacitane zo vstupu od uzivatela preved na male a porovnaj.
cize napr. uzivatel zada slovo ShiT, prevedies to na SHIT a porovnas :)
To p3cq56: pouzi funkciu strToLower alebo strToUpper
tak jsem to nakonec vyresil funkci:
char * StringToUpperCase(char * zeile)
{
char * temp;
int i;
int p = strlen(zeile);
temp = (char *) malloc(p);
for (i=0; zeile[i]!=0 && i<256; i++)
if (zeile[i]>='a' && zeile[i]<='z')
temp[i]=(char) zeile[i]-32; else temp[i]=zeile[i];
temp[i]=0;
return temp;
}
a volanim:
if(m_bSwearningFilter==LTTRUE)
{
const char *nastywords[] = { "BITCH", "ARSE", "QUEER", "CUNT", "SCRUBER", "FUCK", "WHORE", "SLAG", "SLUT", "SHIT", "ASSHOLE", "SHITHOLE", NULL };
uint32 i = 0;
while (nastywords[i] != NULL)
{
if (strstr(StringToUpperCase(szString), nastywords[i]))
{
char szSwearningMsg[192];
sprintf(szSwearningMsg, "Swearning is NOT accepted on this server.");
HMESSAGEWRITE hMessage = g_pLTServer->StartMessage(m_ClientData[nIndex].m_hClient, MID_MPMGR_PRIVATE_MESSAGE);
hMessage->WriteDWord(0);
hMessage->WriteString(szSwearningMsg);
g_pLTServer->EndMessage(hMessage);
return LTFALSE;
}
i++;
}
}
diky za napad :)
mnochodem na to existuje funkce stricmp; vraci 0, pokud jsou retezce stejne

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Funkce strstr() — založil Sprinter
Moderátoři diskuze