Raised This Month: $ Target: $400
 0% 

Odd Array Problem... need help :)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DaSoul
Senior Member
Join Date: Jan 2006
Old 02-02-2006 , 13:07   Odd Array Problem... need help :)
Reply With Quote #1

I know this code is not perfect...

There is also probably some better ways to do anything that I have done. Any input is appreciated.

It reads pretty much everybody in correctly.

But one user did not have a proper steam id to write to the users.ini file. So I added the server_print statements to find out what was going on.

I get this as my output. It doesnt make sense to me why he would have a b as his steam id. I read it in properly and test the value and it is correctly Hawks steam id.

Any help will be appreciated.

Thanks,
Soul

Code:
#define PLUGIN "DB Mod" #define VERSION "1.0" #define AUTHOR "[gOf]-Soul" /* * * * * */ #include <amxmodx> #include <amxmisc> #include <dbi> #define USERID      0 #define USERNAME    1 #define USERFLAGS   2 #define GROUPNAME   0 #define GROUPFLAGS  1 new Groups[10][2][255] new groupcount = 0 new Admins[250][3][50] new admincount = 0 public plugin_init() {         register_plugin(PLUGIN, VERSION, AUTHOR)     register_cvar("dbmod_sql_host","127.0.0.1")     register_cvar("dbmod_sql_username","root")     register_cvar("dbmod_sql_password","")     register_cvar("dbmod_sql_database","amx")     //register_cvar("dbmod_sql_prefix","dbmod_")         new loading[255]     format(loading,255,"Loading Plugin: %s <> Created By: %s <> Version: %s",PLUGIN,AUTHOR,VERSION)     ServerOut(loading)         new configDir[64]     get_configsdir(configDir, 63)             server_cmd("exec %s/dbmod.cfg", configDir)         new dbhost[64],dbusername[32],dbpassword[32],dbdatabase[32],dbprefix[32]     get_cvar_string("dbmod_sql_host",dbhost,63)     get_cvar_string("dbmod_sql_username",dbusername,31)     get_cvar_string("dbmod_sql_password",dbpassword,31)     get_cvar_string("dbmod_sql_database",dbdatabase,31)     get_cvar_string("dbmod_sql_database",dbprefix,31)             //Load groups from group.ini file     new fileGroups[64]//,numgroup=0     format(fileGroups,64,"%s/groups.ini",configDir)         new line = 0,linelength = 0     new linetext[64]     new left[64],right[64]         //new pattern[] = "(.+) (.+)"         while(read_file(fileGroups,line,linetext,64,linelength) != 0){         //server_print("Group line loaded: %s",linetext)         parse(linetext,left,64,right,64)         copy(Groups[line][GROUPNAME],255,left)         copy(Groups[line][GROUPFLAGS],255,right)         groupcount++         line++     }         //Open connection to db     new Sql:mysql = dbi_connect(dbhost, dbusername, dbpassword, dbdatabase)         //If the connection is less than 1, it is bad       if (mysql < SQL_OK) {         new err[255]         new errNum = dbi_error(mysql, err, 254)         new error[255]         format(error,255,"Connection Error: %s|%d", err, errNum)         ServerOut(error)         return 1     }             //query group members     new i     new whereclause[250]     new group_flags[200]     //new where[250]     for (i = 0;i<line;i++){                 //server_print("Group: %s",Groups[i][GROUPNAME])         //if (i==0){         format(whereclause,250,"(g.group_name = '%s')",Groups[i][GROUPNAME])         new notfound[255]         format(notfound,255,"No rows returned for group: %s",Groups[i][GROUPNAME])         //}         //else{         //  format(where, 250, "') or (g.group_name = '%s')",Groups[i][0])         //replace(whereclause,250,"')",where)         //}                 //server_print(whereclause)                         new query[500]                 format(query,500,"select username,user_steamid,g.group_name from phpbb_users as u \         left join phpbb_user_group as ug on u.user_id = ug.user_id \         left join phpbb_groups as g on ug.group_id = g.group_id \         where (%s) and (u.user_steamid like 'STEAM%')\         ",whereclause)                 //server_print(query)         //Query database with the following query...         new Result:res = dbi_query(mysql, query)                 //If the query is greater than 0, you got a handle to the result set            if (res <= RESULT_NONE) {             new err[255]             new errNum = dbi_error(mysql, err, 254)             if (errNum == 0){                 ServerOut(notfound)                             }             else{                 new errout[255]                 format(errout,255,"error3: %s|%d", err, errNum)                 ServerOut(errout)                 continue             }         }                 //server_print("Result handle: %d", res)                 //Get Users for group               new strUsersFile[64]         format(strUsersFile, 63, "%s/users.out", configDir)                 delete_file (strUsersFile)         //Loop through the result set           new adminpos         while (res && dbi_nextrow(res)>0) {             new user_id[50],user_name[50],group_name[255]             //Get the column/field called "keyname" from the result set             dbi_result(res, "user_steamid", user_id, 50)             dbi_result(res, "username", user_name, 50)             dbi_result(res, "group_name", group_name,255)             GetGroupFlags(group_name,group_flags)                         server_print("Seeing User: %s %s %s",user_id,user_name,group_flags)                         adminpos = GetAdminPosition(user_id)             if (GetAdminPosition(user_id) == -1) {                 adminpos = admincount                 admincount++                 server_print("Adding User: %s %s %s Position: %d",user_id,user_name,group_flags,adminpos)                 copy(Admins[adminpos][USERID],50,user_id)                 copy(Admins[adminpos][USERNAME],50,user_name)             }             else{                 server_print("Found User: %s %s %s Position: %d",user_id,user_name,group_flags,adminpos)             }             server_print(Admins[adminpos][USERID])             strcat(Admins[adminpos][USERFLAGS],group_flags,255)                         adminpos = -1                         //Get Array Index             //get_vaultdata ( const key[], [ data[] = "", len = 0 ] )             //set_vaultdata ( const key[], [ const data[] = "" ] )         }                 //Free the result set           dbi_free_result(res)             }         //Close the connection      dbi_close(mysql)             new strUsersFileNew[64],strUsersFile[64],strLine[255]     format(strUsersFileNew, 63, "%s/users.ini", configDir)     format(strUsersFile, 63, "%s/users.ini", configDir)         delete_file (strUsersFileNew)         for (i = 0;i<admincount;i++){         server_print("%d %s %s %s",i,Admins[i][USERID], Admins[i][USERNAME],Admins[i][USERFLAGS])         CleanFlags(Admins[i][USERFLAGS])         server_print("%d %s %s %s",i,Admins[i][USERID], Admins[i][USERNAME],Admins[i][USERFLAGS])                 format(strLine, 255, "%s ^"^" ^"%s^" ^"ce^" ;%s",Admins[i][USERID],Admins[i][USERFLAGS], Admins[i][USERNAME])         write_file(strUsersFileNew,strLine,-1)     }         //new error[250]     if (file_exists(strUsersFileNew))         ServerOut("Users file copied")     //if (file_copy(strUsersFileNew,strUsersFile,error,250,true)){         //}     //else{     //  ServerOut("Users file not copied - error occurred")     //}         return PLUGIN_HANDLED } public ServerOut(output[255]){     new strout[255]     format(strout,255,"[DB MOD] %s",output)     server_print(strout)     log_amx(strout) } public GetGroupFlags(group_name[],flags[]){     for (new i = 0;i<groupcount;i++){         if (equali(Groups[i][GROUPNAME],group_name)){             copy(flags,63,Groups[i][GROUPFLAGS])             return         }     }     copy(flags,63,"")     return } public GetAdminPosition(steam_id[]){     for (new i = 0;i<admincount;i++){         if (equali(Admins[i][USERID],steam_id))             return i     }     return -1 } public CleanFlags(flags[]){     new newflags[40]     if(strfind(flags,"a") != -1)         strcat(newflags,"a",40)         if(strfind(flags,"b") != -1)         strcat(newflags,"b",40)         if(strfind(flags,"c") != -1)         strcat(newflags,"c",40)         if(strfind(flags,"d") != -1)         strcat(newflags,"d",40)         if(strfind(flags,"e") != -1)         strcat(newflags,"e",40)         if(strfind(flags,"f") != -1)         strcat(newflags,"f",40)         if(strfind(flags,"g") != -1)         strcat(newflags,"g",40)         if(strfind(flags,"h") != -1)         strcat(newflags,"h",40)         if(strfind(flags,"i") != -1)         strcat(newflags,"i",40)         if(strfind(flags,"j") != -1)         strcat(newflags,"j",40)         if(strfind(flags,"k") != -1)         strcat(newflags,"k",40)         if(strfind(flags,"l") != -1)         strcat(newflags,"l",40)         if(strfind(flags,"m") != -1)         strcat(newflags,"m",40)         if(strfind(flags,"n") != -1)         strcat(newflags,"n",40)         if(strfind(flags,"o") != -1)         strcat(newflags,"o",40)         if(strfind(flags,"p") != -1)         strcat(newflags,"p",40)         if(strfind(flags,"q") != -1)         strcat(newflags,"q",40)         if(strfind(flags,"r") != -1)         strcat(newflags,"r",40)         if(strfind(flags,"s") != -1)         strcat(newflags,"s",40)         if(strfind(flags,"t") != -1)         strcat(newflags,"t",40)     if(strfind(flags,"u") != -1)         strcat(newflags,"u",40)     copy(flags,40,newflags) }


