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
  #16  
Old 04-22-2009, 07:31 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Just figured out a pretty cool bonus to this new varlink quest command. Since it only requires the item ID, it makes it very easy to create arrays of items to use for a script that can be called on for creating itemlinks in say messages, or for item turn ins. So, you could have a single array that handles both, which would make things more simple and less likely to have mistakes.

Here is an example:

Code:
%epic = ("Warrior" => 60321, "Rogue" => 52347, "Monk" => 61025, "Berserker" => 18398, "Shadowknight" => 50003, "Paladin" => 64031, "Ranger" => 62627, "Bard" => 77631, "Beastlord" => 52911, "Cleric" => 9955, "Druid" => 62863, "Shaman" => 57400, "Wizard" => 12665, "Magician" => 19092, "Enchanter" => 52952, "Necromancer" => 62581);

sub EVENT_SAY {

  my $class_itemlink = quest::varlink($epic{$class});

  if($text=~/hail/i) {
      quest::say("The $class epic 1.5 is $class_itemlink.  Turn in a Cloth Cap to get yours!"); }

}

sub EVENT_ITEM {

  my $class_epic = $epic{$class};

  #Extremely simple Epic 1.5 quest (turn in a cloth cap!)
  if (plugin::check_handin(\%itemcount, 1001 => 1)) {
    quest::summonitem($class_epic);
    quest::exp(45000);
    quest::say ("It doesn't get much easier than that!");
  }
}
That is just a basic example and I am sure it could be written much better. But the main point is that it works and could really make handling a large number of items for turn ins and item links in say messages fairly quick to do.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #17  
Old 04-22-2009, 11:17 AM
realityincarnate
Developer
 
Join Date: Dec 2007
Posts: 122
Default

Oh yeah, it looks like I used an int16 in the perl XS part. I have no idea why I did that... I'm not sure this whole early morning/late night coding thing is such a great idea.

In perlparser.cpp change
Code:
uint16 itemID;
to
Code:
uint32 itemID;
And for the sake of consistency and to avoid any problems with much later item ids, you should probably change "int item_id" to "uint32 item_id" in the function headers in questmgr.h and .cpp too.
Reply With Quote
  #18  
Old 04-22-2009, 05:42 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

LOL, thanks! I was looking through for where that int16 was getting set, but I didn't think to look in the perl part!

I will get those changes done and run 1 final test on it, but I am sure that will fix it. That should pretty much finish up the new way to put item links into a variable. I guess this thread can get back to the original SayLink topic :P
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #19  
Old 04-23-2009, 10:56 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

I got the quest::varlink() command added to the SVN and also updated the wiki (here and the one I am working on to convert to MediaWiki) with the new quest command. Many thanks, realityincarnate! It works great, and that fix did correct the issue from before.

Not to figure out how to do those conversions into the aug fields and back into a string for the quest::saylink() command
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #20  
Old 04-25-2009, 04:39 PM
realityincarnate
Developer
 
Join Date: Dec 2007
Posts: 122
Default

I finally got another chance to look at forcing another string into the link, and it's a lot more messed up than I thought.

For some reason, the client likes to receive a text representation of the hex values for augments, etc. I probably should have realized it from looking at how the item id is handled in the original sprintf statement used to generate the links, but it just didn't sink in. So just trying to put a string in there directly causes crashes because it doesn't know what to do with, for example, a hex number represented by "ST".

I was able to trick it into holding some information, but it's much less efficient than I had hoped. I used the string "test", which has a hex representation of 74 65 73 74. The link string allocates five characters for each augment, so we can put two letters in each.
Code:
sprintf(out_text, "%c%06X""%4X%1X%4X%1X""%s%s%c",0x12,999999,'te',0,'st',0,"00000000000000000000000000000","test link",0x12);
will produce an item link that will have "te" in aug0 and "st" in aug1.

Putting them back together is more fun. Each aug slot has two letters, now represented by hex bytes, and in the wrong order. I got them back out using a struct.
Code:
struct AugIn {
	char let2;
	char let1;
};
and running this to build the string.
Code:
AugIn* test;
	char response2[250];
	sprintf(response,"%c",0x00);
	for (int i = 0 ; i < 5; i++) {
		test = (AugIn*) &augments[i];
		sprintf(response,"%s%c%c", response, test->let1, test->let2);
	}
