00001
00002
00003
00004
00005
00006 #include "copyright.h"
00007 #include "autoconf.h"
00008 #include "config.h"
00009 #include "externs.h"
00010
00011 #include "attrs.h"
00012 #include "command.h"
00013 #include "functions.h"
00014 #include "powers.h"
00015
00016
00017
00018
00019 static int count_quota(dbref player)
00020 {
00021 if (Owner(player) != player)
00022 {
00023 return 0;
00024 }
00025 int q = 0 - mudconf.player_quota;
00026
00027 dbref i;
00028 DO_WHOLE_DB(i)
00029 {
00030 if (Owner(i) != player)
00031 {
00032 continue;
00033 }
00034 if (Going(i) && (!isRoom(i)))
00035 {
00036 continue;
00037 }
00038 switch (Typeof(i))
00039 {
00040 case TYPE_EXIT:
00041
00042 q += mudconf.exit_quota;
00043 break;
00044
00045 case TYPE_ROOM:
00046
00047 q += mudconf.room_quota;
00048 break;
00049
00050 case TYPE_THING:
00051
00052 q += mudconf.thing_quota;
00053 break;
00054
00055 case TYPE_PLAYER:
00056
00057 q += mudconf.player_quota;
00058 break;
00059 }
00060 }
00061 return q;
00062 }
00063
00064 static void mung_quotas(dbref player, int key, int value)
00065 {
00066 dbref aowner;
00067 int aq, rq, xq, aflags;
00068 char *buff;
00069
00070 if (key & QUOTA_FIX)
00071 {
00072
00073
00074 xq = count_quota(player);
00075 if (key & QUOTA_TOT)
00076 {
00077 buff = atr_get(player, A_RQUOTA, &aowner, &aflags);
00078 aq = mux_atol(buff) + xq;
00079 atr_add_raw(player, A_QUOTA, mux_ltoa_t(aq));
00080 free_lbuf(buff);
00081 }
00082 else
00083 {
00084 buff = atr_get(player, A_QUOTA, &aowner, &aflags);
00085 rq = mux_atol(buff) - xq;
00086 atr_add_raw(player, A_RQUOTA, mux_ltoa_t(rq));
00087 free_lbuf(buff);
00088 }
00089 }
00090 else
00091 {
00092
00093
00094 buff = atr_get(player, A_QUOTA, &aowner, &aflags);
00095 if (!*buff)
00096 {
00097 free_lbuf(buff);
00098 buff = atr_get(player, A_RQUOTA, &aowner, &aflags);
00099 rq = mux_atol(buff);
00100 free_lbuf(buff);
00101 aq = rq + count_quota(player);
00102 }
00103 else
00104 {
00105 aq = mux_atol(buff);
00106 free_lbuf(buff);
00107 buff = atr_get(player, A_RQUOTA, &aowner, &aflags);
00108 rq = mux_atol(buff);
00109 free_lbuf(buff);
00110 }
00111
00112
00113
00114 if (key & QUOTA_REM)
00115 {
00116 aq += (value - rq);
00117 rq = value;
00118 }
00119 else
00120 {
00121 rq += (value - aq);
00122 aq = value;
00123 }
00124
00125
00126
00127 atr_add_raw(player, A_QUOTA, mux_ltoa_t(aq));
00128 atr_add_raw(player, A_RQUOTA, mux_ltoa_t(rq));
00129 }
00130 }
00131
00132 static void show_quota(dbref player, dbref victim)
00133 {
00134 dbref aowner;
00135 int aq, rq, aflags;
00136 char *buff;
00137
00138 buff = atr_get(victim, A_QUOTA, &aowner, &aflags);
00139 aq = mux_atol(buff);
00140 free_lbuf(buff);
00141 buff = atr_get(victim, A_RQUOTA, &aowner, &aflags);
00142 rq = aq - mux_atol(buff);
00143 free_lbuf(buff);
00144 if (!Free_Quota(victim))
00145 {
00146 buff = tprintf("%-16s Quota: %9d Used: %9d", Name(victim), aq, rq);
00147 }
00148 else
00149 {
00150 buff = tprintf("%-16s Quota: UNLIMITED Used: %9d", Name(victim), rq);
00151 }
00152 notify_quiet(player, buff);
00153 }
00154
00155 void do_quota
00156 (
00157 dbref executor,
00158 dbref caller,
00159 dbref enactor,
00160 int key,
00161 int nargs,
00162 char *arg1,
00163 char *arg2
00164 )
00165 {
00166 UNUSED_PARAMETER(caller);
00167 UNUSED_PARAMETER(enactor);
00168 UNUSED_PARAMETER(nargs);
00169
00170 if (!(mudconf.quotas || Quota(executor)))
00171 {
00172 notify_quiet(executor, "Quotas are not enabled.");
00173 return;
00174 }
00175 if ((key & QUOTA_TOT) && (key & QUOTA_REM))
00176 {
00177 notify_quiet(executor, "Illegal combination of switches.");
00178 return;
00179 }
00180
00181 dbref who;
00182 int value = 0, i;
00183 bool set = false;
00184
00185
00186
00187 if (key & QUOTA_ALL)
00188 {
00189 if (arg1 && *arg1)
00190 {
00191 value = mux_atol(arg1);
00192 set = true;
00193 }
00194 else if (key & (QUOTA_SET | QUOTA_FIX))
00195 {
00196 value = 0;
00197 set = true;
00198 }
00199 if (set)
00200 {
00201 STARTLOG(LOG_WIZARD, "WIZ", "QUOTA");
00202 log_name(executor);
00203 log_text(" changed everyone's quota");
00204 ENDLOG;
00205 }
00206 DO_WHOLE_DB(i)
00207 {
00208 if (isPlayer(i))
00209 {
00210 if (set)
00211 {
00212 mung_quotas(i, key, value);
00213 }
00214 show_quota(executor, i);
00215 }
00216 }
00217 return;
00218 }
00219
00220
00221
00222 if (!arg1 || *arg1 == '\0')
00223 {
00224 who = Owner(executor);
00225 }
00226 else
00227 {
00228 who = lookup_player(executor, arg1, true);
00229 if (!Good_obj(who))
00230 {
00231 notify_quiet(executor, "Not found.");
00232 return;
00233 }
00234 }
00235
00236
00237
00238 if (!Quota(executor))
00239 {
00240 if (arg2 && *arg2)
00241 {
00242 notify_quiet(executor, NOPERM_MESSAGE);
00243 return;
00244 }
00245 if (Owner(executor) != who)
00246 {
00247 notify_quiet(executor, NOPERM_MESSAGE);
00248 return;
00249 }
00250 }
00251 if (arg2 && *arg2)
00252 {
00253 set = true;
00254 value = mux_atol(arg2);
00255 }
00256 else if (key & QUOTA_FIX)
00257 {
00258 set = true;
00259 value = 0;
00260 }
00261 if (set)
00262 {
00263 STARTLOG(LOG_WIZARD, "WIZ", "QUOTA");
00264 log_name(executor);
00265 log_text(" changed the quota of ");
00266 log_name(who);
00267 ENDLOG;
00268 mung_quotas(who, key, value);
00269 }
00270 show_quota(executor, who);
00271 }
00272
00273 FUNCTION(fun_hasquota)
00274 {
00275 UNUSED_PARAMETER(caller);
00276 UNUSED_PARAMETER(enactor);
00277 UNUSED_PARAMETER(nfargs);
00278 UNUSED_PARAMETER(cargs);
00279 UNUSED_PARAMETER(ncargs);
00280
00281 if (!mudconf.quotas)
00282 {
00283 safe_str("#-1 Quotas are not enabled.", buff, bufc);
00284 return;
00285 }
00286
00287
00288
00289 dbref who = lookup_player(executor, fargs[0], true);
00290 if (!Good_obj(who))
00291 {
00292 safe_str("#-1 NOT FOUND", buff, bufc);
00293 return;
00294 }
00295
00296
00297
00298 if ( Owner(executor) != who
00299 && !Quota(executor))
00300 {
00301 safe_str(NOPERM_MESSAGE, buff, bufc);
00302 return;
00303 }
00304
00305 bool bResult = true;
00306 if (!Free_Quota(who))
00307 {
00308 int aflags;
00309 dbref aowner;
00310 char *quota = atr_get(who, A_RQUOTA, &aowner, &aflags);
00311 int rq = mux_atol(quota);
00312 free_lbuf(quota);
00313 bResult = (rq >= mux_atol(fargs[1]));
00314 }
00315 safe_bool(bResult, buff, bufc);
00316 }