Code:
Seeing User: STEAM_0:0:711690 Soul acdefghijklmnopqrstu
Adding User: STEAM_0:0:711690 Soul acdefghijklmnopqrstu Position: 0
STEAM_0:0:711690
Seeing User: STEAM_0:1:3355103 Fueler acdefghijklmnopqrstu
Adding User: STEAM_0:1:3355103 Fueler acdefghijklmnopqrstu Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:0:711690 Soul acdefghijku
Found User: STEAM_0:0:711690 Soul acdefghijku Position: 0
STEAM_0:0:711690
Seeing User: STEAM_0:0:6925045 Mystral Hawk acdefghijku
Adding User: STEAM_0:0:6925045 Mystral Hawk acdefghijku Position: 2
STEAM_0:0:6925045
Seeing User: STEAM_0:1:3355103 Fueler acdefghijku
Found User: STEAM_0:1:3355103 Fueler acdefghijku Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:0:924603 Puss in Boots acdefghijku
Adding User: STEAM_0:0:924603 Puss in Boots acdefghijku Position: 3
STEAM_0:0:924603
Seeing User: STEAM_0:0:9721601 Inferno_DH acdefghijku
Adding User: STEAM_0:0:9721601 Inferno_DH acdefghijku Position: 4
STEAM_0:0:9721601
Seeing User: STEAM_0:1:3355103 Fueler cdefijku
Found User: STEAM_0:1:3355103 Fueler cdefijku Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:1:3355103 Fueler cdeiu
Found User: STEAM_0:1:3355103 Fueler cdeiu Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:0:711690 Soul it
Found User: STEAM_0:0:711690 Soul it Position: 0
STEAM_0:0:711690
Seeing User: STEAM_0:0:6925045 Mystral Hawk it
Found User: STEAM_0:0:6925045 Mystral Hawk it Position: 2
STEAM_0:0:6925045
Seeing User: STEAM_0:1:3355103 Fueler it
Found User: STEAM_0:1:3355103 Fueler it Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:1:3806983 ric3 it
Adding User: STEAM_0:1:3806983 ric3 it Position: 5
STEAM_0:1:3806983
Seeing User: STEAM_0:0:924603 Puss in Boots it
Found User: STEAM_0:0:924603 Puss in Boots it Position: 3
STEAM_0:0:924603
Seeing User: STEAM_0:0:4632267 Daweism it
Adding User: STEAM_0:0:4632267 Daweism it Position: 6
STEAM_0:0:4632267
Seeing User: STEAM_0:1:10117998 ex!Le it
Adding User: STEAM_0:1:10117998 ex!Le it Position: 7
STEAM_0:1:10117998
Seeing User: STEAM_0:0:214586 Kira it
Adding User: STEAM_0:0:214586 Kira it Position: 8
STEAM_0:0:214586
Seeing User: STEAM_0:1:5084033 OneKillWonder it
Adding User: STEAM_0:1:5084033 OneKillWonder it Position: 9
STEAM_0:1:5084033
Seeing User: steam_0:0:780026 P.I.T.A it
Adding User: steam_0:0:780026 P.I.T.A it Position: 10
steam_0:0:780026
Seeing User: STEAM_0:1:3237524 matt it
Adding User: STEAM_0:1:3237524 matt it Position: 11
STEAM_0:1:3237524
Seeing User: STEAM_0:1:9138715 Aceventura9586 it
Adding User: STEAM_0:1:9138715 Aceventura9586 it Position: 12
STEAM_0:1:9138715
Seeing User: STEAM_0:0:9721601 Inferno_DH it
Found User: STEAM_0:0:9721601 Inferno_DH it Position: 4
STEAM_0:0:9721601
Seeing User: STEAM_0:0:1630356 nightfall it
Adding User: STEAM_0:0:1630356 nightfall it Position: 13
STEAM_0:0:1630356
Seeing User: STEAM_0:0:9046989 Tormented Soul it
Adding User: STEAM_0:0:9046989 Tormented Soul it Position: 14
STEAM_0:0:9046989
Seeing User: STEAM_0:1:726390 unruly it
Adding User: STEAM_0:1:726390 unruly it Position: 15
STEAM_0:1:726390
Seeing User: STEAM_0:0:8435997 greygoose it
Adding User: STEAM_0:0:8435997 greygoose it Position: 16
STEAM_0:0:8435997
Seeing User: STEAM_0:0:8726666 Termin it
Adding User: STEAM_0:0:8726666 Termin it Position: 17
STEAM_0:0:8726666
Seeing User: STEAM_0:1:9846099 look_alike it
Adding User: STEAM_0:1:9846099 look_alike it Position: 18
STEAM_0:1:9846099
Seeing User: STEAM_0:1:2628263 Rambo` it
Adding User: STEAM_0:1:2628263 Rambo` it Position: 19
STEAM_0:1:2628263
Seeing User: STEAM_0:0:1364582 LaNc3aLoT it
Adding User: STEAM_0:0:1364582 LaNc3aLoT it Position: 20
STEAM_0:0:1364582
Seeing User: STEAM_0:0:502704 Dork it
Adding User: STEAM_0:0:502704 Dork it Position: 21
STEAM_0:0:502704
Seeing User: STEAM_0:1:9625453 Blitzkrieg it
Adding User: STEAM_0:1:9625453 Blitzkrieg it Position: 22
STEAM_0:1:9625453
Seeing User: steam_0:1:4238737 theAxe it
Adding User: steam_0:1:4238737 theAxe it Position: 23
steam_0:1:4238737
Seeing User: STEAM_0:0:3127540 kr4m it
Adding User: STEAM_0:0:3127540 kr4m it Position: 24
STEAM_0:0:3127540
Seeing User: STEAM_0:0:2740585 MiserySignals it
Adding User: STEAM_0:0:2740585 MiserySignals it Position: 25
STEAM_0:0:2740585
Seeing User: STEAM_0:0:553579 kuya it
Adding User: STEAM_0:0:553579 kuya it Position: 26
STEAM_0:0:553579
Seeing User: STEAM_0:1:4043285 Dump it
Adding User: STEAM_0:1:4043285 Dump it Position: 27
STEAM_0:1:4043285
Seeing User: STEAM_0:0:2960622 Nova it
Adding User: STEAM_0:0:2960622 Nova it Position: 28
STEAM_0:0:2960622
Seeing User: STEAM_0:1:9627563 EffeKt it
Adding User: STEAM_0:1:9627563 EffeKt it Position: 29
STEAM_0:1:9627563
Seeing User: steam_0:1:5831595 Blank Stare it
Adding User: steam_0:1:5831595 Blank Stare it Position: 30
steam_0:1:5831595
Seeing User: STEAM_0:0:4186628 Drake it
Adding User: STEAM_0:0:4186628 Drake it Position: 31
STEAM_0:0:4186628
Seeing User: STEAM_0:1:771897 AnewF0und it
Adding User: STEAM_0:1:771897 AnewF0und it Position: 32
STEAM_0:1:771897
Seeing User: STEAM_0:1:4095350 Strifealot it
Adding User: STEAM_0:1:4095350 Strifealot it Position: 33
STEAM_0:1:4095350
Seeing User: STEAM_0:0:1214680 billrecon it
Adding User: STEAM_0:0:1214680 billrecon it Position: 34
STEAM_0:0:1214680
Seeing User: STEAM_0:1:3355103 Fueler b
Found User: STEAM_0:1:3355103 Fueler b Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:1:3355103 Fueler b
Found User: STEAM_0:1:3355103 Fueler b Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:1:3355103 Fueler b
Found User: STEAM_0:1:3355103 Fueler b Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:1:3355103 Fueler b
Found User: STEAM_0:1:3355103 Fueler b Position: 1
STEAM_0:1:3355103
Seeing User: STEAM_0:1:3355103 Fueler b
Found User: STEAM_0:1:3355103 Fueler b Position: 1
STEAM_0:1:3355103
0 STEAM_0:0:711690 Soul acdefghijklmnopqrstuacdefghijkuit
0 STEAM_0:0:711690 Soul acdefghijklmnopqrstu
1 STEAM_0:1:3355103 Fueler acdefghijklmnopqrstuacdefghijkucdefijkucdeiuitbb
1 STEAM_0:1:3355103 Fueler abcdefghijklmnopqrstu
2 b Mystral Hawk acdefghijkuit
2 b Mystral Hawk acdefghijktu
3 STEAM_0:0:924603 Puss in Boots acdefghijkuit
3 STEAM_0:0:924603 Puss in Boots acdefghijktu
4 STEAM_0:0:9721601 Inferno_DH acdefghijkuit
4 STEAM_0:0:9721601 Inferno_DH acdefghijktu
5 STEAM_0:1:3806983 ric3 it
5 STEAM_0:1:3806983 ric3 it
6 STEAM_0:0:4632267 Daweism it
6 STEAM_0:0:4632267 Daweism it
7 STEAM_0:1:10117998 ex!Le it
7 STEAM_0:1:10117998 ex!Le it
8 STEAM_0:0:214586 Kira it
8 STEAM_0:0:214586 Kira it
9 STEAM_0:1:5084033 OneKillWonder it
9 STEAM_0:1:5084033 OneKillWonder it
10 steam_0:0:780026 P.I.T.A it
10 steam_0:0:780026 P.I.T.A it
11 STEAM_0:1:3237524 matt it
11 STEAM_0:1:3237524 matt it
12 STEAM_0:1:9138715 Aceventura9586 it
12 STEAM_0:1:9138715 Aceventura9586 it
13 STEAM_0:0:1630356 nightfall it
13 STEAM_0:0:1630356 nightfall it
14 STEAM_0:0:9046989 Tormented Soul it
14 STEAM_0:0:9046989 Tormented Soul it
15 STEAM_0:1:726390 unruly it
15 STEAM_0:1:726390 unruly it
16 STEAM_0:0:8435997 greygoose it
16 STEAM_0:0:8435997 greygoose it
17 STEAM_0:0:8726666 Termin it
17 STEAM_0:0:8726666 Termin it
18 STEAM_0:1:9846099 look_alike it
18 STEAM_0:1:9846099 look_alike it
19 STEAM_0:1:2628263 Rambo` it
19 STEAM_0:1:2628263 Rambo` it
20 STEAM_0:0:1364582 LaNc3aLoT it
20 STEAM_0:0:1364582 LaNc3aLoT it
21 STEAM_0:0:502704 Dork it
21 STEAM_0:0:502704 Dork it
22 STEAM_0:1:9625453 Blitzkrieg it
22 STEAM_0:1:9625453 Blitzkrieg it
23 steam_0:1:4238737 theAxe it
23 steam_0:1:4238737 theAxe it
24 STEAM_0:0:3127540 kr4m it
24 STEAM_0:0:3127540 kr4m it
25 STEAM_0:0:2740585 MiserySignals it
25 STEAM_0:0:2740585 MiserySignals it
26 STEAM_0:0:553579 kuya it
26 STEAM_0:0:553579 kuya it
27 STEAM_0:1:4043285 Dump it
27 STEAM_0:1:4043285 Dump it
28 STEAM_0:0:2960622 Nova it
28 STEAM_0:0:2960622 Nova it
29 STEAM_0:1:9627563 EffeKt it
29 STEAM_0:1:9627563 EffeKt it
30 steam_0:1:5831595 Blank Stare it
30 steam_0:1:5831595 Blank Stare it
31 STEAM_0:0:4186628 Drake it
31 STEAM_0:0:4186628 Drake it
32 STEAM_0:1:771897 AnewF0und it
32 STEAM_0:1:771897 AnewF0und it
33 STEAM_0:1:4095350 Strifealot it
33 STEAM_0:1:4095350 Strifealot it
34 STEAM_0:0:1214680 billrecon it
34 STEAM_0:0:1214680 billrecon it
[DB MOD] Users file copied
L 02/02/2006 - 12:42:34: [db_mod.amxx] [DB MOD] Users file copied
DaSoul is offline
DaSoul
Senior Member
Join Date: Jan 2006
Old 02-02-2006 , 13:38  
Reply With Quote #2

