So,
What I am trying to do is really simple
Store the name, steamid and IP on the database when he joins the server. But, when connecting I want to the plugin to check if the player is already registered. So, we get the IP that is stored on the database for the player's steamid. If the database player's IP does not match to the actual player's IP, I want it to write a new line with new data, as such the name, steamID and iP.
The problem is that it is not storing any data.
PHP Code:
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"
#include <sourcemod>
#include <sdktools>
Database DB = null;
char Error[256];
#pragma newdecls required
public Plugin myinfo =
{
name = "[SpirT - Database Query]",
author = PLUGIN_AUTHOR,
description = "",
version = PLUGIN_VERSION,
url = ""
};
public void OnPluginStart()
{
DB = SQL_Connect("spirtdb", true, Error, sizeof(Error));
if(DB == null)
{
PrintToServer("[DB] Cannot connect to MySQL Server: %s", Error);
CloseHandle(DB);
}
else
{
PrintToServer("[DB] Connection Successful");
char squery[256];
Format(squery, sizeof(squery), "CREATE TABLE IF NOT EXISTS players (name varchar(32) NOT NULL, steamid varchar(32) NOT NULL, ip varchar(64) NOT NULL)");
if(!SQL_FastQuery(DB, squery))
{
char terror[256];
SQL_GetError(DB, terror, sizeof(terror));
PrintToServer("[DB] Could not create db tables. Error: %s", terror);
}
else
{
PrintToServer("[DB] Tables Created if they don't exist.");
}
}
}
public void OnClientPutInServer(int client)
{
char iname[32];
GetClientName(client, iname, sizeof(iname));
char iid[32];
GetClientAuthId(client, AuthId_Steam2, iid, sizeof(iid));
char iip[64];
GetClientIP(client, iip, sizeof(iip), true);
char squery[256];
Format(squery, sizeof(squery), "SELECT ip FROM players WHERE steamid = '%s'", iid);
DBResultSet select = SQL_Query(DB, squery);
if(select == null)
{
PrintToServer("[DB] Could not get data from the database.");
return;
}
char dbIP[64];
SQL_FetchString(DB, 0, dbIP, sizeof(dbIP));
if(StrEqual(dbIP, iip))
{
PrintToServer("[DB] Player is already saved on the database.");
return;
}
char newquery[256];
Format(newquery, sizeof(newquery), "INSERT INTO players (name, steamid, ip) VALUES ('%s', '%s', '%s')", iname, iid, iip);
DBResultSet query2 = SQL_Query(DB, newquery);
if(query2 == null)
{
PrintToServer("[DB] Could not save new player data.");
return;
}
PrintToServer("[DB] New player data was save in the database with success.");
return;
}
Any solution for the plugin to fix my issue?
OBS: That plugin was storing the player data EVERYTIME he joined the server, so I tried to update it to a more NON-SPAMMING version. This "new update" on the source above is creating the tables but not storing data.
Best Regards,
SpirT.
__________________