Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie

Dane sql w nowym pliku


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
11 odpowiedzi w tym temacie

#1 Fiziol

    Życzliwy

  • Użytkownik

Reputacja: 14
Początkujący

  • Postów:27
Offline

Napisano 22.03.2012 22:46

Witam Potrzebuje informacji na temat zapisu mysql. Mam kilka pluginów ktore mam podpięte pod jedną baze mysql i sie tam robi kocial chce aby mi ktoś wytlumaczyl ( podesłał link ) jak zmienić zapis w pluginie .sma aby nie czytał z sql.cfg tylko np nowysql.cfg + do tego jak napisdać aby każdy plugin mial swoje dane cvar sql np nie amx_sql_host tylko amx_sql_hosttop15. Bardzo bym prosił o przykład poprawnie napisanego pluginu i poradnik maly.
  • +
  • -
  • 0

#2 Na 5tyk

    Godlike

  • Użytkownik

Reputacja: 430
Wszechobecny

  • Postów:1 712
  • GG:
  • Imię:Patryk
  • Lokalizacja:PL
Offline

Napisano 22.03.2012 22:58

Wystarczy zmienic w *.sma kilka 4-5 linijek aby bylo np.
amx_blabla_host
amx_blabla_user
amx_blabla_db
amx_blabla_pass
  • +
  • -
  • 0

#3 Fiziol

    Życzliwy

  • Autor tematu
  • Użytkownik

Reputacja: 14
Początkujący

  • Postów:27
Offline

Napisano 23.03.2012 08:48

I plugin sam wykryje że ma czytać z pliku nowysql.cfg??

Czyli jak mam tak wpisane

Dołączona grafika

I po edycji pluginu to co mówileś wszystko powinno działąć ?

Dołączona grafika
  • +
  • -
  • 0

#4 Na 5tyk

    Godlike

  • Użytkownik

Reputacja: 430
Wszechobecny

  • Postów:1 712
  • GG:
  • Imię:Patryk
  • Lokalizacja:PL
Offline

Napisano 23.03.2012 09:11

Tam co zaznaczyłeś amx_sql_hostczat (i inne) będzie czytało z sql.cfg
  • +
  • -
  • 0

#5 Fiziol

    Życzliwy

  • Autor tematu
  • Użytkownik

Reputacja: 14
Początkujący

  • Postów:27
Offline

Napisano 23.03.2012 14:08

Tyle to wiem sam, ale mi chodzi aby czytalo z nowysql.cfg!!!
  • +
  • -
  • 0

#6 Na 5tyk

    Godlike

  • Użytkownik

Reputacja: 430
Wszechobecny

  • Postów:1 712
  • GG:
  • Imię:Patryk
  • Lokalizacja:PL
Offline

Napisano 24.03.2012 08:52

Dziś zobaczę jak to zrobić, bo szczerze mówiąc z pamięci na fonie to g***o pomoge :D
  • +
  • -
  • 0

#7 DarkGL

    Nie oddam ciasteczka !

  • Administrator

Reputacja: 6 553
Godlike

  • Postów:11 976
  • GG:
  • Steam:steam
  • Imię:Rafał
  • Lokalizacja:Warszawa
Offline

Napisano 24.03.2012 09:02

zmieniasz nazwy cvarów w sma pluginu
możesz je teraz dopisać do amxx.cfg a jak chcesz w odzielnnym pliku to kod do wczytania
new szPath[256];
	formatex(szPath[ get_configsdir( szPath,charsmax( szPath ) ) ], charsmax( szPath ),"/nowysql.cfg");
	
	server_cmd("exec %s",szPath);
	server_exec()
dodajesz ten kod już po zarejestrowaniu cvarów
  • +
  • -
  • 0

#8 Fiziol

    Życzliwy

  • Autor tematu
  • Użytkownik

Reputacja: 14
Początkujący

  • Postów:27
Offline

