#include <iostream>
#include <sqlite3.h>
#include <string>
const std::string DB_PATH = "/root/.local/share/ddnet/ddnet-server.sqlite";
// Функция для выполнения SQL-запроса
bool executeSQL(sqlite3* db, const std::string& sql) {
char* errMsg = nullptr;
int result = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &errMsg);
if (result != SQLITE_OK) {
std::cerr << "SQL error: " << errMsg << std::endl;
sqlite3_free(errMsg);
return false;
}
return true;
}
// Создание таблицы пользователей
void createUsersTable(sqlite3* db) {
const std::string sql = "CREATE TABLE IF NOT EXISTS users ("
"login TEXT PRIMARY KEY, "
"password TEXT NOT NULL);";
if (!executeSQL(db, sql)) {
std::cerr << "Failed to create table." << std::endl;
}
}
// Функция регистрации
bool registerUser(sqlite3* db, const std::string& login, const std::string& password) {
std::string sql = "INSERT INTO users (login, password) VALUES ('" + login + "', '" + password + "');";
if (executeSQL(db, sql)) {
std::cout << "Registration successful." << std::endl;
return true;
} else {
std::cerr << "User with this login already exists or registration failed." << std::endl;
return false;
}
}
// Функция авторизации
bool loginUser(sqlite3* db, const std::string& login, const std::string& password) {
std::string sql = "SELECT login FROM users WHERE login = '" + login + "' AND password = '" + password + "';";
sqlite3_stmt* stmt;
bool success = false;
if (sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, nullptr) == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
success = true;
std::cout << "Login successful." << std::endl;
} else {
std::cerr << "Invalid login or password." << std::endl;
}
sqlite3_finalize(stmt);
} else {
std::cerr << "Failed to execute login query." << std::endl;
}
return success;
}
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: ./program /register <login> <password> <password_confirm> or /login <login> <password>" << std::endl;
return 1;
}
sqlite3* db;
if (sqlite3_open(DB_PATH.c_str(), &db) != SQLITE_OK) {
std::cerr << "Failed to open database: " << sqlite3_errmsg(db) << std::endl;
return 1;
}
// Создаем таблицу пользователей, если ее еще нет
createUsersTable(db);
std::string command = argv[1];
if (command == "/register" && argc == 5) {
std::string login = argv[2];
std::string password = argv[3];
std::string password_confirm = argv[4];
if (password != password_confirm) {
std::cerr << "Passwords do not match." << std::endl;
} else {
registerUser(db, login, password);
}
} else if (command == "/login" && argc == 4) {
std::string login = argv[2];
std::string password = argv[3];
loginUser(db, login, password);
} else {
std::cerr << "Invalid command or arguments." << std::endl;
}
sqlite3_close(db);
return 0;
}
#include <iostream>
#include <sqlite3.h>
#include <string>
const std::string DB_PATH = "/root/.local/share/ddnet/ddnet-server.sqlite";
// Функция для выполнения SQL-запроса
bool executeSQL(sqlite3* db, const std::string& sql) {
char* errMsg = nullptr;
int result = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &errMsg);
if (result != SQLITE_OK) {
std::cerr << "SQL error: " << errMsg << std::endl;
sqlite3_free(errMsg);
return false;
}
return true;
}
// Создание таблицы пользователей
void createUsersTable(sqlite3* db) {
const std::string sql = "CREATE TABLE IF NOT EXISTS users ("
"login TEXT PRIMARY KEY, "
"password TEXT NOT NULL);";
if (!executeSQL(db, sql)) {
std::cerr << "Failed to create table." << std::endl;
}
}
// Функция регистрации
bool registerUser(sqlite3* db, const std::string& login, const std::string& password) {
std::string sql = "INSERT INTO users (login, password) VALUES ('" + login + "', '" + password + "');";
if (executeSQL(db, sql)) {
std::cout << "Registration successful." << std::endl;
return true;
} else {
std::cerr << "User with this login already exists or registration failed." << std::endl;
return false;
}
}
// Функция авторизации
bool loginUser(sqlite3* db, const std::string& login, const std::string& password) {
std::string sql = "SELECT login FROM users WHERE login = '" + login + "' AND password = '" + password + "';";
sqlite3_stmt* stmt;
bool success = false;
if (sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, nullptr) == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_ROW) {
success = true;
std::cout << "Login successful." << std::endl;
} else {
std::cerr << "Invalid login or password." << std::endl;
}
sqlite3_finalize(stmt);
} else {
tw:
4.0K -rw-r--r-- 1 solly solly 1.7K Apr 19 2020 license.txt
8.0K -rw-r--r-- 1 solly solly 4.9K Apr 19 2020 readme.md
4.0K -rw-r--r-- 1 solly solly 925 Apr 19 2020 storage.cfg
1.6M -rwxr-xr-x 1 solly solly 1.6M Apr 19 2020 teeworlds
576K -rwxr-xr-x 1 solly solly 576K Apr 19 2020 teeworlds_srv
ddnet:
12M -rwxr-xr-x 1 solly solly 12M Oct 4 18:19 DDNet
5.0M -rwxr-xr-x 1 solly solly 5.0M Oct 4 18:19 DDNet-Server
4.0K -rwxr-xr-x 1 solly solly 527 Oct 4 18:19 config_directory.sh
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 config_retrieve
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 config_store
0 drwxr-xr-x 1 solly solly 734 Oct 4 18:19 data
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 demo_extract_chat
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 dilate
8.1M -rw-r--r-- 1 solly solly 8.1M Oct 4 18:19 discord_game_sdk.so
12K -rw-r--r-- 1 solly solly 12K Oct 4 18:19 license.txt
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 map_convert_07
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 map_create_pixelart
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 map_diff
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 map_extract
4.0K -rw-r--r-- 1 solly solly 987 Oct 4 18:19 storage.cfg
2. why arent teeworlds and ddnet merged since it looks pretty similar in the issues tab of both (edited)tw:
4.0K -rw-r--r-- 1 solly solly 1.7K Apr 19 2020 license.txt
8.0K -rw-r--r-- 1 solly solly 4.9K Apr 19 2020 readme.md
4.0K -rw-r--r-- 1 solly solly 925 Apr 19 2020 storage.cfg
1.6M -rwxr-xr-x 1 solly solly 1.6M Apr 19 2020 teeworlds
576K -rwxr-xr-x 1 solly solly 576K Apr 19 2020 teeworlds_srv
ddnet:
12M -rwxr-xr-x 1 solly solly 12M Oct 4 18:19 DDNet
5.0M -rwxr-xr-x 1 solly solly 5.0M Oct 4 18:19 DDNet-Server
4.0K -rwxr-xr-x 1 solly solly 527 Oct 4 18:19 config_directory.sh
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 config_retrieve
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 config_store
0 drwxr-xr-x 1 solly solly 734 Oct 4 18:19 data
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 demo_extract_chat
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 dilate
8.1M -rw-r--r-- 1 solly solly 8.1M Oct 4 18:19 discord_game_sdk.so
12K -rw-r--r-- 1 solly solly 12K Oct 4 18:19 license.txt
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 map_convert_07
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 map_create_pixelart
1.9M -rwxr-xr-x 1 solly solly 1.9M Oct 4 18:19 map_diff
2.1M -rwxr-xr-x 1 solly solly 2.1M Oct 4 18:19 map_extract
4.0K -rw-r--r-- 1 solly solly 987 Oct 4 18:19 storage.cfg
2. why arent teeworlds and ddnet merged since it looks pretty similar in the issues tab of both (edited)