Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 04-25-2009, 05:32 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Interesting stuff. I am not sure I understand why it is that only 2 letters can be used per aug slot. If it has 5 bytes per aug, couldn't we set 5 chars per aug? Then break the string into sections of 5 and maybe run some conversions on it like do atohex, then hextoi. I don't think all of the needed functions exist yet, but hextoi does in MiscFunctions.h. Then, after that, we would just do the reverse when the link was clicked. I dunno what it would take to do all of that though, but it sounds at least possible. Unless there is another reason for them only allowing 2 letters. If that is the case, then the database is probably the best way to go and should be pretty simple to do.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #2  
Old 04-25-2009, 06:52 PM
realityincarnate
Developer
 
Join Date: Dec 2007
Posts: 122
Default

The limitation is that the client wants the link sent as text. So, to send the letter "t", which is 74 in hex, you need to send the client the characters "7" and "4". So each character we want actually needs two bytes sent to the client. Since they're in groups of five, it ends up wasting the last byte. We could probably come up with a way to combine and use those too, but it seemed like a lot of work at the time.
Reply With Quote
  #3  
Old 04-26-2009, 03:08 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Shouldn't whatever we send be exactly what we get back when the client clicks the link? If so, we should be able to fill those characters with anything. Maybe we could simply place the string directly in there without doing anything at all to it other than making sure it doesn't exceed the 40 chars we have for it.

I think the client is going to want to look at them as ints or something, otherwise, how can you fit an aug with an itemID higher than 9999 in the string? Still not sure I am following what you are saying.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #4  
Old 04-26-2009, 01:00 PM
realityincarnate
Developer
 
Join Date: Dec 2007
Posts: 122
Default

That's understandable, I'm not sure I know exactly what it's doing myself. But it does look like the client gets the information as text and sends it back to the server as integers.

For example, I made a link to a silver jasper ring (item 14628, 0x3924 hex). The link gets the item id as a string "03924", five bytes long: 30 33 39 32 34. When I click on the link, it sends the item id back to the server as a 4 byte integer: 24 39 00 00. The same thing happens with the augment ids. That means that the highest id # it can deal with is 1048575 (0xFFFFF).

So if you try to just fill it with whatever characters you want, it runs into trouble with anything other than 0-9 and A-F. I'm not sure exactly what it does, but when I forced the alphabet into the link string, I got back bytes: AB CD EF 00 and the zone crashed. The same thing happened whenever I used letters after "f". If I filled the evolving and hash areas with letters higher than "f", the link still appeared purple, but clicking it didn't send anything to the server at all.

If we can figure out exactly what it's doing to the other bytes, we might be able to work around it and use them, but right now I don't even know what it's sending; the zone crashes in the middle of the packet dump.
Reply With Quote
  #5  
Old 04-26-2009, 07:12 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Well yeah it should be sending the info back as ints because that is how we have the structure set to interpret them. It should just be a matter of converting that int back into hex and then into a part of a string and combining them.

If what you are saying about the IDs and strings are true, that is really weird! If so, then yeah, it is pretty useless to even try doing the item name in the string.

Sounds like that database way might be the easiest way to handle it. Should be simple enough to handle that part. Just need to play with it some I guess.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #6  
Old 05-20-2009, 07:56 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Ok, I think I have this almost working. So far, I have it able to create the link properly. It will update the table with a new phrase and ID automatically if one doesn't exist. The only problem left is that I don't know how to pull a string out of a query result to use for when you click the actual link.

Here is what I have so far. Feel free to make fixes, comments, or suggestions. Also note that I have a few extra messages being sent to the client for testing purposes. Those can be removed when this is finished.

