Skocz do zawartości

Nowy szablon forum

mygo.pl

Stworzyliśmy dla Was nowy wygląd forum. Z pewnością znajdziesz rzeczy, które wg Ciebie mogą zostać zmienione - wspomnij o tym w specjalnym wątku.

Czytaj więcej

Jak założyć własną sieć

serwerów CS

Zastanawiasz się nad prowadzeniem własnej sieci serwerów? Przeczytaj podstawowe informacje, na które należy zwrócić uwagę, przy takim projekcie.

Czytaj więcej

Tworzymy spis sieci

dodaj swoją

Dodaj sieć do której należysz, pozwoli to na promocję i budowę ogólnopolskiej bazy sieci CS.

Czytaj więcej

[ANY] DB++ (Optimized way to use queries)


MYGO.pl
 Udostępnij

Rekomendowane odpowiedzi

  • RSSy
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<= MaxClientsi++)
        
gDataPackConnections[i] = new DataPack();
}

/* Player has joined and transaction is ready */
public void DBPP_PlayerJoin(int iClient, const char[] sSteamTransaction hTransaction)
{
    
/* We want to send nick, so let get it */
    
char sNick[64];
    
GetClientName(iClientsNick64);
    
    
ReplaceString(sNick64"`",     "");
    
ReplaceString(sNick64"'",     "");
    
ReplaceString(sNick64"\"",     "");

    
/* 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(sQuery256"INSERT INTO `connections` (`steam`, `nick`, `time`) VALUES ('%s', '%s', '%d');"
        
sSteamsNickiTime);

    
/* 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(sQuerygDataPackConnections[iClient]);
}

/* Ok, we have a result, so let's log it out */
public void DBPP_PlayerJoin_Results(int iClient, const char[] sSteamint iQueryDBResultSet hResultSetDataPack dPack)
{
    
LogConnection(iClientdPackfalse);
    
    
/* 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[] sSteamint iFailedQueryDataPack dPack)
{
    
LogConnection(iClientdPacktrue);
}

void LogConnection(int iClientDataPack dPackbool 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(sNick64);
        
    
int iTime dPack.ReadCell();
    
    
char sTime[32];
    
FormatTime(sTime32"%d/%m/%y %H:%M:%S"iTime);
    
    
LogMessage("[DB++] Player %s joined at %s"sNicksTime);
    
    
/* Our query was failure */
    
if (bFailure == true)
    {
        
char sQuery[256];
        
dPack.ReadString(sQuery256);
    
        
LogMessage("[DB++] Failed query: %s"sQuery);
    }


2. Write your own (Tutorial will be later :D)

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 


Attached Files
File Type: zip dbpp.zip (18.6 KB)

Wyświetl pełny artykuł

Odnośnik do komentarza
Udostępnij na innych stronach

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
 Udostępnij

  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...