Skip to content

Commit

Permalink
Merge pull request LandSandBoat#3521 from LandSandBoat/populate_world…
Browse files Browse the repository at this point in the history
…_server

[core] MOVE MESSAGE SERVER TO XI_WORLD PROCESS
  • Loading branch information
zach2good authored Feb 10, 2023
2 parents 02fc13f + 4072f9b commit 191d0f1
Show file tree
Hide file tree
Showing 21 changed files with 315 additions and 52 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ jobs:
xi_connect
xi_map
xi_search
xi_world
Linux_GCC11_64bit:
needs: Sanity_Checks
Expand Down Expand Up @@ -300,6 +301,7 @@ jobs:
xi_connect.exe
xi_map.exe
xi_search.exe
xi_world.exe
Windows_64bit_Release_Tracy_Modules:
needs: Sanity_Checks
Expand Down Expand Up @@ -421,12 +423,14 @@ jobs:
chmod +x xi_connect
chmod +x xi_map
chmod +x xi_search
chmod +x xi_world
ls -l
printf "\nStart server processes\n"
screen -d -m -S xi_connect ./xi_connect --log login-server.log
screen -d -m -S xi_search ./xi_search --log search-server.log
screen -d -m -S xi_map ./xi_map --log map-server.log
screen -d -m -S xi_world ./xi_world --log world-server.log
printf "\nWaiting 5m for servers to fully start up\n"
sleep 300s
Expand Down Expand Up @@ -482,6 +486,7 @@ jobs:
cat login-server*.log
cat map-server*.log
cat search-server*.log
cat world-server*.log
if grep -qi "warning\|error\|crash" login-server*.log; then
exit -1
Expand All @@ -495,6 +500,10 @@ jobs:
exit -1
fi
if grep -qi "warning\|error\|crash" world-server*.log; then
exit -1
fi
MultiInstance_Startup_Checks_Linux:
runs-on: ubuntu-22.04
needs: Linux_Clang14_64bit
Expand Down Expand Up @@ -542,13 +551,15 @@ jobs:
chmod +x xi_connect
chmod +x xi_map
chmod +x xi_search
chmod +x xi_world
ls -l
printf "\nStart server processes\n"
screen -d -m -S xi_connect ./xi_connect --log login-server.log
screen -d -m -S xi_search ./xi_search --log search-server.log
screen -d -m -S xi_map ./xi_map --log map-server-0.log --ip 127.0.0.1 --port 54230
screen -d -m -S xi_map ./xi_map --log map-server-1.log --ip 127.0.0.1 --port 54231
screen -d -m -S xi_world ./xi_world --log world-server.log
sleep 300s
killall screen
- name: Check for errors and warnings
Expand All @@ -558,6 +569,7 @@ jobs:
cat search-server*.log
cat map-server-0*.log
cat map-server-1*.log
cat world-server*.log
if grep -qi "warning\|error\|crash" login-server*.log; then
exit -1
Expand All @@ -575,6 +587,10 @@ jobs:
exit -1
fi
if grep -qi "warning\|error\|crash" world-server*.log; then
exit -1
fi
Full_Startup_Checks_Windows:
runs-on: windows-latest
needs: Windows_64bit_Debug
Expand Down
27 changes: 21 additions & 6 deletions src/common/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,31 @@
#include <windows.h>
#endif