Here is the part that is not working:
client_packet.cpp
Code:
void Client::Handle_OP_ItemLinkClick(const EQApplicationPacket *app)
{
	if(app->size != sizeof(ItemViewRequest_Struct)){
		LogFile->write(EQEMuLog::Error, "Wrong size on OP_ItemLinkClick.  Got: %i, Expected: %i", app->size, sizeof(ItemViewRequest_Struct));
		DumpPacket(app);
		return;
	}
	DumpPacket(app);
	ItemViewRequest_Struct* ivrs = (ItemViewRequest_Struct*)app->pBuffer;

	//todo: verify ivrs->link_hash based on a rule, in case we don't care about people being able to sniff data from the item DB

	const Item_Struct* item = database.GetItem(ivrs->item_id);
	if (!item) {
		if (ivrs->item_id > 500000)
		{
			char* response;
			int sayid = ivrs->item_id - 500000;

			if (sayid && sayid > 0) 
			{
				const char *ERR_MYSQLERROR = "Error in saylink phrase queries after clicking the link";
				char errbuf[MYSQL_ERRMSG_SIZE];
				char *query = 0;
				MYSQL_RES *result;
				MYSQL_ROW row;
				

				if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `phrase` FROM saylink WHERE `id` = '%i'", response),errbuf,&result))
				{

					if (mysql_num_rows(result) >= 1)
					{
						while((row = mysql_fetch_row(result)))
						{
							response = new char[strlen(row[0]) + 1];
							strcpy(response, row[0]);
						}
						mysql_free_result(result);
					}
						
					mysql_free_result(result);
					safe_delete_array(query);
				}
				else 
				{
					Message(13, "Error: The saylink (%s) was not found in the database.",response);
					safe_delete_array(query);
					return;
				}
			}
			Message(13, "The Respone is %s.",response);
			this->ChannelMessageReceived(8, 1, 100, response);
			return;
		}
		else {
			Message(13, "Error: The item for the link you have clicked on does not exist!");
			return;
		}

	}

	ItemInst* inst = database.CreateItem(item, item->MaxCharges, ivrs->augments[0], ivrs->augments[1], ivrs->augments[2], ivrs->augments[3], ivrs->augments[4]);
	if (inst) {
		SendItemPacket(0, inst, ItemPacketViewLink);
		safe_delete(inst);
	}
	return;
}
Here is the rest that seems to work just fine, but could probably use some looking over by a more experienced coder:
questmgr.cpp
Code:
const char* QuestManager::saylink(char* Phrase) {

	const char *ERR_MYSQLERROR = "Error in saylink phrase queries";
	char errbuf[MYSQL_ERRMSG_SIZE];
	char *query = 0;
	MYSQL_RES *result;
	MYSQL_ROW row;
	int sayid = 0;

	// Search for existing saylink table entry for this phrase
	if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `id` FROM `saylink` WHERE `phrase` = '%s'", Phrase),errbuf,&result))
	{
		if (mysql_num_rows(result) >= 1)
		{
			while((row = mysql_fetch_row(result)))
			{
				sayid = atoi(row[0]);
			}
			mysql_free_result(result);
		}
		else   // Add a new saylink entry to the database and query it again for the new sayid number
		{
			mysql_free_result(result);
			safe_delete_array(query);

			database.RunQuery(query,MakeAnyLenString(&query,"INSERT INTO `saylink` (`phrase`) VALUES ('%s')", Phrase),errbuf);
			safe_delete_array(query);

			if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `id` FROM saylink WHERE `phrase` = '%s'", Phrase),errbuf,&result))
			{
				if (mysql_num_rows(result) >= 1)
				{
					while((row = mysql_fetch_row(result)))
					{
						sayid = atoi(row[0]);
					}
				}
				mysql_free_result(result);
				safe_delete_array(query);
			}
			else 
			{
				LogFile->write(EQEMuLog::Error, ERR_MYSQLERROR, errbuf);
				safe_delete_array(query);
			}
			safe_delete_array(query);
		}
		safe_delete_array(query);
	}

	char linktext[250];
	if (initiator->GetClientVersion() == EQClientSoF)
	{
		sprintf(linktext,"%c%06X%s%s%c",0x12,500000+sayid,"00000000000000000000000000000000000000000000",Phrase,0x12);
	}
	else
	{
		sprintf(linktext,"%c%06X%s%s%c",0x12,500000+sayid,"000000000000000000000000000000000000000",Phrase,0x12);
	}
	strcpy(Phrase,linktext);
	return Phrase;
}
questmgr.h
Code:
const char* saylink(char* Phrase);
perlparser.cpp
Code:
XS(XS__saylink);
XS(XS__saylink) {
	dXSARGS;
	if (items != 1)
		Perl_croak(aTHX_ "Usage: saylink(phrase)");
	dXSTARG;

	Const_char * RETVAL;
	char text[250];
	strcpy(text,(char *)SvPV_nolen(ST(0)));

	RETVAL = quest_manager.saylink(text);

	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
	XSRETURN(1);
}
And here is the SQL for the table:
Code:
DROP TABLE IF EXISTS `saylink`;
CREATE TABLE `saylink` (
  `id` int(10) NOT NULL auto_increment,
  `phrase` varchar(64) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;
This won't be a required table unless you want to use saylinks.

I think saylink is pretty close to done now. Once this is working and hopefully gets reviewed by a decent coder here, I will get it added to the SVN unless someone else wants to beat me to it. I can't wait to try this out
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #7  
Old 05-20-2009, 09:52 AM
drakelord
Hill Giant
 
Join Date: Nov 2002
Location: NC, USA
Posts: 182
Default

Can't you just create a new temporary string, set the query result to it, then come up with a substring from that and pass it to the variable? Might be easier than trying to edit the query directly.
__________________
Hmm.
Reply With Quote
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 02:09 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3