Beispiel #1
0
void addUser(LinkedList<User> *listOfUsers)
{
	string name, username, password;

	clearScreen();
	displayLogo();

	//The user is prompted for the appropriate information
	cout << "Please enter the name of the new user:\n\n";
	getline(cin, name);

	cout << "\nPlease enter the username of the new user:\n\n";
	getline(cin, username);

	cout << "\nPlease enter the password of the new user:\n\n";
	getline(cin, password);

	//A new user with the specified information is created
	User newUser(name, username, password);

	//The new user is added to the list of users
	listOfUsers->append(newUser);
	
	saveUsers(listOfUsers);
}
Beispiel #2
0
void removeUser(LinkedList<User> *listOfUsers)
{
	string username; 

	//The user is prompted for the username of the user that they want removed
	cout << "Please enter the username of the user to remove:\n\n";
	getline(cin, username);

	removeByUser_UserName(listOfUsers, username); //This function passes the list of user and username of the user to be removed
	saveUsers(listOfUsers);
}
Beispiel #3
0
void shutdownTT() /* Using SIGUSR1 to shutdown the system - BackboneGlobal is a global variable - Very bad practice but the only way it works */
{
    sendSignalToTerm(BackboneGlobal);
    sendSignalToAdmin(BackboneGlobal);
    sendSignalToLog(BackboneGlobal);
    saveFlights(BackboneGlobal);
    saveUsers(BackboneGlobal);
    freeBackbone();
    printf("System is shutting down!\n");
    unlink(npServer);
    exit(0);
}
Beispiel #4
0
void shutdownT(pBackbone BackboneAux)
{
    sendSignalToTerm(BackboneAux);
    sendSignalToAdmin(BackboneAux);
    sendSignalToLog(BackboneAux);
    saveFlights(BackboneAux);
    saveUsers(BackboneAux);
    freeBackbone();
    printf("System is shutting down!\n");
    unlink(npServer);
    exit(0);
}
Beispiel #5
0
void MessageManager::save(SimpleXML& aXml) {
    aXml.addTag("ChatFilterItems");
    aXml.stepIn();
    {
        RLock l(Ignorecs);
        for (const auto& i : ChatFilterItems) {
            aXml.addTag("ChatFilterItem");
            aXml.addChildAttrib("Nick", i.getNickPattern());
            aXml.addChildAttrib("NickMethod", i.getNickMethod());
            aXml.addChildAttrib("Text", i.getTextPattern());
            aXml.addChildAttrib("TextMethod", i.getTextMethod());
            aXml.addChildAttrib("MC", i.matchMainchat);
            aXml.addChildAttrib("PM", i.matchPM);
            aXml.addChildAttrib("Enabled", i.getEnabled());
        }
    }
    aXml.stepOut();

    if (dirty)
        saveUsers();
}
Beispiel #6
0
void Server::client_readyRead()
{
    QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
    if (!socket) {
        qWarning("Server::client_readyRead(): Cast of sender() to QTcpSocket* failed");
        return;
    }

#ifdef DEBUG
    qDebug("\nServer::client_readyRead(): %li bytes available", (long)socket->bytesAvailable());
#endif

    Client *client = m_clients[socket];
    QDataStream in(socket);
    in.setVersion(QDataStream::Qt_4_0);
    if (client->packetSize == 0) {
        if (socket->bytesAvailable() < (int)sizeof(quint32)) // packet size
            return;
        in >> client->packetSize;
    }
    if (socket->bytesAvailable() < client->packetSize)
        return;
    client->packetSize = 0; // reset packet size

    qint32 type;
    in >> type;

#ifdef DEBUG
    qDebug("PacketType %i (%s) from '%s' (%s:%i)", type,
           qPrintable(QccPacket::typeString((QccPacket::PacketType)type)),
           qPrintable(client->user ? client->user->username() : "[no user object]"),
           qPrintable(socket->peerAddress().toString()), socket->peerPort());
#endif

    switch ((QccPacket::PacketType)type) {
    case QccPacket::UserRegister:
    {
        QString username, password;
        QByteArray publicKey;
        in >> username >> password >> publicKey;
#ifdef DEBUG
        qDebug("Username = '******' password = '******'", qPrintable(username), qPrintable(password));
#endif
        if (username.isEmpty()) {
            QString reason = "The username cannot be empty.";
            QccPacket packet(QccPacket::RegisterFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("RegisterFailure: %s", qPrintable(reason));
#endif
            break;
        }
        if (m_users.contains(username)) {
            QString reason = QString("The username \"%1\" is not available.").arg(username);
            QccPacket packet(QccPacket::RegisterFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("RegisterFailure: %s", qPrintable(reason));
#endif
            break;
        }
#ifdef DEBUG
            qDebug("RegisterSuccess");
#endif
        User *user = new User(username, password);
        user->setPublicKey(publicKey);
        user->setSocket(socket);
        connect(user, SIGNAL(statusChanged()), SLOT(client_statusChanged()));
        user->setStatus(User::Online);
        m_users.insert(username, user);
        saveUsers();
        client->user = user;
        QccPacket(QccPacket::RegisterSuccess).send(socket);
        break;
    }
    case QccPacket::UserAuthentication:
    {
        QString username, password;
        QByteArray publicKey;
        in >> username >> password >> publicKey;
#ifdef DEBUG
        qDebug("Username = '******' password = '******'", qPrintable(username), qPrintable(password));
#endif
        User *user = m_users.contains(username) ? m_users[username] : NULL;
        if (user && user->matchPassword(password)) {
#ifdef DEBUG
            qDebug("AuthenticationSuccess");
#endif
            user->setPublicKey(publicKey);
            user->setSocket(socket);
            user->setStatus(User::Online);
            client->user = user;
            QccPacket(QccPacket::AuthenticationSuccess).send(socket);
        } else {
            QString reason = "The username or password you entered is incorrect.";
            QccPacket packet(QccPacket::AuthenticationFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("AuthenticationFailure: %s", qPrintable(reason));
#endif
        }
        break;
    }
    case QccPacket::RequestAuthorization:
    {
        QString username;
        in >> username;
        if (!m_users.contains(username)) {
            QString reason = QString("The user \"%1\" does not exist.").arg(username);
            QccPacket packet(QccPacket::AuthorizationFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("AuthorizationFailure: %s", qPrintable(reason));
#endif
            break;
        }
        if (client->user->username() == username) {
            QString reason = QString("You cannot add yourself.");
            QccPacket packet(QccPacket::AuthorizationFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("AuthorizationFailure: %s", qPrintable(reason));
#endif
            break;
        }
        if (client->user->containsContact(username)) {
            QString reason = QString("The user \"%1\" is already on your contact list.").arg(username);
            QccPacket packet(QccPacket::AuthorizationFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("AuthorizationFailure: %s", qPrintable(reason));
#endif
            break;
        }
        User *receiver = m_users.value(username);
        if (receiver && receiver->isOnline()) {
            QccPacket packet(QccPacket::RequestAuthorization);
            packet.stream() << client->user->username();
            packet.send(receiver->socket());
#ifdef DEBUG
            qDebug("RequestAuthorization: forwarded to '%s'", qPrintable(username));
#endif
        } else {
            QString reason = QString("The user \"%1\" is not online.").arg(username);
            QccPacket packet(QccPacket::AuthorizationFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("AuthorizationFailure: %s", qPrintable(reason));
#endif
        }
        break;
    }
    case QccPacket::AuthorizationAccepted:
    {
        QString username;
        in >> username;
        if (username.isEmpty())
            break;
        User *receiver = m_users[username];
        if (receiver && receiver->isOnline()) {
            receiver->addContact(client->user->username());
            client->user->addContact(username);
            saveUsers();
            QccPacket packet(QccPacket::AuthorizationAccepted);
            packet.stream() << client->user->username() << (qint32)client->user->status() << client->user->publicKey();
            packet.send(receiver->socket());
            QccPacket packet2(QccPacket::AuthorizationAccepted);
            packet2.stream() << username << (qint32)receiver->status() << receiver->publicKey();
            packet2.send(socket);
        }
#ifdef DEBUG
            qDebug("AuthorizationAccepted: forwarded to '%s'", qPrintable(username));
#endif
        break;
    }
    case QccPacket::AuthorizationDeclined:
    {
        QString username;
        in >> username;
        if (username.isEmpty())
            break;
        User *receiver = m_users.value(username);
        if (receiver && receiver->isOnline()) {
            QccPacket packet(QccPacket::AuthorizationDeclined);
            packet.stream() << client->user->username();
            packet.send(receiver->socket());
        }
#ifdef DEBUG
            qDebug("AuthorizationDeclined: forwarded to '%s'", qPrintable(username));
#endif
        break;
    }
    case QccPacket::RequestContactList:
    {
        QccPacket packet(QccPacket::ContactList);
        QSet<QString> contacts = client->user->contacts();
        packet.stream() << (qint32)contacts.count();
        foreach (const QString &contactName, contacts) {
            User *contact = m_users.value(contactName);
            if (!contact) continue;
            packet.stream() << contactName << qint32(contact->status()) << contact->publicKey();
        }
        packet.send(socket);
#ifdef DEBUG
            qDebug("ContactList: %i contacts send", contacts.count());
#endif
        break;
    }
    case QccPacket::RemoveContact:
    {
        QString username;
        in >> username;
        if (client->user->removeContact(username)) {
            QccPacket packet(QccPacket::ContactRemoved);
            packet.stream() << username;
            packet.send(socket);
            User *receiver = m_users[username];
            if (receiver && receiver->removeContact(client->user->username()) && receiver->isOnline()) {
                QccPacket packet2(QccPacket::ContactRemoved);
                packet2.stream() << client->user->username();
                packet2.send(receiver->socket());
            }
            saveUsers();
#ifdef DEBUG
            qDebug("ContactRemoved: contact '%s' removed", qPrintable(username));
#endif
        }
        break;
    }
    case QccPacket::Message:
    {
        qint32 id;
        QString receiverName;
        QString message;
        in >> id >> receiverName >> message;
        if (!client->user->containsContact(receiverName)) {
            QString reason = QString("The user \"%1\" is not on your contact list.").arg(receiverName);
            QccPacket packet(QccPacket::MessageFailure);
            packet.stream() << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("MessageFailure: %s", qPrintable(reason));
#endif
            break;
        }
        User *receiver = m_users.value(receiverName);
        if (receiver && receiver->isOnline()) {
            QccPacket packet(QccPacket::Message);
            packet.stream() << id << client->user->username() << message;
            packet.send(receiver->socket());
#ifdef DEBUG
            qDebug("Message: forwarded to '%s'", qPrintable(receiverName));
#endif
        } else {
            QString reason = QString("The user \"%1\" is not online.").arg(receiverName);
            QccPacket packet(QccPacket::MessageFailure);
            packet.stream() << id << receiverName << reason;
            packet.send(socket);
#ifdef DEBUG
            qDebug("MessageFailure: failed to forward to '%s' => %s",
                   qPrintable(receiverName), qPrintable(reason));
#endif
        }
        break;
    }
    case QccPacket::MessageSuccess:
    {
        qint32 id;
        QString receiverName;
        in >> id >> receiverName;
        User *receiver = m_users.value(receiverName);
        if (receiver && receiver->isOnline()) {
            QccPacket packet(QccPacket::MessageSuccess);
            packet.stream() << id << client->user->username();
            packet.send(receiver->socket());
#ifdef DEBUG
            qDebug("MessageSuccess: forwarded to '%s'", qPrintable(receiverName));
#endif
        }
        break;
    }
    default:
        qWarning("Server::client_readyRead(): Illegal PacketType %i", type);
        return;
    }
Beispiel #7
0
void modifyUser(LinkedList<User> *listOfUsers)
{
	string username, reply, modification;
	Node<User> *tmp;

	//The user is initially prompted for a username in order to identify which person to mod
	cout << "What is the username of the user you wish to modify?\n\n";
	getline(cin, username);

	tmp = listOfUsers->mHead; //tmp is set to the first user in the list

	while (tmp != NULL)
	{
		//As long as the specified user isn't found and tmp isn't NULL, the loop will search for the user
		if (tmp->mData.getUserName() == username)
		{
			break;
		}
		else
		{
			tmp = tmp->mNext;
		}
	}

	if (tmp == NULL)
	{
		cout << "That user does not exist.\n\n";
	}
	else //If they exist, the user is prompted to change either the name, username, or password 
	{
		cout << "Would you like to modify the name, username, or password?\n\n";
		getline(cin, reply);

		if (reply == "name")
		{
			cout << "What is the new name?\n\n";
			getline(cin, modification);

			//setName is called and the modification is passed in order to update the name
			tmp->mData.setName(modification); 
		}
		else if (reply == "username")
		{
			cout << "What is the new username?\n\n";
			getline(cin, modification);

			//setUserName is called and the modification is passed in order to update the username
			tmp->mData.setUserName(modification);
		}
		else if (reply == "password")
		{
			cout << "What is the new password?\n\n";
			getline(cin, modification);

			//setPassword is called and the modification is passed in order to update the password
			tmp->mData.setPassword(modification);
		}
		else
		{
			cout << "Invalid selection.\n\n";
		}
	}
	
	saveUsers(listOfUsers);
}
Beispiel #8
0
void UserManagement::readUserData(QString fileName)
{
    //READS THE USER.CSV FILE AND PARSES IT ACCORDINGLY
    QFile players(fileName);
    if (players.open(QIODevice::ReadOnly))
    {
        QTextStream reader(&players);
        QString data=reader.readLine();
        QStringList values;
        while(!data.isNull())
        {
            if(data.contains(":"))//checks for garbage that doesnt have :
            {
                values=data.split(":");
                userTimestamp.append(values[0]);
                if(nameValidation(values[1]))//CHECKS FOR NAME VALIDATION
                {
                    userPlayer.append(values[1]);
                }
                else
                {
                    userPlayer.append("");
                    players.remove();
                    userTimestamp.clear();
                    userPlayer.clear();
                    userLevel.clear();
                    saveUsers(fileName);
                    break;
                }
                if(levelValidation(values[2]))//CHECKS FOR LEVEL VALIDATION
                {
                    userLevel.append(values[2]);
                }
                else
                {
                        userPlayer.append("");
                        players.remove();
                        userTimestamp.clear();
                        userPlayer.clear();
                        userLevel.clear();
                        saveUsers(fileName);
                        break;
                    }
                data = reader.readLine();
            }
            else
                break;
        }
        players.close();
    }
    else//CHECKS IF FILE ISNT READ (AKA DOESNT EXIST)
    {

        userPlayer.append("");
        userTimestamp.append("");
        userLevel.append("");
    }
    if(userPlayer.size()==0)//CHECKS IF FILE IS EMPTY
    {
        userPlayer.append("");
        userTimestamp.append("");
        userLevel.append("");
        QMessageBox invalidPlayerData;
        invalidPlayerData.setText("Error! “pvz_players” has invalid player data!\nThe program will run with default settings.\nPlease create a new user.");
        invalidPlayerData.setStandardButtons(QMessageBox::Ok);
        invalidPlayerData.exec();
    }
}
Beispiel #9
0
void Library::loadUsers()
{
	ifstream infile(filenameUsers.c_str());
	if (!infile.is_open())
	{
		cout << "O ficheiro " << filenameUsers << " nao existe. A criar...\n";
		saveUsers();
		infile.open(filenameUsers.c_str());
	}
	if (infile.fail())
	{
		cout << "Erro ao ler o ficheiro "<< filenameUsers << "!";
		return;
	}
	bool done = false;
	string tempStr;
	istringstream Line;
	do
	{
		char tempChar;
		getline(infile,tempStr);
		Line.clear();
		Line.str(tempStr);
		Line >> tempChar;
		if (tempChar == '\\')
		{
			IdentNum userID, bookID;
			string userName;
			bool userActive;
			bool noName = true;
			getline(infile,tempStr);//userID
			Line.clear();
			Line.str(tempStr);
			Line >> userID;
			getline(infile,tempStr);//userName
			Line.clear();
			Line.str(tempStr);
			while (Line >> tempStr)
			{
				if (noName)
				{
					userName = tempStr;
					noName = false;
				}
				else userName = userName + " " + tempStr;
			}
			getline(infile,tempStr);//userActive
			Line.clear();
			Line.str(tempStr);
			Line >> userActive;
			getline(infile,tempStr);//booksRequested
			Line.clear();
			Line.str(tempStr);			
			User userTemp(userName);
			Line >> bookID;
			if (bookID != 0)
			{
				userTemp.borrowBook(bookID);
				while (Line >> bookID)
					userTemp.borrowBook(bookID);
			}
			userTemp.setID(userID);
			userTemp.setActive(userActive);
			users.push_back(userTemp);
		}
Beispiel #10
0
Library::~Library()
{
	saveBooks();
	saveUsers();
}
Beispiel #11
0
LoginDialog::~LoginDialog()
{
    // save users
    saveUsers();
}