17.03.2015, 22:52
(
Последний раз редактировалось mrxqware; 18.03.2015 в 10:59.
)
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:
This are the errors:
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);
}
Код:
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.

