7 Commits
0.2 ... 0.3

Author SHA1 Message Date
Tekaoh
ff96c2bce3 Version bump to 0.3 2020-04-15 17:37:09 -04:00
Tekaoh
2ecfdb18eb Add an admin menu page 2020-04-15 17:06:59 -04:00
Tekaoh
7c881aaac9 Move checks to included files 2020-04-15 10:52:13 -04:00
Tekaoh
c880c904d5 Blank indices are good 2020-04-15 10:39:25 -04:00
Tekaoh
f515e278a7 Avoid php notices by using proper checks 2020-04-15 07:25:04 -04:00
Tekaoh
cb61131d04 Update readme.txt 2020-04-15 07:24:20 -04:00
Tekaoh
2368828f68 Put readme.txt in trunk 2020-04-15 07:14:33 -04:00
9 changed files with 94 additions and 59 deletions

17
swg-auth/admin/admin.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
add_action('admin_menu', 'swg_auth_menu');
function swg_auth_menu(){
add_menu_page(
'SWG Auth',
'SWG Auth',
'administrator',
'swg-auth-menu',
'swg_auth_menu_html',
'',
3
);
}
function swg_auth_menu_html(){
include(plugin_dir_path(__FILE__) . 'swg-auth-menu-html.php');
}

1
swg-auth/admin/index.php Normal file
View File

@@ -0,0 +1 @@
<?php //Shh...

View File

@@ -0,0 +1,16 @@
<div class="wrap">
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
<p>Welcome to SWG Auth for Wordpress. Your plugin is functioning normally.</p>
<p>To enable authentication for your SWG server, edit these lines in your server config:</p>
<code>
[LoginServer]<br />
useExternalAuth=true<br />
externalAuthURL=<?php echo get_site_url() ?>/?action=swg-auth
</code>
<p>Additionally, you can use this plugin to enable God Mode in game. Wordpress Administrators will also be SWG Admins. To do this, be sure you have compiled the latest version of the src and add these lines to your server config:</p>
<code>
[ServerUtility]<br />
externalAdminLevelsEnabled=true<br />
externalAdminLevelsURL=<?php echo get_site_url() ?>/?action=swg-auth-admin-level
</code>
</div>

View File

@@ -0,0 +1 @@
<?php //Shh...

View File

@@ -0,0 +1,18 @@
<?php
// Check if the swg-auth-admin-level action is requested and that a user_name is provided
if(isset($_GET['action']) && $_GET['action'] == 'swg-auth-admin-level' && isset($_POST['user_name'])){
// Look up the user's ID
$userID = get_user_by('login', $_POST['user_name']);
// Check if the user is a Wordpress Admin
if(user_can($userID, 'administrator')){
// If the user is a Wordpress Admin, automatically send back level 50
$response['message'] = "50";
echo json_encode($response);
die;
}
// Not an admin
$response['message'] = "0";
echo json_encode($response);
die;
}

View File

@@ -0,0 +1,19 @@
<?php
// Check if the swg-auth action is requested and that a user_name and user_password are provided
if(isset($_GET['action']) && $_GET['action'] == 'swg-auth' && isset($_POST['user_name']) && isset($_POST['user_password'])){
// Ask Wordpress to authenticate the user_name and user_password
$userInfo = wp_authenticate_username_password(NULL, $_POST['user_name'], $_POST['user_password']);
// Check if the authentication request returned an error
if(is_wp_error($userInfo)){
// If there was an error, we'll let the client know.
$response['message'] = "Account does not exist or password was incorrect";
} else {
// If there's no error, Success!
$response['message'] = "success";
}
// Json encode our response so that the LoginServer knows what we're talking about
echo json_encode($response);
// Once we've responded, we don't want Wordpress to continue
die;
}

1
swg-auth/index.php Normal file
View File

@@ -0,0 +1 @@
<?php //Shh...

View File

