break; case 3: $tx = $inner_x + -1 * $cur_x; $ty = $inner_y + $cur_y; break; } echo "Getting {$tx}, {$ty}\r\n"; // Use this to get only outside of the map if wanted. if (sqrt(pow($cur_x, 2) + pow($cur_y, 2) - pow($cur_y / 2, 2)) >= $min_radius) { $count++; $status = $won->GetWorldMap($tx, $ty, $scan_size, $scan_size); if (!$status) { echo "Error: Failed to load map for {$tx}, {$ty}\r\n"; break; } DataLoadDAO::operationComplete($won->db, $won->data_load_id); usleep(500000); // Wait half a second between calls - just because } $cur_x += $interval; } // We're done with the X axis for this row, Increment Y and reset X to 0 if (!$status) { break; } $cur_y += $interval; $cur_x = 0; } // We're done with this quadant, Increment the quadrant and reset Y to 0 if (!$status) { break;
public function Run() { $heartbeat_msg = '{"payload":{},"type":"heartbeat"}'; $log_seq = 0; $func_args = func_get_args(); $func_log_id = DataLoadLogDAO::startFunction($this->db, $this->data_load_id, __CLASS__, __FUNCTION__, $func_args); $seconds_between_heartbeat = 30; $closed = false; while (1) { DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Send heartbeat message"); echo "Sending: {$heartbeat_msg}\n----------\n"; $this->client->send($heartbeat_msg); $last_heartbeat = microtime(true); DataLoadDAO::operationComplete($this->db, $this->data_load_id); // This loop controls how many times we will try go receive in between heartbeats //for($i = 0; $i < 1; $i++) { // Continue reading until we run out of content to read, disconnect, or reach our heartbeat time while (1) { try { $message_handled = false; $opcode = ''; DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Listening..."); $seconds_since_heartbeat = microtime(true) - $last_heartbeat; echo "Seconds Since Heartbeat: {$seconds_since_heartbeat}\n"; $new_timeout = round($seconds_between_heartbeat - $seconds_since_heartbeat, 0); if ($new_timeout <= 0) { break; } echo "New Heartbeat Timeout: {$new_timeout} seconds\n"; echo "Receiving: "; $this->client->setTimeout($new_timeout); $data = $this->client->receive(); $opcode = $this->client->getLastOpcode(); echo "{$opcode}\n"; DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'MESSAGE', "Receive Complete [{$opcode}]"); //, $data); // Handle special cases here switch ($opcode) { case 'ping': // Respond with pong echo "Sending Pong\n----------\n"; DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Sending pong message"); $this->client->send('', 'pong'); $message_handled = true; break; case 'close': echo "Received Close. Disconnecting...\n"; DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', "Sending pong message"); $message_handled = true; $closed = true; break; } // If we already handled this message, go receive a new one if ($message_handled) { break; } try { echo "Trying to decode string\n"; $decoded_data = @gzdecode($data); if ($decoded_data == false) { echo "String not compressed\n{$data}\n==========\n"; DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'MESSAGE', "[{$opcode}] Message Not Compressed", $data); } else { $data = $decoded_data; echo "DECODED:\n{$data}\n==========\n"; DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'MESSAGE', "Decoded [{$opcode}] message", $data); } } catch (Exception $ex) { echo "Error\n"; } } catch (Exception $ex) { echo "No Data Found\n"; DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "No Data Found [{$opcode}]", $ex->getMessage(), 1); //usleep(5000000); //break; } } //} if ($closed) { break; } } DataLoadLogDAO::completeFunction($this->db, $func_log_id, 'Finished with Listener, this should never happen'); }