what should I be using in the datawritter for varbinary(16) (storing IPs)

tenants

Well-known member
I was using this, and it works 99% of the time:

Code:
'ip_address'    => array('type' => self::TYPE_STRING)

but I've noticed a bug when logging certain IP address (it's rare), and for me only causes a logging empty field.

When this happened, I think, or I believe the original IP was '172.94.59.10', this was grabbed with

Code:
'XenForo_Helper_Ip::getBinaryIp();

then got stored as a var binary 16 in the database as ac5e3b

but this returns false when using XenForo_Helper_Ip::convertIpBinaryToString($binIP);

I suspect is has something to do with using the TYPE_STRING in the datawritter rather than something binary, what should I be using?

The core doesn't use a datawritter for storing IPs, and does it directly from the model, so I cant find a good example

Code:
        $this->_getDb()->insert('xf_ip', array(
            'user_id' => $userId,
            'content_type' => $contentType,
            'content_id' => $contentId,
            'action' => $action,
            'ip' => $ipAddress,
            'log_date' => max(0, $date)
        ));
 
Last edited:
The core doesn't use a datawritter for storing IPs, and does it directly from the model, so I cant find a good example
Look at the ModeratorLog DataWriter. Just set the ip_address field as the standard IP string, and then have a verify method such as in that DW which converts the string to the binary format before saving.

That all said, I'm not sure what would be wrong with the approach you've taken for that to fall over, but worth, at the very least, modelling it on the way ModeratorLog DW does it to see if that makes any discernible difference.
 
Ah ha, thanks Chris, it looks like a simple cast will fix it

Code:
 (string)XenForo_Helper_Ip::convertIpStringToBinary()
 
Back
Top Bottom