usage of G_refPrintf in g_vote.c is bugy


(SCDS_reyalP) #1

g_vote.c does nice things like this.


	G_refPrintf(ent, "
Available Warmup Damage types:
------------------------------");

But because of the
it doesn’t actually get printed. I’m not sure exactly why everything after a
gets dropped but it does. Simple workaround is to remove the leading
and use multiple calls to print multiple lines.


(Lanz) #2

That’s because of the way they handled the message on the client. It’s one pice of ugly code…

in CG_AddPMItem:


void CG_AddPMItem( popupMessageType_t type, const char* message, qhandle_t shader ) {
	pmListItem_t* listItem;
	char* end;

	if( !message || !*message ) {
		return;
	}

	listItem = CG_FindFreePMItem();

	if( !listItem ) {
		return;
	}

	if( shader ) {
		listItem->shader = shader;
	} else {
		listItem->shader = cgs.media.pmImages[type];
	}

	listItem->inuse = qtrue;
	listItem->type = type;
	Q_strncpyz( listItem->message, message, sizeof( cg_pmStack[0].message ) );


	while( end = strchr( listItem->message, '
' ) ) {
		*end = '\0';
	}

	trap_Print( va( "%s
", listItem->message ) );


	if( !cg_pmWaitingList ) {
		cg_pmWaitingList = listItem;
		listItem->time = cg.time;
	} else {
		pmListItem_t* loop = cg_pmWaitingList;
		while( loop->next ) {
			loop = loop->next;
		}

		loop->next = listItem;
	}
}

Just take a look at that horrible while loop there :eek:

But I have a fix for it since I changed that code a while ago.


void CG_AddPMItem( popupMessageType_t type, const char* message, qhandle_t shader ) {
	pmListItem_t* listItem;
	char *start, *end;
	
	if( !message || !*message ) {
		return;
	}

	start = end = message;
	
	while( end = strchr( start, '
' ) ) {
		*end = '\0';
			
		listItem = CG_FindFreePMItem();

		if( !listItem ) {
			return;
		}

		if( shader ) {
			listItem->shader = shader;
		} else {
			listItem->shader = cgs.media.pmImages[type];
		}

		listItem->inuse = qtrue;
		listItem->type = type;

		Q_strncpyz( listItem->message, start, sizeof( cg_pmStack[0].message ) );

		trap_Print( va( "%s
", listItem->message ) );

		if( !cg_pmWaitingList ) {
			cg_pmWaitingList = listItem;
			listItem->time = cg.time;
		} else {
			pmListItem_t* loop = cg_pmWaitingList;
			while( loop->next ) {
				loop = loop->next;
			}
			loop->next = listItem;
		}
		
		end++;
		start = end;
	}
}


(Chruker) #3

Lanz your new code, breaks the working of the function for single line messages which means any wm_announce strings from script, notices on who joined a team, connected, disconnect, died etc. don’t work after applying the code.


(Rain) #4

In etpro, I just moved the trap_Print above the
mangling, since having even more junk in the popup message area isn’t really a desirable thing to begin with.