Junior Member
|
08-09-2018
, 15:12
Re: [REQ] Register and login system (mysql)
|
#8
|
Not a duplicate. Unfortunately, Mugiwara does not do it.
Because he did 1 but he was wrong. It does not work any part of it either.
Please help! Not working!
Quote:
#include <sourcemod>
#pragma semicolon 1
Database g_hDatabase;
char g_sSteamid[MAXPLAYERS + 1][32];
char g_sName[MAXPLAYERS + 1][256];
char g_sPassword[MAXPLAYERS + 1][256];
char g_sEmail[MAXPLAYERS + 1][256];
bool g_bRegister;
public void OnPluginStart()
{
Database.Connect(SQL_Connection, "vipsystem");
}
public void SQL_Connection(Database hDatabase, const char[] sError, int iData)
{
if (hDatabase == null)
ThrowError(sError);
else
{
g_hDatabase = hDatabase;
g_hDatabase.Query(SQL_Error, "CREATE TABLE IF NOT EXISTS players (steam_id VARCHAR(32) NOT NULL PRIMARY KEY, account_name VARCHAR(32) NOT NULL, account_password VARCHAR(32) NOT NULL, account_email VARCHAR(32) NOT NULL)");
}
}
public void SQL_Error(Database hDatabase, DBResultSet hResults, const char[] sError, int iData)
{
if (hResults == null)
ThrowError(sError);
}
public void OnClientPostAdminCheck(int iClient)
{
if (IsValidClient(iClient))
{
GetClientAuthId(iClient, AuthId_Steam2, g_sSteamid[iClient], sizeof(g_sSteamid[]));
Menu hMenu = new Menu(Menu_Authorization);
hMenu.SetTitle("Choose Your Option.");
hMenu.AddItem("", "Login");
hMenu.AddItem("", "Register");
hMenu.Display(iClient, MENU_TIME_FOREVER);
}
}
public int Menu_Authorization(Menu hMenu, MenuAction hAction, int iClient, int iParam)
{
switch (hAction)
{
case MenuAction_Select:
{
switch (iParam)
{
case 0:
{
char sQuery[256];
//Format(sQuery, sizeof(sQuery), "SELECT * FROM players WHERE steam_id = \"%s\"", g_sSteamid[iClient]);
Format(sQuery, sizeof(sQuery), "SELECT * FROM players WHERE steam_id = '%s'", g_sSteamid[iClient]);
g_hDatabase.Query(SQL_Authorization, sQuery, GetClientUserId(iClient));
}
case 1:
g_bRegister = true;
}
}
case MenuAction_End:
delete hMenu;
}
//char sQuery[256];
//SQL_TQuery(g_hDatabase, SQL_ErrorCheckCallBack, sQuery);
}
public void SQL_Authorization(Database hDatabase, DBResultSet hResults, const char[] sError, int iData)
{
if (hResults == null)
ThrowError(sError);
int iClient = GetClientOfUserId(iData);
if (IsValidClient(iClient))
{
if (hResults.RowCount != 0)
{
hResults.FetchRow();
hResults.FetchString(1, g_sSteamid[iClient], sizeof(g_sSteamid[]));
hResults.FetchString(2, g_sName[iClient], sizeof(g_sName[]));
hResults.FetchString(3, g_sPassword[iClient], sizeof(g_sPassword[]));
//hResults.FetchString(4, g_sEmail[iClient], sizeof(g_sEmail[]));
}
else
PrintToChat(iClient, "Your account wasn't found! You may register.");
}
//SQL_TQuery(g_hDatabase, SQL_ErrorCheckCallBack, sQuery);
SQL_TQuery(g_hDatabase, SQL_ErrorCheckCallBack, hResults.FetchRow());
}
public Action OnClientSayCommand(int iClient, const char[] sCommand, const char[] sArgs)
{
if (g_bRegister)
{
char sName[64], sPassword1[64], sPassword2[64], sEmail[64];
GetCmdArg(1, sName, sizeof(sName));
GetCmdArg(2, sPassword1, sizeof(sPassword1));
GetCmdArg(3, sPassword2, sizeof(sPassword2));
GetCmdArg(4, sEmail, sizeof(sEmail));
if (sPassword1[0] != sPassword2[0])
{
PrintToChat(iClient, "Invalid password confirmation.");
return Plugin_Handled;
}
char sQuery[256];
//Format(sQuery, sizeof(sQuery), "INSERT INTO players (steam_id, account_name, account_password, account_email) VALUES (\"%s\", \"%s\", \"%s\", \"%s\")", g_sSteamid[iClient], sName, sPassword1, sEmail);
Format(sQuery, sizeof(sQuery), "INSERT INTO players (steam_id, account_name, account_password, account_email) VALUES ('%s', '%s', '%s', '%s')", g_sSteamid[iClient], sName, sPassword1, sEmail);
g_hDatabase.Query(SQL_Error, sQuery);
g_bRegister = false;
return Plugin_Handled;
}
return Plugin_Continue;
}
public SQL_ErrorCheckCallBack(Handlewner, Handle:hDatabase, const String:error[], any:data)
{
// This is just an errorcallback for function who normally don't return any data
if(hDatabase == INVALID_HANDLE)
{
SetFailState("Query failed! %s", error);
}
}
stock bool IsValidClient(int iClient)
{
if (!(0 < iClient <= MaxClients) || !IsClientInGame(iClient) || IsFakeClient(iClient))
return false;
return true;
}
|
Register error:
L 08/20/2018 - 13:28:57: [SM] Exception reported: No command callback available
L 08/20/2018 - 13:28:57: [SM] Blaming: Regandlogin.smx
L 08/20/2018 - 13:28:57: [SM] Call stack trace:
L 08/20/2018 - 13:28:57: [SM] [0] GetCmdArg
L 08/20/2018 - 13:28:57: [SM] [1] Line 118, Regandlogin.sp::OnClientSayCommand
login error: no errors but, not working.
Last edited by raptor666; 08-20-2018 at 07:32.
|
|