| 1 | /* |
| 2 | * Copyright (C) 2004 Dizzy |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 20 | #define ATTRGROUP_INTERNAL_ACCESScxx . . $ `src/bnetd/attrlayer.cpp:20:9`! |
| 21 | #include "attrlayer.h"cxx . . $ `<file>/src/bnetd/attrlayer.h`/ |
| 22 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 23 | #include "common/flags.h"cxx . . $ `<file>/src/common/flags.h`/ |
| 24 | #include "attr.h"cxx . . $ `<file>/src/bnetd/attr.h`/ |
| 25 | #include "attrgroup.h"cxx . . $ `<file>/src/bnetd/attrgroup.h`/ |
| 26 | #include "storage.h"cxx . . $ `<file>/src/bnetd/storage.h`/ |
| 27 | #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/ |
| 28 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 29 | |
| 30 | namespace pvpgncxx . . $ pvpgn/ |
| 31 | { |
| 32 | |
| 33 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 34 | { |
| 35 | |
| 36 | static t_attrgroupcxx . . $ pvpgn/bnetd/t_attrgroup# *defattrscxx . . $ pvpgn/bnetd/defattrs. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 37 | |
| 38 | static DECLARE_ELIST_INITcxx . . $ `src/common/elist.h:194:9`!(loadedlist); |
| 39 | static DECLARE_ELIST_INITcxx . . $ `src/common/elist.h:194:9`!(dirtylist); |
| 40 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char*> loadedtabscxx . . $ pvpgn/bnetd/loadedtabs.; |
| 41 | |
| 42 | static int attrlayer_unload_defaultcxx . . $ pvpgn/bnetd/attrlayer_unload_default(b126dc7c1de90089).(void); |
| 43 | |
| 44 | extern int attrlayer_initcxx . . $ pvpgn/bnetd/attrlayer_init(b126dc7c1de90089).(void) |
| 45 | { |
| 46 | elist_initcxx . . $ `src/common/elist.h:193:9`!(&loadedlist); |
| 47 | elist_initcxx . . $ `src/common/elist.h:193:9`!(&dirtylist); |
| 48 | attrlayer_load_defaultcxx . . $ pvpgn/bnetd/attrlayer_load_default(b126dc7c1de90089).(); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | extern int attrlayer_cleanupcxx . . $ pvpgn/bnetd/attrlayer_cleanup(b126dc7c1de90089).(void) |
| 54 | { |
| 55 | attrlayer_flushcxx . . $ pvpgn/bnetd/attrlayer_flush(7864480464b09eea).(FS_FORCEcxx . . $ `src/bnetd/attrlayer.h:27:9`! | FS_ALLcxx . . $ `src/bnetd/attrlayer.h:28:9`!); |
| 56 | attrlayer_unload_defaultcxx . . $ pvpgn/bnetd/attrlayer_unload_default(b126dc7c1de90089).(); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | extern int attrlayer_load_defaultcxx . . $ pvpgn/bnetd/attrlayer_load_default(b126dc7c1de90089).(void) |
| 62 | { |
| 63 | if (defattrscxx . . $ pvpgn/bnetd/defattrs.) attrlayer_unload_defaultcxx . . $ pvpgn/bnetd/attrlayer_unload_default(b126dc7c1de90089).(); |
| 64 | |
| 65 | defattrscxx . . $ pvpgn/bnetd/defattrs. = attrgroup_create_storagecxx . . $ pvpgn/bnetd/attrgroup_create_storage(46f131f0816d7ee8).(storagecxx . . $ pvpgn/bnetd/storage.->get_defacctcxx . . $ pvpgn/bnetd/$anonymous_type_c7c18ce0294b47dd_0#get_defacct.()); |
| 66 | if (!defattrscxx . . $ pvpgn/bnetd/defattrs.) { |
| 67 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not create attrgroup"); |
| 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | return attrgroup_loadcxx . . $ pvpgn/bnetd/attrgroup_load(272c712ec47d72e9).(defattrscxx . . $ pvpgn/bnetd/defattrs., "BNET"); |
| 72 | } |
| 73 | |
| 74 | static int attrlayer_unload_defaultcxx . . $ pvpgn/bnetd/attrlayer_unload_default(b126dc7c1de90089).(void) |
| 75 | { |
| 76 | attrgroup_destroycxx . . $ pvpgn/bnetd/attrgroup_destroy(4a06131a44a32a35).(defattrscxx . . $ pvpgn/bnetd/defattrs.); |
| 77 | defattrscxx . . $ pvpgn/bnetd/defattrs. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | /* FIXME: dont copy most of the functionality, a good place for a C++ template ;) */ |
| 83 | |
| 84 | extern int attrlayer_flushcxx . . $ pvpgn/bnetd/attrlayer_flush(7864480464b09eea).(int flags) |
| 85 | { |
| 86 | static t_elistcxx . . $ pvpgn/t_elist# *curr = &loadedlistcxx . . $ pvpgn/bnetd/loadedlist.; |
| 87 | static t_elistcxx . . $ pvpgn/t_elist# *next = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 88 | t_attrgroupcxx . . $ pvpgn/bnetd/t_attrgroup# *attrgroup; |
| 89 | unsigned int fcount; |
| 90 | unsigned int tcount; |
| 91 | |
| 92 | fcount = tcount = 0; |
| 93 | if (curr == &loadedlistcxx . . $ pvpgn/bnetd/loadedlist. || FLAG_ISSETcxx . . $ `src/common/flags.h:25:9`!(flags, FS_ALLcxx . . $ `src/bnetd/attrlayer.h:28:9`!)) { |
| 94 | curr = elist_nextcxx . . $ `src/common/elist.h:189:9`!(&loadedlist); |
| 95 | next = elist_nextcxx . . $ `src/common/elist.h:189:9`!(curr); |
| 96 | } |
| 97 | |
| 98 | /* elist_for_each_safe splitted into separate startup for userstep function */ |
| 99 | for (; curr != &loadedlistcxx . . $ pvpgn/bnetd/loadedlist.; curr = next, next = elist_nextcxx . . $ `src/common/elist.h:189:9`!(curr)) { |
| 100 | if (!FLAG_ISSETcxx . . $ `src/common/flags.h:25:9`!(flags, FS_ALLcxx . . $ `src/bnetd/attrlayer.h:28:9`!) && tcount >= prefs_get_user_stepcxx . . $ pvpgn/bnetd/prefs_get_user_step(db52760e79bf9054).()) break; |
| 101 | |
| 102 | attrgroup = elist_entrycxx . . $ `src/common/elist.h:228:9`!(curr, t_attrgroup, loadedlist); |
| 103 | switch (attrgroup_flushcxx . . $ pvpgn/bnetd/attrgroup_flush(fe3030925edb1d32).(attrgroup, flags)) { |
| 104 | case 0: |
| 105 | /* stop on the first account not flushed (ie accessed too early) */ |
| 106 | goto loopout; |
| 107 | case 1: |
| 108 | fcount++; |
| 109 | break; |
| 110 | case -1: |
| 111 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not flush account"); |
| 112 | break; |
| 113 | default: |
| 114 | break; |
| 115 | } |
| 116 | tcount++; |
| 117 | } |
| 118 | |
| 119 | loopout: |
| 120 | if (fcount > 0) |
| 121 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_debugcxx . . $ pvpgn/eventlog_level_debug., __FUNCTION__, "flushed {} user accounts", fcount); |
| 122 | |
| 123 | if (!FLAG_ISSETcxx . . $ `src/common/flags.h:25:9`!(flags, FS_ALLcxx . . $ `src/bnetd/attrlayer.h:28:9`!) && curr != &loadedlistcxx . . $ pvpgn/bnetd/loadedlist.) return 1; |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | extern int attrlayer_savecxx . . $ pvpgn/bnetd/attrlayer_save(7864480464b09eea).(int flags) |
| 129 | { |
| 130 | static t_elistcxx . . $ pvpgn/t_elist# *curr = &dirtylistcxx . . $ pvpgn/bnetd/dirtylist.; |
| 131 | static t_elistcxx . . $ pvpgn/t_elist# *next = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 132 | t_attrgroupcxx . . $ pvpgn/bnetd/t_attrgroup# *attrgroup; |
| 133 | unsigned int scount; |
| 134 | unsigned int tcount; |
| 135 | |
| 136 | scount = tcount = 0; |
| 137 | if (curr == &dirtylistcxx . . $ pvpgn/bnetd/dirtylist. || FLAG_ISSETcxx . . $ `src/common/flags.h:25:9`!(flags, FS_ALLcxx . . $ `src/bnetd/attrlayer.h:28:9`!)) { |
| 138 | curr = elist_nextcxx . . $ `src/common/elist.h:189:9`!(&dirtylist); |
| 139 | next = elist_nextcxx . . $ `src/common/elist.h:189:9`!(curr); |
| 140 | } |
| 141 | |
| 142 | /* elist_for_each_safe splitted into separate startup for userstep function */ |
| 143 | for (; curr != &dirtylistcxx . . $ pvpgn/bnetd/dirtylist.; curr = next, next = elist_nextcxx . . $ `src/common/elist.h:189:9`!(curr)) { |
| 144 | if (!FLAG_ISSETcxx . . $ `src/common/flags.h:25:9`!(flags, FS_ALLcxx . . $ `src/bnetd/attrlayer.h:28:9`!) && tcount >= prefs_get_user_stepcxx . . $ pvpgn/bnetd/prefs_get_user_step(db52760e79bf9054).()) break; |
| 145 | |
| 146 | attrgroup = elist_entrycxx . . $ `src/common/elist.h:228:9`!(curr, t_attrgroup, dirtylist); |
| 147 | switch (attrgroup_savecxx . . $ pvpgn/bnetd/attrgroup_save(fe3030925edb1d32).(attrgroup, flags)) { |
| 148 | case 0: |
| 149 | /* stop on the first account not saved (ie dirty too early) */ |
| 150 | goto loopout; |
| 151 | case 1: |
| 152 | scount++; |
| 153 | break; |
| 154 | case -1: |
| 155 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "could not save account"); |
| 156 | break; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | tcount++; |
| 161 | } |
| 162 | |
| 163 | loopout: |
| 164 | if (scount > 0) |
| 165 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_debugcxx . . $ pvpgn/eventlog_level_debug., __FUNCTION__, "saved {} user accounts", scount); |
| 166 | |
| 167 | if (!FLAG_ISSETcxx . . $ `src/common/flags.h:25:9`!(flags, FS_ALLcxx . . $ `src/bnetd/attrlayer.h:28:9`!) && curr != &dirtylistcxx . . $ pvpgn/bnetd/dirtylist.) return 1; |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | extern void attrlayer_add_loadedlistcxx . . $ pvpgn/bnetd/attrlayer_add_loadedlist(c14d3311d3358512).(t_elistcxx . . $ pvpgn/t_elist# *what) |
| 173 | { |
| 174 | elist_add_tailcxx . . $ pvpgn/elist_add_tail(3e860e19053b2cfa).(&loadedlistcxx . . $ pvpgn/bnetd/loadedlist., what); |
| 175 | } |
| 176 | |
| 177 | extern void attrlayer_del_loadedlistcxx . . $ pvpgn/bnetd/attrlayer_del_loadedlist(c14d3311d3358512).(t_elistcxx . . $ pvpgn/t_elist# *what) |
| 178 | { |
| 179 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(what); |
| 180 | } |
| 181 | |
| 182 | extern void attrlayer_add_dirtylistcxx . . $ pvpgn/bnetd/attrlayer_add_dirtylist(c14d3311d3358512).(t_elistcxx . . $ pvpgn/t_elist# *what) |
| 183 | { |
| 184 | elist_add_tailcxx . . $ pvpgn/elist_add_tail(3e860e19053b2cfa).(&dirtylistcxx . . $ pvpgn/bnetd/dirtylist., what); |
| 185 | } |
| 186 | |
| 187 | extern void attrlayer_del_dirtylistcxx . . $ pvpgn/bnetd/attrlayer_del_dirtylist(c14d3311d3358512).(t_elistcxx . . $ pvpgn/t_elist# *what) |
| 188 | { |
| 189 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(what); |
| 190 | } |
| 191 | |
| 192 | extern t_attrgroupcxx . . $ pvpgn/bnetd/t_attrgroup# * attrlayer_get_defattrgroupcxx . . $ pvpgn/bnetd/attrlayer_get_defattrgroup(cfe99ecc31eb29d3).(void) |
| 193 | { |
| 194 | return defattrscxx . . $ pvpgn/bnetd/defattrs.; |
| 195 | } |
| 196 | |
| 197 | extern void attrlayer_accessedcxx . . $ pvpgn/bnetd/attrlayer_accessed(4d6018b0ff3f0bbd).(t_attrgroupcxx . . $ pvpgn/bnetd/t_attrgroup#* attrgroup) |
| 198 | { |
| 199 | /* move the attrgroup at the end of loaded list for the "flush" loop */ |
| 200 | elist_delcxx . . $ pvpgn/elist_del(c14d3311d3358512).(&attrgroup->loadedlistcxx . . $ pvpgn/bnetd/attrgroup_struct#loadedlist.); |
| 201 | elist_add_tailcxx . . $ pvpgn/elist_add_tail(3e860e19053b2cfa).(&loadedlistcxx . . $ pvpgn/bnetd/loadedlist., &attrgroup->loadedlistcxx . . $ pvpgn/bnetd/attrgroup_struct#loadedlist.); |
| 202 | } |
| 203 | |
| 204 | } |
| 205 | |
| 206 | } |