add created games to the db

This commit is contained in:
Tim Felgentreff 2017-06-08 10:21:41 +02:00
parent bbad7f22be
commit 5722589b56
3 changed files with 22 additions and 2 deletions

View file

@ -329,6 +329,7 @@ static void ParseCreateGame(Session *session, char *buf)
CreateGame(session, description, map, players, ip, port, password);
DebugPrint("%s created a game\n" _C_ session->UserData.Name);
DBAddGame(description, map, players_int);
Send(session, "CREATEGAME_OK\n");
}

View file

@ -59,10 +59,11 @@ static sqlite3 *DB;
#define SQLCreateGamesTable \
"CREATE TABLE games (" \
"date INTEGER," \
"id INTEGER PRIMARY KEY," \
"date INTEGER," \
"gamename TEXT," \
"map_id INTEGER" \
"mapname TEXT" \
"slots INTEGER" \
");"
#define SQLCreateGameDataTable \
@ -259,3 +260,20 @@ int DBUpdateLoginDate(char *username)
}
return 0;
}
int DBAddGame(char *description, char *mapname, int numplayers)
{
char buf[1024];
int t;
char *errmsg;
t = (int)time(0);
sprintf(buf, "INSERT INTO games VALUES(%d, '%s', '%s', %d);",
t, description, mapname, numplayers);
if (sqlite3_exec(DB, buf, NULL, NULL, &errmsg) != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", errmsg);
sqlite3_free(errmsg);
return -1;
}
return 0;
}

View file

@ -41,6 +41,7 @@ extern void DBQuit(void);
extern int DBFindUser(char *username, char *password);
extern int DBAddUser(char *username, char *password);
extern int DBUpdateLoginDate(char *username);
extern int DBAddGame(char *description, char *mapname, int numplayers);
//@}