A similar struct method could be used to make it easier to get the string into the augments in the first place. It works, but leaves us with a limit of 10 characters for the response string. This could be increased by using the other variables (evolving item info, etc), but those variables aren't even being decoded by the emulator at the moment.

In other words, I'm beginning to doubt how much advantage this has over your the original suggestion of just using the database. I'll probably continue playing with it, out of stubbornness more than anything else, but I don't think the results will be anything spectacular.
Reply With Quote
  #21  
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
  #22  
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
  #23  
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
  #24  
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
  #25  
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
  #26  
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
  #27  
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
  #28  
Old 05-20-2009, 05:19 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Drakelord, I think you are overestimating my code knowledge lol. I work purely from examples, so if I can't find something that does nearly exactly what I want to do from somewhere else in the source, I probably can't do it. I have learned a ton in the past year, but still have no technical training at all lol. I think determination is the only reason why I can even code at all.

Basically, I am asking that you give me an example of what you mean. I can't find anywhere in the source where we query to get a string and use it. Maybe if I think about it more I can figure out a place that might do that.

EDIT:
Checked into it a bit more from other stuff in the source and maybe I can just do this:


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

					if (mysql_num_rows(result) == 1)
					{
						row = mysql_fetch_row(result);

						strcpy(response, row[0]);
					}
						
					mysql_free_result(result);
					safe_delete_array(query);
				}
I will try that later and see what happens.

Oh, and I just realized that I had "response" instead of "sayid" in that query, so I corrected that. I am sure that was my problem the whole time lol (or the main one anyway).
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!

Last edited by trevius; 05-21-2009 at 05:42 AM..
Reply With Quote
  #29  
Old 05-21-2009, 02:25 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Yup, that did it! It works now

I am just going to clean it up a bit and get it on the SVN. If there are issues found with it at some point, they can be fixed at any time I am sure, but it seems pretty rock solid from my testing so far.

One thing I am still debating is if I should have it say the "You say" messages as if you had actually said it. Right now, I just have it set to send that message to the player that actually clicks the link, so it still seems similar to normal EQ, but that can be removed. The only concern I have with it not showing who is clicking the link is if people start spamming with it and no one can tell for sure who is doing it. If this gets to be popular, I guess we could always add a rule so admins could decide if they want the "You say" messages or whatever.

With this and $client->message, you could actually have a complete conversation with an NPC without anyone else even seeing the conversation at all. I think that has positive and negative benefits, but is definitely something interesting.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #30  
Old 05-21-2009, 05:26 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

I did some more testing and found that the code I had needed a couple other tweaks and stuff to prevent possible crashes, but it looks to be working perfectly now. I added this to the SVN. All you need to do is add the required SQL and it should work just fine.

To use the new quest function, simply follow this example:
Code:
sub EVENT_SAY {

my $test = quest::saylink("test a saylink");
my $click = quest::saylink("click");
my $say = quest::saylink("say");

  if($text=~/hail/i)
  {
    quest::say("Hello, $name.  Would you like to [$test]? If so, simply [$click] on the pink text and wait for my response.  You may also simply /$say the message like normal if you prefer that method instead.");
  }

  if($text=~/test a saylink/i)
  {
    quest::say("The test was a huge success!  Well done :P");
  }

  if($text=~/click/i)
  {
    quest::say("Yes, click the pink text exactly like you just did!");
  }

  if($text=~/^say$/i)
  {
    quest::say("Saying or clicking the text is the same thing to me!");
  }

}
It's pretty cool if you ask me. Now let's see if EQLive shows up with something similar soon :p

I just added quest::saylink() to the wiki and went ahead and wrote a quick wiki page for using it as well:
http://www.eqemulator.net/wiki/wikka.php?wakka=SayLink

I have some say links setup on Storm Haven if anyone wants to log in to check them out. I have them in both the Titanium and SoF starting areas. The areas aren't full of say links yet, but the nearby NPCs from where you start will have them.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!

Last edited by trevius; 05-21-2009 at 03:15 PM..
Reply With Quote
Reply


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 04:39 PM.


 

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 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3