dudb to y_ini -
mrxqware - 17.03.2015
Hello guys,
I would like to change the dudb include which is using dini to y_ini, since y_ini should be faster.
This is what I tried so far...
I can't get it to a nice clean working code.
Could someone please assist me?
I've read several Y_ini tutorials over and over.
The original dudb include:
http://pastebin.com/9eLCWmLs
My attempt:
Код:
/*#if defined _dudb_included
#endinput
#endif
#define _dudb_included
#pragma library dutils*/
#include <dutils>
#include <dini>
#include <YSI\y_ini>
#define dUser(%1).( udb_User(%1,
#define dUserINT(%1).( udb_UserInt(%1,
#define dUserSet(%1).( udb_UserSet(%1,
#define dUserSetINT(%1).( udb_UserSetInt(%1,
#define dUserSetFLOAT(%1).( udb_UserSetFloat(%1,
#define dUserFLOAT(%1).( udb_UserFloat(%1,
stock udb_hash(buf[])
{
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
stock udb_encode(nickname[])
{
new tmp[MAX_STRING];
set(tmp,nickname);
tmp=strreplace(";","_01",tmp);
tmp=strreplace("!","_02",tmp);
tmp=strreplace("/","_03",tmp);
tmp=strreplace("\\","_04",tmp);
tmp=strreplace("[","_05",tmp);
tmp=strreplace("]","_06",tmp);
tmp=strreplace("?","_07",tmp);
tmp=strreplace(".","_08",tmp);
tmp=strreplace("*","_09",tmp);
tmp=strreplace("<","_10",tmp);
tmp=strreplace(">","_11",tmp);
tmp=strreplace("{","_12",tmp);
tmp=strreplace("}","_13",tmp);
tmp=strreplace(" ","_14",tmp);
tmp=strreplace("\"","_15",tmp);
tmp=strreplace(":","_16",tmp);
tmp=strreplace("|","_17",tmp);
tmp=strreplace("=","_18",tmp);
return tmp;
}
stock udb_decode(nickname[])
{
new tmp[MAX_STRING];
set(tmp,nickname);
tmp=strreplace("_01",";",tmp);
tmp=strreplace("_02","!",tmp);
tmp=strreplace("_03","/",tmp);
tmp=strreplace("_04","\\",tmp);
tmp=strreplace("_05","[",tmp);
tmp=strreplace("_06","]",tmp);
tmp=strreplace("_07","?",tmp);
tmp=strreplace("_08",".",tmp);
tmp=strreplace("_09","*",tmp);
tmp=strreplace("_10","<",tmp);
tmp=strreplace("_11",">",tmp);
tmp=strreplace("_12","{",tmp);
tmp=strreplace("_13","}",tmp);
tmp=strreplace("_14"," ",tmp);
tmp=strreplace("_15","\"",tmp);
tmp=strreplace("_16",":",tmp);
tmp=strreplace("_17","|",tmp);
tmp=strreplace("_18","=",tmp);
return tmp;
}
stock udb_Exists(nickname[])
{
new tmp[MAX_STRING];
format(tmp,sizeof(tmp),"%s.dudb.sav",udb_encode(nickname));
return fexist(tmp);
}
stock udb_Remove(nickname[])
{
new tmp[MAX_STRING];
format(tmp,sizeof(tmp),"%s.dudb.sav",udb_encode(nickname));
return fremove(tmp);
}
stock udb_UserSetInt(nickname[],key[],value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
return INI_WriteInt(File,key,value);
}
stock udb_UserSetFloat(nickname[],key[],Float:value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
return INI_WriteFloat(File,key,value);
}
stock udb_UserSet(nickname[],key[],value[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
return INI_WriteString(File,key,value);
}
stock udb_User(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
format(fname,sizeof(fname), dini_Get(fname,key));
return fname;
}
stock Float:udb_UserFloat(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
return INI_Float(File,key);
}
stock udb_UserInt(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
return INI_Int(fname,key);
}
stock udb_CheckLogin(nickname[],pwd[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
if (udb_UserInt(nickname,"password_hash")==udb_hash(pwd)) return true;
return false;
}
stock udb_Create(nickname[],pwd[])
{
if (udb_Exists(nickname)) return false;
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
udb_UserSetInt(nickname,"password_hash",udb_hash(pwd));
INI_Close(File);
return true;
}
stock udb_RenameUser(nickname[],newnick[])
{
new oldfname[MAX_STRING];
new newfname[MAX_STRING];
format(oldfname,sizeof(oldfname),"%s.dudb.sav",udb_encode(nickname));
format(newfname,sizeof(newfname),"%s.dudb.sav",udb_encode(newnick));
return frenametextfile(oldfname,newfname);
}
This are the errors:
Код:
pawno\include\yudb.inc(106) : warning 209: function "INI_WriteInt" should return a value
pawno\include\yudb.inc(116) : warning 209: function "INI_WriteFloat" should return a value
pawno\include\yudb.inc(124) : warning 209: function "INI_WriteString" should return a value
pawno\include\yudb.inc(140) : error 029: invalid expression, assumed zero
pawno\include\yudb.inc(140) : error 035: argument type mismatch (argument 1)
pawno\include\yudb.inc(140) : error 001: expected token: ";", but found "return"
pawno\include\yudb.inc(140) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
Re: dudb to y_ini -
SickAttack - 18.03.2015
Change this:
pawn Код:
return INI_WriteInt(File,key,value);
To this:
pawn Код:
INI_WriteInt(File,key,value);
return 1;
And so on.
Re: dudb to y_ini -
mrxqware - 18.03.2015
Thank you for your answer.
This is the new code:
Код:
/*#if defined _dudb_included
#endinput
#endif
#define _dudb_included
#pragma library dutils*/
#include <dutils>
#include <dini>
#include <YSI\y_ini>
#define dUser(%1).( udb_User(%1,
#define dUserINT(%1).( udb_UserInt(%1,
#define dUserSet(%1).( udb_UserSet(%1,
#define dUserSetINT(%1).( udb_UserSetInt(%1,
#define dUserSetFLOAT(%1).( udb_UserSetFloat(%1,
#define dUserFLOAT(%1).( udb_UserFloat(%1,
stock udb_hash(buf[])
{
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
stock udb_encode(nickname[])
{
new tmp[MAX_STRING];
set(tmp,nickname);
tmp=strreplace(";","_01",tmp);
tmp=strreplace("!","_02",tmp);
tmp=strreplace("/","_03",tmp);
tmp=strreplace("\\","_04",tmp);
tmp=strreplace("[","_05",tmp);
tmp=strreplace("]","_06",tmp);
tmp=strreplace("?","_07",tmp);
tmp=strreplace(".","_08",tmp);
tmp=strreplace("*","_09",tmp);
tmp=strreplace("<","_10",tmp);
tmp=strreplace(">","_11",tmp);
tmp=strreplace("{","_12",tmp);
tmp=strreplace("}","_13",tmp);
tmp=strreplace(" ","_14",tmp);
tmp=strreplace("\"","_15",tmp);
tmp=strreplace(":","_16",tmp);
tmp=strreplace("|","_17",tmp);
tmp=strreplace("=","_18",tmp);
return tmp;
}
stock udb_decode(nickname[])
{
new tmp[MAX_STRING];
set(tmp,nickname);
tmp=strreplace("_01",";",tmp);
tmp=strreplace("_02","!",tmp);
tmp=strreplace("_03","/",tmp);
tmp=strreplace("_04","\\",tmp);
tmp=strreplace("_05","[",tmp);
tmp=strreplace("_06","]",tmp);
tmp=strreplace("_07","?",tmp);
tmp=strreplace("_08",".",tmp);
tmp=strreplace("_09","*",tmp);
tmp=strreplace("_10","<",tmp);
tmp=strreplace("_11",">",tmp);
tmp=strreplace("_12","{",tmp);
tmp=strreplace("_13","}",tmp);
tmp=strreplace("_14"," ",tmp);
tmp=strreplace("_15","\"",tmp);
tmp=strreplace("_16",":",tmp);
tmp=strreplace("_17","|",tmp);
tmp=strreplace("_18","=",tmp);
return tmp;
}
stock udb_Exists(nickname[])
{
new tmp[MAX_STRING];
format(tmp,sizeof(tmp),"%s.dudb.sav",udb_encode(nickname));
return fexist(tmp);
}
stock udb_Remove(nickname[])
{
new tmp[MAX_STRING];
format(tmp,sizeof(tmp),"%s.dudb.sav",udb_encode(nickname));
return fremove(tmp);
}
stock udb_UserSetInt(nickname[],key[],value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_SetTag(File, "data");
INI_WriteInt(File,key,value);
INI_Close(File);
return 1;
}
stock udb_UserSetFloat(nickname[],key[],Float:value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_SetTag(File, "data");
INI_WriteFloat(File,key,value);
INI_Close(File);
return 1;
}
stock udb_UserSet(nickname[],key[],value[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_SetTag(File, "data");
INI_WriteString(File,key,value);
INI_Close(File);
return 1;
}
stock udb_User(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
format(fname,sizeof(fname), dini_Get(fname,key));
return fname;
}
stock Float:udb_UserFloat(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_Float(File,key);
return 1;
}
stock udb_UserInt(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_Int(File,key);
return 1;
}
stock udb_CheckLogin(nickname[],pwd[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
if (udb_UserInt(nickname,"password_hash")==udb_hash(pwd)) return true;
return false;
}
stock udb_Create(nickname[],pwd[])
{
if (udb_Exists(nickname)) return false;
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
udb_UserSetInt(nickname,"password_hash",udb_hash(pwd));
INI_Close(File);
return true;
}
stock udb_RenameUser(nickname[],newnick[])
{
new oldfname[MAX_STRING];
new newfname[MAX_STRING];
format(oldfname,sizeof(oldfname),"%s.dudb.sav",udb_encode(nickname));
format(newfname,sizeof(newfname),"%s.dudb.sav",udb_encode(newnick));
return frenametextfile(oldfname,newfname);
}
I've got the following errors:
Код:
pawno\include\yudb.inc(146) : error 035: argument type mismatch (argument 1)
pawno\include\yudb.inc(146) : error 046: unknown array size (variable "key")
pawno\include\yudb.inc(146) : error 017: undefined symbol "value"
pawno\include\yudb.inc(146) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
Re: dudb to y_ini -
mrxqware - 18.03.2015
Could someone help me please? I can't figure it out :S
I am willing to pay $10 using paypal for the one who can send me a complete working code.
AW: dudb to y_ini -
Kaliber - 18.03.2015
Pls post the Line 146...
Re: dudb to y_ini -
SickAttack - 18.03.2015
pawn Код:
#include <dini>
#include <YSI\y_ini>
stock udb_hash(buf[])
{
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
stock udb_encode(nickname[])
{
new temp[MAX_STRING];
set(temp, nickname);
temp=strreplace(";","_01",temp);
temp=strreplace("!","_02",temp);
temp=strreplace("/","_03",temp);
temp=strreplace("\\","_04",temp);
temp=strreplace("[","_05",temp);
temp=strreplace("]","_06",temp);
temp=strreplace("?","_07",temp);
temp=strreplace(".","_08",temp);
temp=strreplace("*","_09",temp);
temp=strreplace("<","_10",temp);
temp=strreplace(">","_11",temp);
temp=strreplace("{","_12",temp);
temp=strreplace("}","_13",temp);
temp=strreplace(" ","_14",temp);
temp=strreplace("\"","_15",temp);
temp=strreplace(":","_16",temp);
temp=strreplace("|","_17",temp);
temp=strreplace("=","_18",temp);
return temp;
}
stock udb_decode(nickname[])
{
new temp[MAX_STRING];
set(temp,nickname);
temp=strreplace("_01",";",temp);
temp=strreplace("_02","!",temp);
temp=strreplace("_03","/",temp);
temp=strreplace("_04","\\",temp);
temp=strreplace("_05","[",temp);
temp=strreplace("_06","]",temp);
temp=strreplace("_07","?",temp);
temp=strreplace("_08",".",temp);
temp=strreplace("_09","*",temp);
temp=strreplace("_10","<",temp);
temp=strreplace("_11",">",temp);
temp=strreplace("_12","{",temp);
temp=strreplace("_13","}",temp);
temp=strreplace("_14"," ",temp);
temp=strreplace("_15","\"",temp);
temp=strreplace("_16",":",temp);
temp=strreplace("_17","|",temp);
temp=strreplace("_18","=",temp);
return temp;
}
stock udb_Exists(nickname[])
{
new temp[MAX_STRING];
format(temp,sizeof(temp),"%s.dudb.sav",udb_encode(nickname));
return fexist(temp);
}
stock udb_Remove(nickname[])
{
new temp[MAX_STRING];
format(temp,sizeof(temp),"%s.dudb.sav",udb_encode(nickname));
return fremove(temp);
}
stock udb_UserSetInt(nickname[],key[],value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_SetTag(File, "data");
INI_WriteInt(File,key,value);
INI_Close(File);
return 1;
}
stock udb_UserSetFloat(nickname[],key[],Float:value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_SetTag(File, "data");
INI_WriteFloat(File,key,value);
INI_Close(File);
return 1;
}
stock udb_UserSet(nickname[],key[],value[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_SetTag(File, "data");
INI_WriteString(File,key,value);
INI_Close(File);
return 1;
}
stock udb_User(nickname[],key[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
format(fname,sizeof(fname), dini_Get(fname,key));
return fname;
}
stock udb_UserFloat(nickname[],key[],Float:value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_WriteFloat(File,key,value);
INI_Close(File);
return 1;
}
stock udb_UserInt(nickname[],key[],value)
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_WriteInt(File,key,value);
INI_Close(File);
return 1;
}
stock udb_CheckLogin(nickname[],pwd[])
{
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
if (udb_UserInt(nickname,"password_hash")==udb_hash(pwd)) return true;
return false;
}
stock udb_Create(nickname[],pwd[])
{
if (udb_Exists(nickname)) return false;
new fname[MAX_STRING];
format(fname,sizeof(fname),"%s.dudb.sav",udb_encode(nickname));
new INI:File = INI_Open(fname);
udb_UserSetInt(nickname,"password_hash",udb_hash(pwd));
INI_Close(File);
return true;
}
stock udb_RenameUser(nickname[],newnick[])
{
new oldfname[MAX_STRING];
new newfname[MAX_STRING];
format(oldfname,sizeof(oldfname),"%s.dudb.sav",udb_encode(nickname));
format(newfname,sizeof(newfname),"%s.dudb.sav",udb_encode(newnick));
frenametextfile(oldfname,newfname);
return 1;
}
stock strreplace(trg[],newstr[],src[])
{
new f=0;
new s1[MAX_STRING];
new temp[MAX_STRING];
format(s1,sizeof(s1),"%s",src);
f = strfind(s1,trg);
temp[0]=0;
while (f>=0)
{
strcat(temp,ret_memcpy(s1, 0, f));
strcat(temp,newstr);
format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
f = strfind(s1,trg);
}
strcat(temp,s1);
return temp;
}
stock frenametextfile(oldname[],newname[])
{
if (!fexist(oldname)) return false;
fremove(newname);
if (!fcopytextfile(oldname,newname)) return false;
fremove(oldname);
return true;
}
Re: dudb to y_ini -
mrxqware - 19.03.2015
Thank you, but I don't get it. You made all the functions write the file, and it doesn't read anymore.
Re: dudb to y_ini -
SickAttack - 19.03.2015
Sorry about that, try this:
pawn Код:
stock Float:udb_UserFloat(nickname[], key[])
{
new fname[128], Float:value;
format(fname, sizeof(fname), "%s.dudb.sav", udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_Float(key, value);
INI_Close(File);
return value;
}
stock udb_UserInt(nickname[], key[], value)
{
new fname[128], value;
format(fname, sizeof(fname), "%s.dudb.sav", udb_encode(nickname));
new INI:File = INI_Open(fname);
INI_Int(key, value);
INI_Close(File);
return value;
}