[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  variable comparisons
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

variable comparisons

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by ErockMahan   (81 posts)  [Biography] bio
Date Thu 23 Oct 2008 10:13 PM (UTC)
Message
I'm trying to figure out a simple way to automatically log and track characters based on the ip address. What I would like to do, in theory, is to have the ip address saved as a variable and then to be able to pull up all instances of that variable occurring.

I always think seeing it makes more sense than explaining it:

Bob has logged in from 12.34.56.78
(trigger will save both "bob" and the port number)

Mike has logged in from 12.34.56.78
(trigger will save both "mike" and the port number)


I then want to run an alias that will call all instances of 12.34.56.78, thus showing me both "mike" and "bob"


Is this even possible?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 24 Oct 2008 05:36 AM (UTC)
Message
Anything is possible. ;0

First, this would be easier in Lua, because you have tables which have key/value combinations. However if you want to use VBscript, try using the array functions in MUSHclient:

http://www.gammon.com.au/scripts/doc.php?general=Arrays

In Lua I would have used a table of IP addresses, and for each IP address, another table of names which have used that address. Thus, for an address, I can get a list of all the names. However a similar thing could be done in other languages.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #2 on Sat 25 Oct 2008 05:33 AM (UTC)
Message
In VB, you do have access to the Scripting.Dictionary object, which has the exact same functionality that Lua's tables have... although MC ships with the serialize library for Lua code, which makes persisting them easier. :)
[Go to top] top

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #3 on Mon 27 Oct 2008 11:32 PM (UTC)
Message
Here is the trigger:

<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="[ *[*] has connected.*"
send_to="12"
sequence="100"
>
<send>ArraySet "port", "%1", "%2"</send>
</trigger>
</triggers>

It triggers on this:
[ Bob[12.345.6.789] has connected. [22] ]



Here are the aliases I've tried using to see if it is working:

<aliases>
<alias
match="arrayget *"
enabled="y"
send_to="12"
sequence="100"
>
<send>Note ArrayGet ("port", "%1")</send>
</alias>
<alias
match="arraylist"
enabled="y"
send_to="12"
sequence="100"
>
<send>dim arrList

arrList = world.ArrayListAll

If Not IsEmpty (arrList) Then

For Each a In arrList
world.note a
Next

End If</send>
</alias>
</aliases>


Nothing happens when I use those aliases (or rather, a blank line comes through). What am I doing wrong?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 28 Oct 2008 04:37 AM (UTC)
Message
It helps to check the return code if nothing seems to be working. In your case I tried your trigger, modified a bit like this:


Note ArraySet ("port", "%1", "%2")


That returned 30056 (That array does not exist).

The array documentation notes you have to create an array before using it. One way is just to modify your trigger like this:


ArrayCreate "port"
ArraySet "port", "%1", "%2"


Only the first ArrayCreate will succeed (after that it will return an error "already exists") but as you will ignore the error that is no big deal.

After doing that, it worked and your alias to test the array did what you would expect.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by ErockMahan   (81 posts)  [Biography] bio
Date Reply #5 on Wed 29 Oct 2008 06:40 PM (UTC)
Message
After getting it to "work", my alias will now show me the most recent who logged from what ip, and what ip applies to who. While this is great, it doesn't seem to work for multiple instances of the event. For example:

[ Bob[12.345.678.90] has connected. [19] ]
[ Bob has disconnected. [19] ]
[ Bobby[12.345.678.90] has connected. [19] ]

My alias will only pull up the most recent instance of the ip address (Bobby) instead of what I was hoping, which is that it would show both Bob and Bobby. Am I doing something wrong, or have I been going about this the wrong way?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Wed 29 Oct 2008 10:40 PM (UTC)
Message
You really need a table within a table (or an array within an array).

Effectively you have: <array of names>

Now for each name you need <array of IP addresses>

(Or, for each IP address: <array of names>).

One way of going about that would be to use a comma-delimited string for each IP address. Thus the value (per IP address) might be:

Key: 12.345.678.90
Value: Bob,Bobby,Bruce

Now to add to that you first need to get Bob,Bobby,Bruce into another array. If you want to use the Array functions in MUSHclient, you need key/value pairs, but in this case you don't care about the values (the presence of the key is enough).

Thus it would really be:


Key: 12.345.678.90
Value: Bob,,Bobby,,Bruce,

You could import that into an array like this:


names = "Bob,,Bobby,,Bruce,"   ' original names

' make an array to hold the current names

ArrayCreate "names"
ArrayImport "names", names, ","

' our new name

newname = "Nick"

' add to array

ArraySet "names", newname, ""

' export back out

names = ArrayExport ("names", ",")

' see result 
Note (names)   ' --> Bob,,Bobby,,Bruce,,Nick,


Now this new list of names would be stored in the other array as the value for IP address 12.345.678.90.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


6,364 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]