Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Making a Database.

Making a Database.

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


Pages: 1 2  

Posted by Xyborg   Canada  (47 posts)  Bio
Date Sat 04 Oct 2003 08:52 PM (UTC)
Message
Ok. The mud I play/work on is prone to jackasses coming back continuously to crash the game and stuff. What I want to do, is make a database of the IPs connecting to the mud. I don't have MySQL or anything like that, so I was hoping it would be possible to do just with the game notepad or somthing.

This is how I was thinking it could be done.

Trigger goes off.
script checks to see if it (the ip and player name (Xyborg@66.139.45.45)) exists in the notepad document.
If it isn't in the document, it adds the line and saves the document. (Saving isn't really needed.)
Now if the exact line (Xyborg@66.139.45.45) exists in the document, it isn't added. But if the IP varies at all, it IS added.

If this is possible, how do I go about appending and retriving information from notepad?

Thanks for any help you can give me.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 05 Oct 2003 05:28 AM (UTC)
Message
The example databases given in a couple of plugins just use the Access database format which normally comes with most versions of Windows (the ODBC driver). However, you can do what you want pretty easily by simply storing the names and IPs in a variable, separated by commas, and using Split to break them up into an array. There was a recent post about doing that.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #2 on Mon 06 Oct 2003 05:13 AM (UTC)
Message
wow. I didn't understand anything you just said. This is what I think you said.

"Go look at some of the other plugins."

Sorry for being retarded, but I'm not a smart one. I just do half assed stuff.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #3 on Mon 06 Oct 2003 06:17 AM (UTC)
Message
He said pretty much what you got out of it.

You dont need SQL or anything, windows innately has some database functions on normal installs.

Plugins that use this can be found on the plugins page.

He also went on to say that you dont really need to make a database, you can just use a variable to store the IPs with commas seperating them, and then use the Split command (in the scripting engines) to seperate the variable data ("ip1,ip2,ip3") into an array which will be more usable by the scripting engines to do what you want.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #4 on Mon 06 Oct 2003 06:28 AM (UTC)
Message
Hmm. So there isn't really a way I could have it in the format I want (Xyborg@65.139.45.45) right?

Hrm. Well at least I don't need MySQL.

Ok. Instead of the way I wanted, could I do it in this type of format?

65.139.45.45
Xyborg
Shinjirou

Cause that would be really useful.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #5 on Mon 06 Oct 2003 08:34 AM (UTC)
Message
Why couldnt you have it in the [name]@[ip] format?

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #6 on Mon 06 Oct 2003 03:39 PM (UTC)

Amended on Mon 06 Oct 2003 03:44 PM (UTC) by Xyborg

Message
I have no idea how to store letters in a variable lol. I'm still new to this stuff. Only did one plugin a couple months ago and then I just gave up.

It was just a PL tracker for a DBZ mud I play. Pretty simple. Nick did it with just a trigger which I used and modified to suit my needs. Then I had a hard time trying to re-insert commas into the totalled number.

Basically, what I know of VBscript is in that one plugin I made. If you want to check it out, you can get it at

http://www.badtrip-designs.com/dloads/PLTL16.zip

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Dubthach   (47 posts)  Bio
Date Reply #7 on Mon 06 Oct 2003 05:03 PM (UTC)
Message
You could do this very easily in PerlScript. If VBScript has associative arrays/hashes, you could use this concept for it as well.

Trigger fires, you get user@domain.

split the variable on your comma delimiters.

load up a hash with the keys being members of the split list. set the values to 1 or some other arbitrary value.

add the user@domain to the hash. If the user already exists in the hash, it will not be duplicated because hashes are guaranteed to have unique keys.

join the keys from the hash again by your comma delimiter and shove it back into the variable.

In perl the code would like something like:


@users = split(/,/, $mushvar);

foreach $x (@users)
{
    $hash_users{$x} = 1;
}

$hash_users{$new_user} = 1;

$mushvar = join(',', sort(keys(%hash_users)));


You'll have to figure out how to get and set the $mushvar.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #8 on Mon 06 Oct 2003 09:19 PM (UTC)

Amended on Mon 06 Oct 2003 09:24 PM (UTC) by Shadowfyr

Message
Well Dubthach, I am sure he is now completely confused.

Ok. Xyborg. This is a stripped down and reorganized database that should do what you need:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
   name="IPDatabase"
   author="Kagehi Kossori"
   id="5dfbc176dad925866871c1dc"
   language="VBscript"
   purpose="Maintains a database of IPs and player names."
   date_written="10-06-2003"
   date_modified="10-06-2003"
   requires="3.24"
   save_state="y"
   version="1.0"
   >
<description trim="y">
<![CDATA[
  This plugin manages a basic database of players and IPs.

  Commands are:

  ip:add <Player> <IP Address>   - Adds a player and IP to the database.

  ip:remove <Player> - Removes an item from the database, by Player name.

  ip:clear <IP Address {optional}> - Will clear all names with a single IP or the entire database.

  ip:list <IP or Player {optional)> - This will show an entire like id you leave off the name or IP.
  If you use a name or an IP, then it will list that name and IP or all names associated with that IP.

  ip:help - This help page.

]]>
</description>

