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>
23 $Date: 2009/06/19 12:50:32 $
37 #include "stg/notifer.h"
38 #include "stg/user_ips.h"
39 #include "stg/users.h"
40 #include "stg/module_settings.h"
42 extern "C" PLUGIN * GetPlugin();
45 //-----------------------------------------------------------------------------
46 template <typename varParamType>
47 class CHG_BEFORE_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
49 CHG_BEFORE_NOTIFIER() : auth(NULL) {}
50 void Notify(const varParamType & oldValue, const varParamType & newValue);
51 void SetUser(USER_PTR u) { user = u; }
52 USER_PTR GetUser() {return user; }
53 void SetAuthorizator(const AUTH_STRESS * a) { auth = a; }
57 const AUTH_STRESS * auth;
59 //-----------------------------------------------------------------------------
60 template <typename varParamType>
61 class CHG_AFTER_NOTIFIER: public PROPERTY_NOTIFIER_BASE<varParamType> {
63 CHG_AFTER_NOTIFIER() : auth(NULL) {}
64 void Notify(const varParamType & oldValue, const varParamType & newValue);
65 void SetUser(USER_PTR u) { user = u; }
66 USER_PTR GetUser() {return user; }
67 void SetAuthorizator(const AUTH_STRESS * a) { auth = a; }
71 const AUTH_STRESS * auth;
73 //-----------------------------------------------------------------------------
74 class AUTH_STRESS_SETTINGS {
76 AUTH_STRESS_SETTINGS();
77 const std::string & GetStrError() const { return errorStr; }
78 int ParseSettings(const MODULE_SETTINGS & s);
79 int GetAverageOnlineTime() const;
81 int averageOnlineTime;
84 //-----------------------------------------------------------------------------
85 class AUTH_STRESS :public AUTH {
86 friend class CHG_BEFORE_NOTIFIER<USER_IPS>;
87 friend class CHG_AFTER_NOTIFIER<USER_IPS>;
90 virtual ~AUTH_STRESS() {}
92 void SetUsers(USERS * u);
96 int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
98 void SetSettings(const MODULE_SETTINGS & s);
100 const std::string & GetStrError() const;
101 const std::string GetVersion() const;
102 uint16_t GetStartPosition() const;
103 uint16_t GetStopPosition() const;
105 int SendMessage(const STG_MSG & msg, uint32_t ip) const;
109 void SetUserNotifiers(USER_PTR u);
110 void UnSetUserNotifiers(USER_PTR u);
112 void AddUser(USER_PTR u);
113 void DelUser(USER_PTR u);
115 void Authorize(USER_PTR u) const;
116 void Unauthorize(USER_PTR u) const;
118 static void * Run(void *);
122 mutable std::string errorStr;
123 AUTH_STRESS_SETTINGS stressSettings;
125 std::list<USER_PTR> usersList;
127 MODULE_SETTINGS settings;
130 pthread_mutex_t mutex;
132 std::list<CHG_BEFORE_NOTIFIER<USER_IPS> > BeforeChgIPNotifierList;
133 std::list<CHG_AFTER_NOTIFIER<USER_IPS> > AfterChgIPNotifierList;
135 class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
137 ADD_USER_NONIFIER() : auth(NULL) {}
138 virtual ~ADD_USER_NONIFIER() {}
140 void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
141 void Notify(const USER_PTR & user)
150 class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
152 DEL_USER_NONIFIER() : auth(NULL) {}
153 virtual ~DEL_USER_NONIFIER() {}
155 void SetAuthorizator(AUTH_STRESS * a) { auth = a; }
156 void Notify(const USER_PTR & user)
166 //-----------------------------------------------------------------------------