Raised This Month: $32 Target: $400
 8% 

ShowMenu for large strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 11-02-2006 , 21:04   ShowMenu for large strings
Reply With Quote #1

Here's my implementation that doesn't seem to work... and I can't figure out why. Here's what happens when I use the below code: <url no longer valid>
Look at what's in the red markings. I'm assuming this is the break between user messages sent, but I can't figure out what exactly the problem is.

Code:
	void ShowMenu(int player_index, int seconds, unsigned int keys, const char *menu_string)
	{
		if (g_iShowMenu)
		{
			size_t len = strlen(menu_string);
			if (len < 251)
			{
				RecipientFilter rf;
				rf.RemoveAllRecipients();
				rf.AddRecipient(player_index);

				bf_write *msg = engine->UserMessageBegin(&rf, g_iShowMenu);
				msg->WriteShort((!keys ? (1<<9) : keys));

				msg->WriteChar(seconds);

				msg->WriteByte(0);

				msg->WriteString(menu_string);   
				engine->MessageEnd();
			}
			else
			{
				char menu_string_clamped [240];
				RecipientFilter rf;
				rf.RemoveAllRecipients();
				rf.AddRecipient(player_index);

				do
				{
					bf_write *msg = engine->UserMessageBegin(&rf, g_iShowMenu);
					msg->WriteShort((!keys ? (1<<9) : keys));
					msg->WriteChar(seconds);

					if (len < 251)
						msg->WriteByte(0); // Draw immediately
					else
						msg->WriteByte(1); // Draw later more info required

					snprintf(menu_string_clamped, sizeof(menu_string_clamped), "%s", menu_string);
					msg->WriteString(menu_string_clamped);   
					engine->MessageEnd();

					if (len > 250)
					{
						size_t s = strlen(menu_string_clamped);
						menu_string += s;
						len -= s;
					}
					else break;
				}
				while (len);
			}
		}
	}

Last edited by sslice; 11-06-2006 at 17:14.
sslice is offline
sslice
Senior Member
Join Date: Feb 2005
Location: Texas, USA
Old 11-02-2006 , 22:19   Re: ShowMenu for large strings
Reply With Quote #2

OK.. I fixed it. Apparently you can only send a string about 230 characters long at a time, even though the other data in the user message takes up 4 bytes out of the 255.
sslice is offline
FlyingMongoose
Veteran Member
Join Date: Mar 2004
Old 11-03-2006 , 11:30   Re: ShowMenu for large strings
Reply With Quote #3

You're creating a plugin to display RSS feeds?

Neat, I might be interested in this.
FlyingMongoose is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode