Telnet and PHP

Have you created a useful tool? or Do you want to get help building one? This is the right place!
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7005
Joined: Tue Aug 11, 2009 3:36 am

Telnet and PHP

Post 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:
You do not have the required permissions to view the files attached to this post.
Powered by Eclipse 4.30 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Telnet and PHP

Post 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]
Image
User avatar
disorder35
Posts: 700
Joined: Sat Aug 01, 2009 3:29 pm

Re: Telnet and PHP

Post 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>"; }}}?>
So What?????
User avatar
disorder35
Posts: 700
Joined: Sat Aug 01, 2009 3:29 pm

Re: Telnet and PHP

Post 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.
So What?????
seires
Posts: 73
Joined: Wed Dec 14, 2005 5:24 pm

Re: Telnet and PHP

Post 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?
Naminator_X_
Posts: 39
Joined: Thu Jun 10, 2010 9:06 am

Re: Telnet and PHP

Post by Naminator_X_ »

Oh how much i love unsafe PHP scripts :)
Shadowalker
Posts: 2
Joined: Sun May 22, 2011 1:47 pm
Contact:

Re: Telnet and PHP

Post by Shadowalker »

Naminator_X_ wrote:Oh how much i love unsafe PHP scripts :)
huh? your talking about mine?
Naminator_X_
Posts: 39
Joined: Thu Jun 10, 2010 9:06 am

Re: Telnet and PHP

Post by Naminator_X_ »

I was talking about the telnet script BUT i haven't yet tested yours :)
Shadowalker
Posts: 2
Joined: Sun May 22, 2011 1:47 pm
Contact:

Re: Telnet and PHP

Post 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
mochitto
Posts: 87
Joined: Fri Jul 18, 2008 2:27 pm
Location: Slovakia

Re: Telnet and PHP

Post 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"); 
You do not have the required permissions to view the files attached to this post.
Sorry for my bad english.
Post Reply