File: AdcHub.h

package info (click to toggle)
eiskaltdcpp 2.4.2-1.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,676 kB
  • sloc: cpp: 97,597; ansic: 5,004; perl: 1,897; xml: 1,440; sh: 1,313; php: 661; javascript: 257; makefile: 39
file content (157 lines) | stat: -rw-r--r-- 5,635 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
 * Copyright (C) 2009-2019 EiskaltDC++ developers
 *
 * 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 2 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 <https://www.gnu.org/licenses/>.
 */

#pragma once

#include "typedefs.h"
#include "Client.h"
#include "AdcCommand.h"
#include "Socket.h"
#ifdef LUA_SCRIPT
#include "ScriptManager.h"
#endif
namespace dcpp {

class ClientManager;
class AdcHub;

#ifdef LUA_SCRIPT
struct AdcScriptInstance : public ScriptInstance {
    bool onClientMessage(AdcHub* aClient, const string& aLine);
};
#endif
class AdcHub : public Client, public CommandHandler<AdcHub>
        #ifdef LUA_SCRIPT
        , public AdcScriptInstance
        #endif
{
public:
    using Client::send;
    using Client::connect;

    void connect(const OnlineUser& user, const string& token);
    void connect(const OnlineUser& user, string const& token, bool secure);

    virtual void hubMessage(const string& aMessage, bool thirdPerson = false);
    virtual void privateMessage(const OnlineUser& user, const string& aMessage, bool thirdPerson = false);
    virtual void sendUserCmd(const UserCommand& command, const ParamMap& params);
    virtual void search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken, const StringList& aExtList);
    virtual void password(const string& pwd);
    virtual void info(bool alwaysSend);

    virtual size_t getUserCount() const { Lock l(cs); return users.size(); }
    virtual int64_t getAvailable() const;

    static string escape(const string& str) { return AdcCommand::escape(str, false); }
    void emulateCommand(const string& cmd) { dispatch(cmd); }
    virtual void send(const AdcCommand& cmd);

    string getMySID() { return AdcCommand::fromSID(sid); }

    static const vector<StringList>& getSearchExts();
    static StringList parseSearchExts(int flag);

    static const string CLIENT_PROTOCOL;
    static const string SECURE_CLIENT_PROTOCOL_TEST;
    static const string ADCS_FEATURE;
    static const string TCP4_FEATURE;
    static const string UDP4_FEATURE;
    static const string NAT0_FEATURE;
    static const string SEGA_FEATURE;
    static const string BASE_SUPPORT;
    static const string BAS0_SUPPORT;
    static const string TIGR_SUPPORT;
    static const string UCM0_SUPPORT;
    static const string BLO0_SUPPORT;
    static const string ZLIF_SUPPORT;
#ifdef WITH_DHT
    static const string DHT0_SUPPORT;
#endif

private:
    friend class ClientManager;
    friend class CommandHandler<AdcHub>;
    friend class Identity;

    AdcHub(const string& aHubURL, bool secure);

    AdcHub(const AdcHub&);
    AdcHub& operator=(const AdcHub&);
    virtual ~AdcHub();

    /** Map session id to OnlineUser */
    typedef unordered_map<uint32_t, OnlineUser*> SIDMap;
    typedef SIDMap::iterator SIDIter;

    bool oldPassword;
    Socket udp;
    SIDMap users;
    StringMap lastInfoMap;
    mutable CriticalSection cs;

    string salt;
    uint32_t sid;

    std::unordered_set<uint32_t> forbiddenCommands;

    static const vector<StringList> searchExts;

    virtual string checkNick(const string& nick);

    OnlineUser& getUser(const uint32_t aSID, const CID& aCID);
    OnlineUser* findUser(const uint32_t sid) const;
    OnlineUser* findUser(const CID& cid) const;
    void putUser(const uint32_t sid, bool disconnect);

    void clearUsers();

    void handle(AdcCommand::SUP, AdcCommand& c) noexcept;
    void handle(AdcCommand::SID, AdcCommand& c) noexcept;
    void handle(AdcCommand::MSG, AdcCommand& c) noexcept;
    void handle(AdcCommand::INF, AdcCommand& c) noexcept;
    void handle(AdcCommand::GPA, AdcCommand& c) noexcept;
    void handle(AdcCommand::QUI, AdcCommand& c) noexcept;
    void handle(AdcCommand::CTM, AdcCommand& c) noexcept;
    void handle(AdcCommand::RCM, AdcCommand& c) noexcept;
    void handle(AdcCommand::STA, AdcCommand& c) noexcept;
    void handle(AdcCommand::SCH, AdcCommand& c) noexcept;
    void handle(AdcCommand::CMD, AdcCommand& c) noexcept;
    void handle(AdcCommand::RES, AdcCommand& c) noexcept;
    void handle(AdcCommand::GET, AdcCommand& c) noexcept;
    void handle(AdcCommand::PSR, AdcCommand& c) noexcept;
    void handle(AdcCommand::NAT, AdcCommand& c) noexcept;
    void handle(AdcCommand::RNT, AdcCommand& c) noexcept;
    void handle(AdcCommand::ZON, AdcCommand& c) noexcept;
    void handle(AdcCommand::ZOF, AdcCommand& c) noexcept;

    template<typename T> void handle(T, AdcCommand&) { }

    void sendSearch(AdcCommand& c);
    void sendUDP(const AdcCommand& cmd) noexcept;
    void unknownProtocol(uint32_t target, const string& protocol, const string& token);
    bool secureAvail(uint32_t target, const string& protocol, const string& token);
    virtual void on(Connecting) noexcept { fire(ClientListener::Connecting(), this); }
    virtual void on(Connected) noexcept;
    virtual void on(Line, const string& aLine) noexcept;
    virtual void on(Failed, const string& aLine) noexcept;

    virtual void on(Second, uint64_t aTick) noexcept;

};

} // namespace dcpp