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

04-26-2009, 07:12 PM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
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.
|
 |
|
 |

05-20-2009, 07:56 AM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
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 
|
 |
|
 |

05-20-2009, 09:52 AM
|
Hill Giant
|
|
Join Date: Nov 2002
Location: NC, USA
Posts: 182
|
|
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.
|
 |
|
 |

05-20-2009, 05:19 PM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
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).
Last edited by trevius; 05-21-2009 at 05:42 AM..
|
 |
|
 |
 |
|
 |

05-21-2009, 02:25 AM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
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.
|
 |
|
 |
 |
|
 |

05-21-2009, 05:26 AM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
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.
Last edited by trevius; 05-21-2009 at 03:15 PM..
|
 |
|
 |

05-21-2009, 09:54 PM
|
Hill Giant
|
|
Join Date: Nov 2002
Location: NC, USA
Posts: 182
|
|
Works great Trev, except for one thing,  ;
I looked through the diff files, and noticed that instead of actually sending the text to the zone channel, you send it directly to the client and to the targeted npc. The problem with this is now that we have the option for npcs to respond without being targeted, this wouldn't work if they tried to implement say links at the same time.
So, it should be an easy fix, right? Just have it actually say the reply instead of sending it directly to the npc. It will be visible to everyone sadly, but it will circumvent this problem.
__________________
Hmm.
|
Thread Tools |
|
Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 11:06 PM.
|
|
 |
|
 |
|
|
|
 |
|
 |
|
 |