</plugin>

<aliases>
  <alias script="Add"
   match="ip:add * *"
   enabled="y">
  </alias>
  
  <alias script="List"
   match="ip:list"
   enabled="y">
  </alias>

  <alias script="List"
   match="ip:list *"
   enabled="y">
  </alias>

  <alias script="Remove"
   match="ip:remove *"
   enabled="y">
  </alias>

  <alias script="ClearList"
   match="ip:clear"
   enabled="y">
  </alias>
</aliases>

<script>
<![CDATA[
dim DBHandle

sub OnPluginInstall
'  timer: enabled, one-shot, active-if-not-connected

  world.addtimer "", 0, 0, 5, "", 1 + 4 + 32, "OnSetup"
end sub

sub Onsetup(tName)
  dim Link
  Link = StartDB
  select case Link
    case 0
      world.ColourNote ""lightblue", "midnightblue", "IP list plugin started."
    case 1
      world.ColourNote "white", "red", "ADOX Catalog missing. You may need to download the latest MDAC from Microsoft."
    case 2
      world.ColourNote "white", "red", "Table creation failed."
  end select    

function GetProvider
  'Uses the "version independent" provider name, to hopefully simplify matters.
  GetProvider = "Provider=Microsoft.Jet.OLEDB;Data Source=IPList.mdb;Jet OLEDB:Engine Type=5;"
end function

function StartDB
  Dim FSO, Exists, CatHandle, oTable
  
  On Error Resume Next
  'Connect to the ADOX functions.
  Set CatHandle = CreateObject ("ADOX.Catalog")
  
  If Err.Number <> 0 Then
    StartDB = 1
    Exit Function 
  End If

  On Error Goto 0

  'Lets first see if it exists.
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Exists = FSO.FileExists ("IPList.mdb")
  Set FSO = Nothing

  if not Exists then
    CatHandle.Create GetProvider
    world.ColourNote "lightblue", "midnightblue", "IPList database created."
  end if

  'Open database.
  Set DBHandle = CreateObject ("ADODB.Connection")
  DBHandle.Open GetProvider

  'Check to see if Table (the actually storage place) exists.
  Exists = vbFalse
  For Each oTable In db.Tables
    If UCase(oTable.Name) = UCase("IPData") Then
      Exists = vbTrue
      Exit For
    End If
  Next

  if not Exists then
    'Create the table.
    if DoSQL ("CREATE TABLE IPData (" & _
      "  ip_address varchar(15) NOT NULL," & _
      "  player_name varchar(64) NOT NULL)") Then
      world.ColourNote "lightblue", "midnightblue", "IPList database created."
    else
      StartDB = 2
      Exit Function 
    end if
  end if

  Set CatHandle = Nothing
  StartDB = 0
end function

'
'  Execute some arbitrary SQL
'
Function DoSQL (sSQL)
  DoSQL = vbTrue	' error return

  On Error Resume Next
  
' Execute it
  DBHandle.Execute sSQL

  If Err.Number <> 0 Then
    world.ColourNote "white", "red", Err.Description
    Exit Function 
  End If

  On Error GoTo 0

  DoSQL = vbFalse	' OK return
end Function

sub Add (aName, Output, Wilds)
  Dim ip_address, player_name

  player_name = Wilds(1)
  ip_address = Wilds(2)

  If DoSQL _
    ("INSERT INTO IPList (player_name, ip_address)" & _
          " VALUES (" & _
          """" & Player & """, " & _
          """" & ip_address & """);") Then Exit Sub         
 
  world.ColourNote "white", "green", "Player '" & Player & _
     "' added to the database"  
end sub

sub Remove (aName, Output, Wilds)
  If DoSQL _
    ("DELETE FROM IPList WHERE player_name = " & _
          """" & Wilds(1) & """ ") Then Exit Sub
 
  world.ColourNote "white", "green", "Player '" & Wilds(1) & _
     "' deleted from the database"
end sub

sub List (aName, Output, Wilds)
  Dim ip_address, player_name
  Dim rst, count, SQuery
  Dim LastIP

  if Wilds(1) = "" then
    sQuery = "SELECT * FROM IPData ORDER BY ip_address"
  else
    sQuery = "SELECT * FROM IPData WHERE " & _
         "player_name like ""%" & wildcards (1) & "%"" " & _
         "OR ip_address like ""%" & wildcards (1) & "%"" "
         "ORDER BY ip_address"
  end if

  On Error Resume Next
  
  Set rst = CreateObject ("ADODB.Recordset")
  rst.Open sQuery, DBHandle

  If Err.Number <> 0 Then
    world.ColourNote "white", "red", Err.Description
    Set rst = Nothing
    Exit Function
  End If

  count = 0

  ' display each record
  Do Until rst.EOF

    count = count + 1

    ip_address   = rst.Fields ("ip_address").Value
    player_name  = rst.Fields ("port").Value

    If LastIP <> ip_address then
      world.note " "
      world.ColourNote "white", "darkred", ip_name & ":"
      LastIP = ip_address
    End If
    
    world.ColourNote "white", "darkred", player_name

    rst.MoveNext

  Loop

  Set rst = Nothing

end sub

sub ClearList (aName, Output, Wilds)
  if Wilds(1) <> "" then
    If DoSQL _
    ("DELETE FROM IPList WHERE ip_address = " & _
          """" & Wilds(1) & """ ") Then Exit Sub
    world.ColourNote "white", "green", "IP '" & Wilds(1) & _
     "' deleted from the database"
  else
    If DoSQL("DELETE FROM IPList") Then Exit Sub
    world.ColourNote "white", "green", "All data erased."
  end if
end sub
]]>
</script> 

<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="ip:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
Sub OnHelp (sName, sLine, wildcards)
  World.Note World.GetPluginInfo (World.GetPluginID, 3)
End Sub
]]>
</script> 

