Debian Codegraph @

src/bnetd/watch.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 1999,2000 Ross Combs ([email protected])
3 * Copyright (C) 2005 Dizzy
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
20 #include "watch.h"cxx . . $ `<file>/src/bnetd/watch.h`/
21 #include "common/field_sizes.h"cxx . . $ `<file>/src/common/field_sizes.h`/
22 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
23 #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/
24 #include "message.h"cxx . . $ `<file>/src/bnetd/message.h`/
25 #include "friends.h"cxx . . $ `<file>/src/bnetd/friends.h`/
26 #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/
27 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
28
29
30 namespace pvpgncxx . . $ pvpgn/
31 {
32
33 namespace bnetdcxx . . $ pvpgn/bnetd/
34 {
35
36 scoped_ptrcxx . . $ pvpgn/scoped_ptr#<WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#> watchlistcxx . . $ pvpgn/bnetd/watchlist.;
37
38 Watchcxx . . $ pvpgn/bnetd/Watch#::Watchcxx . . $ pvpgn/bnetd/Watch#Watch(3ec15225d867d3da).(t_connection* owner_, t_accountcxx . . $ pvpgn/bnetd/t_account#* who_, unsigned what_, t_clienttagcxx . . $ pvpgn/t_clienttag# ctag_)
39 :ownercxx . . $ pvpgn/bnetd/Watch#owner.(owner_), whocxx . . $ pvpgn/bnetd/Watch#who.(who_), whatcxx . . $ pvpgn/bnetd/Watch#what.(what_), ctagcxx . . $ pvpgn/bnetd/Watch#ctag.(ctag_)
40 {
41 }
42
43 Watchcxx . . $ pvpgn/bnetd/Watch#::~cxx . . $ pvpgn/bnetd/Watch#`~Watch`(ced63f7c635d850d).Watchcxx . . $ pvpgn/bnetd/Watch#() throw()
44 {
45 }
46
47 t_connection*
48 Watchcxx . . $ pvpgn/bnetd/Watch#::getOwnercxx . . $ pvpgn/bnetd/Watch#getOwner(ee9430605b44e25e).() const
49 {
50 return ownercxx . . $ pvpgn/bnetd/Watch#owner.;
51 }
52
53 t_accountcxx . . $ pvpgn/bnetd/t_account#*
54 Watchcxx . . $ pvpgn/bnetd/Watch#::getAccountcxx . . $ pvpgn/bnetd/Watch#getAccount(bd50dfe41cbbfab3).() const
55 {
56 return whocxx . . $ pvpgn/bnetd/Watch#who.;
57 }
58
59 unsigned
60 Watchcxx . . $ pvpgn/bnetd/Watch#::getEventMaskcxx . . $ pvpgn/bnetd/Watch#getEventMask(ddd8539a2fcdd4ce).() const
61 {
62 return whatcxx . . $ pvpgn/bnetd/Watch#what.;
63 }
64
65 t_clienttagcxx . . $ pvpgn/t_clienttag#
66 Watchcxx . . $ pvpgn/bnetd/Watch#::getClientTagcxx . . $ pvpgn/bnetd/Watch#getClientTag(ddd8539a2fcdd4ce).() const
67 {
68 return ctagcxx . . $ pvpgn/bnetd/Watch#ctag.;
69 }
70
71 void
72 Watchcxx . . $ pvpgn/bnetd/Watch#::setEventMaskcxx . . $ pvpgn/bnetd/Watch#setEventMask(cb2f890c2fdad230).(unsigned what_)
73 {
74 whatcxx . . $ pvpgn/bnetd/Watch#what. = what_;
75 }
76
77 /* who == NULL means anybody */
78 void
79 WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#::addcxx . . $ pvpgn/bnetd/WatchComponent#add(3ec15225d867d3da).(t_connection * owner, t_accountcxx . . $ pvpgn/bnetd/t_account# * who, t_clienttagcxx . . $ pvpgn/t_clienttag# clienttag, unsigned events)
80 {
81 for (WatchListcxx . . $ pvpgn/bnetd/WatchComponent#WatchList#::iteratorcxx . . $ std/__cxx11/list#iterator# it(wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).()); it !=cxx . . $ std/`operator!=`(2ff7fa6cf5bdfcad). wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).(); ++cxx . . $ std/_List_iterator#operator++(70483be15bedaca0).it)
82 {
83 if (owner == it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getOwnercxx . . $ pvpgn/bnetd/Watch#getOwner(ee9430605b44e25e).() && who == it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getAccountcxx . . $ pvpgn/bnetd/Watch#getAccount(bd50dfe41cbbfab3).() && clienttag == it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getClientTagcxx . . $ pvpgn/bnetd/Watch#getClientTag(ddd8539a2fcdd4ce).())
84 {
85 it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).setEventMaskcxx . . $ pvpgn/bnetd/Watch#setEventMask(cb2f890c2fdad230).(it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getEventMaskcxx . . $ pvpgn/bnetd/Watch#getEventMask(ddd8539a2fcdd4ce).() | events);
86 return;
87 }
88 }
89
90 wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..push_backcxx . . $ std/__cxx11/list#push_back(fe7a8a4d1eddb70).(Watchcxx . . $ pvpgn/bnetd/Watch#Watch(3ec15225d867d3da).(owner, who, events, clienttag));
91 }
92
93
94 /* who == NULL means anybody */
95 int
96 WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#::delcxx . . $ pvpgn/bnetd/WatchComponent#del(4da098f4e89597b2).(t_connection * owner, t_accountcxx . . $ pvpgn/bnetd/t_account# * who, t_clienttagcxx . . $ pvpgn/t_clienttag# clienttag, unsigned events)
97 {
98 for (WatchListcxx . . $ pvpgn/bnetd/WatchComponent#WatchList#::iteratorcxx . . $ std/__cxx11/list#iterator# it(wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).()); it !=cxx . . $ std/`operator!=`(2ff7fa6cf5bdfcad). wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).(); ++cxx . . $ std/_List_iterator#operator++(70483be15bedaca0).it)
99 {
100 if (owner == it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getOwnercxx . . $ pvpgn/bnetd/Watch#getOwner(ee9430605b44e25e).() && who == it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getAccountcxx . . $ pvpgn/bnetd/Watch#getAccount(bd50dfe41cbbfab3).() && (!clienttag || clienttag == it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getClientTagcxx . . $ pvpgn/bnetd/Watch#getClientTag(ddd8539a2fcdd4ce).()))
101 {
102 unsigned evmask = it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getEventMaskcxx . . $ pvpgn/bnetd/Watch#getEventMask(ddd8539a2fcdd4ce).() & (~events);
103 if (!evmask) wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..erasecxx . . $ std/__cxx11/list#erase(aceec42672b9127f).(itcxx . . $ std/_List_const_iterator#_List_const_iterator(2c469dd624388c9f).);
104 else it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).setEventMaskcxx . . $ pvpgn/bnetd/Watch#setEventMask(cb2f890c2fdad230).(evmask);
105 return 0;
106 }
107 }
108
109 return -1;
110 }
111
112
113 /* this differs from del_events because it doesn't return an error if nothing was found */
114 void
115 WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#::delcxx . . $ pvpgn/bnetd/WatchComponent#del(428cd989165da3c5).(t_connection * owner)
116 {
117 for (WatchListcxx . . $ pvpgn/bnetd/WatchComponent#WatchList#::iteratorcxx . . $ std/__cxx11/list#iterator# it(wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..begincxx . . $ std/__cxx11/list#begin(57ce810e58fbcab0).()); it !=cxx . . $ std/`operator!=`(2ff7fa6cf5bdfcad). wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..endcxx . . $ std/__cxx11/list#end(57ce810e58fbcab0).();)
118 {
119 if (owner == it->cxx . . $ std/_List_iterator#`operator->`(34d6acfd341ba7ab).getOwnercxx . . $ pvpgn/bnetd/Watch#getOwner(ee9430605b44e25e).())
120 it =cxx . . $ std/_List_iterator#`operator=`(63b4a3b6306efdcf). wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..erasecxx . . $ std/__cxx11/list#erase(aceec42672b9127f).(itcxx . . $ std/_List_const_iterator#_List_const_iterator(2c469dd624388c9f).);
121 else ++cxx . . $ std/_List_iterator#operator++(70483be15bedaca0).it;
122 }
123 }
124
125 int
126 WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#::dispatch_whispercxx . . $ pvpgn/bnetd/WatchComponent#dispatch_whisper(5f92e2dc3f12ba14).(t_accountcxx . . $ pvpgn/bnetd/t_account# *account, char const *gamename, t_clienttagcxx . . $ pvpgn/t_clienttag# clienttag, Watchcxx . . $ pvpgn/bnetd/Watch#::EventTypecxx . . $ pvpgn/bnetd/Watch#EventType# event) const
127 {
128 t_elem const * curr;
129 char msg[512];
130 int cnt = 0;
131 char const *myusername;
132 t_list * flist;
133 t_connection * dest_c, *my_c;
134 t_friendcxx . . $ pvpgn/bnetd/t_friend# * fr;
135 char const * game_title;
136
137 if (!(myusername = account_get_namecxx . . $ `src/bnetd/account.h:115:10`!(account)))
138 {
139 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL account name");
140 return -1;
141 }
142
143 my_c = account_get_conncxx . . $ pvpgn/bnetd/account_get_conn(831fe2ed2f0bd703).(account);
144
145 game_title = clienttag_get_titlecxx . . $ pvpgn/clienttag_get_title(81a3ae90da26a711).(clienttag);
146
147 /* mutual friends handling */
148 flist = account_get_friendscxx . . $ pvpgn/bnetd/account_get_friends(27f2e57ffe21264).(account);
149 if (flist)
150 {
151 switch (event)
152 {
153 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_joingamecxx . . $ pvpgn/bnetd/Watch#ET_joingame.:
154 if (gamename)
155 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Your friend %s has entered a %s game named \"%s\".", myusername, game_title, gamename);
156 else
157 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Your friend %s has entered a %s game", myusername, game_title);
158 break;
159 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_leavegamecxx . . $ pvpgn/bnetd/Watch#ET_leavegame.:
160 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Your friend %s has left a %s game.", myusername, game_title);
161 break;
162 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_logincxx . . $ pvpgn/bnetd/Watch#ET_login.:
163 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Your friend %s has entered %s.", myusername, prefs_get_servernamecxx . . $ pvpgn/bnetd/prefs_get_servername(33a1f659e94feb42).());
164 break;
165 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_logoutcxx . . $ pvpgn/bnetd/Watch#ET_logout.:
166 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Your friend %s has left %s.", myusername, prefs_get_servernamecxx . . $ pvpgn/bnetd/prefs_get_servername(33a1f659e94feb42).());
167 break;
168 }
169 LIST_TRAVERSEcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/list.h:94:9`!(flist, curr)
170 {
171 if (!(fr = (t_friendcxx . . $ pvpgn/bnetd/t_friend#*)elem_get_data(curr)))
172 {
173 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("found NULL entry in list");
174 continue;
175 }
176
177 dest_c = connlist_find_connection_by_accountcxx . . $ pvpgn/bnetd/connlist_find_connection_by_account(831fe2ed2f0bd703).(fr->friendacccxx . . $ pvpgn/bnetd/friend_struct#friendacc.);
178
179 if (dest_c == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) /* If friend is offline, go on to next */
180 continue;
181 else {
182 cnt++; /* keep track of successful whispers */
183 if (friend_get_mutualcxx . . $ pvpgn/bnetd/friend_get_mutual(1bd0d6ddce271d17).(fr))
184 message_send_textcxx . . $ pvpgn/bnetd/message_send_text(61daf7e3ba1862c4).(dest_c, message_type_whispercxx . . $ pvpgn/bnetd/message_type_whisper., my_c, msg);
185 }
186 }
187 }
188
189 if (cnt) DEBUG2cxx . . $ `src/common/eventlog.h:90:9`!("notified {} friends about {}", cnt, myusername);
190
191 /* watchlist handling */
192 switch (event)
193 {
194 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_joingamecxx . . $ pvpgn/bnetd/Watch#ET_joingame.:
195 if (gamename)
196 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Watched user %s has entered a %s game named \"%s\".", myusername, game_title, gamename);
197 else
198 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Watched user %s has entered a %s game", myusername, game_title);
199 break;
200 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_leavegamecxx . . $ pvpgn/bnetd/Watch#ET_leavegame.:
201 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Watched user %s has left a %s game.", myusername, game_title);
202 break;
203 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_logincxx . . $ pvpgn/bnetd/Watch#ET_login.:
204 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Watched user %s has entered %s.", myusername, prefs_get_servernamecxx . . $ pvpgn/bnetd/prefs_get_servername(33a1f659e94feb42).());
205 break;
206 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_logoutcxx . . $ pvpgn/bnetd/Watch#ET_logout.:
207 stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(msg, sizeof(msg), "Watched user %s has left %s", myusername, prefs_get_servernamecxx . . $ pvpgn/bnetd/prefs_get_servername(33a1f659e94feb42).());
208 break;
209 }
210
211 for (WatchListcxx . . $ pvpgn/bnetd/WatchComponent#WatchList#::const_iteratorcxx . . $ std/__cxx11/list#const_iterator# it(wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..begincxx . . $ std/__cxx11/list#begin(9afe7339530a999).()); it !=cxx . . $ std/`operator!=`(1e6c2fe662e4ed08). wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist..endcxx . . $ std/__cxx11/list#end(9afe7339530a999).(); ++cxx . . $ std/_List_const_iterator#operator++(aee61632d924a923).it)
212 {
213 if (it->cxx . . $ std/_List_const_iterator#`operator->`(8e614c7de0b1573e).getOwnercxx . . $ pvpgn/bnetd/Watch#getOwner(ee9430605b44e25e).() && (!it->cxx . . $ std/_List_const_iterator#`operator->`(8e614c7de0b1573e).getAccountcxx . . $ pvpgn/bnetd/Watch#getAccount(bd50dfe41cbbfab3).() || it->cxx . . $ std/_List_const_iterator#`operator->`(8e614c7de0b1573e).getAccountcxx . . $ pvpgn/bnetd/Watch#getAccount(bd50dfe41cbbfab3).() == account) && (!it->cxx . . $ std/_List_const_iterator#`operator->`(8e614c7de0b1573e).getClientTagcxx . . $ pvpgn/bnetd/Watch#getClientTag(ddd8539a2fcdd4ce).() || (clienttag == it->cxx . . $ std/_List_const_iterator#`operator->`(8e614c7de0b1573e).getClientTagcxx . . $ pvpgn/bnetd/Watch#getClientTag(ddd8539a2fcdd4ce).())) && (it->cxx . . $ std/_List_const_iterator#`operator->`(8e614c7de0b1573e).getEventMaskcxx . . $ pvpgn/bnetd/Watch#getEventMask(ddd8539a2fcdd4ce).() & event))
214 {
215 message_send_textcxx . . $ pvpgn/bnetd/message_send_text(61daf7e3ba1862c4).(it->cxx . . $ std/_List_const_iterator#`operator->`(8e614c7de0b1573e).getOwnercxx . . $ pvpgn/bnetd/Watch#getOwner(ee9430605b44e25e).(), message_type_whispercxx . . $ pvpgn/bnetd/message_type_whisper., my_c, msg);
216 }
217 }
218
219 return 0;
220 }
221
222 int
223 WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#::dispatchcxx . . $ pvpgn/bnetd/WatchComponent#dispatch(5f92e2dc3f12ba14).(t_accountcxx . . $ pvpgn/bnetd/t_account# * who, char const * gamename, t_clienttagcxx . . $ pvpgn/t_clienttag# clienttag, Watchcxx . . $ pvpgn/bnetd/Watch#::EventTypecxx . . $ pvpgn/bnetd/Watch#EventType# event) const
224 {
225 switch (event)
226 {
227 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_logincxx . . $ pvpgn/bnetd/Watch#ET_login.:
228 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_logoutcxx . . $ pvpgn/bnetd/Watch#ET_logout.:
229 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_joingamecxx . . $ pvpgn/bnetd/Watch#ET_joingame.:
230 case Watchcxx . . $ pvpgn/bnetd/Watch#::ET_leavegamecxx . . $ pvpgn/bnetd/Watch#ET_leavegame.:
231 return dispatch_whispercxx . . $ pvpgn/bnetd/WatchComponent#dispatch_whisper(5f92e2dc3f12ba14).(who, gamename, clienttag, event);
232 default:
233 eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got unknown event {}", (unsigned int)event);
234 return -1;
235 }
236 return 0;
237 }
238
239
240 WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#::WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#WatchComponent(49f6e7a06ebc5aa8).()
241 :wlistcxx . . $ pvpgn/bnetd/WatchComponent#wlist.()
242 {
243 }
244
245
246 WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#::~cxx . . $ pvpgn/bnetd/WatchComponent#`~WatchComponent`(ced63f7c635d850d).WatchComponentcxx . . $ pvpgn/bnetd/WatchComponent#() throw ()
247 {
248 }
249
250 }
251
252 }