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

createing a bot useing jelc

Recommended Posts

this guilde shows how to create a fully functional bot useing JELC which stands for JAVA Eternal Lands Client. it is a project to create an EL Client in java, there is a basic el client which is mainly useful for chatting. if you would like to help contact me or frak and we can add your code to the project.

 

You need to download and install the Java 5 SDK as i have used that API to build it.

next you need to get the jelc library from cvs, this should contain:

\bots\deadface\* - this contains the deadface verson 1 code, it is a big and complex bot and really monolythic in it's design.

\bots\deadface2\* - this is the code for deadface/iknow/knoppy and perhaps a fiew other bots.

\elc\* - this contains all the libraries requried for your bot.

\elc\gui\* - this is my attempt at a java gui client, it currently is just a chat client.

\playerView\* - this is a library that parses the 'who's online' pages as well as parses the players stats pages.

 

important classes:

\bots\SimpleBot.java - this is a simple demonstration of a bot that just replys 'hi username' when you say hi. this is based on Client.java if you want to start from scratch you could use this as a starting point.

 

\bots\deadface\MyBot.java - this is the main class, commands are processed by: void processCommands(String person, String message, int type) and public void replyMessage(String name,String message,int type) is called to send the message through the right channel.

 

\bot\deadface2\MyBot2.java - the main class for deadface2.

 

Adding functionality to deadface2:

 

the easyest way to add functionality to deadface2 is to use one of the existing classes as a basis of your new function, the simplest one i have is hi.java

 

public class Func implements BotCommand {
MyBot2 bot;
Func(MyBot2 bot){
 this.bot=bot;
}
public boolean process(String name, String[] args, int type) {
 if(args[0].equalsIgnoreCase("func")||args[0].equalsIgnoreCase("#func")){//looks for 'funk' as the first parameter
 	bot.reply(name,"message to send back",type);
 	return true; //returns true to say that it did some processing
 }
 return false; //it has not processed, if no functions process it will return an error saying it was a bad command
}

public void sendHelp(String name, int type) {
 bot.reply(name,"put your help message here",type); //command descrption for the 'help' command
}
public void onQuit() {
 //put your quit code here such as saveing lists to a file, called when the application quits
}

}

 

 

now you have creatred a new function you need to register it in the bot, do this by adding a line to MyBot2 's constructor, you will need to add something like:

this.addBotListener(new Func(this));

 

just compile it and run it with:

java bots.deadface2.MyBot2 username password

Edited by dns_server

Share this post


Link to post
Share on other sites

Thanks for this great work!

 

I use JELC for my recently created bot and I want to detect when a player want to trade with my bot. Is this already implemented, if yes could you tell me how?

Share this post


Link to post
Share on other sites

    public void onSystemMessage(String message){
   	
   	StringTokenizer st=new StringTokenizer(message," ");
   	String person=st.nextToken();
   	if(st.nextToken().equals("wants")&&st.nextToken().equals("to"))
   	{
     System.out.println("---"+person+" wants to trade");
     try{Thread.sleep(700);}catch(Exception e){e.printStackTrace();}
     tradeName = person;
     Hashtable hash=this.getActors();
     Iterator i=hash.values().iterator();
     while(i.hasNext()){
     	Actor tmp=(Actor)i.next();
     	if(tmp.getActor_name().contains(person)){
       System.out.println(tmp);
       tradeWith(tmp);
       onTrade();
     	}
     }
     return;
   	}
   	st=new StringTokenizer(message," ");
   	person=st.nextToken();
   	if(st.nextToken().equals("aborted")&&st.nextToken().equals("the"))
   	{
     System.out.println("---"+person+" aborted the trade");
     tradeName = null;
     abortTrade();
     return;
   	}
   }

shouuld be enough to atleast detect when someone wants to trade.

I have some of gamblers code and i am trying to work out how to get tradeing working in a logical manner.

Share this post


Link to post
Share on other sites
where do i get the program to make a bot, and dose it cost money? i wanna evil bot. :inquisitive:  mwa ha ha ha ha!!

208339[/snapback]

 

It is not like you download a program, tell it what color your bots hair should be and you are all set. You have to have some knowledge about programming. JELC provides an excellent basis if you know some Java. Go learn it :P

Share this post


Link to post
Share on other sites

I dont think the jelc client ever supported any trade/storage protocols at all. So if you want to trade you will have to write the code yourself. (If its any good, i am sure the project would appreciate any code donations :D)

Share this post


Link to post
Share on other sites
this guilde shows how to create a fully functional bot useing JELC which stands for JAVA Eternal Lands Client.

 

DNS,

The DeadFace2 code in CVS seems to be missing the containsName method in PlayerList.java. This causes errors in Guild.java and News.java.

Share this post


Link to post
Share on other sites

It'll be a pain with the current package structure.

 

I'll export an ANT script when I get home, unless DNS can do it

Share this post


Link to post
Share on other sites
Thanks, that would be great!

216428[/snapback]

Ok, ant build.xml commited. You'll need to make sure you have xerces.jar, xalan.jar and xml-apis.jar in the same directory as build.xml.

Share this post


Link to post
Share on other sites

Thanks, but when I run ant I get the following error:

java.io.FileNotFoundException: ./build-user.xml (No such file or directory)

Edited by squiz

Share this post


Link to post
Share on other sites

Thanks, but when I run ant I get the following error:

java.io.FileNotFoundException: ./build-user.xml (No such file or directory)

 

