Skip to content

Commit

Permalink
[search] Start on refactoring search server
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Feb 21, 2022
1 parent c2bc2c5 commit eb00563
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ add_subdirectory(common)
add_subdirectory(login)
add_subdirectory(map)
add_subdirectory(search)
add_subdirectory(world)
#add_subdirectory(world)
5 changes: 3 additions & 2 deletions src/search/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
set(SOURCES
data_loader.cpp
data_loader.h
search.cpp
search.h
main.cpp
search_server.cpp
search_server.h
tcp_request.cpp
tcp_request.h)

Expand Down
22 changes: 13 additions & 9 deletions src/search/data_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,28 @@ along with this program. If not, see http://www.gnu.org/licenses/
*/
#include <cstring>

#include "../common/mmo.h"
#include "../common/logging.h"
#include "../common/sql.h"
#include "common/mmo.h"
#include "common/logging.h"
#include "common/sql.h"
#include "common/settings_manager.h"

#include <algorithm>

#include "data_loader.h"
#include "search.h"
#include "search_server.h"

CDataLoader::CDataLoader()
{
SqlHandle = Sql_Malloc();

// ShowStatus("sqlhandle is allocating");
if (Sql_Connect(SqlHandle, search_config.mysql_login.c_str(), search_config.mysql_password.c_str(), search_config.mysql_host.c_str(),
search_config.mysql_port, search_config.mysql_database.c_str()) == SQL_ERROR)
if (Sql_Connect(SqlHandle,
SettingsManager::Get<std::string>(SqlSettings::LOGIN).c_str(),
SettingsManager::Get<std::string>(SqlSettings::PASSWORD).c_str(),
SettingsManager::Get<std::string>(SqlSettings::HOST).c_str(),
SettingsManager::Get<uint32>(SqlSettings::PORT),
SettingsManager::Get<std::string>(SqlSettings::DATABASE).c_str()) == SQL_ERROR)
{
ShowError("cant connect");
ShowFatalError("Could not connect to SQL database");
std::exit(-1);
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/search/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include "search_server.h"

int main(int argc, char** argv)
{
auto argParser = std::make_unique<argparse::ArgumentParser>(argv[0]);

try
{
argParser->parse_args(argc, argv);
}
catch (const std::runtime_error& err)
{
std::cerr << err.what() << std::endl;
std::cerr << argParser;
std::exit(1);
}

auto pSearchServer = std::make_unique<SearchServer>(std::move(argParser));

while (pSearchServer->IsRunning())
{
pSearchServer->Tick();
}

return 0;
}
9 changes: 1 addition & 8 deletions src/search/search.cpp → src/search/search_server.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef u_int SOCKET;
#include <sstream>

#include "data_loader.h"
#include "search.h"
#include "search_server.h"
#include "tcp_request.h"

#include "packets/auction_history.h"
Expand All @@ -69,13 +69,6 @@ typedef u_int SOCKET;
#define CODE_ZONE 20
#define CODE_ZONE_ALL 16

struct SearchCommInfo
{
SOCKET socket;
uint32 ip;
uint16 port;
};

void TaskManagerThread();

int32 ah_cleanup(time_point tick, CTaskMgr::CTask* PTask);
Expand Down
15 changes: 13 additions & 2 deletions src/search/search.h → src/search/search_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/

#include "../common/cbasetypes.h"
#pragma once

#include "common/application.h"

struct search_config_t
{
Expand Down Expand Up @@ -54,4 +56,13 @@ struct search_req
uint8 commentType;
};

extern search_config_t search_config;
struct SearchCommInfo
{
SOCKET socket;
uint32 ip;
uint16 port;
};

class SearchServer final : public Application
{
};
3 changes: 0 additions & 3 deletions src/world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ int main(int argc, char** argv)
while (pWorldServer->IsRunning())
{
pWorldServer->Tick();

// DEBUG
pWorldServer->bIsRunning = false;
}

return 0;
Expand Down
2 changes: 0 additions & 2 deletions src/world/world_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class WorldServer final : public Application
WorldServer(std::unique_ptr<argparse::ArgumentParser>&& pArgParser)
: Application(std::move(pArgParser))
{
std::cout << "\033[1;31mWORLD SERVER\033[0m\n";

// World server should _mostly_ be comprised of ZMQ handlers and timed tasks.
}

Expand Down

0 comments on commit eb00563

Please sign in to comment.