"; $idx += $len+1; } return $ret; } function VC_PRIV_ArrayToStringList($array) { $ret = ""; foreach ($array as $i => $value) $ret = $ret . " $value"; return $ret; } function VC_PRIV_ReadSocket($socket) { $readfrom = array($socket); $select = socket_select($readfrom, $null, $null, 1); if ($select === false) return false; if ($select == 0) return ""; $line = socket_read($socket, 1024); if ($line === false) { $error = socket_last_error($socket); $errorMessage = socket_strerror($error); print "Socket Read Error(" . $error . "): " . $errorMessage . "
"; } return $line; } function VC_PRIV_ReadLine($socket) { global $VC_PRIV_READLINE_BUFFER; //print "Enter Buffer is " . $VC_PRIV_READLINE_BUFFER . "
"; while (strcspn($VC_PRIV_READLINE_BUFFER, "\r\n") == strlen($VC_PRIV_READLINE_BUFFER)) { //read some more from the socket $text = VC_PRIV_ReadSocket($socket); //print "Text is " . $text . "
"; if ($text === false) { print "FALSE
"; return false; } if ($text == "") { print "ZERO
"; return 0; } $VC_PRIV_READLINE_BUFFER = $VC_PRIV_READLINE_BUFFER . $text; //print "line is now " . $VC_PRIV_READLINE_BUFFER . "
"; } $lineLength = strcspn($VC_PRIV_READLINE_BUFFER, "\r\n"); $ret = substr($VC_PRIV_READLINE_BUFFER, 0, $lineLength); $whitespaceLength = strspn($VC_PRIV_READLINE_BUFFER, "\r\n", $lineLength); $VC_PRIV_READLINE_BUFFER = substr($VC_PRIV_READLINE_BUFFER, $lineLength + $whitespaceLength); //print "Exit Buffer is " . $whitespaceLength . " :: " . $VC_PRIV_READLINE_BUFFER . "
"; return $ret; } function VC_PRIV_Send($socket, $string) { return socket_send($socket, $string, strlen($string), 0); } function VC_PRIV_FinishConnect($socket, $ip, $port, $username, $password) { //print "Connecting to " . $ip . ":" . $port . "
"; if (socket_connect($socket, $ip, $port) === false) { socket_close($socket); return 0; } while ($line != "Please enter your username to continue:") { $line = VC_PRIV_ReadLine($socket); //print "Line is: " . $line . "
"; if ($line === false || $line == "") { socket_close($socket); return 0; } } $username = $username . "\r\n"; socket_send($socket, $username, strlen($username), 0); $line = VC_PRIV_ReadLine($socket); if ($line != "Password:") return 0; $password = $password . "\r\n"; socket_send($socket, $password, strlen($password), 0); $line = VC_PRIV_ReadLine($socket); //print "Line is " . $line . "
"; if ($line != "Password accepted. You may now admin to your whims.") { socket_close($socket); return 0; } VC_PRIV_ReadLine($socket); return $socket; } function VC_Connect_IPv4($ip, $port, $username, $password) { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!VC_PRIV_FinishConnect($socket, $ip, $port, $username, $password)) return 0; return $socket; } function VC_Connect_IPv6($ip, $port, $username, $password) { $socket = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP); if (!VC_PRIV_FinishConnect($socket, $ip, $port, $username, $password)) return 0; return $socket; } function VC_Disconnect($link) { socket_close($link); } function VC_GetClients($link) { VC_PRIV_Send($link, "GetClients\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); //this line should read "Received GetClients" $line = VC_PRIV_ReadLine($link); //this line should read "ID\tChannel\tUser\tIP\tName\tModifiers" $count = 0; $line = VC_PRIV_ReadLine($link); while ($line != "End GetClients") { if ($line == "" || $line === false) break; $info = VC_PRIV_ParseTabbedParams($line); $ret[$count] = $info; $count++; $line = VC_PRIV_ReadLine($link); } return $ret; } function VC_GetChannels($link) { VC_PRIV_Send($link, "GetChannels\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); //this line should read "Received GetChannels" $line = VC_PRIV_ReadLine($link); //this line should read "ID\tParent\tName" $count = 0; $line = VC_PRIV_ReadLine($link); while ($line != "End GetChannels") { if ($line == "" || $line === false) break; $info = VC_PRIV_ParseTabbedParams($line); $ret[$count] = $info; $count++; $line = VC_PRIV_ReadLine($link); } return $ret; } function VC_GetGroups($link) { VC_PRIV_Send($link, "GetGroups\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); //this line should read "Received GetGroups" $line = VC_PRIV_ReadLine($link); //this line should read "ID\tTag\tName" $count = 0; $line = VC_PRIV_ReadLine($link); while ($line != "End GetGroups") { if ($line == "" || $line === false) break; $info = VC_PRIV_ParseTabbedParams($line); $ret[$count] = $info; $count++; $line = VC_PRIV_ReadLine($link); } return $ret; } function VC_GetUsers($link) { VC_PRIV_Send($link, "GetUsers\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); //this line should read "Received GetUsers" $line = VC_PRIV_ReadLine($link); //this line should read "ID\tName\tGroups" $count = 0; $line = VC_PRIV_ReadLine($link); while ($line != "End GetUsers") { if ($line == "" || $line === false) break; $info = VC_PRIV_ParseTabbedParams($line); $ret[$count] = $info; $count++; $line = VC_PRIV_ReadLine($link); } return $ret; } function VC_GetBans($link) { VC_PRIV_Send($link, "GetBans\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); //this line should read "Received GetBans" $line = VC_PRIV_ReadLine($link); //this line should read "ID\tVictim\tAdmin\tIP\tSubnet\tChannelID\tTime\tExpireTime\tReason" $count = 0; $line = VC_PRIV_ReadLine($link); while ($line != "End GetBans") { if ($line == "" || $line === false) break; $info = VC_PRIV_ParseTabbedParams($line); $ret[$count] = $info; $count++; $line = VC_PRIV_ReadLine($link); } return $ret; } //$id: the ID of the user or group to be queried //returns: An array of permissions, except the first element in the array is the // ID of the user/group being queried function VC_GetServerPermissions($link, $id) { VC_PRIV_Send($link, "GetServerPermissions $id\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); if ($line != "Received GetServerPermissions") return false; //this line should read "Received GetServerPermissions" $line = VC_PRIV_ReadLine($link); $count = 0; $line = VC_PRIV_ReadLine($link); while ($line != "End GetServerPermissions") { if ($line == "" || $line === false) break; $info = VC_PRIV_ParseTabbedParams($line); $ret[$count] = $info; $count++; $line = VC_PRIV_ReadLine($link); } return $ret; } //$id: the ID of the user or group to be queried //$chan: the channel ID to be queried //returns: An array of permissions, except the first element in the array is the // ID of the user/group being queried, and the second element is the channelID function VC_GetChannelPermissions($link, $id, $chan) { VC_PRIV_Send($link, "GetChannelPermissions $id $chan\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); if ($line != "Received GetChannelPermissions") return false; //this line should read "Received GetChannelPermissions" $line = VC_PRIV_ReadLine($link); $count = 0; $line = VC_PRIV_ReadLine($link); while ($line != "End GetChannelPermissions") { if ($line == "" || $line === false) break; $info = VC_PRIV_ParseTabbedParams($line); $ret[$count] = $info; $count++; $line = VC_PRIV_ReadLine($link); } return $ret; } function VC_GetChannelAuthList($link, $channelid) { VC_PRIV_Send($link, "GetChannelAuthList $channelid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); $index = 0; $ret = array(); for ($line = VC_PRIV_ReadLine($link); $line != "" && $line !== false; $line = VC_PRIV_ReadLine($link)) { if ($line == "End GetChannelAuthList") break; $ret[$index] = $line; $index++; } return $ret; } function VC_GetChannelAutoMods($link, $channelid) { VC_PRIV_Send($link, "GetChannelAutoMods $channelid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); $index = 0; $ret = array(); for ($line = VC_PRIV_ReadLine($link); $line != "" && $line !== false; $line = VC_PRIV_ReadLine($link)) { if ($line == "End GetChannelAutoMods") break; $ret[$index] = $line; $index++; } return $ret; } function VC_GetChannelAutoVoices($link, $channelid) { VC_PRIV_Send($link, "GetChannelAutoVoices $channelid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); $index = 0; $ret = array(); for ($line = VC_PRIV_ReadLine($link); $line != "" && $line !== false; $line = VC_PRIV_ReadLine($link)) { if ($line == "End GetChannelAutoVoices") break; $ret[$index] = $line; $index++; } return $ret; } function VC_GetServerOptions($link) { VC_PRIV_Send($link, "GetServerOptions\r\n"); $line = VC_PRIV_ReadLine($link); $ret = array(); $line = VC_PRIV_ReadLine($link); $ret[0] = substr($line, strcspn($line, ":") + 1); $line = VC_PRIV_ReadLine($link); $ret[1] = substr($line, strcspn($line, ":") + 1); $line = VC_PRIV_ReadLine($link); $ret[2] = substr($line, strcspn($line, ":") + 1); $line = VC_PRIV_ReadLine($link); $ret[3] = substr($line, strcspn($line, ":") + 1); return $ret; } function VC_GetServerMOTD($link) { //WARNING: this doesn't currently work with multiple newlines in a row // because VC_PRIV_ReadLine will strip all newlines VC_PRIV_Send($link, "GetServerMOTD\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); $ret = ""; $newlineCount = 0; while (($line = VC_PRIV_ReadLine($link)) != "End GetServerMOTD") { if ($line == "") { //WARNING: empty lines could mean that it really is an empty line or we're waiting on the socket //if there's more than 5 newlines in a row, assume that the socket is having trouble $newlineCount++; if ($newlineCount > 5) break; } else $newlineCount = 0; if ($line === false) break; if ($ret == "") $ret = $line; else $ret = $ret . "
" . $line; } return $ret; } function VC_ServerPermissionUpdate($link, $id, $perm, $newstate) { VC_PRIV_Send($link, "ServerPermissionUpdate $id $perm $newstate\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerPermissionUpdate: SUCCESS"; } function VC_ChannelPermissionUpdate($link, $id, $chanid, $perm, $newstate) { VC_PRIV_Send($link, "ChannelPermissionUpdate $id $chanid $perm $newstate\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelPermissionUpdate: SUCCESS"; } function VC_Kick($link, $clientid, $reason) { VC_PRIV_Send($link, "Kick $clientid $reason\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "Kick: SUCCESS"; } function VC_Ban($link, $clientid, $reason) { VC_PRIV_Send($link, "Ban $clientid $reason\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "Ban: SUCCESS"; } function VC_Move($link, $clientid, $chanid) { VC_PRIV_Send($link, "Move $clientid $chanid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "Move: SUCCESS"; } function VC_ServerMOTD($link, $motd) { $motd = str_replace("\r\n", "\\n", $motd); $motd = str_replace("\n", "\\n", $motd); $motd = str_replace("\r", "\\n", $motd); VC_PRIV_Send($link, "ServerMOTD $motd\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerMOTD: SUCCESS"; } function VC_BanRemove($link, $banid) { VC_PRIV_Send($link, "BanRemove $banid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "BanRemove: SUCCESS"; } //NOTE: modifiers can be either an absolute value or an "offset" // For example, to add the muted modifier without modifying any other modifiers, // pass "+1", or to remove the muted modifier, pass "-1" function VC_ClientModifiers($link, $clientid, $modifiers) { VC_PRIV_Send($link, "ClientModifiers $clientid $modifiers\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ClientModifiers: SUCCESS"; } //NOTE: password is ignored if the joinMethod is not "passworded" function VC_ChannelCreate($link, $parentid, $joinMethod, $name, $password) { VC_PRIV_Send($link, "ChannelCreate $parentid $joinMethod \"$name\" \"$password\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelCreate: SUCCESS"; } function VC_ChannelName($link, $chanid, $name) { VC_PRIV_Send($link, "ChannelName $chanid \"$name\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelName: SUCCESS"; } function VC_ChannelComment($link, $chanid, $comment) { VC_PRIV_Send($link, "ChannelComment $chanid \"$comment\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelComment: SUCCESS"; } //NOTE: modifiers can be an absolute value or an "offset" // see VC_ClientModifiers for details function VC_ChannelModifiers($link, $chanid, $modifiers) { VC_PRIV_Send($link, "ChannelModifiers $chanid $modifiers\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelModifiers: SUCCESS"; } function VC_ChannelJoinMethod($link, $chanid, $joinmethod, $password) { $out = "ChannelJoinMethod $chanid $joinmethod"; if ($joinmethod == 1) $out = $out . " \"$password\""; $out = $out . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelJoinMethod: SUCCESS"; } //NOTE: All "$ids" parameters below should be an array of user/group IDs function VC_ChannelAuthAdd($link, $chanid, $ids) { $out = "ChannelAuthAdd $chanid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelAuthAdd: SUCCESS"; } function VC_ChannelAuthRemove($link, $chanid, $ids) { $out = "ChannelAuthRemove $chanid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelAuthRemove: SUCCESS"; } function VC_ChannelAutoModAdd($link, $chanid, $ids) { $out = "ChannelAutoModAdd $chanid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelAutoModAdd: SUCCESS"; } function VC_ChannelAutoModRemove($link, $chanid, $ids) { $out = "ChannelAutoModRemove $chanid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelAutoModRemove: SUCCESS"; } function VC_ChannelAutoVoiceAdd($link, $chanid, $ids) { $out = "ChannelAutoVoiceAdd $chanid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelAutoVoiceAdd: SUCCESS"; } function VC_ChannelAutoVoiceRemove($link, $chanid, $ids) { $out = "ChannelAutoVoiceRemove $chanid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelAutoVoiceRemove: SUCCESS"; } function VC_ChannelDelete($link, $chanid) { VC_PRIV_Send($link, "ChannelDelete $chanid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ChannelDelete: SUCCESS"; } function VC_UserCreate($link, $name, $password) { VC_PRIV_Send($link, "UserCreate \"$name\" \"$password\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "UserCreate: SUCCESS"; } function VC_UserPassword($link, $userid, $password) { VC_PRIV_Send($link, "UserPassword $userid \"$password\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "UserPassword: SUCCESS"; } function VC_UserGroupAdd($link, $userid, $ids) { $out = "UserGroupAdd $userid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "UserGroupAdd: SUCCESS"; } function VC_UserGroupRemove($link, $userid, $ids) { $out = "UserGroupRemove $userid" . VC_PRIV_ArrayToStringList($ids) . "\r\n"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "UserGroupRemove: SUCCESS"; } function VC_UserDelete($link, $userid) { VC_PRIV_Send($link, "UserDelete $userid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "UserDelete: SUCCESS"; } function VC_GroupCreate($link, $name) { VC_PRIV_Send($link, "GroupCreate \"$name\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "GroupCreate: SUCCESS"; } function VC_GroupName($link, $groupid, $name) { VC_PRIV_Send($link, "GroupName $groupid \"$name\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "GroupName: SUCCESS"; } function VC_GroupTag($link, $groupid, $tag) { VC_PRIV_Send($link, "GroupTag $groupid \"$tag\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "GroupTag: SUCCESS"; } function VC_GroupDelete($link, $groupid) { VC_PRIV_Send($link, "GroupDelete $groupid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "GroupDelete: SUCCESS"; } function VC_AllowRegister($link, $clientid) { VC_PRIV_Send($link, "AllowRegister $clientid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "AllowRegister: SUCCESS"; } function VC_ServerJoinPassword($link, $password) { VC_PRIV_Send($link, "ServerJoinPassword \"$password\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerJoinPassword: SUCCESS"; } function VC_ServerAdminPassword($link, $password) { VC_PRIV_Send($link, "ServerAdminPassword \"$password\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerAdminPassword: SUCCESS"; } function VC_ServerGuestRegistration($link, $enable) { VC_PRIV_Send($link, "ServerGuestRegistration $enable\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerGuestRegistration: SUCCESS"; } function VC_ServerIdleOperation($link, $op, $timeout, $channelid) { $out = "ServerIdleOperation $op"; if ($op != 0) { $out = $out . " $timeout"; if ($op == 1) //move to channel { $out = $out . " $channelid"; } } $out = $out . "\r\n"; print $out . "
"; VC_PRIV_Send($link, $out); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerIdleOperation: SUCCESS"; } function VC_ServerDefaultChannel($link, $channelid) { VC_PRIV_Send($link, "ServerDefaultChannel $channelid\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerDefaultChannel: SUCCESS"; } function VC_ServerMaxDuplicateIPs($link, $numIPs) { VC_PRIV_Send($link, "ServerMaxDuplicateIPs $numIPs\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerMaxDuplicateIPs: SUCCESS"; } function VC_ServerVoiceQuality($link, $quality) { VC_PRIV_Send($link, "ServerVoiceQuality $quality\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerVoiceQuality: SUCCESS"; } function VC_ServerMaxClients($link, $maxClients) { VC_PRIV_Send($link, "ServerMaxClients $maxClients\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); return $line == "ServerMaxClients: SUCCESS"; } function VC_SearchLog($link, $startTimeOffset, $endTimeOffset, $searchString) { VC_PRIV_Send($link, "SearchLog $startTimeOffset $endTimeOffset \"$searchString\"\r\n"); $line = VC_PRIV_ReadLine($link); $line = VC_PRIV_ReadLine($link); $ret = array(); if (substr($line, 0, 9) != 'SearchLog') return $ret; $line = VC_PRIV_ReadLine($link); $index = 0; while ($line != "SearchLog End" && $line !== false && $line != "") { $ret[$index] = $line; $index++; $line = VC_PRIV_ReadLine($link); } return $ret; } ?>