Browse Source

mtest additions

master
Felty 1 year ago
parent
commit
91c8981674
8 changed files with 275 additions and 2 deletions
  1. +4
    -0
      vidyen-wc-mmo/README.md
  2. +32
    -0
      vidyen-wc-mmo/includes/functions/core/vidyen_mmo_mtest_user_query_func.php
  3. +9
    -0
      vidyen-wc-mmo/includes/js/loa-mtest-generate.js
  4. +8
    -0
      vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-api-bal.php
  5. +11
    -0
      vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-credit-postback.php
  6. +11
    -0
      vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-deduct-postback.php
  7. +196
    -0
      vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-mtest-id.php
  8. +4
    -2
      vidyen-wc-mmo/vidyen-wc-mmo.php

+ 4
- 0
vidyen-wc-mmo/README.md View File

@ -14,6 +14,10 @@ Patreon supports get free webhosting btw.
# Change Log
= 0.6.0 =
- Added Mintest support
= 0.5.0 =
- Update: Added latest backend funcitonality to make the in game monentization without having to register an account.

+ 32
- 0
vidyen-wc-mmo/includes/functions/core/vidyen_mmo_mtest_user_query_func.php View File

@ -0,0 +1,32 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
//This is designed for the user query in the meta.
//Perhaps the name is too long?
function vidyen_mmo_mtest_user_query_func($mtest_user_id)
{
$user_query = new WP_User_Query( array( 'meta_key' => 'vidyen_mmo_mtest_id', 'meta_value' => $mtest_user_id ) );
$users = $user_query->get_results();
//Thi is a bit hackey. Basically it does a for loop and stop on the first one otherwise if none found returns a 0.
if ( ! empty( $users ) )
{
foreach ( $users as $user )
{
// get all the user's data
$user_info = get_userdata( $user->ID );
$output_result = $user_info->ID;
return intval($output_result);
}
}
else
{
return 0;
}
//print_r($users[0]);
return;
//return 'There should be something here: '. $users[0];
}

+ 9
- 0
vidyen-wc-mmo/includes/js/loa-mtest-generate.js View File

@ -0,0 +1,9 @@
//Sets the field to copy link
function copy_link()
{
var copyText = document.getElementById("url_output");
copyText.select();
document.execCommand("copy");
alert("Paste this command into LoA: " + copyText.value);
}

+ 8
- 0
vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-api-bal.php View File

