/* Calisto (c) 1998-1999 Peter Howkins, Matthew Howkins, Simon Howkins $Id: privs.c,v 1.5 2000/01/13 21:14:39 peter Exp $ $Log: privs.c,v $ Revision 1.5 2000/01/13 21:14:39 peter Changed privs from numeric to string, changed function prototypes Revision 1.4 2000/01/02 15:37:02 peter Changed PRIV_AD_GENERAL to PRIV_AD_BASE and added PRIV_SU_BASE Revision 1.3 1999/12/20 20:54:09 peter Added clearpriv(), privname_to_priv(), and other small changes Revision 1.2 1999/12/12 16:28:38 peter Added priv a_general Revision 1.1 1999/11/29 22:05:17 peter Initial revision */ static char rcsid[] = "$Id: privs.c,v 1.5 2000/01/13 21:14:39 peter Exp $"; #include "library.h" #include "privs.h" #include "strplus.h" #include "structs.h" #define RANK_GUEST 1 #define RANK_RESIDENT 2 #define RANK_SU 3 #define RANK_LA 4 #define RANK_ADMIN 5 #define RANK_HA 6 /* basic guest and ressie privs */ #define PRIV_BASE (1 << 0) #define PRIV_TALK (1 << 1) #define PRIV_SAVE (1 << 2) #define PRIV_BS1 (1 << 3) #define PRIV_BS2 (1 << 4) #define PRIV_BS3 (1 << 5) #define PRIV_BS4 (1 << 6) #define PRIV_BS5 (1 << 7) #define PRIV_BS6 (1 << 8) #define PRIV_BS7 (1 << 9) /* su privs */ #define PRIV_SU_BASE (1 << 10) #define PRIV_SU_BUMP (1 << 11) #define PRIV_SU_TRACE (1 << 12) #define PRIV_SUS2 (1 << 13) #define PRIV_SUS3 (1 << 14) #define PRIV_SUS4 (1 << 15) #define PRIV_SUS5 (1 << 16) #define PRIV_SUS6 (1 << 17) #define PRIV_SUS7 (1 << 18) #define PRIV_SUS8 (1 << 19) /* admin privs */ #define PRIV_AD_BASE (1 << 20) #define PRIV_AD_SHUTDOWN (1 << 21) #define PRIV_AD_GRANT (1 << 22) #define PRIV_ADS2 (1 << 23) #define PRIV_ADS3 (1 << 24) #define PRIV_ADS4 (1 << 25) #define PRIV_ADS5 (1 << 26) #define PRIV_ADS6 (1 << 27) #define PRIV_ADS7 (1 << 28) #define PRIV_ADS8 (1 << 29) /* spare privs */ #define PRIV_S30 (1 << 30) #define PRIV_S31 (1 << 31) /* combination privs */ #define C_PRIV_GUEST (PRIV_TALK | PRIV_BASE) #define C_PRIV_RESIDENT (C_PRIV_GUEST | PRIV_SAVE) #define C_PRIV_SU (C_PRIV_RESIDENT | PRIV_SU_TRACE | PRIV_SU_BUMP | \ PRIV_SU_BASE) #define C_PRIV_LA (C_PRIV_SU) #define C_PRIV_ADMIN (C_PRIV_LA | PRIV_AD_BASE) #define C_PRIV_HA (C_PRIV_ADMIN | PRIV_AD_SHUTDOWN | PRIV_AD_GRANT) typedef struct { const char *rankname; const int rank; } rank; typedef struct { const char *privname; const unsigned long priv; const char *col; } priv; static const rank ranks[] = { { "guest", RANK_GUEST }, { "resident", RANK_RESIDENT }, { "su", RANK_SU }, { "ladmin", RANK_LA }, { "admin", RANK_ADMIN }, { "hadmin", RANK_HA }, }; static const unsigned rankn = sizeof ranks / sizeof(rank); static const priv privs[] = { /* basic guest and ressie privs */ { "n_base", PRIV_BASE, "^n" }, { "n_talk", PRIV_TALK, "^n" }, { "n_save", PRIV_SAVE, "^n" }, /* su privs */ { "s_base", PRIV_SU_BASE, "^c" }, { "s_trace", PRIV_SU_TRACE, "^c" }, { "s_bump", PRIV_SU_BUMP, "^c" }, /* admin privs */ { "a_base", PRIV_AD_BASE, "^r" }, { "a_shutdown", PRIV_AD_SHUTDOWN,"^P" }, { "a_grant", PRIV_AD_GRANT, "^P" }, /* combination privs */ { "guest", C_PRIV_GUEST, "^n" }, { "resident", C_PRIV_RESIDENT, "^n" }, { "su", C_PRIV_SU, "^c" }, { "la", C_PRIV_LA, "^b" }, { "admin", C_PRIV_ADMIN, "^r" }, { "ha", C_PRIV_HA, "^P" } }; static const unsigned privn = sizeof privs / sizeof(priv); /* Takes a priv name, and returns a priv pointer, or NULL if not found */ static const priv *privname_to_priv(const char *privname) { unsigned i; for (i = 0; i < privn; i++) { if (STRIEQ(privname, privs[i].privname)) return &privs[i]; } return NULL; } bool privname_exists(const char *privname) { return (privname_to_priv(privname) != NULL); } bool haspriv(const character *c, const char *privname) { const priv *p = privname_to_priv(privname); if (p) { return (c->privs & p->priv); } else { return FALSE; } } void setpriv(character *c, const char *privname) { const priv *p = privname_to_priv(privname); if (p) c->privs |= p->priv; } void clearpriv(character *c, const char *privname) { const priv *p = privname_to_priv(privname); if (p) c->privs &= ~p->priv; } const char *privcol(const char *privname) { const priv *p = privname_to_priv(privname); if (p) { return p->col; } else { return NULL; } } void privs_list_all(character *c) { unsigned i; for (i = 0; i < privn; i++) send_to_char(c, "%s%s^n ", privs[i].col, privs[i].privname); } void privs_list_player(character *c, character *target) { unsigned i; for (i = 0; i < privn; i++) if (target->privs & privs[i].priv) send_to_char(c, " %s%s", privs[i].col, privs[i].privname); send_to_char(c, "^n %08lx", target->privs); }