Hello! Want to release my new plugin, which will help you to optimize network oriented queries.
Installation:
1. Put folder from `dbpp.zip` to root folder of game (Example: tf2/ csgo/).
2. Add in databases.cfg this one:
PHP Code:
"dbpp"
{
"driver" "mysql"
"host" "your_ip"
"database" "your_db"
"user" "your_user"
"pass" "your_password"
}
3. Test and write your own plugins!
How to use this API?
1. Analyze this example
PHP Code:
#include <sourcemod>
#include <dbplusplus>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo =
{
name = "[DB++] Test Plugin",
author = "Jake",
description = "-",
version = "0.1 beta",
url = "http://ezplay.pro/"
};
/**
* We're creating datapack
* to identify query
* and send some data
**/
DataPack gDataPackConnections[MAXPLAYERS];
public void OnPluginStart()
{
/* Create datapack for each player */
for (int i = 1; i <= MaxClients; i++)
gDataPackConnections[i] = new DataPack();
}
/* Player has joined and transaction is ready */
public void DBPP_PlayerJoin(int iClient, const char[] sSteam, Transaction hTransaction)
{
/* We want to send nick, so let get it */
char sNick[64];
GetClientName(iClient, sNick, 64);
ReplaceString(sNick, 64, "`", "");
ReplaceString(sNick, 64, "'", "");
ReplaceString(sNick, 64, "\"", "");
/* Time of connection */
int iTime = GetTime();
/* Formatting query */
char sQuery[256];
/* Just insert data in MySQL */
/* For Example: */
/* INSERT INTO `table` (`field`) VALUES (`data`); */
FormatEx(sQuery, 256, "INSERT INTO `connections` (`steam`, `nick`, `time`) VALUES ('%s', '%s', '%d');",
sSteam, sNick, iTime);
/* Clearing data from datapack */
gDataPackConnections[iClient].Reset(true);
/* Writing new data */
gDataPackConnections[iClient].WriteString(sNick);
gDataPackConnections[iClient].WriteCell(iTime);
gDataPackConnections[iClient].WriteString(sQuery);
/* Ok, we are ready to */
/* add query in transaction */
/* 1st param - query */
/* 2nd param - datapack */
hTransaction.AddQuery(sQuery, gDataPackConnections[iClient]);
}
/* Ok, we have a result, so let's log it out */
public void DBPP_PlayerJoin_Results(int iClient, const char[] sSteam, int iQuery, DBResultSet hResultSet, DataPack dPack)
{
LogConnection(iClient, dPack, false);
/* Don't forget: */
/* Result sets will be deleted automaticly */
}
/* Something goes wrong, but we still can log data */
public void DBPP_PlayerJoin_Fail(int iClient, const char[] sSteam, int iFailedQuery, DataPack dPack)
{
LogConnection(iClient, dPack, true);
}
void LogConnection(int iClient, DataPack dPack, bool bFailure)
{
/* Checking for needed query */
/* If false - it's not our query */
if (dPack != gDataPackConnections[iClient])
return;
/* Reset position in datapack */
dPack.Reset();
/* Read data and log it. Simple. */
char sNick[64];
dPack.ReadString(sNick, 64);
int iTime = dPack.ReadCell();
char sTime[32];
FormatTime(sTime, 32, "%d/%m/%y %H:%M:%S", iTime);
LogMessage("[DB++] Player %s joined at %s", sNick, sTime);
/* Our query was failure */
if (bFailure == true)
{
char sQuery[256];
dPack.ReadString(sQuery, 256);
LogMessage("[DB++] Failed query: %s", sQuery);
}
}
2. Write your own (Tutorial will be later
)
You can change config source code of API
PHP Code:
// Config name in `databases.cfg`
#define CONFIG_NAME "dbpp"
// Charset, which is used in database
// (be careful when you change it)
#define CONFIG_CHARSET "utf8"
// Auth ID
// (change if you know what you do)
#define CONFIG_AUTHID AuthId_Steam2
// Auth ID Length
// (not necessary to change it)
#define CONFIG_STEAMLENGTH 32
// Database Priorities
// (please don't set all to high if you don't need)
#define CONFIG_DBPRIO_JOIN DBPrio_Normal
#define CONFIG_DBPRIO_LEAVE DBPrio_Normal
#define CONFIG_DBPRIO_EVENT DBPrio_Low
// Comment line below if loading of player data on plugin start is not needed
#define CONFIG_LOAD_PLAYERS_ON_INIT