Thread

Problems with AW_QUERY (Sdk)

Problems with AW_QUERY // Sdk

1  |  

lucio pascarelli

Nov 17, 1998, 7:56pm
I am working on an SDK app that should keep an SQL database in sync with the
World Database. The reason for this is to help in the maintenance of my
world Virtualy for which I already periodically propdump and load onto SQL
server. In the long term however I want to create a building assistant bot.

The program below works fine for the first number of aw_query calls.
However, after a some 100 calls the aw_query starts to send the same objects
back, apparently ignoring the the sequence numbers.

The code is based on the Sample #2 apps on the SDK Docs. I have added some
command line parameters. The last parameter toggles between a debug output
(showing the sector and sequence numbers exchange) and a propdump format.

I have reviewed the code and compared it to the sample (which used to work
also on Virtualy) but have run out of neurons to find the bug. My C skills
are quite new.

Thanks.

Lucio


// sqlbot.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "aw.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ONE_HOUR (60 * 60 * 1000)

#define DBNTWIN32
#include <stdio.h>
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>

void handle_cell_begin (void);
void handle_cell_object (void);
void handle_cell_end (void);
void handle_query (int rc);

int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR);
BOOL gbOpen = FALSE;

int owner;
int sequence[3][3];
int speaker_x;
int speaker_y;
int speaker_z;
int speaker_yaw;
int speaker_number;
int cell_x;
int cell_z;
int coord_x;
int coord_z;
int sect_x;
int sect_z;

int flDebug;

typedef struct strOBJECT_T
{
int AW_CELL_X;
int AW_CELL_Z;
int AW_OBJECT_NUMBER;
int AW_OBJECT_OWNER;
int AW_OBJECT_BUILD_TIMESTAMP;
int AW_OBJECT_X;
int AW_OBJECT_Y;
int AW_OBJECT_Z;
int AW_OBJECT_YAW;
int AW_OBJECT_MODEL_LEN;
int AW_OBJECT_DESCRIPTION_LEN;
int AW_OBJECT_ACTION_LEN;
char AW_OBJECT_MODEL[255];
char AW_OBJECT_DESCRIPTION[255];
char AW_OBJECT_ACTION[255];

} strOBJECT, *pstrOBJECT;

int DBInsertObject(char* user, char* pwd, char* server, pstrOBJECT obj);

main (int argc, char *argv[])
{

int rc;

/* check command line */
if (argc < 7) {
printf ("Usage: %s number password world NS WE DebugFlag\n", argv[0]);
exit (1);
}

flDebug = atoi(argv[6]);

/* initialize Active Worlds API */
if (rc = aw_init (AW_BUILD)) {
printf ("Unable to initialize API (reason %d)\n", rc);
exit (1);
}

/* install cell update event handlers */
aw_event_set (AW_EVENT_CELL_BEGIN, handle_cell_begin);
aw_event_set (AW_EVENT_CELL_OBJECT, handle_cell_object);
aw_event_set (AW_EVENT_CELL_END, handle_cell_end);

/* install query callback */
aw_callback_set (AW_CALLBACK_QUERY, handle_query);

/* create bot instance */
if (rc = aw_create (0, 0, 0)) {
printf ("Unable to create bot instance (reason %d)\n", rc);
exit (1);
}

/* log bot into the universe */
owner = atoi (argv[1]);
aw_int_set (AW_LOGIN_OWNER, owner);

aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, argv[2]);
aw_string_set (AW_LOGIN_APPLICATION, "SQL Bot Test");
aw_string_set (AW_LOGIN_NAME, "SQL Bot Test");
if (rc = aw_login ()) {
printf ("Unable to login (reason %d)\n", rc);
exit (1);
}

/* log bot into the world */
if (rc = aw_enter (argv[3], 0)) {
printf ("Unable to enter world (reason %d)\n", rc);
exit (1);
}


/* issue first property query */

coord_x = atoi(argv[4]);
coord_z = atoi(argv[5]);

sect_x = aw_sector_from_cell(coord_x);
sect_z = aw_sector_from_cell(coord_z);

if (flDebug)
printf ("Starting query at: %d, %d \n", coord_x, coord_z);

aw_query (sect_x, sect_z, sequence);

/* keep it running long enough !!! */
while (!(rc = aw_wait (ONE_HOUR)));

/* close everything down */
aw_destroy ();
aw_term ();
return 0;

}

