Explorar el Código

* Changed bits to uint64_t
* flag_t is now unsigned long long
* Added flag['char'] business


svn: 956

Bryan Drewery hace 22 años
padre
commit
a068fb1a7c
Se han modificado 3 ficheros con 119 adiciones y 132 borrados
  1. 34 32
      src/bits.h
  2. 27 40
      src/flags.c
  3. 58 60
      src/flags.h

+ 34 - 32
src/bits.h

@@ -1,37 +1,39 @@
 #ifndef _BITS_H
 #define _BITS_H
 
-#define BIT0	0x000000001
-#define BIT1	0x000000002
-#define BIT2	0x000000004
-#define BIT3	0x000000008
-#define BIT4	0x000000010
-#define BIT5	0x000000020
-#define BIT6	0x000000040
-#define BIT7	0x000000080
-#define BIT8	0x000000100
-#define BIT9	0x000000200
-#define BIT10	0x000000400
-#define BIT11	0x000000800
-#define BIT12	0x000001000
-#define BIT13	0x000002000
-#define BIT14	0x000004000
-#define BIT15	0x000008000
-#define BIT16	0x000010000
-#define BIT17	0x000020000
-#define BIT18	0x000040000
-#define BIT19	0x000080000
-#define BIT20	0x000100000
-#define BIT21	0x000200000
-#define BIT22	0x000400000
-#define BIT23	0x000800000
-#define BIT24	0x001000000
-#define BIT25	0x002000000
-#define BIT26	0x040000000
-#define BIT27	0x080000000
-#define BIT28	0x100000000
-#define BIT29	0x200000000
-#define BIT30	0x400000000
-#define BIT31	0x800000000
+#include <sys/types.h>
+
+#define BIT0	(uint64_t) 0x000000001
+#define BIT1	(uint64_t) 0x000000002
+#define BIT2	(uint64_t) 0x000000004
+#define BIT3	(uint64_t) 0x000000008
+#define BIT4	(uint64_t) 0x000000010
+#define BIT5	(uint64_t) 0x000000020
+#define BIT6	(uint64_t) 0x000000040
+#define BIT7	(uint64_t) 0x000000080
+#define BIT8	(uint64_t) 0x000000100
+#define BIT9	(uint64_t) 0x000000200
+#define BIT10	(uint64_t) 0x000000400
+#define BIT11	(uint64_t) 0x000000800
+#define BIT12	(uint64_t) 0x000001000
+#define BIT13	(uint64_t) 0x000002000
+#define BIT14	(uint64_t) 0x000004000
+#define BIT15	(uint64_t) 0x000008000
+#define BIT16	(uint64_t) 0x000010000
+#define BIT17	(uint64_t) 0x000020000
+#define BIT18	(uint64_t) 0x000040000
+#define BIT19	(uint64_t) 0x000080000
+#define BIT20	(uint64_t) 0x000100000
+#define BIT21	(uint64_t) 0x000200000
+#define BIT22	(uint64_t) 0x000400000
+#define BIT23	(uint64_t) 0x000800000
+#define BIT24	(uint64_t) 0x001000000
+#define BIT25	(uint64_t) 0x002000000
+#define BIT26	(uint64_t) 0x004000000
+#define BIT27	(uint64_t) 0x008000000
+#define BIT28	(uint64_t) 0x010000000
+#define BIT29	(uint64_t) 0x020000000
+#define BIT30	(uint64_t) 0x040000000
+#define BIT31	(uint64_t) 0x080000000
 
 #endif /* !_BITS_H */

+ 27 - 40
src/flags.c

@@ -14,7 +14,26 @@
 #include "userent.h"
 #include "users.h"
 
