MyBB Community Forums

Full Version: My first plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
EDIT: ****** FULL WORKING PLUGIN is in post #3 *********
I'm trying to make a plugin to check user name against a out side database. I am using the "hello world" plugin as a staring point. I made the changes to do the work I need but it dose not seem to run. I enabled error reporting and got not errors but it is not showing on the plugins page for me to active.

here is the code


$plugins->add_hook("member_do_register_start", "check_user_in_game");

function check_user_in_game_info()
{
	return array(
		"name"			=> "Check User In Game",
		"description"	=> "Check Users IGN (in game name) for minecraft",
		"version"		=> "1.0",
		"guid" 			=> "",
		"compatibility" => "1.6.7"
	);
}
function check_user_in_game($this)
{

    $conUserName = mysql_connect($check_user_in_game_DB_location,$check_user_in_game_DB_name,$check_user_in_game_DB_pass);
    mysql_select_db($check_user_in_game_DB_name, $conUserName);
    $checkUserNameCall = "SELECT playername FROM `".$check_user_in_game_DB_table."` WHERE playername = '".mysql_real_escape_string($this->data['username'])."' LIMIT 1";
    $checkUserNameResult = mysql_query($checkUserNameCall,$conUserName) or $this->set_error("Oh, snap! Something went wrong if HordeCraft Member. dang!");

	if($checkUserNameResult && mysql_num_rows($checkUpdateResult) < 1)
	{
	   mysql_close($conUserName);
	   $this->set_error("Not A HordeCraft Member.");
	   return false;
	}
	mysql_close($conUserName);
	return true;
}

the only thing not showen is some vars for DB info.
why is this not activating or even showing in the plugins page.

Thanks.
There is no activate() function in the code. Add the following code in the code;
function check_user_in_game_activate()
{
}

function check_user_in_game_deactivate()
{
}

This will atleast show on the plugin's activate / deactivate link. Also make sure that your plugin is named like: check_user_in_game.php and place inside the ./inc/plugins/ folder.
Thank you for you reply. That was it I fell kinda dumb for not seeing that now.

Had another small issue, but will start a new post for it.

Thank you again.
*********************
Here is the whole thing working Just add you Database info and change the feed back to you forum.
*********************
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("datahandler_user_validate", "check_user_in_game_name");

function check_user_in_game_name_info()
{
	/**
	 * Array of information about the plugin.
	 * name: The name of the plugin
	 * description: Description of what the plugin does
	 * website: The website the plugin is maintained at (Optional)
	 * author: The name of the author of the plugin
	 * authorsite: The URL to the website of the author (Optional)
	 * version: The version number of the plugin
	 * guid: Unique ID issued by the MyBB Mods site for version checking
	 * compatibility: A CSV list of MyBB versions supported. Ex, "121,123", "12*". Wildcards supported.
	 */
	return array(
		"name"			=> "Check User In Game",
		"description"	=> "Check Users IGN (in game name) for minecraft",
		"website"		=> " ",
		"author"		=> " ",
		"authorsite"	=> " ",
		"version"		=> "1.0",
		"guid" 			=> "",
		"compatibility" => "1607"
	);
}
function check_user_in_game_name_activate()
{
}

function check_user_in_game_name_deactivate()
{
}
function check_user_in_game_name($thisSignup)
{
    GLOBAL $mybb;
    GLOBAL $errors;
    $check_user_in_game_DB_location     = "xxxx";
    $check_user_in_game_DB_user_name    = "xxxx";
    $check_user_in_game_DB_user_pass    = "xxxx";
    $check_user_in_game_DB_name         = "xxxx";
    $check_user_in_game_DB_table        = "xxxx";
    $check_user_in_game_DB_table_column = "xxxx";

    $conUserName = mysql_connect($check_user_in_game_DB_location,$check_user_in_game_DB_user_name,$check_user_in_game_DB_user_pass)or die("error 1");
    mysql_select_db($check_user_in_game_DB_name, $conUserName);
    $checkUserNameCall = "SELECT ".$check_user_in_game_DB_table_column." FROM `".$check_user_in_game_DB_table."` WHERE ".$check_user_in_game_DB_table_column." = '".mysql_real_escape_string($mybb->input['username'])."' LIMIT 1";
    $checkUserNameResult = mysql_query($checkUserNameCall,$conUserName)or die("error 2 ".mysql_error());// $errors[] = "Oh, snap! Something went wrong if HordeCraft Member. dang!";

	if($checkUserNameResult && mysql_num_rows($checkUserNameResult) < 1)
	{

	    mysql_close($conUserName);
	    $thisSignup->set_error("User Name MUST be the same as your IGN (In Game Name) OR Not A HordeCraft Member.");
	    return false;
	} elseif(!$checkUserNameResult){
	    $thisSignup->set_error("Unable to check your players Status. Please contant an site admin.");
	    return false;
    }
	mysql_close($conUserName);
	return true;
}
Hope this is helpful to someone else.
Hay,

where does this code go(as in which file?)?

Thanks
Create a .php file naming "check_user_in_game_name" (without quotes). Then paste the complete code of Post#3. Activate it in AdminCP > Plugins