</muclient>

Hopefully this all works. I haven't tested it though.

I left out some things, like the extra queries before an Add or Delete. These either work or don't, it doesn't make sense to execute an INSERT, which doesn't replace existing records anyway. It 'would' be important if we where using a database with extra data that we didn't want to get overwritten and we used the UPDATE command, but in this case it is redundant.

I also leave the Database connection open. There isn't any harm in doing this and it likely saves at least some time. Again, this 'might' be an issue if the database was remote or it was possible that the engine could disconnect when in use, but that is very unlikely here. Nick's version is nicely modularized, but is hard to fumble through and figure things out. ;)
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #9 on Tue 07 Oct 2003 01:21 AM (UTC)
Message
Ok. I got a couple errors but I fixed what I could. The following one I don't know how to fix.

Error number: -2146827286
Event: Execution of line 21 column 1
Description: Syntax error
Line in error:
function GetProvider
Called by: Immediate execution

function GetProvider
  'Uses the "version independent" provider name, to hopefully simplify matters.
  GetProvider = "Provider=Microsoft.Jet.OLEDB;Data Source=IPList.mdb;Jet OLEDB:Engine Type=5;"
end function


Then I think it will work.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #10 on Tue 07 Oct 2003 06:53 PM (UTC)

Amended on Tue 07 Oct 2003 06:55 PM (UTC) by Shadowfyr

Message
Ah.. Look at the Onsetup sub. First off, that sub should be

sub OnSetup (tName)

The timer won't work if the name isn't exactly the same. However, this is also the source for your error. If you look carefully at the error, it doesn't say anything about the contents of the function at all. It is complaining about its existance. The reason is fairly obvious, you need to add:

End Sub

to the end of the OnSetup sub, right after the 'End Select' statement. I accidently left that out, so it is complaining about a new function being defined 'before' the last sub or function has been finished. One can hope that these are the only errors, but... I am not going to hold my breath. lol
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #11 on Tue 07 Oct 2003 10:54 PM (UTC)
Message
Ah! I totally missed that. Anywho. I added the 'end sub' part and it went a little further. Got some error about expecting and end statement but that was an easy fix. Just had an extra " somewhere. But then I got this.

Error number: -2146827264
Event: Execution of line 137 column 10
Description: Expected statement
Line in error:
"ORDER BY ip_address"
Called by: Immediate execution

which I found in the List sub. Tried a couple things to try and fix it but none of them worked, so again I have to get help.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #12 on Tue 07 Oct 2003 11:36 PM (UTC)
Message
Previous line in missing the '& _'. This mean basically & - "Append another string" and _ - "The rest of this statement is on the next line of the script". So with those missing it assumes that you have finished the command, but then have a string that doesn't belong to anyone on line that produces the error.
Top

Posted by Xyborg   Canada  (47 posts)  Bio
Date Reply #13 on Wed 08 Oct 2003 03:39 AM (UTC)
Message
Fixed that and now I'm screwed again.

Error number: -2146827272
Event: Execution of line 148 column 10
Description: Expected 'Sub'
Line in error:
Exit Function
Called by: Immediate execution

Don't know which line is 148 since I use Notepad. Of course I'm always open to suggestions about good programs for this stuff. If you know any, lemme know.

Anyways. Like I said, I can't tell which line is 148 but I did look at all the lines containing Exit Funtion and around that, but I still couldn't find anything wrong.

Thanks for all the help so far guys.

We offer power to those willing to take it. Sadly, few are unburdened enough by their prejudices to accept.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #14 on Wed 08 Oct 2003 04:42 AM (UTC)
Message
To find the line number, copy the script part of the plugin, and paste into a MUSHclient notepad window. Then use Ctrl+G (go to line) to go to line 148 (or whatever).

You may need to uncheck "word wrap" in the notepad preferences (File -> Global Preferences -> Notepad) or the wrapping at the window edge might throw out the line count.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


85,225 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

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