|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum) |
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.
|
05-21-2009, 10:11 PM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
I don't really know how hard it would be to do that. Without a target, it crashes the zone as it is currently set. Maybe a messageclose would work, but I haven't tried that yet. Though, I think it would be a pretty extremely rare case that someone would use both proximity say and say links at the same time. Feel free to submit a working change to the code if you want though.
Everyone already sees the message as long as an NPC is actually targeted when the link is clicked. The only way to not have it send the message is to simply parse it instead of doing the message sending stuff. I originally had it set to do that, but there may be issues with doing it that way.
|
|
|
|
05-22-2009, 03:53 PM
|
Administrator
|
|
Join Date: Sep 2006
Posts: 1,348
|
|
Code:
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'", sayid),errbuf,&result))
{
if (mysql_num_rows(result) == 1)
{
row = mysql_fetch_row(result);
strcpy(response, row[0]);
}
This is at best a crash and at worse something far more dangerous. You can't simply strcpy to memory that does not exist. While there's a chance because you don't initialize response that the memory does exist you're going to be overwriting random data and it's going to do *bad* things to your server.
Also it better not be crashing the zone just because of something as trivial as not having a target, there should be sanity checks in place to counter that.
|
|
|
|
05-22-2009, 04:25 PM
|
|
The PEQ Dude
|
|
Join Date: Apr 2003
Location: -
Posts: 1,988
|
|
Quote:
Originally Posted by KLS
This is at best a crash and at worse something far more dangerous.
|
*And by that she means the complete and total destruction of the universe. -editor
|
05-22-2009, 04:55 PM
|
Dragon
|
|
Join Date: Apr 2009
Location: California
Posts: 814
|
|
Ooh, yeah, some unstable referencing there.
Using char response[64]; instead of char* response; will solve the main problem by allocating 63 bytes for the phrase (plus one for the null terminator).
The second step would be changing strcpy() so that if someone gets funny and passes a phrase larger than 63 characters you won't be looking at a buffer overflow:
Code:
if (mysql_num_rows(result) == 1)
{
row = mysql_fetch_row(result);
strncpy_s(response, sizeof(response), row[0], _TRUNCATE);
}
|
05-22-2009, 05:13 PM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Yeah, Derision had already pointed out the Memory Allocation issue to me in a PM lol. I was gonna fix it on the next update I did. Simple fix anyway. And the code I posted here isn't the final code. I did add a sanity check to have it verify that they have a target before it tries to send the say message to the target. I will put the truncate in there too, thanks Shendare.
I was hoping for someone to review the code, but since it was already working and not a required feature by any means, I figured I would get what I had up there and add in any needed fixes later. Thanks for the info.
Edit: NM, I see KLS already got the mem allocation thing fixed. Thanks, KLS.
Last edited by trevius; 05-23-2009 at 01:16 AM..
|
06-06-2009, 03:58 PM
|
Fire Beetle
|
|
Join Date: Jun 2008
Location: -
Posts: 14
|
|
Is there any way to make it where when the player clicks a saylink, the npc they are talking to responds as if they said that but the player doesn't actually say anything?
Also, can you make the text you click on different than what is said/sent to npc?
|
06-06-2009, 06:30 PM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
You can't make the name of the link different than what is said when it gets clicked. But, if needed, you should be able to change what your script is waiting to be said so that it catches things however you want to say them. An example would be if your NPC said "bind your soul", most players would type "bind my soul", but if you clicked the link, it would say "bind your soul". In this example, you could just have the NPC look for either "bind" or "soul" to be said so that both phrases would work as replies.
It is possible to code it so the players don't actually say anything, but it may be better that they do. All we would have to do is do the parse of the text right there instead of sending the message as a say. It probably wouldn't be bad to do it that way, other than people maybe clicking the links to annoy people and no way to tell for sure who it is causing the spam.
|
|
|
|
06-06-2009, 11:04 PM
|
Sarnak
|
|
Join Date: Dec 2005
Location: the Void
Posts: 40
|
|
is this working?
Just wondering if saylink is working in the Branch version ?
I see the code for it there. Table in the DB is there but its not working for me when I follow the examples in this thread or the wikki you have linked hrmmm.
Just compiled ver 635 of the Instance Branch version today. Guess I'll take a look at the regular SVN and see if there is a difference in code for the saylink.
|
06-06-2009, 11:30 PM
|
|
The PEQ Dude
|
|
Join Date: Apr 2003
Location: -
Posts: 1,988
|
|
Branch is no longer used, we're back on the trunk.
|
06-06-2009, 11:37 PM
|
Sarnak
|
|
Join Date: Dec 2005
Location: the Void
Posts: 40
|
|
thanks for the info Cavedude
|
06-07-2009, 03:49 AM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Have you tried reading the little wiki page on Say Links?
http://www.eqemulator.net/wiki/wikka.php?wakka=SayLink
That might help a bit. They are really easy to use. Once you get the first one working, it is extremely easy to get any extra ones added.
|
06-07-2009, 01:31 PM
|
Sarnak
|
|
Join Date: Dec 2005
Location: the Void
Posts: 40
|
|
...
Yes I did, but Cavedude pointed me in the right direction.
Updated and compiled the lastest Rev from the Trunk and saylinks are working now.
Thanks guys for the help
|
|
|
|
06-11-2009, 04:46 PM
|
Fire Beetle
|
|
Join Date: Jun 2008
Location: -
Posts: 14
|
|
I think it would help a lot if there was at least an option to make the saylink not actually make the player say something. If you combined that with using $client->Message("(npc) says ...") instead of quest::say("..."), you could have completely private/spam-free interactions with npcs. It would also help a lot for my passcode script idea. (see below)
Also, I came up with a kind of cheap way in perl to make the text you click different from the text that is said:
Code:
sub Saylink
{
my $saylink = quest::saylink($_[0]);
my $length = length(substr($saylink,46)) - 1;
if($_[1]) { substr($saylink,46,$length,$_[1]); }
return $saylink;
}
It basically just creates a new saylink with the text you want it to say and then edits the string that quest::saylink() returns to change the text that you click.
So for example you could do $saylink = Saylink("option1","[Ask about the recent attacks.]"); and it would make a saylink titled "[Ask about the recent attacks.]" and when you click it, it would make you say "option1". This can help in some cases but doesn't have much practical use until you get to more advanced stuff: Like my passcode script idea.
-Passcode script idea-
If saylinks didn't actually make the player say something, you could use them for private npc interactions. One example of this would be to set a passcode that is required in order for something to happen (being able to open a door, zone somewhere, summon an item, spawn a mob, enter an instance, etc). I tried doing this in game and it works fine. The script just creates saylinks for the digits (0-9) and then a saylink for resetting the passcode and a saylink for submitting the passcode. When you click one of the digits, it adds that digit to $passcode[$cid] which is an array of passcodes where the index is the character's id (This is so any number of players can use the script at the same time without messing each other up). When you click [reset passcode], it sets $passcode[$cid] back to empty and when you click [submit passcode], it checks $passcode[$cid] against $check, the variable that the correct passcode is stored in. If they match, access is granted and you can flag the player or do whatever you wanted to do. If they don't match, it denies them access.
Code:
$check = 52213; # the passcode to check against: can also load it from a global/file/etc
sub EVENT_SAY
{
$cid = $client->CharacterID(); # gets the character's id and uses it as the index for the @passcode array
@args = split(/ /, $text); # split up $text by spaces and store each word/number/etc in the @args array
if($args[0]=~/hail/i)
{
InitSaylinks();
ShowMenu();
}
if($args[0]=~/push/i)
{
$passcode[$cid] = $passcode[$cid] . $args[1];
ShowMenu();
}
if($args[0]=~/reset/i)
{
$passcode[$cid] = "";
ShowMenu();
}
if($args[0]=~/enter/i)
{
if($passcode[$cid] eq $check)
{
$client->Message(15, "Access granted!");
$passcode[$cid] = "";
# now do whatever you wanted to do: open door, move player to location, move player to another zone, spawn a mob, summon an item, etc
}
else
{
$client->Message(13, "Wrong passcode! Access denied!");
$passcode[$cid] = "";
ShowMenu();
}
}
}
sub InitSaylinks
{
my $count = 0;
while($count < 10) {
$sl_push[$count] = Saylink("push " . $count, $count);
$count++;
}
$sl_reset = Saylink("reset","[Reset passcode]");
$sl_enter = Saylink("enter","[Submit passcode]");
}
sub Saylink
{
my $saylink = quest::saylink($_[0]);
my $length = length(substr($saylink,46)) - 1;
if($_[1] ne "") { substr($saylink,46,$length,$_[1]); }
return $saylink;
}
sub ShowMenu
{
if($passcode[$cid]) { $client->Message(4, "You have entered: $passcode[$cid]"); }
$client->Message(4, "Enter passcode: @sl_push $sl_reset $sl_enter");
}
It would end up looking something like this (correct passcode is 52213 in this example):
|
|
|
|
|
|
|
06-11-2009, 05:19 PM
|
|
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
That passcode idea is pretty neat. I am not sure of any places where I would use something like that, but I always love to see innovative ideas to push the limits of what we can do with the emulator systems available.
As for making the saylinks so they don't actually say what they click, that isn't too hard. I think we can just do the parse of the text right in the place were we currently send the message to the NPC. Though, it might take a bit of extra code to ensure that it doesn't cause other issues. Using the parse at that point is exactly how I originally tested saylinks (mentioned at the beginning of this thread), so I know it works.
I have been thinking about adding in a rule to allow admins to decide whether they want their saylinks to cause the players to actually say the message or not. But, another route might be to add in a second variation to the command. Maybe something like "ssaylink()" for Silent Saylink, or something to that effect. Then, one could chose either type for any scenario instead of having to chose 1 or the other for the entire server. The coding is already all there, so it would mostly just be adding the new command and the parse code. I think to differentiate between the 2 types of saylinks, we could just have the silent saylinks set their item ID to a much higher range. Since normal saylinks are set in the 500k range, the silent ones could be set to use the 1mil range or something like that.
I will try to look into getting this change added sometime soon, but I have a lot on my plate atm as usual, so no ETA. Glad to see people using the saylink system. I think it is a pretty neat little feature.
|
|
|
|
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 08:27 AM.
|
|
|
|
|
|
|
|
|
|
|
|
|