Application::Application(std::string serverName, std::unique_ptr<argparse::ArgumentParser>&& pArgParser)
Application::Application(std::string serverName, int argc, char** argv)
: m_ServerName(serverName)
, m_IsRunning(true)
, gArgParser(std::move(pArgParser))
, m_RequestExit(false)
, gArgParser(std::make_unique<argparse::ArgumentParser>(argv[0]))
{
#ifdef _WIN32
SetConsoleTitleA(fmt::format("{}-server", serverName).c_str());
#endif

logging::InitializeLog(serverName, fmt::format("log/{}-server.log", serverName), false);
gArgParser->add_argument("--log")
.default_value(fmt::format("log/{}-server.log", serverName));

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

auto logName = gArgParser->get<std::string>("--log");
logging::InitializeLog(serverName, logName, false);
lua_init();
settings::init();
ShowInfo("Begin %s-server initialisation...", serverName);
Expand All @@ -54,14 +69,14 @@ Application::Application(std::string serverName, std::unique_ptr<argparse::Argum

bool Application::IsRunning()
{
return m_IsRunning;
return !m_RequestExit;
}

void Application::Tick()
{
// Main runtime cycle
duration next;
while (m_IsRunning)
while (!m_RequestExit)
{
next = CTaskMgr::getInstance()->DoTimer(server_clock::now());
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class Application
{
public:
Application(std::string serverName, std::unique_ptr<argparse::ArgumentParser>&& pArgParser);
Application(std::string serverName, int argc, char** argv);
virtual ~Application() = default;

Application(const Application&) = delete;
Expand All @@ -44,7 +44,7 @@ class Application

protected:
std::string m_ServerName;
std::atomic<bool> m_IsRunning;
std::atomic<bool> m_RequestExit;

std::unique_ptr<argparse::ArgumentParser> gArgParser;
std::unique_ptr<ConsoleService> gConsoleService;
Expand Down
2 changes: 0 additions & 2 deletions src/login/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ set(SOURCES
login_session.h
login.cpp
login.h
message_server.cpp
message_server.h
)

if(UNIX)
Expand Down
9 changes: 0 additions & 9 deletions src/login/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ struct epoll_event login_lobbyviewEpollEvent = { EPOLLIN };
#include "login.h"
#include "login_auth.h"
#include "login_conf.h"
#include "message_server.h"

std::thread messageThread;

std::unique_ptr<SqlConnection> sql;

Expand Down Expand Up @@ -143,7 +140,6 @@ int32 do_init(int32 argc, char** argv)
ShowInfo("Character deletion is currently disabled.");
}

messageThread = std::thread(message_server_init, std::ref(requestExit));
// clang-format off
gConsoleService = std::make_unique<ConsoleService>();

Expand Down Expand Up @@ -206,11 +202,6 @@ int32 do_init(int32 argc, char** argv)
void do_final(int code)
{
requestExit = true;
message_server_close();
if (messageThread.joinable())
{
messageThread.join();
}

timer_final();
socket_final();
Expand Down
13 changes: 11 additions & 2 deletions src/login/login_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#include "common/logging.h"
#include "common/socket.h"

#include "map/message.h"

#include "login.h"
#include "login_auth.h"
#include "message_server.h"

#include <cctype>
#include <cstdio>
Expand Down Expand Up @@ -132,6 +133,7 @@ int32 login_parse(int32 fd)
{
fmtQuery = "UPDATE accounts SET accounts.timelastmodify = NULL WHERE accounts.id = %d";
sql->Query(fmtQuery, sd->accid);

fmtQuery = "SELECT charid, server_addr, server_port \
FROM accounts_sessions JOIN accounts \
ON accounts_sessions.accid = accounts.id \
Expand All @@ -147,13 +149,20 @@ int32 login_parse(int32 fd)

ip |= (port << 32);

std::ignore = ip;

zmq::message_t chardata(sizeof(charid));
ref<uint32>((uint8*)chardata.data(), 0) = charid;
zmq::message_t empty(0);

queue_message(ip, MSG_LOGIN, &chardata, &empty);
// TODO: MSG_LOGIN is a no-op in message_server.cpp,
// : so sending this does nothing?
// : But in the client (message.cpp), it _could_
// : be used to clear out lingering PChar data.
// queue_message(ipp, MSG_LOGIN, &chardata, &empty);
}
}

memset(&sessions[fd]->wdata[0], 0, 33);
sessions[fd]->wdata.resize(33);
ref<uint8>(sessions[fd]->wdata.data(), 0) = LOGIN_SUCCESS;
Expand Down
10 changes: 10 additions & 0 deletions src/world/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
set(SOURCES
${COMMON_SOURCES}
besieged_system.cpp
besieged_system.h
campaign_system.cpp
campaign_system.h
colonization_system.cpp
colonization_system.h
conquest_system.cpp
conquest_system.h
http_server.cpp
http_server.h
main.cpp
message_server.cpp
message_server.h
world_server.cpp
world_server.h)

Expand Down
22 changes: 22 additions & 0 deletions src/world/besieged_system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
===========================================================================
Copyright (c) 2023 LandSandBoat Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/

#include "besieged_system.h"
28 changes: 28 additions & 0 deletions src/world/besieged_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
===========================================================================
Copyright (c) 2023 LandSandBoat Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/
#pragma once

class BesiegedSystem
{
public:
BesiegedSystem() = default;
~BesiegedSystem() = default;
};
22 changes: 22 additions & 0 deletions src/world/campaign_system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
===========================================================================
Copyright (c) 2023 LandSandBoat Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/

#include "campaign_system.h"
28 changes: 28 additions & 0 deletions src/world/campaign_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
===========================================================================
Copyright (c) 2023 LandSandBoat Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/
#pragma once

class CampaignSystem
{
public:
CampaignSystem() = default;
~CampaignSystem() = default;
};
22 changes: 22 additions & 0 deletions src/world/colonization_system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
===========================================================================
Copyright (c) 2023 LandSandBoat Dev Teams
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
===========================================================================
*/

#include "colonization_system.h"
Loading

0 comments on commit 191d0f1

Please sign in to comment.