Same here. 'build.xml' contains a reference to a 'build-user.xml' file, which is not in CVS.

 

jelc/build.xml

<?xml version='1.0'?>
<!DOCTYPE project [<!ENTITY buildfile SYSTEM "file:./build-user.xml">]>
<!-- WARNING: Eclipse autogenerated file. 
		  Any modifications will be overwritten.
		  Please edit build-user.xml instead.
-->
<project name='jelc2' default='build' basedir='.'>
&buildfile;
...

Share this post


Link to post
Share on other sites

Woops, I forgot to commit it :-D

 

I'll commit in an hour or so, when I get home...

 

Just checked the public CVS and it appears that this is still missing. Any chance that there's another site we can grab the file(s) from until they make it into CVS (or become available in the public version)?

Share this post


Link to post
Share on other sites

It still doesn't compile "out of the box".

 

Buildfile: build.xml

init:

build:
 [echo] jelc2: /home/ralph/temp/jelc.cvs/jelc/build.xml
[javac] Compiling 77 source files to /home/ralph/temp/jelc.cvs/jelc
[javac] /home/ralph/temp/jelc.cvs/jelc/bots/deadface2/MyBot2.java:4: package f00f.net.irc.martyr does not exist
[javac] import f00f.net.irc.martyr.GenericAutoService;
[javac]							^
[javac] /home/ralph/temp/jelc.cvs/jelc/bots/deadface2/MyBot2.java:5: package f00f.net.irc.martyr does not exist
[javac] import f00f.net.irc.martyr.IRCConnection;
[javac]							^
[javac] /home/ralph/temp/jelc.cvs/jelc/bots/deadface2/MyBot2.java:6: package f00f.net.irc.martyr does not exist
[javac] import f00f.net.irc.martyr.InCommand;
[javac]							^
[javac] /home/ralph/temp/jelc.cvs/jelc/bots/deadface2/MyBot2.java:7: package f00f.net.irc.martyr does not exist
.
.
.
.
[javac] /home/ralph/temp/jelc.cvs/jelc/bots/deadface2/PriceList.java:59: cannot resolve symbol
[javac] symbol  : constructor PrintWriter (java.io.File)
[javac] location: class java.io.PrintWriter
[javac]					 PrintWriter out=new PrintWriter(f);
[javac]										 ^
[javac] /home/ralph/temp/jelc.cvs/jelc/elc/gui/Logger.java:30: cannot resolve symbol
[javac] symbol  : constructor PrintWriter (java.io.File)
[javac] location: class java.io.PrintWriter
[javac]							 out=new PrintWriter(f);
[javac]									 ^
[javac] /home/ralph/temp/jelc.cvs/jelc/elc/gui/MapView.java:171: cannot resolve symbol
[javac] symbol  : constructor PrintWriter (java.io.File)
[javac] location: class java.io.PrintWriter
[javac]					 PrintWriter out=new PrintWriter(f);
[javac]										 ^
[javac] 71 errors

BUILD FAILED
/home/ralph/temp/jelc.cvs/jelc/build.xml:16: Compile failed; see the compiler error output for details.

Share this post


Link to post
Share on other sites

squiz you need matyr from http://martyr.sourceforge.net/ and you need to compile with the java 5 sdk.

 

ent, i haven't gotten anything graphical yet, we are working on rewritening the network code but are haveing problems as sdl_net sends data in big endian and java uses small so we need to work out a better way of doing it that is more portable for mobiles.

After next monday i should have finished my uni studies so i will have a lot of time to work on it.

 

i'll also work on publically releaeing version 3 of deadface, i've changed the signature of process to be:

public boolean process(Replyer reply,String[] args);

 

Where there are several backends that implement the interface replyer, this includes irc, a socket backend (you can telnet to it) a console (so you can type commands from the termenal) as well as an ingame backend. i'll work on an email backend so you can send commands to an email address and recieve a reply. if you can think of another backend that you want added i can work on it.

 

public interface Replyer {
public void reply(String str);
public int getType();
public String getName();
public int getMaxMessageSize();
public void flush();
}

Share this post


Link to post
Share on other sites
Guest Kytrnal

petteyg359@petteyg359 ~/jelc $ javac bots/deadface2/MyBot2.java
bots/deadface2/MyBot2.java:304: error while writing bots.deadface2.MyBot2.processThread: bots/deadface2/MyBot2$processThread.class (Permission denied)
	private class processThread extends Thread{
			^
./bots/deadface2/Guild.java:108: cannot find symbol
symbol  : method containsName(java.lang.String)
location: class playerView.PlayerList
									if(!bot.guild.list.containsName(args[2])){
													  ^
./bots/deadface2/Guild.java:138: cannot find symbol
symbol  : method containsName(java.lang.String)
location: class playerView.PlayerList
	return bot.seen.getGuild("lnx").contains(name)||list.containsName(name);
														^
./bots/deadface2/Guild.java:205: cannot find symbol
symbol  : method containsName(java.lang.String)
location: class playerView.PlayerList
			if(!list.containsName(person)){
					^
./bots/deadface2/News.java:79: cannot find symbol
symbol  : method containsName(java.lang.String)
location: class playerView.PlayerList
			if(!toldList.containsName(name)){
						^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors

I haven't done anything with Java in a long time, so I'm lost at this point...

Edited by Kytrnal

Share this post


Link to post
Share on other sites

have you tried compileing with ant?

because the project is big and complex you can have problems compileing it manually with javac. i would recomend that you use an IDE like eclipse to help compileing it.

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.

×