Jump to content
Eternal Lands Official Forums
Sign in to follow this  
monneyman

how do u make

Recommended Posts

By reading all the stickied information available on the topic, and doing searches. <_<

Edited by crusadingknight

Share this post


Link to post
Share on other sites
how do u make a bot

206120[/snapback]

 

 

Hi. Here is some code that works good, to maybe help you get the idea of what needs to be done. This is a little program that just sits on the EL and just stands there. But the important thing is it logs in and stands there. Maybe it will help someone to develop some more code from it. This is written in a cool language called Qore. It is fast becomming one of my favorite languages. You can find it on http://www.freshmeat.net and search for Qore. Compile the language from the cvs to run this correctly. I think this will only runs on Unix, but will help with ideas still.

 

#!/usr/local/bin/qore

sub logfile($s) {
printf("%s", $s);
fflush();
}

sub connect() {
printf("Connecting as %s...", $nick);
$el = new Socket();
$el.connect("62.93.225.26:2000");
printf("Connected (socket %d).\n",$el.getSocket());
}

sub disconnect() {
$el.close();
printf("%s disconnected.\n", $nick);
}

sub D($packet) {
my $buffer_ord = "";
my $length = strlen($packet);
for (my $i=0; $i < $length; $i++) {
 $buffer_ord = $buffer_ord + sprintf("%d ", ord(substr($packet, $i, 1)));
}
return $buffer_ord;
}

sub receive_packet() {
if (!$el.isDataAvailable()) {
 return;
}
my $command = ord($el.recv(1));
logfile(sprintf("Command:%d, ",$command));
my $lowbyte_len = ord($el.recv(1));
my $hibyte_len = ord($el.recv(1)) * 256;
my $length = $lowbyte_len + $hibyte_len - 1;
logfile(sprintf("Length:%d, ",$length));
my $buffer = $el.recv($length);
if ($buffer == -1) {
 print("They killed us.\n");
 $el.close();
 exit();
}
my $buffer_ord = D($buffer);
logfile(sprintf("Packet:%s\n", $buffer_ord));
#	logfile(sprintf("p:%s", $buffer));
parse_packet($command, $buffer);
}


sub parse_packet($command, $packet) {
if ($command == 0) {
 my $channel = ord(substr($packet, 0, 1));
 logfile(sprintf("Channel %d\n", $channel));
 my $color = ord(substr($packet, 1, 1));
 logfile(sprintf("Color %d\n", $color));
# once this is all settled, put into an array so just one statement
 if ($channel == 0) {
 	printf("%s", substr($packet, 2, strlen($packet) - 2));
 }
 if ($channel == 1) {
 }
 if ($channel == 2) {
 }
 if ($channel == 3) {
 	if ($color == 144) {
   printf("%s[#32m", chr(27));
   $el.send($LOG_IN_PACKET);
 	} else {
   printf("Color not found: %d\n", $color);
 	}
 	printf("%s%s[#0m", substr($packet, 2, strlen($packet) - 2), chr(27));
 }
 if ($channel == 4) {
 }
 if ($channel == 5) {
 }
}
if ($command == 2) {
}
if ($command == 5) {
}
if ($command == 19) {
 print("Here your inventory\n");
}
if ($command == 60) {
}
if ($command == 251) {
 logfile(sprintf("%s[#31m%s%s[#0m", chr(27), substr($packet, 0, strlen($packet)), chr(27)));
 disconnect();
 exit();
}
}

sub event_loop() {
while (1) {
 $now = mktime(now());
 if ($now - $then > 30) {
 	$el.send($HEART_BEAT_PACKET);
 	$then = $now;
 }	
 receive_packet();
}  
}


$nick = "your-username-here";
$pass = "your-password-here";
$debug = 1;

# ----- Set up the fixed packets now, to make it faster later
$PING_PACKET = sprintf("%s%s%s%s%s%s%s", chr(13), chr(5), chr(0), chr(0), chr(7), chr(7), chr(7));
$HEART_BEAT_PACKET = sprintf("%s%s%s", chr(14), chr(1), chr(0));
$LOG_IN_PACKET = sprintf("%s%s%s%s %s%s", chr(140), chr(strlen($nick) + strlen($pass) + 3), chr(0), $nick, $pass, chr(0));
$SEND_MY_INVENTORY_PACKET = sprintf("%s%s%s%s%s%s%s%s", chr(18), chr(6), chr(0), chr(0), chr(0), chr(0), chr(0), chr(0));


# ----- Set up time stuff
$then = mktime(now());
$now = $then;

connect();
event_loop();
disconnect();

Share this post


Link to post
Share on other sites
Hi. Here is some code that works good, to maybe help you get the idea of what needs to be done.

207138[/snapback]

 

Hello

 

Thank you Wicca for the code. I'll try to use it later in my linux box and tell you about my experience.

 

