Page 1 of 1

Telnet and PHP

Posted: Sat Dec 11, 2010 3:48 pm
by Zoey76
Hello community, I'll try to write a few functions in PHP to use telnet from a website :P

Note that commands that use a parameter needs one space.
Also you might need to use a form to submit the actions.

At the moment it's only the PHP code part.

When I get time I'll post something complete.


This is just an example:

Re: Telnet and PHP

Posted: Mon Dec 13, 2010 12:35 am
by UnAfraid
here is my version :)
[php]<?phpclass telnet {    var $ip = '127.0.0.1';    var $port = 12345;    var $timeout = 2;    var $password = 'rndpasswd?';    function command($command)     {        $fp=@fsockopen($this->ip,$this->port,$errno,$errstr, $this->timeout);        if(!$fp)            return  "<font color=#6F5A0B>Warning:</font> No telnet connection to Server.<br>";        else         {            fputs($fp, $this->password . "\r");            fputs($fp, $command . "\r");            fputs($fp,"quit\r");            $output = '';            while(!feof($fp))                $output.=fread($fp,16);            fclose($fp);            $clear_r=array("Please Insert Your Password!","Password Correct!","Welcome To The L2J Telnet Session.","[L2J]","Bye Bye!");            $output = str_replace($clear_r,"", $output);            if(strstr($output,"Incorrect Password!"))                return  "<font color=#6F5A0B>Warning:</font> Incorrect Telnet Password.<br>";            return $output;        }    }    function Execute($command)     {        return $this->command($command);    }     function give($char, $item, $count)     {        return $this->command("give " . $char . " " . $item . " " . $count . "\r");    }     function kick($char_name)    {        $this->command("kick ".$char_name."\r");    }     function stats() {        return $this->command("stats\r");    }}?>[/php]

using
[php]$telnet = new telnet;    $telnet->ip = '127.0.0.1';    $telnet->port = 12345;    $telnet->password = 'password';    $telnet->timeout = 2;    echo $telnet->Execute('help');[/php]

Re: Telnet and PHP

Posted: Fri Jan 07, 2011 6:14 am
by disorder35
I need to turn this script into telnet to give the player a coin after he vote for the server. Just the part that add the item to the players account.
Can anyone help me with that?

Thanks

Code: Select all

<?php//CONFIGS$server = 'XXXXXXXX'; //Server$database = 'XXXXXXXX'; //Database name$user = 'XXXXXXXX'; //MySQL User$pass = "XXXXXXXX"; //MySQL User Password$reward = 14720; //Item ID$reward_name = 'Event - Apiga'; //Item's Name$quantity = 1; //Quantity of the item                        //END OF CONFIGS?> <head><title>Get your reward!</title><style type="text/css">.input_field, .button1 {     background: #0c0c0c;    border: 1px solid #1c1c1c;    font-family: Verdana, Helvetica, Arial, sans-serif;    font-size: 0.90em;    padding: 3px;    color: #FFFFFF;}</style></head><body bgcolor=#0b0b0b><center><form action=vote.php method=post><font color=orange><b>Character's Name:</b></font><br><input type=text name=char class=input_field><br><input class=button1 type=submit name=reward value='Send my Reward'></form><?phpif($quantity>1){$be='were';}else{$be='was';}if(isset($_POST['reward'])){mysql_connect("$server", "$user", "$pass");mysql_select_db("$database");$char = $_POST['char'];if($char == ""){echo "<font color=red>Invalid Character's Name!</font>";}else {$microtime = explode(" ", microtime());$microtime = $microtime[1];$voteTime = 12*60*60;$voteBounds = $microtime - $voteTime;$votedToday = mysql_query("SELECT site_voted FROM voting_system WHERE ip_address = '$char' && time_voted > $voteBounds");if(mysql_num_rows($votedToday) == 0) {$result = mysql_query("SELECT * FROM voting_system WHERE ip_address LIKE '$char'") or die(mysql_error());$row_sql = mysql_fetch_assoc($result);$total = mysql_num_rows($result); if($total>0){mysql_query("UPDATE voting_system SET time_voted='$microtime' WHERE ip_address='$char'");}else {mysql_query("INSERT INTO voting_system(ip_address, time_voted, site_voted) VALUES('$char', '$microtime', '1')"); }  $query="SELECT * FROM characters WHERE char_name='$char' LIMIT 1";                 $result = mysql_query($query);                 if($row = mysql_fetch_array($result))                 {                         $id = $row['charId'];                         $acc = $row['account_name'];                         //$rec = $row['rec_have'];                                                          mysql_query("INSERT INTO items VALUES('$id', '', '$reward', '$quantity', '0', 'INVENTORY', '0', 'null', '0', '0', '-1', '-1')");                                        echo "<font color=green>Thanks for Voting!<br>$quantity $reward_name $be added to char $char </font><br><form method=post><input type=button class=button1 value='Close Window'onclick=\"window.close()\"></form>";                    }                else {                echo "<font color=red>Character Doesn't Exist!<br></font>";                }                                        }else { echo "<font color=red>You can only vote every 12 hours!</font><br><form method=post><input type=button class=button1 value='Close Window'onclick=\"window.close()\"></form>"; }}}?>

Re: Telnet and PHP

Posted: Fri Jan 21, 2011 7:25 am
by disorder35
Can anyone help me please, I need a script that will give the item to the players after they vote on all 3 sites.
I need the Item to be added in inventory in game.
Please help me.
Thank you.

Re: Telnet and PHP

Posted: Fri Jan 21, 2011 7:45 am
by seires
disorder35 wrote:Can anyone help me please, I need a script that will give the item to the players after they vote on all 3 sites.
I need the Item to be added in inventory in game.
Please help me.
Thank you.
Could you share this complete voting system?

Re: Telnet and PHP

Posted: Wed May 25, 2011 9:05 am
by Naminator_X_
Oh how much i love unsafe PHP scripts :)

Re: Telnet and PHP

Posted: Thu May 26, 2011 7:31 am
by Shadowalker
Naminator_X_ wrote:Oh how much i love unsafe PHP scripts :)
huh? your talking about mine?

Re: Telnet and PHP

Posted: Thu May 26, 2011 4:16 pm
by Naminator_X_
I was talking about the telnet script BUT i haven't yet tested yours :)

Re: Telnet and PHP

Posted: Thu May 26, 2011 10:41 pm
by Shadowalker
Naminator_X_ wrote:I was talking about the telnet script BUT i haven't yet tested yours :)
it's working fine :) if u find something let me know :P

Re: Telnet and PHP

Posted: Sun Aug 21, 2011 5:03 pm
by mochitto
I have rewrited this telnet class, that classes made for every command new connection to the server, now you can make x commands on one connection, when class is destructed, socket is clossed, or you can call disconnect() function.

My telnet class: http://pastebin.com/LpL9kgzN

Code: Select all

<?php     include "l2jTelnet.php";     //host, port, pass, timeout    $telnet = new telnet("127.0.0.1", "12345", "123456", 2);    $telnet->init();    echo $telnet->write("help");    echo $telnet->write("help");    echo $telnet->write("status");