<?php

include_once("internal/log.php");

// --------------------------------------------
abstract class Tracker {
	// general time based update
	public function update($time) {}

	// match status events
	protected function handle_match_end($doc) {}
	protected function handle_faction_lost($doc) {}
	// base state events
	protected function handle_base_owner_change_event($doc) {}
	// comms services state events
	protected function handle_comms_change_event($doc) {}
	// vehicle state events
	protected function handle_vehicle_holder_change_event($doc) {}
	protected function handle_vehicle_destroyed_event($doc) {}
	// chat events
	protected function handle_chat_event($doc) {}
	// results for script issued queries
	protected function handle_query_result($doc) {}
	// player events
	protected function handle_player_connect_event($doc) {}
	protected function handle_player_disconnect_event($doc) {}
	protected function handle_player_spawn_event($doc) {}
	protected function handle_player_kill_event($doc) {}
	protected function handle_player_die_event($doc) {}
	// hitbox events
	protected function handle_hitbox_event($doc) {}
	// item events
	protected function handle_item_drop_event($doc) {}

	function handle_event($doc) {
		// check message type and dispatch to a handler
		$root_name = $doc->firstChild->localName;
		if ($root_name == "match_result") {
			$this->handle_match_end($doc);
		} else if ($root_name == "query_result") {
			$this->handle_query_result($doc);
		} else if ($root_name == "comms_change_event") {
			$this->handle_comms_change_event($doc);
		} else if ($root_name == "vehicle_holder_change_event") {
			$this->handle_vehicle_holder_change_event($doc);
		} else if ($root_name == "vehicle_destroyed_event") {
			$this->handle_vehicle_destroyed_event($doc);
		} else if ($root_name == "base_owner_change_event") {
			$this->handle_base_owner_change_event($doc);
		} else if ($root_name == "chat_event") {
			$this->handle_chat_event($doc);
		} else if ($root_name == "player_connect_event") {
			$this->handle_player_connect_event($doc);
		} else if ($root_name == "player_disconnect_event") {
			$this->handle_player_disconnect_event($doc);
		} else if ($root_name == "player_spawn") {
			$this->handle_player_spawn_event($doc);
		} else if ($root_name == "player_kill") {
			$this->handle_player_kill_event($doc);
		} else if ($root_name == "player_die") {
			$this->handle_player_die_event($doc);
		} else if ($root_name == "hitbox_event") {
			$this->handle_hitbox_event($doc);
		} else if ($root_name == "dummy_event") {
		} else if ($root_name == "faction_lost") {
			$this->handle_faction_lost($doc);
		} else if ($root_name == "item_drop_event") {
			$this->handle_item_drop_event($doc);
		} else {
			_log("unhandled message: " . $root_name);
		}
	}

	abstract function has_started();
	abstract function has_ended();
}


?>