2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
22 #include "stg/blowfish.h"
23 #include "stg/rs_packets.h"
24 #include "stg/logger.h"
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wshadow"
33 #include <jthread.hpp>
34 #pragma GCC diagnostic pop
48 enum {CONNECT, ALIVE, DISCONNECT} type;
53 explicit AliveData(const UserData& ud)
57 bool operator<(const std::string& rhs) const { return data.login < rhs; };
68 void SetPort(uint16_t p) { port = p; };
69 void SetPassword(const std::string & p);
70 void SetUserTimeout(int t) { userTimeout = t; };
71 void SetScriptOnConnect(const std::string & script) { scriptOnConnect = script; };
72 void SetScriptOnDisconnect(const std::string & script) { scriptOnDisconnect = script; };
76 bool IsRunning() const { return !receiverStopped && !processorStopped; };
78 const std::string & GetStrError() const { return errorStr; };
79 const std::string & GetVersion() const { return version; };
83 void Run(std::stop_token token);
84 void RunProcessor(std::stop_token token);
88 bool RecvPacket(const std::stop_token& token);
90 bool CheckHeader(const RS::PACKET_HEADER & header) const;
91 bool GetParams(char * buffer, UserData & data);
93 void ProcessPending();
94 void ProcessTimeouts();
95 bool Disconnect(const AliveData& data) const;
96 bool Connect(const PendingData& data) const;
99 STG::Logger& WriteServLog;
101 mutable std::string errorStr;
102 std::string scriptOnConnect;
103 std::string scriptOnDisconnect;
104 std::string password;
107 bool receiverStopped;
108 bool processorStopped;
109 std::vector<AliveData> users;
110 std::vector<PendingData> pending;
113 std::jthread m_receiverThread;
114 std::jthread m_processorThread;