Gebruiker:Lode/PHP highlight test 2
Uit 3Dwiki
[bewerken] een
<?
//////////////////////////////////////////////////////// // Config ////////////////////////////////////////////////////////
// Universe $Config['Host'] = "auth.activeworlds.com"; $Config['Port'] = 0;
// Login $Config['Owner'] = 12345; $Config['Pass'] = "mypass"; $Config['BotName'] = "BotName";
// Default World $Config['World'] = "MyWorld";
//////////////////////////////////////////////////////// // Control Structure ////////////////////////////////////////////////////////
// Load php_awsdk if (!extension_loaded("AWSDK")) {
dl ("extensions/php_awsdk.dll");
if (!extension_loaded("AWSDK"))
die ("AW-SDK is not loaded!");
}
// Initialize app stuff app_init ();
// Initialize & login with SDK if ($rc = sdk_login ()) {
die ("Error: $rc");
}
// Tell the client that its plain text header ("Content-type: text/plain");
// Propdump header echo ("propdump version 1\n");
// The main propdump loop aw_int_set (AW_CELL_ITERATOR, 0); while (!aw_cell_next ()) {
// Just loop
}
// Clean up sdk_term (); app_term ();
//////////////////////////////////////////////////////// // Functions ////////////////////////////////////////////////////////
function sdk_login () {
global $bot;
global $Config;
// Initialize
if ($rc = aw_init (AW_BUILD)) {
sdk_term ();
return $rc;
}
// Connect
if ($rc = aw_create ($Config['Host'], $Config['Port'], &$bot)) {
sdk_term ();
return $rc;
}
// Set login vars
aw_int_set (AW_LOGIN_OWNER, $Config['Owner']);
aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, $Config['Pass']);
aw_string_set (AW_LOGIN_NAME, $Config['BotName']);
aw_string_set (AW_LOGIN_APPLICATION, "php_awsdk");
// Set event handlers
aw_event_set (AW_EVENT_CELL_OBJECT);
aw_event_unset (AW_CALLBACK_CELL_RESULT);
// Login
if ($rc = aw_login ()) {
sdk_term ();
return $rc;
}
// Enter world
if ($rc = aw_enter ($Config['World'])) {
sdk_term ();
return $rc;
}
return 0;
}
function sdk_term () {
aw_exit (); aw_destroy (); aw_term ();
}
function app_init () {
ignore_user_abort (true); set_time_limit (0);
}
function app_term () {
}
//////////////////////////////////////////////////////// // Event Handlers ////////////////////////////////////////////////////////
function aw_event_cell_object () {
$cit = aw_int (AW_OBJECT_OWNER); $time = aw_int (AW_OBJECT_BUILD_TIMESTAMP);
$x = aw_int (AW_OBJECT_X); $y = aw_int (AW_OBJECT_Y); $z = aw_int (AW_OBJECT_Z); $yaw = aw_int (AW_OBJECT_YAW);
$model = aw_string (AW_OBJECT_MODEL); $desc = aw_string (AW_OBJECT_DESCRIPTION); $action = aw_string (AW_OBJECT_ACTION);
$lenModel = strlen(model); $lenDesc = strlen(desc); $lenAction = strlen(action);
// Format vars in the standard propdump format
$data = sprintf ("%d %d %d %d %d %d %d %d %d %s%s%s\n",
$cit, $time, $x, $y, $z, $yaw,
$lenModel, $lenDesc, $lenAction,
$model, $desc, $action);
echo ($data);
}
?>
[bewerken] twee
<?
for ($i=0;$i<3;$i++) {
for ($j=0;$j<3;$j++) {
$seq[$i][$j] = 0;
}
}
// Universe $Config['Host'] = "auth.activeworlds.com"; $Config['Port'] = 0;
// Login $Config['Owner'] = 12345; $Config['Pass'] = "mypass"; $Config['BotName'] = "BotName";
// Default World $Config['World'] = "MyWorld";
/////////////////////////////////////////////////////// // INITIALIZE ///////////////////////////////////////////////////////
header ("Content-type: text/plain\n");
// Load php_awsdk if (!extension_loaded("AWSDK")) {
dl ("extensions/php_awsdk.dll");
if (!extension_loaded("AWSDK"))
die ("AW-SDK is not loaded!");
}
debug_out ("aw_init"); if ($rc = aw_init (AW_BUILD))
die ("aw_init: $rc
\n");
aw_event_set (AW_EVENT_CELL_BEGIN); aw_event_set (AW_EVENT_CELL_OBJECT); //aw_callback_set (AW_CALLBACK_QUERY);
///////////////////////////////////////////////////////
// BOT 1 LOGIN
///////////////////////////////////////////////////////
debug_out ("aw_create"); settype ($bot, "integer"); if ($rc = aw_create ($Config['Host'], $Config['Port'], &$bot))
die ("aw_create: $rc
\n");
debug_out ("Setting login variables"); aw_int_set (AW_LOGIN_OWNER, $Config['Owner']); aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, $Config['Pass']); aw_string_set (AW_LOGIN_NAME, $Config['BotName'] . " 1"); aw_string_set (AW_LOGIN_APPLICATION, "php_awsdk");
debug_out ("aw_login"); if ($rc = aw_login ())
die ("aw_login: $rc
\n");
debug_out ("Logged in");
debug_out ("aw_enter"); if ($rc = aw_enter ($Config['World']))
die ("aw_enter: $rc
\n");
/////////////////////////////////////////////////////// // TESTS ///////////////////////////////////////////////////////
$obj_count=0;
$i = 0; do {
aw_say ("Query $i");
$rc = aw_query_func ();
aw_wait (100);
$i++;
} while (!aw_bool (AW_QUERY_COMPLETE));
/////////////////////////////////////////////////////// // TERMINATE ///////////////////////////////////////////////////////
debug_out ("TOTAL OBJECTS: $obj_count");
debug_out ("aw_destroy"); aw_destroy ();
debug_out ("aw_term"); aw_term ();
/////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////
function term ($message) {
die ("$message
\n");
}
function debug_out ($message) {
//echo ("$message
\n");
}
function aw_query_func () {
global $seq;
global $sx;
global $sz;
return aw_query ($sx, $sz, $seq);
/*
return aw_query ($sx, $sz,
$seq[0][0], $seq[0][1], $seq[0][2],
$seq[1][0], $seq[1][1], $seq[1][2],
$seq[2][0], $seq[2][1], $seq[2][2]);
*/
}
function aw_event_cell_begin () {
global $sx; global $sy; global $seq;
$cx = aw_int (AW_CELL_X);
$cz = aw_int (AW_CELL_Z);
$sx = aw_sector_from_cell ($cx);
$sz = aw_sector_from_cell ($cz);
/* sanity check: make sure sector coordinates are within range */
if ($sx < -1 || $sx > 1 || $sz < -1 || $sz > 1)
return;
$seq[$sz+1][$sx+1] = aw_int (AW_CELL_SEQUENCE);
}
function aw_event_cell_object () {
global $obj_count; $obj_count++;
$cit = aw_int (AW_OBJECT_OWNER); $time = aw_int (AW_OBJECT_BUILD_TIMESTAMP);
$x = aw_int (AW_OBJECT_X); $y = aw_int (AW_OBJECT_Y); $z = aw_int (AW_OBJECT_Z); $yaw = aw_int (AW_OBJECT_YAW);
$model = aw_string (AW_OBJECT_MODEL); $desc = aw_string (AW_OBJECT_DESCRIPTION); $action = aw_string (AW_OBJECT_ACTION);
$lenModel = strlen(model); $lenDesc = strlen(desc); $lenAction = strlen(action);
// Format vars in the standard propdump format
$data = sprintf ("%d %d %d %d %d %d %d %d %d %s%s%s\n",
$cit, $time, $x, $y, $z, $yaw,
$lenModel, $lenDesc, $lenAction,
$model, $desc, $action);
echo ($data);
}
function aw_event_callback_query ($rc) {
}
?>
[bewerken] drie
<?
for ($i=0;$i<5;$i++) {
for ($j=0;$j<5;$j++) {
$seq[$i][$j] = 0;
}
}
// Universe $Config['Host'] = "auth.activeworlds.com"; $Config['Port'] = 0;
// Login $Config['Owner'] = 12345; $Config['Pass'] = "mypass"; $Config['BotName'] = "BotName";
// Default World $Config['World'] = "MyWorld";
/////////////////////////////////////////////////////// // INITIALIZE ///////////////////////////////////////////////////////
header ("Content-type: text/plain\n");
// Load php_awsdk if (!extension_loaded("AWSDK")) {
dl ("extensions/php_awsdk.dll");
if (!extension_loaded("AWSDK"))
die ("AW-SDK is not loaded!");
}
debug_out ("aw_init"); if ($rc = aw_init (AW_BUILD))
die ("aw_init: $rc
\n");
aw_event_set (AW_EVENT_CELL_BEGIN); aw_event_set (AW_EVENT_CELL_OBJECT); //aw_callback_set (AW_CALLBACK_QUERY);
///////////////////////////////////////////////////////
// BOT 1 LOGIN
///////////////////////////////////////////////////////
debug_out ("aw_create"); settype ($bot, "integer"); if ($rc = aw_create ($Config['Host'], $Config['Port'], &$bot))
die ("aw_create: $rc
\n");
debug_out ("Setting login variables"); aw_int_set (AW_LOGIN_OWNER, $Config['Owner']); aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, $Config['Pass']); aw_string_set (AW_LOGIN_NAME, $Config['BotName'] . " 1"); aw_string_set (AW_LOGIN_APPLICATION, "php_awsdk");
debug_out ("aw_login"); if ($rc = aw_login ())
die ("aw_login: $rc
\n");
debug_out ("Logged in");
debug_out ("aw_enter"); if ($rc = aw_enter ($Config['World']))
die ("aw_enter: $rc
\n");
/////////////////////////////////////////////////////// // TESTS ///////////////////////////////////////////////////////
$obj_count=0;
$i = 0; do {
aw_say ("Query $i");
$rc = aw_query_func ();
aw_wait (100);
$i++;
} while (!aw_bool (AW_QUERY_COMPLETE));
/////////////////////////////////////////////////////// // TERMINATE ///////////////////////////////////////////////////////
debug_out ("TOTAL OBJECTS: $obj_count");
debug_out ("aw_destroy"); aw_destroy ();
debug_out ("aw_term"); aw_term ();
/////////////////////////////////////////////////////// // Functions ///////////////////////////////////////////////////////
function term ($message) {
die ("$message
\n");
}
function debug_out ($message) {
//echo ("$message
\n");
}
function aw_query_func () {
global $seq; global $sx; global $sz; return aw_query_5x5 ($sx, $sz, $seq);
}
function aw_event_cell_begin () {
global $sx; global $sy; global $seq;
$cx = aw_int (AW_CELL_X);
$cz = aw_int (AW_CELL_Z);
$sx = aw_sector_from_cell ($cx);
$sz = aw_sector_from_cell ($cz);
/* sanity check: make sure sector coordinates are within range */
if ($sx < -2 || $sx > 2 || $sz < -2 || $sz > 2)
return;
$seq[$sz+2][$sx+2] = aw_int (AW_CELL_SEQUENCE);
}
function aw_event_cell_object () {
global $obj_count; $obj_count++;
$cit = aw_int (AW_OBJECT_OWNER); $time = aw_int (AW_OBJECT_BUILD_TIMESTAMP);
$x = aw_int (AW_OBJECT_X); $y = aw_int (AW_OBJECT_Y); $z = aw_int (AW_OBJECT_Z); $yaw = aw_int (AW_OBJECT_YAW);
$model = aw_string (AW_OBJECT_MODEL); $desc = aw_string (AW_OBJECT_DESCRIPTION); $action = aw_string (AW_OBJECT_ACTION);
$lenModel = strlen(model); $lenDesc = strlen(desc); $lenAction = strlen(action);
// Format vars in the standard propdump format
$data = sprintf ("%d %d %d %d %d %d %d %d %d %s%s%s\n",
$cit, $time, $x, $y, $z, $yaw,
$lenModel, $lenDesc, $lenAction,
$model, $desc, $action);
echo ($data);
}
function aw_event_callback_query ($rc) {
}
?>