Napisano 24.03.2012 21:23

zmieniasz nazwy cvarów w sma pluginu możesz je teraz dopisać do amxx.cfg


public check_sql()
{

    new host[64], user[64], pass[64], db[64],errorcode

    get_cvar_string("rank_db_host", host, 63)
    get_cvar_string("rank_db_user", user, 63)
    get_cvar_string("rank_db_pass", pass, 63)
    get_cvar_string("rank_db_database", db, 63)

    g_SqlX = SQL_MakeDbTuple(host, user, pass, db)
    g_SqlConnection = SQL_Connect(g_SqlX,errorcode,g_error,511);
 
    if (!g_SqlConnection) {
	    console_print(0,"Chat log SQL: Could not connect to SQL database.!")
	    return log_amx("Chat log SQL: Could not connect to SQL database.")
    }

i jak SKOMPILOWALEM i dopisałem do amxx.cfg to nie trybi
  • +
  • -
  • 0

#9 DarkGL

    Nie oddam ciasteczka !

  • Administrator

Reputacja: 6 553
Godlike

  • Postów:11 976
  • GG:
  • Steam:steam
  • Imię:Rafał
  • Lokalizacja:Warszawa
Offline

Napisano 25.03.2012 09:19

nie trybi w sensie ?
logi ?
sprawdź czy podałeś dobre dane do sql
  • +
  • -
  • 0

#10 Fiziol

    Życzliwy

  • Autor tematu
  • Użytkownik

Reputacja: 14
Początkujący

  • Postów:27
Offline

Napisano 25.03.2012 10:03

logi z pliku error

L 03/25/2012 - 10:35:20: [MySQL] Invalid handle: 0
L 03/25/2012 - 10:35:20: [AMXX] Run time error 10 (plugin "chat_logger_sq.amxx") (native "SQL_FreeHandle") - debug not enabled!
L 03/25/2012 - 10:35:20: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).


logi z pliku tam gdzie sie zapisują logi startu prawidlowo dzialajacych pluginów

L 03/25/2012 - 10:35:23: [chat_logger_sq.amxx] Chat log SQL: Could not connect to SQL database.


Plugin sma skompilowałem podpialem pod te same dane co amxbans, tabela sie nie utworzyla w phpmyadmin.

oryginalny plik sma ( jest to plugin odpowiedzialny za zapis z say serwera )

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <sqlx>


#define PLUGINNAME "Chat Logger SQL"
#define VERSION "0.8b"
#define AUTHOR "naputtaja"
#define table "amx_chat_log"
#define MAXLEN 511
#define MAX_WORDS 150

// SQL Settings
new Handle:g_SqlX
new Handle:g_SqlConnection
new g_error[512]
new g_No_Save_Words[MAX_WORDS][20]
new g_No_Save_Num

new const TEAMNAME[_:CsTeams][] = {"*DEAD*", "(Terrorist)", "(Counter-Terrorist)", "*SPEC*"}



public check_sql()
{

new host[64], user[64], pass[64], db[64],errorcode

get_cvar_string("amx_sql_host", host, 63)
get_cvar_string("amx_sql_user", user, 63)
get_cvar_string("amx_sql_pass", pass, 63)
get_cvar_string("amx_sql_db", db, 63)

g_SqlX = SQL_MakeDbTuple(host, user, pass, db)
g_SqlConnection = SQL_Connect(g_SqlX,errorcode,g_error,511);

if (!g_SqlConnection) {
console_print(0,"Chat log SQL: Could not connect to SQL database.!")
return log_amx("Chat log SQL: Could not connect to SQL database.")
}

new query_create[1001]
format(query_create,1000,"CREATE TABLE IF NOT EXISTS `%s`(`id` int(11) NOT NULL auto_increment,`name` varchar(100) NOT NULL default '',`authid` varchar(100) NOT NULL default '',`ip` varchar(100) NOT NULL default '',`alive` int(11) NOT NULL default '0', `team` varchar(100) NOT NULL default '',`date` date NOT NULL default '0000-00-00',`time` time NOT NULL default '00:00:00',`cmd` varchar(100) NOT NULL default '',`message` text NOT NULL,PRIMARY KEY (`id`));",table)
SQL_ThreadQuery(g_SqlX,"QueryHandle",query_create)

console_print(0,"[AMXX SQL] Connected!")
return PLUGIN_CONTINUE
}

