CODE: Clans...

From: Corey Hoitsma (choitsma@netcom.com)
Date: 07/01/96


I'll attach my clan file, and I hope SOMEONE can give me some
insight on this.

First problem:

	It doesn't read the clan file at boot up... well,
	it's SUPPOSE to, I've added load_clans(): after
	load_banned(); but whenever I do clans(which shows all
	the clans) it says no clans made. I've made the 
	#define FILE_CLANS "misc/clans" etc too..
	Then whenever I do makeclan blah blah then do clans
	it crashes. Any ideas why?

Second problem:

	Shees, can't rember the second one... slipped my mind:P

Thanks for any help!

Corey Hoitsma                   AKA -= Myrddin =-
             choitsma@netcom.com
Tazmania			tazmania.ah.net 7000
==============================================================================
Content-ID: <Pine.3.89.9607012156.A29043@netcom18>
Content-Description: 

/* *	*	*	*	*
	A clan file, mayde by Myrddin
*	*	*	*	*/

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

struct clan_list_element *clan_list = NULL;
int number_clans = 0;

char *clan_types[] = {
	"MAGE",
	"WARRIOR",
	"THIEF",
	"CLERIC",
	"KNIGHT",
	"OPEN",
	"*ERROR*"
};

void load_clans(void)
{
	FILE *fl;
	int i, clan_date, clan_num;
	char clan_leader[80], clan_type[10];
	char clan_name[80];
	struct clan_list_element *next_node;

clan_list = 0;

  if (!(fl = fopen(CLAN_FILE, "r"))) {
    perror("Unable to open clan file");
    return; }
	
/* NUM, TYPE, CLAN NAME, LEADER, MADE */

while(fscanf(fl, " %d %s %s %d %s ", &clan_num, clan_type, clan_name, &clan_date, clan_leader) == 4) {
    CREATE(next_node, struct clan_list_element, 1);
    strncpy(next_node->name, clan_name, 80);
    next_node->name[80] = '\0';
    strncpy(next_node->leader, clan_leader, MAX_NAME_LENGTH);
    next_node->name[MAX_NAME_LENGTH] = '\0';
    next_node->date = clan_date;
    next_node->number = clan_num;	

    for (i = CLAN_MAGE; i <= CLAN_OPEN; i++)
      if (!strcmp(clan_type, clan_types[i]))
        next_node->type = i;

	number_clans++;
    next_node->next = clan_list;
    clan_list = next_node;
  }
fclose(fl);
}

void _write_one_clan_node(FILE * fp, struct clan_list_element * node)
{
  if (node) {
    _write_one_clan_node(fp, node->next);
    fprintf(fp, " %d %s %s %ld %s\n", node->number, clan_types[node->type],
            node->name, (long) node->date, node->leader);
  }
}

void write_clan_list(void)
{
  FILE *fl;
 
  if (!(fl = fopen(CLAN_FILE, "w"))) {
    perror("write_clan_list");
    return;
  }
  _write_one_clan_node(fl, clan_list);/* recursively write from end to 
start */
  fclose(fl);
  return;
}

ACMD(do_clans)
{
  char clan[MAX_INPUT_LENGTH],
        format[MAX_INPUT_LENGTH], *timestr;
  struct clan_list_element *clan_node;
 
load_clans();

  *buf = '\0';
 
  if (!*argument) {
    if (!clan_list) {
      send_to_char("No clans are made.\r\n", ch);
      return;
    }
    strcpy(format, "%-5.5s %-15.15s  %-10.10s  %-10.10s  %-16.16s\r\n");
    sprintf(buf, format,
 	    "Clan Number",
            "Clan Name",
            "Clan Type",
            "When Made",
            "Clan Leader");
    send_to_char(buf, ch);
    sprintf(buf, format,
            "---------------------------------",
            "---------------------------------",
            "---------------------------------",
            "---------------------------------");
    send_to_char(buf, ch);
 
    for (clan_node = clan_list; clan_node; clan_node = clan_node->next) {
      if (clan_node->date) {
        timestr = asctime(localtime(&(clan_node->date)));
        *(timestr + 10) = 0;
        strcpy(clan, timestr);
      } else
        strcpy(clan, "Unknown");
      sprintf(buf, format, (char)clan_node->number, clan_node->name, 
clan_types[clan_node->type], clan, clan_node->leader);
      send_to_char(buf, ch);
    }
    return;
  }
}

ACMD (do_makeclan)
{
  char flag[MAX_INPUT_LENGTH], clan[MAX_INPUT_LENGTH], leader[MAX_INPUT_LENGTH];
  char *nextchar;
  int i, number;
  struct clan_list_element *clan_node;
 
  *buf = '\0';

  three_arguments(argument, flag, clan, leader);
  if (!*clan || !*flag || !*leader) {
    send_to_char("Usage: makeclan {CLASS | OPEN} clan_name leader\r\n", ch);
    return;
  }
  if (!(!str_cmp(flag, "m") || !str_cmp(flag, "w") || 
!str_cmp(flag, "t") || !str_cmp(flag, "c") || !str_cmp(flag, "k") || 
!str_cmp(flag, "o"))) {
    send_to_char("Flag must be M, W, T, C, K or O.\r\n", ch);
    return;
  }
  for (clan_node = clan_list; clan_node; clan_node = clan_node->next) {
    if (!str_cmp(clan_node->name, clan)) {
	send_to_char("That clan is already made!\r\n", ch);
      return;
    }
  }
 number = number_clans;
 number++; 

  CREATE(clan_node, struct clan_list_element, 1);
  clan_node->number = number;
  strncpy(clan_node->name, clan, 80);
/*  for (nextchar = clan_node->name; *nextchar; nextchar++)
    *nextchar = LOWER(*nextchar);*/
  clan_node->name[80] = '\0';
  strncpy(clan_node->leader, leader, MAX_NAME_LENGTH);
  clan_node->leader[MAX_NAME_LENGTH] = '\0';
  clan_node->date = time(0);
 
  for (i = CLAN_MAGE; i <= CLAN_OPEN; i++)
    if (!str_cmp(flag, clan_types[i]))
      clan_node->type = i;
 
  clan_node->next = clan_list;
  clan_list = clan_node;
 
  sprintf(buf, "%s has made a new clan [%s], leader [%s] for %s players.", 
GET_NAME(ch), clan, leader,
          clan_types[clan_node->type]);
  mudlog(buf, NRM, MAX(LVL_GOD, GET_INVIS_LEV(ch)), TRUE);
  send_to_char("Clan Made.\r\n", ch);
  write_clan_list();
}


ACMD(do_rmclan)
{
  char clan[80];
  struct clan_list_element *clan_node, *temp;
  int found = 0;
 
  one_argument(argument, clan);
  if (!*clan) {
    send_to_char("A clan name might help.\r\n", ch);
    return;
  }
  clan_node = clan_list;
  while (clan_node && !found) {
    if (!str_cmp(clan_node->name, clan))
      found = 1;
    else
      clan_node = clan_node->next;
  }
 
  if (!found) {
    send_to_char("That clan isn't even made yet!\r\n", ch);
    return;
  }
  REMOVE_FROM_LIST(clan_node, clan_list, next);
  send_to_char("Clan removed.\r\n", ch);
  sprintf(buf, "%s removed the %s clan.",
          GET_NAME(ch), clan_node->name);
  mudlog(buf, NRM, MAX(LVL_GOD, GET_INVIS_LEV(ch)), TRUE);
 
  free(clan_node);
  write_clan_list();
}



This archive was generated by hypermail 2b30 : 12/07/00 PST