Skip to forum content

You are not logged in. Please login or register.


forums.pvpgn.pro → 3d Party Tools → [Script] Simple PHP function for D2GS telnet commands

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 1

1 (edited by htorbov 02.12.2017 23:11)

Topic: [Script] Simple PHP function for D2GS telnet commands

Inspired by https://github.com/pvpgn/d2smanager-api:

<?php
// Command
$telnet = Telnet('maxuser 200');

if($telnet == 'Yes') {
    echo 'Maximum users has been updated.';
}
else {
    echo $telnet;
}

// Function
function Telnet($command, $host = '127.0.0.1', $port = '8888', $password = 'abcd123') {
    $handler = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

    if($handler) {
        socket_set_option($handler, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 3, 'usec' => 0));

        if(@socket_connect($handler, $host, $port)) {
            while($out = @socket_read($handler, 1024)) {
                if(preg_match('/Password:/i', $out)) {
                    break;
                }
            }

            socket_write($handler, $password . "\n", strlen($password) + 1);

            while($out = @socket_read($handler, 1024)) {
                if(preg_match('/D2GS>/i', $out)) {
                    $logged = 1;
                }
                if(preg_match('/Sorry!/i', $out)) {
                    $logged = 0;
                }
            }

            if($logged == 1) {
                socket_write($handler, $command . "\n", strlen($command) + 1);

                $result = 'Yes';
            }
            else {
                $result = 'Incorrect password for socket.';
            }
        }
        else {
            $result = 'Error Connecting Telnet: ' . socket_strerror(socket_last_error());
        }

        socket_close($handler);
    }
    else {
        $result = 'Error Creating Socket: ' . socket_strerror(socket_last_error());
    }

    return $result;
}
?>

Posts: 1

Pages 1

You must login or register to post a reply

Who now at forum

Currently view post: 1 guest, 0 registered users

forums.pvpgn.pro → 3d Party Tools → [Script] Simple PHP function for D2GS telnet commands



Generated in 0.049 seconds (74% PHP - 26% DB) with 20 queries