public chat_log_sql(id)
{
if(is_user_bot(id)) return



static datestr[11]
new authid[16],name[32],ip[16],timestr[9]
new cmd[9]

if(!is_user_connected(id)) return



read_argv(0,cmd,8)

new message[192]
read_args(message,191)
remove_quotes(message)

new i = 0
while ( i < g_No_Save_Num )
{
if ( containi ( message, g_No_Save_Words[i++] ) != -1 )return
}

new CsTeams:team = cs_get_user_team(id)
get_user_authid(id,authid,15)
get_user_name(id,name,31)
get_user_ip(id, ip, 15, 1)

get_time("%Y.%m.%d", datestr, 10)
get_time("%H:%M:%S", timestr, 8)

new query[1001]
format(query,1000,"INSERT into %s (name,authid,ip,alive,team,date,time,message,cmd) values ('%s','%s','%s','%d','%s','%s','%s','%s','%s')",table,name,authid,ip,is_user_alive(id),TEAMNAME[_:team],datestr,timestr,message,cmd)
SQL_ThreadQuery(g_SqlX,"QueryHandle",query)
}


public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
if(FailState == TQUERY_CONNECT_FAILED)
return log_amx("Chat log SQL: Could not connect to SQL database.")

else if(FailState == TQUERY_QUERY_FAILED)
return log_amx("Chat log SQL: Query failed")

if(Errcode)
return log_amx("Chat log SQL: Error on query: %s",Error)

new DataNum
while(SQL_MoreResults(Query))
{
DataNum = SQL_ReadResult(Query,0)
server_print("zomg, some data: %s",DataNum)
SQL_NextRow(Query)
}
return PLUGIN_CONTINUE
}

readList()
{
new Configsdir[64]
new NoSaveWords_file[64]
get_configsdir( Configsdir, 63 )
format(NoSaveWords_file, 63, "%s/ChatLoggerSQL_NoSaveWords.ini", Configsdir )

if ( !file_exists(NoSaveWords_file) )
{
return log_amx("Chat log SQL: ChatLoggerSQL_NoSaveWords.ini File not found")
server_print ( "====================================================================" )
server_print ( "[Chat Logger Sql] loaded ChatLoggerSQL_NoSaveWords.ini File not found", g_No_Save_Num )
server_print ( "====================================================================" )
}


new len, i=0
while( i < MAX_WORDS && read_file( NoSaveWords_file, i , g_No_Save_Words[g_No_Save_Num], 19, len ) )
{
i++
if( g_No_Save_Words[g_No_Save_Num][0] == ';' || len == 0 )
continue
g_No_Save_Num++
}

i=0

server_print ( "======================================================" )
server_print ( "[Chat Logger Sql] loaded %d No Save words", g_No_Save_Num )
server_print ( "======================================================" )

return PLUGIN_CONTINUE

}

public plugin_end()
{
SQL_FreeHandle(g_SqlConnection)
return
}

public plugin_init()
{
register_plugin(PLUGINNAME, VERSION, AUTHOR)
register_cvar("amx_chat_logger",VERSION,FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)

register_clcmd("say", "chat_log_sql")
register_clcmd("say_team", "chat_log_sql")
readList()
set_task(0.1, "check_sql")
return PLUGIN_CONTINUE
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1035\\ f0\\ fs16 \n\\ par }
*/


Plugin po przerobce

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <sqlx>