-static int                     allow_dk_cmds = 1;
+flag_t		FLAG[128];
+
+void init_flags()
+{
+       unsigned char i;
+
+       for (i = 0; i < 'A'; i++)
+               FLAG[i] = 0;
+       for (; i <= 'Z'; i++)
+               FLAG[i] = (flag_t) 1 << (26 + (i - 'A'));
+       for (; i < 'a'; i++)
+               FLAG[i] = 0;
+       for (; i <= 'z'; i++)
+               FLAG[i] = (flag_t) 1 << (i - 'a');
+       for (; i < 128; i++)
+               FLAG[i] = 0;
+
+//printf("a: %llX A: %llX\n",  FLAG['a'],  FLAG['Z']);
+//printf("0: %llX 26: %llX\n",  BIT0, BIT31);
+}
 
 /* Some flags are mutually exclusive -- this roots them out
  */
@@ -145,41 +164,18 @@ void break_down_flags(const char *string, struct flag_record *plus, struct flag_
       if ((*string >= 'a') && (*string <= 'z')) {
 	switch (mode) {
 	case 0:
-	  which->global |= 1 << (*string - 'a');
+	  /* which->global |= (flag_t) 1 << (*string - 'a'); */
+          which->global |= FLAG[(unsigned char) *string];
 	  break;
 	case 1:
-	  which->chan |= 1 << (*string - 'a');
+	  /* which->chan |= (flag_t) 1 << (*string - 'a'); */
+          which->chan |= FLAG[(unsigned char) *string];
 	  break;
 	case 2:
-	  which->bot |= 1 << (*string - 'a');
-	}
-      } 
-/* udef
-      else if ((*string >= 'A') && (*string <= 'Z')) {
-	switch (mode) {
-	case 0:
-	  which->udef_global |= 1 << (*string - 'A');
-	  break;
-	case 1:
-	  which->udef_chan |= 1 << (*string - 'A');
-	  break;
+	  /* which->bot |= (flag_t) 1 << (*string - 'a'); */
+          which->bot |= FLAG[(unsigned char) *string];
 	}
       } 
-      else if ((*string >= '0') && (*string <= '9')) {
-	switch (mode) {
-	  // Map 0->9 to A->K for glob/chan so they are not lost
-	case 0:
-	  which->udef_global |= 1 << (*string - '0');
-	  break;
-	case 1:
-	  which->udef_chan |= 1 << (*string - '0');
-	  break;
-	case 2:
-	  which->bot |= BOT_FLAG0 << (*string - '0');
-	  break;
-	}
-      }
-*/
     }
     string++;
   }
@@ -302,17 +298,8 @@ int flagrec_ok(struct flag_record *req, struct flag_record *have)
     int hav = have->global;
 
     /* Exception 1 - global +d/+k cant use -|-, unless they are +p */
-    if (!req->chan && !req->global) {
-      if (!allow_dk_cmds) {
-	if (glob_party(*have))
-	  return 1;
-	if (glob_kick(*have) || chan_kick(*have))
-	  return 0;		/* +k cant use -|- commands */
-	if (glob_deop(*have) || chan_deop(*have))
-	  return 0;		/* neither can +d's */
-      }
+    if (!req->chan && !req->global)
       return 1;
-    }
     /* The +n/+m checks arent needed anymore since +n/+m
      * automatically add lower flags
      */

+ 58 - 60
src/flags.h

@@ -13,12 +13,14 @@
 #define PRIV_VOICE 2
 
 
-typedef long flag_t;
+typedef unsigned long long	flag_t;
+
+extern flag_t	FLAG[128];
 
 struct flag_record {
   flag_t match;
   flag_t global;
-  flag_t  bot;
+  flag_t bot;
   flag_t chan;
 };
 
