ASCII playerfile Clan Snippet [by Ming]
Snippet Posted Sunday, June 6th @ 08:40:26 PM, by George Greer in the Players dept.
Ming writes, " This is a really simple clan framework for those that are using the ascii pfile system. Thought it would be helpful."
here is a really simple clan system devised for circle 3.0b pl 12 and
an ascii pfile system. features include direct writes to the ascii pfile
system - no indexing files are used. this design consideration was
implemented to avoid errors associated with linkouts and crashes
affecting the index files common to all other clan systems. here, if a
player's clan information is corrupt, one only has to edit the errant
pfile. this code does not contain a lot of frills, but serves as a basis
for additions. clan members have clan tell and clan who, while the leader
(designated with the 'assign' command from the implementor - no reboots
needed to implement a clan) has some administrative functions.

enjoy!

riverwind and taerin
kaos clan of wintermute mud
http://mute.starweb.net/

-----------------------------------------------------------------------
in structs.h:

/* clan ranks, taerin 5/30/99 */

#define CLAN_RANK_INITIATE	1
#define CLAN_RANK_APPRENTICE	2
#define CLAN_RANK_MEMBER	3
#define CLAN_RANK_MASTER	4
#define CLAN_RANK_LEADER	5

#define GET_CLAN_NAME(ch)	((ch)->player_specials->saved.clan_name)
#define GET_CLAN_RANK(ch)	((ch)->player_specials->saved.clan_rank)

#define MAX_CLAN_LENGTH	8

-----------------------------------------------------------------------
in structs.h, struct player_special_data_saved:

	char clan_name[MAX_CLAN_LENGTH+1];	/* clan info to be saved, taerin 5/30/99 */
	int  clan_rank;			/* rank within the clan */

-----------------------------------------------------------------------
Save it in db.c, int load_char:

    strcpy(psds->clan_name, "");	/* taerin: initializing clan names */
    psds->clan_rank = 0;		/* taerin: initializing clan ranks */

-----------------------------------------------------------------------
in db.c, int load_char, case 'C':

	else if ( !strcmp(tag, "ClaN") )
	  strcpy( psds->clan_name, line );
	else if ( !strcmp(tag, "ClaR") )
	  psds->clan_rank = num;

-----------------------------------------------------------------------
in db.c, void save_char:

    if ( psds->clan_name )
        fprintf( outfile, "ClaN: %s\n", GET_CLAN_NAME(ch) );

    if ( psds->clan_rank )
        fprintf( outfile, "ClaR: %d\n", (int)psds->clan_rank );

-----------------------------------------------------------------------
in act.informative.c, ACMD(do_score):

char *get_rank_name(int rank);

  /* clan segment */
        if ( GET_CLAN_RANK(ch) > 0 )
        {
                sprintf( buf, "%s      %sYou are a member (%s) of the %s clan.%s\r\n\r\n",
                         buf, CCCYN(ch, C_NRM) ,get_rank_name(GET_CLAN_RANK(ch)),
                         GET_CLAN_NAME(ch), CCNRM(ch, C_NRM) );
        }

-----------------------------------------------------------------------
in act.informative.c, do_who:

    if ( GET_CLAN_RANK(wch) > 0 )
    {
	strcat( buf, CCCYN(ch, C_NRM) );
	strcat( buf, " [" );
	strcat( buf, GET_CLAN_NAME(wch) );
	strcat( buf, "]" );
	strcat( buf, CCNRM(ch, C_NRM) );
    }

-----------------------------------------------------------------------
in act.wizard.c, void do_stat_character:

	sprintf( buf, "Clan: [%s], Rank: [%s]\r\n",
			GET_CLAN_NAME(k), get_rank_name(GET_CLAN_RANK(k)) );
	send_to_char(buf, ch);

-----------------------------------------------------------------------
in interpreter.c:

ACMD(do_assign)
ACMD(do_clan);
ACMD(do_ctell);
ACMD(do_clan_tell);

  { "assign"   , POS_RESTING , do_assign   , LVL_IMPL, 0 },
  { "clan"     , POS_SLEEPING, do_clan     , 0, 0 },
  { "ctell"    , POS_SLEEPING, do_clan_tell, 0, 0 },

-----------------------------------------------------------------------
in Makefile:

OBJFILES list, add clan.o
CXREF_FILES list, add clan.c

clan.o  : clan.c conf.h sysdep.h structs.h utils.h comm.h db.h interpreter.h handler.h screen.h
        $(CC) -c $(CFLAGS) clan.c

-----------------------------------------------------------------------
and a new file, clan.c:

/*
    clan.c
    wintermute mud
    circlemud 3.0bpl12
    ascii pfile system
    taerin and riverwind 5/29/99
*/

#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "db.h"
#include "interpreter.h"
#include "handler.h"
#include "screen.h"

