Skip to content

Commit

Permalink
adding contest mode mysql user backend.
Browse files Browse the repository at this point in the history
fixed an regexp for user and password extracting.
  • Loading branch information
heroxbd committed Nov 19, 2011
1 parent 43e7f60 commit 3cbb0c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion QSanguosha.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
TARGET = QSanguosha
QT += network sql
TEMPLATE = app
CONFIG += warn_on audio joystick qaxcontainer debug_and_release
CONFIG += warn_on audio joystick qaxcontainer debug
QMAKE_CXXFLAGS_DEBUG = -ggdb

macx {
CONFIG -= joystick # in Mac, we do not support joystick currently
Expand Down
21 changes: 20 additions & 1 deletion src/server/contestdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,26 @@ ContestDB *ContestDB::GetInstance(){
}

bool ContestDB::loadMembers(){
QSqlQuery query("SELECT username, password, salt FROM users");
QString dbType = Config.value("Contest/dbType", "sqlite");
if (dbType == "MySQL"){
QString dbUser = Config.value("Contest/dbUser");
QString dbHost = Config.value("Contest/dbHost");
QString dbPswd = Config.value("Contest/dbPasswd");
QString dbName = Config.value("Contest/dbName");
QString dbTable = Config.value("Contest/dbTable", "user");
QSqlDatabase dbMySQL = QSqlDatabase::addDatabase("QMYSQL");
dbMySQL.setHostName(dbHost);
dbMySQL.setDatabaseName(dbName);
dbMySQL.setUserName(dbUser);
dbMySQL.setPassword(dbPswd);
bool ok = dbMySQL.open();
if(!ok){
QSqlError error = dbMySQL.lastError();
QMessageBox::warning(NULL, tr("Database open error"), tr("The database can not be opened:\n %1").arg(error.text()));
}
}

QSqlQuery query("SELECT username, password, salt FROM" + dbTable);
QSqlError error = query.lastError();
if(error.isValid()){
QMessageBox::warning(NULL, tr("Database query error"), tr("Please create database before using this mode"));
Expand Down
4 changes: 3 additions & 1 deletion src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,9 @@ void Server::processRequest(char *request){
ClientSocket *socket = qobject_cast<ClientSocket *>(sender());
socket->disconnect(this, SLOT(processRequest(char*)));

QRegExp rx("(signupr?) (.+):(.+)(:.+)?\n");
// signup(r) format is "signupr <base64(username)>:<avantar>[:<md5 of password>]"
// e.g. "signupr aGVpaGVp:machao:4e4d6c332b6fe62a63afe56171fd3725"
QRegExp rx("(signupr?) ([^:]+):([^:]+)(:.+)?\n");
if(!rx.exactMatch(request)){
emit server_message(tr("Invalid signup string: %1").arg(request));
socket->send("warn INVALID_FORMAT");
Expand Down

0 comments on commit 3cbb0c0

Please sign in to comment.