Browse Source

mmo update 0.3.1

master
Felty 2 years ago
parent
commit
5abae97562
4 changed files with 134 additions and 9 deletions
  1. +129
    -0
      vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-credit-postback.php
  2. +1
    -7
      vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-deduct-postback.php
  3. +1
    -0
      vidyen-wc-mmo/vidyen-wc-mmo-menu.php
  4. +3
    -2
      vidyen-wc-mmo/vidyen-wc-mmo.php

+ 129
- 0
vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-credit-postback.php View File

@ -0,0 +1,129 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
//NOTE: This is designed for credit post backs of MMO systems with VidYen
function vidyen_mmo_postback_credit_func( $atts )
{
//NOTE: The admin needs to set the post back correctly. We will have no idea what the user id will be as it will be fed into the system by the post back
//We will need the secret
//Also NOTE: I changed pid to outputid because i think going forward pid is a bit nondescriptive
//THis needs to called to get the api key.
$vidyen_api = sanitize_text_field(vyps_mmo_sql_api_key_func());
$atts = shortcode_atts(
array(
'apikey' => $vidyen_api,
'profile' => '',
'ip1' => '163.182.175.208',
'ip2' => '163.182.175.208',
'ip3' => '208.253.87.210',
'point_id' => 0,
'outputamount' => 0,
'refer' => 0,
'to_user_id' => 0,
'comment' => '',
'reason' => 'MMO Transfer',
'meta_id' => '',
'round' => 'default',
'pro'=> FALSE,
), $atts, 'vyps-adgate' );
$round_direction_decision = $atts['round']; //By default this is default, which just takes the direction its closest too.
//The scarcy thing is... This post back can be writing to your SQL tables. SO we HAVE to be careful with it.
global $wpdb;
$table_name_log = $wpdb->prefix . 'vyps_points_log';
$site_vidyen_api = $atts['apikey'];
//define('AdGate_IP', $postback_ip_address); // Note: as noted above change the IP to match what is in your affiliate panel.
$post_ip = $_SERVER['REMOTE_ADDR'];
if (isset($_POST['apikey']))
{
if($site_vidyen_api != $_POST['apikey'])
{
// Throw either a custom Exception or just throw a generic \Exception
//header('HTTP/1.1 203 Partial Information');
//exit(); //NOTE: I put exit as the AdGate method was bad
return 'Invalid API key';
}
}
else
{
return 'Api Key not Set!!';
}
/* debug
if (!isset($_POST['email']))
{
return 'Email not set!';
}
elseif (!isset($_POST['points']))
{
return 'Point value not set!';
}
*/
//We are getting the user and then get the user id from that since they might be different between servers. I'm just guessing
//So we need to see if email and points or just a user id wihcih work different.
if ( (isset($_POST['email']) AND isset($_POST['points'])) OR (isset($_POST['userid']) AND isset($_POST['points'])))
{
if ( isset($_POST['email']) AND !isset($_POST['userid']) )
{
$user_email = sanitize_email($_POST['email']); //Huh they actualyly had this. Hrm.... honestly it doesn't seem to care about the email in the get. Learn something every day.
$user_data = get_user_by('email', $user_email);
$user_id = $user_data->ID;
}
elseif ( !isset($_POST['email']) AND isset($_POST['userid']) )
{
$loa_user_id = sanitize_text_field($_POST['userid']);
$user_id = vidyen_mmo_loa_user_query_func($loa_user_id);
//$user_id = 1; //Hard coded for now
if ($user_id < 1)
{
return 2; //Error code for user id not found. Game client should tell them to find in game id and put it in website.
}
}
//$user_id = 2;
$points = intval($_POST['points']);
if (intval($atts['point_id']) != 0)
{
$point_id = intval($atts['point_id']);
}
else
{
$point_id = intval(vyps_mmo_sql_point_id_func()); //give the option, for shortcodes. the api will be universal.
}
$point_amount = intval($points);
$reason = sanitize_text_field($atts['reason']);
$vyps_meta_id = 'mmo' . $user_id . $transactionId_sanitized; //the meta_id will be adgate with userid plus the transaction id. To see if its unique.
$current_balance = vyps_point_balance_func($point_id, $user_id); //need to check to see if they have an actual balance to report //NOTE: I opted with letting the other site tell how much it will withdraw at a time.
if( $points > 0) // We shouldn't be running SQL stuff if the amount is 0
{
return vyps_point_credit_func( $point_id, $point_amount, $user_id, $reason, $vyps_meta_id ); //I knew I had a good reason to use this
//The above should resturn a 1 if successful. I'm not going to add an add here just yet. This is an output system.
//If the get gets a 1 then it adds the points on the other side. I would recommend not doing an all system just like 100 points.
//I am going to add a balance api, but may not be needed.
}
else
{
return 0; //simple enough. It didn't work. Did not add points.
}
//The rest of the post back isn't needed. I will delete but will make a different page for ads or balances.
}
return -1; //Uknown reason
}
/* Telling WP to use function for shortcode */
add_shortcode( 'vidyen-mmo-credit', 'vidyen_mmo_postback_credit_func');

vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-postback.php → vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-deduct-postback.php View File

@ -2,13 +2,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
//NOTE: This is designed for post backs of MMO systems with VidYen
//Responses
//-1 unknown error
//0 = default, no transact
//1 = success
//2 = no user id found on
//NOTE: This is designed for deduct post backs of MMO systems with VidYen
function vidyen_mmo_postback_deduct_func( $atts )
{

+ 1
- 0
vidyen-wc-mmo/vidyen-wc-mmo-menu.php View File

@ -129,6 +129,7 @@ function vidyen_wc_mmo_sub_menu_page()
<p><b>[vidyen-mmo-bal]</b> for live balance.</p>
<p><b>[vyps-mmo-pe]</b> for live point exchange.</p>
<p><b>[vidyen-mmo-deduct point_id=2 apikey=(set here on in MMO menu)]</b> This is a postback page. If you do not remember how to do the post back page watch the Wannads tutorial video in full.</p>
<p><b>[vidyen-mmo-credit point_id=2 apikey=(set here on in MMO menu)]</b> Same as above but does the credit when you want to talk currency off server and into site.</p>
<p><b>[vidyen-mmo-api-bal mode=GET gui=TRUE point_id=7]</b> This is a postback page for external curls. If you do not remember how to do the post back page watch the Wannads tutorial video in full.</p>
<p><b>[vidyen-mmo-register apikey=test]</b> This is for your registration curl. Only enter your apikey where test is written.</p>
<p><b>[vidyen-loa-id]</b> This is for your LoA userid box. It shows each user their currently stored LoA userid and lets them clear it if its incorrect. If edit=TRUE you are able to edit this directly from the website.</p>

+ 3
- 2
vidyen-wc-mmo/vidyen-wc-mmo.php View File

@ -3,7 +3,7 @@
Plugin Name: VidYen MMO Plugin
Plugin URI: https://wordpress.org/plugins/vidyen-point-system-vyps/
Description: MMO Support Plugin
Version: 0.2.0
Version: 0.3.1
Author: VidYen, LLC
Author URI: https://vidyen.com/
License: GPLv2
@ -81,7 +81,8 @@ include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_loa_u
/*** Shortcodes ***/
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-bal.php'); //Ajax Balance
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vyps-wc-mmo-point-exchange.php'); //Ajax Point Exchange
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-postback.php'); //Post back for game transfers
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-credit-postback.php'); //Post back for game credit transfers
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-deduct-postback.php'); //Post back for game deduct transfers
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-api-bal.php'); //Post back for game transfers
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-loa-id.php'); //Stores the LOA Player ID
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-register.php'); //Registers the User ID

Loading…
Cancel
Save