void do_clan_who( struct char_data *ch );
void do_clan_tell( struct char_data *ch, char *msg );
void do_clan_dismiss( struct char_data *ch, struct char_data *victim );
void do_clan_enlist( struct char_data *ch, struct char_data *victim );
void do_clan_promote( struct char_data *ch, struct char_data *victim );
void do_clan_demote( struct char_data *ch, struct char_data *victim );

char *get_rank_name(int rank);

extern struct descriptor_data *descriptor_list;

/* to set up a new clan, implmentor needs to:

    assign  

*/


ACMD(do_clan)
{
    struct char_data *victim = NULL;
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];

    if ( !*GET_CLAN_NAME(ch) )
    {
        send_to_char( "You do not belong to any clan.\r\n", ch );
        return;
    }

    half_chop( argument, arg1, arg2 );

    if ( !*arg1 )
    {
        send_to_char( "Usage: clan [ who | tell | resign ]\r\n", ch );

        if ( GET_CLAN_RANK(ch) == CLAN_RANK_LEADER )
        {
            send_to_char( "Also:  clan [ enlist | dismiss | promote | demote ] victim\r\n", ch );
        }

        if ( GET_LEVEL(ch) == LVL_IMPL )
        {
            send_to_char( "Assign leaders: assign  \r\n", ch );
        }

        return;
    }

    /* perform general level functions first */

    if ( is_abbrev( arg1, "who" ) )
    {
        do_clan_who( ch );
        return ;
    }

    if ( is_abbrev( arg1, "tell" ) )
    {
        do_clan_tell( ch, arg2 );
        return ;
    }

    if ( is_abbrev( arg1, "resign" ) )
    {
        do_clan_dismiss( ch, ch );
        return ;
    }

    /* now perform privileged functions */

    if ( GET_CLAN_RANK(ch) != CLAN_RANK_LEADER )
    {
        send_to_char( "You do not have the authority to reorganize the clan.\r\n", ch );
        return;
    }

    if ( !(victim = get_char_room_vis( ch, arg2 )) )
    {
        send_to_char( "That person is not available.\r\n", ch );
        return;
    }

    if ( GET_LEVEL(victim) > (LVL_IMMORT - 1) )
    {
        send_to_char( "Immortals cannot join clans!\r\n", ch );
        return;
    }

    if ( is_abbrev( arg1, "enlist" ) )
    {
        do_clan_enlist( ch, victim );
        return ;
    }

    if ( strcmp(GET_CLAN_NAME(victim), GET_CLAN_NAME(ch)) ) 
    {
        send_to_char( "That person is not in your clan!\r\n", ch );
        return;
    }

    if ( is_abbrev( arg1, "dismiss" ) )
    {
        do_clan_dismiss( ch, victim );
        return ;
    }

    if ( is_abbrev( arg1, "promote" ) )
    {
        do_clan_promote( ch, victim );
        return ;
    }

    if ( is_abbrev( arg1, "demote" ) )
    {
        do_clan_demote( ch, victim );
        return ;
    }
}

void do_clan_who( struct char_data *ch )
{
    struct descriptor_data *d;

    sprintf( buf, "\r\n%s%s clan members online\r\n====/=====================-%s\r\n",
            CCBLU(ch, C_NRM), GET_CLAN_NAME(ch), CCNRM(ch, C_NRM) );
    send_to_char( buf, ch );

    for ( d = descriptor_list; d; d = d->next )
    {
        if (d->connected)
        {
            continue;
        }

        if ( !strcmp(GET_CLAN_NAME(d->character), GET_CLAN_NAME(ch)) )
        {
            sprintf( buf, "%s\r\n", GET_NAME(d->character) );
            send_to_char( buf, ch );
        }
    }

    return;
}

void do_clan_tell( struct char_data *ch, char *msg )
{
    struct descriptor_data *d;

    if ( GET_CLAN_RANK( ch ) < 1 )
    {
        send_to_char( "You need to be an initiate or higher in a clan.\r\n", ch );
        return;
    }

    for ( d = descriptor_list; d; d = d->next )
    {
        if (d->connected)
        {
            continue;
        }

        if ( !strcmp(GET_CLAN_NAME(d->character), GET_CLAN_NAME(ch)) )
        {
            *buf = '\0';

            if ( GET_NAME(d->character) == GET_NAME(ch) )
            {
                sprintf( buf, "%sYou tell the clan, ' %s '%s\r\n",
                    CCCYN(ch, C_NRM), msg, CCNRM(ch, C_NRM) );
                send_to_char( buf, d->character );

            }
            else
            {
                sprintf( buf, "%s%s tells the clan, ' %s '%s\r\n",
                    CCCYN(ch, C_NRM), GET_NAME(ch), msg, CCNRM(ch, C_NRM) );
                send_to_char( buf, d->character );
            }
        }
    }

    return;

}