At this moment i need to refresh my Java knowledge (i don't code anything since long time) because i'm going to work in a pair of big projects. So i've decided to play with the new NetBeans 5.0 IDE and code a bot for EL, nothing serious, for training.

 

To start, i will try to translate your code to Java (yeah, i know it will look too easy for most of you, but for me it will be an intense remembering of java). If i get something decent, i will post it here.

 

I took a look to dns's Jelc, it's awesome and very complete, but the project seems to be stopped and it crashes just after connect (maybe the protocol has changed since it was coded).

 

I think that your code will help me to understand the basic elements of the protocol, maybe later i can take a deeper look to Jelc.

 

Thanks again.

 

Regards

Share this post


Link to post
Share on other sites
how do u make a bot

206120[/snapback]

 

Here is an old example in TCL.

To run it, install Tcl and type:

tclsh tclbot.tcl

 

It will sit on EL and just stand there, and report incomming packets. At least it logs you in and waits. Maybe someone can use it or understand bots better this way. This is a shrt amount of code used in the old Quartermaster and MadameYes bots.

#! /usr/bin/tclsh


# to run this bot, make sure you have Tcl installed.
# "tclsh tclbot.tcl"  <-- to run it


set botname "your-bots-nickname"
set botpass "your-bots-password"
set server "62.93.225.26"
set port "2000"



proc WriteSocketData {str} {

global sock

global connected

set connected 1

if {[string length $str] == 0} {

 puts "ERROR: WriteSocketData: no str"

 return 0

}

if [catch {eof $sock}] {

 puts "(3) Socket closed."

 catch {close $sock}

 return

}

puts -nonewline $sock $str

flush $sock

}



proc SendHeart_Beat {} {

set HEART_BEAT 14

set NULL 0

set s [binary format ccc $HEART_BEAT [string length $NULL] $NULL]

WriteSocketData $s

}



proc SendLogin {login} {

puts "Sending login..."

set NULL 0

set LOG_IN 140

if {[string length $login] == 0} {

 puts "ERROR: SendLogin: no login"

 return

}

set s [binary format ccca[string length $login]c $LOG_IN [expr [string length $login] + 1 + 1] $NULL $login $NULL]

WriteSocketData $s

}



proc ReadSocketData {} {

global sock

global connected

global forever

if [eof $sock] {

 puts "(2) Socket closed"

 catch {close $sock}

 set forever 1

 return -1

}

if [catch {set raw_data [read $sock]}] {

 puts "Connection timed out."

 catch {close $sock}

 return -1

}

if {($raw_data <= 0) && [eof $sock]} {

 puts "(1) They disconnected us."

 catch {close $sock}

 set forever 1

 return -1

}

set connected 1

binary scan $raw_data c[string length $raw_data] indexed_data

for {set i 0} {$i < [llength $indexed_data]} {incr i} {

 if {[lindex $indexed_data $i] < 0} {

 	set indexed_data [lreplace $indexed_data $i $i [expr 256 + [lindex $indexed_data $i]]]

 }

}

fconfigure $sock -translation binary -buffering line -buffersize 512 -blocking 1

while {1} {

 set l [expr [lindex $indexed_data 1] + ([lindex $indexed_data 2] * 256)]

 set packetI [lrange $indexed_data 0 [expr $l + 1]]

 set packetR [string range $raw_data 0 [expr $l + 1]]

 if {[llength $indexed_data] == [expr $l + 2]} {

 	ReadSocketData1 "$packetR" "$packetI"

 	break

 }

 ReadSocketData1 "$packetR" "$packetI"



 set indexed_data [lrange $indexed_data [expr $l + 2] end]

 set raw_data [string range $raw_data [expr $l + 2] end]

}

fconfigure $sock -translation binary -buffering none -blocking 0


}


# You'll want to tinker with this... it is the commands from the EL server
# Each packet comes here, and this code deals with it

proc ReadSocketData1 {raw_data indexed_data} {

switch [lindex $indexed_data 0] {
 1	{
 	puts "Something came into view Animal? Person?"
 }
 2	{
 	puts "Something is moving: $indexed_data"
 }
 3	{
 	puts "You are..."
 }
 5	{
 	puts "A new game-minute"
 }
 6	{
 	puts "Someone left the area. This packet tells who!"
 }
 15	{
 	puts "It started to rain"
 }
 27	{
 	puts "A new bag came. This packet tells where!"
 }

 250	{

 	puts "Login OK."

 }

 251	{

 	puts "Login not OK."

 }

 default	{

 	puts $indexed_data

 }

}

}



proc EventLoop {} {

global heart_start

global sock

global forever

if {[clock seconds] - $heart_start > 25} {

 set heart_start [clock seconds]

 SendHeart_Beat

}

}


set heart_start [clock seconds]
set connected 0


puts "Running on $tcl_platform(platform): $tcl_platform(os): $tcl_platform(osVersion): $tcl_platform(machine)"

while {1} {

puts "Entering startup loop..."



if [catch {set sock [socket $server $port]}] {

 puts "Host is unreachable, trying again..."

 after 3000

 continue

}

puts "Configuring socket..."

fconfigure $sock -translation binary -buffering none -blocking 0

fileevent $sock readable [list ReadSocketData]

fileevent $sock writable [list EventLoop]

catch {vwait connected}

puts "Connected"

set connected 0

catch {vwait connected}

after 1000

SendLogin "$botname $botpass"

puts "Entering event loop, here we go..."

if [catch {eof $sock}] {

 puts "(4) Socket closed."

 catch {close $sock}

 after 3000

 continue

}

fileevent $sock readable [list ReadSocketData]

fileevent $sock writable [list EventLoop]

set forever 0

after 3000

catch {vwait forever}

puts "Disconnected."

}




Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×