@@ -3,7 +3,7 @@
* Plugin Name: SWG Auth
* Plugin URI: https://tekaohswg.github.io/swg-auth-wordpress.html
* Description: Star Wars Galaxies Authentication for Wordpress
* Version: 0.2
* Version: 0.3
* Author: Tekaoh
* Author URI: https://tekaohswg.github.io
*/
@@ -15,49 +15,10 @@ if(!defined('ABSPATH')){
// Run when Wordpress is loaded
add_action('wp_loaded', 'swg_auth_run');
function swg_auth_run(){
// Check if the swg-auth action is requested
if($_GET['action'] == 'swg-auth'){
// Check if a user_name and user_password are provided
if($_POST['user_name'] && $_POST['user_password']){
// Ask Wordpress to authenticate the user_name and user_password
$userInfo = wp_authenticate_username_password(NULL, $_POST['user_name'], $_POST['user_password']);
// Check if the authentication request returned an error
if(is_wp_error($userInfo)){
// If there was an error, we'll let the client know.
$response['message'] = "Account does not exist or password was incorrect";
} else {
// If there's no error, Success!
$response['message'] = "success";
}
// Json encode our response so that the LoginServer knows what we're talking about
echo json_encode($response);
// Once we've responded, we don't want Wordpress to continue
die;
}
// If we're here, the swg-auth action was requested but no user_name and user_password were provided. That's weird... Don't return anything
die;
}
// Check if the swg-auth-admin-level action is requested
if($_GET['action'] == 'swg-auth-admin-level'){
// Check if a user_name is provided
if($_POST['user_name']){
// Look up the user
$userID = get_user_by('login', $_POST['user_name']);
// Check if the user is a Wordpress Admin
if(user_can($userID, 'administrator')){
// Send back level 50
$response['message'] = "50";
echo json_encode($response);
die;
}
// Not an admin
$response['message'] = "0";
echo json_encode($response);
die;
}
// If we're here, the swg-auth-admin-level action was requested by no user_name was provided. Don't return anything.
die;
}
include(plugin_dir_path(__FILE__) . 'includes/swg-auth-check.php');
include(plugin_dir_path(__FILE__) . 'includes/swg-auth-admin-level-check.php');
}
// Run the admin panel stuff
include(plugin_dir_path(__FILE__) . 'admin/admin.php');

View File

@@ -1,10 +1,9 @@
=== SWG Auth ===
Contributors: tekaoh
Donate link: https://tekaohswg.github.io/donate.html
Tags: admin, integration
Requires at least: 2.8
Tested up to: 5.4
Stable tag: 0.2
Stable tag: 0.3
Requires PHP: 4.3
License: The Unlicense
License URI: https://unlicense.org
@@ -13,7 +12,7 @@ Star Wars Galaxies Authentication for Wordpress
== Description ==
If you're running a Star Wars Galaxies server, now you can use Wordpress to allow users to sign up and change their passwords.
If you're running a Star Wars Galaxies server, now you can use Wordpress to manage your users.
== Installation ==
@@ -22,23 +21,25 @@ If you're running a Star Wars Galaxies server, now you can use Wordpress to allo
3. Point your SWG server's externalAuthURL config flag to `http://url.to.wordpress/?action=swg-auth`.
4. Done!
== Frequently Asked Questions ==
= How do I run a Star Wars Galaxies server? =
Check out https://swg-source.github.io/ and join that community on discord. If you'd rather build your own VM than download one, you could check out https://tekaohswg.github.io/new.html but be aware that this isn't for the faint of heart.
== Screenshots ==
1. Once this plugin is installed, your SWG Server will authenticate users with Wordpress.
== Changelog ==
= 0.3 =
* Added an admin menu that provides you with the server cfg you need
* Bug fixes
= 0.2 =
* Wordpress can now take requests for admin level checks
= 0.1 =
* Initial version
* Authentication is functional
== Upgrade Notice ==
= 0.3 =
* Bug fixes
= 0.2 =
* New features
= 0.1 =
* Initial version