@ -55,6 +55,14 @@ function vidyen_mmo_postback_api_bal_func( $atts )
//$user_id = 1; //Hard coded for now
$mmo_get_balance = vyps_point_balance_func($point_id, $user_id);
}
elseif (isset($_GET['mtname']))
{
$point_id = intval($atts['point_id']);
$mtest_user_id = sanitize_text_field($_GET['mtname']);
$user_id = vidyen_mmo_mtest_user_query_func($mtest_user_id);
//$user_id = 1; //Hard coded for now
$mmo_get_balance = vyps_point_balance_func($point_id, $user_id);
}
else
{
$mmo_get_balance = 0;

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

@ -86,6 +86,17 @@ function vidyen_mmo_postback_credit_func( $atts )
return 2; //Error code for user id not found. Game client should tell them to find in game id and put it in website.
}
}
elseif (isset($_POST['mtname']))
{
$point_id = intval($atts['point_id']);
$mtest_user_id = sanitize_text_field($_POST['mtname']);
$user_id = vidyen_mmo_mtest_user_query_func($mtest_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;

+ 11
- 0
vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-deduct-postback.php View File

@ -86,6 +86,17 @@ function vidyen_mmo_postback_deduct_func( $atts )
return 2; //Error code for user id not found. Game client should tell them to find in game id and put it in website.
}
}
elseif (isset($_POST['mtname']))
{
$point_id = intval($atts['point_id']);
$mtest_user_id = sanitize_text_field($_POST['mtname']);
$user_id = vidyen_mmo_mtest_user_query_func($mtest_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;

+ 196
- 0
vidyen-wc-mmo/includes/shortcodes/vidyen-mmo-mtest-id.php View File

@ -0,0 +1,196 @@
<?php
//This is for the player id that players must set on the website
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
//This should need no shortcode attributes
function vidyen_mmo_mtest_id_func($atts)
{
//Simple attribue to see if you can edit. But default will be off.
$atts = shortcode_atts(
array(
'edit' => FALSE
), $atts, 'vyps-mtest-query' );
//Boot user out if not logged in. BTW my code is evolving. -Felty
if ( ! is_user_logged_in() )
{
return; //Not logged in. You see nothing.
}
//Get current user Id obviously and email
$user_id = get_current_user_id();
$user_info = get_userdata($user_id);
$user_email = $user_info->user_email;
$user_registration_link = '/registerid '. $user_email;
//$mtest_link_generate_url = plugins_url( 'js/', dirname(__FILE__) ) . 'mtest-id-generate.js'; //Not needed I think.
//This is hardcoded, but the label we are going to cram into the usermeta table
$key = 'vidyen_mmo_mtest_id';
//NO WIRE ARRAYS! Only one value at all time. Unless someone messed something up somewhere.
$single = TRUE;
//I'm only going to run this is you edit. Otherwise its just a clear
if ($atts['edit'] == TRUE)
{
if (isset($_POST['update_mtest_id']))
{
//As the post is the only thing that edits data, I suppose this is the best place to the noce
$vyps_nonce_check = $_POST['vypsnoncepost'];
//Make sure no one is being tricked into updating their Wallet Address
if ( ! wp_verify_nonce( $vyps_nonce_check, 'vyps-nonce' ) )
{
// This nonce is not valid.
die( 'Security check' );
}
else
{
// The nonce was valid.
//Carry on.
//Do the dew.
//Do we even need a else here?
}
//Getting the mtest_id and things.
$mtest_id = sanitize_text_field($_POST['mtest_id']); //Sanitize it! From orbit!
//Ok now we update in hell! (Hell = usermeta table) I wonder if anyone reads these coments. -Felty
update_user_meta( $user_id, $key, $mtest_id );
}
//NOTE: This should come after the post so it will update before the refresh or otherwise the mtest_id may be out of date. Remind me to check.
//And we have the current mtest_id. This may not exist or be blank. Also I'm 99.99999999% sure I can't tell if its actually a real XMR address
$mtest_id = get_user_meta( $user_id, $key, $single );
//Adding a nonce to the post
$vyps_nonce_check = wp_create_nonce( 'vyps-nonce' );
//displaying mtest_id if EXISTS
if (strlen($mtest_id) > 1)
{
$display_mtest_id = "Current mtest ID:<br>" . $mtest_id; //I'm really guessing here as just assuming that if they put in more than one. Probaly should do validation somewhere down road
}
else
{
$display_mtest_id = "No mtest ID set:"; //Just some text
}
$form_result_ouput = "
<div>
<p>$display_mtest_id</p>
<form method=\"post\" name=\"createuser\" id=\"createuser\" class=\"validate\" novalidate=\"novalidate\" enctype=\"multipart/form-data\">
<table class=\"form-table\">
<tbody>
<tr class=\"form-field form-required\">
<th scope=\"row\">
<label for=\"mtest_id\">Update mtest ID:</label>
</th>
<td>
<input name=\"mtest_id\" type=\"text\" id=\"mtest_id\" value=\"$mtest_id\" aria-required=\"true\" autocapitalize=\"none\" autocorrect=\"off\" maxlength=\"256\">
</td>
</tr>
</tbody>
</table>
<p class=\"submit\">
<input type=\"hidden\" name=\"vypsnoncepost\" id=\"vypsnoncepost\" value=\"$vyps_nonce_check\" />
<input type=\"submit\" name=\"update_mtest_id\" id=\"update_mtest_id\" class=\"button button-primary\" value=\"Update\">
</p>
</form>
</div>
";
}
else
{
//This is all other cases... ALl you can do is clear.
if (isset($_POST['change_mtest_id_action']))
{
//As the post is the only thing that edits data, I suppose this is the best place to the noce
$vyps_nonce_check = $_POST['vypsnoncepost'];
//Make sure no one is being tricked into updating their Wallet Address
if ( ! wp_verify_nonce( $vyps_nonce_check, 'vyps-nonce' ) )
{
// This nonce is not valid.
die( 'Security check' );
}
//Getting the mtest_id and things.
//$mtest_id = sanitize_text_field($_POST['mtest_id']); //Sanitize it! From orbit!
if (isset($_POST['mtest_id']))
{
$mtest_id = sanitize_text_field($_POST['mtest_id']);
}
else
{
$mtest_id = ''; //Tis blank if no post!
}
//Ok now we update in hell! (Hell = usermeta table) I wonder if anyone reads these coments. 300 was a good movie. -Felty
update_user_meta( $user_id, $key, $mtest_id );
}
//Adding a nonce to the post
$vyps_nonce_check = wp_create_nonce( 'vyps-nonce' );
$mtest_id = get_user_meta($user_id, $key, $single); //I forgot this. Shoudl work now.
//displaying mtest_id if EXISTS
if (strlen($mtest_id) > 1)
{
$display_mtest_id = $mtest_id; //I'm really guessing here as just assuming that if they put in more than one. Probaly should do validation somewhere down road
}
else
{
$display_mtest_id = "No Mine Test ID set!"; //Just some text
}
$form_result_ouput =
"<div>
<form method=\"post\" name=\"createuser\" id=\"createuser\" class=\"validate\" novalidate=\"novalidate\" enctype=\"multipart/form-data\">
<table class=\"form-table\">
<tbody>
<tr class=\"form-field form-required\">
<th scope=\"row\">
<label for=\"mtest_id\">Mine Test ID:</label>
</th>
<td>
<input name=\"mtest_id\" type=\"text\" id=\"mtest_id\" value=\"$display_mtest_id\" autocapitalize=\"none\" autocorrect=\"off\" maxlength=\"256\">
</td>
</tr>
</tbody>
</table>
<p class=\"submit\">
<input type=\"hidden\" name=\"vypsnoncepost\" id=\"vypsnoncepost\" value=\"$vyps_nonce_check\" />
<input type=\"hidden\" name=\"change_mtest_id_action\" id=\"change_mtest_id_action\" value=\"change_mtest_id_action\" />
<input type=\"submit\" name=\"set_mtest_id\" id=\"set_mtest_id\" class=\"button button-primary\" value=\"Clear ID\" onclick=\"return confirm('Are you sure you want to change your ID?');\">
</p>
</form>
</div>
";
}
//Remember kids. Always return shortcodes. Never echo or you are going to have a bad time.
return $form_result_ouput;
}
//Adding the shortcode.
add_shortcode( 'vidyen-mtest-id', 'vidyen_mmo_mtest_id_func');
//Some debuging going on here.
function vidyen_load_mtest_id_shortcode_func($atts)
{
$atts = shortcode_atts(
array(
'mtest_id' => 'empty'
), $atts, 'vyps-mtest-query' );
$mtest_user_id = $atts['mtest_id'];
return vidyen_mmo_mtest_user_query_func($mtest_user_id);
}
add_shortcode( 'vyps-mtest-query', 'vidyen_load_mtest_id_shortcode_func');

+ 4
- 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.5.5
Version: 0.6.0
Author: VidYen, LLC
Author URI: https://vidyen.com/
License: GPLv2
@ -76,7 +76,8 @@ include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_wooco
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vyps_woowallet_currency.php'); //Custom Currencies to WooCommerce
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vyps_sql_call_func.php'); //SQL Call functions
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vyps_mmo_wc_ww_bal_func.php'); //Custom WooWallet balance function for this purpose
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_loa_user_query_func.php'); //Adds meta check
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_loa_user_query_func.php'); //Adds meta check for LOA
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_mtest_user_query_func.php'); //Adds meta check for MTEST
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_wm_point_balance_func.php'); //In game webminer balance
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_wm_point_deduct_func.php'); //In game deduct
include( plugin_dir_path( __FILE__ ) . 'includes/functions/core/vidyen_mmo_wm_point_credit_func.php'); //In game deduct
@ -89,6 +90,7 @@ include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-credit-po
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-mtest-id.php'); //Stores the LOA Player ID
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-register.php'); //Registers the User ID
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-wm-api-bal.php'); //Stores the LOA Player ID
include( plugin_dir_path( __FILE__ ) . 'includes/shortcodes/vidyen-mmo-wm-deduct-postback.php'); //Webminer deduct

Loading…
Cancel
Save