Thread

Pbs. with Avatar_Add() in java. Any pbs with the C++ and Delphy version (Sdk)

Pbs. with Avatar_Add() in java. Any pbs with the C++ and Delphy version // Sdk

1  |  

calt exec

Mar 8, 2000, 12:29pm
Hello,

I post this e-mail about a problem related to the use of Avatar_Add().
The language used is java.

Context:
A bot, with the avatar-add() handler activated, enter in a word having
several avatar. A list of avatar-add() event are generated.

Pb:
When processing avatar-add() event handler, wrong
citizen name, IpAddress and citizen number are return.
(! In my Java program, that is working with AWSDKJava, the next
Avatar_Add event is occuring while the bot is still processing one.)

Question:
Are you aware of similar problem in C++ or Pascal ?
Do you have any idea of what could create this problem in java ?

See the details of the question in the message bellow.

Please post your answer to this group and to Iwan Tolboom <Ivanhoe>
[mailto:iacmtolboom at chello.nl]

Thank you,

Thierry Nabeth
INSEAD CALT
http://www.insead.fr/CALT/


-----Original Message-----
From: Iwan Tolboom <Ivanhoe> [mailto:iacmtolboom at chello.nl]
Sent: Wednesday, March 08, 2000 2:34 PM
To: NABETH Thierry
Subject: Java and SDk


Hi Thierry,

I just found out that one needs to be a citizen of AW to post to the
newsgroups there.
As I am not, however I want to become one, I can't due to the lack of a
credeitcard.
Could you post this message in the SDK newsgroup for me.

I would be very obliged. Iwan.

Hi everybody,

At the moment I am working on Bots that can be controlled through the
webpage.
For this purpose I choose Java as a programming language and so I need
to interface with the Aw.dll through JNI (Java Native Interface).
Most methods that make a bot act in some way work correctly.
But when I want to acquire information about a citizen things get messy.

Assume the following scenario:
1. a bot listens to Avatar_Add and Avatar_Delete
2. place it in the center of a world, where it is generally very
crowded, so a lot of Avatar_Add events occur.
3. Of each Avatar_Add event I want to acquire the following information:
- citizen name, IpAddress and citizen number
4. In my Avatar_Add event I call the diverse functions that return this
information
5. After this the following event is processed of the next avatar that
entered the space of my bot

In delphi and C++ programs I have seen this all works well.

! In my Java program, that is working with AWSDKJava, the next
Avatar_Add event is occuring while the bot is still processing one.

? So I would like to ask the following questions :
- Is this something that also happens with C++ or Delphi Bots but I just
didn't notice it ?
- Are all methods and callbacks of the SDK synchronized, thus when one
process is still underway preventing new events to be processed, by
leaving them on the stack, untill the processing has finished ?
- As non C++ programmer, I would like to know if a wrapper with
non-synchronized methods around a dll with synchronized methods explains
the mentioned problem.

I hope you don't mind me asking this much in my first posting.

Thanks,

Iwan Tolboom

My 1D emailadres : mailto:iacmtolboom at chello.nl
My 2D homepage : http://members.ams.chello.nl/iacmtolb/
My 3D hometown : http://www.3dee.nl




===== java code =========

