Kolbot to iDB Integration

Description

After kolbot finishes a mule character, its expiration date, items, gold, socket quest and imbue quest get published to iDB. This removes the need to log all your mules manually via iDB or iDB-Web.

Tips

If kolbot fails to send to iDB, it will write details into file: \d2bs\kolbot\iDB-Failed-[database name].txt in format: [realm]/[account]/[password]/[character name].

How To

\d2bs\kolbot\libs\OOG.js

Make sure you are loading iDB.js on bot initialization:
var D2Bot = {
    handle: 0,
    init: function() {
        var handle = DataFile.getStats().handle;
        if (handle) {
            this.handle = handle;
        }
        var s = getScript("tools/iDB.js");
        if (!s || !s.running) {
            load("tools/iDB.js");
        }
        return this.handle;
    },
Or if you already have a script like AutoPerm:
var D2Bot = {
    handle: 0,
    init: function() {
        var handle = DataFile.getStats().handle;
        if (handle) {
            this.handle = handle;
        }
        var s = getScript("tools/AutoPerm.js");
        if (!s || !s.running) {
            if (FileTools.exists("tools/AutoPerm.js")) {
                load("tools/AutoPerm.js");
            }
        }
        s = getScript("tools/iDB.js");
        if (!s || !s.running) {
            load("tools/iDB.js");
        }
        return this.handle;
    },

\d2bs\kolbot\libs\MuleLogger.js

Add LogToiDB flag:
LogToiDB: true,
LogToShop: false,
SendToSite: false,
LogGame: ["", ""],
LogNames: false,
LogItemLevel: true,
LogEquipped: false,
LogMerc: false,
SaveScreenShot: false,
IngameTime: rand(10, 20),
getItemDesc: function (unit, logIlvl) {
Near the very bottom, add the code to trigger logging:
if (this.LogToiDB) {
    var iDBDoneLogging, tick = getTickCount();
    addEventListener("scriptmsg", function (msg) {
        if (msg && typeof msg === "string" && msg === "iDBDoneLogging") {
            iDBDoneLogging = true;
        }
    });
    scriptBroadcast("iDBLog");
    while (!iDBDoneLogging && getTickCount() ‐ tick < 10000) {
        delay(100);
    }
}
FileTools.writeText("mules/" + realm + "/" + me.account + "/" + me.name + …
print("Item logging done.");
If you want to save Horadric Cube data, comment or remove this line:
trash = [
    ..
    547, //Golden Bird
    548, //Lamesen's Tome
//    549, //Horadric Cube
    550, //Horadric Scroll
    551, //Mephisto's Soulstone
    ..	
];

\d2bs\kolbot\libs\common\Misc.js

Search for "randomString", if you don't have it, add it into the Misc definition:
var Misc = {
    randomString: function (len, num) {
        let possible = 'abcdefghijklmnopqrstuvwxyz';
        if (num) {
            possible += '0123456789';
        }
        let text = '';
        for (let i = 0; i < len; i += 1) {
            text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    },

\d2bs\kolbot\tools\iDB.js

Download
Extract and place iDB.js into tools folder then configure the top section.
iDBdatabaseName Name of the database in iDB that you want to publish to (if it doesn't exist, the database will be created automatically)
iDBaddress localhost or 127.0.0.1 to point at the local machine
Otherwise, use the target's IP or host name
Don't forget to open the firewall & setup port forwarding on the target server!
iDBport Typically 7337 unless the TCP-Port has been changed on iDB
iDBloginName Leave blank
iDBloginPass Leave blank
defPass Default password to use in case password lookup fails (it's a good idea to use fail or something similar so you know when the script is having trouble looking up the correct password from your mule config)
whitelistedProfiles List of all the profiles that should publish to iDB (automules, muleloggers and droppers do not have to be listed!)
whitelistedProfiles: [
    "TestProfile",
    "MyOtherProfile"
]
blacklistedProfiles List of all the profiles that should not publish to iDB (even if they are automules, muleloggers, droppers, etc.)
blacklistedProfiles: [
    "TestProfile",
    "MyOtherProfile"
]

Troubleshooting

Error: Invalid hostname specified

If you try to use the latest D2BS.dll created by Noah you might notice you can't send items to iDB anymore. That is because a domain whitelist was added to d2bs.ini.

You can verify that you are affected by checking the logs in your \d2bs\logs\ folder and looking for the following error message: Error: Invalid hostname specified.

Solution

You can either add your iDBaddress to the whitelist in d2bs.ini OR take the recommended option of replacing your current D2BS.dll with this one: https://github.com/jaenster/jaenster-kolbot/raw/jaenster/autoplay/d2bs/D2BS.dll.

Items disappearing after drop attempt

You can easily recognize this error by seeing drops fail due to account login failed - invalid account or password. You can then verify that the kolbot to iDB script is having trouble collecting the true password by finding messages like [realm]/[account]/[password]/[character] - failed to find password, using default in your \d2bs\kolbot\iDB-Failed-[database name].txt log file.

iDB.js looks in MuleLogger.js and AutoMule.js for passwords. If there's no match, it uses defPass in iDB.js settings. If using a kolbot script that makes accounts with randomized passwords (eg. Laz's Runeword Maker), this will be problematic.

Solution

Disable randomized passwords on newly created accounts in whatever custom kolbot script(s) you're using. Set the password to match your defPass (from iDB.js settings).

Changelog

2020-10-05: v1.10

  • UPD Accounts are logged to file when password determination fails

2020-07-31: v1.9

  • ADD Added logging by default for automule, mulelogger and dropper profiles as well as support for profile whitelisting / blacklisting

2020-02-03: v1.8

  • ADD Added support for gold, imbue, socket

2019-12-28: v1.7

  • ADD Added character name to the failure logging

2019-12-16: v1.6

  • FIX Wait for all incoming packets to process before publishing to iDB

2019-12-16: v1.5

  • ADD Added logging on failure

2019-05-30: v1.0

  • ADD Initial