Пример #1
0
int Q_isalphanumeric( int c ) {
	if ( Q_isalpha( c ) ||
		 Q_isnumeric( c ) ) {
		return( 1 );
	}
	return ( 0 );
}
Пример #2
0
/*
===============
Rankings_DrawName
===============
*/
void Rankings_DrawName( void* self )
{
    menufield_s		*f;
    int				length;
    char*			p;

    f = (menufield_s*)self;

    // GRANK_FIXME - enforce valid characters
    for( p = f->field.buffer; *p != '\0'; p++ )
    {
        //if( ispunct(*p) || isspace(*p) )
        if( !( ( (*p) >= '0' && (*p) <= '9') || Q_isalpha(*p)) )
        {
            *p = '\0';
        }
    }

    // strip color codes
    Q_CleanStr( f->field.buffer );
    length = strlen( f->field.buffer );
    if( f->field.cursor > length )
    {
        f->field.cursor = length;
    }

    Rankings_DrawText( f );
}
Пример #3
0
/*
==================
MenuField_Key
==================
*/
sfxHandle_t MenuField_Key( menufield_s* m, int* key )
{
	int keycode;

	keycode = *key;

	switch ( keycode )
	{
		case K_KP_ENTER:
		case K_ENTER:
		case K_JOY1:
		case K_JOY2:
		case K_JOY3:
		case K_JOY4:
		case K_2JOY1:
		case K_2JOY2:
		case K_2JOY3:
		case K_2JOY4:
		case K_3JOY1:
		case K_3JOY2:
		case K_3JOY3:
		case K_3JOY4:
		case K_4JOY1:
		case K_4JOY2:
		case K_4JOY3:
		case K_4JOY4:
			// have enter go to next cursor point
			*key = K_TAB;
			break;

		case K_TAB:
		case K_KP_DOWNARROW:
		case K_DOWNARROW:
		case K_KP_UPARROW:
		case K_UPARROW:
			break;

		default:
			if ( keycode & K_CHAR_FLAG )
			{
				keycode &= ~K_CHAR_FLAG;

				if ((m->generic.flags & QMF_UPPERCASE) && Q_islower( keycode ))
					keycode -= 'a' - 'A';
				else if ((m->generic.flags & QMF_LOWERCASE) && Q_isupper( keycode ))
					keycode -= 'A' - 'a';
				else if ((m->generic.flags & QMF_NUMBERSONLY) && Q_isalpha( keycode ))
					return (menu_buzz_sound);

				MField_CharEvent( &m->field, keycode);
			}
			else
				MField_KeyDownEvent( &m->field, keycode );
			break;
	}

	return (0);
}
Пример #4
0
/*
===============
Rankings_DrawPassword
===============
*/
void Rankings_DrawPassword( void* self )
{
    menufield_s*	f;
    char			password[MAX_EDIT_LINE];
    int				length;
    int				i;
    char*			p;

    f = (menufield_s*)self;

    // GRANK_FIXME - enforce valid characters
    for( p = f->field.buffer; *p != '\0'; p++ )
    {
        //if( ispunct(*p) || isspace(*p) )
        if( !( ( (*p) >= '0' && (*p) <= '9') || Q_isalpha(*p)) )
        {
            *p = '\0';
        }
    }

    length = strlen( f->field.buffer );
    if( f->field.cursor > length )
    {
        f->field.cursor = length;
    }

    // save password
    Q_strncpyz( password, f->field.buffer, sizeof(password) );

    // mask password with *
    for( i = 0; i < length; i++ )
    {
        f->field.buffer[i] = '*';
    }

    // draw masked password
    Rankings_DrawText( f );
    //MenuField_Draw( f );

    // restore password
    Q_strncpyz( f->field.buffer, password, sizeof(f->field.buffer) );
}
Пример #5
0
/*
====================
LAN_CompareServers
====================
*/
static int LAN_CompareServers( int source, int sortKey, int sortDir, int s1, int s2 ) {
	int res;
	serverInfo_t *server1, *server2;

	server1 = LAN_GetServerPtr(source, s1);
	server2 = LAN_GetServerPtr(source, s2);
	if (!server1 || !server2) {
		return 0;
	}

	res = 0;
	switch( sortKey ) {
		case SORT_HOST:
			{
				char	hostName1[ MAX_HOSTNAME_LENGTH ];
				char	hostName2[ MAX_HOSTNAME_LENGTH ];
				char	*p;
				int		i;

				for( p = server1->hostName, i = 0; *p != '\0'; p++ )
				{
					if( Q_isalpha( *p ) )
						hostName1[ i++ ] = *p;
				}
				hostName1[ i ] = '\0';

				for( p = server2->hostName, i = 0; *p != '\0'; p++ )
				{
					if( Q_isalpha( *p ) )
						hostName2[ i++ ] = *p;
				}
				hostName2[ i ] = '\0';

				res = Q_stricmp( hostName1, hostName2 );
			}
			break;

		case SORT_MAP:
			res = Q_stricmp( server1->mapName, server2->mapName );
			break;
		case SORT_CLIENTS:
			if (server1->clients < server2->clients) {
				res = -1;
			}
			else if (server1->clients > server2->clients) {
				res = 1;
			}
			else {
				res = 0;
			}
			break;
		case SORT_PING:
		case 4: // Hack to make 1.1 ui work
			if (server1->ping < server2->ping) {
				res = -1;
			}
			else if (server1->ping > server2->ping) {
				res = 1;
			}
			else {
				res = 0;
			}
			break;
	}

	if (sortDir) {
		if (res < 0)
			return 1;
		if (res > 0)
			return -1;
		return 0;
	}
	return res;
}
Пример #6
0
static char *ClientCleanName(const char *in, char *out, int outSize)
{
	int outpos = 0, colorlessLen = 0, letters = 0, spaces = 0;

	// discard leading spaces
	for (; *in == ' '; in++);

	for (; *in && outpos < outSize - 1; in++) {
		out[outpos] = *in;

		if (*in == ' ') {
			// don't allow too many consecutive spaces
			if (spaces > 2)
				continue;

			spaces++;
		}
		else if (outpos > 0 && out[outpos - 1] == Q_COLOR_ESCAPE) {
			if (Q_IsColorString(&out[outpos - 1])) {
				colorlessLen--;

				if (ColorIndex(*in) == 0) {
					// Disallow color black in names to prevent players
					// from getting advantage playing in front of black backgrounds
					outpos--;
					continue;
				}
			}
			else {
				spaces = 0;
				colorlessLen++;
			}
		}
		else {
			spaces = 0;
			colorlessLen++;
		}

		if (Q_isalpha(*in)) {
			letters++;
		}

		outpos++;
	}

	// disregard trailing spaces
	while (outpos > 0 && out[outpos - 1] == ' ') {
		--outpos;
	}

	out[outpos] = '\0';

	// don't allow empty names in local games
	if (*out == '\0' || colorlessLen == 0) {
		Q_strncpyz(out, "UnnamedPlayer", outSize);
	}

	if (!Q_stricmp(out, "UnnamedPlayer")) {
		return "Pick a proper name.";
	}

	if (letters < 3) {
		return "A valid name contains at least three letters.";
	}

	if (colorlessLen > 20) {
		return "Your name is too long.";
	}

	return NULL;
}