This commit is contained in:
Walter Julius Hennecke 2012-05-26 00:28:00 +02:00
parent 661427ccbb
commit 74086df7ba
2 changed files with 121 additions and 35 deletions

View file

@ -402,7 +402,7 @@ qboolean G_Sql_UserDB_CheckRight(int uid, int right) {
}
if(res == SQLITE_ROW) {
rights = (long)sqlite3_column_int64;
rights = (long)sqlite3_column_int64(stmt, 0);
if(right & right) {
return qtrue;
} else {
@ -421,7 +421,51 @@ G_Sql_UserDB_AddRight
===============
*/
qboolean G_Sql_UserDB_AddRight(int uid, int right) {
sqlite3_stmt *stmt;
int res;
long rights;
res = sqlite3_prepare_v2(user_db, SQL_USER_GET_RIGHTS, -1, &stmt, 0);
if(G_Sql_Check_PrepareReturn(res)) {
return qfalse;
}
res = sqlite3_step(stmt);
if(G_Sql_Check_StepReturn(res)) {
return qfalse;
}
if(res == SQLITE_ROW) {
rights = (long)sqlite3_column_int64(stmt, 0);
} else {
return qfalse;
}
rights |= right;
rights |= right;
res = sqlite3_prepare_v2(user_db, SQL_USER_MOD_RIGHTS, -1, &stmt, 0);
if(G_Sql_Check_PrepareReturn(res)) {
return qfalse;
}
res = sqlite3_bind_int(stmt, 1, rights);
if(G_Sql_Check_BindReturn(res)) {
return qfalse;
}
res = sqlite3_bind_int(stmt, 2, uid);
if(G_Sql_Check_BindReturn(res)) {
return qfalse;
}
res = sqlite3_step(stmt);
if(G_Sql_Check_StepReturn(res)) {
return qfalse;
}
return qtrue;
}
/*
@ -430,7 +474,49 @@ G_Sql_UserDB_RemoveRight
===============
*/
qboolean G_Sql_UserDB_RemoveRight(int uid, int right) {
sqlite3_stmt *stmt;
int res;
long rights;
res = sqlite3_prepare_v2(user_db, SQL_USER_MOD_RIGHTS, -1, &stmt, 0);
if(G_Sql_Check_PrepareReturn(res)) {
return qfalse;
}
res = sqlite3_step(stmt);
if(G_Sql_Check_StepReturn(res)) {
return qfalse;
}
if(res == SQLITE_ROW) {
rights = (long)sqlite3_column_int64(stmt, 0);
} else {
return qfalse;
}
rights &= right;
res = sqlite3_prepare_v2(user_db, SQL_USER_MOD_RIGHTS, -1, &stmt, 0);
if(G_Sql_Check_PrepareReturn(res)) {
return qfalse;
}
res = sqlite3_bind_int(stmt, 1, rights);
if(G_Sql_Check_BindReturn(res)) {
return qfalse;
}
res = sqlite3_bind_int(stmt, 2, uid);
if(G_Sql_Check_BindReturn(res)) {
return qfalse;
}
res = sqlite3_step(stmt);
if(G_Sql_Check_StepReturn(res)) {
return qfalse;
}
return qtrue;
}
#endif //SQL

View file

@ -2,67 +2,67 @@
#ifndef _G_SQL_H_
#define _G_SQL_H_
#define MAX_SQL_RESULT 4096
#define SQL_ENABLE_FOREIGN_KEY_CONSTRAINTS "PRAGMA foreign_keys = ON;"
#define SQL_BEGIN_TRANSACTION "BEGIN TRANSACTION"
#define SQL_ROLLBACK_TRANSACTION "ROLLBACK TRANSACTION"
#define SQL_COMMIT_TRANSACTION "COMMIT TRANSACTION"
#define SQL_USER_CREATEUSERTABLE "CREATE TABLE IF NOT EXISTS rpgx_users ( \
#define MAX_SQL_RESULT 4096
#define SQL_ENABLE_FOREIGN_KEY_CONSTRAINTS "PRAGMA foreign_keys = ON;"
#define SQL_BEGIN_TRANSACTION "BEGIN TRANSACTION"
#define SQL_ROLLBACK_TRANSACTION "ROLLBACK TRANSACTION"
#define SQL_COMMIT_TRANSACTION "COMMIT TRANSACTION"
#define SQL_USER_CREATEUSERTABLE "CREATE TABLE IF NOT EXISTS rpgx_users ( \
id INTEGER PRIMARY KEY AUTOINCREMENT, \
username TEXT NOT NULL , \
password TEXT NOT NULL \
)"
#define SQL_USER_CREATERIGHTSTABLE "CREATE TABLE IF NOT EXISTS rpgx_userRights ( \
id INT NOT NULL PRIMARY KEY, \
admin BIT NOT NULL, \
rights LONG NOT NULL, \
FOREIGN KEY(id) REFERENCES rpgx_users(id) \
)"
#define SQL_USER_DELETE "DELETE FROM rpgx_users WHERE username = :UNAME"
#define SQL_USER_DELTE_RIGHTS "DELETE FROM rpgx_userRights WHERE id = :ID"
#define SQL_USER_ADD "INSERT INTO rpgx_users VALUES(NULL,:USERNAME,:PASSWORD)"
#define SQL_USER_ADD_RIGHTS "INSERT INTO rpgx_userRights VALUES(NULL, 0, 0, :ID)"
#define SQL_USER_MOD_RIGHTS "UPDATE rpgx_userRights SET rights = :RIGHTS WHERE id = :ID"
#define SQL_USER_GET_RIGHTS "SELECT rights FROM rpgx_userRights WHERE id = :ID"
#define SQL_USER_CHECK_ADMIN "SELECT admin FROM rpgx_userRights WHERE id = :ID"
#define SQL_USER_GET_PASSWORD "SELECT password FROM rpgx_users WHERE id = :ID"
#define SQL_USER_SET_PASSWORD "UPDATE rpgx_users SET password = :PASSWORD WHERE id = :ID"
#define SQL_USER_GET_UID "SELECT id FROM rpgx_users WHERE username = :UNAME"
#define SQL_USER_LOGIN "SELECT id FROM rpgx_users WHERE username = :UNAME AND password = :PASSWORD"
#define SQL_USER_CREATERIGHTSTABLE "CREATE TABLE IF NOT EXISTS rpgx_userRights ( \
id INT NOT NULL PRIMARY KEY, \
admin BIT NOT NULL, \
rights LONG NOT NULL, \
FOREIGN KEY(id) REFERENCES rpgx_users(id) \
)"
#define SQL_USER_DELETE "DELETE FROM rpgx_users WHERE username = :UNAME"
#define SQL_USER_DELTE_RIGHTS "DELETE FROM rpgx_userRights WHERE id = :ID"
#define SQL_USER_ADD "INSERT INTO rpgx_users VALUES(NULL,:USERNAME,:PASSWORD)"
#define SQL_USER_ADD_RIGHTS "INSERT INTO rpgx_userRights VALUES(NULL, 0, 0, :ID)"
#define SQL_USER_MOD_RIGHTS "UPDATE rpgx_userRights SET rights = :RIGHTS WHERE id = :ID"
#define SQL_USER_GET_RIGHTS "SELECT rights FROM rpgx_userRights WHERE id = :ID"
#define SQL_USER_CHECK_ADMIN "SELECT admin FROM rpgx_userRights WHERE id = :ID"
#define SQL_USER_GET_PASSWORD "SELECT password FROM rpgx_users WHERE id = :ID"
#define SQL_USER_SET_PASSWORD "UPDATE rpgx_users SET password = :PASSWORD WHERE id = :ID"
#define SQL_USER_GET_UID "SELECT id FROM rpgx_users WHERE username = :UNAME"
#define SQL_USER_LOGIN "SELECT id FROM rpgx_users WHERE username = :UNAME AND password = :PASSWORD"
typedef enum {
SQLF_GIVE = 1,
SQLF_GOD = 2,
SQLF_NOCLIP = 4,
SQLF_CLOAK = 8,
SQLF_EVOSUIT = 16,
SQLF_EVOSUIT = 16,
SQLF_FLIGHT = 32,
SQLF_FORCENAME = 64,
SQLF_FORCEKILL = 128,
SQLF_FORCENAME = 64,
SQLF_FORCEKILL = 128,
SQLF_KICK = 256,
SQLF_DRAG = 512,
SQLF_DISARM = 1024,
SQLF_FORCERANK = 2048,
SQLF_FORCERANK = 2048,
SQLF_REVIVE = 4096,
SQLF_NOOB = 8192,
SQLF_MESSAGE = 16384,
SQLF_FORCEMODEL = 32768,
SQLF_MESSAGE = 16384,
SQLF_FORCEMODEL = 32768,
SQLF_MUSIC = 65536,
SQLF_SOUND = 131072,
SQLF_USEENT = 262144,
SQLF_BEAM = 524288,
SQLF_FORCEPLAYER = 1048576,
SQLF_FORCEPLAYER = 1048576,
SQLF_FX = 2097152,
SQLF_CHARS = 4194304,
SQLF_CLAMP = 8388608,
SQLF_LOCK = 16777216,
SQLF_FFSTUFF = 33554432,
SQLF_FFSTUFF = 33554432,
SQLF_ALERT = 67108864,
SQLF_TESS = 134217728,
SQLF_FORCECLASS = 268435456,
SQLF_FORCEVOTE = 536870912,
SQLF_FORCECLASS = 268435456,
SQLF_FORCEVOTE = 536870912,
SQLF_SHAKE = 1073741824,
SQLF_ENTLIST = 2147483648
SQLF_ENTLIST = 2147483648
} sql_userflags;
#endif // _G_SQL_H_