@@ -63,33 +65,28 @@ struct flag_record {
 #define CHAN_VALID 0x03ffffff	/* all flags that can be chan specific */
 #define BOT_VALID  0x7fe689C1 /* all BOT_ flags in use               */
 
+#define USER_ADMIN	FLAG['a']
+#define USER_BOT	FLAG['b']
+#define USER_CHANHUB	FLAG['c']
+#define USER_DEOP	FLAG['d']
+#define USER_EXEMPT	FLAG['e']
+#define USER_HUBA	FLAG['i']
+#define USER_CHUBA	FLAG['j']
+#define USER_KICK	FLAG['k']
+#define USER_DOLIMIT	FLAG['l']
+#define USER_MASTER	FLAG['m']
+#define USER_OWNER	FLAG['n']
+#define USER_OP		FLAG['o']
+#define USER_PARTY	FLAG['p']
+#define USER_QUIET	FLAG['q']
+#define USER_UPDATEHUB	FLAG['u']
+#define USER_VOICE	FLAG['v']
+#define USER_WASOPTEST	FLAG['w']
+#define USER_NOFLOOD	FLAG['x']
+#define USER_DOVOICE	FLAG['y']
+#define USER_DEFAULT	0
+
 
-#define USER_ADMIN         BIT0  /* a  user is an admin                  */
-#define USER_BOT           BIT1  /* b  user is a bot                     */
-#define USER_CHANHUB       BIT2  /* c  bot is a chanhub    */
-#define USER_DEOP          BIT3  /* d  user is global de-op              */
-#define USER_EXEMPT        BIT4  /* e  exempted from stopnethack         */
-#define USER_F             BIT5  /* f  unused             */
-#define USER_G             BIT6  /* g  unused                            */
-#define USER_H             BIT7  /* h  unused                            */
-#define USER_HUBA          BIT8  /* i  access to HUBS        */
-#define USER_CHUBA         BIT9  /* j  access to CHANHUBS(+c)            */
-#define USER_KICK          BIT10 /* k  user is global auto-kick          */
-#define USER_DOLIMIT       BIT11 /* l  bot sets limit on channel(s)        */
-#define USER_MASTER        BIT12 /* m  user has full bot access          */
-#define USER_OWNER         BIT13 /* n  user is the bot owner             */
-#define USER_OP            BIT14 /* o  user is +o on all channels        */
-#define USER_PARTY         BIT15 /* p  user can CHAT on partyline:*needs (+i or +j)    */
-#define USER_QUIET         BIT16 /* q  user is global de-voice           */
-#define USER_R  	   BIT17 /* r  unused    */
-#define USER_S             BIT18 /* s  unused             */
-#define USER_T             BIT19 /* t  unused             */
-#define USER_UPDATEHUB     BIT20 /* u  bot is the updatehub         */
-#define USER_VOICE         BIT21 /* v  user is +v on all channels        */
-#define USER_WASOPTEST     BIT22 /* w  wasop test needed for stopnethack */
-#define USER_NOFLOOD       BIT23 /* x  user is exempt from flood kicks   */
-#define USER_DOVOICE       BIT24 /* y  bot gives voices                  */
-#define USER_DEFAULT       BIT25 /* use default-flags                    */
 
 #define bot_hublevel(x) ( ( (x) && (x->flags & USER_BOT) && (get_user(&USERENTRY_BOTADDR, x)) ) ? \
                           ( ((struct bot_addr *) get_user(&USERENTRY_BOTADDR, x))->hublevel ? \
@@ -98,38 +95,39 @@ struct flag_record {
 
 /* Flag checking macros
  */
-#define chan_op(x)			((x).chan & USER_OP)
-#define glob_op(x)			((x).global & USER_OP)
-#define chan_deop(x)			((x).chan & USER_DEOP)
-#define glob_deop(x)			((x).global & USER_DEOP)
-#define glob_master(x)			((x).global & USER_MASTER)
-#define glob_bot(x)			((x).global & USER_BOT)
-#define glob_owner(x)			((x).global & USER_OWNER)
-#define chan_master(x)			((x).chan & USER_MASTER)
-#define chan_owner(x)			((x).chan & USER_OWNER)
-#define chan_kick(x)			((x).chan & USER_KICK)
-#define glob_kick(x)			((x).global & USER_KICK)
-#define chan_voice(x)			((x).chan & USER_VOICE)
-#define glob_voice(x)			((x).global & USER_VOICE)
-#define chan_wasoptest(x)		((x).chan & USER_WASOPTEST)
-#define glob_wasoptest(x)		((x).global & USER_WASOPTEST)
-#define chan_quiet(x)			((x).chan & USER_QUIET)
-#define glob_quiet(x)			((x).global & USER_QUIET)
-#define glob_party(x)			((x).global & USER_PARTY)
-#define glob_hilite(x) 			((x).global & USER_HIGHLITE)
-#define chan_exempt(x)			((x).chan & USER_EXEMPT)
-#define glob_exempt(x)			((x).global & USER_EXEMPT)
-#define glob_admin(x)			((x).global & USER_ADMIN)
-#define glob_huba(x)			((x).global & USER_HUBA)
-#define glob_chuba(x)			((x).global & USER_CHUBA)
-#define glob_dolimit(x)			((x).global & USER_DOLIMIT)
-#define chan_dolimit(x)			((x).chan & USER_DOLIMIT)
-#define glob_dovoice(x)			((x).global & USER_DOVOICE)
-#define chan_dovoice(x)			((x).chan & USER_DOVOICE)
-#define glob_noflood(x)			((x).global & USER_NOFLOOD)
-#define chan_noflood(x)			((x).chan & USER_NOFLOOD)
-#define glob_chanhub(x)			((x).global & USER_CHANHUB)
-
+#define chan_op(x)                     ((x).chan & USER_OP)
+#define glob_op(x)                     ((x).global & USER_OP)
+#define chan_deop(x)                   ((x).chan & USER_DEOP)
+#define glob_deop(x)                   ((x).global & USER_DEOP)
+#define glob_master(x)                 ((x).global & USER_MASTER)
+#define glob_bot(x)                    ((x).global & USER_BOT)
+#define glob_owner(x)                  ((x).global & USER_OWNER)
+#define chan_master(x)                 ((x).chan & USER_MASTER)
+#define chan_owner(x)                  ((x).chan & USER_OWNER)
+#define chan_kick(x)                   ((x).chan & USER_KICK)
+#define glob_kick(x)                   ((x).global & USER_KICK)
+#define chan_voice(x)                  ((x).chan & USER_VOICE)
+#define glob_voice(x)                  ((x).global & USER_VOICE)
+#define chan_wasoptest(x)              ((x).chan & USER_WASOPTEST)
+#define glob_wasoptest(x)              ((x).global & USER_WASOPTEST)
+#define chan_quiet(x)                  ((x).chan & USER_QUIET)
+#define glob_quiet(x)                  ((x).global & USER_QUIET)
+#define glob_party(x)                  ((x).global & USER_PARTY)
+#define glob_hilite(x)                         ((x).global & USER_HIGHLITE)
+#define chan_exempt(x)                 ((x).chan & USER_EXEMPT)
+#define glob_exempt(x)                 ((x).global & USER_EXEMPT)
+#define glob_admin(x)                  ((x).global & USER_ADMIN)
+#define glob_huba(x)                   ((x).global & USER_HUBA)
+#define glob_chuba(x)                  ((x).global & USER_CHUBA)
+#define glob_dolimit(x)                        ((x).global & USER_DOLIMIT)
+#define chan_dolimit(x)                        ((x).chan & USER_DOLIMIT)
+#define glob_dovoice(x)                        ((x).global & USER_DOVOICE)
+#define chan_dovoice(x)                        ((x).chan & USER_DOVOICE)
+#define glob_noflood(x)                        ((x).global & USER_NOFLOOD)
+#define chan_noflood(x)                        ((x).chan & USER_NOFLOOD)
+#define glob_chanhub(x)                        ((x).global & USER_CHANHUB)
+
+void init_flags();
 void get_user_flagrec(struct userrec *, struct flag_record *, const char *);
 void set_user_flagrec(struct userrec *, struct flag_record *, const char *);
 void break_down_flags(const char *, struct flag_record *, struct flag_record *);