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 : Maxim Mamontov <faust@stargazer.dp.ua>
25 #include "stg/common.h"
35 class UpdateRouter : public std::unary_function<std::pair<const uint32_t, RS::USER>, void>
38 explicit UpdateRouter(REMOTE_SCRIPT & t)
41 void operator() (std::pair<const uint32_t, USER> & val)
43 std::vector<uint32_t> newRouters = obj.IP2Routers(val.second.ip);
44 std::vector<uint32_t>::const_iterator oldIt(val.second.routers.begin());
45 std::vector<uint32_t>::const_iterator newIt(newRouters.begin());
46 val.second.shortPacketsCount = 0;
47 while (oldIt != val.second.routers.end() ||
48 newIt != newRouters.end())
50 if (oldIt == val.second.routers.end())
52 if (newIt != newRouters.end())
54 obj.SendDirect(val.second, *newIt); // Connect on new router
58 else if (newIt == newRouters.end())
60 obj.SendDirect(val.second, *oldIt, true); // Disconnect on old router
63 else if (*oldIt < *newIt)
65 obj.SendDirect(val.second, *oldIt, true); // Disconnect on old router
68 else if (*oldIt > *newIt)
70 obj.SendDirect(val.second, *newIt); // Connect on new router
76 if (newIt != newRouters.end())
80 val.second.routers = newRouters;