add ip2int and int2ip functions to be able to store on pg IPV4 ip addresses
[brisk.git] / web / Obj / brisk.phh
index 546f5eb..f221518 100644 (file)
@@ -154,7 +154,7 @@ $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
 $G_lng = langtolng($G_lang);
 
 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
-$G_brisk_version = "4.18.3";
+$G_brisk_version = "4.18.5";
 
 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: Puffin riattivato, accessi da cloud disattivati, corretto bug sulla gestione di puffin, riabilitato blocco dei proxy.',
@@ -345,6 +345,20 @@ $G_PG_cons_n = 345;
     /*     printf("\n"); */
     /* } */
 
+function ip2int($s)
+{
+    $v = ip2long($s);
+    if (PHP_INT_SIZE == 4)
+        return ($v);
+
+    return ( ($v & 0x80000000 ? 0xffffffff00000000 : 0x00) | $v );
+}
+
+function int2ip($i)
+{
+    return long2ip($i & 0xffffffff);
+}
+
 function nickserv_msg($dt, $msg) {
     return sprintf('chatt_sub("%s",[0x040003,"%s"],"%s");', $dt, NICKSERV, $msg);
 }
@@ -3301,7 +3315,7 @@ function validate_name($name)
 {
     $name_new = str_replace(' ', '_', mb_substr(trim($name),0,12, "UTF-8"));
 
-  for ($i = 0 ; $i < strlen($name_new) ; $i++) {
+  for ($i = 0 ; $i < mb_strlen($name_new) ; $i++) {
     $c = $name_new[$i];
     if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
       return ($name_new);