diff --git a/BaseAPI.php b/BaseAPI.php
new file mode 100755
index 0000000..1251d6f
--- /dev/null
+++ b/BaseAPI.php
@@ -0,0 +1,165 @@
+ pear install HTTP_Request
+
+class BaseAPI {
+ protected $resource_base = "";
+ protected $resource_uri = "";
+ protected $api_version = "";
+ protected $response_type = "";
+
+ protected $output_array = true;
+
+ //Properties set-response-type
+ public function set_response_type($response_type) {
+ $this->response_type = $response_type;
+ }
+
+ //Properties get-response-type
+ public function get_response_type() {
+ return $this->response_type;
+ }
+
+ //Properties set-output-array
+ public function set_output_array($output_array) {
+ $this->output_array = $output_array;
+ }
+
+ //Properties get-output-array
+ public function get_output_array() {
+ return $this->output_array;
+ }
+
+
+ //Properties set-api-version
+ public function set_api_version($version) {
+ $this->api_version = $version;
+ }
+
+ //Properties get-api-version
+ public function get_api_version() {
+ return $this->api_version;
+ }
+
+ //DO - get
+ public function _do_get($resource_request, $headers) {
+ if (function_exists('curl_init')) {
+ $curl = curl_init();
+
+ //TODO: add headers
+ //curl_setopt($curl, CURLOPT_HEADER, 0);
+ curl_setopt($curl, CURLOPT_URL, $resource_request);
+ curl_setopt($curl, CURLOPT_USERAGENT, CommonConstants::$LIB_NAME . ' ' . CommonConstants::$LIB_VERSION . ' (curl) ' . phpversion());
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+
+ $response_content = curl_exec($curl);
+ $response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+
+ //echo $response_code;
+
+ if ($response_code && $response_code >= 400 ) {
+ throw new Exception($response_code . ' ' . $response_content);
+ }
+
+ curl_close($curl);
+ } else {
+ $request =& new HTTP_Request($resource_request);
+
+ //$request->setMethod(HTTP_REQUEST_METHOD_GET;
+
+ if ($headers != null) {
+ foreach($headers as $header_name => $header_value) {
+ $request->addHeader($header_name, $header_value);
+ }
+ }
+
+ if (!PEAR::isError($request->sendRequest())) {
+ $response_content = $request->getResponseBody();
+ } else {
+ die($response->getMessage());
+ }
+
+ //echo $client->status;
+
+ if ($request->getResponseCode() >= 400) {
+ throw new Exception($request->getResponseCode() . ' ' . $response_content);
+ }
+ }
+
+ if ($this->output_array) {
+ $response_content = ArrayUtil::to_array($response_content, $this->get_response_type());
+ }
+
+ return $response_content;
+ }
+
+ //DO - post -- $post_data should be in the following format array('name' => 'Some Name', 'email' => 'email@example.com'));
+ public function _do_post($resource_request, $post_data, $headers) {
+ if (function_exists('curl_init')) {
+ $curl = curl_init();
+
+ //TODO: add headers
+ //curl_setopt($curl, CURLOPT_HEADER, 0);
+ curl_setopt($curl, CURLOPT_URL, $resource_request);
+ curl_setopt($curl, CURLOPT_USERAGENT, CommonConstants::$LIB_NAME . ' ' . CommonConstants::$LIB_VERSION . ' (curl) ' . phpversion());
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+
+ curl_setopt($ch, CURLOPT_POST, 1);
+
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->convert_post_data($post_data));
+
+ $response_content = curl_exec($curl);
+ $reponse_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+
+ curl_close($curl);
+ } else {
+ $request =& new HTTP_Request($resource_request);
+
+ $request->setMethod(HTTP_REQUEST_METHOD_POST);
+
+ if ($headers != null) {
+ foreach($headers as $header_name => $header_value) {
+ $request->addHeader($header_name, $header_value);
+ }
+ }
+
+ if ($post_data != null) {
+ foreach($post_data as $post_data_name => $post_name_value) {
+ $request->addPostData($post_data_name, $post_name_value);
+ }
+ }
+ //$request->setBody('264730435 http://api.msappspace.com/v1/users/264730435 none ');
+
+ //$request->setBody("\r\n");
+
+ if (!PEAR::isError($request->sendRequest())) {
+ $response_content = $request->getResponseBody();
+ } else {
+ die($response->getMessage());
+ }
+
+ //echo $client->status;
+
+ if ($request->getResponseCode() >= 400) {
+ throw new Exception($request->getResponseCode() . ' ' . $response_content);
+ }
+ }
+
+ return $response_content;
+ }
+
+ //DO - put -- $put_data should be in the following format array('name' => 'Some Name', 'email' => 'email@example.com'));
+ public function _do_put($resource_request, $put_data, $headers) {
+ $put_override_header = array(CommonConstants::$X_HTTP_METHOD_OVERRIDE_HEADER => 'PUT');
+
+ if ($headers != null) {
+ $headers = array_merge($headers, $put_override_header);
+ } else {
+ $headers = $put_override_header;
+ }
+
+ return $this->_do_post($resource_request, $put_data, $headers);
+ }
+}
+?>
\ No newline at end of file
diff --git a/Common.php b/Common.php
new file mode 100755
index 0000000..1173883
--- /dev/null
+++ b/Common.php
@@ -0,0 +1,295 @@
+
\ No newline at end of file
diff --git a/MyOpenSpaceAPI.php b/MyOpenSpaceAPI.php
new file mode 100755
index 0000000..de84bf4
--- /dev/null
+++ b/MyOpenSpaceAPI.php
@@ -0,0 +1,171 @@
+opensocial_view = $view;
+ }
+
+ public function set_opensocial_detail($detail) {
+ $this->opensocial_detail = $detail;
+ }
+
+ public function set_openocial_token($token) {
+ $this->opensocial_token = $token;
+ }
+
+ public function set_context($context) {
+ $this->context = $context;
+ }
+
+ //ctor
+ public function __construct($opensocial_token, $opensocial_view, $opensocial_detail) {
+ $this->opensocial_token = $opensocial_token;
+ $this->api_version = ApiVersionType::$VERSION1;
+
+ $this->resource_base = CommonConstants::$URL_OPENSOCIAL_ROOT_API;
+ $this->response_type = ResponseType::$XML;
+ $this->context = ContextType::$VIEWER;
+ }
+
+ // GETS get_profile
+ public function get_profile() {
+ $resource = 'profile';
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ // GETS get_friends
+ public function get_friends($page = null, $page_size = null, $list = null) {
+ $resource = 'friends';
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ // GETS get_albums
+ public function get_albums($album_id = null) {
+ $resource = 'albums';
+
+ if ($album_id != null) {
+ $resource .= CommonConstants::$URL_SEPERATOR . $album_id;
+ }
+
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ // GETS get_albums_photos
+ public function get_albums_photos($album_id) {
+ $resource = 'albums';
+
+ $resource .= CommonConstants::$URL_SEPERATOR . $album_id;
+ $resource .= CommonConstants::$URL_SEPERATOR . 'photos';
+
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ // GETS get_photos
+ public function get_photos($photo_id = null) {
+ $resource = 'photos';
+
+ if ($album_id != null) {
+ $resource .= CommonConstants::$URL_SEPERATOR . $album_id;
+ }
+
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+ // GETS get_videos
+ public function get_videos($video_id = null) {
+ $resource = 'videos';
+
+ if ($video_id != null) {
+ $resource .= CommonConstants::$URL_SEPERATOR . $video_id;
+ }
+
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ // GETS get_global_appdata
+ public function get_global_appdata($key = null) {
+ $resource = 'appdata/global';
+
+ if ($key != null) {
+ $resource .= CommonConstants::$URL_SEPERATOR . $key;
+ }
+
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ // GETS get_appdata
+ public function get_appdata($key = null) {
+ $resource = 'appdata';
+
+ if ($key != null) {
+ $resource .= CommonConstants::$URL_SEPERATOR . $key;
+ }
+
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ // GETS get_friends_appdata
+ public function get_friends_appdata($key = null) {
+ $resource = 'friends/appdata';
+
+ if ($key != null) {
+ $resource .= CommonConstants::$URL_SEPERATOR . $key;
+ }
+
+ $result = $this->do_get($this->context, $resource, null);
+ return $result;
+ }
+
+ //DO
+ public function do_get($context, $resource, $headers) {
+ $resource_request = $this->resource_base . CommonConstants::$URL_SEPERATOR;
+ $resource_request .= $this->api_version . CommonConstants::$URL_SEPERATOR;
+
+ $resource_request .= $context . CommonConstants::$URL_SEPERATOR;
+ $resource_request .= $resource . "." . $this->get_response_type();
+
+ $resource_request .= "?";
+ $resource_request .= OpenSocialQueryStringList::$QS_OPEN_SOCIAL_TOKEN . "=" . $this->opensocial_token;
+ $resource_request .= "&";
+ $resource_request .= OpenSocialQueryStringList::$QS_OPEN_SOCIAL_VIEW . "=" + $this->opensocial_view;
+ $resource_request .= "&";
+ $resource_request .= OpenSocialQueryStringList::$QS_DETAIL_TYPE . "=" + $this->opensocial_detail;
+
+ return parent::_do_get($resource_request, $headers);
+ }
+
+ //DO
+ public function do_post($resource, $post_data, $headers) {
+ //TODO:
+ return parent::_do_post($resource_request, $post_data, $headers);
+ }
+
+ //DO
+ public function do_put($resource, $put_data, $headers) {
+ //TODO:
+ return parent::_do_put($resource_request, $put_data, $headers);
+ }
+
+ //DO
+ public function validate_oauth($oauth_signature) {
+ //TODO:
+ }
+}
+?>
\ No newline at end of file
diff --git a/MySpaceAPI.php b/MySpaceAPI.php
new file mode 100755
index 0000000..a7b0598
--- /dev/null
+++ b/MySpaceAPI.php
@@ -0,0 +1,196 @@
+application_key = $application_key;
+ $this->application_secret = $application_secret;
+
+ $this->oauth_consumer = new OAuthConsumer($this->application_key, $this->application_secret);
+ $this->oauth_token = new OAuthToken(null, null);
+
+ $this->api_version = ApiVersionType::$VERSION1;
+
+ $this->resource_base = CommonConstants::$URL_ROOT_API;
+ $this->response_type = ResponseType::$XML;
+ }
+
+ // GETS get-user
+ public function get_user($user_id) {
+ $resource = sprintf('users%s%s', CommonConstants::$URL_SEPERATOR, $user_id);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-profile
+ public function get_profile($user_id) {
+ $resource = sprintf('users%s%s%sprofile', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-friends
+ public function get_friends($user_id, $page = null, $page_size = null, $list = null) {
+ $resource = sprintf('users%s%s%sfriends', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $paging = "";
+
+ if ($page !== null) {
+ $paging .= 'page=' . $page . '&';
+ }
+
+ if ($page_size !== null) {
+ $paging .= 'page_size=' . $page_size . '&';
+ }
+
+ if ($list !== null) {
+ $paging .= 'list=' . $list . '&';
+ }
+
+ if (strlen($paging) > 0) {
+ $paging = '?' . substr($paging, 0, strlen($paging)-1);
+ }
+
+ return $this->do_get($resource . $paging, null);
+ }
+
+ //GETS get-friendship
+ public function get_friendship($user_id, $array_ids) {
+ $resource = sprintf('users%s%s%sfriends%s%s', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR, CommonConstants::$URL_SEPERATOR, implode($array_ids, ';'));
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-albums
+ public function get_albums($user_id) {
+ $resource = sprintf('users%s%s%salbums', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-album
+ public function get_album($user_id, $album_id) {
+ $resource = sprintf('users%s%s%salbums%s%s%sphotos', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR, CommonConstants::$URL_SEPERATOR, $album_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-photos
+ public function get_photos($user_id) {
+ $resource = sprintf('users%s%s%sphotos', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-photo
+ public function get_photo($user_id, $photo_id) {
+ $resource = sprintf('users%s%s%sphotos%s%s', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR, CommonConstants::$URL_SEPERATOR, $photo_id);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-interests
+ public function get_interests($user_id) {
+ $resource = sprintf('users%s%s%sinterests', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-details
+ public function get_details($user_id) {
+ $resource = sprintf('users%s%s%sdetails', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-videos
+ public function get_videos($user_id) {
+ $resource = sprintf('users%s%s%svideos', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-video
+ public function get_video($user_id, $video_id) {
+ $resource = sprintf('users%s%s%svideos%s%s', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR, CommonConstants::$URL_SEPERATOR, $video_id);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-groups
+ public function get_groups($user_id) {
+ $resource = sprintf('users%s%s%sgroups', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-status
+ public function get_status($user_id) {
+ $resource = sprintf('users%s%s%sstatus', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-mood
+ public function get_mood($user_id) {
+ $resource = sprintf('users%s%s%smood', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //GETS get-comments
+ public function get_comments($user_id) {
+ $resource = sprintf('users%s%s%scomments', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_get($resource, null);
+ return $result;
+ }
+
+ //PUTS put-mood
+ public function put_mood($user_id, $mood) {
+ $resource = sprintf('users%s%s%smood', CommonConstants::$URL_SEPERATOR, $user_id, CommonConstants::$URL_SEPERATOR);
+ $result = $this->do_put($resource, array('mood' => $mood), null);
+ return $result;
+ }
+
+ public function do_get($resource, $headers) {
+ $this->resource_uri = CommonConstants::$URL_SEPERATOR . $this->api_version . CommonConstants::$URL_SEPERATOR . $resource . '.' . $this->get_response_type();
+ $sha1 = new OAuthSignatureMethod_HMAC_SHA1();
+ $req = OAuthRequest::from_consumer_and_token($this->oauth_consumer, $this->oauth_token, HttpMethodType::$GET, $this->resource_base . $this->resource_uri, $headers);
+ $req->sign_request($sha1, $this->oauth_consumer, null);
+ $resource_request = $req->to_url();
+ return parent::_do_get($resource_request, $headers);
+ }
+
+ public function do_post($resource, $post_data, $headers) {
+ $this->resource_uri = CommonConstants::$URL_SEPERATOR . $this->api_version . CommonConstants::$URL_SEPERATOR . $resource . '.' . $this->get_response_type();
+ $sha1 = new OAuthSignatureMethod_HMAC_SHA1();
+ $req = OAuthRequest::from_consumer_and_token($this->oauth_consumer, $this->oauth_token, HttpMethodType::$GET, $this->resource_base . $this->resource_uri, $headers);
+ $req->sign_request($sha1, $this->oauth_consumer, null);
+ $resource_request = $req->to_url();
+ return parent::_do_post($resource_request, $post_data, $headers);
+ }
+
+ public function do_put($resource, $put_data, $headers) {
+ $this->resource_uri = CommonConstants::$URL_SEPERATOR . $this->api_version . CommonConstants::$URL_SEPERATOR . $resource . '.' . $this->get_response_type();
+ $sha1 = new OAuthSignatureMethod_HMAC_SHA1();
+ $req = OAuthRequest::from_consumer_and_token($this->oauth_consumer, $this->oauth_token, HttpMethodType::$GET, $this->resource_base . $this->resource_uri, $headers);
+ $req->sign_request($sha1, $this->oauth_consumer, null);
+ $resource_request = $req->to_url();
+ return parent::_do_put($resource_request, $put_data, $headers);
+ }
+
+ public function validate_oauth($oauth_signature) {
+ //TODO:
+ }
+}
+?>
\ No newline at end of file
diff --git a/OAuth.php b/OAuth.php
new file mode 100644
index 0000000..6d2f881
--- /dev/null
+++ b/OAuth.php
@@ -0,0 +1,613 @@
+key = $key;
+ $this->secret = $secret;
+ $this->callback_url = $callback_url;
+ }/*}}}*/
+}/*}}}*/
+
+class OAuthToken {/*{{{*/
+ // access tokens and request tokens
+ public $key;
+ public $secret;
+
+ /**
+ * key = the token
+ * secret = the token secret
+ */
+ function __construct($key, $secret) {/*{{{*/
+ $this->key = $key;
+ $this->secret = $secret;
+ }/*}}}*/
+
+ /**
+ * generates the basic string serialization of a token that a server
+ * would respond to request_token and access_token calls with
+ */
+ function to_string() {/*{{{*/
+ return "oauth_token=" . urlencode($this->key) .
+ "&oauth_token_secret=" . urlencode($this->secret);
+ }/*}}}*/
+
+ function __toString() {/*{{{*/
+ return $this->to_string();
+ }/*}}}*/
+}/*}}}*/
+
+class OAuthSignatureMethod {/*{{{*/
+
+}/*}}}*/
+
+class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {/*{{{*/
+ function get_name() {/*{{{*/
+ return "HMAC-SHA1";
+ }/*}}}*/
+
+ public function build_signature($request, $consumer, $token) {/*{{{*/
+ $sig = array(
+ urlencode($request->get_normalized_http_method()),
+ preg_replace('/%7E/', '~', urlencode($request->get_normalized_http_url())),
+ urlencode($request->get_signable_parameters()),
+ );
+
+ $key = urlencode($consumer->secret) . "&";
+
+ if ($token) {
+ $key .= urlencode($token->secret);
+ }
+
+ $raw = implode("&", $sig);
+ // for debug purposes
+ $request->base_string = $raw;
+
+ // this is silly.
+ $hashed = base64_encode(hash_hmac("sha1", $raw, $key, TRUE));
+ return $hashed;
+ }/*}}}*/
+}/*}}}*/
+
+class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {/*{{{*/
+ public function get_name() {/*{{{*/
+ return "PLAINTEXT";
+ }/*}}}*/
+ public function build_signature($request, $consumer, $token) {/*{{{*/
+ $sig = array(
+ urlencode($consumer->secret)
+ );
+
+ if ($token) {
+ array_push($sig, urlencode($token->secret));
+ } else {
+ array_push($sig, '');
+ }
+
+ $raw = implode("&", $sig);
+ // for debug purposes
+ $request->base_string = $raw;
+
+ return urlencode($raw);
+ }/*}}}*/
+}/*}}}*/
+
+class OAuthRequest {/*{{{*/
+ private $parameters;
+ private $http_method;
+ private $http_url;
+ // for debug purposes
+ public $base_string;
+ public static $version = '1.0';
+
+ function __construct($http_method, $http_url, $parameters=NULL) {/*{{{*/
+ @$parameters or $parameters = array();
+ $this->parameters = $parameters;
+ $this->http_method = $http_method;
+ $this->http_url = $http_url;
+ }/*}}}*/
+
+ /**
+ * attempt to build up a request from what was passed to the server
+ */
+ public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {/*{{{*/
+ @$http_url or $http_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+ @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
+
+ $request_headers = OAuthRequest::get_headers();
+
+ // let the library user override things however they'd like, if they know
+ // which parameters to use then go for it, for example XMLRPC might want to
+ // do this
+ if ($parameters) {
+ $req = new OAuthRequest($http_method, $http_url, $parameters);
+ }
+ // next check for the auth header, we need to do some extra stuff
+ // if that is the case, namely suck in the parameters from GET or POST
+ // so that we can include them in the signature
+ else if (@substr($request_headers['Authorization'], 0, 5) == "OAuth") {
+ $header_parameters = OAuthRequest::split_header($request_headers['Authorization']);
+ if ($http_method == "GET") {
+ $req_parameters = $_GET;
+ }
+ else if ($http_method = "POST") {
+ $req_parameters = $_POST;
+ }
+ $parameters = array_merge($header_parameters, $req_parameters);
+ $req = new OAuthRequest($http_method, $http_url, $parameters);
+ }
+ else if ($http_method == "GET") {
+ $req = new OAuthRequest($http_method, $http_url, $_GET);
+ }
+ else if ($http_method == "POST") {
+ $req = new OAuthRequest($http_method, $http_url, $_POST);
+ }
+ return $req;
+ }/*}}}*/
+
+ /**
+ * pretty much a helper function to set up the request
+ */
+ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {/*{{{*/
+ @$parameters or $parameters = array();
+ $defaults = array("oauth_version" => OAuthRequest::$version,
+ "oauth_nonce" => OAuthRequest::generate_nonce(),
+ "oauth_timestamp" => OAuthRequest::generate_timestamp(),
+ "oauth_consumer_key" => $consumer->key);
+ $parameters = array_merge($defaults, $parameters);
+
+ if ($token) {
+ $parameters['oauth_token'] = $token->key;
+ }
+ return new OAuthRequest($http_method, $http_url, $parameters);
+ }/*}}}*/
+
+ public function set_parameter($name, $value) {
+ $this->parameters[$name] = $value;
+ }
+
+ public function get_parameter($name) {
+ return $this->parameters[$name];
+ }
+
+ public function get_parameters() {
+ return $this->parameters;
+ }
+
+ /**
+ * return a string that consists of all the parameters that need to be signed
+ */
+ public function get_signable_parameters() {/*{{{*/
+ $sorted = $this->parameters;
+ ksort($sorted);
+
+ $total = array();
+ foreach ($sorted as $k => $v) {
+ if ($k == "oauth_signature") continue;
+ //$total[] = $k . "=" . $v;
+ // andy, apparently we need to double encode or something yuck
+ $total[] = urlencode($k) . "=" . urlencode($v);
+ }
+ return implode("&", $total);
+ }/*}}}*/
+
+ /**
+ * just uppercases the http method
+ */
+ public function get_normalized_http_method() {/*{{{*/
+ return strtoupper($this->http_method);
+ }/*}}}*/
+
+ /**
+ * parses the url and rebuilds it to be
+ * scheme://host/path
+ */
+ public function get_normalized_http_url() {/*{{{*/
+ $parts = parse_url($this->http_url);
+ $port = "";
+ if( array_key_exists('port', $parts) && $parts['port'] != '80' ){
+ $port = ':' . $parts['port'];
+ }
+ ## aroth, updated to include port
+ $url_string =
+ "{$parts['scheme']}://{$parts['host']}{$port}{$parts['path']}";
+ return $url_string;
+ }/*}}}*/
+
+ /**
+ * builds a url usable for a GET request
+ */
+ public function to_url() {/*{{{*/
+ $out = $this->get_normalized_http_url() . "?";
+ $out .= $this->to_postdata();
+ return $out;
+ }/*}}}*/
+
+ /**
+ * builds the data one would send in a POST request
+ */
+ public function to_postdata() {/*{{{*/
+ $total = array();
+ foreach ($this->parameters as $k => $v) {
+ $total[] = urlencode($k) . "=" . urlencode($v);
+ }
+ $out = implode("&", $total);
+ return $out;
+ }/*}}}*/
+
+ /**
+ * builds the Authorization: header
+ */
+ public function to_header() {/*{{{*/
+ $out ='"Authorization: OAuth realm="",';
+ $total = array();
+ foreach ($this->parameters as $k => $v) {
+ if (substr($k, 0, 5) != "oauth") continue;
+ $total[] = urlencode($k) . '="' . urlencode($v) . '"';
+ }
+ $out = implode(",", $total);
+ return $out;
+ }/*}}}*/
+
+ public function __toString() {/*{{{*/
+ return $this->to_url();
+ }/*}}}*/
+
+
+ public function sign_request($signature_method, $consumer, $token) {/*{{{*/
+ $this->set_parameter("oauth_signature_method", $signature_method->get_name());
+ $signature = $this->build_signature($signature_method, $consumer, $token);
+ $this->set_parameter("oauth_signature", $signature);
+ }/*}}}*/
+
+ public function build_signature($signature_method, $consumer, $token) {/*{{{*/
+ $signature = $signature_method->build_signature($this, $consumer, $token);
+ return $signature;
+ }/*}}}*/
+
+ /**
+ * util function: current timestamp
+ */
+ private static function generate_timestamp() {/*{{{*/
+ return time();
+ }/*}}}*/
+
+ /**
+ * util function: current nonce
+ */
+ private static function generate_nonce() {/*{{{*/
+ $mt = microtime();
+ $rand = mt_rand();
+
+ return md5($mt . $rand); // md5s look nicer than numbers
+ }/*}}}*/
+
+ /**
+ * util function for turning the Authorization: header into
+ * parameters, has to do some unescaping
+ */
+ private static function split_header($header) {/*{{{*/
+ // this should be a regex
+ // error cases: commas in parameter values
+ $parts = explode(",", $header);
+ $out = array();
+ foreach ($parts as $param) {
+ $param = ltrim($param);
+ // skip the "realm" param, nobody ever uses it anyway
+ if (substr($param, 0, 5) != "oauth") continue;
+
+ $param_parts = explode("=", $param);
+
+ // rawurldecode() used because urldecode() will turn a "+" in the
+ // value into a space
+ $out[$param_parts[0]] = rawurldecode(substr($param_parts[1], 1, -1));
+ }
+ return $out;
+ }/*}}}*/
+
+ /**
+ * helper to try to sort out headers for people who aren't running apache
+ */
+ private static function get_headers() {
+ if (function_exists('apache_request_headers')) {
+ // we need this to get the actual Authorization: header
+ // because apache tends to tell us it doesn't exist
+ return apache_request_headers();
+ }
+ // otherwise we don't have apache and are just going to have to hope
+ // that $_SERVER actually contains what we need
+ $out = array();
+ foreach ($_SERVER as $key => $value) {
+ if (substr($key, 0, 5) == "HTTP_") {
+ // this is chaos, basically it is just there to capitalize the first
+ // letter of every word that is not an initial HTTP and strip HTTP
+ // code from przemek
+ $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
+ $out[$key] = $value;
+ }
+ }
+ return $out;
+ }
+}/*}}}*/
+
+class OAuthServer {/*{{{*/
+ protected $timestamp_threshold = 300; // in seconds, five minutes
+ protected $version = 1.0; // hi blaine
+ protected $signature_methods = array();
+
+ protected $data_store;
+
+ function __construct($data_store) {/*{{{*/
+ $this->data_store = $data_store;
+ }/*}}}*/
+
+ public function add_signature_method($signature_method) {/*{{{*/
+ $this->signature_methods[$signature_method->get_name()] =
+ $signature_method;
+ }/*}}}*/
+
+ // high level functions
+
+ /**
+ * process a request_token request
+ * returns the request token on success
+ */
+ public function fetch_request_token(&$request) {/*{{{*/
+ $this->get_version($request);
+
+ $consumer = $this->get_consumer($request);
+
+ // no token required for the initial token request
+ $token = NULL;
+
+ $this->check_signature($request, $consumer, $token);
+
+ $new_token = $this->data_store->new_request_token($consumer);
+
+ return $new_token;
+ }/*}}}*/
+
+ /**
+ * process an access_token request
+ * returns the access token on success
+ */
+ public function fetch_access_token(&$request) {/*{{{*/
+ $this->get_version($request);
+
+ $consumer = $this->get_consumer($request);
+
+ // requires authorized request token
+ $token = $this->get_token($request, $consumer, "request");
+
+ $this->check_signature($request, $consumer, $token);
+
+ $new_token = $this->data_store->new_access_token($token, $consumer);
+
+ return $new_token;
+ }/*}}}*/
+
+ /**
+ * verify an api call, checks all the parameters
+ */
+ public function verify_request(&$request) {/*{{{*/
+ $this->get_version($request);
+ $consumer = $this->get_consumer($request);
+ $token = $this->get_token($request, $consumer, "access");
+ $this->check_signature($request, $consumer, $token);
+ return array($consumer, $token);
+ }/*}}}*/
+
+ // Internals from here
+ /**
+ * version 1
+ */
+ private function get_version(&$request) {/*{{{*/
+ $version = $request->get_parameter("oauth_version");
+ if (!$version) {
+ $version = 1.0;
+ }
+ if ($version && $version != $this->version) {
+ throw new OAuthException("OAuth version '$version' not supported");
+ }
+ return $version;
+ }/*}}}*/
+
+ /**
+ * figure out the signature with some defaults
+ */
+ private function get_signature_method(&$request) {/*{{{*/
+ $signature_method =
+ @$request->get_parameter("oauth_signature_method");
+ if (!$signature_method) {
+ $signature_method = "PLAINTEXT";
+ }
+ if (!in_array($signature_method,
+ array_keys($this->signature_methods))) {
+ throw new OAuthException(
+ "Signature method '$signature_method' not supported try one of the following: " . implode(", ", array_keys($this->signature_methods))
+ );
+ }
+ return $this->signature_methods[$signature_method];
+ }/*}}}*/
+
+ /**
+ * try to find the consumer for the provided request's consumer key
+ */
+ private function get_consumer(&$request) {/*{{{*/
+ $consumer_key = @$request->get_parameter("oauth_consumer_key");
+ if (!$consumer_key) {
+ throw new OAuthException("Invalid consumer key");
+ }
+
+ $consumer = $this->data_store->lookup_consumer($consumer_key);
+ if (!$consumer) {
+ throw new OAuthException("Invalid consumer");
+ }
+
+ return $consumer;
+ }/*}}}*/
+
+ /**
+ * try to find the token for the provided request's token key
+ */
+ private function get_token(&$request, $consumer, $token_type="access") {/*{{{*/
+ $token_field = @$request->get_parameter('oauth_token');
+ $token = $this->data_store->lookup_token(
+ $consumer, $token_type, $token_field
+ );
+ if (!$token) {
+ throw new OAuthException("Invalid $token_type token: $token_field");
+ }
+ return $token;
+ }/*}}}*/
+
+ /**
+ * all-in-one function to check the signature on a request
+ * should guess the signature method appropriately
+ */
+ private function check_signature(&$request, $consumer, $token) {/*{{{*/
+ // this should probably be in a different method
+ $timestamp = @$request->get_parameter('oauth_timestamp');
+ $nonce = @$request->get_parameter('oauth_nonce');
+
+ $this->check_timestamp($timestamp);
+ $this->check_nonce($consumer, $token, $nonce, $timestamp);
+
+ $signature_method = $this->get_signature_method($request);
+
+ $signature = $request->get_parameter('oauth_signature');
+ $built = $signature_method->build_signature(
+ $request, $consumer, $token
+ );
+
+ if ($signature != $built) {
+ throw new OAuthException("Invalid signature");
+ }
+ }/*}}}*/
+
+ /**
+ * check that the timestamp is new enough
+ */
+ private function check_timestamp($timestamp) {/*{{{*/
+ // verify that timestamp is recentish
+ $now = time();
+ if ($now - $timestamp > $this->timestamp_threshold) {
+ throw new OAuthException("Expired timestamp, yours $timestamp, ours $now");
+ }
+ }/*}}}*/
+
+ /**
+ * check that the nonce is not repeated
+ */
+ private function check_nonce($consumer, $token, $nonce, $timestamp) {/*{{{*/
+ // verify that the nonce is uniqueish
+ $found = $this->data_store->lookup_nonce($consumer, $token, $nonce, $timestamp);
+ if ($found) {
+ throw new OAuthException("Nonce already used: $nonce");
+ }
+ }/*}}}*/
+
+
+
+}/*}}}*/
+
+class OAuthDataStore {/*{{{*/
+ function lookup_consumer($consumer_key) {/*{{{*/
+ // implement me
+ }/*}}}*/
+
+ function lookup_token($consumer, $token_type, $token) {/*{{{*/
+ // implement me
+ }/*}}}*/
+
+ function lookup_nonce($consumer, $token, $nonce, $timestamp) {/*{{{*/
+ // implement me
+ }/*}}}*/
+
+ function fetch_request_token($consumer) {/*{{{*/
+ // return a new token attached to this consumer
+ }/*}}}*/
+
+ function fetch_access_token($token, $consumer) {/*{{{*/
+ // return a new access token attached to this consumer
+ // for the user associated with this token if the request token
+ // is authorized
+ // should also invalidate the request token
+ }/*}}}*/
+
+}/*}}}*/
+
+
+/* A very naive dbm-based oauth storage
+ */
+class SimpleOAuthDataStore extends OAuthDataStore {/*{{{*/
+ private $dbh;
+
+ function __construct($path = "oauth.gdbm") {/*{{{*/
+ $this->dbh = dba_popen($path, 'c', 'gdbm');
+ }/*}}}*/
+
+ function __destruct() {/*{{{*/
+ dba_close($this->dbh);
+ }/*}}}*/
+
+ function lookup_consumer($consumer_key) {/*{{{*/
+ $rv = dba_fetch("consumer_$consumer_key", $this->dbh);
+ if ($rv === FALSE) {
+ return NULL;
+ }
+ $obj = unserialize($rv);
+ if (!($obj instanceof OAuthConsumer)) {
+ return NULL;
+ }
+ return $obj;
+ }/*}}}*/
+
+ function lookup_token($consumer, $token_type, $token) {/*{{{*/
+ $rv = dba_fetch("${token_type}_${token}", $this->dbh);
+ if ($rv === FALSE) {
+ return NULL;
+ }
+ $obj = unserialize($rv);
+ if (!($obj instanceof OAuthToken)) {
+ return NULL;
+ }
+ return $obj;
+ }/*}}}*/
+
+ function lookup_nonce($consumer, $token, $nonce, $timestamp) {/*{{{*/
+ return dba_exists("nonce_$nonce", $this->dbh);
+ }/*}}}*/
+
+ function new_token($consumer, $type="request") {/*{{{*/
+ $key = md5(time());
+ $secret = time() + time();
+ $token = new OAuthToken($key, md5(md5($secret)));
+ if (!dba_insert("${type}_$key", serialize($token), $this->dbh)) {
+ throw new OAuthException("doooom!");
+ }
+ return $token;
+ }/*}}}*/
+
+ function new_request_token($consumer) {/*{{{*/
+ return $this->new_token($consumer, "request");
+ }/*}}}*/
+
+ function new_access_token($token, $consumer) {/*{{{*/
+
+ $token = $this->new_token($consumer, 'access');
+ dba_delete("request_" . $token->key, $this->dbh);
+ return $token;
+ }/*}}}*/
+}/*}}}*/
+
+?>
diff --git a/README b/README
new file mode 100644
index 0000000..018d4ea
--- /dev/null
+++ b/README
@@ -0,0 +1,9 @@
+Ahoy Maties! To run the app you'll need to search the code for all places you see "CHANGEME" and replace them with your database username/password/facebook api keys/secret keys/canvas urls.
+
+The database schema is located in the file sql/db.sql
+
+I haven't included the images that are used in the Pirates game, so you'll need to find some images to use yourself. Most of the images we use on the game are from stock photo sites, and some were custom illustrations by an artist.
+
+You'll also to need to download adodb for php and the facebook client code, and put that in the 'adodb', and '../client' folders.
+
+If you have any problems with the code, please get in contact with me. Go make a cool Facebook game, or improve this one! If you make some improvements that you want to put live in the game that's already on Facebook, let me know and I can check them out.
\ No newline at end of file
diff --git a/Space.php b/Space.php
new file mode 100644
index 0000000..2295299
--- /dev/null
+++ b/Space.php
@@ -0,0 +1,226 @@
+profile(1234567890);
+*/
+
+
+require_once('OAuth.php');
+
+class Space {
+ private $sServer = 'http://api.myspace.com/';
+ //private $sExt = '.json';
+ private $sExt = '.xml';
+ private $sVersion = 'v1/';
+
+ private $sKey;
+ private $sSecret;
+ private $oaConsumer;
+ private $oaToken;
+
+ private $bProfile = true;
+
+
+ public function __construct($sKey,$sSecret) {
+ $this->sKey = $sKey;
+ $this->sSecret = $sSecret;
+ $this->oaConsumer = new OAuthConsumer($this->sKey,$this->sSecret);
+ $this->oaToken = new OAuthToken(null,null);
+ }
+
+ public function currentUser() {
+ $sQuery = 'currentuser';
+ return $this->do_request($sQuery);
+ }
+
+ public function user($iUser) {
+ $sQuery = 'users/'.$iUser;
+ return $this->do_request($sQuery);
+ }
+
+ public function profile($iUser) {
+ $sQuery = 'users/'.$iUser.'/profile';
+ return $this->do_request($sQuery);
+ }
+
+ public function friends($iUser,$page = null,$page_size = null,$list = null) {
+ $sQuery = 'users/'.$iUser.'/friends';
+ $hParams = array();
+ if( $page !== null ) {
+ $hParams['page'] = $page;
+ }
+
+ if( $page_size !== null ) {
+ $hParams['page_size'] = $page;
+ }
+
+ if( $list !== null ) {
+ $hParams['list'] = $page;
+ }
+ return $this->do_request($sQuery,$hParams);
+ }
+
+ public function friendship($iUser,$aIds) {
+ $sQuery = 'users/'.$iUser.'/friends/'.implode($aIds,';');
+ return $this->do_request($sQuery);
+ }
+
+ public function albums($iUser) {
+ $sQuery = 'users/'.$iUser.'/albums';
+ return $this->do_request($sQuery);
+ }
+
+ public function album($iUser,$iAlbum) {
+ $sQuery = 'users/'.$iUser.'/albums/'.$iAlbum.'/photos';
+ return $this->do_request($sQuery);
+ }
+
+ public function photos($iUser) {
+ $sQuery = 'users/'.$iUser.'/photos';
+ return $this->do_request($sQuery);
+ }
+
+ public function photo($iUser,$iPhoto) {
+ $sQuery = 'users/'.$iUser.'/photos/'.$iPhoto;
+ return $this->do_request($sQuery);
+ }
+
+ public function interests($iUser) {
+ $sQuery = 'users/'.$iUser.'/interests';
+ return $this->do_request($sQuery);
+ }
+
+ public function details($iUser) {
+ $sQuery = 'users/'.$iUser.'/details';
+ return $this->do_request($sQuery);
+ }
+
+ public function videos($iUser) {
+ $sQuery = 'users/'.$iUser.'/videos';
+ return $this->do_request($sQuery);
+ }
+
+ public function video($iUser,$iVideo) {
+ $sQuery = 'users/'.$iUser.'/videos/'.$iVideo;
+ return $this->do_request($sQuery);
+ }
+
+ public function groups($iUser) {
+ $sQuery = 'users/'.$iUser.'/groups';
+ return $this->do_request($sQuery);
+ }
+
+ public function status($iUser) {
+ $sQuery = 'users/'.$iUser.'/status';
+ return $this->do_request($sQuery);
+ }
+
+ public function mood($iUser) {
+ $sQuery = 'users/'.$iUser.'/mood';
+ return $this->do_request($sQuery);
+ }
+
+ private function do_request($sQuery,$hParams = array()) {
+ if( $this->bProfile ) {
+ $s = microtime(true);
+ $r = $this->_do_request($sQuery,$hParams);
+ $e = microtime(true);
+
+ self::$aCalls[] = array( 'query' => $sQuery, 'time' => ($e-$s) );
+ self::$iTotal == ($e-$s);
+
+ return $r;
+ } else {
+ return $this->_do_request($sQuery,$hParams);
+ }
+ }
+
+ private function _do_request($sQuery,$hParams = array()) {
+ $sURL = $this->sServer.$this->sVersion.$sQuery.$this->sExt;
+ $sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
+ $r = OAuthRequest::from_consumer_and_token($this->oaConsumer,$this->oaToken,'GET',$sURL,$hParams);
+
+ $r->sign_request($sha1_method, $this->oaConsumer, NULL);
+ $sURL = $r->to_url();
+
+ if (function_exists('curl_init')) {
+ // Use CURL if installed...
+ $oCurl = curl_init();
+ curl_setopt($oCurl, CURLOPT_URL, $sURL);
+ curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($oCurl, CURLOPT_USERAGENT, 'mySpace API PHP5 Client 0.1 (curl) ' . phpversion());
+ $sContent = curl_exec($oCurl);
+ $code = curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
+ curl_close($oCurl);
+ } else {
+ // Note: this needs remote file enabled in php.ini
+ $sContent = file_get_contents($r->to_url());
+ }
+
+ if( $this->sExt == '.json' ) {
+ return json_decode($sContent);
+ } else if( $this->sExt == '.xml' ) {
+ $oXML = @simplexml_load_string($sContent); // Warnings for "invalid" xmlns
+ $hResult = self::convert_simplexml_to_array($oXML);
+
+ if( $code && $code >= 400 ) {
+ throw new Exception($code.' '.$hResult['BODY']['DIV']['P']);
+ }
+ return $hResult;
+ }
+ }
+
+ public static function convert_simplexml_to_array($sxml) {
+ $arr = array();
+ if ($sxml) {
+ foreach ($sxml as $k => $v) {
+ if ($sxml['count']) {
+ $arr[] = self::convert_simplexml_to_array($v);
+ } else {
+ $arr[$k] = self::convert_simplexml_to_array($v);
+ }
+ }
+ }
+ if (sizeof($arr) > 0) {
+ return $arr;
+ } else {
+ return (string)$sxml;
+ }
+ }
+
+
+ static private $aCalls = array();
+ static private $iTotal = 0;
+
+ static public function get_calls() {
+ return self::$aCalls;
+ }
+
+ static public function get_number_calls() {
+ return sizeof(self::$aCalls);
+ }
+
+ static public function get_time() {
+ return self::$iTotal;
+ }
+
+}
+
+?>
diff --git a/Util.php b/Util.php
new file mode 100755
index 0000000..9d4951d
--- /dev/null
+++ b/Util.php
@@ -0,0 +1,71 @@
+ $value) {
+ if ($xml['count']) {
+ $arr[] = self::xml_to_array($value);
+ } else {
+ $arr[$key] = self::xml_to_array($value);
+ }
+ }
+ }
+
+ if (sizeof($arr) > 0) {
+ return $arr;
+ } else {
+ return (string)$xml;
+ }
+ }
+}
+
+class HttpUtil {
+ public static function get_server($uri) {
+ //TODO: do something better
+ $uri = preg_replace('/http(s)?:\/\//', '', strtolower($uri));
+ return $uri;
+ }
+
+ public static function get_protocol_port($uri) {
+ //TODO: do something better
+ if (substr($uri, 0, 5) == 'https') {
+ return 443;
+ } else if (substr($uri, 0, 4) == 'http') {
+ return 80;
+ }
+
+ return 80;
+ }
+
+ public static function convert_post_data($arr) {
+ $post_result = "";
+
+ foreach ($arr as $key => $value) {
+ $post_result .= $key . '=' . $value . '&';
+ }
+
+ if (strlen($post_result) > 0) {
+ $post_result = substr($post_result, 0, strlen($post_result)-1);
+ }
+
+ return $post_result;
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/active_users.php b/active_users.php
new file mode 100644
index 0000000..837f5aa
--- /dev/null
+++ b/active_users.php
@@ -0,0 +1,63 @@
+
+ ";
+echo "
";
+echo "active users ";
+echo "up to level 100 ";
+$active_users = $memcache->get('active_lo');
+foreach($active_users as $a => $value) {
+?>
+ () (get($user . 'pvp'); ?>)
+
+}
+echo " ";
+
+
+echo "over level 100 ";
+$active_users = $memcache->get('active_hi');
+//print_r($active_users);
+
+foreach($active_users as $a => $value) {
+?>
+ () (get($user . 'pvp'); ?>)
+
+}
+echo " ";
+echo "over level 1000 ";
+$active_users = $memcache->get('active_hi_2');
+
+foreach($active_users as $a => $value) {
+?>
+ () (get($user . 'pvp'); ?>)
+
+}
+
+echo " ";
+echo "over level 5000 ";
+$active_users = $memcache->get('active_hi_3');
+
+foreach($active_users as $a => $value) {
+?>
+ () (get($user . 'pvp'); ?>)
+
+}
+
+
+echo "
";
+
+?>
+
+
+
+
diff --git a/activity.php b/activity.php
new file mode 100644
index 0000000..0aea8a6
--- /dev/null
+++ b/activity.php
@@ -0,0 +1,139 @@
+
+GetArray('select * from coin_log where user_id = ? order by date desc limit 5000', array($id));
+
+$level_log = $DB->GetArray('select * from level_log where user_id = ? order by date desc limit 5000 ', array($id));
+
+//print_r($r);
+?>
+
+
+COIN LOG for (last 5000) max miles:
+log started on: GetOne('select date from coin_log where user_id = ? order by date asc', array($id)); ?>
+
+
+
+
+amount
+date
+action
+secondary_user
+current coin total
+current buried coin total
+
+
+ $value) {
+
+$user_id = $value['user_id'];
+$amount = $value['amount'];
+$date = $value['date'];
+$action = $value['action'];
+$secondary_user = $value['secondary_user'];
+$current_coin_total = $value['current_coin_total'];
+$current_buried_coin_total = $value['current_buried_coin_total'];
+
+?>
+
+print_r($amount);
+?>
+
+
+
+
+print_r($date);
+?>
+
+
+
+
+print_r($action);
+?>
+
+
+
+
+print_r($secondary_user);
+?>
+
+
+
+
+print_r(number_format($current_coin_total));
+?>
+
+
+
+
+print_r(number_format($current_buried_coin_total));
+?>
+
+
+
+
+redirect('index.php?msg=joke-added');
+?>
+
+
+
+
+LEVEL LOG for (last 5000)
+
+
+
+
+date
+action
+secondary_user
+
+
+ $value) {
+
+$user_id = $value['user_id'];
+$date = $value['date'];
+$action = $value['action'];
+$secondary_user = $value['secondary_user'];
+
+?>
+
+
+
+print_r($date);
+?>
+
+
+
+
+print_r($action);
+?>
+
+
+
+
+print_r($secondary_user);
+?>
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ad_bottom.inc.php b/ad_bottom.inc.php
new file mode 100644
index 0000000..58c94c2
--- /dev/null
+++ b/ad_bottom.inc.php
@@ -0,0 +1,7 @@
+
+
+
\ No newline at end of file
diff --git a/add_pirate_jokes.php b/add_pirate_jokes.php
new file mode 100644
index 0000000..7af3365
--- /dev/null
+++ b/add_pirate_jokes.php
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+Pirate Jokes!
+
+ Arrrrrrr!
+
+
+Tell us a Pirate Joke! If we use it, we'll credit you 200 coins! Please limit submissions to 10 per day.
+
+
+
+
+
+
+
+
+
+
Submit yer joke here
+It should be in the form of :
+Question
+Answer
+
+
+
+
+Example:
+Q: Why are Pirates so Cool?
+A: They just ARRR!
+
+All jokes are reviewed for coolness and pirateness. Anything not funny will be rejected!
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/approve_jokes.php b/approve_jokes.php
new file mode 100644
index 0000000..336f98d
--- /dev/null
+++ b/approve_jokes.php
@@ -0,0 +1,67 @@
+
+redirect('index.php');
+}
+
+$question = $_REQUEST['question'];
+$answer = $_REQUEST['answer'];
+
+global $DB, $facebook;
+
+print dashboard($user);
+
+$r = $DB->GetArray('select * from jokes where approved = 0');
+
+//print_r($r);
+?>
+
+
+ $value) {
+
+$question = $value['question'];
+$answer = $value['answer'];
+$joke_id = $value['id'];
+$joke_user = $value['user'];
+
+?>
+
+print_r($question);
+?>
+
+
+
+
+print_r($answer);
+?>
+
+
+
+approve!
+
+
+
+decline!
+
+
+
+
+redirect('index.php?msg=joke-added');
+?>
+
+
+
+
\ No newline at end of file
diff --git a/approve_the_joke.php b/approve_the_joke.php
new file mode 100644
index 0000000..627e07d
--- /dev/null
+++ b/approve_the_joke.php
@@ -0,0 +1,36 @@
+
+redirect('index.php');
+}
+
+
+if(!$joke_id) {
+ $facebook->redirect('approve_jokes.php');
+
+}
+$r = $DB->Execute('update jokes set approved = 1 where id = ?', array($joke_id));
+
+$question = $DB->GetOne('select question from jokes where id = ?', array($joke_id));
+$answer = $DB->GetOne('select answer from jokes where id = ?', array($joke_id));
+$user = $DB->GetOne('select user from jokes where id = ?', array($joke_id));
+
+$r = $DB->Execute('insert into jokes_approved (question, answer, user, created_at) values(?, ?, ?, now())', array($question ,$answer, $user));
+
+
+$r = $DB->Execute('update users set buried_coin_total = buried_coin_total + 200 where id = ?', array($joke_user));
+
+//print_r($r);
+
+$facebook->redirect('approve_jokes.php');
+?>
\ No newline at end of file
diff --git a/attack_merchant_ship_action.php b/attack_merchant_ship_action.php
new file mode 100644
index 0000000..011ff02
--- /dev/null
+++ b/attack_merchant_ship_action.php
@@ -0,0 +1,306 @@
+redirect('merchant_ship_attack_result.php');
+}
+redirect_to_index_if_not_or($user, "found_merchant_ship", "attack_ship_merchant");
+
+update_action($user, "attack_ship_merchant");
+
+
+$enemy = $memcache->get($user . 'merchant_ship');
+if($enemy == false) {
+ $enemy = array('level' => 100, 'damage' => '0', 'team' => 'buccaneer', 'coin_total' => 100, 'cannons' => 100);
+ $memcache->set($user . 'merchant_ship', $enemy);
+}
+
+$round = get_round($user);
+
+
+$enemy_level = $enemy['level'];
+$enemy_damage = $enemy['damage'];
+$enemy_team = $enemy['team'];
+$enemy_cannons = $enemy['cannons'];
+$enemy_coins = $enemy['coin_total'];
+$enemy_health = $enemy_level - $enemy_damage;
+
+
+if($enemy_coins < 1) {
+ $enemy_coins = rand(1,100);
+}
+
+
+
+
+//your id
+$your_id = $user;
+$sql = 'select level, damage, team, coin_total from users where id = ?';
+$battle_stats = $DB->GetRow($sql, array($user));
+//print_r($battle_stats);
+$your_level = $battle_stats['level'];
+$your_damage = $battle_stats['damage'];
+$your_team = $battle_stats['team'];
+$your_coins = $battle_stats['coin_total'];
+
+//get cannon level
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+
+$your_cannons = $DB->GetOne($sql, array($user, 'cannons'));
+if(empty($your_cannons)) {
+ $your_cannons = 1;
+}
+
+$direction = $_REQUEST['d'];
+$enemy_move = rand(1,3);
+if($enemy_move == 1) { //if they're left and the random number says to go right, then actually go straight, and vice vs.
+
+ if($direction == 'right') {
+ $enemy_direction = 'straight';
+ }
+ else {
+ $enemy_direction = 'left';
+ }
+
+}
+else if($enemy_move == 2) {
+ $enemy_direction = 'straight';
+}
+else {
+ if($direction == 'left') {
+ $enemy_direction = 'left';
+ }
+ else {
+ $enemy_direction = 'right';
+ }
+}
+
+
+
+$low = ceil($your_cannons * 1.75);
+$high = ceil($your_cannons * 2.25);
+$your_hit = rand($low, $high);
+
+$low = ceil($enemy_cannons * 1.75);
+$high = ceil($enemy_cannons * 2.25);
+$enemy_hit = rand($low, $high);
+
+//echo "enemy move: $enemy_move";
+//echo "direction: $direction";
+
+if($direction != 'straight' && $enemy_direction == $direction) {
+ //chance for critical strike for left + right
+ $critical = rand(1,5);
+ if($critical == 3) {
+ $your_hit = $your_hit * 2;
+ }
+
+}
+else if($direction == 'straight' && $enemy_direction == $direction) {
+ //small chance for a critical hit
+ // if straight
+ $critical = rand(1,100);
+ if($critical == 50) {
+ $your_hit = $your_hit * 2;
+ }
+
+}
+else if($direction == 'straight' && ($enemy_direction == 'left' || $enemy_direction == 'right')) { //partial hit
+ //$your_hit = round($your_hit * .5);
+ //$your_hit =
+}
+else {
+ //$your_hit = 0;
+ //$enemy_hit = 0;
+}
+
+$merchant_ship_battle_history = $memcache->get($user . 'msbh');
+
+$history = "$round: You fired yer cannons for $your_hit damage! ";
+$history .= "$round: The merchant ship attacked you back for $enemy_hit damage! ";
+
+$history .= $merchant_ship_battle_history;
+
+$memcache->set($user . 'msbh', $history);
+
+set_damage($user, get_damage($user) + $enemy_hit);
+//set_damage($enemy_id, get_damage($enemy_id) + $your_hit);
+$enemy['damage'] = $your_hit + $enemy_damage;
+$memcache->set($user . 'merchant_ship', $enemy);
+
+
+//echo "your hit: $your_hit ";
+//enemys hit
+//$sql = 'select id from battles where user_id = ? and user_id_2 = ? and battle_type =?';
+//$battle_id = $DB->GetOne($sql, array($user, $enemy_id, 's'));
+
+
+
+//echo "enemy hit: $enemy_hit ";
+
+$your_health = get_level($user) - get_damage($user); // - $enemy_hit;
+$enemy_health = $enemy_level - $enemy_damage - $your_hit;
+
+
+
+if($your_health < 0) {
+ $your_health=0;
+}
+if($enemy_health < 0) {
+ $enemy_health=0;
+}
+//set health in memcache
+//set_health($user, $your_health);
+//set_health($enemy_id, $enemy_health);
+
+
+//echo "your health: $your_health ";
+//echo "enemy health: $enemy_health ";
+
+
+$round = get_round($user);
+
+//$_REQUEST['r'];
+
+if(empty($round)) {
+ $round = 1;
+}
+else {
+ //$round++;
+ increment_round($user);
+}
+
+//$your_low_health_to_flee = rand(1,$your_level/5);
+//$enemy_low_health_to_flee = rand(1,$enemy_level/5);
+
+
+//if($your_health < 1 && $enemy_health)
+if($your_health < 1) {
+ //you lose
+
+ reset_round($user);
+
+ $sql = 'update users set coin_total = 0 where id = ?';
+ $DB->Execute($sql, array($user));
+ //log coins lost for you
+ log_coins($user, -$your_coins, 'merchant ship attack loss', $enemy_id);
+
+ //$sql = 'update users set coin_total = coin_total + ? where id = ?';
+ //$DB->Execute($sql, array($your_coins, $enemy_id));
+ //log coins gained for enemy
+ //log_coins($enemy_id, $your_coins, 'ship defense win', $user);
+
+
+ //$sql = 'update battles set result = ?, gold_change = ? where user_id = ? and user_id_2 = ? and result=?';
+ //$DB->Execute($sql, array('l', $your_coins, $user, $enemy_id, 'p'));
+
+ // update damage for you
+ //$sql = 'update users set damage = level where id = ?';
+ //$DB->Execute($sql, array($user));
+ set_damage($user, get_level($user));
+
+ //update damage for enemy
+ //$sql = 'update users set damage = damage + ? where id = ?';
+ //$DB->Execute($sql, array($your_hit, $enemy_id));
+ //set_damage($enemy_id, get_damage($enemy_id) + $your_hit);
+
+ //$sql = 'update users set user_in_battle = 0 where id = ? OR id = ?';
+ //$DB->Execute($sql, array($user, $enemy_id));
+
+ update_action($user, "merchant_ship_attack_result");
+
+ //update your health to 50%
+ $your_level = get_level($user);
+ $half = round($your_level / 2);
+ $sql = 'update users set damage = damage - ? where id = ?';
+ $DB->Execute($sql, array($half, $user));
+
+ $memcache->set($user . 'merchant_ship', false);
+
+ if($your_coins != 0) {
+ $history .= "- You lost the battle! The enemy ship stole $your_coins coins from you!! ";
+ }
+ else {
+ $history .= "- You lost the battle! Arrr.... ";
+ }
+ $memcache->set($user . 'msbh', $history);
+
+ $facebook->redirect("$facebook_canvas_url/merchant_ship_attack_result.php?i=$battle_id&u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction&coins=$your_coins&result=lose");
+
+}
+else if ($enemy_health < 1) {
+ //you win
+ reset_round($user);
+ //$sql = 'update users set coin_total = 0 where id = ?';
+ //$DB->Execute($sql, array($enemy_id));
+
+ log_coins($user, $enemy_coins, 'merchant ship attack win', $enemy_id);
+
+ $sql = 'update users set coin_total = coin_total + ? where id = ?';
+ $DB->Execute($sql, array($enemy_coins, $user));
+
+
+ //give them a treasure map 1/3 of the time
+ $ra = rand(1,100);
+ if($ra < 33) {
+ $stuff_id = 1;
+ $give_stuff = true;
+ }
+ else {
+ $give_stuff = false;
+ }
+
+ if($give_stuff) {
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1';
+ $DB->Execute($sql, array($user, $stuff_id));
+ }
+
+
+
+ update_action($user, "merchant_ship_attack_result");
+
+ $memcache->set($user . 'merchant_ship', false);
+ $history .= "+: You won the battle! You stole $enemy_coins coins from the merchant ship!! ";
+
+ $memcache->set($user . 'msbh', $history);
+
+ $facebook->redirect("$facebook_canvas_url/merchant_ship_attack_result.php?u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction&coins=$enemy_coins&result=win&stuff=$stuff_id");
+
+
+}
+
+
+else if(($round > 5)) {
+//it's a tie, max rounds
+ reset_round($user);
+
+ //$sql = 'update battles set result = ? where user_id = ? and user_id_2 = ? and result=?';
+ //$DB->Execute($sql, array('t', $user, $enemy_id, 'p'));
+
+ //$sql = 'update users set user_in_battle = 0 where id = ? OR id = ?';
+ //$DB->Execute($sql, array($user, $enemy_id));
+
+ update_action($user, "merchant_ship_attack_result");
+
+ $memcache->set($user . 'merchant_ship', false);
+
+ $facebook->redirect("$facebook_canvas_url/merchant_ship_attack_result.php?u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction&result=tie");
+}
+
+else {
+
+
+ $facebook->redirect("$facebook_canvas_url/attack_ship_merchant.php?u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction");
+
+}
+
+
+//if either person's hit power is 0 then:
+//update the battle sql
+//redirect to the win/lose page
+
+
+?>
diff --git a/attack_monster_action.php b/attack_monster_action.php
new file mode 100644
index 0000000..d3c232b
--- /dev/null
+++ b/attack_monster_action.php
@@ -0,0 +1,311 @@
+redirect('monster_attack_result.php');
+}
+
+redirect_to_index_if_not_secondary($user, "attacked_by_monster");
+
+$s = $_REQUEST['weird'];
+//echo "s:";
+
+//print_r($s);
+//print_r($_REQUEST);
+
+//exit("");
+
+$enemy = $memcache->get($user . 'merchant_ship');
+if($enemy == false) {
+ $enemy = array('level' => 100, 'damage' => '0', 'team' => '', 'coin_total' => 100, 'cannons' => 100);
+ $memcache->set($user . 'merchant_ship', $enemy);
+}
+
+
+$enemy_level = $enemy['level'];
+$enemy_damage = $enemy['damage'];
+//$enemy_team = $enemy['team'];
+$enemy_cannons = $enemy['cannons'];
+$enemy_coins = $enemy['coin_total'];
+$enemy_health = $enemy_level - $enemy_damage;
+
+
+if($enemy_coins < 1) {
+ $enemy_coins = rand(1,100);
+}
+
+
+
+
+//your id
+$your_id = $user;
+$sql = 'select level, damage, team, coin_total from users where id = ?';
+$battle_stats = $DB->GetRow($sql, array($user));
+//print_r($battle_stats);
+$your_level = $battle_stats['level'];
+$your_damage = $battle_stats['damage'];
+$your_team = $battle_stats['team'];
+$your_coins = $battle_stats['coin_total'];
+
+//get cannon level
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+
+$your_cannons = $DB->GetOne($sql, array($user, 'cannons'));
+if(empty($your_cannons)) {
+ $your_cannons = 1;
+}
+
+
+$round = get_round($user);
+
+if(empty($round)) {
+ $round = 1;
+}
+else {
+ increment_round($user);
+}
+
+$monster_battle_history = $memcache->get($user . 'monster_battle_history');
+
+$drink = $_REQUEST['rum'];
+
+if($drink == 'drink') {
+ $action_type='rum';
+ $rum_required = round(get_crew_count($user) / 4);
+ $rum_total = get_rum_count($user);
+
+ if($rum_total > $rum_required) {
+ drink_rum_battling($user, $rum_required);
+ reset_round($user);
+ $history = "+ Yer crew drank rum and are ready for battle! ";
+ }
+
+}
+else if($s == 'DYNAMITEPARROTS') {
+ $dynamite_total = get_dynamite_count($user);
+ $parrot_total = get_parrot_count($user);
+
+ if($dynamite_total > 0 && $parrot_total > 0) {
+ }
+ $your_hit = rand(round($enemy_level * .05), round($enemy_level * .25));
+ $enemy_hit = rand(round($enemy_level * .01), round($enemy_level * .05));
+
+ $ra = rand(0,1);
+ if($ra == 0) {
+ $history = "+ Your parrot dropped some dynamite and hit the monster for $your_hit damage! ";
+ //decrease dynamite count
+ set_dynamite_total($user, $dynamite_total - 1);
+ $action_type = 'parrot';
+
+ }
+ else {
+ $history = "+ Your parrot attacked but was killed in the process! It hit the monster for $your_hit damage. ";
+ //decrease parrot count, decrease dynamite count
+ set_dynamite_total($user, $dynamite_total - 1);
+ set_parrot_total($user, $parrot_total - 1);
+ $action_type = 'parrotdied';
+
+ }
+
+
+ $history .= "- The monster attacked you back for $enemy_hit damage! ";
+
+
+}
+else if($s == 'EATHAM') {
+ $success = eat_ham($user);
+
+ $your_hit = 0;
+ $history = "+ You ate some ham and healed yerself 25% ";
+
+ $ra = rand(0,2);
+ if($ra == 0) {
+ $enemy_hit = 0;
+ }
+ else if($ra == 1) {
+ $enemy_hit = rand(round($enemy_level * .01), round($enemy_level * .05));
+ $history .= "- The monster attacked you for $enemy_hit damage! ";
+
+ }
+ else {
+ $enemy_hit = $enemy_cannons;
+ $history .= "- The monster attacked you for $enemy_hit damage! ";
+
+ }
+
+
+ $action_type = 'ham';
+
+
+}
+else {
+
+
+ $low = ceil($your_cannons / 2);
+ $high = ceil($your_cannons);
+ $your_hit = rand($low, $high);
+ $low = ceil($enemy_cannons / 2);
+ $high = ceil($enemy_cannons);
+ $enemy_hit = rand($low, $high);
+
+
+$history = "+ You fired yer cannons for $your_hit damage! ";
+$history .= "- The monster attacked you back for $enemy_hit damage! ";
+
+$action_type = 'cannon';
+
+
+
+}
+
+
+$history .= $monster_battle_history;
+
+
+
+set_damage($user, get_damage($user) + $enemy_hit);
+//set_damage($enemy_id, get_damage($enemy_id) + $your_hit);
+$enemy['damage'] = $your_hit + $enemy_damage;
+$memcache->set($user . 'merchant_ship', $enemy);
+
+
+$your_health = get_level($user) - get_damage($user); // - $enemy_hit;
+$enemy_health = $enemy_level - $enemy_damage - $your_hit;
+
+
+
+if($your_health < 0) {
+ $your_health=0;
+}
+if($enemy_health < 0) {
+ $enemy_health=0;
+}
+
+
+
+
+$memcache->set($user . 'monster_battle_history', $history);
+
+if($your_health < 1) {
+ reset_round($user);
+
+ set_damage($user, get_level($user));
+
+ update_secondary_action($user, "monster_attack_result");
+ update_action($user, 'NULL');
+ //you lost, lose treasure hunt
+ $memcache->set($user . 'treasure_attack_mile', 0);
+
+
+ //update your health to 50%
+ $your_level = get_level($user);
+ $half = round($your_level / 2);
+ $sql = 'update users set damage = damage - ? where id = ?';
+ $DB->Execute($sql, array($half, $user));
+
+ $memcache->set($user . 'merchant_ship', false);
+
+
+ $bootylostname = '';
+ $bootylostcount = '';
+
+ $crew_lost = rand(0,2);
+ kill_crewmembers($user, $crew_lost);
+
+ if($crew_lost != 0) {
+ $history .= "- The monster attacked and killed $crew_lost of yer crew! ";
+ $memcache->set($user . 'monster_battle_history', $history);
+
+ }
+
+ $history = $memcache->get($user . 'monster_battle_history');
+
+ $monster_type = $memcache->get($user . 'mt');
+ if($monster_type == 'seamonster' || $monster_type == FALSE) {
+ $monster_type = 'seamonster';
+ }
+ $memcache->set($user . 'mt', false);
+ $DB->Execute('insert into npc_battles (user_id, type, level, cannons, result, coins, created_at, crew_lost) values(?, ?, ?, ?, ?, ?, now(), ?)', array($user, $monster_type, $enemy_level, $enemy_cannons, 'l', 0, $crew_lost));
+
+
+ $facebook->redirect("$facebook_canvas_url/monster_attack_result.php?i=$battle_id&u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction&coins=$enemy_coins&result=lose&crew=$crew_lost");
+
+}
+else if ($enemy_health < 1) {
+ //you win
+ reset_round($user);
+
+ log_coins($user, $enemy_coins, 'monster attack win', $enemy_id);
+
+ $sql = 'update users set coin_total = coin_total + ? where id = ?';
+ $DB->Execute($sql, array($enemy_coins, $user));
+
+ $history .= "+ The monster dropped $enemy_coins coins!! ";
+
+
+ update_secondary_action($user, "monster_attack_result");
+
+ $memcache->set($user . 'merchant_ship', false);
+
+ $memcache->set($user . 'treasure_attack_mile', 0);
+
+ //$booty = 'sea monster scales';
+ //$booty = 'sea monster head';
+ //$booty = 'sea monster tail';
+
+ $level = lower_level_up($user);
+ if($level == true) {
+ $level_up = 1;
+ $history .= "+ You leveled up! ";
+ log_levels($user, 'level up from fighting monster');
+
+ }
+ else {
+ $level_up = 0;
+ }
+
+ $memcache->set($user . 'monster_battle_history', $history);
+
+ $DB->Execute('insert into npc_battles (user_id, type, level, cannons, result, coins, created_at, level_up) values(?, ?, ?, ?, ?, ?, now(), ?)', array($user, 'sea_monster', $enemy_level, $enemy_cannons, 'w', $enemy_coins, $level_up));
+
+ $facebook->redirect("$facebook_canvas_url/monster_attack_result.php?u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction&coins=$enemy_coins&result=win&level=$level");
+
+
+}
+
+
+else if(($round > 6)) {
+//it's a tie, max rounds
+ reset_round($user);
+
+ update_secondary_action($user, "monster_attack_result");
+
+ //you lost, lose treasure hunt
+ update_action($user, 'NULL');
+
+ $memcache->set($user . 'merchant_ship', false);
+
+ $memcache->set($user . 'treasure_attack_mile', 0);
+
+ $history = $memcache->get($user . 'monster_battle_history');
+ $DB->Execute('insert into npc_battles (user_id, type, level, cannons, result, created_at) values(?, ?, ?, ?, ?, now())', array($user, 'sea_monster', $enemy_level, $enemy_cannons, 'tie'));
+
+ $facebook->redirect("$facebook_canvas_url/monster_attack_result.php?u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction&result=tie");
+}
+
+else {
+
+ $facebook->redirect("$facebook_canvas_url/attacked_by_monster.php?u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction&action_type=$action_type");
+
+}
+
+
+//if either person's hit power is 0 then:
+//update the battle sql
+//redirect to the win/lose page
+
+
+?>
diff --git a/attack_ship.php b/attack_ship.php
new file mode 100644
index 0000000..00c62b7
--- /dev/null
+++ b/attack_ship.php
@@ -0,0 +1,417 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+GetRow($sql, array($user));
+//print_r($battle_stats);
+$your_level = $battle_stats['level'];
+$your_damage = $battle_stats['damage'];
+$your_team = $battle_stats['team'];
+$your_coins = $battle_stats['coin_total'];
+$your_health = $your_level - $your_damage;
+
+//get cannon level
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+
+$your_cannons = $DB->GetOne($sql, array($user, 'cannons'));
+if(empty($your_cannons)) {
+ $your_cannons = 0;
+}
+
+
+$your_hull = $DB->GetOne($sql, array($user, 'hull'));
+if(empty($your_hull)) {
+ $your_hull = 0;
+}
+
+$sql = 'select battling_enemy_id from users where id = ?';
+$found_enemy_id = $DB->GetOne($sql, array($user));
+
+if($found_enemy_id ) {
+ $enemy_id = $found_enemy_id; //already in a battle...
+ $sql = 'select id, level, damage, team, coin_total from users where id = ?';
+ $msg = "Shiver me timbers! The attack is on!";
+
+
+ if(isset($_REQUEST['u']) && $_REQUEST['u'] == 0) {
+ $msg = 'Arrr... You fire and miss!!';
+ }
+
+ $enemy = $DB->GetRow($sql, array($enemy_id));
+}
+
+
+//print_r($found_enemy_id);
+else { //find a new enemy!
+
+
+ //do the new way 50 of the time, old way 50% of the time
+ $ra = rand(1,2);
+
+ if($ra ==1) {
+ $enemy = new_ship_battle_smart($user);
+
+ if($enemy == $user) {
+ $enemy = new_ship_battle($user);
+ }
+ }
+ else {
+ $enemy = new_ship_battle($user);
+ if($enemy == $user) {
+ $enemy = FALSE;
+ }
+ }
+ //echo "enemy is: $enemy";
+ if($enemy == FALSE) {
+ update_action($user, "attack_ship_merchant");
+ $facebook->redirect("attack_ship_merchant.php");
+ }
+
+ $sql = 'update users set battling_enemy_id = ? where id = ?';
+ $enemy_id = $enemy['id'];
+ $DB->Execute($sql, array($enemy_id, $user));
+
+ $msg = "You're fightin!";
+
+ //clear the battle history for the attacker
+ $memcache->set($user . 'pvp_attack_history', false);
+
+ //clear for defender
+ $memcache->set($enemy_id . 'defender_pvp_attack_history', false);
+
+
+}
+
+//print_r($enemy);
+
+$enemy_id = $enemy['id'];
+
+if(empty($enemy_id) || $enemy_id == $user) {
+ update_action($user, "attack_ship_merchant");
+ $facebook->redirect("attack_ship_merchant.php");
+}
+
+$enemy_level = $enemy['level'];
+$enemy_damage = $enemy['damage'];
+$enemy_team = $enemy['team'];
+$enemy_coins = $enemy['coin_total'];
+
+$enemy_health = $enemy_level - $enemy_damage;
+
+//get cannon level for the enemy
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+$enemy_cannons = $DB->GetOne($sql, array($enemy_id, 'cannons'));
+if(empty($enemy_cannons)) {
+ $enemy_cannons = 0;
+}
+
+$enemy_hull = $DB->GetOne($sql, array($enemy_id, 'hull'));
+if(empty($enemy_hull)) {
+ $enemy_hull = 0;
+}
+
+set_was_attacked($enemy_id, $user);
+
+if($hit == 'miss') { //it was a miss
+ $msg = "Arrrrrrr... you fired $direction and missed! and caused $your_hit damage . They fired back, causing you $enemy_hit damage ";
+
+}
+else if(!empty($your_hit) && !empty($enemy_hit)) {
+ $msg = "Arrrrrrr... you fired and caused $your_hit damage . They fired back, causing you $enemy_hit damage ";
+}
+else {
+ //$msg = 'Shiver Me Timbers! the Attack is ON';
+}
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Cap'n
+
+Level Pirate ( health remaining)
+Level Cannons
+
+Level Hull
+
+
+ coin onboard
+
+ coins onboard
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Cap'n
+
+
+Level Pirate ( health remaining)
+Level Cannons
+
+Level Hull
+
+
+ coin onboard
+ 1): ?>
+ coins onboard
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Last known position of Ship
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Last known position of Ship
+
+
+
+
+
+
+
+
+
+
+
+
+Last known position of Ship
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0) {
+
+?>
+
+*Heal yourself by eating ham ( left)
+
+
+
+}
+else {
+?>
+
+*Heal yourself by buying some ham (50 coins)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+get($user . 'pvp_attack_history');
+ ?>
+
+
+
+
+Battle History
+
+';
+
+echo adsense_468($user);
+echo ' ';
+//require_once "my_pirate.inc.php";
+
+//require_once "world_stats.inc.php";
+//set_profile($user);
+
+
+
+
+
+?>
+
+
+
diff --git a/attack_ship_action.php b/attack_ship_action.php
new file mode 100644
index 0000000..d54b131
--- /dev/null
+++ b/attack_ship_action.php
@@ -0,0 +1,466 @@
+redirect('ship_attack_result.php');
+}
+
+redirect_to_index_if_not_or($user, "ship", "attack_ship");
+
+$enemy_id = $DB->GetOne('select battling_enemy_id from users where id = ?', array($user));
+
+if($enemy_id == FALSE || $enemy_id == 0) {
+ update_action($user, 'NULL');
+ set_was_attacked($user, 0);
+ set_was_bombed($user, 0);
+ $DB->Execute('delete from battles where user_id = ? and result = ?', array($user, 'p'));
+ $facebook->redirect('index.php?msg=ship-ran-away');
+}
+
+
+$sql = 'select id, level, damage, team, coin_total from users where id = ?';
+$enemy = $DB->GetRow($sql, array($enemy_id));
+
+$enemy_id = $enemy['id'];
+$enemy_level = $enemy['level'];
+$enemy_damage = $enemy['damage'];
+$enemy_team = $enemy['team'];
+$enemy_coins = $enemy['coin_total'];
+
+if($enemy_coins < 1) {
+ $enemy_coins = rand(1,100);
+}
+
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+$enemy_cannons = $DB->GetOne($sql, array($enemy_id, 'cannons'));
+if(empty($enemy_cannons) || $enemy_cannons == 0) {
+ $enemy_cannons = 1;
+}
+
+$enemy_hull = $DB->GetOne($sql, array($enemy_id, 'hull'));
+if(empty($enemy_hull) || $enemy_hull == 0) {
+ $enemy_hull = 0;
+}
+
+//your id
+$your_id = $user;
+$sql = 'select level, damage, team, coin_total from users where id = ?';
+$battle_stats = $DB->GetRow($sql, array($user));
+//print_r($battle_stats);
+$your_level = $battle_stats['level'];
+$your_damage = $battle_stats['damage'];
+$your_team = $battle_stats['team'];
+$your_coins = $battle_stats['coin_total'];
+
+//get cannon level
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+
+$your_cannons = $DB->GetOne($sql, array($user, 'cannons'));
+if(empty($your_cannons) || $your_cannons == 0) {
+ $your_cannons = 1;
+}
+
+$your_hull = $DB->GetOne($sql, array($user, 'hull'));
+if(empty($your_hull) || $your_hull == 0) {
+ $your_hull = 0;
+}
+
+
+$direction = $_REQUEST['d'];
+$enemy_move = rand(1,3);
+if($enemy_move == 1) { //if they're left and the random number says to go right, then actually go straight, and vice vs.
+
+ if($direction == 'right') {
+ $enemy_direction = 'straight';
+ }
+ else {
+ $enemy_direction = 'left';
+ }
+
+}
+else if($enemy_move == 2) {
+ $enemy_direction = 'straight';
+}
+else {
+ if($direction == 'left') {
+ $enemy_direction = 'left';
+ }
+ else {
+ $enemy_direction = 'right';
+ }
+}
+
+
+$pvp_attack_history = $memcache->get($user . 'pvp_attack_history');
+
+$defender_pvp_attack_history = $memcache->get($enemy_id . 'defender_pvp_attack_history');
+
+
+$low = ceil($your_cannons * 1.75);
+$high = ceil($your_cannons * 2.25);
+$your_hit = rand($low, $high);
+//reduce your_hit by half of your hull level
+$your_hit = $your_hit - round($enemy_hull/rand(1.75, 2.25));
+if($your_hit < 1) {
+ $your_hit = 1;
+}
+
+$low = ceil($enemy_cannons * 1.75);
+$high = ceil($enemy_cannons * 2.25);
+$enemy_hit = rand($low, $high);
+//reduce enemy_hit by half of hull level
+$enemy_hit = $enemy_hit - round($your_hull/rand(1.75, 2.25));
+if($enemy_hit < 1) {
+ $enemy_hit = 1;
+}
+
+
+//echo "enemy move: $enemy_move";
+//echo "direction: $direction";
+
+if($direction != 'straight' && $enemy_direction == $direction) {
+ //chance for critical strike for left + right
+ $critical = rand(1,10);
+ if($critical == 3) {
+ $your_hit = $your_hit * 2;
+ }
+
+}
+else if($direction == 'straight' && $enemy_direction == $direction) {
+ //small chance for a critical hit
+ // if straight
+ $critical = rand(1,10);
+ if($critical == 50) {
+ $your_hit = round($your_hit * 2);
+ }
+
+}
+
+
+
+else if($direction == 'straight' && ($enemy_direction == 'left' || $enemy_direction == 'right')) { //partial hit
+ //$your_hit = round($your_hit * .5);
+ //$your_hit =
+}
+else {
+ //$your_hit = 0;
+ //$enemy_hit = 0;
+}
+
+//set_damage($user, $enemy_hit);
+//set_damage($enemy_id, $your_hit);
+if(empty($enemy_id) || !isset($enemy_id)) {
+ update_action($user, "attack_ship_merchant");
+ $facebook->redirect('attack_ship_merchant.php');
+}
+
+set_damage($user, get_damage($user) + $enemy_hit);
+set_damage($enemy_id, get_damage($enemy_id) + $your_hit);
+
+
+
+//echo "your hit: $your_hit ";
+
+//enemys hit
+
+$sql = 'select id from battles where user_id = ? and user_id_2 = ? and battle_type =? order by id desc';
+
+$battle_id = $DB->GetOne($sql, array($user, $enemy_id, 's'));
+
+
+
+//echo "enemy hit: $enemy_hit ";
+
+$your_health = get_level($user) - get_damage($user); // - $enemy_hit;
+$enemy_health = get_level($enemy_id) - get_damage($enemy_id); // - $your_hit;
+
+
+
+if($your_health < 0) {
+ $your_health=0;
+}
+if($enemy_health < 0) {
+ $enemy_health=0;
+}
+//set health in memcache
+//set_health($user, $your_health);
+//set_health($enemy_id, $enemy_health);
+
+
+//echo "your health: $your_health ";
+//echo "enemy health: $enemy_health ";
+
+
+$round = get_round($user);
+
+//$_REQUEST['r'];
+
+if(empty($round)) {
+ $round = 1;
+}
+else {
+ //$round++;
+ increment_round($user);
+}
+
+//$your_low_health_to_flee = rand(1,$your_level/5);
+//$enemy_low_health_to_flee = rand(1,$enemy_level/5);
+
+
+
+
+if($your_health < 1 && $enemy_health > 0) {
+ //you lose
+
+ reset_round($user);
+
+ $sql = 'update users set coin_total = 0 where id = ?';
+ $DB->Execute($sql, array($user));
+ //log coins lost for you
+ log_coins($user, -$your_coins, 'ship attack loss', $enemy_id);
+
+ $sql = 'update users set coin_total = coin_total + ? where id = ?';
+ $DB->Execute($sql, array($your_coins, $enemy_id));
+ //log coins gained for enemy
+ log_coins($enemy_id, $your_coins, 'ship defense win', $user);
+
+
+ $sql = 'update battles set result = ?, gold_change = ? where user_id = ? and user_id_2 = ? and result=?';
+ $DB->Execute($sql, array('l', $your_coins, $user, $enemy_id, 'p'));
+
+ // update damage for you
+ //$sql = 'update users set damage = level where id = ?';
+ //$DB->Execute($sql, array($user));
+ set_damage($user, get_level($user));
+
+ //update damage for enemy
+ //$sql = 'update users set damage = damage + ? where id = ?';
+ //$DB->Execute($sql, array($your_hit, $enemy_id));
+ set_damage($enemy_id, get_damage($enemy_id) + $your_hit);
+
+ $sql = 'update users set user_in_battle = 0 where id = ? OR id = ?';
+ $DB->Execute($sql, array($user, $enemy_id));
+
+ update_action($user, "ship_attack_result");
+
+ //update your health to 50%
+ $your_level = get_level($user);
+ $half = round($your_level / 2);
+ $sql = 'update users set damage = damage - ?, battling_enemy_id = 0 where id = ?';
+ $DB->Execute($sql, array($half, $user));
+
+
+ //battle history for the final killing blow for both defender and attacker
+
+
+
+
+ if($your_coins == 0) {
+ $history .= "- Yer hitpoints fell to 0. The enemy has $enemy_health hitpoints. You lost the battle! ";
+
+ $defender_history .= "+ The enemies hitpoints fell to 0! You won the battle! ";
+
+
+ }
+ else {
+ $history .= "- Yer hitpoints fell to 0. The enemy has $enemy_health hitpoints. You lost the battle and $your_coins coins! ";
+
+ $defender_history .= "+ The enemies hitpoints fell to 0! You won the battle and $your_coins coins! ";
+
+ }
+
+ $history .= "$round: You fired yer cannons for $your_hit damage! The enemy has $enemy_health health left. ";
+
+ $history .= "$round: The enemy pirate attacked you back for $enemy_hit damage! You have $your_health health left. ";
+
+ $defender_history .= "$round: You fired yer cannons back for $enemy_hit damage! The enemy has $your_health health left. ";
+
+ $defender_history .= "$round: The enemy pirate attacked you for $your_hit damage! You have $enemy_health health left. ";
+
+
+ $history .= $pvp_attack_history;
+ $memcache->set($user . 'pvp_attack_history', $history);
+
+ $defender_history .= $defender_pvp_attack_history;
+ $memcache->set($enemy_id . 'defender_pvp_attack_history', $defender_history);
+
+
+ $facebook->redirect("$facebook_canvas_url/ship_attack_result.php?i=$battle_id&u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction");
+
+}
+else if ($enemy_health < 1 && $your_health > 0) {
+ //there is a weird bug where sometimes multiple attacks are showing up in the logs for the same
+ //user_id vs user_id_2 attack this shouldn't happen because the action is set to null but
+ //hopefully this fixes it anyway.... =/
+ //it sets a flag in memcache lasting 60 seconds to true, and if true that prevents this from running again
+ $flag = $memcache->get($user . 'attacked' . $enemy_id);
+
+ if($flag == 1) {
+ update_action($user, 'NULL');
+ set_was_attacked($user, 0);
+ set_was_bombed($user, 0);
+ $DB->Execute('delete from battles where user_id = ? and result = ?', array($user, 'p'));
+ $facebook->redirect('index.php?msg=ship-ran-away');
+ }
+
+ $memcache->set($user . 'attacked' . $enemy_id, 1, false, 60);
+
+ //you win
+ reset_round($user);
+ $sql = 'update users set coin_total = 0 where id = ?';
+ $DB->Execute($sql, array($enemy_id));
+
+
+ $sql = 'update users set coin_total = coin_total + ? where id = ?';
+
+ if($enemy_coins < 100) {
+ $enemy_coins = 100 + rand(1, 150);
+ }
+
+ log_coins($user, $enemy_coins, 'ship attack win', $enemy_id);
+
+ $DB->Execute($sql, array($enemy_coins, $user));
+
+ log_coins($enemy_id, -$enemy_coins, 'ship defense loss', $user);
+
+ $sql = 'update battles set result = ?, gold_change = ? where user_id = ? and user_id_2 = ? and result=?';
+ $DB->Execute($sql, array('w', $enemy_coins, $user, $enemy_id, 'p'));
+
+ // update damage for you
+ //DON"T TAKE AWAY DAMAGE IF ENEMY IS ALREADY DEAD
+ //set_damage($user, get_damage($user) + $enemy_hit);
+
+ //$sql = 'update users set damage = level where id = ?';
+ //$DB->Execute($sql, array($enemy_id));
+ set_damage($enemy_id, get_level($enemy_id));
+
+ $sql = 'update users set user_in_battle = 0 where id = ? OR id = ?';
+ $DB->Execute($sql, array($user, $enemy_id));
+
+
+ //update enemy health to 50%
+ $enemy_level = get_level($enemy_id);
+ $half = round($enemy_level / 2);
+ $sql = 'update users set damage = damage - ? where id = ?';
+ $DB->Execute($sql, array($half, $enemy_id));
+
+
+ $sql = 'update users set battling_enemy_id = 0 where id = ?';
+ $DB->Execute($sql, array($user));
+
+ update_action($user, "ship_attack_result");
+
+
+
+
+ $history .= "+ You won the battle and took $enemy_coins coins from the enemy pirate! ";
+
+ $history .= "$round: You fired yer cannons for $your_hit damage! The enemy has $enemy_health health left. ";
+
+ $history .= "$round: The enemy pirate attacked you back for $enemy_hit damage! You have $your_health health left. ";
+
+
+ $defender_history .= "- You lost the battle! The enemy pirate took $enemy_coins coins from you! ";
+
+
+ $defender_history .= "$round: You fired yer cannons back for $enemy_hit damage! The enemy has $your_health health left. ";
+
+ $defender_history .= "$round: The enemy pirate attacked you for $your_hit damage! You have $enemy_health health left. ";
+
+
+ $history .= $pvp_attack_history;
+ $memcache->set($user . 'pvp_attack_history', $history);
+
+
+ $defender_history .= $defender_pvp_attack_history;
+ $memcache->set($enemy_id . 'defender_pvp_attack_history', $defender_history);
+
+ $facebook->redirect("$facebook_canvas_url/ship_attack_result.php?i=$battle_id&u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction");
+
+
+}
+
+else if(($round > 4) || ($enemy_health < 1 && $your_health < 1) ) {
+//it's a tie, max rounds
+ $sql = 'update users set battling_enemy_id = 0 where id = ?';
+ $DB->Execute($sql, array($user));
+
+ reset_round($user);
+
+ $sql = 'update battles set result = ? where user_id = ? and user_id_2 = ? and result=?';
+ $DB->Execute($sql, array('t', $user, $enemy_id, 'p'));
+
+ $sql = 'update users set user_in_battle = 0 where id = ? OR id = ?';
+ $DB->Execute($sql, array($user, $enemy_id));
+
+ update_action($user, "ship_attack_result");
+
+
+ //tie history
+ $history .= "+ The battle was a tie! ";
+
+ $history .= "$round: You fired yer cannons for $your_hit damage! The enemy has $enemy_health health left. ";
+
+ $history .= "$round: The enemy pirate attacked you back for $enemy_hit damage! You have $your_health health left. ";
+
+ $defender_history .= "+ The battle was a tie! ";
+
+ $defender_history .= "$round: You fired yer cannons back for $enemy_hit damage! The enemy has $your_health health left. ";
+
+ $defender_history .= "$round: The enemy pirate attacked you for $your_hit damage! You have $enemy_health health left. ";
+
+ $history .= $pvp_attack_history;
+ $memcache->set($user . 'pvp_attack_history', $history);
+
+ $defender_history .= $defender_pvp_attack_history;
+ $memcache->set($enemy_id . 'defender_pvp_attack_history', $defender_history);
+
+
+
+
+ $facebook->redirect("$facebook_canvas_url/ship_attack_result.php?i=$battle_id&u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction");
+}
+
+else {
+ // update health points in db for both users
+ //$sql = 'update users set damage = damage + ? where id = ?';
+ //$DB->Execute($sql, array($enemy_hit, $user));
+ //set_damage($user, get_damage($user) + $enemy_hit);
+ //set_damage($enemy_id, get_damage($enemy_id) + $your_hit);
+
+ //$sql = 'update users set damage = damage + ? where id = ?';
+ //$DB->Execute($sql, array($your_hit, $enemy_id));
+
+ //else redirect back to attack_ship with a mesage of the hits taken,
+
+ $history .= "$round: You fired yer cannons for $your_hit damage! The enemy has $enemy_health health left. ";
+
+$history .= "$round: The enemy pirate attacked you back for $enemy_hit damage! You have $your_health health left. ";
+ $history .= $pvp_attack_history;
+ $memcache->set($user . 'pvp_attack_history', $history);
+
+
+
+ $defender_history .= "$round: You fired yer cannons for $enemy_hit damage! The enemy has $your_health health left. ";
+
+$defender_history .= "$round: The enemy pirate attacked you for $your_hit damage! You have $enemy_health health left. ";
+ $defender_history .= $defender_pvp_attack_history;
+ $memcache->set($enemy_id . 'defender_pvp_attack_history', $defender_history);
+
+
+
+ $facebook->redirect("$facebook_canvas_url/attack_ship.php?u=$your_hit&e=$enemy_hit&r=$round&d=$direction&f=$enemy_direction");
+
+}
+
+
+//if either person's hit power is 0 then:
+//update the battle sql
+//redirect to the win/lose page
+
+
+?>
diff --git a/attack_ship_merchant.php b/attack_ship_merchant.php
new file mode 100644
index 0000000..a07e2e3
--- /dev/null
+++ b/attack_ship_merchant.php
@@ -0,0 +1,393 @@
+
+
+
+redirect("$facebook_canvas_url/index.php");
+redirect_to_index_if_not_or($user, "found_merchant_ship", "attack_ship_merchant");
+
+//echo get_current_action($user);
+
+update_action($user, "attack_ship_merchant");
+$round = get_round($user);
+
+//echo $round;
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+?>
+
+
+
+set($user . 'merchant_ship_limit', 1, false, 60 * 6);
+?>
+
+
+
+
+
+
+
+
+
+GetRow($sql, array($user));
+//print_r($battle_stats);
+$your_level = $battle_stats['level'];
+$your_damage = $battle_stats['damage'];
+$your_team = $battle_stats['team'];
+$your_coins = $battle_stats['coin_total'];
+$your_health = $your_level - $your_damage;
+
+//get cannon level
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+
+$your_cannons = $DB->GetOne($sql, array($user, 'cannons'));
+if(empty($your_cannons)) {
+ $your_cannons = 0;
+}
+
+$enemy = $memcache->get($user . 'merchant_ship');
+if($enemy == false) {
+
+ $c = rand($your_cannons/2, $your_cannons);
+
+ $h = rand(1,10);
+ if($h == 1) {
+ $coins = rand(2000, 3000);
+ $level = rand($your_level + 10, $your_level * 2);
+
+ if($c < 40) {
+ $c = 40;
+ }
+
+ }
+ else {
+ if($c < 20) {
+ $c = 20;
+ }
+ $level = rand($your_level - round($your_level/3), $your_level + round($your_level/3));
+
+ $coins = rand(400, 700);
+ }
+ $enemy = array('level' => $level, 'damage' => '0', 'coin_total' => $coins, 'cannons' => $c);
+ $memcache->set($user . 'merchant_ship', $enemy);
+
+ //clear the battle history for the attacker
+ $memcache->set($user . 'msbh', false);
+
+
+}
+
+
+$enemy_level = $enemy['level'];
+$enemy_damage = $enemy['damage'];
+//$enemy_team = $enemy['team'];
+$enemy_cannons = $enemy['cannons'];
+$enemy_coins = $enemy['coin_total'];
+$enemy_health = $enemy_level - $enemy_damage;
+
+
+
+
+if($hit == 'miss') { //it was a miss
+ $msg = "Arrrrrrr... you fired $direction and missed! and caused $your_hit damage . They fired back, causing you $enemy_hit damage ";
+
+}
+else if(!empty($your_hit) && !empty($enemy_hit)) {
+ $msg = "Arrrrrrr... you fired and caused $your_hit damage . They fired back, causing you $enemy_hit damage ";
+}
+else {
+ //$msg = 'Shiver Me Timbers! the Attack is ON';
+}
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Cap'n
+
+
+
+
+
+Level Pirate ( health remaining)
+Level Cannons
+
+ coin onboard
+
+ coins onboard
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Level Pirate ( health remaining)
+Level Cannons
+
+ coin onboard
+ 1): ?>
+ coins onboard
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Last known position of Ship
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Last known position of Ship
+
+
+
+
+
+
+
+
+
+
+
+
+
+Last known position of Ship
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0) {
+
+?>
+
+*Heal yourself by eating ham ( left)
+
+
+
+}
+else {
+?>
+
+*Heal yourself by buying some ham (50 coins)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+get($user . 'msbh'); ?>
+
+
+Battle History
+
+
+';
+
+?>
+
+
+
diff --git a/attacked_by_monster.php b/attacked_by_monster.php
new file mode 100644
index 0000000..37f37f2
--- /dev/null
+++ b/attacked_by_monster.php
@@ -0,0 +1,455 @@
+
+
+get($user . 'mt');
+if($monster_type == FALSE) {
+
+ $ra = rand(0,3);
+ if($ra == 0) {
+ $monster_type = 'crabtopuss';
+ $monster_type_pid = $crabtopuss;
+ $memcache->set($user . 'mt', 'crabtopuss');
+
+ }
+ else if($ra == 1) {
+ $monster_type = 'deadfish';
+ $monster_type_pid = $deadfish;
+ $memcache->set($user . 'mt', 'deadfish');
+ }
+ else if($ra == 2) {
+ $monster_type = 'squid';
+ $monster_type_pid = $squid;
+ $memcache->set($user . 'mt', 'squid');
+ }
+ else {
+ $monster_type = 'seamonster';
+ $monster_type_pid = $seadragon;
+ $memcache->set($user . 'mt', 'seamonster');
+ }
+
+}
+else {
+ if($monster_type == 'seamonster') {
+ $monster_type_pid = $seadragon;
+ }
+ else if($monster_type == 'squid') {
+ $monster_type_pid = $squid;
+ }
+ else if($monster_type == 'deadfish') {
+ $monster_type_pid = $deadfish;
+ }
+ else if($monster_type == 'crabtopuss') {
+ $monster_type_pid = $crabtopuss;
+ }
+ else {
+ $monster_type_pid = $seadragon;
+ }
+}
+
+redirect_to_index_if_not_secondary($user, "attacked_by_monster");
+
+//update_action($user, "attacked_by_monster");
+$round = get_round($user);
+
+//echo $round;
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+?>
+
+set($user . 'merchant_ship_limit', 1, false, 60 * 6);
+?>
+
+
+
+
+
+
+
+GetRow($sql, array($user));
+//print_r($battle_stats);
+$your_level = $battle_stats['level'];
+$your_damage = $battle_stats['damage'];
+$your_team = $battle_stats['team'];
+$your_coins = $battle_stats['coin_total'];
+$your_health = $your_level - $your_damage;
+
+//get cannon level
+$sql = 'select level from upgrades where user_id = ? and upgrade_name = ?';
+
+$your_cannons = $DB->GetOne($sql, array($user, 'cannons'));
+if(empty($your_cannons)) {
+ $your_cannons = 0;
+}
+
+$enemy = $memcache->get($user . 'merchant_ship');
+if($enemy == false) {
+ $h = rand(1,100);
+ if($h == 1) {
+ $c = rand($your_cannons/2, $your_cannons + round($your_cannons/3));
+ if($c < 75) {
+ $c = 75;
+ }
+ $coins = rand(2000, 4000);
+ if($your_level > 1000) {
+ $coins = $coins * 2;
+ $c += round($c/4);
+ }
+
+ $level = rand($your_level + 25, $your_level * 2);
+ }
+ else {
+ $c = rand($your_cannons/2, $your_cannons);
+ if($c < 50) {
+ $c = 50;
+ }
+
+ $level = rand($your_level - round($your_level/3), $your_level + round($your_level/3));
+ $coins = rand(250, 1000);
+ if($your_level > 1000) {
+ $coins = $coins * 2;
+ $c += round($c/4);
+ }
+ }
+
+ if($level > 500) {
+ if($c < 100) {
+ $c = rand(50,100);
+ }
+ }
+
+ if($level > 1000) {
+ if($c < 1000) {
+ $c = rand(100,200);
+ }
+ }
+ //$level = 300;
+ $enemy = array('level' => $level, 'damage' => '0', 'coin_total' => $coins, 'cannons' => $c);
+ $memcache->set($user . 'merchant_ship', $enemy);
+ //clear battle history - new ship!
+ $memcache->set($user . 'monster_battle_history', false);
+
+}
+
+
+$enemy_level = $enemy['level'];
+$enemy_damage = $enemy['damage'];
+//$enemy_team = $enemy['team'];
+$enemy_cannons = $enemy['cannons'];
+$enemy_coins = $enemy['coin_total'];
+$enemy_health = $enemy_level - $enemy_damage;
+
+$action_type = $_REQUEST['action_type'];
+
+if($hit == 'miss') { //it was a miss
+ $msg = "Arrrrrrr... you fired $direction and missed! and caused $your_hit damage . The monster attacked back, causing you $enemy_hit damage ";
+
+}
+if($action_type == 'parrot') {
+ if(empty($enemy_hit)) {
+ $msg = "Your parrot dropped some dynamite on the monster for $your_hit damage!";
+ }
+ else {
+ $msg = "Your parrot dropped some dynamite on the monster for $your_hit damage! The monster attacked back for $enemy_hit damage!";
+ }
+}
+else if($action_type == 'parrotdied') {
+ if(empty($enemy_hit)) {
+ $msg = "Your parrot caused $your_hit damage, but died in the attack!!";
+ }
+ else {
+ $msg = "Your parrot caused $your_hit damage, but died in the attack!! The monster attacked back for $enemy_hit damage!";
+ }
+}
+else if($action_type == 'rum') {
+ $msg = "Yer crew drank rum and are ready for battle!";
+
+}
+else if(!empty($your_hit) && !empty($enemy_hit)) {
+ $msg = "Arrrrrrr... you fired and caused $your_hit damage The monster attacked back, causing you $enemy_hit damage ";
+}
+else if($action_type == 'ham') {
+ if(!empty($enemy_hit)) {
+ $msg = "You ate some ham and healed yerself but the monster attacked you for $enemy_hit damage!";
+ }
+ else {
+ $msg = "You ate some ham and healed yerself!";
+ }
+}
+else {
+ $msg = 'Shiver Me Timbers! A monster is attacking you!';
+}
+
+
+$round = get_round($user);
+
+//echo "round $round";
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Cap'n
+
+Level Pirate
+
+
+
+
+
+
+
+
+
+ health remaining
+Level Cannons
+
+
+
+
+ ham
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Level Monster ( health remaining)
+Level Attack Power
+Defeat this monster to continue yer quest for treasure!
+
+ coin onboard
+
+ coins onboard
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $rum_required && $round == 5) {
+?>
+
+
+
+ To continue fighting yer crew must drink!
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0 && $parrot_total > 0) { ?>
+
+
+
+
+
+
+
+
+
+ 0) { ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Battle History
+ get($user . 'monster_battle_history'); ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+You cannot run away from this attacker!
+
+
+
+
+
+
+
+';
+//require_once "my_pirate.inc.php";
+
+//require_once "world_stats.inc.php";
+//set_profile($user);
+
+
+
+
+?>
+
+
+
diff --git a/barfight_action.php b/barfight_action.php
new file mode 100644
index 0000000..be726c1
--- /dev/null
+++ b/barfight_action.php
@@ -0,0 +1,73 @@
+redirect("tavern.php?msg=?lose&coins=$coins&weapon=pistol&your_exp=$your_exp&enemy_exp=$enemy_exp");
+ }
+ else {
+ //winner
+ //wins up to 50 coins,
+ //takes weapon
+ $facebook->redirect("tavern.php?msg=?win&coins=$coins&weapon=pistol&your_exp=$your_exp&enemy_exp=$enemy_exp");
+ }
+}
+else if($action == 'swords') {
+ //check for swords
+ //if one of them doesnt have swords, move on
+
+ if(rand(0,1) == 1) {
+ //loser
+ //loses up to 50 coins
+ //takes weapon
+ $facebook->redirect("tavern.php?msg=?lose&coins=$coins&weapon=pistol&your_exp=$your_exp&enemy_exp=$enemy_exp");
+ }
+ else {
+ //winner
+ //wins up to 50 coins,
+ //takes weapon
+ $facebook->redirect("tavern.php?msg=?win&coins=$coins&weapon=pistol&your_exp=$your_exp&enemy_exp=$enemy_exp");
+ }
+}
+else {
+ //if no pistols or swords
+ if(rand(0,1) == 1) {
+ //loser
+ //loses up to 50 coins
+ $facebook->redirect("tavern.php?msg=?lose&coins=$coins&your_exp=$your_exp&enemy_exp=$enemy_exp");
+ }
+ else {
+ //winner
+ //wins up to 50 coins,
+ $facebook->redirect("tavern.php?msg=?win&coins=$coins&your_exp=$your_exp&enemy_exp=$enemy_exp");
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/booty.php b/booty.php
new file mode 100644
index 0000000..d330a92
--- /dev/null
+++ b/booty.php
@@ -0,0 +1,6 @@
+redirect("$facebook_canvas_url/user_profile.php?action=inventory");
\ No newline at end of file
diff --git a/bootyview.php b/bootyview.php
new file mode 100644
index 0000000..6f19d30
--- /dev/null
+++ b/bootyview.php
@@ -0,0 +1,67 @@
+redirect("$facebook_canvas_url/install.php");
+}
+
+$id = $_GET['id'];
+if(!$id) {
+ $facebook->redirect("$facebook_canvas_url/booty.php");
+}
+
+print dashboard();
+
+?>
+
+
+
+
+
+
+
+
+Item Details Aye Captain, learn your booty uses well...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bottom_links.php b/bottom_links.php
new file mode 100644
index 0000000..1140280
--- /dev/null
+++ b/bottom_links.php
@@ -0,0 +1,107 @@
+
+
+
+
+
+
+
+
+*/
+
+
+$pvp_toggle = $_REQUEST['pvp'];
+//print "aaa $pvp_toggle bbb";
+if(!empty($pvp_toggle)) {
+ if($pvp_toggle == 'off') {
+ $memcache->set($user .'pvp', $pvp_toggle);
+ $DB->Execute('update users set pvp_off = 1 where id = ?', array($user));
+ }
+ else if($pvp_toggle == 'on') {
+ //echo 'setting to on';
+ $memcache->set($user .'pvp', $pvp_toggle);
+ $DB->Execute('update users set pvp_off = 0 where id = ?', array($user));
+ }
+ }
+
+$pvp_toggle = $memcache->get($user . 'pvp');
+//print "pvp toggle $pvp_toggle";
+if($pvp_toggle == 'off') {
+?>
+
+
+
+
+
+Sail into enemy waters if you want to fight pirates and pillage towns!
+
+
+
+
+
+
+
+
+
+
+You may be attacked by enemy pirates at random! Arrr!
+
+
+
+
+
+
+
+*">Dig up buried coins 0) {
+?>
+*Heal yourself by eating ham ( left)
+
+
+}
+else {
+?>
+
+*Heal yourself by buying some ham (50 coins)
+
+
+
+*">Level Up by recruiting Pirates.
+*">View your stats to see how strong of a pirate you are.
+
+
+
+
+
diff --git a/bottom_links_no_pvp.php b/bottom_links_no_pvp.php
new file mode 100644
index 0000000..87da591
--- /dev/null
+++ b/bottom_links_no_pvp.php
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+*/ ?>
+
+get($user . 'pvp');
+//print "pvp toggle $pvp_toggle";
+if($pvp_toggle == 'off') {
+?>
+
+
+
+
+
+*Sailing safe waters!
+
+
+Sail into enemy waters if you want to fight pirates and pillage towns!
+
+
+
+
+
+
+
+
+
+
+*Exploring enemy waters!
+
+You may be attacked by enemy pirates at random! Arrr!
+
+
+
+
+
+
+
+
+
+
+
+*>Dig up buried coins 0) {
+?>
+*Heal yourself by eating ham ( left)
+
+
+}
+else {
+?>
+
+*Heal yourself by buying some ham (50 coins)
+
+
+
+*">Level Up by recruiting Pirates.
+*>View your stats to see how strong of a pirate you are.
+
+
+
+
+
+
diff --git a/bury_coins_arr.php b/bury_coins_arr.php
new file mode 100644
index 0000000..5c3e1d1
--- /dev/null
+++ b/bury_coins_arr.php
@@ -0,0 +1,69 @@
+Execute('insert into bot_log (user_id, created_at) values(?, now())', array($user));
+
+$type= get_team($user);
+
+//$gold = rand(1, 100);
+
+$your_coins = get_coin_total($user);
+
+
+$sql = 'update users set buried_coin_total = buried_coin_total + ?, coin_total=0 where id = ?';
+ $DB->Execute($sql, array($your_coins, $user));
+
+//require_once "my_pirate.inc.php";
+
+//require_once "world_stats.inc.php";
+//set_profile($user);
+
+$action = "buried coins";
+log_coins($user, 0, $action);
+
+
+//echo "You found $booty!!!";
+
+update_action($user, "NULL");
+
+print dashboard();
+
+?>
+
+
+
+
+
+ Ahoy! You buried coins
+
+Burying your treasure prevents other pirates from stealing it. Dig it up again if you want to spend it!
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bury_coins_arrr.php b/bury_coins_arrr.php
new file mode 100644
index 0000000..d87967f
--- /dev/null
+++ b/bury_coins_arrr.php
@@ -0,0 +1,56 @@
+Execute($sql, array($your_coins, $user));
+
+
+$action = "buried coins";
+log_coins($user, 0, $action);
+
+
+update_action($user, "NULL");
+
+print dashboard();
+
+?>
+
+
+
+
+
+You buried $your_coins coins");
+
+?>
+
+
+Burying your treasure prevents other pirates from stealing it. Dig it up again if you want to spend it!
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/buy.php b/buy.php
new file mode 100644
index 0000000..9ee502a
--- /dev/null
+++ b/buy.php
@@ -0,0 +1,323 @@
+get('shipyard_down');
+if($down == 1){
+ $facebook->redirect('index.php?msg=try-again-buy');
+}
+
+$upgrade_name = $_REQUEST['u'];
+
+if($upgrade_name != 'sails' && $upgrade_name != 'cannons' && $upgrade_name != 'hull' && $upgrade_name != 'crew' && $upgrade_name != 'wenches' && $upgrade_name != 'rum' && $upgrade_name != 'ham' && $upgrade_name != '5ham' && $upgrade_name != 'level' && $upgrade_name != 'sextant')
+{
+ $facebook->redirect('index.php');
+}
+
+$type= get_team($user);
+
+$upgrades = get_upgrades($user);
+
+//print_r($upgrades);
+//$cannon_level = $upgrades
+
+foreach($upgrades as $key=>$value) {
+ $upgrade_name = $value['upgrade_name'];
+ $level = $value['level'];
+ if($upgrade_name == 'cannons') {
+ $cannon_level = $level;
+ }
+ else if($upgrade_name == 'sails') {
+ $sail_level = $level;
+ }
+ else if($upgrade_name == 'hull') {
+ $hull_level = $level;
+ }
+ else if($upgrade_name == 'crew') {
+ $crew_level = $level;
+ }
+}
+
+
+if(!isset($crew_level)) {
+ $crew_level = 0;
+}
+
+if(!isset($hull_level)) {
+ $hull_level = 0;
+}
+if(!isset($cannon_level)) {
+ $cannon_level = 0;
+}
+if(!isset($sail_level)) {
+ $sail_level = 0;
+}
+
+$crew_price = 400;
+for($i = 0; $i < $crew_level; $i++) {
+ $crew_price += $crew_price * .05;
+}
+$crew_price = round($crew_price);
+if($crew_price > 10000) {
+ $crew_price = 10000;
+}
+
+$hull_price = 300;
+for($i = 0; $i < $hull_level; $i++) {
+ $hull_price += $hull_price * .05;
+}
+$hull_price = round($hull_price);
+if($hull_price > 10000) {
+ $hull_price = 10000;
+}
+
+$cannon_price = 100;
+for($i = 0; $i < $cannon_level; $i++) {
+ $cannon_price += $cannon_price * .05;
+}
+$cannon_price = round($cannon_price);
+if($cannon_price > 10000) {
+ $cannon_price = 10000;
+}
+
+$sail_price = 200;
+for($i = 0; $i < $sail_level; $i++) {
+ $sail_price += $sail_price * .05;
+}
+$sail_price = round($sail_price);
+if($sailprice > 10000) {
+ $sailprice = 10000;
+}
+
+$wench_price = 25;
+for($i = 0; $i < $crew_level; $i++) {
+ $wench_price += $wench_price * .05;
+}
+$wench_price = round($wench_price);
+if($wench_price > 1000) {
+ $wench_price = 1000;
+}
+
+//$crew_price = ($crew_level + 1) * 400;
+//$hull_price = ($hull_level + 1) * 300;
+//$cannon_price = ($cannon_level + 1) * 100;
+//$sail_price = ($sail_level + 1) * 200;
+
+$upgrade_name = $_REQUEST['u'];
+
+if($upgrade_name == 'cannons') {
+ $cost = $cannon_price;
+}
+if($upgrade_name == 'level') {
+ $cost = 50;
+}
+if($upgrade_name == 'sails') {
+ $cost = $sail_price;
+}
+if($upgrade_name == 'hull') {
+ $cost = $hull_price;
+}
+if($upgrade_name == 'crew') {
+ $cost = $crew_price;
+}
+if($upgrade_name == 'wenches') {
+ $cost = $wench_price;
+}
+if($upgrade_name == 'rum') {
+ $cost = 50;
+}
+if($upgrade_name == 'ham') {
+ $cost = 50;
+}
+if($upgrade_name == '5ham') {
+ $cost = 200;
+}
+if($upgrade_name == 'sextant') {
+ $cost = 150;
+}
+
+$coins = get_coin_total($user);
+
+$ship_upgrade = false;
+if($coins < $cost) {
+
+ $buried_coins = get_coin_total_buried($user);
+ if($buried_coins > 0) {
+
+ $msg = error_msg_return("Sorry, you don't have enough coins to purchase that yet. Dig up coins !");
+
+ }
+ else {
+ error_msg_return("Sorry, you don't have enough coins to purchase that yet. Go find more booty!!");
+
+ }
+
+}
+else if($upgrade_name == "level") {
+ $ship_upgrade = true;
+ $level = get_level($user);
+ //echo "level is: $level";
+
+ if($level !=0) {
+ //fix for people trying to hack this and typing in buy.php?u=level directly,
+ //then going down in level. LOL
+ $facebook->redirect("index.php");
+ }
+
+ $sql = 'update users set level = 1 where id = ?';
+ $DB->Execute($sql, array($user));
+
+ update_coins($user, -$cost);
+ log_coins($user, -$cost, 'bought level 1');
+ log_levels($user, 'bought level 1');
+
+ $coin_left = $coins - $cost;
+
+ $msg = "Avast! You purchased a level 1 Pirate upgrade for $cost coins! You have $coin_left coins left. ";
+
+
+}
+else if($upgrade_name == "wenches" or $upgrade_name == "rum" or $upgrade_name == "ham" or $upgrade_name == "5ham" or $upgrade_name == "sextant") {
+ //update_coins($user, -$cost);
+ //$coin_left = $coins - $cost;
+ $msg = "Avast! You purchased $upgrade_name for $cost coins! You have $coin_left coins left.";
+ if($upgrade_name == "wenches") {
+
+
+ $action = get_current_action($user);
+ $no_captcha = get_no_captcha();
+ $pass = false;
+ if (in_array($user, $no_captcha )) {
+ $pass = true;
+ }
+
+ if($action != "captcha_complete" && $pass == false) {
+ update_action($user, "captcha");
+ $s = urlencode("buy.php?u=wenches");
+ $facebook->redirect("$facebook_canvas_url/captcha_page.php?page=$s");
+ }
+ else { //this means they've completed the captcha
+ update_action($user, "NULL");
+ }
+ log_coins($user, -$cost, 'bought wenches');
+ update_coins($user, -$cost);
+ $coin_left = $coins - $cost;
+
+ set_damage($user, 0); //heal completely
+ set_miles_traveled($user, 0);
+ $msg .= "Your crew is now rejuvenated and ready to hit the high seas. ";
+
+
+ }
+ else if($upgrade_name == "rum") {
+
+ log_coins($user, -$cost, 'bought rum');
+ update_coins($user, -$cost);
+ $coin_left = $coins - $cost;
+
+ $stuff_id = 9; //rum
+ $msg = "Avast! You purchased some Rum for $cost coins! You have $coin_left coins left. ";
+ $msg = $msg . " ";
+
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1';
+ $DB->Execute($sql, array($user, $stuff_id));
+ }
+ else if($upgrade_name == "ham") {
+ log_coins($user, -$cost, 'bought ham');
+ update_coins($user, -$cost);
+ $coin_left = $coins - $cost;
+
+ $stuff_id = 12; //ham
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1';
+ $DB->Execute($sql, array($user, $stuff_id));
+ $msg = "Avast! You purchased Salted Ham for $cost coins! You have $coin_left coins left. ";
+ $msg = $msg . " ";
+ }
+ else if($upgrade_name == "5ham") {
+ log_coins($user, -$cost, 'bought 5 ham');
+ update_coins($user, -$cost);
+ $coin_left = $coins - $cost;
+
+ $stuff_id = 12; //ham
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 5';
+ $DB->Execute($sql, array($user, $stuff_id));
+ $msg = "Avast! You purchased 5 Salted Hams for $cost coins! You have $coin_left coins left. ";
+ $msg = $msg . " ";
+ }
+ else if($upgrade_name == "sextant") {
+ log_coins($user, -$cost, 'bought sextant');
+ update_coins($user, -$cost);
+ $coin_left = $coins - $cost;
+
+ $stuff_id = 13; //ham
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1';
+ $DB->Execute($sql, array($user, $stuff_id));
+ $msg = "Avast! You purchased a Sextant for $cost coins! You have $coin_left coins left. ";
+ }
+
+}
+else {
+
+
+
+ $ship_upgrade = true;
+ buy_upgrade_transaction($user, $upgrade_name, $cost);
+
+ //update_coins($user, -$cost);
+ //$DB->Execute('update bla set bla = bla');
+ //$DB->FailTrans();
+ //$DB->CompleteTrans();
+
+ $coin_left = $coins - $cost;
+
+ $action = "bought upgrade $upgrade_name";
+ log_coins($user, -$cost, $action);
+
+ $msg = "Avast! You purchased $upgrade_name for $cost coins! You have $coin_left coins left. ";
+
+}
+
+print dashboard();
+
+?>
+
+
+
+ ARRRR you ready for your ship upgrade?
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ">Go back to sea -adventure, danger and treasure await
+
+
+
+
+
+
diff --git a/cant_pillage_yet.php b/cant_pillage_yet.php
new file mode 100644
index 0000000..76c5445
--- /dev/null
+++ b/cant_pillage_yet.php
@@ -0,0 +1,13 @@
+
diff --git a/cant_pillage_yet_facebook.php b/cant_pillage_yet_facebook.php
new file mode 100644
index 0000000..7a132fd
--- /dev/null
+++ b/cant_pillage_yet_facebook.php
@@ -0,0 +1,104 @@
+GetOne('select level from upgrades where user_id = ? and upgrade_name = ?', array($user, 'crew'));
+
+if($crew > 5) {
+ $facebook->redirect('index.php');
+}
+
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+update_action($user, "NULL");
+
+print dashboard();
+
+?>
+
+
+GetOne('select pillage_invites from users where id = ?', array($user));
+
+ //echo "pillage invites $pillage_invites";
+if($pillage_invites > 2) {
+ $DB->Execute('update users set pillage_invites = 0 where id = ?', array($user));
+ buy_upgrade($user, 'crew');
+ $facebook->redirect('index.php?msg=pillage-invite-crew');
+}
+
+?>
+Ye can't be pillaging without a crew!
+
+Invite 3 friends to be Pirates to gain yer first crew member!
+You have friends left to invite before getting a crew member
+
+api_client->fql_query("SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = $user)");
+$arFriends = "";
+
+// Build an delimited list of users...
+if ($rs)
+{
+ for ( $i = 0; $i < count($rs); $i++ )
+ {
+ if ( $arFriends != "" )
+ $arFriends .= ",";
+
+ $arFriends .= $rs[$i]["uid"];
+ }
+}
+
+
+
+$sNextUrl = urlencode("&i=".$user);
+
+// Build your invite text
+$invfbml = <<
+ wants you to become a Pirate. Pillage, plunder, and sail on the high seas!
+
+FBML;
+
+?>
+
+
+
+
+
+...Or Sail into the Harbor and hire some crew members
+//If you need coins, sail and look on deserted islands!
+?>
+
+
+
+Pillaging Tips:
+The more crew you have the more money you'll make.
+The less houses you attack the higher chance you'll win.
+Crew can be killed if your attack fails! It's rare but it happens!
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cant_pillage_yet_myspace.php b/cant_pillage_yet_myspace.php
new file mode 100644
index 0000000..20b588f
--- /dev/null
+++ b/cant_pillage_yet_myspace.php
@@ -0,0 +1,54 @@
+GetOne('select level from upgrades where user_id = ? and upgrade_name = ?', array($user, 'crew'));
+
+if($crew > 5) {
+// $facebook->redirect('index.php');
+}
+
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+update_action($user, "NULL");
+
+print dashboard();
+
+?>
+
+
+
+Ye can't be pillaging without a crew!
+Crew members cost 400 coins at the shipyard
+
+You have coins. Find more gold on deserted islands.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/captcha_frame.php b/captcha_frame.php
new file mode 100644
index 0000000..704a1e0
--- /dev/null
+++ b/captcha_frame.php
@@ -0,0 +1,197 @@
+addServer('10.12.198.194', 11219);
+
+ $memcache = new MemcacheWrapper();
+ $memcache->addServer('10.12.198.194', 11211);
+
+}
+else {
+
+ //$db_ip = '10.8.50.198';
+ $db_ip = 'CHANGEME';
+ $db_user = 'CHANGEME';
+ $db_pass = 'CHANGEME';
+ $db_name = 'CHANGEME';
+
+ $facebook_canvas_url = 'http://dev.greenrobot.com/pirates/myspace';
+ $base_url = $facebook_canvas_url;
+ $base_url_captcha = 'http://gamesecuritywords.com/pirates/myspace';
+
+
+
+ $memcache_temp = new MemcacheWrapper('mt'); //use temp for mile limits, gambing limits
+ $memcache_temp->addServer('10.12.198.194', 11213);
+ $memcache_temp->addServer('10.8.50.196', 11213);
+
+ $memcache = new MemcacheWrapper('my');
+ $memcache->addServer('10.12.198.194', 11211);
+
+}
+
+ $connect= "mysql://$db_user:$db_pass@$db_ip/$db_name?persist";
+ $DB = NewADOConnection($connect);
+
+function update_action2($user, $action) {
+ global $DB, $memcache;
+ if($memcache) {
+ $team = $memcache->set($user . ":a", $action);
+ $DB->Execute("update users set current_action='$action' where id = $user");
+ }
+ else {
+ $DB->Execute("update users set current_action='$action' where id = $user");
+ }
+}
+
+if ($_POST["submit"]) {
+
+ //include_once '../client/facebook.php';
+ //include_once 'lib.php';
+ //include_once 'config.php';
+ $user = $_REQUEST['user'];
+ $page = $_REQUEST['page'];
+ $item = $_REQUEST['item'];
+
+ require_once('recaptchalib.php');
+ if($network_id == 0) {
+ $privatekey = '6LfN1AAAAAAAANNTEhf1pqAHUKim9tlkkYZH88d5';
+ }
+ else {
+ //$privatekey = '6LfN1AAAAAAAANNTEhf1pqAHUKim9tlkkYZH88d5';
+ $privatekey = '6LeF6wIAAAAAAJZd605m48lwKLYACX2uWOGFyXbB';
+ }
+ $resp = recaptcha_check_answer ($privatekey,
+ $_SERVER["REMOTE_ADDR"],
+ $_POST["recaptcha_challenge_field"],
+ $_POST["recaptcha_response_field"]);
+
+ if ($resp->is_valid) {
+ echo "You got it! ";
+ if($page != "") {
+ if($item != "") {
+ update_action2($user, "captcha_complete");
+ $url = "$facebook_canvas_url/$page" . "?item=$item";
+ if($network_id == 0) {
+ echo "click here to continue! ";
+ }
+ else {
+ echo "click here to continue! ";
+ }
+ //$facebook->redirect("$url");
+ }
+ else {
+ update_action2($user, "captcha_complete");
+ //$facebook->redirect("$facebook_canvas_url/$page");
+ if($network_id == 0) {
+ echo "click here to continue! ";
+ }
+ else {
+ echo "click here to continue! ";
+ }
+ }
+ }
+ else {
+ update_action2($user, "captcha_complete");
+ if($network_id == 0) {
+ echo "click here to continue! ";
+ }
+ else {
+ echo "click here to continue! ";
+ }
+ //$facebook->redirect("$facebook_canvas_url/index.php");
+ }
+
+
+
+ # in a real application, you should send an email, create an account, etc
+ } else {
+ # set the error code so that we can display it. You could also use
+ die ("You entered the words incorrectly, please try again "); //, but using the error message is
+ # more user friendly
+ $error = $resp->error;
+ }
+}
+else {
+$user = $_REQUEST['fb_sig_user'];
+if(empty($user)) {
+ $user = $_REQUEST['user'];
+}
+
+?>
+
+
+
+
+
+
+/captcha_frame.php'>?>
+*/
+?>
+
+
+
+
+
+
+
+
diff --git a/captcha_page.php b/captcha_page.php
new file mode 100644
index 0000000..3977cd1
--- /dev/null
+++ b/captcha_page.php
@@ -0,0 +1,86 @@
+redirect("$facebook_canvas_url/install.php");
+}
+
+//don't let users come to this page without thier action being set correctly
+$action = get_current_action($user);
+if($action != "captcha") {
+ $facebook->redirect("$facebook_canvas_url/index.php");
+}
+
+ if($msg): ?>
+
+
+
+
+Arrr ye a human pirate? Let us be making sure!
+
+There are two words in the picture below.
+Type them into the box and hit submit to continue
+
+
+
+
+
+
+
+
+
+
+
+?>
+
+
+
+}
+?>
+
+
+
+
Can't see the image above?
+
Make sure you have no adblock software or 3rd party extensions installed. Javascript should be enabled
+
+
+
+
+
+
+
+
+
+There are no advertisements on this page The image above is used only to stop bots.
+
+
+
+
+
+
diff --git a/captcha_page_myspace.php b/captcha_page_myspace.php
new file mode 100644
index 0000000..f17fed0
--- /dev/null
+++ b/captcha_page_myspace.php
@@ -0,0 +1,303 @@
+redirect("$facebook_canvas_url/install.php");
+}
+
+//don't let users come to this page without thier action being set correctly
+$action = get_current_action($user);
+if($action != "captcha") {
+ $facebook->redirect("$facebook_canvas_url/index.php");
+}
+
+ if($msg): ?>
+
+
+
+
+Arrr ye a human pirate? Let us be making sure!
+
+There are two words in the picture below.
+Type them into the box and hit submit to continue
+
+
+
+
+
+
+
+/captcha_frame.php?user='>
+*/
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+addServer('10.12.198.194', 11211);
+ $memcache_temp->addServer('10.8.50.196', 11211);
+
+ $memcache = new MemcacheWrapper();
+ $memcache->addServer('10.12.198.194', 11211);
+
+}
+else {
+
+ $db_ip = '10.8.50.198';
+ $db_user = 'CHANGEME';
+ $db_pass = 'CHANGEME';
+ $db_name = 'CHANGEME';
+
+ $facebook_canvas_url = 'http://dev.greenrobot.com/pirates/myspace';
+ $base_url = $facebook_canvas_url;
+ $base_url_captcha = 'http://gamesecuritywords.com/pirates/myspace';
+
+
+
+ $memcache_temp = new MemcacheWrapper('mt'); //use temp for mile limits, gambing limits
+ $memcache_temp->addServer('10.12.198.194', 11213);
+ $memcache_temp->addServer('10.8.50.196', 11213);
+
+ $memcache = new MemcacheWrapper('my');
+ $memcache->addServer('10.12.198.194', 11211);
+
+}
+
+ $connect= "mysql://$db_user:$db_pass@$db_ip/$db_name?persist";
+ $DB = NewADOConnection($connect);
+
+function update_action2($user, $action) {
+ global $DB, $memcache;
+ if($memcache) {
+ $team = $memcache->set($user . ":a", $action);
+ $DB->Execute("update users set current_action='$action' where id = $user");
+ }
+ else {
+ $DB->Execute("update users set current_action='$action' where id = $user");
+ }
+}
+
+if ($_POST["submit"]) {
+
+ //include_once '../client/facebook.php';
+ //include_once 'lib.php';
+ //include_once 'config.php';
+ $user = $_REQUEST['user'];
+ $page = $_REQUEST['page'];
+ $item = $_REQUEST['item'];
+
+ require_once('recaptchalib.php');
+ if($network_id == 0) {
+ $privatekey = '6LfN1AAAAAAAANNTEhf1pqAHUKim9tlkkYZH88d5';
+ }
+ else {
+ //$privatekey = '6LfN1AAAAAAAANNTEhf1pqAHUKim9tlkkYZH88d5';
+ $privatekey = '6LeF6wIAAAAAAJZd605m48lwKLYACX2uWOGFyXbB';
+ }
+ $resp = recaptcha_check_answer ($privatekey,
+ $_SERVER["REMOTE_ADDR"],
+ $_POST["recaptcha_challenge_field"],
+ $_POST["recaptcha_response_field"]);
+
+ if ($resp->is_valid) {
+ echo "You got it! ";
+ if($page != "") {
+ if($item != "") {
+ update_action2($user, "captcha_complete");
+ $url = "$facebook_canvas_url/$page" . "?item=$item";
+ if($network_id == 0) {
+ echo "click here to continue! ";
+ }
+ else {
+ echo "click here to continue! ";
+ }
+ //$facebook->redirect("$url");
+ }
+ else {
+ update_action2($user, "captcha_complete");
+ //$facebook->redirect("$facebook_canvas_url/$page");
+ if($network_id == 0) {
+ echo "click here to continue! ";
+ }
+ else {
+ echo "click here to continue! ";
+ }
+ }
+ }
+ else {
+ update_action2($user, "captcha_complete");
+ if($network_id == 0) {
+ echo "click here to continue! ";
+ }
+ else {
+ echo "click here to continue! ";
+ }
+ //$facebook->redirect("$facebook_canvas_url/index.php");
+ }
+
+
+
+ # in a real application, you should send an email, create an account, etc
+ } else {
+ # set the error code so that we can display it. You could also use
+ die ("You entered the words incorrectly, please try again "); //, but using the error message is
+ # more user friendly
+ $error = $resp->error;
+ }
+}
+
+//else {
+//$user = $_REQUEST['fb_sig_user'];
+//if(empty($user)) {
+// $user = $_REQUEST['user'];
+//}
+
+?>
+
+
+
+
+
+
+/captcha_frame.php'>?>
+*/
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+?>
+
+
+
+
Can't see the image above?
+
Make sure you have no adblock software or 3rd party extensions installed. Javascript should be enabled
+
+
+
+
+
+
+
+
+
+There are no advertisements on this page The image above is used only to stop bots.
+
+
+
+
+
+
diff --git a/captcha_test.php b/captcha_test.php
new file mode 100644
index 0000000..5fc520b
--- /dev/null
+++ b/captcha_test.php
@@ -0,0 +1,22 @@
+redirect("$facebook_canvas_url/install.php");
+}
+
+update_action($user, "captcha");
+
+$facebook->redirect("$facebook_canvas_url/captcha_page.php?page=harbor.php");
+
+?>
diff --git a/cheater_ids.php b/cheater_ids.php
new file mode 100644
index 0000000..88028c4
--- /dev/null
+++ b/cheater_ids.php
@@ -0,0 +1,573 @@
+
diff --git a/cheaterboard.php b/cheaterboard.php
new file mode 100644
index 0000000..23ceb8a
--- /dev/null
+++ b/cheaterboard.php
@@ -0,0 +1,321 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$level = get_level($user);
+
+print dashboard();
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Top $uc_team_listing Pirates!"; ?>
+
+
+
+ '/>
+ ' />
+ ' />
+ '/>
+
+
+ redirect('index.php');
+}
+ ?>
+
+
Ahoy! If you see this message, your account has been been moved to a different pirate server! There are now about 60 users on this server, and there are less rules compared to the main pirates server. You were moved here because of using multiple accounts to advance one account, using automation, or other suspicious activity. (main pirate server rules ) Your Coins, Levels, Booty have not been transferred to this new server. Every one of the new 'advanced' players is starting at level 0. It should be pretty easy to make this leaderboard even without yer old booty, so go get it! :) Setting this system up and finding who to put in it was not fun for me. I don't want to ban anyone or stop people from having fun in the game (especially passionate users like you guys), but keeping the game fun for the majority of players is the most important thing.
+Arrrr.....
+
+
+
+
+ get("leaderboard");
+ if($r == FALSE) {
+ $sql = "SELECT id, name, level , buried_coin_total, created_at, level * buried_coin_total b FROM users ORDER BY b DESC LIMIT 50";
+
+ $r = $DB->GetArray($sql);
+ $memcache->set("leaderboard", $r, false, 3600 * 6);
+ }
+ }
+ else if ($sort_listing == 'coins') {
+ $r = $memcache->get("leaderboard_coins");
+ if($r == FALSE) {
+ $sql = "SELECT id, name, level , buried_coin_total, created_at, buried_coin_total b FROM users ORDER BY b DESC LIMIT 50";
+
+ $r = $DB->GetArray($sql);
+ $memcache->set("leaderboard_coins", $r, false, 3600 * 6);
+ }
+ }
+ else if ($sort_listing == 'level') {
+ $r = $memcache->get("leaderboard_level");
+ if($r == FALSE) {
+ $sql = "SELECT id, name, level , buried_coin_total, created_at, level b FROM users ORDER BY b DESC LIMIT 50";
+
+ $r = $DB->GetArray($sql);
+ $memcache->set("leaderboard_level", $r, false, 3600 * 6);
+ }
+ }
+
+
+
+
+
+
+ }
+
+
+ else {
+ if($sort_listing == 'overall') {
+ $r = $memcache->get("leaderboard_$team_listing");
+ if($r == FALSE) {
+ $sql = "SELECT id, name, level , buried_coin_total, created_at, level * buried_coin_total b FROM users where team = ? ORDER BY b DESC LIMIT 50";
+
+ $r = $DB->GetArray($sql, array($team_listing));
+ $memcache->set("leaderboard_$team_listing", $r, false, 3605 * 6);
+ }
+ }
+
+ else if($sort_listing == 'coins') {
+ $r = $memcache->get("leaderboard_coins_$team_listing");
+ if($r == FALSE) {
+ $sql = "SELECT id, name, level , buried_coin_total, created_at, buried_coin_total b FROM users where team = ? ORDER BY b DESC LIMIT 50";
+
+ $r = $DB->GetArray($sql, array($team_listing));
+ $memcache->set("leaderboard_coins_$team_listing", $r, false, 3605 * 6);
+ }
+ }
+ else if($sort_listing == 'level') {
+ $r = $memcache->get("leaderboard_level_$team_listing");
+ if($r == FALSE) {
+ $sql = "SELECT id, name, level , buried_coin_total, created_at, level b FROM users where team = ? ORDER BY b DESC LIMIT 50";
+
+ $r = $DB->GetArray($sql, array($team_listing));
+ $memcache->set("leaderboard_level_$team_listing", $r, false, 3605 * 6);
+ }
+ }
+
+
+
+
+
+ }
+ ?>
+
+
+ $value) {
+ //echo "key $key";
+ //echo "value $value";
+ //print_r($value);
+
+ $id = $value['id'];
+ $score = $value['b'];
+ $level = $value['level'];
+ $created_at = date("F j, Y", strtotime($value['created_at']));
+ $buried_coin_total = $value['buried_coin_total'];
+ $rank = $key + 1;
+ $buried_coin_total = number_format($buried_coin_total);
+ echo "$rank ";
+ echo " ";
+ echo " Pirate Since $created_at ";
+
+
+ if($sort_listing == 'level') {
+ echo "level: $level ";
+ }
+ else {
+ echo "level: $level ";
+ }
+
+ if($sort_listing == 'coins') {
+ echo "gold: $buried_coin_total ";
+ }
+ else {
+ echo "gold: $buried_coin_total ";
+ }
+
+ echo "
";
+
+ }
+
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
Go back to sea -adventure, danger and treasure await
+
+
+
+
+
+
+
+
+ Pirate Leaderboard
+
+
+
+
+
+
+
diff --git a/clear_action.php b/clear_action.php
new file mode 100644
index 0000000..8bc0b71
--- /dev/null
+++ b/clear_action.php
@@ -0,0 +1,10 @@
+redirect("$facebook_canvas_url/index.php");
+
+
+?>
\ No newline at end of file
diff --git a/clear_secondary.php b/clear_secondary.php
new file mode 100644
index 0000000..9cba351
--- /dev/null
+++ b/clear_secondary.php
@@ -0,0 +1,15 @@
+redirect("$facebook_canvas_url/index.php");
+
+?>
\ No newline at end of file
diff --git a/clear_was_attacked.php b/clear_was_attacked.php
new file mode 100644
index 0000000..e7c6046
--- /dev/null
+++ b/clear_was_attacked.php
@@ -0,0 +1,25 @@
+Execute("update users set user_was_attacked = '0' where id = ?", array($user));
+set_was_attacked($user, 0);
+set_was_bombed($user, 0);
+
+update_action($user, "NULL");
+
+$action = $_REQUEST['action'];
+
+if($action == 'eatham') {
+ $facebook->redirect("$facebook_canvas_url/item_action.php?item=ham");
+}
+else if($action == 'buyham') {
+ $facebook->redirect("$facebook_canvas_url/buy.php?u=ham");
+}
+else {
+ $facebook->redirect("$facebook_canvas_url/index.php");
+}
+
+?>
\ No newline at end of file
diff --git a/click.php b/click.php
new file mode 100644
index 0000000..93b89df
--- /dev/null
+++ b/click.php
@@ -0,0 +1,50 @@
+Execute("insert into clicks (from_id, facebook_id, created_at) VALUES (?, ?, now())", array($from_id, $facebook_id));
+//}
+
+header('Location: http://www.facebook.com/apps/application.php?id=2342084241');
+
+if($from_id == 0) {
+ header('Location: CHANGEME');
+}
+
+
+//if from_id is 0, then go to apps.facebook.com/pirates
+//piratewarsonline.com/click.php?o=999&z=234234
+
+
+
+?>
diff --git a/clicks_out.php b/clicks_out.php
new file mode 100644
index 0000000..11d9958
--- /dev/null
+++ b/clicks_out.php
@@ -0,0 +1,35 @@
+
+require_once 'lib.php';
+global $DB;
+
+echo '
';
+echo "ARrrr Pirate Clicks Sent Out: ";
+echo $DB->GetOne("select count(*) from clicks_out");
+echo " ";
+
+
+
+echo "Last 100 clicks:";
+echo " ";
+?>
+
+Text Facebook Id Date
+GetArray("select * from clicks_out order by created_at desc limit 100");
+foreach($total as $key => $value) {
+ $text=$value['offer_text'];
+ $fb_id=$value['fb_id'];
+ $created_at=$value['created_at'];
+
+ print "$text $fb_id $created_at ";
+
+}
+ //print_r($total);
+
+
+?>
+
+
+
+
diff --git a/config.php b/config.php
new file mode 100644
index 0000000..04de7dc
--- /dev/null
+++ b/config.php
@@ -0,0 +1,11 @@
+get_loggedin_user();
+//print_r($user);
+//echo $user;
+//die("ok");
+//$is_logged_out = !$user;
+
+$i = $_REQUEST['i'];
+
+//if($is_logged_out && !isset($i)) {
+// require_once 'index_logged_out.php';
+// exit;
+//}
+
+$facebook->require_frame();
+$user = $facebook->require_login();
+
+
+////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+require_once 'cheater_ids.php';
+
+///ISOLATED SERVER FOR CHEATERS
+if(isset($cheaters[$user])) {
+//if(in_array($user, $cheaters)) {
+ die("Your account has been banned from Pirates. This is because you broke the Facebook Terms of Service or the Pirate Rules. Common reasons for being banned are using automated bots to play the game or creating fake/multiple Facebook accounts. If you have any questions please message me. I apoligize for not messaging you individually. -Andy");
+
+
+
+
+}
+else {
+ $db_user = 'CHANGEME';
+ //$db_user = 'CHANGEME';
+ //$db_pass = 'CHANGEME';
+ $db_pass = 'CHANGEME';
+
+ // the name of the database that you create for footprints.
+ //$db_name = 'piratewarsdev';
+ $db_name = 'CHANGEME';
+
+
+ $memcache_temp = new Memcache(); //use temp for mile limits, gambing limits
+ $memcache_temp->addServer('10.12.198.194', 11219);
+
+ $memcache = new Memcache();
+ $memcache->addServer('10.12.198.194', 11211);
+
+
+}
+
+require_once 'image_ids.php';
diff --git a/config_myspace.php b/config_myspace.php
new file mode 100644
index 0000000..34519e0
--- /dev/null
+++ b/config_myspace.php
@@ -0,0 +1,76 @@
+addServer('10.12.198.194', 11213);
+ $memcache_temp->addServer('10.8.50.196', 11213);
+
+ $memcache = new MemcacheWrapper('my');
+ $memcache->addServer('10.12.198.194', 11211);
+
+
+
+
+
+require_once 'image_ids.php';
+ //require_once('Space.php');
+
+global $user, $key, $secret;
+
+ //$key = 'http://www.greenrobot.com/pirates/myspace';
+ //$secret = 'CHANGEME';
+
+ //$user = $_REQUEST['opensocial_owner_id'];
+
+
+
+global $query_string;
+//print "
";
+//$oauth_params = array();
+//$exclude = array('action', 'image_id', 'splash', 'failure', 'success', 'bet', 'u', 'type', 'c', 'msg', 'to', 'gold', 'level_up', 'booty', 'amount', 'd');
+
+/*
+foreach($_REQUEST as $x => $y) {
+ //print "x: ";
+ //print_r($x);
+ //print "y: ";
+ //print_r($y);
+
+ if(!in_array($x, $exclude)) {
+ $oauth_params[$x] = $y;
+ }
+
+}
+*/
+//print " ";
+
+//$query_string = http_build_query($oauth_params);
+//print_r($query_string);
diff --git a/config_network.php b/config_network.php
new file mode 100644
index 0000000..68f9f17
--- /dev/null
+++ b/config_network.php
@@ -0,0 +1,11 @@
+
diff --git a/coolapps.php b/coolapps.php
new file mode 100644
index 0000000..fab5909
--- /dev/null
+++ b/coolapps.php
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Welcome to Pirate Booty Bonus! We think you should try these cool apps! If you see an application you like, install it and we'll credit you 100 Coins! !
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Show people you've got some class by displaying pictures of fine art in your profile.
+ Add Art
+
+
+
+
+
+
+
+ Display exotic beaches, beautiful sunsets, and magnificent mountains in your profile.
+ Add Paradise
+
+
+
+
+
+
+
+ Browse and display pictures of classic beauties in tasteful swimwear.
+ Add bikiniGirls
+
+
+
+
+
+
+
+ Sort through tons of funny LOLcats, and add the best ones to your profile to share with friends.
+ Add LOLcats
+
+
+
+
+
+
+
+
+
+
+
+
+
+Facebook Developers! Would you like your application listed here? Try it out
+
+
+
+
+
\ No newline at end of file
diff --git a/decline_the_joke.php b/decline_the_joke.php
new file mode 100644
index 0000000..2d7e522
--- /dev/null
+++ b/decline_the_joke.php
@@ -0,0 +1,32 @@
+
+redirect('index.php');
+}
+
+
+if(!$joke_id) {
+ $facebook->redirect('approve_jokes.php');
+
+}
+$r = $DB->Execute('update jokes set approved = 2 where id = ?', array($joke_id));
+
+//$r = $DB->Execute('update users set buried_coin_total = buried_coin_total + 200 where id = ?', array($joke_user));
+
+//print_r($r);
+
+$facebook->redirect('approve_jokes.php');
+?>
\ No newline at end of file
diff --git a/enemy_base.php b/enemy_base.php
new file mode 100644
index 0000000..3ccf166
--- /dev/null
+++ b/enemy_base.php
@@ -0,0 +1,70 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+print dashboard();
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Time for pillagin!';
+ success_msg($msg2); ?>
+
+
+
+
+
+
+
+
+
+Pillage to find booty and coins
+
+
+
+Only for landlubbers...
+
+
+
+
+
+
+
+
+
+
diff --git a/enemy_ship.php b/enemy_ship.php
new file mode 100644
index 0000000..a0d0881
--- /dev/null
+++ b/enemy_ship.php
@@ -0,0 +1,41 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+
+print dashboard();
+?>
+
+
+
+
+You found an Enemy Ship. ARRRR you gonna attack?'); ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/explore.php b/explore.php
new file mode 100644
index 0000000..83699e3
--- /dev/null
+++ b/explore.php
@@ -0,0 +1,210 @@
+
+redirect("$facebook_canvas_url/found_land.php");
+}
+else if($r == "bottle") {
+ $facebook->redirect("$facebook_canvas_url/index.php?msg=bottle");
+}
+else if($r == "parrot") {
+ $facebook->redirect("$facebook_canvas_url/index.php?msg=parrot");
+}
+else if($r== "ship") {
+ $facebook->redirect("$facebook_canvas_url/found_ship.php");
+}
+else if($r== "found_merchant_ship") {
+ $facebook->redirect("$facebook_canvas_url/found_merchant_ship.php");
+}
+else if($r== "bomb") {
+ $facebook->redirect("$facebook_canvas_url/throw_bomb.php");
+}
+else if($r== "seamonster") {
+ $facebook->redirect("$facebook_canvas_url/found_disturbance.php");
+}
+if($_REQUEST['sent'] == "1") {
+ $msg = "Yer Pirate invitations have been sent!";
+}
+
+if($_REQUEST['msg'] == "send-limit") {
+ $msg = "Your requests were not sent. You're over the limit for today. Try again later. :(";
+}
+
+//allow bad things to happen since this is only explore page
+$ship_image_blue = get_ship_image_and_weather($type, $user, false);
+$dangerMsg = processes_weather_effects($user, $ship_image_blue);
+
+$converted = false;
+if($dangerMsg != "" and get_health($user) <= 0) {
+ $enemy = random_enemy($type);
+ $w = ucwords($enemy);
+ update_team($user, $enemy);
+ $dangerMsg = "Bad weather has destroyed your ship! You are fished out by $w pirates and you become one of them.";
+ $converted = true;
+ $type = get_team($user);
+}
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+
+print dashboard();
+
+$team = $type;
+$coins = get_coin_total($user);
+$buried_coins = get_coin_total_buried($user);
+$health=get_health($user);
+$my_level=get_level($user);
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+You went sailing
+
+ocean as far as the eye can see...
+
+
+
+
+
+
+ Level Pirate
+ Hit Points:
+ Coins: Buried:
+
+
+
+
+
+= $milesMax and $dangerMsg == "") {
+
+ print get_too_many_miles_msg($user);
+
+ } else { ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+= $milesMax and $dangerMsg == "") {
+?>
+
+
+
+
\ No newline at end of file
diff --git a/footer.php b/footer.php
new file mode 100644
index 0000000..8793e26
--- /dev/null
+++ b/footer.php
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+Play Scribble
+- a multiplayer draw and guess game similar to Pictionary
+
+
+
diff --git a/footer_nolinks.php b/footer_nolinks.php
new file mode 100644
index 0000000..4e86c55
--- /dev/null
+++ b/footer_nolinks.php
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/found_land.php b/found_land.php
new file mode 100644
index 0000000..6a4a661
--- /dev/null
+++ b/found_land.php
@@ -0,0 +1,103 @@
+= $milesMax) {
+ update_action($user, "NULL");
+ $facebook->redirect("explore.php");
+}
+
+$type= get_team($user);
+
+//do not allow bad weather effects to happen
+$ship_image_blue = get_ship_image_and_weather($type, $user, true);
+
+
+if($_REQUEST['sent'] == "1") {
+ $msg = "Yer Pirate invitations have been sent!";
+}
+
+
+if($_REQUEST['msg'] == "send-limit") {
+ $msg = "Your requests were not sent. You're over the limit for today. Try again later. :(";
+}
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+print dashboard();
+
+$team = get_team($user);
+$coins = get_coin_total($user);
+$buried_coins = get_coin_total_buried($user);
+$health=get_health($user);
+$my_level=get_level($user);
+
+?>
+
+
+
+
+
+Avast!
+
+
+
+
+
+
+
+
+ Level Pirate
+ Hit Points:
+ Coins: Buried:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/found_merchant_ship.php b/found_merchant_ship.php
new file mode 100644
index 0000000..bf377b7
--- /dev/null
+++ b/found_merchant_ship.php
@@ -0,0 +1,103 @@
+= $milesMax) {
+ update_action($user, "NULL");
+ $facebook->redirect("explore.php");
+}
+redirect_to_index_if_not($user, "found_merchant_ship");
+
+$type= get_team($user);
+
+//do not allow bad weather effects to happen
+$ship_image_blue = get_ship_image_and_weather($type, $user, true);
+
+//$r = explore($user);
+//echo "r; $r";
+
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+
+print dashboard();
+
+$team = get_team($user);
+$coins = get_coin_total($user);
+$buried_coins = get_coin_total_buried($user);
+$health=get_health($user);
+$my_level=get_level($user);
+
+?>
+
+
+
+
+
+Avast!
+
+
+
+
+
+
+
+
+ Level Pirate
+ Hit Points:
+ Coins: Buried:
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/found_ship.php b/found_ship.php
new file mode 100644
index 0000000..61f3c76
--- /dev/null
+++ b/found_ship.php
@@ -0,0 +1,103 @@
+
+= $milesMax) {
+ update_action($user, "NULL");
+ $facebook->redirect("explore.php");
+}
+
+$type= get_team($user);
+
+//do not allow bad weather effects to happen
+$ship_image_blue = get_ship_image_and_weather($type, $user, true);
+
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+
+print dashboard();
+
+$team = get_team($user);
+$coins = get_coin_total($user);
+$buried_coins = get_coin_total_buried($user);
+$health=get_health($user);
+$my_level=get_level($user);
+
+?>
+
+
+
+
+
+Avast!
+
+
+
+
+
+
+
+
+ Level Pirate
+ Hit Points:
+ Coins: Buried:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/gambit_postback.php b/gambit_postback.php
new file mode 100644
index 0000000..5966e82
--- /dev/null
+++ b/gambit_postback.php
@@ -0,0 +1,41 @@
+Execute("update users set buried_coin_total=buried_coin_total + ? where id = ?", array($amount, $uid));
+
+
+$sql = 'insert into offers(user_id, offer_id, site, completed_at, currency) values (?, ?, ?, now(), ?)';
+$r = $DB->Execute($sql, array($uid, $oid, $site, $amount));
+
+
+
+?>
+success
diff --git a/gambitoffers.php b/gambitoffers.php
new file mode 100644
index 0000000..7ba9c5e
--- /dev/null
+++ b/gambitoffers.php
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Welcome to Pirate Booty Bonus! We need money to improve the site, you help us get it. We give you huge prizes!
+
+
+
+
+
+
+
+When you fill out offers, we get money and give you pirate gold!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/gambling.php b/gambling.php
new file mode 100644
index 0000000..1bb2527
--- /dev/null
+++ b/gambling.php
@@ -0,0 +1,596 @@
+ rand(30,60)) {
+ $facebook->redirect("$facebook_canvas_url/index.php?msg=gambling-addiction");
+}
+$type= get_team($user);
+
+
+if($_REQUEST['sent'] == "1") {
+ $msg = "Yer Pirate invitations have been sent!";
+}
+
+
+if($_REQUEST['msg'] == "send-limit") {
+ $msg = "Your requests were not sent. You're over the limit for today. Try again later. :(";
+}
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$level = get_level($user);
+
+$oddsForOver = 2;
+$oddsForUnder = 2;
+$oddsForExactly = 6;
+
+//get gambling stuff
+$betType = $_POST['type'];
+$bet = $_POST['bet'];
+$bet = (int)$bet;
+
+global $network_id;
+
+//start with snake eyes
+if($network_id == 0) {
+
+$diceImage1 = 33707139;
+$diceImage2 = 33707139;
+}
+else if($network_id == 1 || $network_id == 2) {
+$diceImage1 = 'n1807687_33707139_7638.jpg';
+$diceImage2 = 'n1807687_33707140_7745.jpg';
+
+}
+//if they've placed a bet we have to roll
+if($bet > 0) {
+ if($coin_total >= $bet) { //we need to roll
+ //immediately take out the coins
+
+ if($bet > 2500) {
+ $bet = 2500;
+ }
+
+ $coin_total = $coin_total - $bet;
+ set_coins($user, $coin_total);
+ log_coins($user, -$bet, 'gambling bet');
+
+ srand((double)microtime()*1000000);
+ $dice1 = rand(1,6);
+ $dice2 = rand(1,6);
+
+ $diceImage1 = get_die_roll_image($dice1);
+ $diceImage2 = get_die_roll_image($dice2);
+
+ //resolve the bet
+ if($betType > 0) {
+ if($betType == 1) { //over
+ if($dice1 + $dice2 > 7) {
+ $winnings = $bet * $oddsForOver;
+ $coin = $coin_total + $winnings;
+ $gamblingMsg = "You bilge rat! Ya be winning $winnings coins! ";
+ }
+ else {
+ $coin = $coin_total;
+ $gamblingMsg = "Yar har har, you lose! tanks for the $bet coins!";
+ }
+ }
+ else if($betType == 2) { //under
+ if($dice1 + $dice2 < 7) {
+ $winnings = $bet * $oddsForUnder;
+ $coin = $coin_total + $winnings;
+ $gamblingMsg = "You old salty dog! Ya be winning $winnings coins! ";
+ }
+ else {
+ $coin = $coin_total;
+ $gamblingMsg = "Yar har har, you lose! tanks for the $bet coins!";
+ }
+ }
+ else { //exactly
+ if($dice1 + $dice2 == 7) {
+ $winnings = $bet * $oddsForExactly;
+ $coin = $coin_total + $winnings;
+ $gamblingMsg = "Shiver me timbers! Ya be winning $winnings coins! ";
+ }
+ else {
+ $coin = $coin_total;
+ $gamblingMsg = "Yar har har, you lose! tanks for the $bet coins!";
+ }
+ }
+
+ if($coin < 0) {
+ $coin = 0;
+ }
+ set_coins($user, $coin);
+
+ if($winnings != 0) {
+ log_coins($user, $winnings, 'gambling win');
+ }
+
+ $coin_total = $coin;
+ }
+ else {
+ $betType = 1; //default to over
+ }
+
+ //get roll history
+ $lineNumber = 10;
+ $roll11 = $_POST['roll21'];
+ $roll12 = $_POST['roll22'];
+
+ if($roll11 == 0) {
+ $lineNumber = 9;
+ }
+
+ $roll21 = $_POST['roll31'];
+ $roll22 = $_POST['roll32'];
+
+ if($roll21 == 0) {
+ $lineNumber = 8;
+ }
+
+ $roll31 = $_POST['roll41'];
+ $roll32 = $_POST['roll42'];
+
+ if($roll31 == 0) {
+ $lineNumber = 7;
+ }
+
+ $roll41 = $_POST['roll51'];
+ $roll42 = $_POST['roll52'];
+
+ if($roll41 == 0) {
+ $lineNumber = 6;
+ }
+
+ $roll51 = $_POST['roll61'];
+ $roll52 = $_POST['roll62'];
+
+ if($roll51 == 0) {
+ $lineNumber = 5;
+ }
+
+ $roll61 = $_POST['roll71'];
+ $roll62 = $_POST['roll72'];
+
+ if($roll61 == 0) {
+ $lineNumber = 4;
+ }
+
+ $roll71 = $_POST['roll81'];
+ $roll72 = $_POST['roll82'];
+
+ if($roll71 == 0) {
+ $lineNumber = 3;
+ }
+
+ $roll81 = $_POST['roll91'];
+ $roll82 = $_POST['roll92'];
+
+ if($roll81 == 0) {
+ $lineNumber = 2;
+ }
+
+ $roll91 = $_POST['roll101'];
+ $roll92 = $_POST['roll102'];
+
+ if($roll91 == 0) {
+ $lineNumber = 1;
+ }
+
+ $roll101 = $dice1;
+ $roll102 = $dice2;
+
+ if($roll101 == 0) {
+ $lineNumber = 0;
+ }
+ }
+ else {
+ $error = "Yar, not enough gold for that bet there fella.";
+ }
+
+ //set default bet, be sure to do this after you've reconciled the last bet
+ if($bet == 0) {
+ if($coin_total >= 10) {
+ $defaultBet = 10;
+ }
+ else {
+ $defaultBet = $coin_total;
+ }
+ }
+ else {
+ if($coin_total >= $bet) {
+ $defaultBet = $bet;
+ }
+ else {
+ $defaultBet = $coin_total;
+ }
+ }
+}
+else {
+ //get roll history
+ $lineNumber = 10;
+ $roll11 = $_POST['roll11'];
+ $roll12 = $_POST['roll12'];
+
+ if($roll11 == 0) {
+ $lineNumber = 9;
+ }
+
+ $roll21 = $_POST['roll21'];
+ $roll22 = $_POST['roll22'];
+
+ if($roll21 == 0) {
+ $lineNumber = 8;
+ }
+
+ $roll31 = $_POST['roll31'];
+ $roll32 = $_POST['roll32'];
+
+ if($roll31 == 0) {
+ $lineNumber = 7;
+ }
+
+ $roll41 = $_POST['roll41'];
+ $roll42 = $_POST['roll42'];
+
+ if($roll41 == 0) {
+ $lineNumber = 6;
+ }
+
+ $roll51 = $_POST['roll51'];
+ $roll52 = $_POST['roll52'];
+
+ if($roll51 == 0) {
+ $lineNumber = 5;
+ }
+
+ $roll61 = $_POST['roll61'];
+ $roll62 = $_POST['roll62'];
+
+ if($roll61 == 0) {
+ $lineNumber = 4;
+ }
+
+ $roll71 = $_POST['roll71'];
+ $roll72 = $_POST['roll72'];
+
+ if($roll71 == 0) {
+ $lineNumber = 3;
+ }
+
+ $roll81 = $_POST['roll81'];
+ $roll82 = $_POST['roll82'];
+
+ if($roll81 == 0) {
+ $lineNumber = 2;
+ }
+
+ $roll91 = $_POST['roll91'];
+ $roll92 = $_POST['roll92'];
+
+ if($roll91 == 0) {
+ $lineNumber = 1;
+ }
+
+ $roll101 = $_POST['roll101'];
+ $roll102 = $_POST['roll101'];
+
+ if($roll101 == 0) {
+ $lineNumber = 0;
+ }
+}
+
+function averageTotals() {
+ global $lineNumber, $roll11, $roll12, $roll21, $roll22, $roll31, $roll32, $roll41, $roll42, $roll51, $roll52, $roll61, $roll62, $roll71, $roll72, $roll81, $roll82, $roll91, $roll92, $roll101, $roll102;
+ $total = $roll11 + $roll12 + $roll11 + $roll12 + $roll31 + $roll32 + $roll41 + $roll42 + $roll51 + $roll52 + $roll61 + $roll62 + $roll71 + $roll72 + $roll81 + $roll82 + $roll91 + $roll92 + $roll101 + $roll102;
+ if($lineNumber == 0) {
+ $average = $total;
+ }
+ else {
+ $average = round($total / $lineNumber, 2);
+ }
+ return $average;
+}
+
+function lineNumberReturn() {
+ global $lineNumber;
+ $lineNumber = $lineNumber - 1;
+ if($lineNumber > -1) {
+ return $lineNumber + 1;
+ }
+ else {
+ return "";
+ }
+}
+
+function showLine($line) {
+ global $roll11, $roll12, $roll21, $roll22, $roll31, $roll32, $roll41, $roll42, $roll51, $roll52, $roll61, $roll62, $roll71, $roll72, $roll81, $roll82, $roll91, $roll92, $roll101, $roll102;
+
+ if($line == 10) {
+ if($roll101 + $roll102 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 9) {
+ if($roll91 + $roll92 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 8) {
+ if($roll81 + $roll82 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 7) {
+ if($roll71 + $roll72 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 6) {
+ if($roll61 + $roll62 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 5) {
+ if($roll51 + $roll52 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 4) {
+ if($roll41 + $roll42 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 3) {
+ if($roll31 + $roll32 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 2) {
+ if($roll21 + $roll22 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ else if($line == 1) {
+ if($roll11 + $roll12 == 0) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+}
+
+print dashboard();
+?>
+
+
+
+
+ Welcome to the Gambling Parlor!
+
+
+";
+ echo "";
+ echo "$gamblingMsg ";
+ echo " ";
+ echo " ";
+ }
+ else {
+ if($error != "") {
+?>
+
+
+
+
+
+If ye be lookin to go back broke... you've come to the right place.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Game Type: Over Under Seven Max bet 2500 coins
+
+
+ You have coins available for gambling
+ 0) { ?>
+
+
+
+
+
+
+
+
+ >Over 7
+ >Under 7
+ >Exactly 7
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Roll # Amount Total
+
+
+
+
+
+
+
+
+
+
+ Average
+
+
+
+
+
+ Play the Odds
+ Over Seven to 1
+ Under Seven to 1
+ Exactly Seven to 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+*/
+?>
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/harbor.php b/harbor.php
new file mode 100644
index 0000000..399cfc3
--- /dev/null
+++ b/harbor.php
@@ -0,0 +1,119 @@
+ 5000) {
+ $active_users = $memcache->get('active_hi_3');
+}
+else if($level > 1000) {
+ $active_users = $memcache->get('active_hi_2');
+}
+else if($level > 100) {
+ $active_users = $memcache->get('active_hi');
+}
+else {
+ $active_users = $memcache->get('active_lo');
+}
+
+if(!is_array($active_users)) {
+ $active_users = array();
+}
+
+foreach($active_users as $u => $value) {
+ if ($user == $value) {
+ //print $u;
+ unset($active_users[$u]);
+ $active_users = array_values($active_users);
+ if($level > 5000) {
+ $active_users = $memcache->set('active_hi_3', $active_users);
+ }
+ else if($level > 1000) {
+ $active_users = $memcache->set('active_hi_2', $active_users);
+ }
+ else if($level > 100) {
+ $active_users = $memcache->set('active_hi', $active_users);
+ }
+ else {
+ $active_users = $memcache->set('active_lo', $active_users);
+ }
+ }
+}
+
+
+if($_REQUEST['sent'] == "1") {
+ $msg = "Yer Pirate invitations have been sent!";
+}
+
+
+if($_REQUEST['msg'] == "send-limit") {
+ $msg = "Your requests were not sent. You're over the limit for today. Try again later. :(";
+}
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+print dashboard();
+?>
+
+
+
+
+
+
+
+
+
+
+Avast!
+
+
+
+Now entering a friendly harbor ...Arrrrr...
+
+">Shipyard -purchase upgrades for yer ship
+">Pirate Tavern - gambling, boozing, relaxing
+
+
+>Pirate Market - trade booty for level increases
+
+>Pirate Roster - check out the top pirates on facebook
+
+
+
+>The Trading Post - buy and sell your items! (beta)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/head_towards_land.php b/head_towards_land.php
new file mode 100644
index 0000000..2f7eccf
--- /dev/null
+++ b/head_towards_land.php
@@ -0,0 +1,43 @@
+redirect("$facebook_canvas_url/index.php");
+}
+$userMiles = get_miles_traveled($user);
+$milesMax = get_max_miles($user);
+if($userMiles >= $milesMax) {
+ update_action($user, "NULL");
+ $facebook->redirect('explore.php');
+}
+
+//is it an island or is it an enemy base?
+//is it a gold on the island, pirate coins, a treasure map, just a beach
+
+ $ra= rand(1,100);
+
+ //echo "ra; $ra";
+
+ if($ra < 45) { //enemy base
+ $pvp_toggle = $memcache->get($user . 'pvp');
+ if($pvp_toggle == 'off') {
+ update_action($user, "island");
+ $facebook->redirect("$facebook_canvas_url/island.php");
+ }
+ else {
+ update_action($user, "enemy_base");
+ $facebook->redirect("$facebook_canvas_url/enemy_base.php");
+ }
+ }
+ else { // island
+ update_action($user, "island");
+ $facebook->redirect("$facebook_canvas_url/island.php");
+ }
+
+
+
+?>
diff --git a/header.php b/header.php
new file mode 100644
index 0000000..b67767e
--- /dev/null
+++ b/header.php
@@ -0,0 +1,25 @@
+
+require_login();
+
+$was_bombed = get_was_bombed($user);
+
+if($was_bombed != "" && $was_bombed != 0) {
+ $facebook->redirect("you_were_bombed.php");
+}
+$was_attacked = get_was_attacked($user);
+
+if($was_attacked != "" && $was_attacked != 0) {
+ $facebook->redirect("you_were_attacked.php");
+}
+
+
+?>
+
diff --git a/image_ids.php b/image_ids.php
new file mode 100644
index 0000000..caddc03
--- /dev/null
+++ b/image_ids.php
@@ -0,0 +1,9 @@
+
\ No newline at end of file
diff --git a/image_ids_myspace.php b/image_ids_myspace.php
new file mode 100644
index 0000000..153133b
--- /dev/null
+++ b/image_ids_myspace.php
@@ -0,0 +1,241 @@
+
\ No newline at end of file
diff --git a/includes.php b/includes.php
new file mode 100644
index 0000000..a007cc2
--- /dev/null
+++ b/includes.php
@@ -0,0 +1,13 @@
+
\ No newline at end of file
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..2da3fdb
--- /dev/null
+++ b/index.php
@@ -0,0 +1,670 @@
+
+redirect("$facebook_canvas_url/install.php?i=$in");
+ }
+ else if( $network_id == 1 ) {
+ $facebook->redirect("http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=100506&appParams=$in");
+ }
+}
+
+
+global $DB, $network_id;
+
+redirect_if_action($user);
+ $action = get_current_action($user);
+ //echo $action;
+$was_bombed=get_was_bombed($user);
+if($was_bombed != "" && $was_bombed != 0 ) {
+ if($network_id == 0) {
+ $facebook->redirect('you_were_bombed.php');
+ }
+ else {
+ require_once "you_were_bombed.php";
+ exit();
+ }
+}
+$was_attacked = get_was_attacked($user);
+if($was_attacked != "" && $was_attacked != 0) {
+ if($network_id == 0) {
+ $facebook->redirect('you_were_attacked.php');
+ }
+ else {
+ require_once "you_were_attacked.php";
+ exit();
+ }
+}
+
+//echo "action $action";
+//$secondary_action = get_secondary_action($user);
+//echo "secondary action $secondary_action";
+
+//print $memcache->get($user . 'merchant_ship_limit');
+
+//set_level($user, 1200);
+
+$type = get_team($user);
+
+//do not allow bad weather effects
+$ship_image_blue = get_ship_image_and_weather($type, $user, true);
+
+
+//print $user;
+
+if($_REQUEST['sent'] == "1") {
+ $msg = explanation_msg_return('Yer Pirate invitations have been sent!');
+}
+
+if($_REQUEST['msg'] == "pillage-invite-crew") {
+ $msg = explanation_msg_return('Yer Pirate invitations have been sent and you now have a new crew member!');
+}
+
+if($_REQUEST['msg'] == "send-limit") {
+ $msg = error_msg_return("Your requests were not sent You're over the limit for today. Try again later. :(");
+}
+
+if($_REQUEST['msg'] == "try-again-buy") {
+ $msg = error_msg_return("Yer crew are repairing yer ship so you can't buy anything right now! Arrrr...Try again in a couple seconds.");
+}
+
+if($_REQUEST['msg'] == "cant-bomb-user-over-limit") {
+ $msg = error_msg_return("Yer crew refuses to bomb this pirate! Arrr.... try again in a few days.");
+}
+if($_REQUEST['msg'] == "sinking-ship") {
+ $amount = $_REQUEST['amount'];
+ $booty = $_REQUEST['booty'];
+
+ if($booty == 'cannons') {
+ $current_upgrade_level = get_cannons($user);
+ if($amount == 1) {
+ $booty_first = 'cannon';
+ }
+ else {
+ $booty_first = $booty;
+ }
+ }
+ else if($booty == 'crew') {
+ $current_upgrade_level = get_crew_count($user);
+ $booty_first = $booty;
+
+ }
+ else if($booty == 'sails') {
+ $current_upgrade_level = get_sails($user);
+ if($amount == 1) {
+ $booty_first = 'sail';
+ }
+ else {
+ $booty_first = $booty;
+ }
+ }
+
+
+ if($booty == 'crew') {
+ $msg = success_msg_return("Ahoy! You found a sinking pirate ship! Yer crew were able to pillage $amount $booty_first for yer ship! You now have $current_upgrade_level $booty");
+ }
+ else {
+ $msg = success_msg_return("Ahoy! You found a sinking pirate ship! Yer crew were able to pillage $amount $booty_first for yer ship! You now have level $current_upgrade_level $booty");
+ }
+}
+if($_REQUEST['msg'] == "bottle") {
+ $bottle_count = get_bottle_count($user);
+ $msg = success_msg_return("Arrr... You found a message in a bottle floating in the sea! You now have $bottle_count bottles!");
+}
+if($_REQUEST['msg'] == "trade-declined") {
+ $bottle_count = get_bottle_count($user);
+ $msg = success_msg_return("You declined the trade offered by the merchant ship captain. Arrr...");
+}
+if($_REQUEST['msg'] == "trade-accepted") {
+ $bottle_count = get_bottle_count($user);
+ $msg = explanation_msg_return("You accepted the merchant's trade offer and your got your new booty!");
+}
+if($_REQUEST['msg'] == "parrot") {
+ $parrot_count = get_parrot_count($user);
+ $parrot_arr = 'parrot';
+ if($parrot_count > 1) {
+ $parrot_arr = 'parrots';
+ }
+ $msg = explanation_msg_return("Arrr... You found a parrot at sea! You now have $parrot_count $parrot_arr! Parrots can be raced for gold at the tavern!");
+}
+if($_REQUEST['msg'] == "treasure-start") {
+ $miles = $memcache->get($user . 'treasure_hunt_miles');
+ if($miles == FALSE) { //
+ $action = get_current_action($user);
+ redirect_to_index_if_not($user, "treasure_hunt");
+ $miles = rand(10,15);
+ $memcache->set($user . 'treasure_hunt_miles', $miles);
+ }
+ else {
+ $action = get_current_action($user);
+ redirect_to_index_if_not($user, "treasure_hunt");
+ //$miles = rand(10,50);
+ $memcache->set($user . 'treasure_hunt_miles', $miles);
+ }
+
+ if($miles == 1) {
+ $miles_text = 'mile';
+ }
+ else {
+ $miles_text = 'miles';
+ }
+ $msg = explanation_msg_return("You've started on a quest for treasure! You have $miles more mile to go before getting the treasure!");
+
+}
+else if($action == 'treasure_hunt') {
+ $action = get_current_action($user);
+ redirect_to_index_if_not($user, "treasure_hunt");
+ $miles = $memcache->get($user . 'treasure_hunt_miles');
+ $memcache->set($user . 'treasure_hunt_miles', $miles - 1);
+ $nmiles = $miles - 1;
+ if($nmiles < 0) {
+ $nmiles = 0;
+ }
+ $memcache->set($user . 'treasure_hunt_miles', $nmiles);
+
+ //increment miles
+ increment_miles_traveled($user);
+
+ $msg = explanation_msg_return("You're on a quest for treasure! You have $nmiles more miles to go before getting the treasure!");
+}
+
+if($_REQUEST['msg'] == "send-limit-bombs") {
+ $msg = explanation_msg_return("Your bombs were sent! However, you're over the Facebook limit for today. Any future bombs will not be sent. Try again tommorow. :(");
+}
+
+if($_REQUEST['msg'] == "send-limit-dynamite") {
+ $msg = explanation_msg_return("Your dynamite was sent! However, you're over the Facebook limit for today. Any future dynamite will not be sent. Try again tommorow. :(");
+}
+
+if($_REQUEST['msg'] == "ship-ran-away") {
+ $msg = explanation_msg_return("The ship you were chasing sailed away before you could attack! Arrrr...");
+}
+
+if($_REQUEST['msg'] == "joke-added") {
+ $msg = explanation_msg_return("Yer Pirate Joke was submitted! If it's funny we'll credit you 200 coins!");
+}
+
+if($_REQUEST['msg'] == "settings-saved") {
+ $msg = explanation_msg_return("Yer settings were saved!");
+}
+
+if($_REQUEST['pvp'] == "on") {
+ $msg = explanation_msg_return("You are exploring enemy waters! If you are attacked yer crew will try to defend themselves");
+}
+
+if($_REQUEST['pvp'] == "off") {
+ $msg = explanation_msg_return("You sail into safe waters! You won't be attacked or find any enemy pirate ships or towns. You can still be bombed by yer friends");
+}
+
+if($_REQUEST['msg'] == "tshirt-ok") {
+ $msg = explanation_msg_return("Avast! Your T Shirt should arrive in a few weeks! Thanks for playing!!! Arrrr...");
+}
+
+if($_REQUEST['msg'] == "gambling-addiction") {
+ $msg = explanation_msg_return("A tavern thug throws you out of the game room! Better be comin back later! Arrrr...");
+}
+
+
+//http://www.facebook.com/profile.php?id=1807687
+if($_REQUEST['msg'] == "threw-bomb") {
+ $to = $_REQUEST['to'];
+ $gold = $_REQUEST['gold'];
+ $level_up = $_REQUEST['level_up'];
+ //if($level_up ==1) {
+ $msg = "";
+ $msg = $msg . image_return($bomb_100);
+
+ $msg = $msg . "
+
";
+ $msg = $msg . image_return($bomb_100);
+ if($network_id == 0) {
+ $name = " ";
+ }
+ else {
+ //$name = get_name_for_id($to);
+ $name = $_REQUEST['enemy_name'];
+ }
+ $msg = $msg . "
";
+ //
+ //
+ $msg = $msg . "";
+ $msg = $msg . " You threw a bomb at $name and stole $gold coins!
";
+ if($level_up == true) {
+ $msg .= "Level +1
";
+ }
+ else {
+ $msg .= "You didn't level up this time.after lvl 100 bombs become less effective for leveling. try trading booty for upgrades at the market to increase yer level!
";
+ }
+
+
+ //$msg .= "
+ //
+ // ";
+
+ //}
+}
+
+
+
+
+
+else if($_REQUEST['msg'] == "left-dynamite") {
+ $to = $_REQUEST['to'];
+ $gold = $_REQUEST['gold'];
+ $level_up = $_REQUEST['level_up'];
+ if($network_id == 0) {
+ $name = " ";
+ }
+ else {
+ $name = get_name_for_id($to);
+ }
+
+ $msg = "You launched a dynamite monkey attack against $name and receive $gold coins!";
+
+ if($level_up == true) {
+ $msg .= "Level +1
";
+ }
+ else {
+ $msg .= "You didn't level up this time... maybe next time.
";
+ }
+
+ $msg = explanation_msg_return($msg);
+
+}
+
+
+else if($_REQUEST['msg'] == "left-dynamite-for-pirate") {
+ $to = $_REQUEST['to'];
+ $gold = $_REQUEST['gold'];
+ $level_up = $_REQUEST['level_up'];
+ if($network_id == 0) {
+ $name = " ";
+ }
+ else {
+ $name = get_name_for_id($to);
+ }
+
+ if($name == '' || !$name) {
+ $name = 'your friend';
+ }
+
+ $msg = "You left an explosive booby trap for $name When the trap goes off your monkey will steal some of their booty!";
+
+
+ $msg = explanation_msg_return($msg);
+
+}
+
+
+
+else if($_REQUEST['msg'] == "drank-rum") {
+ $msg = explanation_msg_return("You drank some Rum! Your crew is ready to hit the seas.");
+}
+else if($_REQUEST['msg'] == "eat-ham") {
+ $msg = explanation_msg_return("You ate some Salted Ham! Your crew is healed and ready to hit the seas.");
+}
+else if($_REQUEST['msg'] == "hack") {
+ $msg = error_msg_return("1337 H4x0r! Arr... this is pirates, hackers beware!");
+}
+
+
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+
+ if( $network_id == 0 ) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+ }
+ else if( $network_id == 1 ) {
+ $facebook->redirect("http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=100506&appParams=$in");
+ }
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ //if($_REQUEST['opensocial_viewer_id'] == -1) {
+ //check if there is a p referer
+ $p = $_REQUEST['p'];
+ if(isset($p) && $p != '') {
+ //set the referer cookie
+
+ $cookietime = time() + (3600 * 24 * 30);
+
+ header("p3p: CP=\"ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV\"");
+ if($p != -1) {
+ setcookie('pirates_ref', $p, $cookietime, "/");
+ }
+
+
+
+ $recruiter_name = get_name_for_id($p);
+ echo "$recruiter_name wants you to play pirates with them! Click here to Play !
";
+ exit();
+ }
+ else {
+ //echo "Installe Pirates to Play!
";
+ //exit();
+ require_once 'install.php';
+ exit();
+ }
+ //}
+ //else {
+
+ // require_once 'install.php';
+ // exit();
+ //}
+}
+
+
+print dashboard();
+
+
+if($msg) {
+ echo $msg;
+}
+?>
+
+
+
+
+
+
+
+
+Ahoy, Matey!
+
+
+where do ye want to sail today?
+
+
+
+
+
+ Level Pirate
+ Hit Points:
+ Coins: Buried:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ get($user . 'treasure_attack_mile');
+ //echo "treasure $treasure_attack";
+ if($treasure_attack == 1) {
+ //echo "AT"
+ update_secondary_action($user, 'attacked_by_monster');
+ $facebook->redirect('attacked_by_monster.php');
+ }
+ else if ($treasure_attack > 1) {
+ $treasure_attack--;
+ $memcache->set($user . 'treasure_attack_mile', $treasure_attack);
+ }
+
+ $miles = $memcache->get($user . 'treasure_hunt_miles');
+ //print $miles;
+
+ if($miles < 1) {
+ update_action($user, 'treasure_booty');
+
+?>
+
+ >
+ get the BOOTY-->
+ (ARRR!)
+
+
+
+
+
+ >
+ -->
+ (ARRR!)
+
+
+
+
+
+
+
+
+
+
+
+ }
+
+?>
+
+
+
+
+
+
+
+
+
+set($user .'pvp', $pvp_toggle);
+ $DB->Execute('update users set pvp_off = 1 where id = ?', array($user));
+ }
+ else if($pvp_toggle == 'on') {
+ //echo 'setting to on';
+ $memcache->set($user .'pvp', $pvp_toggle);
+ $DB->Execute('update users set pvp_off = 0 where id = ?', array($user));
+ }
+ }
+?>
+
+
+
+
+
+
+
+
+
+
+
+Execute('update users set updated_at = now() where id = ?', array($user));
+
+
+//FOR FIGHTING SELECTION -
+//put users in a pool if they qualify to be attacked
+
+//echo new_ship_battle($user);
+$was_attacked_2 = $memcache->get($user . 'attacked');
+//print "was attacked $was_attacked";
+//if attacked remove from the
+
+//print "pvp toggle $pvp_toggle";
+
+//if user has coins onboard and is above level 10 put them in memcache pool
+if($my_level > 50 && $health > 1 && $coins > 1 && $was_attacked_2 == false && $pvp_toggle != 'off') {
+//echo 'ok';
+//print_r($active_users);
+//$new_active_users[] += $user;
+//echo $my_level;
+if($my_level > 5000) {
+ $active_users = $memcache->get('active_hi_3');
+ if($active_users == false) {
+ $active_users = array();
+ }
+ //print_r($active_users);
+ if(!in_array($user, $active_users)) {
+ //echo 'hello';
+ array_push($active_users, $user);
+ $memcache->set('active_hi_3', $active_users);
+ }
+}
+else if($my_level > 1000) {
+ $active_users = $memcache->get('active_hi_2');
+ if($active_users == false) {
+ $active_users = array();
+ }
+ //print_r($active_users);
+ if(!in_array($user, $active_users)) {
+ //echo 'hello';
+ array_push($active_users, $user);
+ $memcache->set('active_hi_2', $active_users);
+ }
+}
+else if($my_level > 100) {
+ $active_users = $memcache->get('active_hi');
+ if($active_users == false) {
+ $active_users = array();
+ }
+ //print_r($active_users);
+ if(!in_array($user, $active_users)) {
+ //echo 'hello';
+ array_push($active_users, $user);
+ $memcache->set('active_hi', $active_users);
+ }
+}
+else {
+ $active_users = $memcache->get('active_lo');
+ if($active_users == false) {
+ $active_users = array();
+ }
+ if(!in_array($user, $active_users)) {
+ //echo 'setting!';
+ array_push($active_users, $user);
+ $memcache->set('active_lo', $active_users);
+ }
+ else {
+ //echo 'already in';
+ }
+}
+
+
+
+}
+else {
+//echo 'not ok';
+//echo "my level: $my_level";
+//echo "my health: $real_health";
+//echo "my coins: $coins";
+//echo "was attacked: $was_attacked";
+
+
+}
+
+ //set_profile($user);
+try {
+
+ $is_set = $facebook->api_client->data_getUserPreference(1);
+
+}
+catch (Exception $e) { } //echo "is set: $is_set";
+
+ $f = get_profile_box($user);
+ $facebook->api_client->profile_setFBML(null, $user, $f, null, null, $f);
+
+ // Don't do this again
+ $facebook->api_client->data_setUserPreference(1, 'set');
+ //}
+
+
+
+
+
+ echo "Ahoy Matey! Add Pirates to yer profile!
";
+
+
+ require_once 'footer.php';
+?>
+
+Yarr! We be experiencing technical difficulties! Facebook has disabled one of the developer's profiles where all the pirate images are stored. This is a temporary problem which will be fixed when the profile and images are restored. 4/21/09
+*/
+?>
diff --git a/index_logged_out.php b/index_logged_out.php
new file mode 100644
index 0000000..7d4d7da
--- /dev/null
+++ b/index_logged_out.php
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Ahoy! Become a Pirate and sail the high seas of Facebook looking for treasure!
+
+
+But watch out for other Pirates who might try to steal your treasure or make you walk the plank! Shiver me timbers!
+Once you have some booty, trade it in for cool upgrades like bigger sails, stronger cannons, and more. Arrrr!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ";
+
+
+require_once 'footer_nolinks.php';
+?>
+
diff --git a/install.php b/install.php
new file mode 100644
index 0000000..97a72e3
--- /dev/null
+++ b/install.php
@@ -0,0 +1,196 @@
+redirect($_REQUEST['u']);
+}
+
+//dont allow people to be bitten twice
+if(user_already_recruited($user)) {
+ $facebook->redirect("index.php");
+}
+
+
+$infector= $_REQUEST['i'];
+if(!isset($infector)) {
+ $facebook->redirect("who.php");
+}
+
+if($_REQUEST['side'] == 'bucaneer') {
+ $type = "bucaneer";
+}
+else if($_REQUEST['side'] == 'corsair') {
+ $type = "corsair";
+}
+else if($_REQUEST['side'] == 'barbary') {
+ $type = "barbary";
+}
+else {
+ $type = get_team($infector);
+ //$type_name = get_type_name_for($infector);
+}
+
+
+if($infector == 0) {
+ $infector_name = "a $type_name";
+}
+
+else {
+ $infec = $facebook->api_client->users_getInfo($infector, array('name'));
+ $infector_name = $infec[0]['name'];
+}
+
+
+$re = $facebook->api_client->users_getInfo($user, array('name'));
+$name = $re[0]['name'];
+$gender = $re[0]['sex'];
+$country = $re[0]['current_location']['country'];;
+$zip = $re[0]['current_location']['zip'];;
+$age = $re[0]['birthday'];
+
+
+if($infector !=0) {
+ $body = "Avast! $name was recruited by $infector_name and is now a Pirate!";
+
+ //DEV
+ $template_bundle_id = 29631703987;
+ //PROD
+ //$template_bundle_id = 28511859241;
+
+ $tokens = array('images'=>array(array('src'=>'CHANGEME/images/flag_200.jpg', 'href'=>"CHANGEME/?i=$user")) );
+
+ $target_ids = array($infector);
+ //print_r($target_ids);
+ $body_general = '';
+
+ try {
+ $facebook->api_client->feed_publishUserAction( $template_bundle_id, json_encode($tokens) , $infector, $body_general);
+ }
+ catch(Exception $e) {
+ error_log("feed publish not successful for template $template_bundle_id for $user", 0);
+ }
+
+
+}
+else {
+ $body = "Avast! $name became a Pirate!";
+
+
+ //DEV
+ $template_bundle_id = 29633093987;
+ //PROD
+ //$template_bundle_id = 28520159241;
+
+ $tokens = array('images'=>array(array('src'=>'CHANGEME/images/flag_200.jpg', 'href'=>"CHANGEME/?i=$user")) );
+
+ $target_ids = array($infector);
+
+ $body_general = '';
+ try {
+ $facebook->api_client->feed_publishUserAction( $template_bundle_id, json_encode($tokens), NULL, $body_general);
+ }
+ catch(Exception $e) {
+ error_log("feed publish not successful for template $template_bundle_id for $user", 0);
+ }
+
+
+}
+$image_1 = "$base_url/images/flag_200.jpg";
+$image_1_link = "$facebook_canvas_url/?i=$user";
+$title = "became a Pirate Arr...";
+
+
+//$re2 = $facebook->api_client->feed_publishActionOfUser($title, $body, $image_1, $image_1_link);
+
+
+$sql = "select path from users where id = ?";
+$parent_path = $DB->GetOne($sql, array($infector));
+
+$session_key = $facebook->fb_params['session_key'];
+
+//insert the new user
+$sql = "insert into users (id, name, team, created_at, recruited_by, session_key, level_is_correct) values(?, ?, '$type', now(), $infector, ?, 1) on duplicate key update updated_at =now()";
+$result = $DB->Execute($sql, array($user, $name, $session_key));
+
+
+
+$path = $parent_path . "/" . $user;
+
+//echo "path is: $path ";
+
+//update the path based on the insert id and the parent
+$sql = "update users set path = '$path' where id = $user";
+$result = $DB->Execute($sql);
+
+//echo "update path result : ";
+//print_r($result);
+
+//print_r($_REQUEST);
+
+//increase_level_for_ancestors($user);
+$users_to_bump = explode('/', $parent_path);
+$users_to_bump = array_filter($users_to_bump);
+
+if ($users_to_bump && is_array($users_to_bump)) {
+ $where = array();
+ $ancestors = array();
+ foreach ($users_to_bump as $key => $fb_uid) {
+ // If we hit this user, then we're done with ancestors.
+ //shouldn't happen as using parent path only..
+ if ($fb_uid == $user) {
+ break;
+ }
+ $ancestors[] = $fb_uid;
+ $where[] = 'id = ?';
+
+ global $memcache; //delete users level from memcache so it gets recomputed after updating lvl
+ if($memcache) { //keep it in delete queue for 10 seconds so the followig update query can run
+ $s = $memcache->delete($fb_uid . ":l", 10);
+ log_levels($fb_uid, 'recruited user');
+
+ }
+
+ }
+ $sql = "update users set level = level + 1 where (". implode(' OR ', $where) .") AND level_is_correct = 1";
+
+
+
+ $DB->Execute($sql, $ancestors);
+
+}
+
+
+
+
+//post to parent's mini feed
+if($infector !=0) {
+ $sql = 'select session_key from users where id = ?';
+ $session_key = $DB->GetOne($sql, array($infector));
+
+ if (!empty($session_key)) {
+ $facebook_infector = new Facebook($api_key, $secret);
+ $facebook_infector->api_client->session_key = $session_key;
+
+ try {
+ $title = 'recruited to become a Pirate. Arrrrr...';
+ $result_infector = $facebook_infector->api_client->feed_publishActionOfUser($title, $body, $image_1, $image_1_link);
+ }
+ catch (FacebookRestClientException $fb_e) {
+
+ }
+ }
+ }
+
+
+
+$facebook->redirect('recruit.php?just-joined=1');
+
+?>
diff --git a/install_myspace.php b/install_myspace.php
new file mode 100644
index 0000000..eb53103
--- /dev/null
+++ b/install_myspace.php
@@ -0,0 +1,168 @@
+redirect("index.php");
+}
+
+ require_once('Space.php');
+ $key = 'CHANGEME';
+ $secret = 'CHANGEME';
+ //$print_r($user);
+ $s = new Space($key,$secret);
+ //print_r($s);
+
+
+
+
+
+
+try {
+ $re = $s->profile($user);
+}
+catch(Exception $e) {
+ //print_r($_REQUEST);
+ echo "Install Pirates to Play!
";
+ exit();
+}
+
+$infector= $_REQUEST['i'];
+if(!isset($infector)) {
+ //check for cookie
+ $pirates_referer = $_COOKIE['pirates_ref'];
+ if(isset($pirates_referer)) {
+ //check if this is a valid user
+ if(is_user_in_db($pirates_referer)) {
+ $infector = $pirates_referer;
+ }
+ else {
+ $facebook->redirect("pick_team.php");
+ }
+ }
+ else {
+ $facebook->redirect("pick_team.php");
+ }
+}
+
+
+//print_r($_REQUEST);
+
+//get path for the infector
+
+if($_REQUEST['side'] == 'bucaneer') {
+ $type = "bucaneer";
+}
+else if($_REQUEST['side'] == 'corsair') {
+ $type = "corsair";
+}
+else if($_REQUEST['side'] == 'barbary') {
+ $type = "barbary";
+}
+else if($infector != '' && $infector != 0) {
+ $type = get_team($infector);
+ //$type_name = get_type_name_for($infector);
+}
+
+
+
+if($infector == 0) {
+ $infector_name = "a $type_name";
+}
+
+else {
+ //print_r($user);
+ //$hProfile = $s->profile($infector);
+ $infector_name = 'unknown';
+ //$hProfile['displayname'];
+
+ //$infec = $facebook->api_client->users_getInfo($infector, array('name'));
+ //$infector_name = $infec[0]['name'];
+}
+
+
+//$re = $facebook->api_client->users_getInfo($user, array('name'));
+//$name = $re[0]['name'];
+//$gender = $re[0]['sex'];
+//$country = $re[0]['current_location']['country'];;
+//$zip = $re[0]['current_location']['zip'];;
+//$age = $re[0]['birthday'];
+
+
+$name = $re['displayname'];
+$gender = $re['gender'];$country = $re['US'];
+$zip = $re['zip'];
+$age = $re['age'];
+
+
+
+
+$sql = "select path from users where id = ?";
+$parent_path = $DB->GetOne($sql, array($infector));
+
+$session_key = 1; //$facebook->fb_params['session_key'];
+
+//insert the new user
+$sql = "insert into users (id, name, team, created_at, recruited_by, session_key, level_is_correct) values(?, ?, '$type', now(), $infector, ?, 1) on duplicate key update updated_at =now()";
+$result = $DB->Execute($sql, array($user, $name, $session_key));
+
+
+
+$path = $parent_path . "/" . $user;
+
+//echo "path is: $path ";
+
+//update the path based on the insert id and the parent
+$sql = "update users set path = '$path' where id = $user";
+$result = $DB->Execute($sql);
+
+//echo "update path result : ";
+//print_r($result);
+
+//print_r($_REQUEST);
+
+//increase_level_for_ancestors($user);
+$users_to_bump = explode('/', $parent_path);
+$users_to_bump = array_filter($users_to_bump);
+
+if ($users_to_bump && is_array($users_to_bump)) {
+ $where = array();
+ $ancestors = array();
+ foreach ($users_to_bump as $key => $fb_uid) {
+ // If we hit this user, then we're done with ancestors.
+ //shouldn't happen as using parent path only..
+ if ($fb_uid == $user) {
+ break;
+ }
+ $ancestors[] = $fb_uid;
+ $where[] = 'id = ?';
+
+ global $memcache; //delete users level from memcache so it gets recomputed after updating lvl
+ if($memcache) { //keep it in delete queue for 10 seconds so the followig update query can run
+ $s = $memcache->delete($fb_uid . ":l", 10);
+ log_levels($fb_uid, 'recruited user');
+
+ }
+
+ }
+ $sql = "update users set level = level + 1 where (". implode(' OR ', $where) .") AND level_is_correct = 1";
+
+
+
+ $DB->Execute($sql, $ancestors);
+
+}
+
+
+
+
+
+header('Location: index.php?just-joined=1');
+
+?>
diff --git a/island.php b/island.php
new file mode 100644
index 0000000..a41c85e
--- /dev/null
+++ b/island.php
@@ -0,0 +1,95 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+print dashboard();
+?>
+
+
+
+Arrrr...What do ye want to do?");
+
+?>
+
+
+
+
+
+
+Buried treasure can't be stolen!
+
+
+
+
+Look for booty on this island
+
+
+
+
+
+Leave a dynamite/monkey booby trap
+
+
+
+
+
+Arrr....
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/island_booty.php b/island_booty.php
new file mode 100644
index 0000000..1085fce
--- /dev/null
+++ b/island_booty.php
@@ -0,0 +1,350 @@
+ rand(5,10)) {
+ $rand = rand(1,10);
+ if($rand != 2) {
+ $booty = "some gold bars";
+ $booty_pic = $gold_image;
+ $stuff_id = 2;
+ }
+ }
+
+}
+
+else if($ra < 55) { $booty = "some gold bars";
+ $booty_pic = $gold_image;
+ $stuff_id = 2;
+
+}
+else if($ra < 80) {
+ $booty = "a message in a bottle";
+ $booty_pic = $message_in_a_bottle_image;
+ $stuff_id = 3;
+}
+else if($ra < 105) {
+ $booty = "some dynamite";
+ $booty_pic = $dynamite_image;
+ $stuff_id = 4;
+
+}
+else if($ra < 120) {
+ $booty = "a pirate flag";
+ $booty_pic = $flag_image;
+ $stuff_id = 5;
+
+}
+else if($ra < 125) {
+ $booty = "a monkey";
+ $booty_pic = $monkey_200;
+ $stuff_id = 7;
+
+}
+else if($ra < 158) {
+ $booty = "a pistol";
+ $booty_pic = $pistol_350;
+ $stuff_id = 8;
+}
+else if($ra < 170) {
+ $booty = "a sword";
+ $booty_pic = $sword_350;
+ $stuff_id = 10;
+}
+else if($ra < 180) {
+ $booty = "a parrot";
+ $booty_pic = $parrot_200;
+ $stuff_id = 11;
+}
+else if($ra < 190) {
+ $booty = "some rum";
+ $booty_pic = $rum_200;
+ $stuff_id = 9;
+}
+else if($ra < 212) {
+ $booty = "a bomb";
+ $booty_pic = $bomb_image;
+ $stuff_id = 6;
+
+}
+else if($ra < 530) {
+ //give possibly more coins if you traveled real far
+ if($miles_traveled > 10 && $miles_traveled < 100) {
+ $ra = rand($miles_traveled, 80);
+
+ //rarely give them 5x or 10x bonus on coins
+ $ra2 = rand(1,50000);
+ if($ra2 == 125) {
+ $ra = $ra * 3;
+ }
+ else if($ra2 == 200) {
+ $ra = $ra * 6;
+ }
+
+ }
+
+ else {
+ $ra = rand(10, 70);
+ }
+
+ $pvp_toggle = $memcache->get($user . 'pvp');
+ // echo "PVP TOGGLE $pvp_toggle";
+ //print "pvp toggle $pvp_toggle";
+ if($pvp_toggle != 'off') {
+ // echo 'COOL';
+ $ra = $ra + rand(10,50);
+
+ if($ra < 70) {
+ $ra = rand(70,100);
+ }
+
+
+
+ //rarely give them 5x or 10x bonus on coins
+ $ra2 = rand(1,1000);
+ if($ra2 == 125) {
+ $ra = $ra * 3;
+ }
+ else if($ra2 == 200) {
+ $ra = $ra * 6;
+ }
+
+
+
+ }
+
+
+ $booty = "$ra pirate coins";
+ $booty_pic = $pirate_coins_image;
+ $found_coins = TRUE;
+}
+else {
+ $booty = "nothing";
+}
+if($booby_trap) {
+ //is there a booby trap for this user
+ $dynamite = is_dynamite_set($user);
+ //echo 'dynamite: ';
+ //echo $dynamite;
+ if($dynamite < 1) { //no dynamite for this user
+ $ra = rand(3, 100);
+
+
+ $found_coins = true; // no booty or coins found they blew up
+ //$booty = "nothing";
+ $booty = "$ra pirate coins";
+ $booty_pic = $pirate_coins_image;
+ $stuff = 'nothing';
+ }
+ else {
+ $user_blown_up = blow_up_user($user);
+ $booty = "nothing"; // no booty or coins found they blew up
+ $found_coins = false;
+
+ //assumes there is at least 1 dynamite for this user
+ //unsets dynamite set for this user and takes away 20% of their highest item collection and 10% of their next highest
+
+ }
+
+}
+
+
+
+if($found_coins) {
+ $sql = 'update users set coin_total = coin_total + ? where id = ?';
+ $DB->Execute($sql, array($ra, $user));
+ $action = 'island coins';
+ log_coins($user, $ra, $action);
+
+}
+else if($booty != 'nothing' && $stuff != 'nothing') {
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1';
+ $DB->Execute($sql, array($user, $stuff_id));
+}
+
+?>
+
+
+
+
+
+You found $booty");
+?>
+
+
+
+
+
+GetOne('select last_treasure_mile from users where id = ?', array($user));
+
+
+$map_count = get_map_count($user);
+
+$already_quested = $memcache->get($user . 'quested');
+
+$pvp_off = $memcache->get($user . 'pvp');
+//echo "pvp off $pvp_off";
+$weekly_miles = $DB->GetOne('select weekly_miles from users where id = ?', array($user));
+
+$crew_count = get_crew_count($user);
+
+$sails = get_sails($user);
+
+//echo "sails $sails";
+if($sails < 25) {
+ $s = false;
+}
+else if($sails > 150) {
+ $s = true;
+}
+else {
+ $t = rand(0,1);
+ if($t == 0) {
+ $s = true;
+ }
+ else {
+ $s = false;
+ }
+}
+
+//$sails = 350;
+//$weekly_miles = 100;
+//$s =true;
+//$already_quested = 0;
+
+if($map_count > 0 && $already_quested != 1 && $pvp_off != 'off' && $weekly_miles > 50 && $crew_count > 2 && $s == true) {
+//if(true) {
+//echo $weekly_miles;
+update_action($user, 'island_treasure');
+//print_r($map_count);
+
+
+if($map_count == 1) {
+ $map_text = 'map';
+}
+else {
+ $map_text = 'maps';
+}
+?>
+
+
+
+Yer crew found a spot on this island matching one of yer maps!!
+
+
+
+
+
+
+
+
+
+
+ If you go on the quest, your treasure map will be destroyed!
+ Watch out for enemies - if you can't defeat them you won't get the treasure and won't get yer map back!
+ Stock up on ham and rum before going on the quest!
+
+
+
+
+
+
+
+
Do you want to go >on a quest for treasure?
+
+
Use treasure maps to find BOOTY ( left)
+
+
+
ARRR! You searched around the island but didn't find any booty!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+*/
+
+print adsense_468($user);
+
+?>
+
+
+
+
diff --git a/item_action.php b/item_action.php
new file mode 100644
index 0000000..2082d2f
--- /dev/null
+++ b/item_action.php
@@ -0,0 +1,69 @@
+redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$level = get_level($user);
+
+//$how_many_bombs = get_how_many_bombs($user);
+
+//print dashboard();
+
+$item = $_REQUEST['item'];
+
+if($item == "rum") {
+
+ $action = get_current_action($user);
+ $no_captcha = get_no_captcha();
+ $pass = false;
+ if (in_array($user, $no_captcha )) {
+ $pass = true;
+ }
+ //echo "action $action pass $pass";
+ //exit();
+ if($action != "captcha_complete" && $pass == false) {
+ update_action($user, "captcha");
+ $facebook->redirect("$facebook_canvas_url/captcha_page.php?page=item_action.php&item=rum");
+ }
+ else { //this means they've completed the captcha
+ update_action($user, "NULL");
+ }
+
+ $success = drink_rum($user);
+
+ if($success == true) {
+
+ //echo 'hello';
+ $facebook->redirect("index.php?msg=drank-rum");
+ }
+ else {
+ $facebook->redirect("index.php");
+ }
+}
+else if($item == "ham") {
+ $success = eat_ham($user);
+
+ if($success == true) {
+ $facebook->redirect("index.php?msg=eat-ham");
+ }
+ else {
+ $facebook->redirect("index.php");
+ }
+}
+else {
+ $facebook->redirect("index.php");
+}
+
+?>
\ No newline at end of file
diff --git a/item_exchange.php b/item_exchange.php
new file mode 100644
index 0000000..5d3dd9c
--- /dev/null
+++ b/item_exchange.php
@@ -0,0 +1,526 @@
+redirect("you_were_bombed.php");
+}
+$was_attacked = get_was_attacked($user);
+if($was_attacked != "" && $was_attacked != 0) {
+ $facebook->redirect("you_were_attacked.php");
+}
+
+print dashboard();
+
+$action = $_REQUEST['action'];
+$item = $_REQUEST['item'];
+$num = $_REQUEST['num'];
+
+$item_count = 30; //if we have more items than this, increase this #
+
+if(isset($_POST['buy'])) {
+ if(isset($_POST['id'])) {
+ $uid = $_POST['id'];
+ $success = complete_buy_action($user, $uid);
+ if($success == "no coins") {
+ echo_error("Not enough coins to purchase that item.");
+ }
+ else if($success == "fail") {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ else {
+ echo_success("Item successfully purchased!");
+ }
+ $action = 'buy';
+ }
+}
+
+if(isset($_POST['sell'])) {
+ if(isset($_POST["u"])) {
+ if(isset($_POST["price"])) {
+ $price = $_POST["price"];
+ if($price < 1) {
+ $price = 1;
+ }
+ if($price > 1000) {
+ $price = 1000;
+ }
+
+ $item = $_POST["u"];
+ $action = 'sale_confirmation';
+ }
+ }
+}
+
+if(isset($_POST['sale_declined'])) {
+ $action = 'sell';
+}
+
+if(isset($_POST['update_declined'])) {
+ $action = 'manage';
+}
+
+if(isset($_POST['sale_confirmation'])) {
+ if(isset($_POST['u'])) {
+ if(isset($_POST['price'])) {
+ $price = $_POST['price'];
+ $item = $_POST['u'];
+ if($price < 1) {
+ $price = 1;
+ }
+ if($price > 1000) {
+ $price = 1000;
+ }
+ $price_to_pay = ceil($price * .05);
+ if(get_is_item_owned($user, $item)) {
+ $coin_total = get_coin_total($user);
+ if($price_to_pay > $coin_total) {
+ echo_error("Not enough coins to list that item.");
+ }
+ else {
+ $new_coin_total = $coin_total - $price_to_pay;
+ if($new_coin_total < 0) {
+ $new_coin_total = 0;
+ }
+ set_coins($user, $new_coin_total);
+ log_coins($user, -$price_to_pay, 'item exchange listing fee');
+ sell_item($user, $item, $price);
+ echo_success("Your item is posted!
It will appear for sale shortly.");
+ }
+ }
+ else {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ $action = 'sell';
+ }
+ }
+}
+
+if(isset($_POST['manage_update'])) {
+ if(isset($_POST['u'])) {
+ if(isset($_POST['price'])) {
+ $price = $_POST['price'];
+ if($price < 1) {
+ $price = 1;
+ }
+ $uid = $_POST['u'];
+ $item = $_POST['id'];
+ $action = 'update_confirmation';
+ }
+ }
+}
+
+if(isset($_POST['manage_delete'])) {
+ if(isset($_POST['u'])) {
+ $uid = $_POST['u'];
+ if(get_is_owned($user, $uid)) {
+ $success = delete_sell_item($user, $uid, true);
+ if($success == false) {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ else {
+ echo_success("Item sale cancelled!");
+ }
+ }
+ else {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ }
+}
+
+if(isset($_POST['update_confirmation'])) {
+ if(isset($_POST['u'])) {
+ if(isset($_POST['price'])) {
+ $price = $_POST['price'];
+ $uid = $_POST['id'];
+ if($price < 1) {
+ $price = 1;
+ }
+ if(get_is_owned($user, $uid)) {
+ $price_to_pay = ceil($price * .05);
+ $coin_total = get_coin_total($user);
+ if($price_to_pay > $coin_total) {
+ echo_error("Not enough coins to update the listing!");
+ }
+ else {
+ $new_coin_total = $coin_total - $price_to_pay;
+ if($new_coin_total < 0) {
+ $new_coin_total = 0;
+ }
+ log_coins($user, -$price_to_pay, 'item exchange listing fee');
+ set_coins($user, $new_coin_total);
+ //check to see if it's in indexing string, if not- do not allow them to update! (hack)
+ $stuff_id = get_stuff_id_from_uid($user, $uid);
+ if($stuff_id != false) {
+ $success = delete_sell_item($user, $uid, true);
+ if($success == true) {
+
+ //print "user has item: ";
+ //print user_has_item($user, $stuff_id);
+
+ $sale_id = sell_item($user, $stuff_id, $price);
+ update_memcache_sell_item_indexing($user, $sale_id, false, $price, false);
+ $success = update_db_and_memcache_buying($user, $sale_id);
+ if($success == false) {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ else {
+ echo_success("Your sale has been updated!
It will appear for sale shortly.");
+ }
+ }
+ else {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ }
+ else {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ }
+ }
+ else {
+ echo_error("The item doesn't exist. It was probably purchased by someone else!");
+ }
+ $action = 'manage';
+ }
+ }
+}
+
+$team = get_team($user);
+
+$pirates_selling = 932;
+$total_items = 3943;
+?>
+
+
+
Welcome to the Trading Post!
+
+
+
+ />
+ />
+ />
+ />
+
+
+
+
+
+
+
+ Items for sale:
+
+
+
+
+
+ Seller
+ Time Left
+ Sale Price
+
+
+
+
+
+ count($buy_array)) {
+ $end = count($buy_array);
+ }
+
+ for($i = $beginning; $i < $end; $i++) {
+ $price = get_from_memcache("b:" . $buy_array[$i] . ":" . $item . ":p");
+ $created_at = get_from_memcache("b:" . $buy_array[$i] . ":" . $item . ":ca");
+ $sell_user = get_from_memcache("b:" . $buy_array[$i] . ":" . $item . ":u");
+
+ //only display if we can find all the stuff
+ if($price != false and $created_at != false and $sell_user != false) {
+ $team_name = ucwords(get_team($sell_user));
+ echo "
+
+
+ ";
+ echo time_left_of_24hours($created_at);
+ echo "
+ $price gold
+
+
+ ";
+ }
+ }
+ }
+ else {
+ echo "There are currently no items for sale.";
+ }
+ ?>
+
+
+
+
+
+
+ 0) { ?><- Previous
+ 0 and count($buy_array) > $end) { echo " | "; } ?>
+ $end) { ?>Next ->
+
+
+
+
+
+
+ Item
+ Sell Qty
+ Lowest Price
+ Selling Price
+
+
+
+
+ $value) {
+ $stuff_id = $value['stuff_id'];
+ $booty_data = get_booty_data_from_id($stuff_id);
+
+ $count = $value['how_many'];
+ if($count != 0) {
+ echo "
+
+ $booty_data[0] x$count
+ x1
+ ";
+ $low_price = lowest_buy_price($user, $stuff_id);
+ if($low_price == 0 or $low_price == false) {
+ echo "Unknown";
+ $low_price = 50;
+ } else {
+ echo $low_price . " gold";
+ }
+ echo "
+
+
+ ";
+ }
+ }
+
+ ?>
+
+
+
+
+
+
+ Confirmation
+
+
+ Item
+ Sell Qty
+ Selling Price
+ Posting Fee 5%
+
+
+
+
+
+
+ x1
+ gold
+ gold
+
+
+
+ You have: coins coins buried
+
+
+
+ = ceil($price * .05)) { ?>
+
+
+
+
+ You do not have enough coins to pay the posting fee.Dig up some coins or Cancel
+
+
+
+
+
+
+
+
+
+
+ Item
+ Time Left
+ Price
+
+
+
+ ";
+ if($indexing_string == false) {
+ $use_item_array = true;
+ $return_array = create_memcache_sell_items_from_db($user);
+ $indexing_string = $return_array[1];
+// echo "index string rebuild: " . $indexing_string . "
";
+ $item_array = $return_array[0];
+// echo "count rebuild: " . count($item_array) . "
";
+ }
+
+ if($indexing_string != "") {
+ $indexing_string_array = explode(",", $indexing_string);
+ }
+ else {
+ echo "
You currently have no active sales. ";
+ }
+ //echo "index string array count: " . count($indexing_string_array) . "
";
+ //print_r($indexing_string_array);
+
+ for($i = 0; $i < count($indexing_string_array); $i++) {
+ if($use_item_array == false) {
+ $stuff_id = get_sell_item_result($user, ":silsi", $indexing_string_array[$i], $use_item_array, $item_array);
+ }
+ if($stuff_id == false or $use_item_array == true) {
+ if($use_item_array == false) {
+ $return_array = create_memcache_sell_items_from_db($user);
+ $item_array = $return_array[0];
+ }
+ $use_item_array = true;
+ $stuff_id = get_sell_item_result($user, "stuff_id", $i, $use_item_array, $item_array);
+ }
+ if($use_item_array == false) {
+ $price = get_sell_item_result($user, ":silp", $indexing_string_array[$i], $use_item_array, $item_array);
+ }
+ if($price == false or $use_item_array == true) {
+ if($use_item_array == false) {
+ $return_array = create_memcache_sell_items_from_db($user);
+ $item_array = $return_array[0];
+ }
+ $use_item_array = true;
+ $price = get_sell_item_result($user, "price", $i, $use_item_array, $item_array);
+ }
+ if($use_item_array == false) {
+ $created_at = get_sell_item_result($user, ":silca", $indexing_string_array[$i], $use_item_array, $item_array);
+ }
+ if($created_at == false or $use_item_array == true) {
+ if($use_item_array == false) {
+ $return_array = create_memcache_sell_items_from_db($user);
+ $item_array = $return_array[0];
+ }
+ $use_item_array = true;
+ $created_at = get_sell_item_result($user, "created_at", $i, $use_item_array, $item_array);
+ }
+
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+ Trading Post Discussion Board
+
+
+
+
+
+
+
Go back to sea -adventure, danger and treasure await
+
+
+
+
diff --git a/leaderboard.php b/leaderboard.php
new file mode 100644
index 0000000..debcce7
--- /dev/null
+++ b/leaderboard.php
@@ -0,0 +1,693 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db == 0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+//get the selected tab
+$action = $_REQUEST['action'];
+
+if(!isset($action)) {
+ $action = "weekly";
+}
+
+function get_time_left_weekly() {
+ global $memcache, $DB;
+
+/* if($memcache) {
+ $last_weekly_date = $memcache->get("weekly_date:");
+ if(!is_bool($last_weekly_date) and $last_weekly_date != "") {
+ time_left_of_1week($last_weekly_date);
+ return;
+ }
+ } */
+
+ $sql = "select generic_date from generic_data where unique_identifier = 'weekly_refresh_date'";
+ try {
+ $last_weekly_date = $DB->GetOne($sql);
+ } catch (Exception $e) { return false; }
+
+ if(is_bool($last_weekly_date)) {
+ return false;
+ }
+
+/* if($memcache) {
+ $memcache->set("weekly_date:", $last_weekly_date, false, 3600);
+ }*/
+
+ //this echo's it out
+ time_left_of_1week($last_weekly_date);
+}
+
+function get_data_chunk($leaderboard, $chunk_number) {
+ global $memcache, $outlaws_memcache, $DB;
+
+ if($memcache) {
+ if($leaderboard == "overall") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrovrall");
+ } else if($leaderboard == "mostcoins") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins");
+ } else if($leaderboard == "level") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl");
+ } else if($leaderboard == "buccaneer_overall") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrovrall_buc");
+ } else if($leaderboard == "buccaneer_mostcoins") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins_buc");
+ } else if($leaderboard == "buccaneer_level") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl_buc");
+ } else if($leaderboard == "corsair_overall") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrovrall_cor");
+ } else if($leaderboard == "corsair_mostcoins") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins_cor");
+ } else if($leaderboard == "corsair_level") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl_cor");
+ } else if($leaderboard == "barbary_overall") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrovrall_bar");
+ } else if($leaderboard == "barbary_mostcoins") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins_bar");
+ } else if($leaderboard == "barbary_level") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl_bar");
+ } else if($leaderboard == "weekly_miles") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrweeklymiles");
+ } else if($leaderboard == "weekly_money") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrweeklymoney");
+ } else if($leaderboard == "weekly_money") {
+ $person_array = $memcache->get($chunk_number . ":" . $outlaws_memcache . ":ldrweeklylevel");
+ }
+
+ if($person_array != false and $person_array != "") {
+ return unserialize($person_array[0]['array_data']);
+ }
+ }
+
+ if($leaderboard == "overall") {
+ $sql = "select array_data from leader_overall where uid = ?";
+ } else if($leaderboard == "mostcoins") {
+ $sql = "select array_data from leader_most_coins where uid = ?";
+ } else if($leaderboard == "level") {
+ $sql = "select array_data from leader_highest_level where uid = ?";
+ } else if($leaderboard == "buccaneer_overall") {
+ $sql = "select array_data from leader_buccaneer_overall where uid = ?";
+ } else if($leaderboard == "buccaneer_mostcoins") {
+ $sql = "select array_data from leader_buccaneer_most_coins where uid = ?";
+ } else if($leaderboard == "buccaneer_level") {
+ $sql = "select array_data from leader_buccaneer_highest_level where uid = ?";
+ } else if($leaderboard == "corsair_overall") {
+ $sql = "select array_data from leader_corsair_overall where uid = ?";
+ } else if($leaderboard == "corsair_mostcoins") {
+ $sql = "select array_data from leader_corsair_most_coins where uid = ?";
+ } else if($leaderboard == "corsair_level") {
+ $sql = "select array_data from leader_corsair_highest_level where uid = ?";
+ } else if($leaderboard == "barbary_overall") {
+ $sql = "select array_data from leader_barbary_overall where uid = ?";
+ } else if($leaderboard == "barbary_mostcoins") {
+ $sql = "select array_data from leader_barbary_most_coins where uid = ?";
+ } else if($leaderboard == "barbary_level") {
+ $sql = "select array_data from leader_barbary_highest_level where uid = ?";
+ } else if($leaderboard == "weekly_miles") {
+ $sql = "select array_data from leader_weekly_miles where uid = ?";
+ } else if($leaderboard == "weekly_money") {
+ $sql = "select array_data from leader_weekly_money where uid = ?";
+ } else if($leaderboard == "weekly_level") {
+ $sql = "select array_data from leader_weekly_level where uid = ?";
+ }
+
+ try {
+ $person_array = $DB->GetArray($sql, array($chunk_number + 1));
+ } catch (Exception $e) { return false; }
+ if($person_array == false or count($person_array) == 0) {
+ return false;
+ }
+
+ if($memcache) {
+ if($leaderboard == "overall") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrovrall", $person_array);
+ } else if($leaderboard == "mostcoins") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins", $person_array);
+ } else if($leaderboard == "level") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl", $person_array);
+ } else if($leaderboard == "buccaneer_overall") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrovrall_buc", $person_array);
+ } else if($leaderboard == "buccaneer_mostcoins") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins_buc", $person_array);
+ } else if($leaderboard == "buccaneer_level") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl_buc", $person_array);
+ } else if($leaderboard == "corsair_overall") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrovrall_cor", $person_array);
+ } else if($leaderboard == "corsair_mostcoins") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins_cor", $person_array);
+ } else if($leaderboard == "corsair_level") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl_cor", $person_array);
+ } else if($leaderboard == "barbary_overall") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrovrall_bar", $person_array);
+ } else if($leaderboard == "barbary_mostcoins") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrmstcoins_bar", $person_array);
+ } else if($leaderboard == "barbary_level") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrhghlvl_bar", $person_array);
+ } else if($leaderboard == "weekly_miles") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrweeklymiles", $person_array);
+ } else if($leaderboard == "weekly_money") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrweeklymoney", $person_array);
+ } else if($leaderboard == "weekly_level") {
+ $memcache->set($chunk_number . ":" . $outlaws_memcache . ":ldrweeklylevel", $person_array);
+ }
+ }
+
+ return unserialize($person_array[0]['array_data']);
+}
+
+function print_top_person($user_id, $rank, $leaderboard) {
+ global $facebook_canvas_url, $user;
+
+ if($rank == 1) {
+ $rank_color = 'red';
+ } else if($rank == 2) {
+ $rank_color = 'blue';
+ } else if($rank == 3) {
+ $rank_color = 'green';
+ } else {
+ $rank_color = 'black';
+ }
+?>
+
+
+
+
+
+
+
+ 999) { ?>
+
+ 99) { ?>
+
+
+
+
+
+ >
+
+
+
+
+
+
+
+ Level:
+ Gold:
+
+ Level:
+ Gold:
+
+ Level:
+ Gold:
+
+ Level:
+ Miles:
+
+ Level:
+ Coins:
+
+ Level:
+ Gained:
+
+ Pirate Since
+
+
+
+
+
+
+get($user . ":" . $outlaws_memcache . ":ldrnotpos");
+ } else if($leaderboard == 'richest') {
+ $chunk_position = $memcache->get($user . ":" . $outlaws_memcache . ":ldrrichpos");
+ }
+ if($chunk_position === false or $chunk_position == "" or $chunk_position == "NULL" or $chunk_position === NULL) {
+ return false;
+ } else {
+ //can return 0 so watch our for testing for false
+ return $chunk_position;
+ }
+ } else {
+ return false;
+ }
+}*/
+
+$leaderboard_value = $_REQUEST['value'];
+if(!isset($leaderboard_value) or $leaderboard_value == "") {
+ if($action == "weekly") {
+ $leaderboard_value = "weekly_miles";
+ } else if($action == "overall") {
+ $leaderboard_value = "overall";
+ }
+}
+$screen_number = $_REQUEST['page_num'];
+if(!isset($screen_number)) {
+ $screen_number = 0;
+}
+
+print dashboard();
+?>
+
+
+
+
+
Leaderboards
+ Are you on top?
+ real-time stats rank refreshed hourly
+
+
+
+
+
+
+
+ />
+ />
+ />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ";
+ //print rmx_120($user);
+ ?>
+
+
+
+ ";
+ /*$leaderboard_position = get_leaderboard_user_postion($user, $leaderboard_value);
+
+ if(!is_bool($leaderboard_position)) {
+ echo "You are on page " . ($leaderboard_position + 1) . " of this leaderboard! ";
+ }*/
+ if($action == "weekly") {
+ echo "Week Countdown: ";
+ get_time_left_weekly();
+ echo " ";
+ }
+
+ echo "";
+ if($screen_number != 0) {
+ echo "<- Previous | ";
+ }
+
+ if($leaderboard_found) {
+ echo "Next -> ";
+ }
+ echo "
";
+ ?>
+
+
+
Leaderboard entry not found! The leaderboard may be recalculating. Check back in 5 minutes! ";
+ $leaderboard_found = false;
+ }
+ if($leaderboard_found) {
+ echo "
";
+ for($i = 0; $i < count($data_array); $i++) {
+ echo "";
+ if($screen_number == 0 and $i == 0) {
+ print_top_person($data_array[$i]['id'], 1, $leaderboard_value);
+ } else if($screen_number == 0 and $i == 1) {
+ print_top_person($data_array[$i]['id'], 2, $leaderboard_value);
+ } else if($screen_number == 0 and $i == 2) {
+ print_top_person($data_array[$i]['id'], 3, $leaderboard_value);
+ } else {
+ print_top_person($data_array[$i+ ($num_per_chunk * $screen_number)]['id'], $i + ($num_per_chunk * $screen_number) + 1, $leaderboard_value);
+ }
+ echo "
";
+ }
+ echo "
";
+ }
+ ?>
+
+
+ <- Previous | ";
+ }
+
+ if($leaderboard_found) {
+ echo "
Next -> ";
+ }
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+ Pirate Leaderboard
+
+
+
+
+
+
Last Weeks Winners
+
+
First Place Winners
+
+
+
+
+
Second Place Winners
+
+
+
+
+
Third Place Winners
+
+
+
+
+
+
+
+
+
diff --git a/leave_dynamite.php b/leave_dynamite.php
new file mode 100644
index 0000000..93c2602
--- /dev/null
+++ b/leave_dynamite.php
@@ -0,0 +1,31 @@
+('insert into booby_traps () values()');
+?>
+
+
+
+ Ahoy! You left a dynamite booby trap! You'll level up when it blows up another pirate!
+
+Your monkey-dynamite team will wait here until a pirate searches for some booty. When they blow someone up you'll level up!
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/leave_dynamite_action.php b/leave_dynamite_action.php
new file mode 100644
index 0000000..292eb6f
--- /dev/null
+++ b/leave_dynamite_action.php
@@ -0,0 +1,28 @@
+redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$level = get_level($user);
+
+//$how_many_bombs = get_how_many_bombs($user);
+
+//print dashboard();
+
+$friend_selector_id = $_REQUEST['friend_selector_id'];
+$facebook->redirect("leave_dynamite_for.php?id=$friend_selector_id");
+//print $friend_selector_id;
+
+?>
+
diff --git a/leave_dynamite_for.php b/leave_dynamite_for.php
new file mode 100644
index 0000000..828e109
--- /dev/null
+++ b/leave_dynamite_for.php
@@ -0,0 +1,221 @@
+
+
+
+
+api_client->friends_list;
+
+if($type == "corsair") {
+ $ship_image_blue = $ship_corsair_blue_image;
+}
+else if($type == 'buccaneer') {
+ $ship_image_blue = $ship_bucaneer_blue_image;
+}
+else if ($type == "barbary") {
+ $ship_image_blue = $ship_barbary_blue_image;
+}
+
+//$r = explore($user);
+//echo "r; $r";
+
+
+
+if($_REQUEST['sent'] == "1") {
+ $msg = "Yer Pirate invitations have been sent!";
+}
+
+
+if($_REQUEST['msg'] == "send-limit") {
+ $msg = "Your requests were not sent. You're over the limit for today. Try again later. :(";
+}
+
+$throw_at = $_REQUEST['id'];
+if(empty($throw_at)) {
+ $facebook->redirect("$facebook_canvas_url/leave_dynamite_pick.php");
+}
+
+$is_friend = false;
+foreach ($app_friends as $value)
+{
+ if($value == $throw_at) {
+ $is_friend = true;
+ }
+}
+if($is_friend == false) {
+ update_action($user, "NULL");
+ $facebook->redirect("$facebook_canvas_url/index.php?msg=hack");
+}
+
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+//redirect_to_index_if_not($user, "dynamite");
+
+print dashboard();
+
+
+?>
+
+
+
+redirect("index.php");
+}
+
+?>
+
+
+
+
+
+
+
+
+
+ Launch a monkey - dynamite attack!
+
+
+
+ Leave a monkey - dynamite trap!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Pick someone else! (Arrr....)
+
+
+
+
+
+
+
+
+
+
+Send yer monkey to attack . Your monkey will go after looting you some coins.
+
+
+
+
+
+When visits this island there's a chance 'll set off the trap! Their ship will explode, and your monkey will collect some BOOTY!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ coins
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/leave_dynamite_pick.php b/leave_dynamite_pick.php
new file mode 100644
index 0000000..f6aed9b
--- /dev/null
+++ b/leave_dynamite_pick.php
@@ -0,0 +1,129 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+//redirect_to_index_if_not($user, "bomb");
+
+print dashboard();
+
+
+?>
+
+
+
+redirect("index.php");
+}
+
+?>
+
+
+
+
+
+
+
+
+ Leave a monkey - dynamite trap!
+
+
+
+
+
+
+
+ ( dynamite left)
+
+
+
+Type a friends name to leave a dynamite booby trap for them.
+
+
+When they set it off, they'll explode and lose some of their booty.
+ Your monkey will wait here and carry some of the pillaged booty back to you!
+
+
+
+
+
+
+
+
+
+
+
+ ( left)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/leave_the_dynamite_action.php b/leave_the_dynamite_action.php
new file mode 100644
index 0000000..0266f0c
--- /dev/null
+++ b/leave_the_dynamite_action.php
@@ -0,0 +1,53 @@
+redirect("index.php");
+ //print_r($_REQUEST);
+}
+
+
+//print_r($_REQUEST);
+
+ $body = " left a dynamite trap for . Arrrrr... .";
+
+//$image_1 = "$base_url/images/flag_200.jpg";
+//$image_1_link = "$facebook_canvas_url/?i=$user";
+$title = "played with dynamite .";
+
+
+//for the user
+try {
+
+$re2 = $facebook->api_client->feed_publishActionOfUser($title, $body);
+}
+ catch (FacebookRestClientException $fb_e) {
+
+ }
+
+//for the user being dynamited
+
+$sql = 'select session_key from users where id = ?';
+$session_key = $DB->GetOne($sql, array($to_id));
+
+
+$query = "INSERT INTO booby_traps (from_id, to_id, created_at) VALUES ('". $user . "', '" . $to_id . "', now())";
+ $DB->Execute($query);
+
+
+
+$facebook->redirect("$facebook_canvas_url/left_dynamite.php?to=$to_id&sent=1");
+
+//}
+
+
+
+
+ ?>
\ No newline at end of file
diff --git a/left_dynamite.php b/left_dynamite.php
new file mode 100644
index 0000000..87fc221
--- /dev/null
+++ b/left_dynamite.php
@@ -0,0 +1,98 @@
+redirect("$facebook_canvas_url/install.php");
+}
+
+$to_user = $_REQUEST['to'];
+
+$dynamite_total = get_dynamite_count($user);
+$monkey_total = get_monkey_count($user);
+
+$level = get_level($user);
+
+
+//print "bomb is $bomb_total";
+//print "gold is $gold";
+
+
+//threw_dynamite.php?sent=1&auth_token=85000cdeb643344d058a1ab7e85f842f
+//check for existance of sent=1 and auth_token, and number of bombs, then increment users level
+//and decrement the users bomb count
+//take the gold from the $to and add it to the current user
+
+$sent = $_REQUEST['sent'];
+//$auth_token = $_REQUEST['auth_token'];
+
+
+if($dynamite_total < 1 || $monkey_total < 1 || !$sent) {
+ $facebook->redirect("index.php");
+}
+
+
+else {
+
+ set_dynamite_total($user, $dynamite_total - 1);
+ set_monkey_total($user, $monkey_total - 1);
+
+ $gold = get_coin_total($to_user);
+
+ if($gold < 1) {
+ $gold = rand(1,50);
+ }
+
+ if($gold > 50) {
+ $gold = 50;
+ }
+
+ $to_id_team = get_team($to_user);
+
+ if(empty($to_id_team)) {
+ $level_up = lower_level_up($user);
+ if($level_up) {
+ log_levels($user, 'dynamite level up', $to_user);
+ }
+
+ $gold = rand(1,50);
+
+
+ set_coins($user, get_coin_total($user) + $gold); //landlubber give em coins now
+
+ log_coins($user, $gold, 'dynamited landlubber', $to_user);
+
+ $facebook->redirect("index.php?msg=left-dynamite&gold=$gold&to=$to_user&level_up=$level_up");
+
+ }
+else {
+ //pirate, wait for dynamite to blow up
+ $facebook->redirect("index.php?msg=left-dynamite-for-pirate&to=$to_user");
+
+}
+
+
+}
+
+
+//$to_id = $_REQUEST['to'];
+
+
+
+//print_r($_REQUEST);
+
+$facebook->redirect("index.php?msg=left-dynamite&gold=$gold&to=$to_user&level_up=$level_up");
+
+//print $friend_selector_id;
+
+?>
+
diff --git a/level_up.php b/level_up.php
new file mode 100644
index 0000000..d7db57a
--- /dev/null
+++ b/level_up.php
@@ -0,0 +1,347 @@
+ 3000) {
+
+$level_upgraded = $memcache->get($user . 'upgraded_level');
+
+if($level_upgraded == 1) {
+ $facebook->redirect('pirate_market.php?msg=wait-to-upgrade');
+}
+
+}
+
+if($_REQUEST['sent'] == "1") {
+ $msg = "Yer Pirate invitations have been sent!";
+}
+
+
+if($_REQUEST['msg'] == "send-limit") {
+ $msg = "Your requests were not sent. You're over the limit for today. Try again later. :(";
+}
+
+$in = $_REQUEST['i'];
+if(isset($in)) {
+ $facebook->redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+if($coin_total < 0) {
+ $facebook->redirect('level_upgrade.php');
+}
+
+$buried_coin_total = get_coin_total_buried($user);
+
+$my_level = get_level($user);
+
+$upgrades = get_upgrades($user);
+
+//print_r($upgrades);
+//$cannon_level = $upgrades
+
+foreach($upgrades as $key=>$value) {
+ $upgrade_name = $value['upgrade_name'];
+ $level = $value['level'];
+ if($upgrade_name == 'cannons') {
+ $cannon_level = $level;
+ }
+ else if($upgrade_name == 'sails') {
+ $sail_level = $level;
+ }
+ else if($upgrade_name == 'hull') {
+ $hull_level = $level;
+ }
+ else if($upgrade_name == 'crew') {
+ $crew_level = $level;
+ }
+}
+
+
+if(!isset($crew_level)) {
+ $crew_level = 0;
+}
+
+if(!isset($hull_level)) {
+ $hull_level = 0;
+}
+if(!isset($cannon_level)) {
+ $cannon_level = 0;
+}
+if(!isset($sail_level)) {
+ $sail_level = 0;
+}
+
+
+$upgrade_costs = get_upgrade_costs($user);
+
+//print "upgrade cost";
+//print_r($upgrade_costs);
+
+print dashboard();
+
+?>
+
+
+
+
+
+
+
+
+
+Welcome to the Market!
+
+
+Arrrrr.....
+
+
+
+
+
+
+
+
+
+
Purchase Level Upgrade
+
+
+
+
+$value) {
+ //echo "key: $key value:";
+ //print_r($value);
+ //$id = $value['id'];
+ $stuff_id = $value['stuff_id'];
+
+ if($stuff_id == 1) {
+ $booty_name = 'a treasure map';
+ $map_count = $value['how_many'];
+ }
+ else if($stuff_id == 2) {
+ $booty_name = 'some gold bars';
+ $gold_count = $value['how_many'];
+ }
+ else if($stuff_id == 3) {
+ $booty_name = 'a message in a bottle';
+ $message_count = $value['how_many'];
+ }
+ else if($stuff_id == 4) {
+ $booty_name = 'some dynamite';
+ $dynamite_count = $value['how_many'];
+ }
+ else if($stuff_id == 5) {
+ $booty_name = 'a pirate flag';
+ $flag_count = $value['how_many'];
+ }
+ else if($stuff_id == 6) {
+ $booty_name = 'a bomb';
+ $bomb_count =$value['how_many'];
+ }
+ else if($stuff_id == 10) {
+ $sword_name = 'sword';
+ $sword_count =$value['how_many'];
+ }
+ else if($stuff_id == 8) {
+ $pistol_name = 'pistol';
+ $pistol_count =$value['how_many'];
+ }
+
+
+ //$booty_name = $value['booty_name'];
+
+ $count = $value['how_many'];
+ //echo "
$booty_name (x $count)
";
+
+}
+
+function enough_to_level($user, $gold_count, $message_count, $flag_count, $coin_count, $sword_count, $pistol_count) {
+ $upgrade_costs = get_upgrade_costs($user);
+ $gold_cost = $upgrade_costs[0];
+ $message_cost = $upgrade_costs[1];
+ $flag_cost = $upgrade_costs[2];
+ $level = get_level($user);
+ //print_r($level);
+ $coin_cost = $coin_cost = get_level($user) * $gold_cost;
+ if($level > 5000) {
+ $coin_cost = get_level($user) * $gold_cost * 1000;
+ }
+
+ if($level > 5000) {
+ $sword_cost = $upgrade_costs[0] * $upgrade_costs[1];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[1];
+ }
+ else if($level > 1000) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[2];
+ }
+ else if($level > 500) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1];
+ }
+ else if($level > 300) {
+ $sword_cost = 1;
+ $pistol_cost = 1;
+ }
+ else {
+ $sword_cost = 0;
+ $pistol_cost = 0;
+ }
+
+
+ //echo $gold_cost <= $gold_count;
+ //echo $message_cost <= $message_count;
+ //echo $flag_cost <= $flag_count;
+ //echo $coin_cost <= $coin_count;
+
+ if($gold_cost <= $gold_count && $message_cost <= $message_count && $flag_cost <= $flag_count && $coin_cost <= $coin_count && $sword_cost <= $sword_count && $pistol_cost <= $pistol_count) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+ ?>
+
+ 5000) {
+ $sword_cost = $upgrade_costs[0] * $upgrade_costs[1];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[1];
+ }
+ else if($level > 1000) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[2];
+ }
+ else if($level > 500) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1];
+ }
+ else if($level > 300) {
+ $sword_cost = 1;
+ $pistol_cost = 1;
+ }
+ else {
+ $sword_cost = 0;
+ $pistol_cost = 0;
+ }
+
+
+
+
+if(enough_to_level($user, $gold_count, $message_count, $flag_count, $coin_total, $sword_count, $pistol_count)): ?>
+
You purchased a level upgrade! You're now a level
+
+Execute($sql, array($flag_cost, $user, $flag_id));
+
+//update message count
+$sql = "update stuff set how_many = how_many - ? where user_id = ? and stuff_id = ?";
+$DB->Execute($sql, array($message_cost, $user, $message_id));
+
+//update gold count
+$sql = "update stuff set how_many = how_many - ? where user_id = ? and stuff_id = ?";
+$DB->Execute($sql, array($gold_cost, $user, $gold_id));
+
+
+//update sword count
+$sql = "update stuff set how_many = how_many - ? where user_id = ? and stuff_id = ?";
+$DB->Execute($sql, array($sword_cost, $user, $sword_id));
+
+//update pistol count
+$sql = "update stuff set how_many = how_many - ? where user_id = ? and stuff_id = ?";
+$DB->Execute($sql, array($pistol_cost, $user, $pistol_id));
+
+//update coin count
+$sql = "update users set coin_total = coin_total - ? where id = ?";
+$DB->Execute($sql, array($coin_cost, $user));
+
+log_levels($user, 'bought level');
+log_coins($user, -$coin_cost, 'bought level');
+
+
+set_level($user, get_level($user) + 1);
+
+$new_level = get_level($user);
+
+if($new_level > 3000) {
+ global $memcache;
+ $memcache->set($user . 'upgraded_level', 1, false, 60 * 10); //ten minutes
+ }
+
+//decrement message count, flag count, coin total
+
+
+echo get_level($user); ?> Pirate
+redirect("index.php");
+endif; ?>
+
+
+
+
+
+
+
+
+
+
+
Go back to sea -adventure, danger and treasure await
+
+
+
+
+
+
+
+
diff --git a/level_upgrade.php b/level_upgrade.php
new file mode 100644
index 0000000..bfe35d7
--- /dev/null
+++ b/level_upgrade.php
@@ -0,0 +1,364 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$my_level = get_level($user);
+
+$upgrades = get_upgrades($user);
+
+foreach($upgrades as $key=>$value) {
+ $upgrade_name = $value['upgrade_name'];
+ $level = $value['level'];
+ if($upgrade_name == 'cannons') {
+ $cannon_level = $level;
+ }
+ else if($upgrade_name == 'sails') {
+ $sail_level = $level;
+ }
+ else if($upgrade_name == 'hull') {
+ $hull_level = $level;
+ }
+ else if($upgrade_name == 'crew') {
+ $crew_level = $level;
+ }
+}
+
+
+if(!isset($crew_level)) {
+ $crew_level = 0;
+}
+
+if(!isset($hull_level)) {
+ $hull_level = 0;
+}
+if(!isset($cannon_level)) {
+ $cannon_level = 0;
+}
+if(!isset($sail_level)) {
+ $sail_level = 0;
+}
+
+
+$upgrade_costs = get_upgrade_costs($user);
+
+
+print dashboard();
+
+?>
+
+
+
+
+
+Welcome to the Market!
+
+
+What can I do for ya?
+
+
+
+
+
+
+
+
+
+
Purchase Level Upgrade
+
+
+
+
+$value) {
+ //echo "key: $key value:";
+ //print_r($value);
+ //$id = $value['id'];
+ $stuff_id = $value['stuff_id'];
+
+ if($stuff_id == 1) {
+ $booty_name = 'a treasure map';
+ $map_count = $value['how_many'];
+ }
+ else if($stuff_id == 2) {
+ $booty_name = 'some gold bars';
+ $gold_count = $value['how_many'];
+ }
+ else if($stuff_id == 3) {
+ $booty_name = 'a message in a bottle';
+ $message_count = $value['how_many'];
+ }
+ else if($stuff_id == 4) {
+ $booty_name = 'some dynamite';
+ $dynamite_count = $value['how_many'];
+ }
+ else if($stuff_id == 5) {
+ $booty_name = 'a pirate flag';
+ $flag_count = $value['how_many'];
+ }
+ else if($stuff_id == 6) {
+ $booty_name = 'a bomb';
+ $bomb_count =$value['how_many'];
+ }
+ else if($stuff_id == 10) {
+ $sword_name = 'sword';
+ $sword_count =$value['how_many'];
+ }
+ else if($stuff_id == 8) {
+ $pistol_name = 'pistol';
+ $pistol_count =$value['how_many'];
+ }
+
+
+
+ //$booty_name = $value['booty_name'];
+
+ $count = $value['how_many'];
+ //echo "
$booty_name (x $count)
";
+
+}
+function enough_to_level($user, $gold_count, $message_count, $flag_count, $coin_count, $sword_count, $pistol_count) {
+ $upgrade_costs = get_upgrade_costs($user);
+ $gold_cost = $upgrade_costs[0];
+ $message_cost = $upgrade_costs[1];
+ $flag_cost = $upgrade_costs[2];
+ $level = get_level($user);
+ //print_r($level);
+ $coin_cost = $coin_cost = get_level($user) * $gold_cost;
+ if($level > 5000) {
+ $coin_cost = get_level($user) * $gold_cost * 1000;
+ }
+
+ if($level > 5000) {
+ $sword_cost = $upgrade_costs[0] * $upgrade_costs[1];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[1];
+ }
+ else if($level > 1000) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[2];
+ }
+ else if($level > 500) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1];
+ }
+ else if($level > 300) {
+ $sword_cost = 1;
+ $pistol_cost = 1;
+ }
+ else {
+ $sword_cost = 0;
+ $pistol_cost = 0;
+ }
+
+ //echo $gold_cost <= $gold_count;
+ //echo $message_cost <= $message_count;
+ //echo $flag_cost <= $flag_count;
+ //echo $coin_cost <= $coin_count;
+
+ if($gold_cost <= $gold_count && $message_cost <= $message_count && $flag_cost <= $flag_count && $coin_cost <= $coin_count && $sword_cost <= $sword_count && $pistol_cost <= $pistol_count) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+ ?>
+
+
+
You're holding coins
+
+
+
You also have buried coins. Retrieve em to buy stuff here.
+
+
+
+
+
+
+
+
+
Arr....You can increase your level by recruitin your mates, or by trading in special items.
+
+
+
Purchase a level increase for the price of:
+
+
+
+
+ Not enough booty to level up yet! Arrrrrr....
+
+
+
+ 5000) {
+ $sword_cost = $upgrade_costs[0] * $upgrade_costs[1];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[1];
+ }
+ else if($level > 1000) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1] * $upgrade_costs[2];
+ }
+ else if($level > 500) {
+ $sword_cost = $upgrade_costs[0];
+ $pistol_cost = $upgrade_costs[1];
+ }
+ else if($level > 300) {
+ $sword_cost = 1;
+ $pistol_cost = 1;
+ }
+ else {
+ $sword_cost = 0;
+ $pistol_cost = 0;
+ }
+
+
+//$rum_cost = $my_level;
+
+$money_cost = $my_level * $gold_cost;
+?>
+
+
+
+ gold bars You Have
+
+ OK
+
+ NEED MORE
+
+
+ message in a bottle You Have
+
+ OK
+
+ NEED MORE
+
+
+
+ pirate flag You Have
+
+ OK
+
+ NEED MORE
+
+
+
+
+
+ 300) {
+
+?>
+
+ swords You Have
+
+ OK
+
+ NEED MORE
+
+
+
+
+
+ pistols You Have
+
+ OK
+
+ NEED MORE
+
+
+
+
+
+
+
+
+
+
+ coins You Have coins
+
+ OK
+
+ NEED MORE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ >Go back to sea -adventure, danger and treasure await
+
+
+
+
+
diff --git a/lib.php b/lib.php
new file mode 100644
index 0000000..d7e94a0
--- /dev/null
+++ b/lib.php
@@ -0,0 +1,5092 @@
+GetOne('select count(*) from comments where xid = ?', array($key));
+}
+
+function get_last_10_posts($key) {
+ global $DB;
+ return $DB->GetArray('select * from comments where xid = ? order by created_at desc limit 10', array($key));
+}
+
+function get_square_profile_pic($profile_id) {
+ global $network_id;
+ if($network_id == 0) {
+ return "
";
+ }
+ else {
+
+ try {
+ require_once('Space.php');
+ $key = 'CHANGEME';
+ $secret = 'CHANGEME';
+ $s = new Space($key, $secret);
+ $hProfile = $s->profile($profile_id);
+ $imageuri = $hProfile['imageuri'];
+ return "
";
+ }
+ catch(Exception $e) {
+ //some problem talking to myspace to get pic
+ return;
+ }
+ }
+}
+
+
+function get_square_profile_pic_50($profile_id) {
+ global $network_id;
+ if($network_id == 0) {
+ return "
";
+ }
+ else {
+
+ try {
+ require_once('Space.php');
+ $key = 'CHANGEME';
+ $secret = 'CHANGEME';
+ $s = new Space($key, $secret);
+ $hProfile = $s->profile($profile_id);
+ $imageuri = $hProfile['imageuri'];
+ return "
";
+ }
+ catch(Exception $e) {
+ //some problem talking to myspace to get pic
+ return;
+ }
+ }
+}
+
+function get_friends($user) {
+ require_once('Space.php');
+ $key = 'CHANGEME';
+ $secret = 'CHANGEME';
+ $s = new Space($key, $secret);
+ $hProfile = $s->friends($user);
+ return $hProfile['friends'];
+}
+
+function get_friend_ids($user) {
+ $friends = get_friends($user);
+ $ids = array();
+ foreach($friends as $friend) {
+ $ids[] = $friend['userid'];
+ }
+ return $ids;
+}
+
+function href($link, $params = NULL) {
+ global $network_id, $query_string;
+ if(true) {
+ echo "href = '" . $link . $params . "'";
+ }
+ else {
+ if($params != NULL) {
+ echo "href = '" . $link . $params . "'";
+
+ }
+ else {
+ echo "href = '$link";
+ }
+
+ }
+}
+
+
+function href_return($link, $params = NULL) {
+ global $network_id, $query_string;
+ if(true) {
+ return "href = '$link'";
+ }
+ else {
+ if($params != NULL) {
+ return "href = '" . $link . $params . "'";
+
+ }
+ else {
+ return "href = '$link'";
+ }
+
+ }
+}
+
+function image($image_name) {
+ global $network_id, $image_uid, $image_url;
+ //temporary hopefully
+ //$network_id = 1;
+ //$image_url = 'CHANGEME/images/a';
+ //echo "
";
+ //return;
+ ///*
+ if($network_id == 0) {
+ echo "
";
+ }
+ else if($network_id == 1 || $network_id == 2) {
+ echo "
";
+
+ }
+ //*/
+
+
+}
+
+function image_return($image_name) {
+ global $network_id, $image_uid, $image_url;
+ //temporary hopefully
+ //$network_id = 1;
+ //$image_url = 'CHANGEME/images/a';
+ //return "
";
+ ///*
+ if($network_id == 0) {
+ return "
";
+ }
+ else if($network_id == 1 || $network_id == 2) {
+ return "
";
+
+ }
+ //*/
+}
+
+
+function get_race_time_left() {
+ global $DB;
+ $sql = "select created_at as a, now() as b from race_results order by created_at desc";
+ $r = $DB->GetRow($sql);
+
+ //print_r($r);
+
+ //YYYYMMDDHHMMSS
+ $a = $r['a'];
+
+ $b = $r['b'];
+
+ $c = date("YmdHis", strtotime($a));
+ $d = date("YmdHis", strtotime($b));
+ //print $created_at;
+ //print_r($a);
+ //print_r($b);
+ $s = 1800 + strtotime($a) - strtotime($b);
+ //print $s;
+ //return relative_date($c, $d);
+ $m =round( $s /60 );
+ if($m == 1) {
+ return '1 minute';
+ }
+ else {
+ return $m . ' minutes';
+ }
+
+}
+
+function get_consecutive_merchant_trades($user) {
+ return 0;
+}
+
+function get_merchant_trade($user) {
+ global $memcache;
+
+ //try and get trade out of memcache
+ $mt = $memcache->get($user . 'mtrade');
+ if($mt != false) {
+ return $mt;
+ }
+
+ $pvp_toggle = $memcache->get($user . 'pvp');
+ if($pvp_toggle == 'off') {
+ //echo "pvp off!";
+ $gold_amount = rand(25,100);
+ }
+ else {
+ $gold_amount = 0;
+ }
+ global $DB;
+ $consecutive_trades = $DB->GetOne('select consecutive_merchant_trades from users where id = ?', array($user));
+
+ $amount1 = rand(2,5);
+ $amount2 = rand(2,5);
+
+ if($consecutive_trades > rand(3,5) && $pvp_toggle != 'off') {
+ $amount2 = round($amount2 * rand(1.5,2.5));
+ }
+
+ if($consecutive_trades > rand(10,15) && $pvp_toggle != 'off') {
+ $amount2 = $amount2 * rand(5,10);
+ $DB->Execute('update users set consecutive_merchant_trades = 0 where id = ?', array($user));
+ }
+
+ $stuffid1 = rand(1,13);
+ $stuffid2 = rand(1,13);
+ if($stuffid2 == $stuffid1) {
+ $stuffid2 = $stuffid1 + 1;
+ }
+ if($stuffid2 == 14) {
+ $stuffid2 = 1;
+ }
+ $stuff1 = get_booty_data_from_id($stuffid1);
+ $stuff2 = get_booty_data_from_id($stuffid2);
+
+ if( $stuff1['0'] == 'Dynamite' || $stuff1['0'] == 'Gold Bars' || $stuff1['0'] == 'Rum') {
+ $what_you_give_name = $stuff1['0'];
+ }
+ else if ($stuff1['0'] == 'Message in a Bottle'){
+ $what_you_give_name = 'Messages in Bottles';
+ }
+ else {
+ $what_you_give_name = $stuff1['0'] . 's';
+ }
+
+ if( $stuff2['0'] == 'Dynamite' || $stuff2['0'] == 'Gold Bars' || $stuff2['0'] == 'Rum') {
+ $what_you_get_name = $stuff2['0'];
+ }
+ else if ($stuff2['0'] == 'Message in a Bottle'){
+ $what_you_get_name = 'Messages in Bottles';
+ }
+ else {
+ $what_you_get_name = $stuff2['0'] . 's';
+ }
+
+ $mt = array(
+ 'what_you_give_name'=> $what_you_give_name,
+ 'what_you_get_name' => $what_you_get_name,
+ 'what_you_give_amount' => $amount1,
+ 'what_you_get_amount' => $amount2,
+ 'what_you_give_pic' => $stuff1['3'],
+ 'what_you_get_pic' => $stuff2['3'],
+ 'what_you_give_id' => $stuffid1,
+ 'what_you_get_id' => $stuffid2,
+ 'gold_amount' => $gold_amount);
+
+ $memcache->set($user . 'mtrade', $mt);
+
+ return $mt;
+}
+
+function get_number_entries($animal_char) {
+ global $DB;
+ $sql = "select count(*) from races where type = '$animal_char' and completed = 0";
+ $r = $DB->GetOne($sql);
+ return $r;
+}
+
+function get_past_winner_amount($a) {
+ if($a == 'parrot') {
+ return 5000;
+ }
+ else {
+ return 600;
+ }
+}
+
+function not_enough_to_race($user, $animal_char) {
+ //now check if they have enough parrotrs or monkeys
+ if($animal_char == 'p') {
+ $animal_count = get_parrot_count($user);
+ }
+ else {
+ $animal_count = get_monkey_count($user);
+ }
+
+ //print_r($animal_count);
+
+ if($animal_count < 1) {
+ return true;
+ }
+
+ return false;
+}
+function user_can_enter_race($user, $animal_char) {
+ global $DB;
+ $sql = "select count(*) from races where user_id = $user and type = '$animal_char' and completed = 0";
+ $r = $DB->GetOne($sql);
+ if($r == 0) {
+ return true;
+
+ }
+
+ else {
+ return false;
+ }
+}
+
+function get_past_winner_id($a) {
+ if($a == 'parrot') {
+ return 3423444;
+ }
+ else {
+ return 1807681;
+ }
+}
+
+
+function get_jackpot_amount($a) {
+ if($a == 'p') {
+ $entries = get_number_entries($a);
+ $jackpot = $entries * 200;
+ if($jackpot < 5000) {
+ $jackpot = 5000;
+ }
+ }
+ else {
+ $entries = get_number_entries($a);
+ $jackpot = $entries * 50;
+ if($jackpot < 2500) {
+ $jackpot = 2500;
+ }
+ }
+
+ return $jackpot;
+}
+
+function get_races_won_by_id($user) {
+ global $DB;
+ $sql = "select type, jackpot, created_at, entrants from race_results where user_id = $user order by created_at DESC";
+ $results_array = $DB->GetArray($sql);
+
+ return $results_array;
+}
+
+
+function user_eligible_for_offer($user, $offer_id) {
+
+ global $DB;
+ $r = $DB->GetOne('select count(*) from offers where user_id = ? and offer_id = ?', array($user, $offer_id));
+
+ //print $r;
+ return !$r;
+
+}
+
+
+//moderators and banned users on the discussion board
+function get_moderators() {
+ return array(1807687);
+}
+
+function get_no_captcha() {
+ return array();
+
+}
+
+function get_banned() {
+ return array();
+}
+
+function get_audited_users() {
+ global $DB, $memcache;
+ require_once 'cheater_ids.php';
+ //todo don't hardcode ids in teh query so when new ones are added...
+ global $cheaters;
+ if(false) {
+ $n = $memcache->get('audied_users');
+ if($n == FALSE) {
+ $r =$DB->GetArray('select logged_users.id, level from logged_users, users where users.id = logged_users.id and logged_users.id not in () order by users.name');
+ $n = array();
+ foreach($r as $key => $value) {
+ $n[]=$value['id'];
+ }
+
+ $memcache->set('audited_users', $n, false, 3600);
+ }
+ }
+ else {
+ //$r =$DB->GetArray('select logged_users.id, users.level from logged_users, users where logged_users.id = users.id order by users.name;');
+ $r =$DB->GetArray('select logged_users.id, level from logged_users, users where users.id = logged_users.id and logged_users.id not in () order by users.name');
+
+
+ }
+
+ return $r;
+
+}
+
+
+function get_audited_users_ids() {
+ global $DB, $memcache;
+ require_once 'cheater_ids.php';
+ //todo don't hardcode ids in teh query so when new ones are added...
+ global $cheaters;
+ if($memcache) {
+ $n = $memcache->get('audited_users_ids');
+ if($n == FALSE) {
+ $r =$DB->GetArray('select id from logged_users');
+ $n = array();
+ foreach($r as $key => $value) {
+ $n[]=$value['id'];
+ }
+
+ $memcache->set('audited_users_ids', $n, false, 3600);
+ }
+ }
+ else {
+ $r =$DB->GetArray('select id from logged_users');
+
+ $n = array();
+ foreach($r as $key => $value) {
+ $n[]=$value['id'];
+ }
+ }
+
+ return $n;
+
+}
+
+
+function dashboard($show_make_better = FALSE) {
+ global $network_id;
+
+ if($network_id == 1) {
+ include 'style.php';
+ }
+
+ $output = "
";
+
+ return $output;
+}
+
+function success_msg($msg) {
+global $network_id;
+if($msg == '') {
+ return;
+}
+if($network_id == 0)
+{
+?>
+
+
+
+
+
+
+
+
+
+
+
$msg ";
+ }
+ else {
+ $str = " ";
+ }
+
+ return $str;
+}
+
+
+function explanation_msg($msg) {
+global $network_id;
+if($network_id == 0)
+{
+?>
+
+
+
+
+
+
+
+
+
+
+
+ $msg ";
+ }
+ else {
+ $str = " ";
+ }
+
+ return $str;
+}
+
+
+
+function error_msg($msg) {
+global $network_id;
+if($network_id == 0)
+{
+?>
+
+
+
+
+
+
+
+
+
+
$msg ";
+ }
+ else {
+ $str = "
";
+ }
+
+ return $str;
+}
+
+
+
+function dashboard_loggedout() {
+ $output = "
";
+
+ return $output;
+}
+
+
+function get_num_ads_complete($user) {
+ global $DB;
+
+ $sql = "SELECT offer_id FROM offers where user_id = $user";
+ $value = $DB->GetArray($sql);
+ return 1;
+ return count($value);
+}
+
+function get_total_user_count() {
+ global $memcache, $DB;
+ $r = $memcache->get("total_user_count");
+ if($r == FALSE) {
+ $sql = "SELECT max(auto_id) from users";
+ $r = $DB->GetOne($sql);
+ $memcache->set("total_user_count", $r, false, 3600 * 12);
+ }
+ //echo "total user count: $r";
+ return $r;
+
+}
+
+function get_gender($user) {
+ global $memcache, $DB, $facebook;
+ $r = $memcache->get($user . "s_gender");
+
+
+ if($r == FALSE) {
+ $sql = "SELECT gender from users where id = ?";
+ $r = $DB->GetOne($sql, array($user));
+
+ if($r == 'm' || $r == 'f') {
+ $memcache->set($user . "s_gender", $r, false, 1);
+
+ }
+ else {
+
+ $re = $facebook->api_client->users_getInfo($user, array('sex'));
+
+ //wtf why does this something throw exception!
+ if($re[0]) {
+ $gender = $re[0]['sex'];
+ }
+ else {
+ $re0 = $re[0];
+ error_log("error getting user info sex: re: $re re0 $re0 user: $user", 0);
+ $gender = 'male';
+ }
+
+
+ $r = $gender;
+
+ if($r == 'male') {
+ $r = 'm';
+ }
+ else if($r == 'female') {
+ $r = 'f';
+ }
+ else {
+ $r = 'm';
+ }
+
+ $DB->Execute('update users set gender = ? where id = ?', array($r, $user));
+
+ }
+
+
+ }
+ else {
+ if ($r != 'm' && $r != 'f') {
+ $re = $facebook->api_client->users_getInfo($user, array('sex'));
+ $gender = $re[0]['sex'];
+ $r = $gender;
+ if($r == 'male') {
+ $r = 'm';
+ }
+ else if($r == 'female') {
+ $r = 'f';
+ }
+ else {
+ $r = 'm';
+ }
+
+ $DB->Execute('update users set gender = ? where id = ?', array($r, $user));
+ }
+
+
+ }
+
+ return $r;
+
+}
+
+
+
+function get_joke_on($user) {
+ global $memcache, $DB;
+ $r = $memcache->get($user . "s_joke_on_off");
+ if($r == FALSE) {
+ $sql = "SELECT joke_on from users where id = ?";
+ $r = $DB->GetRow($sql, array($user));
+ $memcache->set($user . "s_joke_on_off", $r, false, 1);
+ }
+ //echo "total user count: $r";
+ return $r['joke_on'];
+}
+
+function get_use_old_image($user) {
+ global $memcache, $DB;
+ $r = $memcache->get($user . "s_use_old_image");
+ if($r == FALSE) {
+ $sql = "SELECT use_old_image from users where id = ?";
+ $r = $DB->GetOne($sql, array($user));
+ $memcache->set($user . "s_use_old_image", $r, false, 1);
+ }
+ //echo "total user count: $r";
+ return $r;
+}
+
+
+
+function get_bomb_on($user) {
+ global $memcache, $DB;
+ $r = $memcache->get($user . "s_bomb_on_off");
+ if($r == FALSE) {
+ $sql = "SELECT bomb_on from users where id = ?";
+ $r = $DB->GetRow($sql, array($user));
+ $memcache->set($user . "s_bomb_on_off", $r, false, 1);
+ }
+ //echo "total user count: $r";
+ return $r['bomb_on'];
+}
+
+function get_animate_on($user) {
+ global $memcache, $DB;
+ $r = $memcache->get($user . "s_an_on_off");
+ if($r == FALSE) {
+ $sql = "SELECT animate_on from users where id = ?";
+ $r = $DB->GetRow($sql, array($user));
+ $memcache->set($user . "s_an_on_off", $r, false, 1);
+ }
+ //echo "total user count: $r";
+ return $r['animate_on'];
+}
+
+function get_total_joke_count() {
+ global $memcache, $DB;
+ $r = $memcache->get("total_joke_count");
+ if($r == FALSE) {
+ $sql = "SELECT max(id) from jokes_approved";
+ $r = $DB->GetOne($sql);
+ $memcache->set("total_joke_count", $r, false, 60);
+ }
+ //echo "total user count: $r";
+ return $r;
+
+}
+
+function get_first_name_for_id($user) {
+ global $network_id;
+ if($network_id == 0) {
+ return "
";
+ }
+ else {
+ return get_name_for_id($user);
+ }
+}
+
+function get_name_for_id($user) {
+ global $DB;
+ return $DB->GetOne('select name from users where id = ?', array($user));
+}
+
+function new_directed_battle($user, $touser) {
+ global $memcache, $DB;
+ $e = $touser;
+ $memcache->set($e. 'attacked', 1, FALSE, rand(3000, 6000));
+
+ $enemy = $DB->GetRow('select id, level, damage, team, coin_total from users where id = ?', array($e));
+ //print_r($enemy);
+ //store the battle
+
+ $sql = 'insert into battles(user_id, user_id_2, battle_type, opponent_type, created_at) values (?, ?, ?, ?, now())';
+
+ $enemy_id = $enemy['id'];
+ $enemy_team = $enemy['team'];
+
+ $DB->Execute($sql, array($user, $enemy_id, 's', $enemy_team));
+
+ //print_r($enemy);
+ return $enemy;
+}
+
+//return a battle id
+function new_ship_battle_smart($user) {
+ // echo 'new ship';
+ global $DB, $facebook, $memcache;
+ $your_level = get_level($user);
+ $your_team = get_team($user);
+ //$level_low = floor($your_level * (1/3));
+ //$level_high = ceil($your_level * (9/2));
+
+ //if($level_low ==0) { //have to have 1 hit point at least...
+ // $level_low = 1;
+ //}
+ $total_users = get_total_user_count();
+
+ // $random_enemies = array();
+ //generate 500 random numbers
+ //for($i = 0; $i < 10; $i++) {
+ // $random_enemies[]=rand(1, $total_users);
+ //}
+ // $random_enemy_string = implode(', ', $random_enemies);
+
+ //echo "random enemy: $random_enemy";
+ $msg = "Arrrr... The attack is on!";
+
+ if($your_level > 100000) {
+ $active_users = $memcache->get('active_hi_3');
+ }
+ else if($your_level > 1000) {
+ $active_users = $memcache->get('active_hi_2');
+ }
+ else if($your_level > 100) {
+ $active_users = $memcache->get('active_hi');
+ }
+ else {
+ $active_users = $memcache->get('active_lo');
+ }
+
+ //print_r($active_users);
+ $max_active_users = count($active_users);
+ $ra = rand(0, $max_active_users - 1);
+
+ //echo " max active users is $max_active_users ";
+ //echo " ra is $ra ";
+
+ $enemy = $active_users[$ra];
+ //$enemy = random_enemy_id_for_battle_backup($user);
+
+ $pvp_off = $memcache->get($enemy . 'pvp');
+ if($pvp_off == 'off' || $enemy == $user) {
+ $enemy = random_enemy_id_for_battle_backup($user);
+ }
+ else {
+ //print " enemy $enemy ";
+
+
+ //set the enemy as being attacked and keep this for 15 minutes
+ //it won't put them back in the pool
+
+
+ unset($active_users[$ra]);
+
+ $active_users = array_values($active_users);
+
+ if(is_array($active_user)) {
+ $active_users = array();
+ }
+ if($your_level > 100000) {
+ $active_users = $memcache->set('active_hi_3', $active_users);
+ }
+ else if($your_level > 1000) {
+ $active_users = $memcache->set('active_hi_2', $active_users);
+ }
+ else if($your_level > 100) {
+ $active_users = $memcache->set('active_hi', $active_users);
+ //echo 'unsetting high';
+ //print_r($active_users);
+ }
+ else {
+ $active_users = $memcache->set('active_lo', $active_users);
+ }
+
+ }
+ // $was_attacked = $memcache->get($enemy . 'attacked');
+
+ $enemy_action = get_current_action($user);
+
+
+ if($enemy == FALSE || $enemy == $user || $enemy_action == 'treasure_hunt') {
+ $enemy = random_enemy_id_for_battle_backup($user);
+ }
+ if($enemy == FALSE) {
+ return FALSE;
+ }
+ //echo "new enemy";
+ $e = $enemy;
+ $memcache->set($e. 'attacked', 1, FALSE, rand(3000, 6000));
+
+
+
+ $enemy = $DB->GetRow('select id, level, damage, team, coin_total from users where id = ?', array($e));
+
+ $enemy_id = $enemy['id'];
+
+ $sql = 'update users set battling_enemy_id = ? where id = ?';
+ $DB->Execute($sql, array($enemy_id, $user));
+
+ $sql = 'insert into battles(user_id, user_id_2, battle_type, opponent_type, created_at) values (?, ?, ?, ?, now())';
+ //print_r($enemy);
+
+
+ $body = "Avast!
attacked
!";
+
+global $facebook_canvas_url;
+global $base_url;
+$image_1 = "$base_url/images/flag_200.jpg";
+$image_1_link = "$facebook_canvas_url/?i=$user";
+$title = "attacked a Pirate. Arrr...";
+
+
+/*
+//TODO add templatitzed feeds
+try {
+ $re2 = $facebook->api_client->feed_publishActionOfUser($title, $body);
+}
+ catch (FacebookRestClientException $fb_e) {
+}
+*/
+
+//notify user on attack
+//$facebook->api_client->notifications_send(array($enemy_id) , " attacked you! Attack
back!");
+
+
+ $DB->Execute($sql, array($user, $enemy_id, 's', $enemy_team));
+
+ //$battle_id = $DB->GetOne("select last_insert_id()");
+
+ //echo "battle id: $battle_id";
+ //var_dump($enemy);
+ return $enemy;
+}
+
+
+function should_show_ad($user) {
+ global $memcache;
+ if($memcache) {
+ $s = $memcache->get($user . ":z");
+ //echo "s is $s";
+
+ if($s == "") {
+ //echo "returning true";
+ return 1; // not set, default to true
+ }
+
+ return $s;
+ }
+ else {
+ return 1;
+ }
+}
+
+
+function random_enemy_id_for_battle_backup($user) {
+//echo "backup";
+//return a random enemy id
+ global $DB, $facebook;
+ $your_level = get_level($user);
+ $your_team = get_team($user);
+ //$level_low = floor($your_level * (1/3));
+ //$level_high = ceil($your_level * (9/2));
+
+ //if($level_low ==0) { //have to have 1 hit point at least...
+ // $level_low = 1;
+ //}
+ $total_users = get_total_user_count();
+
+ $random_enemies = array();
+ //generate 20 random numbers
+ for($i = 0; $i < 200; $i++) {
+ $random_enemies[]=rand(1, $total_users);
+ }
+ $random_enemy_string = implode(', ', $random_enemies);
+
+ if($your_level < 200) {
+ $sql = "select id, level, damage, team, coin_total from users where auto_id in($random_enemy_string) and id not in(select id from banned) and level !=0 and level != 1 and level != 2 and level != 3 and damage < level and id != ? and user_in_battle = 0 and level < 200 and pvp_off = 0 and current_action != 'treasure_hunt'";
+ }
+ else {
+ $sql = "select id, level, damage, team, coin_total from users where auto_id in($random_enemy_string) and id not in(select id from banned) and level !=0 and level != 1 and level != 2 and level != 3 and damage < level and id != ? and user_in_battle = 0 and level > 200 and pvp_off = 0 and current_action != 'treasure_hunt'";
+ }
+
+ // print "sql $sql";
+ $enemy = $DB->GetRow($sql, array($user));
+
+
+ return $enemy['id'];
+}
+
+
+//return a battle id
+function new_ship_battle($user) {
+ global $DB, $facebook;
+ $your_level = get_level($user);
+ $your_team = get_team($user);
+ //$level_low = floor($your_level * (1/3));
+ //$level_high = ceil($your_level * (9/2));
+
+ //if($level_low ==0) { //have to have 1 hit point at least...
+ // $level_low = 1;
+ //}
+ $total_users = get_total_user_count();
+
+ $random_enemies = array();
+ //generate 20 random numbers
+ if($your_level > 800) {
+ for($i = 0; $i < 1500; $i++) {
+ $random_enemies[]=rand(1, $total_users);
+ }
+ }
+ else {
+ for($i = 0; $i < 200; $i++) {
+ $random_enemies[]=rand(1, $total_users);
+ }
+ }
+ $random_enemy_string = implode(', ', $random_enemies);
+
+ //echo "random enemy: $random_enemy";
+ $msg = "Arrrr... The attack is on!";
+
+
+
+
+ //echo "level low: $level_low";
+ //echo "level high: $level_high";
+ //588360301
+ // $sql = 'select id, level, damage, team, coin_total from users where level between ? and ? and team != ? and coin_total > 0 and user_was_attacked = 0 and user_in_battle = 0 order by rand() limit 1';
+ //pick up to 5 random users which are not flagged as already attacked and not level 0
+
+if ($your_level > 800) {
+ $sql = "select id, level, damage, team, coin_total from users where auto_id in($random_enemy_string) and id not in(select id from banned) and level !=0 and level != 1 and level != 2 and
+level != 3 and damage < level and level > 400 and pvp_off = 0 and id != ? and user_in_battle = 0 and current_action != 'treasure_hunt'";
+ }
+else if($your_level > 200) {
+ $sql = "select id, level, damage, team, coin_total from users where auto_id in($random_enemy_string) and id not in(select id from banned) and level !=0 and
+level != 1 $level != 3 and damage < level and level > 150 and pvp_off = 0 and id != ? and user_in_battle = 0 and current_action != 'treasure_hunt'";
+}
+else if($your_level > 100) {
+ $sql = "select id, level, damage, team, coin_total from users where auto_id in($random_enemy_string) and id not in(select id from banned) and level !=0 and level != 1 and level != 2 and
+level != 3 and damage < level and level > 60 and pvp_off = 0 and id != ? and user_in_battle = 0 and current_action != 'treasure_hunt'";
+}
+else {
+ $sql = "select id, level, damage, team, coin_total from users where auto_id in($random_enemy_string) and id not in(select id from banned) and level !=0 and level != 1 and level != 2 and
+level != 3 and level != 5 and level != 6 and level != 7 and level !=8 and damage < level and pvp_off = 0 and id != ? and user_in_battle = 0 and current_action != 'treasure_hunt'";
+}
+
+ //print "sql $sql";
+ $enemy = $DB->GetRow($sql, array($user));
+ //echo "your team : $your_team";
+ //echo "the enemy";
+ //print_r($enemy);
+
+ if($enemy == FALSE) {
+ return FALSE;
+ }
+
+ $enemy_id = $enemy['id'];
+ $sql = 'update users set battling_enemy_id = ? where id = ?';
+ $DB->Execute($sql, array($enemy_id, $user));
+
+
+ $sql = 'insert into battles(user_id, user_id_2, battle_type, opponent_type, created_at) values (?, ?, ?, ?, now())';
+
+
+
+ $body = "Avast!
attacked
!";
+
+global $facebook_canvas_url;
+global $base_url;
+$image_1 = "$base_url/images/flag_200.jpg";
+$image_1_link = "$facebook_canvas_url/?i=$user";
+$title = "attacked a Pirate. Arrr...";
+
+
+//for the user
+/*
+try {
+ $re2 = $facebook->api_client->feed_publishActionOfUser($title, $body);
+}
+ catch (FacebookRestClientException $fb_e) {
+} */
+
+
+//notify user on attack
+//$facebook->api_client->notifications_send(array($enemy_id) , " attacked you! Attack
back!");
+
+
+ $DB->Execute($sql, array($user, $enemy_id, 's', $enemy_team));
+
+ //$battle_id = $DB->GetOne("select last_insert_id()");
+
+ //echo "battle id: $battle_id";
+ //var_dump($enemy);
+ return $enemy;
+}
+
+
+
+
+function hide_ad($user) {
+ global $memcache;
+ if($memcache) {
+ $s = $memcache->set($user . ":z", 0);
+ //return $s;
+ }
+}
+
+function show_ad($user) {
+ global $memcache;
+ if($memcache) {
+ $s = $memcache->set($user . ":z", 1);
+ return $s;
+ }
+}
+
+function get_max_miles($user) {
+ $sail_level = get_sails($user);
+
+ $base_value = 75;
+
+ $level = get_level($user);
+
+ $sail_total_miles = $base_value + ($sail_level * 2);
+
+// $level = get_level($user);
+
+ //$level = 75;
+ //$level = 0;
+// $level = $level * 3;
+// if($level < 100) {
+// $level = 100;
+// }
+// if($level > 300) {
+// $level = 300;
+// }
+
+ //hard limit of 1000 per hour
+ if($sail_total_miles > 1000) {
+ $sail_total_miles = 1000;
+ }
+ return $sail_total_miles;
+}
+
+function is_dynamite_set($user) {
+ global $DB;
+
+ return $DB->GetOne("select count(*) from booby_traps where to_id = ? and used = 0", array($user));
+//1807687
+
+//584114831
+
+}
+
+function get_recruits($user) {
+ global $memcache, $DB;
+ //$memcache = false;
+ if(false) {
+ $recruits_array = $memcache->get($user . ":fo");
+ if(!is_bool($recruits_array) and $recruits_array != "") {
+ return $recruits_array;
+ }
+ }
+
+ $sql = "select * from users where recruited_by = ?";
+
+ try {
+ $recruits_array = $DB->GetArray($sql, array($user));
+ } catch (Exception $e) { return false; }
+
+ if($memcache) {
+ $memcache->set($user . ":fo", $recruits_array, false, 1800);
+ }
+
+ return $recruits_array;
+}
+
+function get_sails($user)
+{
+ $upgrades = get_upgrades($user);
+ $sail_level = 0;
+ foreach($upgrades as $key=>$value) {
+ $upgrade_name = $value['upgrade_name'];
+ $level = $value['level'];
+ if($upgrade_name == 'sails') {
+ return $level;
+ }
+ else {
+ $sail_level = 0;
+ }
+ }
+ return $sail_level;
+}
+
+function get_was_attacked($user) {
+ global $memcache, $DB;
+ if($memcache) {
+ $user_was_attacked = $memcache->get($user . ":j");
+
+ if($user_was_attacked == FALSE) {
+ $user_was_attacked = $DB->GetOne("select user_was_attacked from users where id = ?", array($user));
+ $memcache->set($user . ":j", $user_was_attacked, FALSE, 600);
+ }
+ }
+ else {
+ $user_was_attacked = $DB->GetOne("select user_was_attacked from users where id = ?", array($user));
+ }
+
+ //print "was attacked $user_was_attacked";
+
+ return $user_was_attacked;
+
+}
+
+
+
+function get_was_bombed($user) {
+ global $memcache, $DB;
+ if($memcache) {
+ $user_was_attacked = $memcache->get($user . ":b");
+
+ if($user_was_attacked == FALSE) {
+ $user_was_attacked = $DB->GetOne("select user_was_bombed from users where id = ?", array($user));
+ $memcache->set($user . ":b", $user_was_attacked);
+ }
+ }
+ else {
+ $user_was_attacked = $DB->GetOne("select user_was_bombed from users where id = ?", array($user));
+ }
+
+
+ return $user_was_attacked;
+
+}
+
+
+
+function set_was_bombed($user, $enemy) {
+ global $memcache, $DB;
+
+ if($memcache) {
+ $s = $memcache->set($user . ":b", $enemy);
+ }
+ $sql = 'update users set user_was_bombed = ? where id = ?';
+ $DB->Execute($sql, array($enemy, $user));
+ return $s;
+}
+
+
+
+function set_was_attacked($user, $enemy) {
+ global $memcache, $DB;
+
+ if($memcache) {
+ $s = $memcache->set($user . ":j", $enemy);
+ }
+ $sql = 'update users set user_was_attacked = ? where id = ?';
+ $DB->Execute($sql, array($enemy, $user));
+ return $s;
+}
+
+function set_captcha_answer($user, $correct_answer) {
+ global $memcache;
+
+ if($memcache) {
+ $s = $memcache->set($user . ":c", $correct_answer);
+ }
+ return $s;
+}
+
+function get_captcha_answer($user) {
+ global $memcache;
+ if($memcache) {
+ $s = $memcache->get($user . ":c");
+
+ if($s == "") {
+ return ""; //not set
+ }
+
+ return $s;
+ }
+ else {
+ return "";
+ }
+}
+function get_defense_rating($user) {
+
+//
very easy easy moderate difficult very difficult extremely difficult
+return "
very easy ";
+}
+function get_miles_traveled($user) {
+ global $memcache_temp;
+ if($memcache_temp) {
+ $s = $memcache_temp->get($user . ":m");
+
+ if($s == "") {
+ return 0; //not set, default to 0 miles sailed
+ }
+
+ return $s;
+ }
+ else { //I don't believe this should ever happen
+ return 0;
+ }
+}
+
+function increment_miles_traveled($user) {
+ $s = get_miles_traveled($user);
+ $s = $s + 1;
+
+ $success = set_miles_traveled($user, $s);
+
+ increment_miles_travelled_db($user);
+
+ return $success;
+}
+
+function set_miles_traveled($user, $miles) {
+ global $memcache_temp;
+
+ if($miles < 0) {
+ $miles = 0;
+ }
+
+ if($memcache_temp) {
+ $s = $memcache_temp->set($user . ":m", $miles);
+ }
+ return $s;
+}
+
+//update weekly miles
+function increment_miles_travelled_db($user) {
+ global $memcache, $DB;
+
+ $sql = "update users set weekly_miles = weekly_miles + 1 where id = ?";
+ try {
+ $DB->Execute($sql, array($user));
+ } catch (Exception $e) { return false; }
+
+ //clear memcache, when we need it later we'll refetch
+ if($memcache) {
+ $memcache->set($user . ":weekly_miles", "", false, 60);
+ }
+
+ return true;
+}
+
+function get_weekly_miles_traveled($user) {
+ global $memcache, $DB;
+
+ if($memcache) {
+ $total_miles = $memcache->get($user . ":weekly_miles");
+ if(!is_bool($total_miles) and $total_miles != "") {
+ return "$total_miles";
+ }
+ }
+
+ $sql = "select weekly_miles from users where id = ?";
+ try {
+ $total_miles = $DB->GetOne($sql, array($user));
+ } catch (Exception $e) { return false; }
+
+ if(is_bool($total_miles)) {
+ return false;
+ }
+
+ if($memcache) {
+ $memcache->set($user . ":weekly_miles", "$total_miles", false, 60);
+ }
+
+ return "$total_miles";
+}
+
+function get_weekly_money($user) {
+ global $memcache, $DB;
+
+ if($memcache) {
+ $stored_money = $memcache->get($user . ":weekly_money");
+ if(!is_bool($stored_money) and $stored_money != "") {
+ return "$stored_money";
+ }
+ }
+
+ $sql = "select weekly_money from users where id = ?";
+ try {
+ $stored_money = $DB->GetOne($sql, array($user));
+ } catch (Exception $e) { return false; }
+
+ if(is_bool($stored_money)) {
+ return false;
+ }
+
+ if($memcache) {
+ $memcache->set($user . ":weekly_money", "$stored_money", false, 60);
+ }
+
+ return "$stored_money";
+}
+
+function get_weekly_level($user) {
+ global $memcache, $DB;
+
+ if($memcache) {
+ $stored_level = $memcache->get($user . ":weekly_level");
+ if(!is_bool($stored_level) and $stored_level != "") {
+ return "$stored_level";
+ }
+ }
+
+ $sql = "select weekly_level from users where id = ?";
+ try {
+ $stored_level = $DB->GetOne($sql, array($user));
+ } catch (Exception $e) { return false; }
+
+ if(is_bool($stored_level)) {
+ return false;
+ }
+
+ if($memcache) {
+ $memcache->set($user . ":weekly_level", "$stored_level", false, 60);
+ }
+
+ return "$stored_level";
+}
+
+function get_last_weekly_winners($award_name) {
+ global $memcache, $DB;
+
+ if($memcache) {
+ $stored_award = $memcache->get($user . ":$award_name");
+ if(!is_bool($stored_award) and $stored_award != "") {
+ return $stored_award;
+ }
+ }
+
+ $sql = "select uid from leader_weekly_winners where award_won = ? and date_won >= now() - INTERVAL 1 WEEK order by date_won desc limit 1";
+ try {
+ $stored_award = $DB->GetArray($sql, array($award_name));
+ } catch (Exception $e) { return false; }
+
+ if(is_bool($stored_award)) {
+ return false;
+ }
+
+ if($memcache) {
+ $memcache->set($user . ":$award_name", $stored_award , false, 3600);
+ }
+
+ return $stored_award;
+}
+
+function drink_rum($user) {
+ $rumCount = get_rum_count($user);
+ if($rumCount > 0) {
+ set_rum_total($user, $rumCount - 1);
+ $milesTraveled = get_miles_traveled($user);
+ $milesTraveled = $milesTraveled - 50;
+ if($milesTraveled < 0) {
+ $milesTraveled = 0;
+ }
+ set_miles_traveled($user, $milesTraveled);
+ return true;
+ }
+ return false;
+}
+
+function drink_rum_battling($user, $how_many) {
+ $rumCount = get_rum_count($user);
+ if($rumCount > 0) {
+ set_rum_total($user, $rumCount - $how_many);
+ return true;
+ }
+ return false;
+}
+
+function eat_ham($user) {
+ $hamCount = get_ham_count($user);
+ if($hamCount > 0) {
+ set_ham_total($user, $hamCount - 1);
+ $totalDamage = get_damage($user);
+ $totalLevel = get_level($user);
+ set_damage($user, ($totalDamage - round($totalLevel * .25)));
+ return true;
+ }
+ return false;
+}
+
+function in_us($user) {
+ return false;
+ global $facebook, $memcache;
+
+ //$memcache->set($user . ":in_us", $in_us, 1);
+
+ if($memcache) {
+ $in_us = $memcache->get($user . ":in_us");
+
+ if($in_us == FALSE) {
+ $result = $facebook->api_client->users_getInfo($user, array('current_location'));
+ $in_us= $result[0]['current_location']['country'];
+ }
+
+ if($in_us == "United States") {
+ return true;
+ }
+
+ else {
+ return false;
+ }
+ }
+
+
+ $result = $facebook->api_client->users_getInfo($user, array('current_location'));
+ $in_us= $result[0]['current_location']['country'];
+
+ //echo $in_us;
+ if($in_us == "United States") {
+ return true;
+ }
+
+ else {
+ return false;
+ }
+
+
+
+}
+
+function get_encoded_interests($user) {
+ global $facebook, $memcache;
+
+ if($memcache) {
+ $google_hint = $memcache->get($user . ":google_hint");
+
+ if($google_hint == FALSE) {
+ $result = $facebook->api_client->users_getInfo($user, array('interests'));
+ $google_hint= urlencode($result[0]['interests']);
+ $memcache->set($user . ":google_hint", $google_hint);
+ }
+
+ return $google_hint;
+ }
+
+
+ $result = $facebook->api_client->users_getInfo($user, array('interests'));
+ $google_hint= urlencode($result[0]['interests']);
+
+ return $google_hint;
+
+
+}
+function cubics_468_60() {
+ return "
";
+}
+
+
+function adsense_336_280($user) {
+ global $base_url;
+ return "
";
+
+}
+
+
+
+
+function adsense_300_250($user) {
+ global $network_id;
+ global $base_url;
+
+ if($network_id == 0) {
+ return "
";
+ }
+ else {
+ return "
";
+
+ }
+
+}
+
+
+function adsense_200_200($user) {
+ global $base_url, $network_id;
+ if($network_id == 0) {
+ return "
";
+ }
+ else {
+ return "
";
+ }
+
+}
+
+function adsense_125_125($user) {
+ global $base_url;
+ return "
";
+
+}
+
+
+
+
+function adbrite_468_60 () {
+ global $base_url;
+ print "
";
+
+}
+
+function rmx_120($user) {
+ global $base_url;
+ print "
";
+
+
+}
+
+function rmx_300_250() {
+ return '
';
+
+
+}
+
+function outlaws_banner() {
+ $str = <<
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+EOD;
+
+return $str;
+
+}
+function cross_promo_banner($user) {
+ global $base_url;
+ //CHANGEME/ads/?site=pirates&user='. $user
+ print ' ';
+
+}
+
+
+
+
+function pubmatic_468_60 () {
+ global $base_url;
+ print " ";
+
+}
+
+function valueclick_468_60() {
+ $page = 'valueclick';
+ global $base_url;
+ return " ";
+
+}
+
+function trianads_468_60() {
+ $r = rand(1,10000);
+ return " ";
+
+}
+
+
+function socialmedia_468_60() {
+ return '
+ ';
+
+}
+function adsense_120($user) {
+ global $base_url, $network_id;
+ if($network_id == 0) {
+ return ' ';
+ }
+ else {
+ return ' ';
+
+ }
+
+}
+
+function adsense_468($user) {
+ global $network_id;
+if($network_id == 0) {
+
+ $rand = rand(1,2);
+ if($rand == 1) {
+ //print '
+ // ';
+ print ' ';
+
+ }
+ /*
+ else if ($rand == 2) {
+ print ' ';
+
+ }*/
+
+ else {
+ // return " ";
+ return " ";
+
+ }
+
+}
+else {
+ return " ";
+}
+
+
+
+}
+
+
+function blow_up_user($user) {
+//unsets dynamite set for this user and takes away 10% of their highest item
+//unset dynamite
+global $DB, $facebook;
+
+$sql = 'select from_id from booby_traps where to_id = ? and used = 0 ORDER BY created_at';
+$from_id = $DB->GetOne($sql, array($user));
+
+//print "from id $from_id";
+
+//figure out id of what you lose
+$sql = 'SELECT how_many c, stuff_id FROM `stuff` where user_id = ? order by c desc limit 1';
+$lost = $DB->GetRow($sql, array($user));
+//print_r($lost);
+$stuff_id = $lost['stuff_id'];
+$how_many = $lost['c'];
+
+$percent = rand(1,5);
+
+$how_many_to_take = round($how_many * .01 * $percent); //take 1-5% of top item
+
+$how_many_left = $how_many - $how_many_to_take;
+
+
+//take away from user
+$sql = 'update stuff set how_many = ? where stuff_id = ? and user_id = ?';
+$DB->Execute($sql, array($how_many_left, $stuff_id, $user));
+
+
+if($how_many_to_take > 10) {
+ $how_many_to_take_limited = 10;
+}
+else {
+ $how_many_to_take_limited = $how_many_to_take;
+}
+if($how_many_to_take_limited < 1) {
+ $how_many_to_take_limited = 1;
+}
+
+
+//give to the pirate who set the trap
+$sql = 'update stuff set how_many = how_many + ? where stuff_id = ? and user_id = ?';
+$DB->Execute($sql, array($how_many_to_take_limited, $stuff_id, $from_id));
+
+
+
+$stuff_stuff = get_booty_data_from_id($stuff_id);
+//print_r($stuff_stuff);
+$stuff_name = $stuff_stuff[0];
+$sql = 'update booby_traps set used = 1 where to_id = ? and from_id = ? and used = 0 ORDER BY created_at LIMIT 1;';
+$DB->Execute($sql, array($user, $from_id));
+
+///notify_dynamite_went_off($from_id);
+
+//send.notification for from_id telling them they blew up $user making them lose some booty
+
+
+$ra = rand(1,3);
+if($ra == 1) {
+ $set_it_off = 'crew members'; //todo check if they have each of these
+}
+else if($ra == 2) {
+ $set_it_off = 'parrots';
+}
+else {
+ $set_it_off = 'monkeys';
+}
+
+$stuff_name_plural = $stuff_name . 's';
+
+if($stuff_name_plural == 'Gold Barss') {
+$stuff_name_plural = 'Gold Barss';
+}
+
+if($stuff_name_plural == 'Rums') {
+$stuff_name_plural = 'Bottles of Rum';
+}
+
+
+global $facebook_canvas_url;
+if($how_many_to_take == 1) {
+$it_them = 'it';
+$the_stuff_name = $stuff_name;
+ if($the_stuff_name == 'Gold Bars') {
+ $the_stuff_name = 'Gold Bar';
+ }
+
+}
+else {
+$it_them = 'them';
+$the_stuff_name = $stuff_name_plural;
+}
+
+
+$facebook->api_client->notifications_send(array($from_id) , " blew up while searching for booty ! Your dynamite trap worked - your monkey carried $how_many_to_take_limited $the_stuff_name back to your ship !", 'user_to_user');
+
+
+global $you_lose_image, $image_uid;
+return "KABOOOOOM!!! One of yer $set_it_off set off a dynamite booby trap while searching for booty! Arrrrrrr... no $set_it_off be injured in the explosion but you be losin $how_many_to_take $the_stuff_name ! Cap'n left this trap for you. Shiver me timbers!! ";
+
+
+}
+
+function use_sextant($user) {
+ $sextantCount = get_sextant_count($user);
+ if($sextantCount > 0) {
+ set_sextant_total($user, $sextantCount - 1);
+ return true;
+ }
+ return false;
+}
+
+function get_user_list() {
+ global $DB;
+ $sql = "SELECT id FROM users";
+
+ $value = $DB->GetArray($sql);
+ return $value;
+}
+
+function ordinal_suffix($value, $sup = 0){
+
+ if(substr($value, -2, 2) == 11 || substr($value, -2, 2) == 12 || substr($value, -2, 2) == 13){
+ $suffix = "th";
+ }
+ else if (substr($value, -1, 1) == 1){
+ $suffix = "st";
+ }
+ else if (substr($value, -1, 1) == 2){
+ $suffix = "nd";
+ }
+ else if (substr($value, -1, 1) == 3){
+ $suffix = "rd";
+ }
+ else {
+ $suffix = "th";
+ }
+ if($sup){
+ $suffix = "" . $suffix . " ";
+ }
+ return $value . $suffix;
+}
+
+function redirect_to_index_if_not_or($user, $action_1, $action_2) {
+ if($user == 1807687 ) {
+ return;
+ }
+ global $DB, $facebook, $facebook_canvas_url;
+ $u = get_current_action($user);
+
+ if($u != $action_1 && $u != $action_2) {
+ $facebook->redirect("$facebook_canvas_url/index.php");
+ //echo "u $u 1 $action_1 $action_2";
+ }
+}
+
+function redirect_to_index_if_not($user, $action) {
+ if($user == 1807687 ) {
+ return;
+ }
+ global $DB, $facebook, $facebook_canvas_url;
+ //$u = $DB->GetOne("select current_action from users where id = $user");
+
+ $u = get_current_action($user);
+
+ //echo $u;
+
+ if($u != $action) {
+ $facebook->redirect("$facebook_canvas_url/index.php");
+ }
+}
+
+function redirect_to_index_if_not_secondary($user, $action) {
+ //if($user == 1807687) {
+ // return;
+ //}
+ global $DB, $facebook, $facebook_canvas_url;
+ //$u = $DB->GetOne("select current_action from users where id = $user");
+
+ $u = get_secondary_action($user);
+
+ //echo $u;
+
+ if($u != $action) {
+ $facebook->redirect("$facebook_canvas_url/index.php");
+ }
+}
+
+
+function redirect_if_action($user) {
+
+ global $DB, $facebook, $facebook_canvas_url, $network_id;
+
+ $secondary = get_secondary_action($user);
+ $u = get_current_action($user);
+
+ if($secondary == 'attacked_by_monster') {
+ $facebook->redirect("$facebook_canvas_url/attacked_by_monster.php");
+ }
+ if($secondary == 'monster_attack_result') {
+ $facebook->redirect("$facebook_canvas_url/monster_attack_result.php");
+ }
+ //echo $u;
+ else if($u == 'land') {
+ $facebook->redirect("$facebook_canvas_url/found_land.php");
+ }
+ else if($u == 'enemy_base') {
+ $facebook->redirect("$facebook_canvas_url/enemy_base.php");
+ }
+ else if($u == 'enemy_ship') {
+ $facebook->redirect("$facebook_canvas_url/enemy_ship.php");
+ }
+ else if($u == 'attack_ship') {
+ $facebook->redirect("$facebook_canvas_url/attack_ship.php");
+ }
+ else if($u == 'attack_ship_merchant') {
+ $facebook->redirect("$facebook_canvas_url/attack_ship_merchant.php");
+ }
+ else if($u == 'island') {
+ $facebook->redirect("$facebook_canvas_url/island.php");
+ }
+ else if($u == 'captcha') {
+ $facebook->redirect("$facebook_canvas_url/captcha_page.php");
+ }
+ else if($u == 'attacked_by_monster') {
+ $facebook->redirect("$facebook_canvas_url/attacked_by_monster.php");
+ }
+ else if($u == 'treasture_hunt') {
+ $facebook->redirect("$facebook_canvas_url/index.php?msg=treasure-start");
+ }
+}
+
+/*
+function redirect_if_action_myspace($user) {
+
+ global $DB, $facebook, $facebook_canvas_url, $network_id;
+
+ //$u = $DB->GetOne("select current_action from users where id = $user");
+
+ //$u = get_current_action($user);
+
+ $secondary = get_secondary_action($user);
+ $u = get_current_action($user);
+
+ //echo "secondary $secondary";
+ //echo "u $u";
+
+ if($secondary == 'attacked_by_monster') {
+ //$facebook->redirect("$facebook_canvas_url/attacked_by_monster.php");
+ require_once 'attacked_by_monster.php';
+ exit();
+
+ }
+ if($secondary == 'monster_attack_result') {
+ //$facebook->redirect("$facebook_canvas_url/monster_attack_result.php");
+ require_once 'monster_attack_result.php';
+ exit();
+ }
+ //echo $u;
+ else if($u == 'land') {
+ //$facebook->redirect("$facebook_canvas_url/found_land.php");
+ require_once 'found_land.php';
+ exit();
+ }
+ else if($u == 'enemy_base') {
+ //$facebook->redirect("$facebook_canvas_url/enemy_base.php");
+ require_once 'enemy_base.php';
+ exit();
+ }
+ else if($u == 'enemy_ship') {
+ //$facebook->redirect("$facebook_canvas_url/enemy_ship.php");
+ require_once 'enemy_ship.php';
+ exit();
+ }
+ else if($u == 'attack_ship') {
+ //$facebook->redirect("$facebook_canvas_url/attack_ship.php");
+ require_once 'attack_ship.php';
+ exit();
+ }
+ else if($u == 'attack_ship_merchant') {
+ //$facebook->redirect("$facebook_canvas_url/attack_ship_merchant.php");
+ require_once 'attack_ship_merchant.php';
+ exit();
+ }
+ else if($u == 'island') {
+ //$facebook->redirect("$facebook_canvas_url/island.php");
+ require_once 'island.php';
+ exit();
+ }
+ else if($u == 'captcha') {
+ $facebook->redirect("$facebook_canvas_url/captcha_page.php");
+ //require_once 'captcha_page.php';
+ //exit();
+ }
+ else if($u == 'attacked_by_monster') {
+ //$facebook->redirect("$facebook_canvas_url/attacked_by_monster.php");
+ require_once 'attacked_by_monster.php';
+ exit();
+ }
+ else if($u == 'treasture_hunt') {
+ $facebook->redirect("$facebook_canvas_url/index.php?msg=treasure-start");
+
+ }
+}
+*/
+
+function get_coin_total_buried($user) {
+ global $DB;
+ $coin = $DB->GetOne("select buried_coin_total from users where id = $user");
+ if($coin < 0) {
+ $coin = 0;
+ $DB->Execute('update users set buried_coin_total = 0 where id = ?', $user, array($user));
+ }
+ return $coin;
+}
+
+function set_coin_total_buried($user, $coins) {
+ global $DB;
+
+ $sql = "update users set buried_coin_total = $coins where id = ?";
+ $DB->Execute($sql, array($user));
+}
+
+/*
+function get_booty($user) {
+ global $DB;
+ $sql = 'select booty_name, count(*) c from booty where user_id = ? group by booty_name';
+ return $DB->GetArray($sql, array($user));
+
+}
+*/
+
+function get_booty($user) {
+ global $DB;
+ $sql = 'select stuff_id, how_many from stuff where user_id = ?';
+ return $DB->GetArray($sql, array($user));
+}
+
+function get_booty_reverse_order($user) {
+ global $DB;
+ $sql = 'select stuff_id, how_many from stuff where user_id = ? order by stuff_id desc';
+ return $DB->GetArray($sql, array($user));
+}
+
+function get_coin_total($user) {
+ global $DB;
+ $coin = $DB->GetOne("select coin_total from users where id = $user");
+ if($coin < 0) {
+ $coin = 0;
+ $DB->Execute('update users set coin_total = 0 where id = ?', array($user));
+ }
+ return $coin;
+}
+
+function random_enemy($type) {
+ $ra= rand(1,100);
+ if($type == 'buccaneer') {
+ if($ra < 50) {
+ return 'corsair';
+ }
+
+ else {
+ return 'barbary';
+ }
+ }
+
+ else if($type == 'corsair') {
+ if($ra < 50) {
+ return 'buccaneer';
+ }
+
+ else {
+ return 'barbary';
+ }
+ }
+
+ else { // barbary
+ if($ra < 50) {
+ return 'corsair';
+ }
+
+ else {
+ return 'buccaneer';
+ }
+ }
+
+}
+function get_dynamite_count($user) {
+ global $DB;
+ $dynamite_id = 4;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $dynamite_id));
+}
+
+function get_monkey_count($user) {
+ global $DB;
+ $dynamite_id = 7;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $dynamite_id));
+}
+
+
+function get_parrot_count($user) {
+ global $DB;
+ $dynamite_id = 11;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $dynamite_id));
+}
+
+
+function get_map_count($user) {
+ global $DB;
+ $map_id = 1;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $map_id));
+}
+
+function get_bomb_count($user) {
+ global $DB;
+ $bomb_id = 6;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $bomb_id));
+}
+
+function get_bottle_count($user) {
+ global $DB;
+ $bottle_id = 3;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $bottle_id));
+}
+
+function set_bomb_total($user, $new_total) {
+ global $DB;
+ $bomb_id = 6;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $bomb_id));
+}
+
+function get_rum_count($user) {
+ global $DB;
+ $bomb_id = 9;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $bomb_id));
+}
+
+function set_rum_total($user, $new_total) {
+ global $DB;
+ $bomb_id = 9;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $bomb_id));
+}
+
+function get_round($user) {
+ global $memcache;
+ $r = $memcache->get($user . 'a_r');
+ if($r == 0 || $r == FALSE) {
+ $r = 1;
+ }
+ return $r;
+}
+
+function increment_round($user) {
+ //if the round here is 0 or false, then just end it by setting to 9
+ //it will get reset for the next fight
+ $round = get_round($user);
+ global $memcache;
+ $round++;
+ $memcache->set($user . 'a_r', $round);
+}
+
+function reset_round($user) {
+ //resets round to 1
+ global $memcache;
+ $memcache->set($user . 'a_r', 1);
+
+}
+
+
+
+function get_ham_count($user) {
+ global $DB;
+ $bomb_id = 12;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $bomb_id));
+}
+
+function get_sextant_count($user) {
+ global $DB;
+ $bomb_id = 13;
+ $sql = "select how_many from stuff where user_id = ? and stuff_id = ?";
+ return $DB->GetOne($sql, array($user, $bomb_id));
+}
+
+function set_ham_total($user, $new_total) {
+ global $DB;
+ $ham_id = 12;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $ham_id));
+}
+
+function set_dynamite_total($user, $new_total) {
+ global $DB;
+ $dynamite_id = 4;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $dynamite_id));
+}
+
+function set_monkey_total($user, $new_total) {
+ global $DB;
+ $monkey_id = 7;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $monkey_id));
+}
+
+function set_map_total($user, $new_total) {
+ global $DB;
+ $map_id = 1;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $map_id));
+}
+
+function set_parrot_total($user, $new_total) {
+ global $DB;
+ $parrot_id = 11;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $parrot_id));
+}
+
+
+
+
+function set_sextant_total($user, $new_total) {
+ global $DB;
+ $sextant_id = 13;
+ if($new_total < 0) {
+ $new_total = 0;
+ }
+ $sql = 'update stuff set how_many=? where user_id = ? and stuff_id = ?';
+ $DB->Execute($sql, array($new_total, $user, $sextant_id));
+}
+
+function increment_booty($user, $stuff_id) {
+ global $DB;
+
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1';
+ $DB->Execute($sql, array($user, $stuff_id));
+}
+
+function decrement_booty($user, $stuff_id) {
+ global $DB;
+
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 0, now()) on duplicate key update how_many = how_many - 1';
+ $DB->Execute($sql, array($user, $stuff_id));
+}
+
+function explore($user) {
+ //echo 'in function explore';
+ global $DB, $memcache;
+
+ //$user_attacked = $memcache->get($user . 'pvpattack');
+
+ //10% chance to see land in the distance
+ //10% chance to see another ship
+ //80% chance of nothing happening.. just keep sailing
+
+ $userMiles = get_miles_traveled($user);
+ $milesMax = get_max_miles($user);
+ if($userMiles < $milesMax) {
+ $success = increment_miles_traveled($user);
+ }
+
+ $ra= rand(1,2000);
+ //echo "ra; $ra";
+ if($ra < 3) {
+ update_action($user, "bottle");
+ $bottle_count = get_bottle_count($user);
+
+ //echo "bomb count: $bomb_count";
+ if($bottle_count > 10) {
+ update_action($user, "land");
+ return 'land';
+ }
+
+ //add 1 bottle to the users inventory
+ $bottle_id = 3;
+ global $DB;
+ $DB->Execute('insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1', array($user, $bottle_id));
+
+ return 'bottle';
+
+ }
+ else if($ra < 6) {
+ if (get_level($user) > 500 && $ra != 4 && $ra != 3) {
+ update_action($user, "land");
+ return 'land';
+ }
+
+ //check if they've already had a sinking ship today and if so forward to found land
+
+ $sinking_ship_limit = $memcache->get($user . 'sinking_ship_limit');
+ //$memcache = false;
+ if($memcache == false) {
+ update_action($user, "land");
+ return 'land';
+ }
+ //$sinking_ship_limit == 1
+ else if($sinking_ship_limit == 1) {
+ update_action($user, "land");
+ return 'land';
+ }
+ else {
+ //else set flag so they don't get it again
+ $memcache->set($user . 'sinking_ship_limit', 1, false, 60 * 60 * 24);
+ }
+
+ //add 1-3 sails, cannons, or crew
+ $upgrade_index = rand(0,2);
+ $upgrades = array('crew', 'sails', 'cannons');
+ $upgrade_name = $upgrades[$upgrade_index];
+
+ //print_r($upgrade_index);
+ //print_r($upgrade_name);
+ $amount = rand(1,3);
+
+ $cannon_limit = round(get_level($user)/2);
+ if($cannon_limit > 200) {
+ $cannon_limit = 200;
+ }
+ //echo "cannon limit $cannon_limit";
+ if($upgrade_name == 'cannons') {
+ $current_upgrade_level = get_cannons($user);
+ if($current_upgrade_level > $cannon_limit ) {
+ update_action($user, "land");
+ return 'land';
+ }
+ }
+ else if($upgrade_name == 'crew') {
+ $current_upgrade_level = get_crew_count($user);
+ if($current_upgrade_level > 150) {
+ update_action($user, "land");
+ return 'land';
+ }
+ }
+ else if($upgrade_name == 'sails') {
+ $current_upgrade_level = get_sails($user);
+ if($current_upgrade_level > 300) {
+ update_action($user, "land");
+ return 'land';
+ }
+
+ }
+ $sql = "insert into sinking_ship_booty (user_id, upgrade_name, amount, created_at) values(?, ?, ?, now())";
+ $result = $DB->Execute($sql, array($user, $upgrade_name, $amount));
+
+
+ $sql = "insert into upgrades (user_id, upgrade_name, created_at) values(?, ?, now()) on duplicate key update level = level+?";
+ $result = $DB->Execute($sql, array($user, $upgrade_name, $amount));
+
+
+ global $facebook;
+ //forward to index with msg
+ $facebook->redirect("index.php?msg=sinking-ship&booty=$upgrade_name&amount=$amount");
+
+
+ }
+ else if($ra < 20) {
+ update_action($user, "parrot");
+ $parrot_count = get_parrot_count($user);
+
+ //echo "bomb count: $bomb_count";
+ if($parrot_count > 0) {
+ update_action($user, "land");
+ return 'land';
+ }
+ //add 1 parrot to the users inventory
+ $bottle_id = 11;
+ global $DB;
+ //$DB->GetOne('select count(*) from stuff
+ $DB->Execute('insert into stuff (user_id, stuff_id, how_many, updated_at) values(?, ?, 1, now()) on duplicate key update how_many = how_many + 1', array($user, $bottle_id));
+
+ return 'parrot';
+
+
+ }
+ else if($ra < 100) {
+ if($network_id == 1) {
+ update_action($user, "land");
+ return 'land';
+ }
+ //10
+ update_action($user, "bomb");
+ $bomb_count = get_bomb_count($user);
+
+ //echo "bomb count: $bomb_count";
+ if($bomb_count < 1) {
+ update_action($user, "land");
+ return 'land';
+ }
+
+ $bomb_on = get_bomb_on($user);
+ if($bomb_on == 0) {
+ update_action($user, "land");
+ return 'land';
+ }
+
+ return 'bomb';
+
+ }
+ else if($ra < 185) { //set to 0 to turn off ship fighting
+ update_action($user, "ship");
+ //echo "get health approx";
+ //echo get_health($user);
+ global $DB;
+ //$memcache;
+ //$pvp_toggle = $memcache->get($user . 'pvp');
+ $pvp_toggle = $DB->GetOne('select pvp_off from users where id = ?', array($user));
+ if($pvp_toggle == 1) {
+ update_action($user, "land");
+ return 'land';
+ }
+ $merchant_limit = $memcache->get($user . 'merchant_ship_limit');
+ if($merchant_limit == 1) {
+ update_action($user, "land");
+ return 'land';
+ }
+
+ if(get_health($user)< 1) {
+ update_action($user, "land");
+ return 'land';
+ }
+ //
+ return 'ship';
+ }
+ else if($ra < 193) { //200
+ update_action($user, 'found_merchant_ship');
+ return 'found_merchant_ship';
+ }
+ else if($ra < 750) { //70
+ update_action($user, "land");
+ return 'land';
+ }
+ else {
+ return 'nothing';
+ }
+
+}
+
+function get_health($user) {
+ $level = get_level($user);
+ $health = $level - get_damage($user);
+ if($health > $level) {
+ $health = $level;
+ set_damage($user, 0);
+ }
+ return $health;
+}
+
+function get_gambling_count($user) {
+
+ global $memcache_temp;
+ $gambling_count = $memcache_temp->get($user . ":gamblecount");
+ if($gambling_count == FALSE) {
+ $gambling_count = 0;
+ }
+
+ return $gambling_count;
+
+}
+
+function get_date_joined($user) {
+ $sql_formatted_datestring = get_user_created_at($user);
+
+ return format_mysql_date($sql_formatted_datestring);
+}
+
+function format_mysql_date($sql_formatted_datestring) {
+
+ $position = strpos($sql_formatted_datestring, " ");
+ $date_string = substr($sql_formatted_datestring, 0, $position);
+
+ //format of the string now is 2007-10-19 as an example, need to rearrange
+ $date_array = explode("-", $date_string);
+ $formatted_date_string = $date_array[1] . "/" . $date_array[2] . "/" . $date_array[0];
+
+ return $formatted_date_string;
+}
+
+function get_user_created_at($user) {
+ global $DB, $memcache;
+
+ if($memcache) {
+ $created_at = $memcache->get($user . ":crtd");
+ if($created_at != "" and !is_bool($created_at)) {
+ return $created_at;
+ }
+ }
+
+ $sql = "select created_at from users where id=$user";
+ $created_at = $DB->GetOne($sql);
+
+ if($memcache) {
+ $memcache->set($user . ":crtd", $created_at, false, 3600);
+ }
+
+ return $created_at;
+}
+
+function secret_encode($string, $key)
+{
+return $string;
+/*
+require_once 'security.inc.php';
+global $salt;
+
+$key = $salt;
+//print "salt is $salt";
+$result = '';
+for($i=1; $i<=strlen($string); $i++)
+{
+$char = substr($string, $i-1, 1);
+$keychar = substr($key, ($i % strlen($key))-1, 1);
+$char = chr(ord($char)+ord($keychar));
+$result.=$char;
+}
+return $result;
+*/
+}
+
+function secret_decode($string, $key)
+{
+return $string;
+/*
+require_once 'security.inc.php';
+global $salt;
+
+$key = $salt;
+
+$result = '';
+for($i=1; $i<=strlen($string); $i++)
+{
+$char = substr($string, $i-1, 1);
+$keychar = substr($key, ($i % strlen($key))-1, 1);
+$char = chr(ord($char)-ord($keychar));
+$result.=$char;
+}
+return $result;
+*/
+}
+
+function increment_gambling_count($user) {
+
+ $gambling_count = get_gambling_count($user);
+ global $memcache_temp;
+ $memcache_temp->set($user . ":gamblecount", $gambling_count + 1);
+ return true;
+
+}
+
+function update_team($user, $enemy) {
+ global $DB, $memcache;
+ if($memcache) {
+ $team = $memcache->set($user . ":t", $team);
+ }
+
+ $DB->Execute("update users set team='$enemy' where id = $user");
+}
+
+function update_coins($user, $coin) {
+ global $DB;
+ $DB->Execute("update users set coin_total=coin_total+$coin where id = $user");
+}
+
+
+
+function log_coins($user, $amount, $action, $secondary_user = 0) {
+ if (!in_array($user, get_audited_users_ids())) {
+ return;
+ }
+ global $DB;
+ if(is_null($secondary_user)) {
+ $secondary_user = 0;
+ }
+
+ $coin_total = get_coin_total($user);
+ $buried_coin_total = get_coin_total_buried($user);
+
+ $action = $action . ' mile: ' . get_miles_traveled($user);
+ $DB->Execute("insert into coin_log (user_id, amount, date, action, secondary_user, current_coin_total, current_buried_coin_total) values(?, ?, now(), ?, ?, ?, ?)", array($user, $amount, $action, $secondary_user, $coin_total, $buried_coin_total));
+
+}
+
+function log_levels($user, $action, $secondary_user = 0) {
+ if (!in_array($user, get_audited_users_ids())) {
+ return;
+ }
+ global $DB;
+ if(is_null($secondary_user)) {
+ $secondary_user = 0;
+ }
+ $action = $action . ' mile: ' . get_miles_traveled($user);
+ $DB->Execute("insert into level_log (user_id, date, action, secondary_user) values(?, now(), ?, ?)", array($user, $action, $secondary_user));
+
+}
+
+
+
+function set_coins($user, $coin) {
+ if($coin < 0) {
+ $coin = 0;
+ }
+ global $DB;
+ $DB->Execute("update users set coin_total=$coin where id = $user");
+}
+
+function update_action($user, $action) {
+ global $DB, $memcache;
+ if($memcache) {
+ $team = $memcache->set($user . ":a", $action);
+ $DB->Execute("update users set current_action='$action' where id = $user");
+ }
+ else {
+ $DB->Execute("update users set current_action='$action' where id = $user");
+ }
+}
+
+function update_secondary_action($user, $action) {
+ global $DB, $memcache;
+ if($memcache) {
+ $team = $memcache->set($user . ":se", $action);
+ $DB->Execute("update users set secondary_action='$action' where id = $user");
+ }
+ else {
+ $DB->Execute("update users set secondary_action='$action' where id = $user");
+ }
+}
+
+function get_current_action($user) {
+ global $memcache;
+
+ if($memcache) {
+ $team = $memcache->get($user . ":a");
+ return $team;
+ }
+ else {
+ global $DB;
+ $sql = "select current_action from users where id=$user";
+ $r = $DB->GetOne($sql);
+ $team = $memcache->set($user . ":a", $r);
+ return $r;
+ }
+}
+
+
+function get_secondary_action($user) {
+ global $memcache;
+
+ if($memcache) {
+ $team = $memcache->get($user . ":se");
+ return $team;
+ }
+ else {
+ global $DB;
+ $sql = "select secondary_action from users where id=$user";
+ $r = $DB->GetOne($sql);
+ $team = $memcache->set($user . ":se", $r);
+ return $r;
+ }
+}
+
+
+function calculate_and_get_level($user) {
+ global $DB;
+ $sql = "select count(*) from users where path like '%$user/%'";
+ //print $sql;
+ $count= $DB->GetOne($sql);
+ $DB->Execute("update users set level=$count, level_is_correct=1 where id = $user");
+ return $count;
+}
+
+function get_level($user) {
+ if($user == NULL) {
+ return '';
+ }
+ global $memcache, $DB;
+
+ if(false) { //todo turn memcache back on
+ //if($memcache) {
+ $level = $memcache->get($user . ":l");
+ //echo "team from memcache is: $team";
+ if($level == FALSE) {
+ $sql = "select level from users where id = ?";
+ $v = $DB->GetOne($sql, array($user));
+ $memcache->set($user . ":l", $v, FALSE, 600);
+ return $v;
+ }
+ return $level;
+ }
+
+ global $DB;
+ $sql = "select level from users where id = $user";
+ return $DB->GetOne($sql);
+}
+
+function get_too_many_miles_msg($user) {
+ //if(get_level($user) < 20) {
+ //increase_level($user);
+ // echo "You leveled up! ";
+
+ //}
+ $milesMax = get_max_miles($user);
+ global $base_url;
+ $adsense_ads = '
';
+
+ $out = '
You\'ve sailed ';
+ $out .= "$milesMax nautical miles ";
+ $out .="Yarrr crew demands rest, rum, and wenches! (resets every hour )";
+
+ $out .= " ";
+ $out .=" ";
+
+ //$out .= '
';
+ //print "$base_url/money/neverblue.php";
+ //$url = "$base_url/money/neverblue.php";
+
+ //$out .= $adsense_ads;
+
+ //$out .= "
Happy Halloween! Get Yer Halloween Costume Avatar! ";
+
+ //$out .= "
";
+
+ return $out;
+}
+
+function set_damage($user, $damage) {
+ global $DB;
+
+ $level = get_level($user);
+ //safety checks to prevent errors
+ if($damage > $level) {
+ $damage = $level;
+ }
+ else if($damage < 0) {
+ $damage = 0;
+ }
+
+ $sql = 'update users set damage = ? where id = ?';
+ $DB->Execute($sql, array($damage, $user));
+
+ return $s;
+}
+
+function set_level($user, $l) {
+
+ global $memcache, $DB;
+ if($memcache) {
+ $s = $memcache->set($user . ":l", $l);
+ }
+
+
+ $sql = 'update users set level = ? where id = ?';
+ $DB->Execute($sql, array($l, $user));
+
+
+ return $s;
+}
+
+//not that important, just store in memcache
+function set_captcha_fail_count($user, $fail_count) {
+ global $memcache;
+ if($memcache) {
+ $s = $memcache->set($user . ":f", $fail_count);
+ }
+}
+
+//not that important, just store in memcache
+function get_captcha_fail_count($user) {
+ global $memcache;
+ if($memcache) {
+ $fail_count = $memcache->get($user . ":f");
+ }
+
+ if($fail_count == FALSE) {
+ $fail_count = 0;
+ }
+
+ return $fail_count;
+}
+
+function get_damage($user) {
+ global $DB;
+
+ $sql = "select damage from users where id = $user";
+ return $DB->GetOne($sql);
+}
+
+function level_is_correct($user) {
+ global $DB;
+ $sql = "select level_is_correct from users where id=$user";
+ return $DB->GetOne($sql);
+}
+
+function is_user_in_db($user) {
+ global $DB;
+ $sql = "select count(*) from users where id = $user";
+ $count= $DB->GetOne($sql);
+ return $count;
+}
+
+function user_already_recruited($user) {
+ global $DB;
+ $c = $DB->GetOne("select count(*) from users where id = $user");
+ if($c !=0 ) {
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+}
+
+
+function get_buccaneer_count() {
+ return false;
+ global $memcache, $DB;
+ $r = $memcache->get("buccaneer_count");
+ if($r == FALSE) {
+ $r = $DB->GetOne("select count(*) from users where team = 'buccaneer'");
+
+ $memcache->set("buccaneer_count", $r, FALSE, 36000 * 6);
+ }
+
+ return $r;
+}
+
+function get_corsair_count() {
+ return false;
+ global $memcache, $DB;
+ $r = $memcache->get("corsair_count");
+ if($r == FALSE) {
+ $r = $DB->GetOne("select count(*) from users where team = 'corsair'");
+
+ $memcache->set("corsair_count", $r, false, 36000 * 6);
+ }
+
+ return $r;
+}
+
+function get_barbary_count() {
+ return false;
+ global $memcache, $DB;
+ $r = $memcache->get("barbary_count");
+ if($r == FALSE) {
+ $r = $DB->GetOne("select count(*) from users where team = 'barbary'");
+
+ $memcache->set("barbary_count", $r, false, 36000 * 6);
+ }
+
+ return $r;
+}
+
+function kill_crewmember($user_id) {
+ global $DB;
+ $upgrade_name = "crew";
+ $sql = "insert into upgrades (user_id, upgrade_name, created_at) values(?, ?, now()) on duplicate key update level = level-1";
+
+ $result = $DB->Execute($sql, array($user_id, $upgrade_name));
+
+}
+
+function kill_crewmembers($user_id, $how_many) {
+ global $DB;
+ $upgrade_name = "crew";
+ $sql = "insert into upgrades (user_id, upgrade_name, created_at) values(?, ?, now()) on duplicate key update level = level-?";
+
+ $result = $DB->Execute($sql, array($user_id, $upgrade_name, $how_many));
+
+}
+
+function buy_upgrade($user_id, $upgrade_name) {
+ global $DB;
+ $DB->StartTrans();
+ $sql = "insert into upgrades (user_id, upgrade_name, created_at) values(?, ?, now()) on duplicate key update level = level+1";
+
+
+ $result = $DB->Execute($sql, array($user_id, $upgrade_name));
+ $DB->FailTrans();
+
+}
+
+function buy_upgrade_transaction($user_id, $upgrade_name, $cost) {
+
+ global $DBNoPersist;
+
+ $DBNoPersist->StartTrans();
+
+ $ok = $DBNoPersist->Execute("update users set coin_total=coin_total-$cost where id = $user_id");
+
+ $sql = "insert into upgrades (user_id, upgrade_name, created_at) values(?, ?, now()) on duplicate key update level = level+1";
+
+ $ok = $DBNoPersist->Execute($sql, array($user_id, $upgrade_name));
+ $DBNoPersist->CompleteTrans();
+
+}
+
+function get_upgrades($user) {
+ global $DB;
+ $sql = "select upgrade_name, level from upgrades where user_id = $user";
+ //print $sql;
+ return $DB->GetArray($sql);
+}
+
+function get_cannons($user) {
+ global $DB;
+ $sql = "select level from upgrades where user_id = $user and upgrade_name = 'cannons'";
+ return $DB->GetOne($sql);
+}
+
+function get_hull($user) {
+ global $DB;
+ $sql = "select level from upgrades where user_id = $user and upgrade_name = 'hull'";
+ return $DB->GetOne($sql);
+}
+
+function get_crew_count($user) {
+ global $DB;
+ return $DB->GetOne('select level from upgrades where user_id = ? and upgrade_name = "crew"', array($user));
+}
+
+function get_army($user) {
+ global $DB;
+ $sql = "select name, level, id from users where path like '%$user/%'";
+ //print $sql;
+ return $DB->GetArray($sql);
+}
+
+function get_days_ago_infected($user) {
+ global $DB;
+ $sql = "select created_at from users where id=$user";
+ $created = $DB->GetOne($sql);
+ $a = relative_date($nnnew_created);
+ return $a;
+}
+
+function time_left_of_1week($posted_date) {
+ global $memcache, $outlaws_memcache, $DB;
+
+ $posted_date = str_replace("-", "", $posted_date);
+ $posted_date = str_replace(":", "", $posted_date);
+ $posted_date = str_replace(" ", "", $posted_date);
+
+ $in_seconds = strtotime(substr($posted_date,0,8).' '.
+ substr($posted_date,8,2).':'.
+ substr($posted_date,10,2).':'.
+ substr($posted_date,12,2));
+
+// $now_string = $memcache->get($outlaws_memcache . ":time");
+
+ //get the current time from the db
+ if($now_string == false) {
+ $sql = "select now()";
+ try {
+ $now_string = $DB->GetOne($sql);
+ } catch (Exception $e) {
+ return "Unknown";
+ }
+// $memcache->set($outlaws_memcache . ":time", $now_string, false, 30); //expire after 30 seconds
+ }
+
+ $now_string = str_replace("-", "", $now_string);
+ $now_string = str_replace(":", "", $now_string);
+ $now_string = str_replace(" ", "", $now_string);
+
+ $now_time = strtotime(substr($now_string,0,8).' '.
+ substr($now_string,8,2).':'.
+ substr($now_string,10,2).':'.
+ substr($now_string,12,2));
+
+ $now_time = $now_time + 31;
+
+ $diff = $now_time - $in_seconds;
+ $months = floor($diff/2592000);
+ $diff -= $months*2419200;
+ $weeks = floor($diff/604800);
+ $diff -= $weeks*604800;
+ $days = floor($diff/86400);
+ $diff -= $days*86400;
+ $hours = floor($diff/3600);
+ $diff -= $hours*3600;
+ $minutes = floor($diff/60);
+ $diff -= $minutes*60;
+ $seconds = $diff;
+
+ //24 hours == 1440 minutes
+ $minutes_difference = (($days * 24) * 60) + $hours * 60 + $minutes;
+ $time_left = (1440 * 7) - $minutes_difference;
+ $days_left = floor(floor($time_left / 60) / 24);
+ $hours_left = floor(($time_left - ($days_left * 24 * 60)) / 60);
+ $minutes_left = $time_left - ($hours_left * 60) - ($days_left * 24 * 60);
+
+ if($days_left == 1) {
+ echo $days_left . " day ";
+ } else if($days_left > 0) {
+ echo $days_left . " days ";
+ }
+
+ if($hours_left == 1) {
+ echo $hours_left . " hour ";
+ } else if($hours_left > 0) {
+ echo $hours_left . " hours ";
+ }
+
+ if($minutes_left == 1) {
+ echo $minutes_left . " minute";
+ } else if($minutes_left > 0) {
+ echo $minutes_left . " minutes";
+ }
+}
+
+function time_left_of_24hours($posted_date) {
+ global $memcache, $DB;
+
+ $posted_date = str_replace("-", "", $posted_date);
+ $posted_date = str_replace(":", "", $posted_date);
+ $posted_date = str_replace(" ", "", $posted_date);
+
+ $in_seconds = strtotime(substr($posted_date,0,8).' '.
+ substr($posted_date,8,2).':'.
+ substr($posted_date,10,2).':'.
+ substr($posted_date,12,2));
+
+ $now_string = $memcache->get(":time");
+
+ //get the current time from the db
+ if($now_string == false) {
+ $sql = "select now()";
+ try {
+ $now_string = $DB->GetOne($sql);
+ } catch (Exception $e) {
+ return "Unknown";
+ }
+ $memcache->set(":time", $now_string, false, 30); //expire after 30 seconds
+ }
+
+ $now_string = str_replace("-", "", $now_string);
+ $now_string = str_replace(":", "", $now_string);
+ $now_string = str_replace(" ", "", $now_string);
+
+ $now_time = strtotime(substr($now_string,0,8).' '.
+ substr($now_string,8,2).':'.
+ substr($now_string,10,2).':'.
+ substr($now_string,12,2));
+
+ $now_time = $now_time + 31;
+
+ $diff = $now_time - $in_seconds;
+ $months = floor($diff/2592000);
+ $diff -= $months*2419200;
+ $weeks = floor($diff/604800);
+ $diff -= $weeks*604800;
+ $days = floor($diff/86400);
+ $diff -= $days*86400;
+ $hours = floor($diff/3600);
+ $diff -= $hours*3600;
+ $minutes = floor($diff/60);
+ $diff -= $minutes*60;
+ $seconds = $diff;
+
+ //24 hours == 1440 minutes
+ $minutes_difference = $hours * 60 + $minutes;
+ $time_left = 1440 - $minutes_difference;
+ $hours_left = floor($time_left / 60);
+ $minutes_left = $time_left - ($hours_left * 60);
+ if($hours_left > 0) {
+ echo $hours_left . " hours ";
+ }
+ else if($hours_left == 1) {
+ echo $hours_left . " hour ";
+ }
+
+ if($minutes > 0) {
+ echo $minutes_left . " minutes";
+ }
+ else if($minutes_left == 1) {
+ echo $minutes_left . " minute";
+ }
+}
+
+function relative_date($posted_date, $two) {
+ /**
+ This function returns either a relative date or a formatted date depending
+ on the difference between the current datetime and the datetime passed.
+ $posted_date should be in the following format: YYYYMMDDHHMMSS
+
+ Relative dates look something like this:
+ 3 weeks, 4 days ago
+ Formatted dates look like this:
+ on 02/18/2004
+
+ The function includes 'ago' or 'on' and assumes you'll properly add a word
+ like 'Posted ' before the function output.
+ **/
+
+ $posted_date = str_replace("-", "", $posted_date);
+ $posted_date = str_replace(":", "", $posted_date);
+ $posted_date = str_replace(" ", "", $posted_date);
+
+ $in_seconds = strtotime(substr($posted_date,0,8).' '.
+ substr($posted_date,8,2).':'.
+ substr($posted_date,10,2).':'.
+ substr($posted_date,12,2));
+ $two_in_seconds = strtotime(substr($two,0,8).' '.
+ substr($two,8,2).':'.
+ substr($two,10,2).':'.
+ substr($two,12,2));
+ //its one hour off for the racing stuff...can't use this function anywhere else for now
+ $diff = $two_in_seconds-$in_seconds;
+ $months = floor($diff/2592000);
+ $diff -= $months*2419200;
+ $weeks = floor($diff/604800);
+ $diff -= $weeks*604800;
+ $days = floor($diff/86400);
+ $diff -= $days*86400;
+ $hours = floor($diff/3600);
+ $diff -= $hours*3600;
+ $minutes = floor($diff/60);
+ $diff -= $minutes*60;
+ $seconds = 60*60 - $diff; //changed!!
+
+ if ($months>0) {
+ // over a month old, just show date (mm/dd/yyyy format)
+ return 'on '.substr($posted_date,4,2).'/'.substr($posted_date,6,2).'/'.substr($posted_date,0,4);
+ } else {
+ if ($weeks>0) {
+ // weeks and days
+ $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks>1?'s':'');
+ $relative_date .= $days>0?($relative_date?', ':'').$days.' day'.($days>1?'s':''):'';
+ } elseif ($days>0) {
+ // days and hours
+ $relative_date .= ($relative_date?', ':'').$days.' day'.($days>1?'s':'');
+ $relative_date .= $hours>0?($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''):'';
+ } elseif ($hours>0) {
+ // hours and minutes
+ $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours>1?'s':'');
+ $relative_date .= $minutes>0?($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''):'';
+ } elseif ($minutes>0) {
+ // minutes only
+ $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':'');
+ } else {
+ // seconds only
+ //$relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':'');
+ $relative_date = round($seconds / 60) . ' minutes';
+ }
+ }
+ // show relative date and add proper verbiage
+ return $relative_date;
+}
+
+
+function get_infector($user) {
+ global $DB;
+ $sql = "select recruited_by from users where id=$user";
+ return $DB->GetOne($sql);
+}
+
+
+
+function friend_count_not_infected($user) {
+ global $facebook, $DB;
+ $friend_ids = $facebook->api_client->friends_get();
+ //print_r($friend_ids);
+ $friend_string = implode(', ', $friend_ids);
+
+ //get friendcount of this user in our db (regardless of type)
+ $sql = "select count(*) from users where id in ($friend_string)";
+ //print $sql;
+ $friends_in_db_count = $DB->GetOne($sql);
+
+ return sizeof($friend_ids) - $friends_in_db_count;
+
+}
+
+
+
+
+
+/*
+get bucaneer, barbary, or corsair for a user. if we dont have the user, random
+*/
+function get_team($user) {
+ if($user == '') {
+ return;
+ }
+ global $DB, $memcache;
+ //this translation stuff sucks...
+ //TODO switch the database to use the letters too..
+
+ if($memcache) {
+ $team = $memcache->get($user . ":t");
+ //echo "team from memcache is: $team";
+ if($team == 'u') {
+ return 'buccaneer';
+ }
+ else if($team == 'c') {
+ return 'corsair';
+ }
+ else if($team == 'a') {
+ return 'barbary';
+ }
+ }
+
+
+ $query = "SELECT team FROM users WHERE id=" . $user;
+ $value = $DB->GetOne($query);
+
+ if($memcache) {
+ if($value == 'buccaneer') {
+ $v_to_store = 'u';
+ }
+ else if($value == 'corsair') {
+ $v_to_store = 'c';
+ }
+ else if($value == 'barbary') {
+ $v_to_store = 'a';
+ }
+
+ $memcache->add($user . ":t", $v_to_store);
+ //echo "setting team in memcache: $value";
+
+ }
+
+ //lazy fix to buccaneer mispelling
+ if($value == 'bucaneer') {
+ $value = 'buccaneer';
+ }
+
+ return $value;
+
+ /*
+ if ($value != null)
+ return $value;
+ else
+ {
+ $ra= rand(1,100);
+
+ if($ra < 33) {
+ return 'bucaneer';
+ }
+
+ else if($ra < 33) {
+ return 'barbary';
+ }
+
+ else {
+ return 'corsair';
+ }
+ }
+ */
+
+
+}
+
+
+function get_team_random($who) {
+ global $DB;
+ $query = "SELECT team FROM users WHERE id=" . $who;
+ $value = $DB->GetOne($query);
+ return $value;
+
+}
+
+
+
+// Returns an array of friends who you have the program installed
+
+function get_installed_friends()
+{
+ global $facebook, $DB;
+ $friends = $facebook->api_client->friends_get();
+ $installedFriends = array();
+ foreach ($friends as $value)
+ {
+ //SELECT id, name, type, level
+ if (($friend = $DB->GetRow("SELECT id FROM users WHERE id = '". $value . "'")) != null)
+ {
+ $installedFriends[] = $friend[0];
+
+ }
+
+ }
+
+ //print_r($installedFriends);
+ return $installedFriends;
+}
+
+function get_profile_box($user) {
+
+
+ global $network_id, $facebook, $facebook_canvas_url, $base_url;
+ if($network_id == 1) {
+ return;
+ }
+
+ $level = get_level($user);
+ //$type = get_type_for($user);
+ //$type_name = get_type_name_for($user);
+ $team = ucwords(get_team($user));
+ $coins = number_format(get_coin_total($user));
+ $buried_coins = number_format(get_coin_total_buried($user));
+ global $DB, $memcache;
+
+ $joke_on = get_joke_on($user);
+
+ if($joke_on == 1) {
+ $ra = rand(1,get_total_joke_count());
+ $r = $DB->GetRow('select * from jokes_approved where id = ?', array($ra));
+
+ $question =$r['question'];
+ $answer =$r['answer'];
+ //$user =$r['user'];
+ }
+
+
+ $use_old_image = get_use_old_image($user);
+
+ if($use_old_image == 0) {
+
+ $gender = get_gender($user);
+ if($gender == 'f') {
+ $genderlong = 'female';
+ }
+ else {
+ $genderlong = 'male';
+ }
+
+ if($level > 200) {
+ $levelrank = 3;
+ }
+ else if($level > 50) {
+ $levelrank = 2;
+ }
+
+ else {
+ $levelrank =1;
+ }
+ $imagefile = "pirate_" . $genderlong . "_" . $levelrank .".jpg";
+ }
+ else {
+ $imagefile = 'Piratey.jpg';
+ }
+
+ //$type_name_plural = get_type_name_plural_for($user);
+ $fbml = "
Shiver me timbers! ";
+ if($use_old_image == 0) {
+ $fbml .= " ";
+ }
+ else {
+ $fbml .= " ";
+
+ }
+
+ $fbml .= "It's Cap'n ";
+ $fbml .="A Level $level $team Pirate ";
+ $fbml .= "coins: $coins buried: $buried_coins
";
+
+ if($joke_on == 1) {
+ $fbml .= "
hide jokes ";
+
+
+
+ $fbml .="
";
+
+ }
+//print $fbml;
+return $fbml;
+ //$facebook->api_client->profile_setFBML($fbml, $user);
+///return "
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Pick a Race:
+
+
+
+
+
+
+
+ Race Winners (last 50)
+
+
+
+
+
+ ";
+ $r = $DB->GetArray('select race_results.created_at c, users.team, users.level, race_results.user_id, users.id, race_results.jackpot, race_results.created_at from race_results, users where type = ? and users.id = race_results.user_id order by race_results.created_at desc limit 50', array($animal_char));
+ foreach($r as $key => $value) {
+ $id = $value['user_id'];
+ $level = $value['level'];
+ $team = $value['team'];
+ $created_at = date("F j, Y h:i", strtotime($value['c']));
+ $jackpot = $value['jackpot'];
+ $team = ucwords($team);
+ $buried_coin_total = $value['buried_coin_total'];
+ $rank = $key + 1;
+ echo "";
+ echo " ";
+ $n_jackpot = number_format($jackpot);
+ echo " Jackpot: $n_jackpot coins $created_at ";
+ echo " ";
+ }
+ echo "
";
+
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Pirate Pet Racing Board
+
+
+
+
+
+
+ Congratulations to the latest Pirate Race Winners
+
+ 's Parrot won coins!
+
+ 's Monkey won coins!
+
+
+
+
+
+
+
+
+
+Go back to sea -adventure, danger and treasure await
+
+
+
+
+
+
+';
+?>
+
\ No newline at end of file
diff --git a/races_action.php b/races_action.php
new file mode 100644
index 0000000..9e34c83
--- /dev/null
+++ b/races_action.php
@@ -0,0 +1,58 @@
+redirect("races.php?msg=not-enough-$type&item=$item_id");
+
+}
+
+//check if they got the money
+if(get_coin_total($user) < $price) {
+ $facebook->redirect("races.php?msg=not-enough-money&item=$item_id");
+}
+
+//check if they already entered, if not redirect back to races.php
+if(!user_can_enter_race($user, $type)) {
+ $facebook->redirect("races.php?msg=already-entered-$type&item=$item_id");
+
+}
+
+
+//deduct racing fee
+set_coins($user, get_coin_total($user) - $price);
+log_coins($user, -$price, 'bought race entry');
+
+
+
+//insert the race entry
+$sql = 'insert into races (user_id, type, completed, created_at) values(?, ?, 0, now())';
+$DB->Execute($sql, array($user, $type));
+
+//print_r($_REQUEST);
+
+$facebook->redirect("races.php?msg=$type-entered-in-race&item=$item_id");
+
+//print $friend_selector_id;
+
+
+
+
+
+ ?>
\ No newline at end of file
diff --git a/recaptchalib.php b/recaptchalib.php
new file mode 100644
index 0000000..aea6e0d
--- /dev/null
+++ b/recaptchalib.php
@@ -0,0 +1,276 @@
+ $value )
+ $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
+
+ // Cut the last '&'
+ $req=substr($req,0,strlen($req)-1);
+ return $req;
+}
+
+
+
+/**
+ * Submits an HTTP POST to a reCAPTCHA server
+ * @param string $host
+ * @param string $path
+ * @param array $data
+ * @param int port
+ * @return array response
+ */
+function _recaptcha_http_post($host, $path, $data, $port = 80) {
+
+ $req = _recaptcha_qsencode ($data);
+
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
+ $http_request .= "Content-Length: " . strlen($req) . "\r\n";
+ $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $req;
+
+ $response = '';
+ if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
+ die ('Could not open socket');
+ }
+
+ fwrite($fs, $http_request);
+
+ while ( !feof($fs) )
+ $response .= fgets($fs, 1160); // One TCP-IP packet
+ fclose($fs);
+ $response = explode("\r\n\r\n", $response, 2);
+
+ return $response;
+}
+
+
+
+/**
+ * Gets the challenge HTML (javascript and non-javascript version).
+ * This is called from the browser, and the resulting reCAPTCHA HTML widget
+ * is embedded within the HTML form it was called from.
+ * @param string $pubkey A public key for reCAPTCHA
+ * @param string $error The error given by reCAPTCHA (optional, default is null)
+ * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
+
+ * @return string - The HTML to be embedded in the user's form.
+ */
+function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
+{
+ if ($pubkey == null || $pubkey == '') {
+ die ("To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey ");
+ }
+
+ if ($use_ssl) {
+ $server = RECAPTCHA_API_SECURE_SERVER;
+ } else {
+ $server = RECAPTCHA_API_SERVER;
+ }
+
+ $errorpart = "";
+ if ($error) {
+ $errorpart = "&error=" . $error;
+ }
+ return '
+
+
+
+
+
+ ';
+}
+
+
+
+
+/**
+ * A ReCaptchaResponse is returned from recaptcha_check_answer()
+ */
+class ReCaptchaResponse {
+ var $is_valid;
+ var $error;
+}
+
+
+/**
+ * Calls an HTTP POST function to verify if the user's guess was correct
+ * @param string $privkey
+ * @param string $remoteip
+ * @param string $challenge
+ * @param string $response
+ * @return ReCaptchaResponse
+ */
+function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response)
+{
+ if ($privkey == null || $privkey == '') {
+ die ("To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey ");
+ }
+
+ if ($remoteip == null || $remoteip == '') {
+ die ("For security reasons, you must pass the remote ip to reCAPTCHA");
+ }
+
+
+
+ //discard spam submissions
+ if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
+ $recaptcha_response = new ReCaptchaResponse();
+ $recaptcha_response->is_valid = false;
+ $recaptcha_response->error = 'incorrect-captcha-sol';
+ return $recaptcha_response;
+ }
+
+ $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/verify",
+ array (
+ 'privatekey' => $privkey,
+ 'remoteip' => $remoteip,
+ 'challenge' => $challenge,
+ 'response' => $response
+ )
+ );
+
+ $answers = explode ("\n", $response [1]);
+ $recaptcha_response = new ReCaptchaResponse();
+
+ if (trim ($answers [0]) == 'true') {
+ $recaptcha_response->is_valid = true;
+ }
+ else {
+ $recaptcha_response->is_valid = false;
+ $recaptcha_response->error = $answers [1];
+ }
+ return $recaptcha_response;
+
+}
+
+/**
+ * gets a URL where the user can sign up for reCAPTCHA. If your application
+ * has a configuration page where you enter a key, you should provide a link
+ * using this function.
+ * @param string $domain The domain where the page is hosted
+ * @param string $appname The name of your application
+ */
+function recaptcha_get_signup_url ($domain = null, $appname = null) {
+ return "http://recaptcha.net/api/getkey?" . _recaptcha_qsencode (array ('domain' => $domain, 'app' => $appname));
+}
+
+function _recaptcha_aes_pad($val) {
+ $block_size = 16;
+ $numpad = $block_size - (strlen ($val) % $block_size);
+ return str_pad($val, strlen ($val) + $numpad, chr($numpad));
+}
+
+/* Mailhide related code */
+
+function _recaptcha_aes_encrypt($val,$ky) {
+ if (! function_exists ("mcrypt_encrypt")) {
+ die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
+ }
+ $mode=MCRYPT_MODE_CBC;
+ $enc=MCRYPT_RIJNDAEL_128;
+ $val=_recaptcha_aes_pad($val);
+ return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
+}
+
+
+function _recaptcha_mailhide_urlbase64 ($x) {
+ return strtr(base64_encode ($x), '+/', '-_');
+}
+
+/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
+function recaptcha_mailhide_url($pubkey, $privkey, $email) {
+ if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
+ die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
+ "you can do so at http://mailhide.recaptcha.net/apikey ");
+ }
+
+
+ $ky = pack('H*', $privkey);
+ $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
+
+ return "http://mailhide.recaptcha.net/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
+}
+
+/**
+ * gets the parts of the email to expose to the user.
+ * eg, given johndoe@example,com return ["john", "example.com"].
+ * the email is then displayed as john...@example.com
+ */
+function _recaptcha_mailhide_email_parts ($email) {
+ $arr = preg_split("/@/", $email );
+
+ if (strlen ($arr[0]) <= 4) {
+ $arr[0] = substr ($arr[0], 0, 1);
+ } else if (strlen ($arr[0]) <= 6) {
+ $arr[0] = substr ($arr[0], 0, 3);
+ } else {
+ $arr[0] = substr ($arr[0], 0, 4);
+ }
+ return $arr;
+}
+
+/**
+ * Gets html to display an email address given a public an private key.
+ * to get a key, go to:
+ *
+ * http://mailhide.recaptcha.net/apikey
+ */
+function recaptcha_mailhide_html($pubkey, $privkey, $email) {
+ $emailparts = _recaptcha_mailhide_email_parts ($email);
+ $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
+
+ return htmlentities($emailparts[0]) . "... @" . htmlentities ($emailparts [1]);
+
+}
+
+
+?>
diff --git a/recruit.php b/recruit.php
new file mode 100644
index 0000000..416c215
--- /dev/null
+++ b/recruit.php
@@ -0,0 +1,61 @@
+api_client->fql_query("SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = $user)");
+$arFriends = "";
+
+// Build an delimited list of users...
+if ($rs)
+{
+ for ( $i = 0; $i < count($rs); $i++ )
+ {
+ if ( $arFriends != "" )
+ $arFriends .= ",";
+
+ $arFriends .= $rs[$i]["uid"];
+ }
+}
+
+$sNextUrl = urlencode("?i=".$user);
+
+// Build your invite text
+$invfbml = <<
+ wants you to become a Pirate. Pillage, plunder, and sail on the high seas!
+
+FBML;
+?>
+
+
+
+
+
+
+
+
+Give yer mates this link to recruit em!
+
+
+
+
+
+For every friend that joins, you'll gain one level! For every friend your friend recruits you'll also get a level.
+
+
+
+
+
diff --git a/recruit_action.php b/recruit_action.php
new file mode 100644
index 0000000..fd9441c
--- /dev/null
+++ b/recruit_action.php
@@ -0,0 +1,60 @@
+';
+
+ }
+ foreach ($inviteList as $value)
+ {
+ $query = "INSERT INTO invite_requests (from_id, to_id, created_at) VALUES ('". $user . "', '" . $value . "', now())";
+ $DB->Execute($query);
+ }
+
+ //print_r($REQUEST);
+ //echo "inviteLLIST; " . sizeof($inviteList);
+ if(sizeof($inviteList) == 0) {
+ //$facebook->redirect("$facebook_canvas_url/recruit.php");
+ die("OK");
+ }
+ //print_r($inviteList);
+
+ $to = $inviteList;
+ //$vorw = get_type_for($user);
+ $title = "Pirate"; //get_type_name_for($user);
+ $content = " Ahoy!...wanna be a pirate? Fight other pirates on the high seas of Facebook in search of booty and adventure!";
+
+
+
+ $request = "request";
+ $image = "$base_url/images/flag_200.jpg";
+ $confirmUrl = $facebook->api_client->notifications_sendRequest ($to, $title, $content, $image, $request);
+ if($confirmUrl != "") {
+ $facebook->redirect($confirmUrl);
+ }
+ else {
+ $facebook->redirect("$facebook_canvas_url/index.php?msg=send-limit");
+ }
+
+
+
+
+ ?>
\ No newline at end of file
diff --git a/remove_from_log.php b/remove_from_log.php
new file mode 100644
index 0000000..89db000
--- /dev/null
+++ b/remove_from_log.php
@@ -0,0 +1,27 @@
+redirect("logged_users.php?msg=not-authorized");
+}
+
+global $DB, $facebook;
+try {
+ $DB->Execute('delete from logged_users where id = ?', array($facebook_id));
+
+}
+catch(ADODB_Exception $e) {
+ //$facebook->redirect('start_log.php?msg=already-logged');
+}
+
+$facebook->redirect("logged_users.php?msg=log-removed&id=$facebook_id");
+
+?>
diff --git a/report_pillaging_results.php b/report_pillaging_results.php
new file mode 100644
index 0000000..76a1a66
--- /dev/null
+++ b/report_pillaging_results.php
@@ -0,0 +1,337 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$houseItem = get_item_from_memcache($user);
+
+print dashboard();
+
+ $house1 = $_REQUEST['house1'];
+ $house2 = $_REQUEST['house2'];
+ $house3 = $_REQUEST['house3'];
+ $house4 = $_REQUEST['house4'];
+ $house5 = $_REQUEST['house5'];
+ $house6 = $_REQUEST['house6'];
+ $house7 = $_REQUEST['house7'];
+ $house8 = $_REQUEST['house8'];
+ $house9 = $_REQUEST['house9'];
+ $house10 = $_REQUEST['house10'];
+ $house11 = $_REQUEST['house11'];
+ $house12 = $_REQUEST['house12'];
+ $house13 = $_REQUEST['house13'];
+ $house14 = $_REQUEST['house14'];
+ $house15 = $_REQUEST['house15'];
+ $stuff_id = $_REQUEST['stuffid'];
+
+ $house_total = $house1 + $house2 + $house3 + $house4 + $house5 + $house6 + $house7 + $house8 + $house9 + $house10 + $house11 + $house12 + $house13 + $house14 + $house15;
+
+ if($stuff_id != "none") {
+ $booty_array = get_booty_data_from_id($stuff_id);
+ $booty_name = $booty_array[0];
+ $booty_thumb_image = $booty_array[1];
+ $booty_large_image = $booty_array[2];
+ }
+
+function process_result($houseResult) {
+ if($houseResult == "nothing") {
+ $ra = rand(1,5);
+ if($ra == 1) {
+ echo "Yar, didn't attack this house";
+ }
+ if($ra == 2) {
+ echo "Your loyal dogs be skipping this one";
+ }
+ if($ra == 3) {
+ echo "This house wasn't worth the effort";
+ }
+ if($ra == 4) {
+ echo "No Captain attack order for this one";
+ }
+ if($ra == 5) {
+ echo "Only landlubbers would attack this house";
+ }
+ }
+ else if($houseResult == "item") {
+ echo "Your crew found an item!";
+ }
+ else if($houseResult == "killed") {
+ echo "The enemy captured and KILLED one of your crew! ";
+ }
+ else if($houseResult == "escapes") {
+ echo "Your crew fail, but escape with their lives";
+ }
+ else if($houseResult > 0) {
+ echo "Your crew pillaged $houseResult coins";
+ }
+ else {
+ $lostAmount = $houseResult * -1;
+ echo "Your crew lose and the enemy steals $lostAmount of your coins";
+ }
+}
+
+function process_highlight($houseResult) {
+ if($houseResult == "nothing") {
+ echo "";
+ }
+ else if($houseResult == "item") {
+ echo "style=\"background-color:#fff9d7;\"";
+ }
+ else if($houseResult == "killed") {
+ echo "style=\"background-color:#fff9d7;\"";
+ }
+ else if($houseResult == "escapes") {
+ echo "style=\"background-color:#fff9d7;\"";
+ }
+ else if($houseResult > 0) {
+ echo "style=\"background-color:#fff9d7;\"";
+ }
+ else {
+ echo "style=\"background-color:#fff9d7;\"";
+ }
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+Pillaging Results
+Ah, let's see how your scurvy scallywags have done!
+
+You now have coins
+ 0) { ?>
+ coins are buried
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ House
+
+
+ Pillage Result
+
+
+
+
+ >
+ House 1
+
+
+
+
+
+
+ >
+ House 2
+
+
+
+
+
+
+ >
+ House 3
+
+
+
+
+
+
+ >
+ House 4
+
+
+
+
+
+
+ >
+ House 5
+
+
+
+
+
+
+ >
+ House 6
+
+
+
+
+
+
+ >
+ House 7
+
+
+
+
+
+
+ >
+ House 8
+
+
+
+
+
+
+ >
+ House 9
+
+
+
+
+
+
+ >
+ House 10
+
+
+
+
+
+
+ >
+ House 11
+
+
+
+
+
+
+ >
+ House 12
+
+
+
+
+
+
+ >
+ House 13
+
+
+
+
+
+
+ >
+ House 14
+
+
+
+
+
+
+ >
+ House 15
+
+
+
+
+
+
+
+
+
+ Total
+
+ coins pillaged.
+
+
+
+
+
+
+
+
+
+
+ You won an item!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+print adsense_468($user);
+
+require_once 'footer.php'; ?>
diff --git a/retrieve_coins.php b/retrieve_coins.php
new file mode 100644
index 0000000..b6ded61
--- /dev/null
+++ b/retrieve_coins.php
@@ -0,0 +1,160 @@
+
+
+
+
+
+ $buried_coins) {
+ $how_many_to_dig = $buried_coins;
+ }
+
+ $action = "retrieved $how_many_to_dig coins";
+ log_coins($user, 0, $action);
+
+
+
+ $msg = "Ahoy! You dug up $how_many_to_dig coins.";
+
+ $sql = 'update users set coin_total = coin_total + ?, buried_coin_total=buried_coin_total - ? where id = ?';
+
+ $DB->Execute($sql, array($how_many_to_dig, $how_many_to_dig, $user));
+
+}
+else {
+ $msg = " Arrr, you have $buried_coins coins buried. How many coins do ya need to dig up?";
+}
+?>
+
+
+
+
+
+You can buy stuff at the harbor with these coins! BEWARE matey, If you go fightin' you might lose em'.
+
+
+
+
+
+
+
+
+
+}
+
+?>
+
+
+
+
+
+}
+print ' ';
+print adsense_468($user);
+?>
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/rules.php b/rules.php
new file mode 100644
index 0000000..0bafac9
--- /dev/null
+++ b/rules.php
@@ -0,0 +1,73 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$level = get_level($user);
+
+print dashboard();
+?>
+
+
+
Pirate Rules
+
+
+(1) Players must play the game fairly and honestly, not engaging in any syndicate play or the use of any auto-mated tools, whether they are your own or made by someone else.
+
+
+(2) Any player movements can be logged at any time to verify their play patterns.
+
+
+(3) Where a playing pattern may be deeemd as unusual, the "captcha" functionality can be implemented for this player for an undetermined amount of time to verfiy their playing of the game fairly. (this assumes you can do this! say every 50 miles?)
+
+
+(4) Playing as a syndicate is not allowed within the game; the definition of syndicate would be any players who are amassing benefits and passing these on to other players in a pattern determined to be consistent by the Developers.
+
+
+(5) Playing patterns unexplicably changing during any monitoring, which is not to the satisfaction of the Developers, will be deemed as breaking the rules of the game.
+
+
+(6) Players are allowed to "gift" other players with their coins through bombing in the event of, for example retiring from the game, to a maximum of 100k, providing this does not materially affect their position within the game (materially in this definition will be determined by the Developers).
+
+
+(7) The Developers reserve the right to remove levels, coins, upgrades and booty for any player determined to have broken the rules. Players will normally be given 24 hours to justify their play patterns before any action is taken although this is not a requirement in all cases.
+
+
+(8) Developers reserve the right to ban any player found to have broken any of the rules.
+
+
+(9) Players are not allowed to spam the game or other players and must treat all other players with respect while posting messages.
+
+
+(10) The Developers reserve the right to change the rules at any point without giving notice.
+
+
+
+
+
diff --git a/run_away_from_ship.php b/run_away_from_ship.php
new file mode 100644
index 0000000..b6d2b4e
--- /dev/null
+++ b/run_away_from_ship.php
@@ -0,0 +1,27 @@
+Execute("update users set user_was_attacked = '0' where id = ?", array($user));
+//set_was_attacked($user, 0);
+//set_was_bombed($user, 0);
+//clear the in progress ship battles
+
+$DB->Execute('update users set battling_enemy_id = 0 where id = ?', array($user));
+
+//print_r($result);
+
+reset_round($user);
+
+$memcache->set($user . 'merchant_ship', false);
+$memcache->set($user . 'msbh', false);
+
+$result = $DB->Execute("delete from battles where user_id = ? and result='p'", array($user));
+
+$facebook->redirect("$facebook_canvas_url/clear_action.php");
+
+
+?>
\ No newline at end of file
diff --git a/scripts/clear_all_active_battles.php b/scripts/clear_all_active_battles.php
new file mode 100644
index 0000000..d0e2e99
--- /dev/null
+++ b/scripts/clear_all_active_battles.php
@@ -0,0 +1,27 @@
+
+//decrease all users damage taken by 1 each hour
+
+include_once '../lib.php';
+include_once '../config.php';
+set_time_limit(0);
+ini_set("memory_limit","100M");
+
+
+global $DB;
+
+//every hour
+$sql = 'update users set user_in_battle = 0 ';
+$DB->Execute($sql);
+
+
+$sql = 'update users set coin_total = 0 where coin_total < 0';
+$DB->Execute($sql);
+
+$sql = "delete from battles where result = 'p'";
+$DB->Execute($sql);
+
+//every 24 hours
+//--clear the distance from home values in memcache for all users
+//--delete all battles older then 24 hours
+
+?>
\ No newline at end of file
diff --git a/scripts/clear_bombing_limit.php b/scripts/clear_bombing_limit.php
new file mode 100644
index 0000000..eae547c
--- /dev/null
+++ b/scripts/clear_bombing_limit.php
@@ -0,0 +1,19 @@
+Execute($sql);
+
+
+?>
diff --git a/scripts/clear_miles.php b/scripts/clear_miles.php
new file mode 100644
index 0000000..fdf6143
--- /dev/null
+++ b/scripts/clear_miles.php
@@ -0,0 +1,37 @@
+ 0';
+$DB->Execute($sql);
+
+$sql = 'update users set damage = 0 where damage < 0';
+$DB->Execute($sql);
+
+memcache_flush($memcache);
+
+
+?>
diff --git a/scripts/cron_script_server1.php b/scripts/cron_script_server1.php
new file mode 100644
index 0000000..69337b0
--- /dev/null
+++ b/scripts/cron_script_server1.php
@@ -0,0 +1,50 @@
+addServer('10.12.198.194', 11213);
+ //just flush the temporary stuff
+
+ $memcache_nontemp = new MemcacheWrapper('my');
+ $memcache_nontemp->addServer('10.12.198.194', 11211);
+}
+else {
+
+ $memcache = new Memcache(); //use temp for mile limits, gambing limits
+ $memcache->addServer('10.12.198.194', 11219);
+ //$memcache->addServer('10.8.50.196', 11211);
+
+ $memcache_nontemp = new Memcache();
+ $memcache_nontemp->addServer('10.12.198.194', 11211);
+
+
+
+
+
+}
+
+$memcache_nontemp->set('shipyard_down', 1, 0, 30);
+
+set_time_limit(0);
+
+//todo least() here with damage always positive
+$sql = 'update users set damage = greatest(0, damage - 50) where damage > 0';
+$DB->Execute($sql);
+
+$memcache->flush();
+
+$memcache_nontemp->set('shipyard_down', 0);
+?>
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
new file mode 100644
index 0000000..6dc1039
--- /dev/null
+++ b/scripts/deploy.sh
@@ -0,0 +1,5 @@
+#/bin/bash
+ssh root@piratewars1.piratewarsonline.com 'cd /var/www/html/pirates/fb && svn up'
+ssh root@piratewars2.piratewarsonline.com 'cd /var/www/html/pirates/fb && svn up'
+ssh root@piratewars5.piratewarsonline.com 'cd /var/www/html/pirates/fb && svn up'
+ssh root@piratewars6.piratewarsonline.com 'cd /var/www/html/pirates/fb && svn up'
diff --git a/scripts/deploy_myspace.sh b/scripts/deploy_myspace.sh
new file mode 100644
index 0000000..2bac7dc
--- /dev/null
+++ b/scripts/deploy_myspace.sh
@@ -0,0 +1,5 @@
+#/bin/bash
+ssh root@piratewars1.piratewarsonline.com 'cd /var/www/html/pirates/myspace && svn up'
+ssh root@piratewars2.piratewarsonline.com 'cd /var/www/html/pirates/myspace && svn up'
+ssh root@piratewars5.piratewarsonline.com 'cd /var/www/html/pirates/myspace && svn up'
+ssh root@piratewars6.piratewarsonline.com 'cd /var/www/html/pirates/myspace && svn up'
diff --git a/scripts/expire_old_sales_reload_buy.php b/scripts/expire_old_sales_reload_buy.php
new file mode 100644
index 0000000..ccc2a45
--- /dev/null
+++ b/scripts/expire_old_sales_reload_buy.php
@@ -0,0 +1,107 @@
+GetArray($sql, array($now_time));
+ }
+ catch (exception $e) {
+// echo "No expired!/n";
+ return false;
+ }
+
+/* for($i = 0; $i < count($returned_array); $i++) {
+ echo $i . " " . $returned_array[$i]['id'] . ":";
+ echo $i . " " . $returned_array[$i]['stuff_id'] . "\n";
+ } */
+
+ return $returned_array;
+}
+
+function delete_expired_uids_from_db($user, $now_time) {
+ global $memcache, $DB;
+
+ $sql = "delete from items_sell where created_at + INTERVAL 1 DAY <= ?;";
+
+ try {
+ $result = $DB->Execute($sql, array($now_time));
+ }
+ catch (exception $e) {
+ return false;
+ }
+
+ return true;
+}
+
+$sql = "select now()";
+$now_time = $DB->GetOne($sql);
+
+$user_array = get_expired_uids($user, $now_time);
+if($user_array == false) {
+ //done, no items have expired
+}
+else {
+ //delete items from memcache etc
+ $success = delete_expired_uids_from_db($user, $now_time);
+ $success = true;
+ if($success == true) {
+// echo "Granting items back: \n";
+ for($i = 0; $i < count($user_array); $i++) {
+ increment_booty($user_array[$i]['id'], $user_array[$i]['stuff_id']);
+
+ $returned_data = get_booty_data_from_id($user_array[$i]['stuff_id']);
+ $item_name = $returned_data[0];
+
+ try {
+ $sql = "select session_key from users where id = ?";
+ $seller_session_key = $DB->GetOne($sql, $user_array[$i]['id']);
+ }
+ catch (exception $e) {
+ //maybe no longer in our db, ignore error
+ }
+
+ try {
+ $facebook_new = new Facebook($api_key, $secret);
+ $facebook_new->set_user($user_array[$i]['id'], $seller_session_key);
+ $facebook_new->api_client->notifications_send(array($user_array[$i]['id']) , " just had an item expire on the Pirates trading post . A $item_name was not sold and was returned to your inventory!");
+ } catch (FacebookRestClientException $fb_e) {
+ //do nothing here, might not have a valid infinite session key to notify the person
+ }
+ }
+
+ $unique_array = array_unique($user_array);
+
+/* echo "\n\n";
+ for($i = 0; $i < count($unique_array); $i++) {
+ echo $i . " " . $unique_array[$i]['id'] . ":";
+ echo $i . " " . $unique_array[$i]['stuff_id'] . "\n";
+ }*/
+
+ for($i = 0; $i < count($unique_array); $i++) {
+ create_memcache_sell_items_from_db($unique_array[$i]['id']);
+ }
+ }
+ else { // do nothing, error has occured
+ }
+}
+
+/***************************************************************************************************/
+// Done Delete Expired, Start repopulate BUY system
+/***************************************************************************************************/
+$num_items = 13;
+
+for($i = 1; $i < $num_items + 1; $i++) {
+ $return_array = generate_memcache_for_buying($user, $i);
+ store_index_string_in_db($return_array[1], $i);
+}
+
+echo "\nDone Script...\n";
+?>
diff --git a/scripts/fix_booty.php b/scripts/fix_booty.php
new file mode 100644
index 0000000..09a6d12
--- /dev/null
+++ b/scripts/fix_booty.php
@@ -0,0 +1,76 @@
+Execute("delete from stuff");
+
+$sql = 'select distinct user_id from booty';
+$users = $DB->GetArray($sql);
+
+foreach($users as $key => $value) {
+ $user_id = $value['user_id'];
+ //print_r($user_id);
+ //print "user_id: $user_id\n";
+//stuff table
+//id, user_id, stuff_id, how_many, updated_at
+$sql = 'select user_id, booty_name, count(*) c from booty where user_id=? group by booty_name';
+
+$stuff = $DB->GetArray($sql, $user_id);
+
+//print_r($stuff);
+
+
+foreach($stuff as $key => $value) {
+ $booty_name = $value['booty_name'];
+ $how_many = $value['c'];
+ $user_id = $value['user_id'];
+
+ if($booty_name == 'a treasure map') {
+ $stuff_id = 1;
+ }
+ else if($booty_name == 'some gold bars') {
+ $stuff_id = 2;
+ }
+ else if($booty_name == 'a message in a bottle') {
+ $stuff_id = 3;
+ }
+ else if($booty_name == 'some dynamite') {
+ $stuff_id = 4;
+ }
+ else if($booty_name == 'a pirate flag') {
+ $stuff_id = 5;
+ }
+ else if($booty_name == 'a bomb') {
+ $stuff_id = 6;
+ }
+ //else if($booty_name == 'some pirate coins') {
+ // break;
+ //}
+
+ if($booty_name != 'some pirate coins') {
+ $sql = 'insert into stuff (user_id, stuff_id, how_many, updated_at) values (?, ?, ?, now())';
+ $DB->Execute($sql, array($user_id, $stuff_id, $how_many));
+ }
+}
+
+
+
+}
+
+
+
+?>
\ No newline at end of file
diff --git a/scripts/leaderboard_script.php b/scripts/leaderboard_script.php
new file mode 100644
index 0000000..0d6d4c8
--- /dev/null
+++ b/scripts/leaderboard_script.php
@@ -0,0 +1,323 @@
+GetArray($sql);
+
+for($ii = 0; $ii < count($person_array); $ii++) {
+ //echo "i: $ii";
+ $user_id = $person_array[$ii][0];
+ $y = $ii + 1;
+ $sql = "insert into user_ranks (user_id, overall, updated_at) values($user_id, $y, now()) on duplicate key update updated_at = now(), overall = $y";
+ $DB->Execute($sql);
+}
+
+//print_r($person_array);
+//exit();
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_overall";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_overall (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":ldrovrall", "");
+
+ /* for($j = 0; $j < count($array_chunks[$y]); $j++) {
+ $current_user = $array_chunks[$y][$j + ($y * 100)]['id'];
+ $memcache->set($current_user . ":" . $outlaws_memcache . ":ldrnotpos", "$y");
+ }*/
+ }
+}
+
+echo "Done Overall...\n";
+
+///////////////////////////////////////////////////////////////////////
+// MOST COINS /////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) ORDER BY buried_coin_total DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql);
+
+for($ii = 0; $ii < count($person_array); $ii++) {
+ //echo "i: $ii";
+ $user_id = $person_array[$ii][0];
+ $y = $ii + 1;
+ $sql = "insert into user_ranks (user_id, most_coins, updated_at) values($user_id, $y, now()) on duplicate key update updated_at = now(), most_coins = $y";
+ $DB->Execute($sql);
+}
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_most_coins";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_most_coins (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":ldrmstcoins", "");
+ }
+}
+
+echo "Done Most Coins...\n";
+
+///////////////////////////////////////////////////////////////////////
+// HIGHEST LEVEL //////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) ORDER BY level DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql);
+
+for($ii = 0; $ii < count($person_array); $ii++) {
+ //echo "i: $ii";
+ $user_id = $person_array[$ii][0];
+ $y = $ii + 1;
+ $sql = "insert into user_ranks (user_id, highest_level, updated_at) values($user_id, $y, now()) on duplicate key update updated_at = now(), highest_level = $y";
+ $DB->Execute($sql);
+}
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_highest_level";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_highest_level (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":ldrhghlvl", "");
+ }
+}
+
+echo "Done Highest Level...\n";
+
+
+
+/*****************************************************************************************/
+// TEAM SPECIFIC LEADERBOARDS //
+
+$num_teams = 3;
+for($i = 0; $i < $num_teams; $i++) {
+
+ if($i == 0) {
+ $team_name = "buccaneer";
+ //memcaches
+ $overall_memcache = "ldrovrall_buc";
+ $mostcoins_memcache = "ldrmstcoins_buc";
+ $highestlevel_memcache = "ldrhghlvl_buc";
+ } else if($i == 1) {
+ $team_name = "corsair";
+ //memcaches
+ $overall_memcache = "ldrovrall_cor";
+ $mostcoins_memcache = "ldrmstcoins_cor";
+ $highestlevel_memcache = "ldrhghlvl_cor";
+ } else if($i == 2) {
+ $team_name = "barbary";
+ //memcaches
+ $overall_memcache = "ldrovrall_bar";
+ $mostcoins_memcache = "ldrmstcoins_bar";
+ $highestlevel_memcache = "ldrhghlvl_bar";
+ }
+
+///////////////////////////////////////////////////////////////////////
+// OVERALL ////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) and team = ? ORDER BY (level * buried_coin_total) DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql, array($team_name));
+
+for($ii = 0; $ii < count($person_array); $ii++) {
+ //echo "i: $ii";
+ $user_id = $person_array[$ii][0];
+ $y = $ii + 1;
+ $sql = "insert into user_ranks (user_id, overall_team, updated_at) values($user_id, $y, now()) on duplicate key update updated_at = now(), overall_team = $y";
+ $DB->Execute($sql);
+}
+
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+
+$sql = "TRUNCATE TABLE leader_" . $team_name . "_overall";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_" . $team_name . "_overall (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":$overall_memcache", "");
+ }
+}
+
+echo "Done $team_name Overall...\n";
+
+///////////////////////////////////////////////////////////////////////
+// MOST COINS /////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) and team = ? ORDER BY buried_coin_total DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql, array($team_name));
+
+for($ii = 0; $ii < count($person_array); $ii++) {
+ //echo "i: $ii";
+ $user_id = $person_array[$ii][0];
+ $y = $ii + 1;
+ $sql = "insert into user_ranks (user_id, most_coins_team, updated_at) values($user_id, $y, now()) on duplicate key update updated_at = now(), most_coins_team = $y";
+ $DB->Execute($sql);
+}
+
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_" . $team_name . "_most_coins";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_" . $team_name . "_most_coins (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":$mostcoins_memcache", "");
+ }
+}
+
+echo "Done $team_name Most Coins...\n";
+
+///////////////////////////////////////////////////////////////////////
+// HIGHEST LEVEL //////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) and team = ? ORDER BY level DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql, array($team_name));
+
+for($ii = 0; $ii < count($person_array); $ii++) {
+ //echo "i: $ii";
+ $user_id = $person_array[$ii][0];
+ $y = $ii + 1;
+ $sql = "insert into user_ranks (user_id, highest_level_team, updated_at) values($user_id, $y, now()) on duplicate key update updated_at = now(), highest_level_team = $y";
+ $DB->Execute($sql);
+}
+
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_" . $team_name . "_highest_level";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_" . $team_name . "_highest_level (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":$highestlevel_memcache", "");
+ }
+}
+
+echo "Done $team_name Highest Level...\n";
+
+}
+
+// END TEAM SPECIFIC LEADERBOARDS
+/*****************************************************************************************/
+
+/*****************************************************************************************/
+// WEEKLY LEADERBOARDS //
+
+///////////////////////////////////////////////////////////////////////
+// OVERALL MILES //////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) ORDER BY weekly_miles DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql);
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_weekly_miles";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_weekly_miles (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":ldrweeklymiles", "");
+ }
+}
+
+echo "Done Weekly Miles...\n";
+
+///////////////////////////////////////////////////////////////////////
+// WEEKLY MONEY ///////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) ORDER BY ((buried_coin_total + coin_total) - weekly_money) DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql);
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_weekly_money";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_weekly_money (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":ldrweeklymoney", "");
+ }
+}
+
+echo "Done Weekly Money...\n";
+
+///////////////////////////////////////////////////////////////////////
+// WEEKLY LEVEL ///////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "SELECT id FROM users where id not in(select id from banned) ORDER BY ((level) - weekly_level) DESC LIMIT 0,9999";
+$person_array = $DB->GetArray($sql);
+
+$array_chunks = array_chunk($person_array, $num_per_chunk, true);
+
+//before we start inserting stuff, lets empty the db table of old stuff
+$sql = "TRUNCATE TABLE leader_weekly_level";
+$DB->Execute($sql);
+
+for($y = 0; $y < count($array_chunks); $y++) {
+ $sql = "insert into leader_weekly_level (array_data) values (?)";
+ $DB->Execute($sql, array(serialize($array_chunks[$y])));
+
+ if($memcache) {
+ $memcache->set($y . ":" . $outlaws_memcache . ":ldrweeklylevel", "");
+ }
+}
+
+echo "Done Weekly Level...\n";
+
+// END WEEKLY LEADERBOARDS
+/*****************************************************************************************/
+
+echo "\nDone Script...\n";
+?>
diff --git a/scripts/leaderboard_weekly_script.php b/scripts/leaderboard_weekly_script.php
new file mode 100644
index 0000000..b223f10
--- /dev/null
+++ b/scripts/leaderboard_weekly_script.php
@@ -0,0 +1,105 @@
+Execute($sql, "weekly_refresh_date");
+
+///////////////////////////////////////////////////////////////////////
+// AWARD WINNERS //////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "select array_data from leader_weekly_miles where uid = 1";
+try {
+ $person_array = $DB->GetArray($sql);
+} catch (Exception $e) { return false; }
+if($person_array != false and count($person_array) != 0) {
+ $array_data = unserialize($person_array[0]['array_data']);
+
+ $gold = $array_data[0]['id']; //winner
+ $silver = $array_data[1]['id']; //2nd place
+ $bronze = $array_data[2]['id']; //3rd place
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($gold, "miles_gold"));
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($silver, "miles_silver"));
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($bronze, "miles_bronze"));
+}
+
+$sql = "select array_data from leader_weekly_money where uid = 1";
+try {
+ $person_array = $DB->GetArray($sql);
+} catch (Exception $e) { return false; }
+if($person_array != false and count($person_array) != 0) {
+ $array_data = unserialize($person_array[0]['array_data']);
+
+ $gold = $array_data[0]['id']; //winner
+ $silver = $array_data[1]['id']; //2nd place
+ $bronze = $array_data[2]['id']; //3rd place
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($gold, "money_gold"));
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($silver, "money_silver"));
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($bronze, "money_bronze"));
+}
+
+$sql = "select array_data from leader_weekly_level where uid = 1";
+try {
+ $person_array = $DB->GetArray($sql);
+} catch (Exception $e) { return false; }
+if($person_array != false and count($person_array) != 0) {
+ $array_data = unserialize($person_array[0]['array_data']);
+
+ $gold = $array_data[0]['id']; //winner
+ $silver = $array_data[1]['id']; //2nd place
+ $bronze = $array_data[2]['id']; //3rd place
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($gold, "level_gold"));
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($silver, "level_silver"));
+
+ $sql = 'insert into leader_weekly_winners (uid, award_won, date_won) values(?, ?, now())';
+ $DB->Execute($sql, array($bronze, "level_bronze"));
+}
+
+///////////////////////////////////////////////////////////////////////
+// CLEAR MILES ////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "update users set weekly_miles = 0";
+$DB->Execute($sql);
+
+echo "Done Clear Miles...\n";
+
+///////////////////////////////////////////////////////////////////////
+// COPY OVER MONEY ////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "update users set weekly_money = (buried_coin_total + coin_total)";
+$DB->Execute($sql);
+
+echo "Done Copy Money...\n";
+
+///////////////////////////////////////////////////////////////////////
+// COPY OVER LEVELS ///////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////
+$sql = "update users set weekly_level = level";
+$DB->Execute($sql);
+
+echo "Done Copy Level...\n";
+
+echo "\nDone Script...\n";
+
+?>
\ No newline at end of file
diff --git a/scripts/run_race.php b/scripts/run_race.php
new file mode 100644
index 0000000..5a61c50
--- /dev/null
+++ b/scripts/run_race.php
@@ -0,0 +1,71 @@
+GetOne($sql);
+
+$jackpot = $monkey_entries * 50;
+if($jackpot < 2500) {
+ $jackpot =2500;
+}
+//select a random user id to win
+$sql = "select user_id from races where type = 'm' and completed = 0 order by rand()";
+$monkey_winner = $DB->GetOne($sql);
+
+//update all the completed to 1;
+$DB->Execute("update races set race_time=now(), completed = 1 where completed = 0 and type='m'");
+
+//insert user_id, type, jackpot, date into race_results
+$DB->Execute("insert into race_results (user_id, type, jackpot, created_at, entrants) values(?, 'm', ?, now(), ?)", array($monkey_winner,$jackpot, $monkey_entries));
+
+
+//add the jackpot coins for the monkey_winner
+$DB->Execute("update users set buried_coin_total=buried_coin_total + ? where id = ?", array($jackpot, $monkey_winner));
+//subtract the monkey from the winner
+$DB->Execute("update stuff set how_many = how_many - 1 where stuff_id = 7 and user_id = ?", array($monkey_winner));
+
+
+
+
+
+//run the parro race
+//how many people are in monkey race?
+$sql = "select count(*) from races where type = 'p' and completed = 0";
+$parrot_entries = $DB->GetOne($sql);
+
+$jackpot = $parrot_entries * 200;
+if($jackpot < 5000) {
+ $jackpot =5000;
+}
+//select a random user id to win
+$sql = "select user_id from races where type = 'p' and completed = 0 order by rand()";
+$parrot_winner = $DB->GetOne($sql);
+
+//update all the completed to 1;
+$DB->Execute("update races set race_time=now(), completed = 1 where completed = 0 and type = 'p'");
+
+//insert user_id, type, jackpot, date into race_results
+$DB->Execute("insert into race_results (user_id, type, jackpot, created_at, entrants) values(?, 'p', ?, now(), ?)", array($parrot_winner,$jackpot, $monkey_entries));
+
+
+//add the jackpot coins for the parrot_winner
+$DB->Execute("update users set buried_coin_total=buried_coin_total + ? where id = ?", array($jackpot, $parrot_winner));
+
+$DB->Execute("update stuff set how_many = how_many - 1 where stuff_id = 11 and user_id = ?", array($parrot_winner));
+
+//subtract the parrot from the winner
+
+
+?>
diff --git a/scripts/script_config.php b/scripts/script_config.php
new file mode 100644
index 0000000..bf07926
--- /dev/null
+++ b/scripts/script_config.php
@@ -0,0 +1,26 @@
+set_user($id, $session_key);
+
+
+////////////////////////////////////////////////////////////////////////////////////////////
+//memcache stuff
+
+$memcache_temp = new Memcache(); //use temp for mile limits, gambing limits
+$memcache_temp->addServer('10.12.198.194', 11219);
+
+$memcache = new Memcache();
+$memcache->addServer('10.12.198.194', 11211);
+
+////////////////////////////////////////////////////////////////////////////////////////////
+
+//be sure to have this set to true so we don't try and include the other config.php in libxml_clear_errors()
+$script_config = true;
+
+require_once '../image_ids.php';
+require_once '../lib.php';
diff --git a/scripts/script_config_myspace.php b/scripts/script_config_myspace.php
new file mode 100644
index 0000000..9b9f128
--- /dev/null
+++ b/scripts/script_config_myspace.php
@@ -0,0 +1,36 @@
+addServer('10.12.198.194', 11213);
+//$memcache_temp->addServer('10.8.50.196', 11213);
+
+$memcache = new MemcacheWrapper('my');
+
+ $memcache->addServer('10.12.198.194', 11211);
+
+
+////////////////////////////////////////////////////////////////////////////////////////////
+
+//be sure to have this set to true so we don't try and include the other config.php in libxml_clear_errors()
+$script_config = true;
+
+require_once '../image_ids.php';
+require_once '../lib.php';
diff --git a/scripts/start_memcache.sh b/scripts/start_memcache.sh
new file mode 100644
index 0000000..1a101a6
--- /dev/null
+++ b/scripts/start_memcache.sh
@@ -0,0 +1 @@
+memcached -d -m 1024 -l 127.0.0.1 -p 11211 -u root
diff --git a/settings.php b/settings.php
new file mode 100644
index 0000000..474a3df
--- /dev/null
+++ b/settings.php
@@ -0,0 +1,123 @@
+
+
+
+
+
+Pirate Settings!
+
+ Arrrrrrr!
+
+
+
+
+
+
+
+
+
+Do you want Pirate Jokes in yer profile?
+
+
+
+ >Yes
+ >No
+
+
+
+
+
+
+Gender of yer Pirate
+
+
+
+ >Male
+ >Female
+
+
+
+
+
+
+Use 'Old-style' Pirate Image
+
+
+
+ >No
+
+ >Yes
+
+
+
+
+ 300) {
+
+?>
+
+
+Do you want want bombs and dynamite traps enabled?
This option can only be turned off after level 300. If you disable it you won't be presented with options to throw bombs or throw dynamite. You also won't get hit by bombs or dynamite.
+
+
+
+ >Yes
+ >No
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/settings_post.php b/settings_post.php
new file mode 100644
index 0000000..8f7999f
--- /dev/null
+++ b/settings_post.php
@@ -0,0 +1,56 @@
+
+Execute($sql, array($joke_on_off, $user));
+//print_r($_REQUEST);
+
+$memcache->set($user . "s_joke_on_off", $joke_on_off, false, 1 * 6);
+
+
+//echo $joke_on_off;
+$sql = 'update users set gender = ? where id = ?';
+global $DB, $memcache;
+$DB->Execute($sql, array($gender, $user));
+//print_r($_REQUEST);
+
+$memcache->set($user . "s_gender", $gender, false, 1 * 6);
+
+
+
+//echo $joke_on_off;
+$sql = 'update users set use_old_image = ? where id = ?';
+global $DB, $memcache;
+$DB->Execute($sql, array($use_old_image, $user));
+//print_r($_REQUEST);
+
+$memcache->set($user . "s_use_old_image", $use_old_image, false, 1 * 6);
+
+
+
+$level = get_level($user);
+
+if($level > 300) {
+ $sql = 'update users set bomb_on = ? where id = ?';
+ $DB->Execute($sql, array($bomb_on_off, $user));
+ $memcache->set($user . "s_bomb_on_off", $joke_on_off, false, 1 * 6);
+
+}
+
+set_profile($user);
+
+$facebook->redirect('index.php?msg=settings-saved');
diff --git a/ship_attack_result.php b/ship_attack_result.php
new file mode 100644
index 0000000..56b7119
--- /dev/null
+++ b/ship_attack_result.php
@@ -0,0 +1,89 @@
+GetOne('select id from battles where user_id = ? order by created_at desc', array($user));
+
+ //$facebook->redirect("$facebook_canvas_url/index.php");
+}
+
+
+$sql = "select * from battles where id = ?";
+$game = $DB->GetRow($sql, $game_id);
+//print_r($game);
+$game_result = $game['result'];
+$gold = $game['gold_change'];
+$enemy = $game['opponent_type'];
+$enemy_id = $game['user_id_2'];
+
+//update_action($user, "NULL");
+
+if($game_result =='l') {
+ $msg="You attack and .... You LOST :( The $enemy pirates stole some of your booty!";
+ $result="The $enemy pirate " . get_first_name_for_id($enemy_id) . " stole $gold coins from you. Yer health was healed by 50% after
+losing! Arrr....there always be another day for fightin! " . image_return($you_lost_image) . "";
+
+
+}
+
+else if($game_result == 't') {
+ $msg="You attack and .... barely escaped alive!! Shiver me timbers! You weren't able to take any gold, but didn't take any of yours either! Arrr..";
+ $result='Arrr....there always be another day for fightin! ';
+
+}
+
+else { //win!
+ $msg="You attack and .... You WON. You stole some booty from those $enemy scallywags!";
+ $result="You took $gold coins from the $enemy Pirate " . get_first_name_for_id($enemy_id) . " Arrrr...Good job matey " . image_return($pirate_coins_image) . " ";
+
+}
+
+$DB->Execute('update users set battling_enemy_id = 0 where id = ?', array($user));
+
+//update_action($user, "NULL");
+
+print dashboard();
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+get($user . 'pvp_attack_history');
+
+echo "Battle History ";
+echo $history;
+echo " ";
+
+?>
+
+
+
+
diff --git a/shipyard.php b/shipyard.php
new file mode 100644
index 0000000..e116114
--- /dev/null
+++ b/shipyard.php
@@ -0,0 +1,201 @@
+
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$level = get_level($user);
+
+$upgrades = get_upgrades($user);
+
+//print_r($upgrades);
+//$cannon_level = $upgrades
+
+foreach($upgrades as $key=>$value) {
+ $upgrade_name = $value['upgrade_name'];
+ $level = $value['level'];
+ if($upgrade_name == 'cannons') {
+ $cannon_level = $level;
+ }
+ else if($upgrade_name == 'sails') {
+ $sail_level = $level;
+ }
+ else if($upgrade_name == 'hull') {
+ $hull_level = $level;
+ }
+ else if($upgrade_name == 'crew') {
+ $crew_level = $level;
+ }
+}
+
+
+if(!isset($crew_level)) {
+ $crew_level = 0;
+}
+
+if(!isset($hull_level)) {
+ $hull_level = 0;
+}
+if(!isset($cannon_level)) {
+ $cannon_level = 0;
+}
+if(!isset($sail_level)) {
+ $sail_level = 0;
+}
+
+$crew_price = 400;
+for($i = 0; $i < $crew_level; $i++) {
+ $crew_price += $crew_price * .05;
+}
+$crew_price = round($crew_price);
+if($crew_price > 10000) {
+ $$crew_price = 10000;
+}
+
+$hull_price = 300;
+for($i = 0; $i < $hull_level; $i++) {
+ $hull_price += $hull_price * .05;
+}
+$hull_price = round($hull_price);
+if($hull_price > 10000) {
+ $hull_price = 10000;
+}
+
+$cannon_price = 100;
+for($i = 0; $i < $cannon_level; $i++) {
+ $cannon_price += $cannon_price * .05;
+}
+$cannon_price = round($cannon_price);
+if($cannon_price > 10000) {
+ $cannon_price = 10000;
+}
+
+$sail_price = 200;
+for($i = 0; $i < $sail_level; $i++) {
+ $sail_price += $sail_price * .05;
+}
+$sail_price = round($sail_price);
+if($sailprice > 10000) {
+ $sailprice = 10000;
+}
+
+
+//$crew_price = ($crew_level + 1) * 400;
+//$hull_price = ($hull_level + 1) * 300;
+//$cannon_price = ($cannon_level + 1) * 100;
+//$sail_price = ($sail_level + 1) * 200;
+
+print dashboard();
+
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+Welcome to the Shipyard!
+
+
+What can I do for ya?
+
+
+
+
+
+
+
+
+
+
+
+
+
You're holding coins
+
+
+
You also have buried coins. ">Retrieve em to buy stuff here.
+
+
+
+
+
Arr....You can increase your level by recruitin your mates, or by spendin' some cash here. Once you're a level 1 pirate you'll be able to fight other pirates
+
+
+
+
Your current cannons are level . Better cannons will give you more power in battles.
+
+
+
Your current sails are level . Better sails will allow you to travel longer distances more quickly.
+
+
+
Your current hull is level . A larger hull will allow you to hold more BOOTY!
+
+
+
You currently have crew members. Additional crew members will give you more power in battles, and allow you to sail for longer periods of time.
+
+
+
+
+
+
+
+
+
+
+
+?>
+
+
+
+">Go back to sea -adventure, danger and treasure await
+
+
\ No newline at end of file
diff --git a/start_log.php b/start_log.php
new file mode 100644
index 0000000..a7ea69a
--- /dev/null
+++ b/start_log.php
@@ -0,0 +1,39 @@
+
+
+
+
+
+Start logging a user
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/start_log_submit.php b/start_log_submit.php
new file mode 100644
index 0000000..b8224be
--- /dev/null
+++ b/start_log_submit.php
@@ -0,0 +1,21 @@
+Execute('insert into logged_users (id) values(?)', array($facebook_id));
+
+}
+catch(ADODB_Exception $e) {
+ $facebook->redirect('start_log.php?msg=already-logged');
+}
+
+$facebook->redirect("start_log.php?msg=log-started&id=$facebook_id");
+
+?>
\ No newline at end of file
diff --git a/style.php b/style.php
new file mode 100644
index 0000000..212b35d
--- /dev/null
+++ b/style.php
@@ -0,0 +1,13 @@
+
+
+
diff --git a/style2.php b/style2.php
new file mode 100644
index 0000000..c0371f5
--- /dev/null
+++ b/style2.php
@@ -0,0 +1,41 @@
+
diff --git a/surveys.php b/surveys.php
new file mode 100644
index 0000000..ff18f82
--- /dev/null
+++ b/surveys.php
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Welcome to Pirate Booty Bonus! We need money to improve the site, you help us get it. We give you huge prizes!
+
+
+
+
+
+
+
+When you fill out surveys, we get money and give you prizes. For each survey you complete, we'll give you 500 gold coins!
+A few minutes of your time can help Pirates get custom graphics and fast servers!
+
+
+";
+//echo "publisher_id $publisher_id ";
+//echo "security_key $security_key ";
+
+$user_go = substr(md5($user . $publisher_id . $security_key), 0, 10);
+
+//echo "user_go $user_go ";
+
+$user_id = "$user-$publisher_id-$user_go";
+
+//echo "user_id $user_id ";
+
+
+//$url = 'http://peanutlabs.com/userGreeting.php?userId=1807687-63-260dc1befe';
+$url = "http://peanutlabs.com/userGreeting.php?userId=$user_id";
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tavern.php b/tavern.php
new file mode 100644
index 0000000..aba67d7
--- /dev/null
+++ b/tavern.php
@@ -0,0 +1,192 @@
+redirect("$facebook_canvas_url/install.php?i=$in");
+}
+//print_r($user);
+$user_in_db = is_user_in_db($user);
+if($user_in_db ==0) {
+ $facebook->redirect("$facebook_canvas_url/install.php");
+}
+
+$coin_total = get_coin_total($user);
+$buried_coin_total = get_coin_total_buried($user);
+
+$my_level = get_level($user);
+
+$upgrades = get_upgrades($user);
+
+//print_r($upgrades);
+//$cannon_level = $upgrades
+
+foreach($upgrades as $key=>$value) {
+ $upgrade_name = $value['upgrade_name'];
+ $level = $value['level'];
+ if($upgrade_name == 'cannons') {
+ $cannon_level = $level;
+ }
+ else if($upgrade_name == 'sails') {
+ $sail_level = $level;
+ }
+ else if($upgrade_name == 'hull') {
+ $hull_level = $level;
+ }
+ else if($upgrade_name == 'crew') {
+ $crew_level = $level;
+ }
+}
+
+
+if(!isset($crew_level)) {
+ $crew_level = 0;
+}
+
+$wench_price = 25;
+for($i = 0; $i < $crew_level; $i++) {
+ $wench_price += $wench_price * .05;
+}
+$wench_price = round($wench_price);
+if($wench_price > 1000) {
+ $wench_price = 1000;
+}
+
+//$crew_price = ($crew_level + 1) * 400;
+//$hull_price = ($hull_level + 1) * 300;
+//$cannon_price = ($cannon_level + 1) * 100;
+//$sail_price = ($sail_level + 1) * 200;
+
+$upgrade_name = $_REQUEST['u'];
+
+if($upgrade_name == 'wenches') {
+ $cost = $wench_price;
+}
+
+print dashboard();
+
+?>
+
+
+
+
+
+
+
+ Welcome to the Tavern! Arr! This is a rough place, so be watchin your step. What do ye be wantin to do today?
+ You're holding coins
+ 0) { ?>
+ You also have buried coins.">Retrieve em to buy stuff here.
+
+
+
+
+
+ ">Tavern Brothel - Hire wenches to relax your crew
+
+
+
+ >Pet Races - Bet on monkey and parrot races
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+get_bar() . "/>"; // for fb:iframe
+
+}
+
+?>
+
+
+
+
+';
+
+?>
+
+
+
+
+
+
+
+ Tavern
+
+
+
+
+
+
+>Go back to sea -adventure, danger and treasure await
+
+
+
diff --git a/tavernboard.php b/tavernboard.php
new file mode 100644
index 0000000..9d27a33
--- /dev/null
+++ b/tavernboard.php
@@ -0,0 +1,46 @@
+
+
+