public synchronized void handleAvatarAdd() { // EVENT_AVATAR_ADD
setProcessing(true, "%Add");
//get the session of the avatar
int avatarSession = get_afterEvent_AvatarSession();
//get the name of the world
//String worldName = get_afterEvent_WorldName();
//get the name of the avatar
String avatarName = get_afterEvent_AvatarName();
//get the citizenNumber of the avatar
int citizenNumber = getCitizenNumber(avatarName);
//get the IPAdres of the avatar
int avatarIpAddress = getAvatarAddress(avatarSession);
//get the entrytime of the avatar
System.out.println("ENTER CitizenNumber "+citizenNumber+"
"+avatarSession+" "+ avatarIpAddress +" "+avatarName);
//add the citizen by avatarIoAdress to the database
setProcessing(false, "%Add");
}


//** START QUERYING CITIZEN ATTRIBUTES
public int getAvatarAddress(int whisperPerson){
getAwSdk().address(whisperPerson);
return getAwSdk().intGet(Aw.AVATAR_ADDRESS);
}

public int getCitizenNumber(String avatarName){
getAwSdk().citizenAttributesByName(avatarName);
return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
}
public int getCitizenNumber(int citizenNumber){
getAwSdk().citizenAttributesByNumber(citizenNumber);
return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
}

public String get_afterEvent_AvatarName() {
return getAwSdk().stringGet(Aw.AVATAR_NAME);
}
public int get_afterEvent_AvatarSession() {
return getAwSdk().intGet(Aw.AVATAR_SESSION);
}
public int get_afterEvent_ChatSession() {
return getAwSdk().intGet(Aw.CHAT_SESSION);
}
public String get_afterEvent_Chat() {
return getAwSdk().stringGet(Aw.CHAT_MESSAGE);
}
public int get_afterEvent_ChatType() {
return getAwSdk().intGet(Aw.CHAT_TYPE);
}

faber

Mar 8, 2000, 3:16pm
The only valid values in avatar_add should be session number and avatar name and the avatars
position (x, y, z, yaw, gesture).

anything else is probably random, especially citizen number and i.p. address.

But the avatar add function should be processed in sequence, not simultaneously. I think you must
not call any aw_sdk function that might have internal aw_wait() calls due to its synchronous nature,
causing intermittend avatar_add calls screwing your outer avatar_add value state.

simply extract session and name, store in some list or array, then return from your handler, and do
any citizen lookup by name, i.p. lookup per session, etc.. somewhere else in your program.

Faber


"calt exec" <nabeth at calt.insead.fr> schrieb im Newsbeitrag news:38C66253.93C05E3B at calt.insead.fr...
> Hello,
>
> I post this e-mail about a problem related to the use of Avatar_Add().
> The language used is java.
>
> Context:
> A bot, with the avatar-add() handler activated, enter in a word having
> several avatar. A list of avatar-add() event are generated.
>
> Pb:
> When processing avatar-add() event handler, wrong
> citizen name, IpAddress and citizen number are return.
> (! In my Java program, that is working with AWSDKJava, the next
> Avatar_Add event is occuring while the bot is still processing one.)
>
> Question:
> Are you aware of similar problem in C++ or Pascal ?
> Do you have any idea of what could create this problem in java ?
>
> See the details of the question in the message bellow.
>
> Please post your answer to this group and to Iwan Tolboom <Ivanhoe>
> [mailto:iacmtolboom at chello.nl]
>
> Thank you,
>
> Thierry Nabeth
> INSEAD CALT
> http://www.insead.fr/CALT/
>
>
> -----Original Message-----
> From: Iwan Tolboom <Ivanhoe> [mailto:iacmtolboom at chello.nl]
> Sent: Wednesday, March 08, 2000 2:34 PM
> To: NABETH Thierry
> Subject: Java and SDk
>
>
> Hi Thierry,
>
> I just found out that one needs to be a citizen of AW to post to the
> newsgroups there.
> As I am not, however I want to become one, I can't due to the lack of a
> credeitcard.
> Could you post this message in the SDK newsgroup for me.
>
> I would be very obliged. Iwan.
>
> Hi everybody,
>
> At the moment I am working on Bots that can be controlled through the
> webpage.
> For this purpose I choose Java as a programming language and so I need
> to interface with the Aw.dll through JNI (Java Native Interface).
> Most methods that make a bot act in some way work correctly.
> But when I want to acquire information about a citizen things get messy.
>
> Assume the following scenario:
> 1. a bot listens to Avatar_Add and Avatar_Delete
> 2. place it in the center of a world, where it is generally very
> crowded, so a lot of Avatar_Add events occur.
> 3. Of each Avatar_Add event I want to acquire the following information:
> - citizen name, IpAddress and citizen number
> 4. In my Avatar_Add event I call the diverse functions that return this
> information
> 5. After this the following event is processed of the next avatar that
> entered the space of my bot
>
> In delphi and C++ programs I have seen this all works well.
>
> ! In my Java program, that is working with AWSDKJava, the next
> Avatar_Add event is occuring while the bot is still processing one.
>
> ? So I would like to ask the following questions :
> - Is this something that also happens with C++ or Delphi Bots but I just
> didn't notice it ?
> - Are all methods and callbacks of the SDK synchronized, thus when one
> process is still underway preventing new events to be processed, by
> leaving them on the stack, untill the processing has finished ?
> - As non C++ programmer, I would like to know if a wrapper with
> non-synchronized methods around a dll with synchronized methods explains
> the mentioned problem.
>
> I hope you don't mind me asking this much in my first posting.
>
> Thanks,
>
> Iwan Tolboom
>
> My 1D emailadres : mailto:iacmtolboom at chello.nl
> My 2D homepage : http://members.ams.chello.nl/iacmtolb/
> My 3D hometown : http://www.3dee.nl
>
>
>
>
> ===== java code =========
>
> public synchronized void handleAvatarAdd() { // EVENT_AVATAR_ADD
> setProcessing(true, "%Add");
> file://get the session of the avatar
> int avatarSession = get_afterEvent_AvatarSession();
> file://get the name of the world
> file://String worldName = get_afterEvent_WorldName();
> file://get the name of the avatar
> String avatarName = get_afterEvent_AvatarName();
> file://get the citizenNumber of the avatar
> int citizenNumber = getCitizenNumber(avatarName);
> file://get the IPAdres of the avatar
> int avatarIpAddress = getAvatarAddress(avatarSession);
> file://get the entrytime of the avatar
> System.out.println("ENTER CitizenNumber "+citizenNumber+"
> "+avatarSession+" "+ avatarIpAddress +" "+avatarName);
> file://add the citizen by avatarIoAdress to the database
> setProcessing(false, "%Add");
> }
>
>
> file://** START QUERYING CITIZEN ATTRIBUTES
> public int getAvatarAddress(int whisperPerson){
> getAwSdk().address(whisperPerson);
> return getAwSdk().intGet(Aw.AVATAR_ADDRESS);
> }
>
> public int getCitizenNumber(String avatarName){
> getAwSdk().citizenAttributesByName(avatarName);
> return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
> }
> public int getCitizenNumber(int citizenNumber){
> getAwSdk().citizenAttributesByNumber(citizenNumber);
> return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
> }
>
> public String get_afterEvent_AvatarName() {
> return getAwSdk().stringGet(Aw.AVATAR_NAME);
> }
> public int get_afterEvent_AvatarSession() {
> return getAwSdk().intGet(Aw.AVATAR_SESSION);
> }
> public int get_afterEvent_ChatSession() {
> return getAwSdk().intGet(Aw.CHAT_SESSION);
> }
> public String get_afterEvent_Chat() {
> return getAwSdk().stringGet(Aw.CHAT_MESSAGE);
> }
> public int get_afterEvent_ChatType() {
> return getAwSdk().intGet(Aw.CHAT_TYPE);
> }

calt exec

Mar 10, 2000, 6:49am
-----Original Message-----
From: Iwan Tolboom <Ivanhoe> [mailto:iacmtolboom at chello.nl]
Sent: Friday, March 10, 2000 3:16 AM
To: NABETH Thierry
Subject: Java Bots


Hi Thierry,
Could you post this in response to the reaction in the SDK newsgroup.

Dear Faber and Thierry,

Thank you very much for such a quick answer.
This really solved the problem and finally I can start writing bots controlled
through applets on the homepage.
I have lots of purposes where both PSes as citizens can control bots or build
through applets.
This way it is very easy to fine tune access to our world.

Thanks again and also Thierry for his patience and for posting this message.

Here is the resulting code , this is just sample code thus a little messy.
Especially the part that start with the citizenWaitVector is of interest. And
off course the call to findExtraInfo in run().


package awbot;
import java.lang.Thread;
import java.util.Vector;

class TestWait extends Thread {
Aw awSdk = null;

/**
* loads the necessary libraries and instantiates awSdk
*/
public Aw getAwSdk() {
if (awSdk == null) {
try {
System.out.println("load dlls");
System.loadLibrary("Aw");
System.loadLibrary("awjava");
System.out.println("done");
} catch (Exception ex) {
System.out.println("The aw.dll or the awjava.dll is not in
the path: "+ex);
return null;
}
awSdk = new Aw();
awSdk.init(Aw.BUILD);
System.out.println("aw initialized");
}
return awSdk;
}

private String universeUrl = null;
private int citizenNumber = 0;
private String priviledgePassword = null;
private String worldName = null;
private String botName = null;
private String applicationName = null;
private int avatarNumber = 0;

/**
* setter methods of diverse fields
*/
public void setUniverseUrl(String universeUrl){
this.universeUrl = universeUrl;
}
public void setCitizenNumber(String citizenNumber){
this.citizenNumber = Integer.parseInt(citizenNumber);
}
public void setPriviledgePassword(String priviledgePassword){
this.priviledgePassword = priviledgePassword;
}
public void setWorldName(String worldName){
this.worldName = worldName;
}
public void setBotName(String botName){
this.botName = botName;
}
public void setApplicationName(String applicationName){
this.applicationName = applicationName;
}
public void setAvatarNumber(String avatarNumber){
this.avatarNumber = Integer.parseInt(avatarNumber);
}

/**
* getter methods of the diverse fields
*/
public String getUniverseUrl(){
return this.universeUrl;
}
public int getCitizenNumber(){
return this.citizenNumber;
}
public String getPriviledgePassword(){
return this.priviledgePassword;
}
public String getWorldName(){
return this.worldName;
}
public String getBotName(){
return this.botName;
}
public String getApplicationName(){
return this.applicationName;
}
public int getAvatarNumber(){
return this.avatarNumber;
}
/**
* empty constructor
*/
public TestWait(){
}
/**
* Initialize the diverse variables
*/
public void initialize( String[] args){
setUniverseUrl(args[0]);
setCitizenNumber(args[1]);
setPriviledgePassword(args[2]);
setWorldName(args[3]);
setBotName(args[4]);
setApplicationName(args[5]);
setAvatarNumber(args[6]);
}
/**
* note : multiple sessions might connect to multiple universes
* each universe may have multiple bots

*/
public void enterUniverse() {
getAwSdk().create(getUniverseUrl(), 0/*port*/);
}

/**
* let a bot enter a world
*/
public void enterWorld() {
System.out.println("PRE:login");
// login(session.owner, session.pw, session.app, botName);
getAwSdk().setInt (Aw.LOGIN_OWNER, getCitizenNumber());
System.out.println("POST:Aw.LOGIN_OWNER, getCitizenNumber()");
getAwSdk().setString(Aw.LOGIN_PRIVILEGE_PASSWORD,
getPriviledgePassword());
System.out.println("POST:Aw.LOGIN_PRIVILEGE_PASSWORD,
getPriviledgePassword()");
getAwSdk().setString(Aw.LOGIN_APPLICATION, getApplicationName());
System.out.println("POST:Aw.LOGIN_APPLICATION, getApplicationName()");
getAwSdk().setString(Aw.LOGIN_NAME, getBotName());
System.out.println("POST:Aw.LOGIN_NAME, getBotName()");
getAwSdk().login();
System.out.println("POST:login");
// enter the world
getAwSdk().enter(getWorldName(), 0);//getRequestedNumberOfAvatars());
// note: avatar = 0
System.out.println("POST enter");

getAwSdk().setInt(Aw.MY_TYPE, getAvatarNumber());
getAwSdk().stateChange();
System.out.println("POST:stateChange");

//getSelectedBot().setBotInstanceNumber(getAwSdk().instance());
// announce our position
getAwSdk().setInt(Aw.MY_X, 1000); // west
getAwSdk().setInt(Aw.MY_Z, 1000); // north
getAwSdk().setInt(Aw.MY_Y, 1000); //up
// make the bot visible
getAwSdk().stateChange();
//getSelectedBot().say("Starting Java Conversation GeneralBot");
}

//**here start the run part **

public void run() { // I am in here the new thread T launched by
testWait.start();
initEvents(); // I am in the new thread T
while (true) {
getAwSdk().processWait(1000); // I am still in the new thread T
// ###
javax.swing.SwingUtilities.invokeAndWait(awProcessEvent); // to comment !!!!
// #### would run in the Swing thread S !!!!
findExtraInfo();
try{
Thread.sleep(20);
} catch (java.lang.InterruptedException ie){
ie.printStackTrace();
}
}
}
//**START OF EVENTHANDLING PART **
/**
* initialize the events the Bot is interested in
*/
public synchronized void initEvents() {
// session.setselectedBot(this);
System.out.println("PRE :initEvents");
getAwSdk().eventSet(Aw.EVENT_AVATAR_ADD, this,
"handleAvatarAdd", "()V");
// getAwSdk().eventSet(Aw.EVENT_AVATAR_CHANGE, this,
"handleAvatarChange", "()V");
getAwSdk().eventSet(Aw.EVENT_AVATAR_DELETE, this,
"handleAvatarDelete", "()V");
// getAwSdk().eventSet(Aw.EVENT_CHAT, this, "handleChat", "()V");
// getAwSdk().eventSet(Aw.EVENT_TELEGRAM, this, "handleTelegram",
"()V");
// getAwSdk().eventSet(Aw.EVENT_AVATAR_CLICK, this,
"handleAvatarClick", "()V");
System.out.println("POST:initEvents");
// ..... add the other handlers here
}
/**
* The class that holds the information of a citizen
*/
class Citizen {
//AW_EVENT_AVATAR_ADD properties
int AW_AVATAR_SESSION = 0;
String AW_AVATAR_NAME = null;
int AW_AVATAR_X = 0;
int AW_AVATAR_Y = 0;
int AW_AVATAR_Z = 0;
int AW_AVATAR_YAW = 0;
int AW_AVATAR_TYPE = 0;
int AW_AVATAR_GESTURE = 0;
//non AW_EVENT_AVATAR_ADD properties
boolean finished = false;
int ipAddress = 0;
int citizenNumber = 0;
/**
* print all citizen info
*/
public void print(){
System.out.println(
""+ AW_AVATAR_SESSION + " : " + AW_AVATAR_NAME + " X="
+ AW_AVATAR_X + " Y=" + AW_AVATAR_Y + " Z=" + AW_AVATAR_Z
+ " YAW=" + AW_AVATAR_YAW +" TYPE=" + AW_AVATAR_TYPE
+ " GESTURE=" + AW_AVATAR_GESTURE
+ " IP=" + ipAddress + "citnum "+ citizenNumber);
}
}
/**
* the vector that is a placeholder for citizens
*/
Vector citizenWaitVector = new Vector();
int lastExtraInfoItem = 0; //the last citizen on the vector that was
processed
void add (Citizen citizen){
citizenWaitVector.add(citizen);
}
/**
* print all citizens on the vector
*/
void print(){
for(int element=0; element < citizenWaitVector.size(); element++){
((Citizen)citizenWaitVector.elementAt(element)).print();
}
}
/**
* method that finds ip adresses and citizennumbers of all citizens that are
* not yet processed.
*/
void findExtraInfo(){
for(int element = lastExtraInfoItem; element < citizenWaitVector.size();
element++){
Citizen citizen = ((Citizen)citizenWaitVector.elementAt(element));
citizen.ipAddress = getAvatarAddress(citizen.AW_AVATAR_SESSION);
//next piece is to remove leading '[' and trailing ']' from bot
names
char[] citizenCharArray = citizen.AW_AVATAR_NAME.toCharArray();
if( (citizenCharArray[0]=='[') &&
(citizenCharArray[citizenCharArray.length-1]==']') ){
citizen.AW_AVATAR_NAME = String.copyValueOf(citizenCharArray, 1,
citizenCharArray.length-2);
System.out.println("bot :"+citizen.AW_AVATAR_NAME);
}
citizen.citizenNumber=getCitizenNumber(citizen.AW_AVATAR_NAME);
citizen.print();
}
lastExtraInfoItem = citizenWaitVector.size();
}

/**
* method called after an avatar is added
*/
public synchronized void handleAvatarAdd() { // EVENT_AVATAR_ADD
Citizen citizen = new Citizen();
//get the session of the avatar
citizen.AW_AVATAR_SESSION = get_afterEvent_AvatarSession();
citizen.AW_AVATAR_NAME = get_afterEvent_AvatarName();
citizen.AW_AVATAR_X = get_afterEvent_AvatarX();
citizen.AW_AVATAR_Y = get_afterEvent_AvatarY();
citizen.AW_AVATAR_Z = get_afterEvent_AvatarZ();
citizen.AW_AVATAR_YAW = get_afterEvent_AvatarYAW();
citizen.AW_AVATAR_TYPE = get_afterEvent_AvatarType();
citizen.AW_AVATAR_GESTURE = get_afterEvent_AvatarGesture();
add(citizen);
citizen.print();
}
public synchronized void handleAvatarChange() { // EVENT_AVATAR_CHANGE
}
public synchronized void handleAvatarClick() { // EVENT_AVATAR_CLICK
}
public synchronized void handleAvatarDelete() { // EVENT_AVATAR_DELETE

}
public synchronized void handleChat() { // EVENT_CHAT
/* String[] chatTypeString = {"said", "broadcasted", "whispered"};
//say
//get the name of the avatar
String avatarName = get_afterEvent_AvatarName();
String chatText = get_afterEvent_Chat();
int chatTypeInt = get_afterEvent_ChatType();
switch(chatTypeInt){
case 0 : chatSaid(avatarName, chatText);
break;
case 1 : chatBroadcasted(avatarName, chatText);
break;
case 2 : chatWhispered(avatarName, chatText);
break;
}

//Watch this : needs CHAT_SESSION for acquiring the IPadress
//get the session of the avatar
int chatSession = get_afterEvent_ChatSession();
*/ }

public synchronized void chatSaid(String avatarName, String avatarText){
}

public synchronized void chatBroadcasted(String avatarName, String
avatarText){
}

public synchronized void chatWhispered(String avatarName, String
avatarText){
}

public synchronized void handleTelegram() { // EVENT_TELEGRAM
}
//** START QUERYING CITIZEN ATTRIBUTES
public synchronized int getAvatarAddress(int whisperPerson){
getAwSdk().address(whisperPerson);
return getAwSdk().intGet(Aw.AVATAR_ADDRESS);
}

public synchronized int getCitizenNumber(String avatarName){
getAwSdk().citizenAttributesByName(avatarName);
return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
}
public synchronized int getCitizenNumber(int citizenNumber){
getAwSdk().citizenAttributesByNumber(citizenNumber);
return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
}

public synchronized String get_afterEvent_AvatarName() {
return getAwSdk().stringGet(Aw.AVATAR_NAME);
}
public synchronized int get_afterEvent_AvatarSession() {
return getAwSdk().intGet(Aw.AVATAR_SESSION);
}
public synchronized int get_afterEvent_AvatarX() {
return getAwSdk().intGet(Aw.AVATAR_X);
}
public synchronized int get_afterEvent_AvatarY() {
return getAwSdk().intGet(Aw.AVATAR_Y);
}
public synchronized int get_afterEvent_AvatarZ() {
return getAwSdk().intGet(Aw.AVATAR_Z);
}
public synchronized int get_afterEvent_AvatarYAW() {
return getAwSdk().intGet(Aw.AVATAR_YAW);
}
public synchronized int get_afterEvent_AvatarType() {
return getAwSdk().intGet(Aw.AVATAR_TYPE);
}
public synchronized int get_afterEvent_AvatarGesture() {
return getAwSdk().intGet(Aw.AVATAR_GESTURE);
}

public synchronized int get_afterEvent_ChatSession() {
return getAwSdk().intGet(Aw.CHAT_SESSION);
}
public synchronized String get_afterEvent_Chat() {
return getAwSdk().stringGet(Aw.CHAT_MESSAGE);
}
public synchronized int get_afterEvent_ChatType() {
return getAwSdk().intGet(Aw.CHAT_TYPE);
}
//**START OF MAIN
/**
* The main entry point of the Bot.
*/
public static void main(String args[]){
System.out.println("***Statistics bot***");
System.out.println("Please supply the following information");
System.out.println("The url of the universe you want to enter");
System.out.println("Your citizennumber");
System.out.println("Your privilige password");
System.out.println("The name of the world you want to enter");
System.out.println("The name of your bot");
System.out.println("The name of your application");
System.out.println("The number of the representing Avatar");
TestWait testWait= new TestWait();
if(args.length == 7){
testWait.initialize(args);
testWait.enterUniverse();
testWait.enterWorld();
testWait.start();
}
}
}

Iwan Tolboom
My 1D emailadres : mailto:iacmtolboom at chello.nl
My 2D homepage : http://members.ams.chello.nl/iacmtolb/
My 3D hometown : http://www.3dee.nl

calt exec

Mar 10, 2000, 6:49am
-----Original Message-----
From: Iwan Tolboom <Ivanhoe> [mailto:iacmtolboom at chello.nl]
Sent: Friday, March 10, 2000 3:16 AM
To: NABETH Thierry
Subject: Java Bots


Hi Thierry,
Could you post this in response to the reaction in the SDK newsgroup.

Dear Faber and Thierry,

Thank you very much for such a quick answer.
This really solved the problem and finally I can start writing bots controlled
through applets on the homepage.
I have lots of purposes where both PSes as citizens can control bots or build
through applets.
This way it is very easy to fine tune access to our world.

Thanks again and also Thierry for his patience and for posting this message.

Here is the resulting code , this is just sample code thus a little messy.
Especially the part that start with the citizenWaitVector is of interest. And
off course the call to findExtraInfo in run().


package awbot;
import java.lang.Thread;
import java.util.Vector;

class TestWait extends Thread {
Aw awSdk = null;

/**
* loads the necessary libraries and instantiates awSdk
*/
public Aw getAwSdk() {
if (awSdk == null) {
try {
System.out.println("load dlls");
System.loadLibrary("Aw");
System.loadLibrary("awjava");
System.out.println("done");
} catch (Exception ex) {
System.out.println("The aw.dll or the awjava.dll is not in
the path: "+ex);
return null;
}
awSdk = new Aw();
awSdk.init(Aw.BUILD);
System.out.println("aw initialized");
}
return awSdk;
}

private String universeUrl = null;
private int citizenNumber = 0;
private String priviledgePassword = null;
private String worldName = null;
private String botName = null;
private String applicationName = null;
private int avatarNumber = 0;

/**
* setter methods of diverse fields
*/
public void setUniverseUrl(String universeUrl){
this.universeUrl = universeUrl;
}
public void setCitizenNumber(String citizenNumber){
this.citizenNumber = Integer.parseInt(citizenNumber);
}
public void setPriviledgePassword(String priviledgePassword){
this.priviledgePassword = priviledgePassword;
}
public void setWorldName(String worldName){
this.worldName = worldName;
}
public void setBotName(String botName){
this.botName = botName;
}
public void setApplicationName(String applicationName){
this.applicationName = applicationName;
}
public void setAvatarNumber(String avatarNumber){
this.avatarNumber = Integer.parseInt(avatarNumber);
}

/**
* getter methods of the diverse fields
*/
public String getUniverseUrl(){
return this.universeUrl;
}
public int getCitizenNumber(){
return this.citizenNumber;
}
public String getPriviledgePassword(){
return this.priviledgePassword;
}
public String getWorldName(){
return this.worldName;
}
public String getBotName(){
return this.botName;
}
public String getApplicationName(){
return this.applicationName;
}
public int getAvatarNumber(){
return this.avatarNumber;
}
/**
* empty constructor
*/
public TestWait(){
}
/**
* Initialize the diverse variables
*/
public void initialize( String[] args){
setUniverseUrl(args[0]);
setCitizenNumber(args[1]);
setPriviledgePassword(args[2]);
setWorldName(args[3]);
setBotName(args[4]);
setApplicationName(args[5]);
setAvatarNumber(args[6]);
}
/**
* note : multiple sessions might connect to multiple universes
* each universe may have multiple bots

*/
public void enterUniverse() {
getAwSdk().create(getUniverseUrl(), 0/*port*/);
}

/**
* let a bot enter a world
*/
public void enterWorld() {
System.out.println("PRE:login");
// login(session.owner, session.pw, session.app, botName);
getAwSdk().setInt (Aw.LOGIN_OWNER, getCitizenNumber());
System.out.println("POST:Aw.LOGIN_OWNER, getCitizenNumber()");
getAwSdk().setString(Aw.LOGIN_PRIVILEGE_PASSWORD,
getPriviledgePassword());
System.out.println("POST:Aw.LOGIN_PRIVILEGE_PASSWORD,
getPriviledgePassword()");
getAwSdk().setString(Aw.LOGIN_APPLICATION, getApplicationName());
System.out.println("POST:Aw.LOGIN_APPLICATION, getApplicationName()");
getAwSdk().setString(Aw.LOGIN_NAME, getBotName());
System.out.println("POST:Aw.LOGIN_NAME, getBotName()");
getAwSdk().login();
System.out.println("POST:login");
// enter the world
getAwSdk().enter(getWorldName(), 0);//getRequestedNumberOfAvatars());
// note: avatar = 0
System.out.println("POST enter");

getAwSdk().setInt(Aw.MY_TYPE, getAvatarNumber());
getAwSdk().stateChange();
System.out.println("POST:stateChange");

//getSelectedBot().setBotInstanceNumber(getAwSdk().instance());
// announce our position
getAwSdk().setInt(Aw.MY_X, 1000); // west
getAwSdk().setInt(Aw.MY_Z, 1000); // north
getAwSdk().setInt(Aw.MY_Y, 1000); //up
// make the bot visible
getAwSdk().stateChange();
//getSelectedBot().say("Starting Java Conversation GeneralBot");
}

//**here start the run part **

public void run() { // I am in here the new thread T launched by
testWait.start();
initEvents(); // I am in the new thread T
while (true) {
getAwSdk().processWait(1000); // I am still in the new thread T
// ###
javax.swing.SwingUtilities.invokeAndWait(awProcessEvent); // to comment !!!!
// #### would run in the Swing thread S !!!!
findExtraInfo();
try{
Thread.sleep(20);
} catch (java.lang.InterruptedException ie){
ie.printStackTrace();
}
}
}
//**START OF EVENTHANDLING PART **
/**
* initialize the events the Bot is interested in
*/
public synchronized void initEvents() {
// session.setselectedBot(this);
System.out.println("PRE :initEvents");
getAwSdk().eventSet(Aw.EVENT_AVATAR_ADD, this,
"handleAvatarAdd", "()V");
// getAwSdk().eventSet(Aw.EVENT_AVATAR_CHANGE, this,
"handleAvatarChange", "()V");
getAwSdk().eventSet(Aw.EVENT_AVATAR_DELETE, this,
"handleAvatarDelete", "()V");
// getAwSdk().eventSet(Aw.EVENT_CHAT, this, "handleChat", "()V");
// getAwSdk().eventSet(Aw.EVENT_TELEGRAM, this, "handleTelegram",
"()V");
// getAwSdk().eventSet(Aw.EVENT_AVATAR_CLICK, this,
"handleAvatarClick", "()V");
System.out.println("POST:initEvents");
// ..... add the other handlers here
}
/**
* The class that holds the information of a citizen
*/
class Citizen {
//AW_EVENT_AVATAR_ADD properties
int AW_AVATAR_SESSION = 0;
String AW_AVATAR_NAME = null;
int AW_AVATAR_X = 0;
int AW_AVATAR_Y = 0;
int AW_AVATAR_Z = 0;
int AW_AVATAR_YAW = 0;
int AW_AVATAR_TYPE = 0;
int AW_AVATAR_GESTURE = 0;
//non AW_EVENT_AVATAR_ADD properties
boolean finished = false;
int ipAddress = 0;
int citizenNumber = 0;
/**
* print all citizen info
*/
public void print(){
System.out.println(
""+ AW_AVATAR_SESSION + " : " + AW_AVATAR_NAME + " X="
+ AW_AVATAR_X + " Y=" + AW_AVATAR_Y + " Z=" + AW_AVATAR_Z
+ " YAW=" + AW_AVATAR_YAW +" TYPE=" + AW_AVATAR_TYPE
+ " GESTURE=" + AW_AVATAR_GESTURE
+ " IP=" + ipAddress + "citnum "+ citizenNumber);
}
}
/**
* the vector that is a placeholder for citizens
*/
Vector citizenWaitVector = new Vector();
int lastExtraInfoItem = 0; //the last citizen on the vector that was
processed
void add (Citizen citizen){
citizenWaitVector.add(citizen);
}
/**
* print all citizens on the vector
*/
void print(){
for(int element=0; element < citizenWaitVector.size(); element++){
((Citizen)citizenWaitVector.elementAt(element)).print();
}
}
/**
* method that finds ip adresses and citizennumbers of all citizens that are
* not yet processed.
*/
void findExtraInfo(){
for(int element = lastExtraInfoItem; element < citizenWaitVector.size();
element++){
Citizen citizen = ((Citizen)citizenWaitVector.elementAt(element));
citizen.ipAddress = getAvatarAddress(citizen.AW_AVATAR_SESSION);
//next piece is to remove leading '[' and trailing ']' from bot
names
char[] citizenCharArray = citizen.AW_AVATAR_NAME.toCharArray();
if( (citizenCharArray[0]=='[') &&
(citizenCharArray[citizenCharArray.length-1]==']') ){
citizen.AW_AVATAR_NAME = String.copyValueOf(citizenCharArray, 1,
citizenCharArray.length-2);
System.out.println("bot :"+citizen.AW_AVATAR_NAME);
}
citizen.citizenNumber=getCitizenNumber(citizen.AW_AVATAR_NAME);
citizen.print();
}
lastExtraInfoItem = citizenWaitVector.size();
}

/**
* method called after an avatar is added
*/
public synchronized void handleAvatarAdd() { // EVENT_AVATAR_ADD
Citizen citizen = new Citizen();
//get the session of the avatar
citizen.AW_AVATAR_SESSION = get_afterEvent_AvatarSession();
citizen.AW_AVATAR_NAME = get_afterEvent_AvatarName();
citizen.AW_AVATAR_X = get_afterEvent_AvatarX();
citizen.AW_AVATAR_Y = get_afterEvent_AvatarY();
citizen.AW_AVATAR_Z = get_afterEvent_AvatarZ();
citizen.AW_AVATAR_YAW = get_afterEvent_AvatarYAW();
citizen.AW_AVATAR_TYPE = get_afterEvent_AvatarType();
citizen.AW_AVATAR_GESTURE = get_afterEvent_AvatarGesture();
add(citizen);
citizen.print();
}
public synchronized void handleAvatarChange() { // EVENT_AVATAR_CHANGE
}
public synchronized void handleAvatarClick() { // EVENT_AVATAR_CLICK
}
public synchronized void handleAvatarDelete() { // EVENT_AVATAR_DELETE

}
public synchronized void handleChat() { // EVENT_CHAT
/* String[] chatTypeString = {"said", "broadcasted", "whispered"};
//say
//get the name of the avatar
String avatarName = get_afterEvent_AvatarName();
String chatText = get_afterEvent_Chat();
int chatTypeInt = get_afterEvent_ChatType();
switch(chatTypeInt){
case 0 : chatSaid(avatarName, chatText);
break;
case 1 : chatBroadcasted(avatarName, chatText);
break;
case 2 : chatWhispered(avatarName, chatText);
break;
}

//Watch this : needs CHAT_SESSION for acquiring the IPadress
//get the session of the avatar
int chatSession = get_afterEvent_ChatSession();
*/ }

public synchronized void chatSaid(String avatarName, String avatarText){
}

public synchronized void chatBroadcasted(String avatarName, String
avatarText){
}

public synchronized void chatWhispered(String avatarName, String
avatarText){
}

public synchronized void handleTelegram() { // EVENT_TELEGRAM
}
//** START QUERYING CITIZEN ATTRIBUTES
public synchronized int getAvatarAddress(int whisperPerson){
getAwSdk().address(whisperPerson);
return getAwSdk().intGet(Aw.AVATAR_ADDRESS);
}

public synchronized int getCitizenNumber(String avatarName){
getAwSdk().citizenAttributesByName(avatarName);
return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
}
public synchronized int getCitizenNumber(int citizenNumber){
getAwSdk().citizenAttributesByNumber(citizenNumber);
return getAwSdk().intGet(Aw.CITIZEN_NUMBER);
}

public synchronized String get_afterEvent_AvatarName() {
return getAwSdk().stringGet(Aw.AVATAR_NAME);
}
public synchronized int get_afterEvent_AvatarSession() {
return getAwSdk().intGet(Aw.AVATAR_SESSION);
}
public synchronized int get_afterEvent_AvatarX() {
return getAwSdk().intGet(Aw.AVATAR_X);
}
public synchronized int get_afterEvent_AvatarY() {
return getAwSdk().intGet(Aw.AVATAR_Y);
}
public synchronized int get_afterEvent_AvatarZ() {
return getAwSdk().intGet(Aw.AVATAR_Z);
}
public synchronized int get_afterEvent_AvatarYAW() {
return getAwSdk().intGet(Aw.AVATAR_YAW);
}
public synchronized int get_afterEvent_AvatarType() {
return getAwSdk().intGet(Aw.AVATAR_TYPE);
}
public synchronized int get_afterEvent_AvatarGesture() {
return getAwSdk().intGet(Aw.AVATAR_GESTURE);
}

public synchronized int get_afterEvent_ChatSession() {
return getAwSdk().intGet(Aw.CHAT_SESSION);
}
public synchronized String get_afterEvent_Chat() {
return getAwSdk().stringGet(Aw.CHAT_MESSAGE);
}
public synchronized int get_afterEvent_ChatType() {
return getAwSdk().intGet(Aw.CHAT_TYPE);
}
//**START OF MAIN
/**
* The main entry point of the Bot.
*/
public static void main(String args[]){
System.out.println("***Statistics bot***");
System.out.println("Please supply the following information");
System.out.println("The url of the universe you want to enter");
System.out.println("Your citizennumber");
System.out.println("Your privilige password");
System.out.println("The name of the world you want to enter");
System.out.println("The name of your bot");
System.out.println("The name of your application");
System.out.println("The number of the representing Avatar");
TestWait testWait= new TestWait();
if(args.length == 7){
testWait.initialize(args);
testWait.enterUniverse();
testWait.enterWorld();
testWait.start();
}
}
}

Iwan Tolboom
My 1D emailadres : mailto:iacmtolboom at chello.nl
My 2D homepage : http://members.ams.chello.nl/iacmtolb/
My 3D hometown : http://www.3dee.nl

calt exec

Mar 10, 2000, 6:53am
Hello,

This message is exactly the same as the previous one.
Just forget it.

Sorry about this (I had some configuration problems).

Thierry

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn