PDA

View Full Version : Java Bot Programming


emike55
12-12-2008, 09:35 PM
Who has a little java programming experience? I got a project that I am playing with, I am trying to access a method in another class from my own class. The background in why I want to do this is because I am trying to build a bot to maintain a flash chatroom. Inside this class I am trying to access is a method for banning and for kicking users from the chatroom. I obviously need to be able to use these methods to run the bot effectively.

The class and method I am trying to access.


package AVChat2;

import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.log4j.Logger;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.*;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.api.so.ISharedObject;
import org.red5.server.stream.ClientBroadcastStream;

public class Application extends ApplicationAdapter
{



public void kickThisUser(String userid, String roomid)
{
log.debug((new StringBuilder("kickThisUser(")).append(userid).append(",").append(roomid).append(")").toString());
IConnection conn = Red5.getConnectionLocal();
IScope room = conn.getScope();
Set clientslist = room.getClients();
for(Iterator iterator = clientslist.iterator(); iterator.hasNext();)
{
IClient item = (IClient)iterator.next();
if(item.getId().equals(userid))
{
String user_type = (String)item.getAttribute("user_type");
if(!user_type.equals("admin"))
item.disconnect();
break;
}
}
}


I've tried many different ways from all I know with no success.

root@host [~]# ls /home/red5/webapps/avchat23/WEB-INF/classes/AVChat2/
./ ../ Application.class userkick.java

This is where I am trying to build it.

package AVChat2;

import AVChat2.Application;

public class userkick
{
public static void main( String[] args )
{
Application.kickThisUser("emike55", "r0");
}
}

FirePenguins
12-12-2008, 10:39 PM
If you are trying to access them from another class you will need to create an instance of the first class within your second class. This link might be helpful: http://www.roseindia.net/java/javascript-array/call-method-another-class.shtml

emike55
12-12-2008, 11:15 PM
Yeah, trying that or did try that too lol. My current code is

package AVChat2;

import AVChat2.Application;

public class userkick
{
Application chat = new Application();

public static void main( String[] args )
{
chat.kickThisUser("emike55", "r0");
}
}


So that is the appropriate way to call that class and method? If so the errors I am receiving have to do with the CLASSPATH variable and where the import statements in the Application.class file are located.

FirePenguins
26-12-2008, 09:43 PM
Hmmm... not quite sure. I've only been using java for a few months myself :p
What specific errors are you getting?