mirror of
https://github.com/UberGames/RPG-X2.git
synced 2024-11-15 01:11:46 +00:00
Extended sqlite implementation
This commit is contained in:
parent
bb3653a36f
commit
13407df2f5
3 changed files with 64 additions and 0 deletions
62
game/g_sql.c
62
game/g_sql.c
|
@ -340,6 +340,38 @@ G_Sql_UserDB_login
|
|||
===============
|
||||
*/
|
||||
qboolean G_Sql_UserDB_login(const char *uName, const char *pwd, int clientnum) {
|
||||
sqlite3_stmt *stmt;
|
||||
int res, id;
|
||||
char *hashedpw;
|
||||
|
||||
res = sqlite3_prepare_v2(user_db, SQL_USER_LOGIN, -1, &stmt, 0);
|
||||
if(G_Sql_Check_PrepareReturn(res)) {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
res = sqlite3_bind_text(stmt, 1, uName, sizeof(uName), SQLITE_STATIC);
|
||||
if(G_Sql_Check_BindReturn(res)) {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
hashedpw = G_Sql_Md5(pwd);
|
||||
res = sqlite3_bind_text(stmt, 2, hashedpw, sizeof(hashedpw), SQLITE_STATIC);
|
||||
if(G_Sql_Check_BindReturn(res)) {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
res = sqlite3_step(stmt);
|
||||
if(G_Sql_Check_StepReturn(res)) {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
if(res == SQLITE_ROW) {
|
||||
id = sqlite3_column_int(stmt, 0);
|
||||
level.clients[clientnum].uid = id;
|
||||
return qtrue;
|
||||
} else {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
return qfalse;
|
||||
}
|
||||
|
@ -350,6 +382,36 @@ G_Sql_UserDB_CheckRight
|
|||
===============
|
||||
*/
|
||||
qboolean G_Sql_UserDB_CheckRight(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_bind_int(stmt, 1, uid);
|
||||
if(G_Sql_Check_BindReturn(res)) {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
res = sqlite3_step(stmt);
|
||||
if(G_Sql_Check_StepReturn(res)) {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
if(res == SQLITE_ROW) {
|
||||
rights = (long)sqlite3_column_int64;
|
||||
if(right & right) {
|
||||
return qtrue;
|
||||
} else {
|
||||
return qfalse;
|
||||
}
|
||||
} else {
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
#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,
|
||||
|
|
BIN
stefgame.suo
BIN
stefgame.suo
Binary file not shown.
Loading…
Reference in a new issue