Odd if I comment out the code to strcat the access flag strings for the groups together then it does not rewrite hawks steam id...

strcat(Admins[adminpos][USERFLAGS],group_flags,255)

Take that out the STEAMID stays what it is suppose to. Put it back in it replaces it to b. Maybe I am not using it correctly or maybe there is a better way to do what I am trying to do.

Each group has their own access flags

If a admin is a member of a group I concat the second group access flags with the original access flags loaded the first time. I clean up the flags later on to make sure there are no repeats. Anyone have a suggestion?
DaSoul is offline
DaSoul
Senior Member
Join Date: Jan 2006
Old 02-02-2006 , 14:03  
Reply With Quote #3

I think I have found a bug...

This sample plugin... with the second strcat commented out

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> public plugin_init() {     register_plugin("strcat test", "0.4", "[gOf]-Soul")         // Add your code here...         new str[3][3][50]     copy(str[0][0],50,"test0-0")     copy(str[0][1],50,"test0-1")     copy(str[0][2],50,"test0-2")         copy(str[1][0],50,"test1-0")     copy(str[1][1],50,"test1-1")     copy(str[1][2],50,"test1-2")         copy(str[2][0],50,"test2-0")     copy(str[2][1],50,"test2-1")     copy(str[2][2],50,"test2-2")         new cat1[25] = "cat test 1 "     new cat2[25] = "cat test 2 "     strcat(cat1,cat2,50)     //strcat(cat1,cat2,50)     copy(str[1][1],50,cat1)         for(new i=0;i<3;i++){         for(new j=0;j<3;j++){             server_print("Array %d - %d = %s",i,j,str[i][j])         }             } }

Produces the following output

Code:
Array 0 - 0 = test0-0
Array 0 - 1 = test0-1
Array 0 - 2 = test0-2
Array 1 - 0 = test1-0
Array 1 - 1 = cat test 1 cat test 2
Array 1 - 2 = test1-2
Array 2 - 0 = test2-0
Array 2 - 1 = test2-1
Array 2 - 2 = test2-2
With the second strcat placed back into the code produces the following output and really garbles up the original array....

Code:
Array 0 - 0 =
Array 0 - 1 = test2-0
Array 0 - 2 = test2-1
Array 1 - 0 =
Array 1 - 1 =
Array 1 - 2 =
Array 2 - 0 =
Array 2 - 1 =
Array 2 - 2 =
DaSoul is offline
DaSoul
Senior Member
Join Date: Jan 2006
Old 02-02-2006 , 14:09  
Reply With Quote #4

Gah I see my problem with the above test LOL...

size 50 concat into a size 25 array.

Also solved my original problem. I was blowing up the userflag portion of my array. Same problem as my second test. Wow... that sucked....
DaSoul is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode