diff --git a/.gitignore b/.gitignore index 63551f8..be36e1f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ CppProperties.json Userfile.csv Userinfo.txt +#ignore file with personal information +c_cpp_properties.json + # User-specific files *.rsuser *.suo diff --git a/.vscode/settings.json b/.vscode/settings.json index b9e543e..4b0f8a3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -64,7 +64,31 @@ "thread": "cpp", "unordered_map": "cpp", "xhash": "cpp", - "*.rh": "cpp" + "*.rh": "cpp", + "*.ipp": "cpp", + "any": "cpp", + "array": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "coroutine": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "map": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "source_location": "cpp", + "future": "cpp", + "ranges": "cpp", + "stop_token": "cpp" }, - "C_Cpp.default.cppStandard": "c++17" + "C_Cpp.default.cppStandard": "c++17", + "C_Cpp.dimInactiveRegions": false } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3c4e980..ee3034f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,35 +4,70 @@ "version": "2.0.0", "tasks": [ { - "label": "build", - "type": "shell", - "command": "cl.exe", + "type": "cppbuild", + "label": "C/C++: g++.exe Create Server", + "command": "C:\\msys64\\mingw64\\bin\\g++.exe", "args": [ - "/std:c++17", - "/property:GenerateFullPaths=true", - "/t:build", - "/consoleloggerparameters:NoSummary" + "--std", + "c++20", + "-g", + "${workspaceFolder}\\common\\*.cpp", + "${workspaceFolder}\\src\\*.cpp", + "-static", + "-static-libgcc", + "-static-libstdc++", + "-o", + "${workspaceFolder}\\LSMSServer.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" ], - "group": "build", - "presentation": { - "reveal": "silent" + "group": { + "kind": "build", + "isDefault": true }, - "problemMatcher": "$msCompile" + "detail": "Compiler: C:\\msys64\\mingw64\\bin\\g++.exe" }, { "type": "cppbuild", - "label": "C/C++: g++.exe Aktive Datei kompilieren", + "label": "C/C++: g++.exe Create Client", "command": "C:\\msys64\\mingw64\\bin\\g++.exe", "args": [ "--std", - "c++17", + "c++20", "-g", - "${workspaceFolder}\\src\\*.cpp", + "${workspaceFolder}\\common\\*.cpp", + "${workspaceFolder}\\Client\\src\\*.cpp", "-static", "-static-libgcc", "-static-libstdc++", "-o", - "${workspaceFolder}\\LSMS.exe" + "${workspaceFolder}\\Client\\LSMSClient.exe" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Compiler: C:\\msys64\\mingw64\\bin\\g++.exe" + }, + { + "type": "cppbuild", + "label": "C/C++: g++.exe Compile Common Files", + "command": "C:\\msys64\\mingw64\\bin\\g++.exe", + "args": [ + "--std", + "c++20", + "-g", + "${workspaceFolder}\\common\\*.cpp" ], "options": { "cwd": "${fileDirname}" diff --git a/Client/LSMSClient.exe b/Client/LSMSClient.exe new file mode 100644 index 0000000..7822bfd Binary files /dev/null and b/Client/LSMSClient.exe differ diff --git a/Client/src/Client.cpp b/Client/src/Client.cpp new file mode 100644 index 0000000..e8c69ca --- /dev/null +++ b/Client/src/Client.cpp @@ -0,0 +1 @@ +#include "Client.h" diff --git a/Client/src/Client.h b/Client/src/Client.h new file mode 100644 index 0000000..859f8ef --- /dev/null +++ b/Client/src/Client.h @@ -0,0 +1,17 @@ +#pragma once +#include + +namespace lsms { + + class Client : public libnet::Client_Interface { + private: + bool m_running = false; + bool m_connected = false; + + bool mf_startup(); + public: + void run_client(); + + }; + +} \ No newline at end of file diff --git a/LSMSServer.exe b/LSMSServer.exe new file mode 100644 index 0000000..665549b Binary files /dev/null and b/LSMSServer.exe differ diff --git a/common/CommonNetInclude.h b/common/CommonNetInclude.h new file mode 100644 index 0000000..db26ac8 --- /dev/null +++ b/common/CommonNetInclude.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#define _WIN32_WINNT 0x0A00 +#endif + +#define ASIO_STANDALONE +#include +#include +#include \ No newline at end of file diff --git a/Data/Books/FifthBook.txt b/common/Data/Books/FifthBook.txt similarity index 100% rename from Data/Books/FifthBook.txt rename to common/Data/Books/FifthBook.txt diff --git a/Data/Books/FirstBook.txt b/common/Data/Books/FirstBook.txt similarity index 100% rename from Data/Books/FirstBook.txt rename to common/Data/Books/FirstBook.txt diff --git a/Data/Books/FoursBook.txt b/common/Data/Books/FoursBook.txt similarity index 100% rename from Data/Books/FoursBook.txt rename to common/Data/Books/FoursBook.txt diff --git a/Data/Books/SecondBook.txt b/common/Data/Books/SecondBook.txt similarity index 100% rename from Data/Books/SecondBook.txt rename to common/Data/Books/SecondBook.txt diff --git a/Data/Books/SixthBook.txt b/common/Data/Books/SixthBook.txt similarity index 100% rename from Data/Books/SixthBook.txt rename to common/Data/Books/SixthBook.txt diff --git a/Data/Books/ThirdBook.txt b/common/Data/Books/ThirdBook.txt similarity index 100% rename from Data/Books/ThirdBook.txt rename to common/Data/Books/ThirdBook.txt diff --git a/Data/Inventory.csv b/common/Data/Inventory.csv similarity index 100% rename from Data/Inventory.csv rename to common/Data/Inventory.csv diff --git a/common/LibConnection.h b/common/LibConnection.h new file mode 100644 index 0000000..31b3d4e --- /dev/null +++ b/common/LibConnection.h @@ -0,0 +1,204 @@ +#pragma once +#include "CommonNetInclude.h" +#include "LibMsg.h" +#include "LibTSQueue.h" + +namespace lsms +{ + namespace libnet + { + template + class Connection : public std::enable_shared_from_this> // enables us to create a shared pointer to this -> similar to this just shared_ptr + { + public: + enum class owner + { + server, + client + }; + + Connection(owner parent, asio::io_context &asioContext, asio::ip::tcp::socket socket, TSQueue> &qIn) + : m_asioContext(asioContext); + m_socket(socket); + m_qMessagesIn(qIn) + { + m_nOwnerType = parent; + } + virtual ~Connection(){ + + }; + + public: + bool connect_to_server(const asio::ip::tcp::resolver::results_type& endpoints) + { + if(m_nOwnerType == owner::client) + { + asio::async_connect(m_socket, endpoints, + [this](std::error_code ec, asio::ip::tcp::endpoint endpoint) + { + if(!ec) + { + mf_read_header(); + } + }); + } + } + void connect_to_client(uint32_t uid = 0) + { + if (m_nOwnerType == owner::server) + { + if (m_socket.is_open()) + { + id = uid; + mf_read_header(); + } + } + } + + void disconnect() + { + if (is_connected()) + asio::post(m_asioContext, [this]() + { m_socket.close(); }); + } + bool is_connected() const + { + return m_socket.is_open(); + } + uint32_t get_id() const + { + return m_id; + } + + public: + bool send(const libmsg::Message &msg) + { + asio::post(m_asioContext, + [this, msg]() + { + bool b_is_writing_messages = !m_qMessagesOut.empty(); + m_qMessagesOut.push_back(msg); + if (!b_is_writing_messages) + { + mf_write_header(); + } + }); + } + + private: + void mf_read_header() + { + asio::async_read(m_socket, asio::buffer(&m_TempMsgIn.header, sizeof(libmsg::MessageHeader)), + [this](std::error_code ec, std::size_t length) + { + if (!ec) + { + if (m_TempMsgIn.header.size > 0) + { + m_TempMsgIn.body.resize(m_TempMsgIn.header.size); + mf_read_body(); + } + else + { + mf_add_to_incoming_message_queue(); + } + } + else + { + // inform server here + m_socket.close(); + } + }); + } + + void mf_read_body() + { + asio::async_read(m_socket, asio::buffer(m_TempMsgIn.body, m_TempMsgIn.body.size()), + [this](std::error_code ec, std::size_t length) + { + if (!ec) + { + mf_add_to_incoming_message_queue(); + } + else + { + // failed to read and add to body + m_socket.close(); + } + }); + } + + void mf_write_header() + { + asio::async_write(m_socket, asio::buffer(&m_qMessagesOut.front().header, sizeof(libmsg::MessageHeader)), + [this](std::error_code ec, std::size_t lenght) + { + if (!ec) + { + if (m_qMessagesOut.front().body.size() > 0) + { + mf_write_body(); + } + else + { + m_qMessagesOut.pop_front(); + if (!m_qMessagesOut.empty()) + { + mf_write_header(); + } + } + } + else + { + // inform that something went wrong + m_socket.close(); + } + }); + } + + void mf_write_body() + { + asio::async_write(m_socket, asio::buffer(&m_qMessagesOut.front().body.data(), m_qMessagesOut.front().body.size()), + [this](std::error_code, std::size_t length) + { + if (!ec) + { + m_qMessagesOut.pop_front(); + + if (!m_qMessagesOut.empty()) + { + mf_write_header(); + } + } + else + { + // inform that sending failed + m_socket.close(); + } + }); + } + void mf_add_to_incoming_message_queue() + { + if (m_nOwnerType == owner::server) + m_qMessagesIn.push_back({this->shared_from_this(), m_TempMsgIn}); + else + m_qMessagesIn.push_back({nullptr, m_TempMsgIn}); + + mf_read_header(); + } + + protected: + asio::ip::tcp::socket m_socket; + + asio::io_context &m_asioContext; + + TSQueue> m_qMessagesOut; + TSQueue> &m_qMessagesIn; + libmsg::Message m_TempMsgIn; + + owner m_nOwnerType = owner::server; + uint32_t m_id = 0; + }; + + } +} \ No newline at end of file diff --git a/common/LibMsg.h b/common/LibMsg.h new file mode 100644 index 0000000..dbbc2ce --- /dev/null +++ b/common/LibMsg.h @@ -0,0 +1,97 @@ +#pragma once +#include "CommonNetInclude.h" + +namespace lsms +{ + + namespace libnet + { + + namespace libmsg + { + + enum class _DefaultMessageType : uint8_t + { + _request, + _answer + //add some more + }; + + template + struct MessageHeader + { + T id{}; + uint32_t size = 0; + }; + + template + struct Message + { + MessageHeader header{}; + std::vector body; + + size_t size() const + { + return sizeof(MessageHeader) + body.size(); + } + + friend std::ostream &operator<<(std::ostream &os, const Message msg) + { + os << "Message ID: " << (int)msg.header.id << " Message Size: " << msg.size; + return os; + } + + template + friend Message &operator<<(Message &msg, const DataType &data) + { + static_assert(std::is_standard_layout::value, "Data is too complex to be handled by message object"); + + size_t current_body_size = msg.body.size(); + + msg.body.resize(current_body_size + sizeof(DataType)); + + std::memcpy(msg.body.data() + current_body_size, &data, sizeof(DataType)); + + msg.header.size = msg.size(); + + return msg; + } + + template + friend Message &operator>>(Message &msg, const DataType &data) + { + static_assert(std::is_standard_layout::value, "Data is too complex to be handled by message object"); + + size_t cached_location = msg.body.size() - sizeof(DataType); + + std::memcpy(&data, msg.body.data() + cached_location, sizeof(DataType)); + + msg.body.resize(cached_location); + + msg.header.size = msg.size(); + + return msg; + } + }; + + + //forward declaration of Connection Type + template + class Connection; + + template + struct Owned_Message { + std::shared_ptr> remote = nullptr; + Message msg; + + friend std::ostream& operator<<(std::ostream os, const Owned_Message msg) + { + os << msg.msg; + return os; + } + }; + + } + } + +} \ No newline at end of file diff --git a/common/LibNet.h b/common/LibNet.h new file mode 100644 index 0000000..11bff5a --- /dev/null +++ b/common/LibNet.h @@ -0,0 +1,7 @@ +#pragma once +#include "LibMsg.h" +#include "LibTSQueue.h" +#include "LibConnection.h" +#include "LibNetClientInterface.h" +#include "LibNetServerInterface.h" +#include "LibTime.h" \ No newline at end of file diff --git a/common/LibNetClientInterface.h b/common/LibNetClientInterface.h new file mode 100644 index 0000000..176021e --- /dev/null +++ b/common/LibNetClientInterface.h @@ -0,0 +1,85 @@ +#pragma once +#include "CommonNetInclude.h" +#include "LibMsg.h" +#include "LibTSQueue.h" +#include "LibConnection.h" + +namespace lsms { + namespace libnet { + + template + class Client_Interface + { + public: + + Client_Interface(){} + + virtual ~Client_Interface() + { + disconnect(); + } + + + bool connect(const std::string& host, const uint16_t port) + { + try + { + asio::ip::tcp::resolver resolver(m_context); + auto endpoints = resolver.resolve(host, std::to_string(port)); + + + m_connection = std::make_unique>( + Connection::owner::client, + m_context, + asio::ip::tcp::socket(m_context), m_qMessagesIn + ); + m_connection->connect_to_server(endpoints); + + m_thrContext = std::thread([this] () { m_context.run(); }); + + } + catch (std::exception& e) + { + //inform that client couldn't connect to ip adress + return false; + } + return true; + } + + void disconnect() + { + if(is_connected()) + m_connection->disconnect(); + + m_context.stop(); + if(m_thrContext.joinable()) + m_thrContext.join(); + + m_connection.release(); + } + + bool is_connected() + { + if(m_connection) + return m_connection->is_connected(); + else + return false; + } + + TSQueue>& getIncomming() + { + return m_qMessagesIn; + } + protected: + asio::io_context m_context; + std::thread m_thrContext + + std::unique_ptr> m_connection; + + private: + TSQueue> m_qMessagesIn; + }; + + + } +} \ No newline at end of file diff --git a/common/LibNetServerInterface.h b/common/LibNetServerInterface.h new file mode 100644 index 0000000..4ee1d1b --- /dev/null +++ b/common/LibNetServerInterface.h @@ -0,0 +1,157 @@ +#pragma once +#include "CommonNetInclude.h" +#include "LibMsg.h" +#include "LibTSQueue.h" +#include "LibConnection.h" + +namespace lsms +{ + namespace libnet + { + template + class Server_Interface + { + public: + Server_Interface(uint16_t port) : m_asioAcceptor(m_asioContext, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)) + { + } + virtual ~Server_Interface() + { + stop_server(); + } + + bool start_server() + { + try + { + wait_for_client_connection(); + m_threadContext = std::thread([this]() + { m_asioContext.run(); }); + } + catch (std::exception &e) + { + // throw an error here + } + // inform that server is running here + } + void stop_server() + { + m_asioContext.stop(); + + if (m_threadContext.joinable()) + m_threadContext.join(); + + // inform that server stopped + } + void wait_for_client_connection() + { + m_asioAcceptor.async_accept( + [this](std::error_code ec, asio::ip::tcp::socket socket) + { + if (!ec) + { + // display successfull connection + + std::shared_ptr> newconn = std::make_shared>(Connection::owner::server, + m_asioContext, std::move(socket), m_qMessagesIn); + + if (on_client_connect(newconn)) + { + m_deqConnections.push_back(std::move(newconn)); + + m_deqConnections.back()->connect_to_client(nIDCounter++); + + // inform server + } + else + { + // connection was denied + } + } + else + { + // inform of error + } + + wait_for_client_connection(); + }); + } + void message_client(std::shared_ptr> client, const Message &msg) + { + if (client && client->is_connected()) + { + client->send(msg); + } + else + { + on_client_disconnect(client); + client.reset(); + m_deqConnections.erase(std::remove(m_deqConnections.begin(), m_deqConnections.end(), client), m_deqConnections.end()); + } + } + void message_all_clients(const Message &msg, std::shared_ptr> pIgnoreClient = nullptr) + { + bool invalid_client_exists = false; + + for (auto &client : m_deqConnections) + { + if (client && client->is_connected()) + { + if (client != pIgnoreClient) + client->send(msg); + } + else + { + on_client_disconnect(client); + client.reset(); + invalid_client_exists = true; + } + } + + if (invalid_client_exists) + { + m_deqConnections.erase(std::remove(m_deqConnections.begin(), m_deqConnections.end(), nullptr), m_deqConnections.end()); + } + } + + void update(size_t nMaxMessages = -1) + { + size_t nMessageCount = 0; + while (nMessageCount < nMaxMessages && !m_qMessagesIn.empty()) + { + auto msg = m_qMessagesIn.pop_front(); + + on_message(msg.remote(), msg.msg); + + nMessageCount++; + } + } + + protected: + virtual bool on_client_connect(std::shared_ptr> client) + { + return false; + } + + virtual void on_client_disconnect(std::shared_ptr> client) + { + } + virtual void on_message(std::shared_ptr> client, Message &msg) + { + } + + protected: + TSQueue> m_qMessagesIn; + + std::deque>> m_deqConnections; + + asio::io_context m_asioContext; + std::thread m_threadContext; + + asio::ip::tcp::acceptor m_asioAcceptor; + + uint32_t nIDCounter = 10000; + }; + + } +} \ No newline at end of file diff --git a/common/LibTSQueue.h b/common/LibTSQueue.h new file mode 100644 index 0000000..6666c73 --- /dev/null +++ b/common/LibTSQueue.h @@ -0,0 +1,80 @@ +#pragma once +#include "CommonNetInclude.h" + +namespace lsms +{ + namespace libnet + { + template + class TSQueue + { + public: + TSQueue() = default; + TSQueue(const TSQueue &) = delete; + virtual ~TSQueue() { clear(); }; + + public: + const T &front() + { + std::scoped_lock lock(muxQueue); + return deqQueue.front(); + } + + const T &back() + { + std::scoped_lock lock(muxQueue); + return deqQueue.back(); + } + + void push_front(const T &item) + { + std::scoped_lock lock(muxQueue); + deqQueue.emplace_front(std::move(item)); + } + + void push_back(const T &item) + { + std::scoped_lock lock(muxQueue); + deqQueue.emplace_back(std::move(item)); + } + + bool empty() + { + std::scoped_lock lock(muxQueue); + return deqQueue.empty(); + } + + size_t count() + { + std::scoped_lock lock(muxQueue); + return deqQueue.size(); + } + + void clear() + { + std::scoped_lock lock(muxQueue); + deqQueue.clear(); + } + + T pop_front() + { + std::scoped_lock lock(muxQueue); + auto t = std::move(deqQueue.front()); + deqQueue.pop_front(); + return t; + } + + T pop_back() + { + std::scoped_lock lock(muxQueue); + auto t = std::move (deqQueue.back); + deqQueue.pop_back(); + return t; + } + + protected: + std::mutex muxQueue; + std::deque deqQueue; + }; + } +} \ No newline at end of file diff --git a/common/LibTime.cpp b/common/LibTime.cpp new file mode 100644 index 0000000..6dfd2c2 --- /dev/null +++ b/common/LibTime.cpp @@ -0,0 +1,12 @@ +#include "LibTime.h" + +namespace LIBTIME +{ + char *getdate_mmddyyyy(char *_str) + { + std::time_t t = std::time(0); + strftime(_str, MAXDATELENGTH, "%m%d%Y", localtime(&t)); + return _str; + } + +}; \ No newline at end of file diff --git a/src/Time.h b/common/LibTime.h similarity index 84% rename from src/Time.h rename to common/LibTime.h index aafa685..ae59a9e 100644 --- a/src/Time.h +++ b/common/LibTime.h @@ -1,10 +1,10 @@ #pragma once #include -namespace libtime +namespace LIBTIME { constexpr size_t MAXDATELENGTH = 80; char *getdate_mmddyyyy(char *); -} +}; \ No newline at end of file diff --git a/src/Book.cpp b/src/Book.cpp index fc1a673..50b3fdf 100644 --- a/src/Book.cpp +++ b/src/Book.cpp @@ -1,5 +1,5 @@ #include "Book.h" -namespace LSMS +namespace lsms { Book::Book(csv::Row *_ptr_row) { diff --git a/src/Book.h b/src/Book.h index 67b849c..236a726 100644 --- a/src/Book.h +++ b/src/Book.h @@ -4,7 +4,7 @@ #include #include -namespace LSMS +namespace lsms { class Book { diff --git a/src/Library.cpp b/src/Library.cpp index 14105ab..e9cdc70 100644 --- a/src/Library.cpp +++ b/src/Library.cpp @@ -1,6 +1,6 @@ #include "Library.h" -namespace LSMS +namespace lsms { Library::Library() {} diff --git a/src/Library.h b/src/Library.h index e9b7f87..1cf67f3 100644 --- a/src/Library.h +++ b/src/Library.h @@ -2,7 +2,7 @@ #include "User.h" #include "Book.h" -namespace LSMS +namespace lsms { #ifndef BOOK_PTR() @@ -19,7 +19,7 @@ namespace LSMS user::User m_user{}; csv::Header m_inventory_structure{"BID,NAME,AUTHOR,COPIES,RENTED,LINK"}; - std::string m_inventory_path{(fm::init_workingdir() + "Data/Inventory.csv")}; + std::string m_inventory_path{(fm::init_workingdir() + "common/Data/Inventory.csv")}; csv::CSVParser m_inventory_csv{m_inventory_path, m_inventory_structure}; bool mf_startup(); diff --git a/src/Server.cpp b/src/Server.cpp new file mode 100644 index 0000000..4abc27e --- /dev/null +++ b/src/Server.cpp @@ -0,0 +1,74 @@ +#include "Library.h" +#include "LibNet.h" + +#include + +#define log(x) std::cout << x + +namespace libnet = lsms::libnet; +namespace libmsg = lsms::libnet::libmsg; + +class Server : public libnet::Server_Interface +{ +public: + Server(uint16_t nPort) : libnet::Server_Interface(nPort) + {} + +protected: + virtual bool on_client_connect(std::shared_ptr> client) + { + return true; + } + + virtual void on_client_disconnect(std::shared_ptr> client) + { + + } + + virtual void on_message(std::shared_ptr> client, libmsg::Message>& msg) + {} + +}; + + +void print_welcome() +{ + std::fstream file; + std::string line; + + try + { + file.open((fm::init_workingdir() + "Welcome.txt"), std::ios::in | std::ios::binary); + if (file.is_open()) + { + while (!file.eof()) + { + fm::_getline(file, line); + std::cout << line << std::endl; + } + } + else + log("Could not open Welcome Message\n"); + } + catch (const std::ifstream::failure &e) + { + } + file.close(); +}; + +int main() +{ + Server server(60000); + server.start_server(); + + lsms::Library lib{}; + + print_welcome(); + std::cin.get(); + system("cls"); + + lib.run(); + + return 0; +} + diff --git a/src/Time.cpp b/src/Time.cpp deleted file mode 100644 index 9109325..0000000 --- a/src/Time.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Time.h" - -char *libtime::getdate_mmddyyyy(char *_str) -{ - std::time_t t = std::time(0); - strftime(_str, MAXDATELENGTH, "%m%d%Y", localtime(&t)); - return _str; -} diff --git a/src/User.cpp b/src/User.cpp index ce0ed00..2764c83 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -1,6 +1,6 @@ #include "User.h" -namespace LSMS +namespace lsms { //namespace user namespace user @@ -444,6 +444,9 @@ namespace LSMS _Userstate &User::add_book(Book &_book, bool _buy = false) { + + //forward declaration of time function + if (!this->can_rent() && !_buy || !this->can_buy() && _buy) { return mf_set_state(failbit); @@ -452,8 +455,8 @@ namespace LSMS bookentry += _book.get_BID(); bookentry += ','; //add date - char datebuf[libtime::MAXDATELENGTH] = {NULL}; - libtime::getdate_mmddyyyy(datebuf); + char datebuf[LIBTIME::MAXDATELENGTH] = {NULL}; + LIBTIME::getdate_mmddyyyy(datebuf); bookentry.append(datebuf); bookentry += ','; //reading pos = begin @@ -501,7 +504,7 @@ namespace LSMS { //initialize needed files csv::Header _userfile_header{"USERNAME,PASSWORD,UID"}; - std::string _path_userfile{fm::init_workingdir() + "Data/Userfile.csv"}; + std::string _path_userfile{fm::init_workingdir() + "common/Data/Userfile.csv"}; csv::CSVParser _userfile_csv{_path_userfile, _userfile_header}; //login page diff --git a/src/User.h b/src/User.h index 6fb6445..52453ff 100644 --- a/src/User.h +++ b/src/User.h @@ -1,13 +1,13 @@ #pragma once #include "CSVParser.h" #include "Book.h" -#include "Time.h" +#include "../common/LibTime.h" #include #include #include #include -namespace LSMS +namespace lsms { #ifndef BOOK_PTR() #define BOOK_PTR() GetBookInstance() @@ -37,7 +37,7 @@ namespace LSMS enum _Userstate { - _Statmask = 0x17 + _Statmask = 0x3 }; static constexpr _Userstate goodbit = (_Userstate)0x1; //everything's fine @@ -122,7 +122,7 @@ namespace LSMS std::vector mvec_owned; std::vector mvec_published; - std::string m_path_userinfo{fm::init_workingdir() + "Data/Userinfo.txt"}; + std::string m_path_userinfo{fm::init_workingdir() + "common/Data/Userinfo.txt"}; csv::Header m_bookheader{"BID,DATE,POSITION"}; std::fstream m_userinfo_txt; diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 40a5a2f..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "Library.h" - -#include - -#define log(x) std::cout << x - -void print_welcome(); - -int main() -{ - - LSMS::Library lib{}; - - print_welcome(); - std::cin.get(); - system("cls"); - - lib.run(); - - return 0; -} - -void print_welcome() -{ - std::fstream file; - std::string line; - - try - { - file.open((fm::init_workingdir() + "Welcome.txt"), std::ios::in | std::ios::binary); - if (file.is_open()) - { - while (!file.eof()) - { - fm::_getline(file, line); - std::cout << line << std::endl; - } - } - else - log("Could not open Welcome Message\n"); - } - catch (const std::ifstream::failure &e) - { - } - file.close(); -};