void do_clan_enlist( struct char_data *ch, struct char_data *victim )
{
    char lbuf[1024];

    if ( !GET_CLAN_RANK(victim) )
    {
        strcpy(GET_CLAN_NAME(victim), GET_CLAN_NAME(ch));
        GET_CLAN_RANK(victim) = CLAN_RANK_INITIATE;

        *lbuf = '\0';

        sprintf( lbuf, "%sWelcome the newest intitiate of %s, %s!%s",
             CCRED(ch, C_NRM), GET_CLAN_NAME(ch), GET_NAME(victim), CCNRM(ch, C_NRM) );
        do_clan_tell(ch, lbuf);
    }
    else
    {
        send_to_char( "That person already belongs to a clan..\r\n", ch );
    }
    return;
}

void do_clan_dismiss( struct char_data *ch, struct char_data *victim )
{
    char lbuf[1024];

    *lbuf = '\0';

    sprintf( lbuf, "%s%s has been dismissed from the clan!%s",
         CCRED(ch, C_NRM), GET_NAME(victim), CCNRM(ch, C_NRM) );
    do_clan_tell(ch, lbuf);

    strcpy(GET_CLAN_NAME(victim), "");
    GET_CLAN_RANK(victim) = 0;

    return;
}

void do_clan_promote( struct char_data *ch, struct char_data *victim )
{
    char lbuf[1024];

    if ( GET_CLAN_RANK(victim) < CLAN_RANK_MASTER )
    {
        GET_CLAN_RANK(victim)++;

        *lbuf = '\0';

        sprintf( lbuf, "%s%s has been promoted in rank to %s!%s",
             CCRED(ch, C_NRM), GET_NAME(victim),
             get_rank_name(GET_CLAN_RANK(victim)), CCNRM(ch, C_NRM) );
        do_clan_tell(ch, lbuf);
    }
    else
    {
        send_to_char( "You can not promote this person any further.\r\n", ch );
    }
    return;
}

void do_clan_demote( struct char_data *ch, struct char_data *victim )
{
    char lbuf[1024];

    if ( GET_CLAN_RANK(victim) > CLAN_RANK_INITIATE )
    {
        GET_CLAN_RANK(victim)--;

        *lbuf = '\0';

        sprintf( lbuf, "%s%s has been demoted in rank to %s!%s",
             CCRED(ch, C_NRM), GET_NAME(victim),
             get_rank_name(GET_CLAN_RANK(victim)), CCNRM(ch, C_NRM) );
        do_clan_tell(ch, lbuf);
    }
    else
    {
        send_to_char( "You can not demote this person any further!\r\n", ch );
    }
   
    return;
}

/* reserved for the implementor only */
ACMD(do_assign)
{
    struct char_data *victim = NULL;
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];

    half_chop( argument, arg1, arg2 );

    if ( !*arg1 || !*arg2 )
    {
        send_to_char( "Usage: assign  \r\n", ch);
        return;
    }

    if ( !(victim = get_char_room_vis( ch, arg2 )) )
    {
        send_to_char( "That person is not available.\r\n", ch );
        return;
    }

    if ( GET_CLAN_RANK(victim) )
    {
        send_to_char( "Can not designate someone already in a clan!\r\n", ch);
        return;
    }

    if ( strlen(arg1) < (MAX_CLAN_LENGTH + 1) )
    {
      strcpy(GET_CLAN_NAME(victim), arg1);
      GET_CLAN_RANK(victim) = 5;

      sprintf( buf, "Assigning clan %s to %s.\r\n", GET_CLAN_NAME(victim), GET_NAME(victim) );
      send_to_char( buf, ch );
    }
    else
    {
        send_to_char( "That clan name exceeds the maximum length allowed.\r\n", ch );
    }

}


char *get_rank_name(int rank)
{
    switch (rank)
    {
        case 1: return "Initiate"; break;
        case 2: return "Apprentice"; break;
        case 3: return "Member"; break;
        case 4: return "Master"; break;
        case 5: return "Leader"; break;
        default: return "Uninitiated"; break;
    }
}

<< Compare Command [by Karl Matthias] | Reply | View as text | Flattened | GDB Manual (Fifth Ed.) >>

 


Related Links
  CircleMUD
Ming
Related Articles
More by greerga
 
 

CircleMUD Snippets
 
Note: Not all of these snippets will work perfectly with your version of code, so be prepared to fix one or two bugs that may arise, and please let me know what you needed to do to fix it. Sending a corrected version is always welcome.
Finally, if you wish to use any of the snippets from this page, you are more than welcome, just mention the authors in your credits. If you wish to release any of these snippets to the public on another site, contact me FIRST.