#define PLUGINNAME "Chat Logger SQL"
#define VERSION "0.8b"
#define AUTHOR "naputtaja"
#define table "amx_chat_log"
#define MAXLEN 511
#define MAX_WORDS 150

// SQL Settings
new Handle:g_SqlX
new Handle:g_SqlConnection
new g_error[512]
new g_No_Save_Words[MAX_WORDS][20]
new g_No_Save_Num

new const TEAMNAME[_:CsTeams][] = {"*DEAD*", "(Terrorist)", "(Counter-Terrorist)", "*SPEC*"}



public check_sql()
{

new host[64], user[64], pass[64], db[64],errorcode


get_cvar_string("rank_db_host", host, 63)
get_cvar_string("rank_db_user", user, 63)
get_cvar_string("rank_db_pass", pass, 63)
get_cvar_string("rank_db_database", db, 63)




g_SqlX = SQL_MakeDbTuple(host, user, pass, db)
g_SqlConnection = SQL_Connect(g_SqlX,errorcode,g_error,511);

if (!g_SqlConnection) {
console_print(0,"Chat log SQL: Could not connect to SQL database.!")
return log_amx("Chat log SQL: Could not connect to SQL database.")
}

new query_create[1001]
format(query_create,1000,"CREATE TABLE IF NOT EXISTS `%s`(`id` int(11) NOT NULL auto_increment,`name` varchar(100) NOT NULL default '',`authid` varchar(100) NOT NULL default '',`ip` varchar(100) NOT NULL default '',`alive` int(11) NOT NULL default '0', `team` varchar(100) NOT NULL default '',`date` date NOT NULL default '0000-00-00',`time` time NOT NULL default '00:00:00',`cmd` varchar(100) NOT NULL default '',`message` text NOT NULL,PRIMARY KEY (`id`));",table)
SQL_ThreadQuery(g_SqlX,"QueryHandle",query_create)

console_print(0,"[AMXX SQL] Connected!")
return PLUGIN_CONTINUE
}

public chat_log_sql(id)
{
if(is_user_bot(id)) return



static datestr[11]
new authid[16],name[32],ip[16],timestr[9]
new cmd[9]

if(!is_user_connected(id)) return



read_argv(0,cmd,8)

new message[192]
read_args(message,191)
remove_quotes(message)

new i = 0
while ( i < g_No_Save_Num )
{
if ( containi ( message, g_No_Save_Words[i++] ) != -1 )return
}

new CsTeams:team = cs_get_user_team(id)
get_user_authid(id,authid,15)
get_user_name(id,name,31)
get_user_ip(id, ip, 15, 1)

get_time("%Y.%m.%d", datestr, 10)
get_time("%H:%M:%S", timestr, 8)

new query[1001]
format(query,1000,"INSERT into %s (name,authid,ip,alive,team,date,time,message,cmd) values ('%s','%s','%s','%d','%s','%s','%s','%s','%s')",table,name,authid,ip,is_user_alive(id),TEAMNAME[_:team],datestr,timestr,message,cmd)
SQL_ThreadQuery(g_SqlX,"QueryHandle",query)
}


public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
if(FailState == TQUERY_CONNECT_FAILED)
return log_amx("Chat log SQL: Could not connect to SQL database.")

else if(FailState == TQUERY_QUERY_FAILED)
return log_amx("Chat log SQL: Query failed")

if(Errcode)
return log_amx("Chat log SQL: Error on query: %s",Error)

new DataNum
while(SQL_MoreResults(Query))
{
DataNum = SQL_ReadResult(Query,0)
server_print("zomg, some data: %s",DataNum)
SQL_NextRow(Query)
}
return PLUGIN_CONTINUE
}

