]> git.stg.codes - stg.git/blob - projects/stargazer/users.cpp
Добавление исходников
[stg.git] / projects / stargazer / users.cpp
1 /*
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.
6  *
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.
11  *
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
15  */
16
17 /*
18  *    Date: 27.10.2002
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23  */
24
25 /*
26  $Revision: 1.61 $
27  $Date: 2010/09/13 05:56:42 $
28  $Author: faust $
29  */
30
31 #ifndef _GNU_SOURCE
32 #define _GNU_SOURCE
33 #endif
34
35 #include <pthread.h>
36 #include <csignal>
37 #include <cassert>
38 #include <algorithm>
39 #include <utility>
40 #include <string>
41 #include <vector>
42
43 #include "settings.h"
44 #include "users.h"
45 #include "user.h"
46 #include "common.h"
47 #include "stg_timer.h"
48
49 using namespace std;
50
51 extern const volatile time_t stgTime;
52
53 //#define USERS_DEBUG 1
54
55 //-----------------------------------------------------------------------------
56 USERS::USERS(SETTINGS * s, BASE_STORE * st, TARIFFS * t, const ADMIN & sa)
57     : users(),
58       usersToDelete(),
59       userIPNotifiersBefore(),
60       userIPNotifiersAfter(),
61       ipIndex(),
62       loginIndex(),
63       settings(s),
64       tariffs(t),
65       store(st),
66       sysAdmin(sa),
67       WriteServLog(GetStgLogger()),
68       nonstop(false),
69       isRunning(false),
70       mutex(),
71       thread(),
72       handle(0),
73       searchDescriptors(),
74       onAddNotifiers(),
75       onDelNotifiers()
76 {
77 pthread_mutexattr_t attr;
78 pthread_mutexattr_init(&attr);
79 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
80 pthread_mutex_init(&mutex, &attr);
81 }
82 //-----------------------------------------------------------------------------
83 USERS::~USERS()
84 {
85 pthread_mutex_destroy(&mutex);
86 }
87 //-----------------------------------------------------------------------------
88 int USERS::FindByNameNonLock(const string & login, user_iter * user) const
89 {
90 map<string, user_iter>::const_iterator iter;
91 iter = loginIndex.find(login);
92 if (iter != loginIndex.end())
93     {
94     if (user)
95         *user = iter->second;
96     return 0;
97     }
98 return -1;
99 }
100 //-----------------------------------------------------------------------------
101 int USERS::FindByName(const string & login, user_iter * user) const
102 {
103 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
104 return FindByNameNonLock(login, user);
105 }
106 //-----------------------------------------------------------------------------
107 bool USERS::TariffInUse(const string & tariffName)
108 {
109 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
110 list<USER>::iterator iter;
111 iter = users.begin();
112 while (iter != users.end())
113     {
114     if (iter->property.tariffName.Get() == tariffName)
115         return true;
116     ++iter;
117     }
118 return false;
119 }
120 //-----------------------------------------------------------------------------
121 int USERS::Add(const string & login, const ADMIN & admin)
122 {
123 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
124 const PRIV * priv = admin.GetPriv();
125
126 if (!priv->userAddDel)
127     {
128     WriteServLog("%s tried to add user \'%s\'. Access denied.",
129          admin.GetLogStr().c_str(), login.c_str());
130     /*errorStr = "Admin \'" + admin.GetLogin() +
131                "\': tried to add user \'" + ud->login + "\'. Access denied.";*/
132     return -1;
133     }
134
135 //////
136 if (store->AddUser(login))
137     {
138     //TODO
139     //WriteServLog("Admin \'%s\': tried to add user \'%s\'. Access denied.",
140     //     admin.GetLogin().c_str(), ud->login.c_str());
141     return -1;
142     }
143 //////
144
145 USER u(settings, store, tariffs, sysAdmin, &ipIndex);
146
147 struct tm * tms;
148 time_t t = stgTime;
149
150 tms = localtime(&t);
151
152 tms->tm_hour = 0;
153 tms->tm_min = 0;
154 tms->tm_sec = 0;
155
156 if (settings->GetDayResetTraff() > tms->tm_mday)
157     tms->tm_mon -= 1;
158
159 tms->tm_mday = settings->GetDayResetTraff();
160
161 u.SetLogin(login);
162
163 u.SetPassiveTimeAsNewUser();
164
165 u.WriteConf();
166 u.WriteStat();
167
168 WriteServLog("%s User \'%s\' added.",
169          admin.GetLogStr().c_str(), login.c_str());
170
171 u.OnAdd();
172
173 users.push_front(u);
174
175 AddUserIntoIndexes(users.begin());
176 SetUserNotifiers(users.begin());
177
178 // õ×ÅÄÏÍÌÑÅÍ ×ÓÅÈ ÖÅÌÁÀÝÉÈ, ÞÔÏ ÄÏÂÁ×ÌÅΠÎÏ×ÙÊ ÐÏÌØÚÏ×ÁÔÅÌØ
179 set<NOTIFIER_BASE<user_iter> *>::iterator ni = onAddNotifiers.begin();
180 while (ni != onAddNotifiers.end())
181     {
182     (*ni)->Notify(users.begin());
183     ++ni;
184     }
185
186 return 0;
187 }
188 //-----------------------------------------------------------------------------
189 void USERS::Del(const string & login, const ADMIN & admin)
190 {
191 const PRIV * priv = admin.GetPriv();
192 user_iter u;
193
194 if (!priv->userAddDel)
195     {
196     WriteServLog("%s tried to remove user \'%s\'. Access denied.",
197          admin.GetLogStr().c_str(), login.c_str());
198     return;
199     }
200
201
202     {
203     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
204
205     if (FindByNameNonLock(login, &u))
206         {
207         WriteServLog("%s tried to delete user \'%s\': not found.",
208                      admin.GetLogStr().c_str(),
209                      login.c_str());
210         return;
211         }
212     }
213
214 set<NOTIFIER_BASE<user_iter> *>::iterator ni = onDelNotifiers.begin();
215 while (ni != onDelNotifiers.end())
216     {
217     (*ni)->Notify(u);
218     ++ni;
219     }
220
221     {
222     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
223
224     u->OnDelete();
225     u->SetDeleted();
226
227     USER_TO_DEL utd;
228     utd.iter = u;
229     utd.delTime = stgTime;
230     usersToDelete.push_back(utd);
231
232     UnSetUserNotifiers(u);
233     DelUserFromIndexes(u);
234
235     WriteServLog("%s User \'%s\' deleted.",
236              admin.GetLogStr().c_str(), login.c_str());
237
238     }
239 }
240 //-----------------------------------------------------------------------------
241 int USERS::ReadUsers()
242 {
243 vector<string> usersList;
244 usersList.clear();
245 if (store->GetUsersList(&usersList) < 0)
246     {
247     WriteServLog(store->GetStrError().c_str());
248     exit(1);
249     }
250
251 user_iter ui;
252
253 for (unsigned int i = 0; i < usersList.size(); i++)
254     {
255     USER u(settings, store, tariffs, sysAdmin, &ipIndex);
256
257     u.SetLogin(usersList[i]);
258     users.push_front(u);
259     ui = users.begin();
260
261     AddUserIntoIndexes(ui);
262     SetUserNotifiers(ui);
263
264     if (ui->ReadConf() < 0)
265         return -1;
266
267     if (ui->ReadStat() < 0)
268         return -1;
269     }
270
271 return 0;
272 }
273 //-----------------------------------------------------------------------------
274 void * USERS::Run(void * d)
275 {
276 printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
277 USERS * us = (USERS*) d;
278
279 struct tm * t;
280 time_t tt = stgTime;
281 t = localtime(&tt);
282
283 int min = t->tm_min;
284 int day = t->tm_mday;
285
286 printfd(__FILE__,"Day = %d Min = %d\n", day, min);
287
288 time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC;
289 string monFile = us->settings->GetMonitorDir() + "/users_r";
290 printfd(__FILE__, "Monitor=%d file USERS %s\n", us->settings->GetMonitoring(), monFile.c_str());
291
292 us->isRunning = true;
293 while (us->nonstop)
294     {
295     //printfd(__FILE__,"New Minute. old = %02d current = %02d\n", min, t->tm_min);
296     //printfd(__FILE__,"New Day.    old = %2d current = %2d\n", day, t->tm_mday);
297
298     for_each(us->users.begin(), us->users.end(), mem_fun_ref(&USER::Run));
299
300     tt = stgTime;
301     t = localtime(&tt);
302
303     if (min != t->tm_min)
304         {
305         printfd(__FILE__,"Sec = %d\n", stgTime);
306         printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t->tm_min);
307         min = t->tm_min;
308
309         us->NewMinute(t);
310         }
311
312     t = localtime(&tt);
313     if (day != t->tm_mday)
314         {
315         printfd(__FILE__,"Sec = %d\n", stgTime);
316         printfd(__FILE__,"New Day. old = %d current = %d\n", day, t->tm_mday);
317         day = t->tm_mday;
318         us->NewDay(t);
319         }
320
321     if (us->settings->GetMonitoring() && (touchTime + MONITOR_TIME_DELAY_SEC <= stgTime))
322         {
323         //printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", tc->monitoring, monFile.c_str());
324         touchTime = stgTime;
325         TouchFile(monFile.c_str());
326         }
327
328     stgUsleep(100000);
329     } //while (us->nonstop)
330
331 user_iter ui = us->users.begin();
332 while (ui != us->users.end())
333     {
334     us->UnSetUserNotifiers(ui);
335     us->DelUserFromIndexes(ui);
336     ui++;
337     }
338
339 list<USER_TO_DEL>::iterator iter;
340 iter = us->usersToDelete.begin();
341 while (iter != us->usersToDelete.end())
342     {
343     iter->delTime -= 2 * userDeleteDelayTime;
344     ++iter;
345     }
346 us->RealDelUser();
347
348 us->isRunning = false;
349
350 return NULL;
351 }
352 //-----------------------------------------------------------------------------
353 void USERS::NewMinute(const struct tm * t)
354 {
355 int usersCnt = 0;
356 list<USER>::iterator usr;
357
358 //Write traff, reset session traff. Fake disconnect-connect
359 if (t->tm_hour == 23 && t->tm_min == 59)
360     {
361     printfd(__FILE__,"MidnightResetSessionStat\n");
362     for_each(users.begin(), users.end(), mem_fun_ref(&USER::MidnightResetSessionStat));
363     }
364
365 if (TimeToWriteDetailStat(t))
366     {
367     //printfd(__FILE__, "USER::WriteInetStat\n");
368     for_each(users.begin(), users.end(), mem_fun_ref(&USER::SwapDetailStat));
369     usersCnt = 0;
370
371     // ðÉÛÅÍ ÀÚÅÒÏ× ÞÁÓÔÑÍÉ. ÷ ÐÅÒÅÒÙ×ÁÈ ×ÙÚÙ×ÁÅÍ USER::Run
372     usr = users.begin();
373     while (usr != users.end())
374         {
375         usersCnt++;
376         usr->WriteDetailStat();
377         usr++;
378         if (usersCnt % 10 == 0)
379             for_each(users.begin(), users.end(), mem_fun_ref(&USER::Run));
380         }
381
382     for_each(users.begin(), users.end(), mem_fun_ref(&USER::ResetDetailStat));
383     }
384
385 RealDelUser();
386 }
387 //-----------------------------------------------------------------------------
388 void USERS::NewDay(const struct tm * t)
389 {
390 struct tm * t1;
391 time_t tt = stgTime;
392 t1 = localtime(&tt);
393 int dayFee = settings->GetDayFee();
394
395 if (dayFee == 0)
396     dayFee = DaysInCurrentMonth();
397
398 printfd(__FILE__, "DayFee = %d\n", dayFee);
399 printfd(__FILE__, "Today = %d DayResetTraff = %d\n", t1->tm_mday, settings->GetDayResetTraff());
400 printfd(__FILE__, "DayFeeIsLastDay = %d\n", settings->GetDayFeeIsLastDay());
401
402 if (!settings->GetDayFeeIsLastDay())
403     {
404     printfd(__FILE__, "DayResetTraff - 1 -\n");
405     DayResetTraff(t1);
406     //printfd(__FILE__, "DayResetTraff - 1 - 1 -\n");
407     }
408
409 if (settings->GetSpreadFee())
410     {
411     printfd(__FILE__, "Spread DayFee\n");
412     for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessDayFeeSpread));
413     }
414 else
415     {
416     if (t->tm_mday == dayFee)
417         {
418         printfd(__FILE__, "DayFee\n");
419         for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessDayFee));
420         }
421     }
422
423 if (settings->GetDayFeeIsLastDay())
424     {
425     printfd(__FILE__, "DayResetTraff - 2 -\n");
426     DayResetTraff(t1);
427     }
428 }
429 //-----------------------------------------------------------------------------
430 void USERS::DayResetTraff(const struct tm * t1)
431 {
432 int dayResetTraff = settings->GetDayResetTraff();
433 if (dayResetTraff == 0)
434     dayResetTraff = DaysInCurrentMonth();
435 if (t1->tm_mday == dayResetTraff)
436     {
437     printfd(__FILE__, "ResetTraff\n");
438     for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessNewMonth));
439     for_each(users.begin(), users.end(), mem_fun_ref(&USER::SetPrepaidTraff));
440     }
441 }
442 //-----------------------------------------------------------------------------
443 int USERS::Start()
444 {
445 if (ReadUsers())
446     {
447     WriteServLog("USERS: Error: Cannot read users!");
448     return -1;
449     }
450
451 nonstop = true;
452 if (pthread_create(&thread, NULL, Run, this))
453     {
454     WriteServLog("USERS: Error: Cannot start thread!");
455     return -1;
456     }
457 return 0;
458 }
459 //-----------------------------------------------------------------------------
460 int USERS::Stop()
461 {
462 printfd(__FILE__, "USERS::Stop()\n");
463
464 if (!isRunning)
465     {
466     //printfd(__FILE__, "Alredy stopped\n");
467     return 0;
468     }
469
470 nonstop = false;
471
472 //5 seconds to thread stops itself
473 unsigned i;
474 for (i = 0; i < 25 * (users.size() / 50 + 1); i++)
475     {
476     if (!isRunning)
477         break;
478
479     usleep(200000);
480     }
481
482 //after 5 seconds waiting thread still running. now kill it
483 if (isRunning)
484     {
485     printfd(__FILE__, "kill USERS thread.\n");
486     //TODO pthread_cancel()
487     if (pthread_kill(thread, SIGINT))
488         {
489         //errorStr = "Cannot kill USERS thread.";
490         //printfd(__FILE__, "Cannot kill USERS thread.\n");
491         //return 0;
492         }
493     printfd(__FILE__, "USERS killed\n");
494     }
495
496 printfd(__FILE__, "Before USERS::Run()\n");
497 for_each(users.begin(), users.end(), mem_fun_ref(&USER::Run));
498 for_each(users.begin(), users.end(), mem_fun_ref(&USER::SwapDetailStat));
499 for_each(users.begin(), users.end(), mem_fun_ref(&USER::WriteDetailStat));
500 for_each(users.begin(), users.end(), mem_fun_ref(&USER::WriteStat));
501 for_each(users.begin(), users.end(), mem_fun_ref(&USER::WriteConf));
502
503 printfd(__FILE__, "USERS::Stop()\n");
504 return 0;
505 }
506 //-----------------------------------------------------------------------------
507 void USERS::RealDelUser()
508 {
509 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
510
511 printfd(__FILE__, "RealDelUser() users to del: %d\n", usersToDelete.size());
512
513 list<USER_TO_DEL>::iterator iter;
514 iter = usersToDelete.begin();
515 while (iter != usersToDelete.end())
516     {
517     printfd(__FILE__, "RealDelUser() user=%s\n", iter->iter->GetLogin().c_str());
518     if (iter->delTime + userDeleteDelayTime < stgTime)
519         {
520         printfd(__FILE__, "RealDelUser() user=%s removed from DB\n", iter->iter->GetLogin().c_str());
521         if (store->DelUser(iter->iter->GetLogin()))
522             {
523             WriteServLog("Error removing user \'%s\' from database.", iter->iter->GetLogin().c_str());
524             }
525         users.erase(iter->iter);
526         usersToDelete.erase(iter++);
527         }
528     else
529         {
530         ++iter;
531         }
532     }
533 return;
534 }
535 //-----------------------------------------------------------------------------
536 int USERS::GetUserNum()
537 {
538 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
539 return users.size();
540 }
541 //-----------------------------------------------------------------------------
542 void USERS::AddToIPIdx(user_iter user)
543 {
544 printfd(__FILE__, "USERS: Add IP Idx\n");
545 uint32_t ip = user->GetCurrIP();
546 //assert(ip && "User has non-null ip");
547 if (!ip)
548     return; // User has disconnected
549
550 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
551
552 const map<uint32_t, user_iter>::iterator it(
553         ipIndex.lower_bound(ip)
554 );
555
556 assert((it == ipIndex.end() || it->first != ip) && "User is not in index");
557
558 ipIndex.insert(it, std::make_pair(ip, user));
559 }
560 //-----------------------------------------------------------------------------
561 void USERS::DelFromIPIdx(uint32_t ip)
562 {
563 printfd(__FILE__, "USERS: Del IP Idx\n");
564 assert(ip && "User has non-null ip");
565
566 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
567
568 const map<uint32_t, user_iter>::iterator it(
569         ipIndex.find(ip)
570 );
571
572 //assert(it != ipIndex.end() && "User is in index");
573 if (it == ipIndex.end())
574     return; // User has not been added
575
576 ipIndex.erase(it);
577 }
578 //-----------------------------------------------------------------------------
579 int USERS::FindByIPIdx(uint32_t ip, user_iter * usr)
580 {
581 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
582
583 map<uint32_t, user_iter>::iterator it;
584 it = ipIndex.find(ip);
585
586 if (it == ipIndex.end())
587     {
588     //printfd(__FILE__, "User NOT found in IP_Index!!!\n");
589     return -1;
590     }
591 *usr = it->second;
592 //printfd(__FILE__, "User found in IP_Index\n");
593 return 0;
594 }
595 //-----------------------------------------------------------------------------
596 void USERS::AddNotifierUserAdd(NOTIFIER_BASE<user_iter> * n)
597 {
598 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
599 onAddNotifiers.insert(n);
600 }
601 //-----------------------------------------------------------------------------
602 void USERS::DelNotifierUserAdd(NOTIFIER_BASE<user_iter> * n)
603 {
604 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
605 //printfd(__FILE__, "DelNotifierUserAdd\n");
606 onAddNotifiers.erase(n);
607 }
608 //-----------------------------------------------------------------------------
609 void USERS::AddNotifierUserDel(NOTIFIER_BASE<user_iter> * n)
610 {
611 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
612 onDelNotifiers.insert(n);
613 }
614 //-----------------------------------------------------------------------------
615 void USERS::DelNotifierUserDel(NOTIFIER_BASE<user_iter> * n)
616 {
617 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
618 onDelNotifiers.erase(n);
619 }
620 //-----------------------------------------------------------------------------
621 int USERS::OpenSearch()
622 {
623 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
624 handle++;
625 searchDescriptors[handle] = users.begin();
626 return handle;
627 }
628 //-----------------------------------------------------------------------------
629 int USERS::SearchNext(int h, user_iter * u)
630 {
631 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
632
633 if (searchDescriptors.find(h) == searchDescriptors.end())
634     {
635     WriteServLog("USERS. Incorrect search handle.");
636     return -1;
637     }
638
639 if (searchDescriptors[h] == users.end())
640     return -1;
641
642 while (searchDescriptors[h]->GetDeleted())
643     {
644     ++searchDescriptors[h];
645     if (searchDescriptors[h] == users.end())
646         {
647         return -1;
648         }
649     }
650
651 *u = searchDescriptors[h];
652
653 ++searchDescriptors[h];
654
655 return 0;
656 }
657 //-----------------------------------------------------------------------------
658 int USERS::CloseSearch(int h)
659 {
660 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
661 if (searchDescriptors.find(h) != searchDescriptors.end())
662     {
663     searchDescriptors.erase(searchDescriptors.find(h));
664     return 0;
665     }
666
667 WriteServLog("USERS. Incorrect search handle.");
668 return -1;
669 }
670 //-----------------------------------------------------------------------------
671 void USERS::SetUserNotifiers(user_iter user)
672 {
673 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
674
675 PROPERTY_NOTIFER_IP_BEFORE nb(*this, user);
676 PROPERTY_NOTIFER_IP_AFTER  na(*this, user);
677
678 userIPNotifiersBefore.push_front(nb);
679 userIPNotifiersAfter.push_front(na);
680
681 user->AddCurrIPBeforeNotifier(&(*userIPNotifiersBefore.begin()));
682 user->AddCurrIPAfterNotifier(&(*userIPNotifiersAfter.begin()));
683 }
684 //-----------------------------------------------------------------------------
685 void USERS::UnSetUserNotifiers(user_iter user)
686 {
687 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
688
689 list<PROPERTY_NOTIFER_IP_BEFORE>::iterator  bi;
690 list<PROPERTY_NOTIFER_IP_AFTER>::iterator   ai;
691
692 bi = userIPNotifiersBefore.begin();
693 while (bi != userIPNotifiersBefore.end())
694     {
695     if (bi->GetUser() == user)
696         {
697         bi->GetUser()->DelCurrIPBeforeNotifier(&(*bi));
698         userIPNotifiersBefore.erase(bi);
699         //printfd(__FILE__, "Notifier Before removed. User %s\n", bi->GetUser()->GetLogin().c_str());
700         break;
701         }
702     bi++;
703     }
704
705 ai = userIPNotifiersAfter.begin();
706 while (ai != userIPNotifiersAfter.end())
707     {
708     if (ai->GetUser() == user)
709         {
710         ai->GetUser()->DelCurrIPAfterNotifier(&(*ai));
711         userIPNotifiersAfter.erase(ai);
712         //printfd(__FILE__, "Notifier After removed. User %s\n", ai->GetUser()->GetLogin().c_str());
713         break;
714         }
715     ai++;
716     }
717 }
718 //-----------------------------------------------------------------------------
719 void USERS::AddUserIntoIndexes(user_iter user)
720 {
721 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
722 loginIndex.insert(pair<string, user_iter>(user->GetLogin(), user));
723 }
724 //-----------------------------------------------------------------------------
725 void USERS::DelUserFromIndexes(user_iter user)
726 {
727 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
728 loginIndex.erase(user->GetLogin());
729 }
730 //-----------------------------------------------------------------------------
731 bool USERS::TimeToWriteDetailStat(const struct tm * t)
732 {
733 int statTime = settings->GetDetailStatWritePeriod();
734
735 switch (statTime)
736     {
737     case dsPeriod_1:
738         if (t->tm_min == 0)
739             return true;
740         break;
741     case dsPeriod_1_2:
742         if (t->tm_min % 30 == 0)
743             return true;
744         break;
745     case dsPeriod_1_4:
746         if (t->tm_min % 15 == 0)
747             return true;
748         break;
749     case dsPeriod_1_6:
750         if (t->tm_min % 10 == 0)
751             return true;
752         break;
753     }
754 return false;
755 }
756 //-----------------------------------------------------------------------------
757 /*int USERS::SendMessage(const string & login,
758                        time_t sndTtime,
759                        time_t showTime,
760                        char type,
761                        const string & text) const
762 {
763 return 0;
764 }*/
765 //-----------------------------------------------------------------------------
766
767
768