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. ;) |