void handle_cell_begin (void)
{
int x, z; // used as indices for the sequence array

cell_x = aw_int(AW_CELL_X);
cell_z = aw_int(AW_CELL_Z);

if (flDebug)
printf ("Starting Cell: %d, %d \n", cell_x, cell_z);

x = aw_sector_from_cell(cell_x) - sect_x;
z = aw_sector_from_cell(cell_z) - sect_z;

if (flDebug)
printf (" Sec: %d, %d \n", x, z);

/* sanity check: make sure sector coordinates are within range */
if (x < -1 || x > 1 || z < -1 || z > 1 )
{
if (flDebug)
printf ("Sector out of Range !!!");
return;
}

sequence[x+1][z+1] = aw_int(AW_CELL_SEQUENCE);

if (flDebug)
{
printf (" Seq: %d, %d, %d\n",
sequence[2][2],sequence[1][2],sequence[0][2]);
printf (" %d, %d, %d\n",
sequence[2][1],sequence[1][1],sequence[0][1]);
printf (" %d, %d, %d\n",
sequence[2][0],sequence[1][0],sequence[0][0]);
}
}

void handle_cell_end (void)
{
cell_x = aw_int(AW_CELL_X);
cell_z = aw_int(AW_CELL_Z);

if (flDebug)
printf (" End: %d, %d \n\n", cell_x, cell_z);

}

void handle_cell_object (void)
{

pstrOBJECT pObj;

pObj = (pstrOBJECT) malloc(sizeof(strOBJECT));

pObj->AW_CELL_X = aw_int(AW_CELL_X);
pObj->AW_CELL_Z = aw_int(AW_CELL_Z);
pObj->AW_OBJECT_NUMBER = aw_int (AW_OBJECT_NUMBER);
pObj->AW_OBJECT_OWNER = aw_int (AW_OBJECT_OWNER);
pObj->AW_OBJECT_BUILD_TIMESTAMP = aw_int (AW_OBJECT_BUILD_TIMESTAMP);
pObj->AW_OBJECT_X = aw_int (AW_OBJECT_X);
pObj->AW_OBJECT_Y = aw_int (AW_OBJECT_Y);
pObj->AW_OBJECT_Z = aw_int (AW_OBJECT_Z);
pObj->AW_OBJECT_YAW = aw_int (AW_OBJECT_YAW);
pObj->AW_OBJECT_MODEL_LEN = strlen(aw_string (AW_OBJECT_MODEL));
pObj->AW_OBJECT_DESCRIPTION_LEN = strlen(aw_string
(AW_OBJECT_DESCRIPTION));
pObj->AW_OBJECT_ACTION_LEN = strlen(aw_string (AW_OBJECT_ACTION));
wsprintf(pObj->AW_OBJECT_MODEL, "%s", aw_string (AW_OBJECT_MODEL));
wsprintf(pObj->AW_OBJECT_DESCRIPTION, "%s", aw_string
(AW_OBJECT_DESCRIPTION));
wsprintf(pObj->AW_OBJECT_ACTION, "%s", aw_string (AW_OBJECT_ACTION));

/* DBInsertObject("sa", "", "server", pObj);*/

if (!flDebug)
{
printf("%d %d %d %d %d %d %d %d %d %s%s%s\n",
pObj->AW_OBJECT_OWNER,
pObj->AW_OBJECT_BUILD_TIMESTAMP,
pObj->AW_OBJECT_X,
pObj->AW_OBJECT_Y,
pObj->AW_OBJECT_Z,
pObj->AW_OBJECT_YAW,
pObj->AW_OBJECT_MODEL_LEN,
pObj->AW_OBJECT_DESCRIPTION_LEN,
pObj->AW_OBJECT_ACTION_LEN,
pObj->AW_OBJECT_MODEL,
pObj->AW_OBJECT_DESCRIPTION,
pObj->AW_OBJECT_ACTION);
}

free(pObj);

}

void handle_query (int rc)
{

if (!aw_bool (AW_QUERY_COMPLETE))
{
aw_query (sect_x, sect_z, sequence);
if (flDebug)
{
printf ("Resend Query: %d %d\n", sect_x, sect_z);
printf (" Seq: %d, %d, %d\n",
sequence[2][2],sequence[1][2],sequence[0][2]);
printf (" %d, %d, %d\n",
sequence[2][1],sequence[1][1],sequence[0][1]);
printf (" %d, %d, %d\n\n",
sequence[2][0],sequence[1][0],sequence[0][0]);
}
}
else
printf ("Query Complete.\n");

}

canopus

Nov 17, 1998, 8:13pm
Is the line that updates the Sequence array correct? Shouldn't the z precede the
x? (Just the reverse of everything else!)