readList()
{
new Configsdir[64]
new NoSaveWords_file[64]
get_configsdir( Configsdir, 63 )
format(NoSaveWords_file, 63, "%s/ChatLoggerSQL_NoSaveWords.ini", Configsdir )

if ( !file_exists(NoSaveWords_file) )
{
return log_amx("Chat log SQL: ChatLoggerSQL_NoSaveWords.ini File not found")
server_print ( "====================================================================" )
server_print ( "[Chat Logger Sql] loaded ChatLoggerSQL_NoSaveWords.ini File not found", g_No_Save_Num )
server_print ( "====================================================================" )
}


new len, i=0
while( i < MAX_WORDS && read_file( NoSaveWords_file, i , g_No_Save_Words[g_No_Save_Num], 19, len ) )
{
i++
if( g_No_Save_Words[g_No_Save_Num][0] == ';' || len == 0 )
continue
g_No_Save_Num++
}

i=0

server_print ( "======================================================" )
server_print ( "[Chat Logger Sql] loaded %d No Save words", g_No_Save_Num )
server_print ( "======================================================" )

return PLUGIN_CONTINUE

}

public plugin_end()
{
SQL_FreeHandle(g_SqlConnection)
return
}

public plugin_init()
{
register_plugin(PLUGINNAME, VERSION, AUTHOR)
register_cvar("amx_chat_logger",VERSION,FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY)

register_clcmd("say", "chat_log_sql")
register_clcmd("say_team", "chat_log_sql")
readList()
set_task(0.1, "check_sql")
return PLUGIN_CONTINUE
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1035\\ f0\\ fs16 \n\\ par }
*/


  • +
  • -
  • 0

#11 DarkGL

    Nie oddam ciasteczka !

  • Administrator

Reputacja: 6 553
Godlike

  • Postów:11 976
  • GG:
  • Steam:steam
  • Imię:Rafał
  • Lokalizacja:Warszawa
Offline

Napisano 25.03.2012 10:23

musisz dodac register_cvar pierwotnie w pluginie ich nie ma bo korzysta z standardowych cvarów skoro używasz innych musisz je zarejestrować
  • +
  • -
  • 0

#12 Fiziol

    Życzliwy

  • Autor tematu
  • Użytkownik

Reputacja: 14
Początkujący

  • Postów:27
Offline

Napisano 25.03.2012 13:31

Kurcze jestem bardzo cienki w tym :/ dopisałem takie coś i mu nawet nie skompilowało :/ napiszesz mi prawidłowo ten plugin :) bo Tobie to zajmnie minutke a ja ciągle tu spamuje :/

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <sqlx>


#define PLUGINNAME "Chat Logger SQL"
#define VERSION "0.8b"
#define AUTHOR "naputtaja"
#define table "amx_chat_log"
#define MAXLEN 511
#define MAX_WORDS 150

// SQL Settings
new Handle:g_SqlX
new Handle:g_SqlConnection
new g_error[512]
new g_No_Save_Words[MAX_WORDS][20]
new g_No_Save_Num

#if defined SQL
#endif


new const TEAMNAME[_:CsTeams][] = {"*DEAD*", "(Terrorist)", "(Counter-Terrorist)", "*SPEC*"}

{
#if defined SQL
register_cvar("czat_db_host", "localhost");
register_cvar("czat_db_user", "root");
register_cvar("czat_db_pass", "root");
register_cvar("czat_db_database", "czat");
#endif

}

public check_sql()
{

new host[64], user[64], pass[64], db[64],errorcode

get_cvar_string("czat_db_host", host, 63)
get_cvar_string("czat_db_user", user, 63)
get_cvar_string("czat_db_pass", pass, 63)
get_cvar_string("czat_db_database", db, 63)

g_SqlX = SQL_MakeDbTuple(host, user, pass, db)
g_SqlConnection = SQL_Connect(g_SqlX,errorcode,g_error,511);

if (!g_SqlConnection) {
console_print(0,"Chat log SQL: Could not connect to SQL database.!")
return log_amx("Chat log SQL: Could not connect to SQL database.")
}


  • +
  • -
  • 0




Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych