Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
nkei0
Beginner


Joined: 08 Oct 2005
Posts: 19

PostPosted: Sun Nov 27, 2005 7:33 pm   

String-lists and parenthesis
 
Alright, I am noticing what looks like a bug or at least I don't understand why it is happening. Anyways, this is what is going on.

Blah says 'blah'
what it looks like when someone says something

I have a spellbot that goes off of a trigger like this:
#AC {^(%w) says '(*)'$} {#IF %2=@onewordcasts {cast %2 %1} {#IF %2=@multiplecommands {%2} {#NOOP}}

I also have the two variables @onewordcasts and @multiplecommands setup. Obviously the @onewordcasts just casts whateverspell on the person. However the @multiplecommands is doing as it says %2. However if it matches in the multiplecommands I have all of the contents of that variable also made into aliases, that way for whichever one it matches, it can do different things.

The problem that I am having is whenever someone says something like
Blah says 'blah)'
It fires the trigger and it commands "cast blah) Blah"
I have already checked with another character and Blah says 'tell Blah %pass)' doesn't work, however I can still see this as being a VERY VERY big security hole and would like to know the correct way about going around this?

Thanks.
Reply with quote
darkspot
Apprentice


Joined: 29 Jul 2002
Posts: 105

PostPosted: Sun Nov 27, 2005 10:59 pm   
 
Code:

#AC {^(%w) says '(*)'$} {#IF (%ismember(%2,@onewordcasts)) {cast %2 %1} {#IF (%ismember(%2, @multiplecommands)) {%2} {#NOOP}}

should work..
from the way you were talking... onewordcasts and multiplecommands were string lists right? (that's what I assumed when I made this)
Reply with quote
nkei0
Beginner


Joined: 08 Oct 2005
Posts: 19

PostPosted: Mon Nov 28, 2005 1:17 am   
 
I apologize so much, I was very tired (still am) when I posted this but the above code is what the trigger is the whole #IF %2=@onewordcasts thing isn't true, i was just mistaking another trigger with that one, the other trigger works fine, it is the %ismember one that is firing incorrectly.
Thanks
Reply with quote
darkspot
Apprentice


Joined: 29 Jul 2002
Posts: 105

PostPosted: Mon Nov 28, 2005 2:48 am   
 
well show us the ismember one?
Reply with quote
nkei0
Beginner


Joined: 08 Oct 2005
Posts: 19

PostPosted: Mon Nov 28, 2005 10:22 am   %ismember
 
Uhh, I thought i said that it was just as you had it above, but oh well here is the exact trigger.

Pattern:
^(%w) says '(*)'$

Command:
#IF %ismember( %2, @onewordcast) {
#VAR todo %additem( "cast %2 %1", @todo) {} Magebot
#IF @nextcmd="" {
#VAR nextcmd %pop( todo)
#IF @nextcmd="" {#noop} {nextcmd}
} {#NOOP}
} {#IF %ismember( %2, @multiple) {
#VAR target {%1} {} Magebot
#VAR todo %additem( "%2", @todo) {} Magebot
nextcmd
} {#NOOP}} {
#SHOW what happens here2?
#NOOP
}
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Nov 30, 2005 8:45 am   
 
Delimeters are you best friends. Use parenthesis, braces, and quotes even when you don't think you need them.

#IF (%ismember( "%2", @onewordcast)) {
#VAR todo {%additem( "cast %2 %1", @todo)} {} Magebot
#IF (@nextcmd="") {
#VAR nextcmd {%pop( todo)}
#IF (@nextcmd="") {#noop} {nextcmd}
} {#NOOP}
} {#IF (%ismember( "%2", @multiple)) {
#VAR target {%1} {} Magebot
#VAR todo {%additem( "%2", @todo)} {} Magebot
nextcmd
} {#NOOP}} {
#SHOW what happens here2?
#NOOP
}

Since you are operating on text from a player you may want to improve the security a little more by using a limited list of accepted commands directly in the trigger. This stops the entire possibility of the trigger being fired with a bad user input.

Pattern example: ^(%w) says '({@AllowedCommands}{ |}{@SubCommands|})'$
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
nkei0
Beginner


Joined: 08 Oct 2005
Posts: 19

PostPosted: Wed Nov 30, 2005 6:26 pm   matching
 
You say I could use this, I'm not sure how I could match both of these the code you listed is:

Pattern example: ^(%w) says '({@AllowedCommands}{ |}{@SubCommands|})'$

how do i match these?
like if you noticed in my above trigger i need to be able to match both, and if it does match i need to be able to know which command it matched to that way I can cast that spell or group of spells on whomever said it.
Your help is greatly appreciated, Thanks.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Dec 01, 2005 1:26 am   
 