[View Quote] > I am working on an SDK app that should keep an SQL database in sync with the
> World Database. The reason for this is to help in the maintenance of my
> world Virtualy for which I already periodically propdump and load onto SQL
> server. In the long term however I want to create a building assistant bot.
>
> The program below works fine for the first number of aw_query calls.
> However, after a some 100 calls the aw_query starts to send the same objects
> back, apparently ignoring the the sequence numbers.
>
> The code is based on the Sample #2 apps on the SDK Docs. I have added some
> command line parameters. The last parameter toggles between a debug output
> (showing the sector and sequence numbers exchange) and a propdump format.
>
> I have reviewed the code and compared it to the sample (which used to work
> also on Virtualy) but have run out of neurons to find the bug. My C skills
> are quite new.
>
> Thanks.
>
> Lucio
>
> // sqlbot.cpp : Defines the entry point for the console application.
> //
>
> #include "stdafx.h"
> #include "aw.h"
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> #define ONE_HOUR (60 * 60 * 1000)
>
> #define DBNTWIN32
> #include <stdio.h>
> #include <windows.h>
> #include <sqlfront.h>
> #include <sqldb.h>
>
> void handle_cell_begin (void);
> void handle_cell_object (void);
> void handle_cell_end (void);
> void handle_query (int rc);
>
> int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR);
> BOOL gbOpen = FALSE;
>
> int owner;
> int sequence[3][3];
> int speaker_x;
> int speaker_y;
> int speaker_z;
> int speaker_yaw;
> int speaker_number;
> int cell_x;
> int cell_z;
> int coord_x;
> int coord_z;
> int sect_x;
> int sect_z;
>
> int flDebug;
>
> typedef struct strOBJECT_T
> {
> int AW_CELL_X;
> int AW_CELL_Z;
> int AW_OBJECT_NUMBER;
> int AW_OBJECT_OWNER;
> int AW_OBJECT_BUILD_TIMESTAMP;
> int AW_OBJECT_X;
> int AW_OBJECT_Y;
> int AW_OBJECT_Z;
> int AW_OBJECT_YAW;
> int AW_OBJECT_MODEL_LEN;
> int AW_OBJECT_DESCRIPTION_LEN;
> int AW_OBJECT_ACTION_LEN;
> char AW_OBJECT_MODEL[255];
> char AW_OBJECT_DESCRIPTION[255];
> char AW_OBJECT_ACTION[255];
>
> } strOBJECT, *pstrOBJECT;
>
> int DBInsertObject(char* user, char* pwd, char* server, pstrOBJECT obj);
>
> main (int argc, char *argv[])
> {
>
> int rc;
>
> /* check command line */
> if (argc < 7) {
> printf ("Usage: %s number password world NS WE DebugFlag\n", argv[0]);
> exit (1);
> }
>
> flDebug = atoi(argv[6]);
>
> /* initialize Active Worlds API */
> if (rc = aw_init (AW_BUILD)) {
> printf ("Unable to initialize API (reason %d)\n", rc);
> exit (1);
> }
>
> /* install cell update event handlers */
> aw_event_set (AW_EVENT_CELL_BEGIN, handle_cell_begin);
> aw_event_set (AW_EVENT_CELL_OBJECT, handle_cell_object);
> aw_event_set (AW_EVENT_CELL_END, handle_cell_end);
>
> /* install query callback */
> aw_callback_set (AW_CALLBACK_QUERY, handle_query);
>
> /* create bot instance */
> if (rc = aw_create (0, 0, 0)) {
> printf ("Unable to create bot instance (reason %d)\n", rc);
> exit (1);
> }
>
> /* log bot into the universe */
> owner = atoi (argv[1]);
> aw_int_set (AW_LOGIN_OWNER, owner);
>
> aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, argv[2]);
> aw_string_set (AW_LOGIN_APPLICATION, "SQL Bot Test");
> aw_string_set (AW_LOGIN_NAME, "SQL Bot Test");
> if (rc = aw_login ()) {
> printf ("Unable to login (reason %d)\n", rc);
> exit (1);
> }
>
> /* log bot into the world */
> if (rc = aw_enter (argv[3], 0)) {
> printf ("Unable to enter world (reason %d)\n", rc);
> exit (1);
> }
>
> /* issue first property query */
>
> coord_x = atoi(argv[4]);
> coord_z = atoi(argv[5]);
>
> sect_x = aw_sector_from_cell(coord_x);
> sect_z = aw_sector_from_cell(coord_z);
>
> if (flDebug)
> printf ("Starting query at: %d, %d \n", coord_x, coord_z);
>
> aw_query (sect_x, sect_z, sequence);
>
> /* keep it running long enough !!! */
> while (!(rc = aw_wait (ONE_HOUR)));
>
> /* close everything down */
> aw_destroy ();
> aw_term ();
> return 0;
>
> }
>
> void handle_cell_begin (void)
> {
> int x, z; // used as indices for the sequence array
>
> cell_x = aw_int(AW_CELL_X);
> cell_z = aw_int(AW_CELL_Z);
>
> if (flDebug)
> printf ("Starting Cell: %d, %d \n", cell_x, cell_z);
>
> x = aw_sector_from_cell(cell_x) - sect_x;
> z = aw_sector_from_cell(cell_z) - sect_z;
>
> if (flDebug)
> printf (" Sec: %d, %d \n", x, z);
>
> /* sanity check: make sure sector coordinates are within range */
> if (x < -1 || x > 1 || z < -1 || z > 1 )
> {
> if (flDebug)
> printf ("Sector out of Range !!!");
> return;
> }
>
> sequence[x+1][z+1] = aw_int(AW_CELL_SEQUENCE);
>
> if (flDebug)
> {
> printf (" Seq: %d, %d, %d\n",
> sequence[2][2],sequence[1][2],sequence[0][2]);
> printf (" %d, %d, %d\n",
> sequence[2][1],sequence[1][1],sequence[0][1]);
> printf (" %d, %d, %d\n",
> sequence[2][0],sequence[1][0],sequence[0][0]);
> }
> }
>
> void handle_cell_end (void)
> {
> cell_x = aw_int(AW_CELL_X);
> cell_z = aw_int(AW_CELL_Z);
>
> if (flDebug)
> printf (" End: %d, %d \n\n", cell_x, cell_z);
>
> }
>
> void handle_cell_object (void)
> {
>
> pstrOBJECT pObj;
>
> pObj = (pstrOBJECT) malloc(sizeof(strOBJECT));
>
> pObj->AW_CELL_X = aw_int(AW_CELL_X);
> pObj->AW_CELL_Z = aw_int(AW_CELL_Z);
> pObj->AW_OBJECT_NUMBER = aw_int (AW_OBJECT_NUMBER);
> pObj->AW_OBJECT_OWNER = aw_int (AW_OBJECT_OWNER);
> pObj->AW_OBJECT_BUILD_TIMESTAMP = aw_int (AW_OBJECT_BUILD_TIMESTAMP);
> pObj->AW_OBJECT_X = aw_int (AW_OBJECT_X);
> pObj->AW_OBJECT_Y = aw_int (AW_OBJECT_Y);
> pObj->AW_OBJECT_Z = aw_int (AW_OBJECT_Z);
> pObj->AW_OBJECT_YAW = aw_int (AW_OBJECT_YAW);
> pObj->AW_OBJECT_MODEL_LEN = strlen(aw_string (AW_OBJECT_MODEL));
> pObj->AW_OBJECT_DESCRIPTION_LEN = strlen(aw_string
> (AW_OBJECT_DESCRIPTION));
> pObj->AW_OBJECT_ACTION_LEN = strlen(aw_string (AW_OBJECT_ACTION));
> wsprintf(pObj->AW_OBJECT_MODEL, "%s", aw_string (AW_OBJECT_MODEL));
> wsprintf(pObj->AW_OBJECT_DESCRIPTION, "%s", aw_string
> (AW_OBJECT_DESCRIPTION));
> wsprintf(pObj->AW_OBJECT_ACTION, "%s", aw_string (AW_OBJECT_ACTION));
>
> /* DBInsertObject("sa", "", "server", pObj);*/
>
> if (!flDebug)
> {
> printf("%d %d %d %d %d %d %d %d %d %s%s%s\n",
> pObj->AW_OBJECT_OWNER,
> pObj->AW_OBJECT_BUILD_TIMESTAMP,
> pObj->AW_OBJECT_X,
> pObj->AW_OBJECT_Y,
> pObj->AW_OBJECT_Z,
> pObj->AW_OBJECT_YAW,
> pObj->AW_OBJECT_MODEL_LEN,
> pObj->AW_OBJECT_DESCRIPTION_LEN,
> pObj->AW_OBJECT_ACTION_LEN,
> pObj->AW_OBJECT_MODEL,
> pObj->AW_OBJECT_DESCRIPTION,
> pObj->AW_OBJECT_ACTION);
> }
>
> free(pObj);
>
> }
>
> void handle_query (int rc)
> {
>
> if (!aw_bool (AW_QUERY_COMPLETE))
> {
> aw_query (sect_x, sect_z, sequence);
> if (flDebug)
> {
> printf ("Resend Query: %d %d\n", sect_x, sect_z);
> printf (" Seq: %d, %d, %d\n",
> sequence[2][2],sequence[1][2],sequence[0][2]);
> printf (" %d, %d, %d\n",
> sequence[2][1],sequence[1][1],sequence[0][1]);
> printf (" %d, %d, %d\n\n",
> sequence[2][0],sequence[1][0],sequence[0][0]);
> }
> }
> else
> printf ("Query Complete.\n");
>
> }

roland vilett

Nov 17, 1998, 9:03pm
Yes, the problem is probably that the x and z are reversed in the line that
updates the sequence array. The first index should be offset from z, the
second from x.

-Roland

[View Quote]

lucio pascarelli

Nov 18, 1998, 5:44pm
Thanks. It worked.

Lucio

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