That is why it was an example. After all the time I have tried to help here I pretty much decided it is not my job to just hand everyone the perfect solution. That is why I post scripts off the top of my head with no debugging; and sometimes give vague 1 word answers. I know that the zMud help is very thorough in documenting things, although sometimes solutions are hard to find. What I decided it is in my job to do is try to point you in the correct direction, and let you learn. zScript is complex enough to class as its own language, and language learning is different then other types of learning. So with all that said, a little more explanation may be helpful.

First find the Pattern Matching area of the help. It is in the contents section Reference, and also cross linked from #TRIGGER and most trigger related topics.

You will note it mentions that the entire section of a pattern in a parenthesis group is captured into a %nn variable. In the example case, when matched the contents of the matching portion to:
%w would be stored in %1
{@AllowedCommands}{ |}{@SubCommands|} would be stored in %2

Now in this example we would want the list represented AllowedCommands to include things like "cast" or "rub lamp". This list could of course be named something shorter like AlC. As long as both the list and the pattern reference match. Next is another list stating that the pattern should match a space or null. 2 spaces and all other characters are right out. Finally the {@SubCommands|}, a combination of the 2 previous examples. It should match a member of the SubComs list or nothing. The combination of matches leaves a large amount of user configuration open, and also requires that the full command be validated. For example the configuration I might use would match "rub lamp cure light" and this might be totally invalid. All of this is a seperate and secondary issue to the script you originally asked for help on. So you can use that script in a more open form if you choose, as you noted zMud does supply a reasonable security on its own.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
nkei0
Beginner


Joined: 08 Oct 2005
Posts: 19

PostPosted: Thu Dec 01, 2005 10:52 am   Solution
 
Excellent, this works, and I knew that it saved what it matches to a variable it just looked funny to me not having a % anywhere, since that is the only way i've really done it because, well this is the first time I've ever ran into a problem with it. So yeah, thanks. However, this doesn't answer why my beginning %ismember trigger is matching incorrectly, and delimiting everything possible doesn't help as someone above mentioned. While I'm happy to know the solution to stop this, I would also like to know why it happens. What are we if we can't understand? (dumb)
Reply with quote
Slaem
Apprentice


Joined: 20 Sep 2005
Posts: 135

PostPosted: Thu Dec 01, 2005 2:14 pm   
 
Yours: #IF %ismember( %2, @onewordcast)
Vij's: #IF (%ismember( "%2", @onewordcast))

You need the quotes to match multiple words.
_________________
Show your love.
Support Zugg Software!
Donate to zugg@zuggsoft.com with PayPal Send Money.
Reply with quote
nkei0
Beginner


Joined: 08 Oct 2005
Posts: 19

PostPosted: Thu Dec 01, 2005 9:14 pm   slaem's comment
 
i wasn't trying to match multiple words.
<3
Reply with quote
Slaem
Apprentice


Joined: 20 Sep 2005
Posts: 135

PostPosted: Fri Dec 02, 2005 3:48 am   Re: %ismember
 
Sorry for quoting the wrong section of your script. I was referring to the multiple word section where you are matching multiple words, but Vij already pointed that out. Do you have an example of text that isn't matching properly, including the value stored in the variable?
_________________
Show your love.
Support Zugg Software!
Donate to zugg@zuggsoft.com with PayPal Send Money.
Reply with quote
nkei0
Beginner


Joined: 08 Oct 2005
Posts: 19

PostPosted: Fri Dec 02, 2005 8:32 am   mismatching
 
Okay, I explained what was going wrong in the original post. However, I will post again with visuals.

The Trigger (don't care about anything else in this as it has already been changed, just what to know why the first ifcheck is misfiring (examples below)
#AC {^(%w) says '(*)'$} {#IF %2=@onewordcasts {cast %2 %1} {#IF %2=@multiplecommands {%2} {#NOOP}}

Example 1:
Craptar says 'I hate you (argh)' (doesn't match, which is correct)
Example 2:
Craptar says 'I hate you argh)' (does match, off of the first ifcheck, wtf?)
Example 3:
Craptar says 'I hate you %argh)' (doesn't match, which is correct)

From these examples you should be able to conclude that my first ifcheck is matching to says that include a ), also it doesn't matter how many words are in the say, but you can also conclude that it WILL NOT match to any say that includes a ) but is preceded by a ( or a %. If you have any further questions, please ask. I won't make fun of you.
Thanks
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Dec 02, 2005 9:34 am   
 
Delimeters are you best friends. Use parenthesis, braces, and quotes even when you don't think you need them.

#AC {^(%w) says '(*)'$} {#IF ("%2"=@onewordcasts) {cast %concat("%2 %1")} {#IF ("%2"=@multiplecommands) {"%2"} {#NOOP}}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net