acfamily.c
上传用户:qys8201
上传日期:2021-12-11
资源大小:978k
文件大小:117k
源码类别:

模拟服务器

开发平台:

C/C++

  1. #define _FAMILY_C_
  2. #include "version.h"
  3. #include "main.h"
  4. #include "acfamily.h"
  5. #include "util.h"
  6. #include "saacproto_serv.h"
  7. #include <malloc.h>
  8. #include <stdio.h>
  9. #include <time.h>
  10. #include <sys/types.h>
  11. #include <dirent.h>
  12. #include <sys/stat.h>
  13. // 家族 Int 资料
  14. static char* FAMILY_INTDATA[familymaxint] = 
  15. {
  16.   "fmindex",
  17.   "fmleadergrano",
  18.   "fmnum",
  19.   "fmjoinnum",
  20.   "fmacceptflag",
  21.   "fmsetupflag",
  22.   "fmsprite",
  23.   "fmpointindex",
  24.   "fmpopular",
  25.   "fmgold",
  26.   "fmmemberindexmaxnum",
  27.   "apply_time",
  28.   "setup_time",
  29.   "predel_time",
  30.   "memonowwritenum",
  31.   "memonum",
  32. "fmadv",
  33.   "fmfeed",
  34.   "fmsynthesize",
  35.   "fmdealfood",
  36.   "fmpk",
  37. #ifdef _NEW_MANOR_LAW
  38. "fmmomentum",
  39. #endif
  40. };
  41. // 家族 char 资料
  42. static char* FAMILY_CHARDATA[familymaxchar] = 
  43. {
  44.   "fmname",
  45.   "fmleadername",
  46.   "fmleaderid",
  47.   "petname",
  48.   "petattr",
  49.   "fmrule",
  50. };
  51. // 家族成员 int 资料
  52. static char* MEMBER_INTDATA[memberdatamaxint] = 
  53. {
  54. "charlv",
  55. "charflag",
  56. "onlineflag",
  57. "charfdid",
  58. "predeltime",
  59. "popular",
  60. #ifdef _FMVER21
  61. "eventflag",
  62. #endif
  63. #ifdef _NEW_MANOR_LAW
  64. "momentum",
  65. #endif
  66. };
  67. // 家族成员 char 资料
  68. static char* MEMBER_CHARDATA[memberdatamaxchar] = 
  69. {
  70. "charname",
  71. "charid",
  72. };
  73. // 成员种类 char 资料
  74. static char* MEMBERKIND_INTDATA[FMMEMBER_KINDNUM] = 
  75. {
  76. "无",
  77. "一般成员",
  78. "申请中",
  79. "族长",
  80. "长老",
  81. };
  82. // 家族之间留言板
  83. struct FMSMEMO
  84. {
  85.    int  num; // 留言数量
  86.    int fmsnowwritenum; // 目前留言位置
  87.    char memodata[FMSMEMONUM][FAMILY_MEMOLEN]; // 留言内容
  88. };
  89. // 庄园
  90. struct FMPOINT
  91. {
  92.    int fl; // 庄园进入图层
  93.    int x; // 庄园进入X座标
  94.    int y; // 庄园进入Y座标
  95.    int fmfl; // 庄园族长图层
  96.    int  village; // 庄园邻近之村庄
  97.    int hadfmindex; // 占领庄园之家族 index
  98.    char hadfmname[CHARNAME_MAX]; // 占领庄园之家族 name
  99.    int hadfmpopular; // 占领庄园之家族综合声望值
  100. };
  101. // 家族成员资料
  102. typedef struct
  103. {
  104.    char charname[CHARNAME_MAX]; // 成员名字
  105.    char charid[USERID_MAX]; // 成员帐号
  106.    int charlv; // 成员等级
  107.    int  charflag; /* 
  108.        FMMEMBER_NONE   清空资料
  109.        FMMEMBER_MEMBER 家族成员
  110.        FMMEMBER_APPLY  申请中
  111.        FMMEMBER_LEADER 族长
  112.        FMMEMBER_ELDER  长老
  113.                                         */
  114.    int onlineflag; // 0:offline; gmsv index
  115.    int charfdid; // 成员在 gmsv 的 fd
  116.    int predeltime; // 预计删除成员时间
  117.    int  popular; // 成员的声望
  118. #ifdef _FMVER21
  119.    int eventflag; // 是否拥有族长资格
  120. #endif
  121. #ifdef _NEW_MANOR_LAW
  122.  int momentum; // 成员气势
  123. #endif
  124. #ifdef _FM_MODIFY
  125.  int gsnum; // 记录玩家是在那一个game server
  126. #endif
  127. }  MEMBERDATA;
  128. struct FAMILY
  129. {
  130.    int  fmindex; // 家族 index
  131.    char fmname[CHARNAME_MAX]; // 家族名称
  132.    char fmleadername[CHARNAME_MAX]; // 族长名称
  133.    char fmleaderid[USERID_MAX]; // 族长帐号
  134.    int fmleadergrano; // 族长照片
  135.    char petname[CHARNAME_MAX]; // 守护兽名称
  136.    char petattr[256]; // 守护兽资料
  137.    int fmnum;  // 家族人数,包含申请退出、加入人数
  138.    int fmjoinnum;  // 真正加入家族人数
  139.    int fmacceptflag;  // 是否接收成员 0:不接受 1:接受
  140.    int fmsetupflag;  // 0:尚未成立 1:已成立
  141.    char fmrule[256]; // 家族主旨
  142.    int fmsprite;  // 0:光明精灵 1:黑暗精灵
  143.    int fmpointindex; // 家族据点 index
  144.    int  fmpopular; // 家族综合声望
  145. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  146.    int fmtotalfame; // 家族综合 + 家族个人声望总合
  147. #endif
  148. #ifdef _NEW_MANOR_LAW
  149.  int fmmomentum; // 家族气势
  150. #endif
  151.    int fmgold; // 家族基金
  152.    int fmmemberindexmaxnum; // 家族目前最大人数
  153.    int apply_time; // 家族申请时间
  154.    int setup_time; // 家族成立时间
  155.    int predel_time; // 预计删除家族时间
  156.    int memonowwritenum; // 目前留言位置
  157.    int  memonum; // 留言数量
  158.    int fmadv; // 冒险任务声望
  159.    int fmfeed; // 饲育声望
  160.    int fmsynthesize; // 合成加工声望
  161.    int fmdealfood; // 料理声望
  162.    int fmpk; // PK声望
  163.    char memolist[FAMILY_MEMONUM][FAMILY_MEMOLEN]; // 留言内容
  164.    MEMBERDATA fmmemberindex[MAX_MEMBERNUM]; // 成员资料
  165. };
  166. int db_familyupdate[MAX_FAMILY]={0};
  167. int db_fmpointupdate = 0;
  168. int db_fmsmemoupdate = 0;
  169. int fmnownum = 0;
  170. int fmindexmaxnum = 0;
  171. extern gmsv gs[MAXCONNECTION];
  172. struct FAMILY family[MAX_FAMILY];
  173. int fmpopularindex[MAX_FAMILY]; // Arminius: sort family
  174. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  175. int fmtotalfameindex[MAX_FAMILY];
  176. #endif
  177. #ifdef _NEW_MANOR_LAW
  178. int fmMomentumIndex[MAX_FAMILY];
  179. #endif
  180. int fmadvindex[MAX_FAMILY];
  181. int fmfeedindex[MAX_FAMILY];
  182. int fmsynthesizeindex[MAX_FAMILY];
  183. int fmdealfoodindex[MAX_FAMILY];
  184. int fmpkindex[MAX_FAMILY];
  185. struct FMPOINT fmpoint[MAX_FMPOINT];
  186. struct FMSMEMO fmsmemo;
  187. // Arminius: sort family & output the sorted list
  188. // Make a sorted index (fmindex) for the family data (family)
  189. #ifdef _NEW_MANOR_LAW
  190. int fmMomentumcompar(const void *indexa, const void *indexb);
  191. #endif
  192. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  193. int fmtotalfamecompar(const void *indexa, const void *indexb);
  194. #endif
  195. int fmpopularcompar(const void *indexa, const void *indexb);
  196. int fmadvcompar(const void *indexa, const void *indexb);
  197. int fmfeedcompar(const void *indexa, const void *indexb);
  198. int fmsynthesizecompar(const void *indexa, const void *indexb);
  199. int fmdealfoodcompar(const void *indexa, const void *indexb);
  200. int fmpkcompar(const void *indexa, const void *indexb);
  201. int CheckFM(int *index, char *fmname, int fmindex);
  202. int CheckFMUse(int index);
  203. void setFamilyFileDataToArg(int index, char *data);
  204. void setMemberFileDataToArg(int index, int memberindex, char *databuf);
  205. // sortFamily: call this after family loaded
  206. void sortFamily(void)
  207. {
  208.   int i;
  209.   for(i = 0; i < MAX_FAMILY; i++)
  210.   {
  211. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  212. fmtotalfameindex[i] = i;
  213. #endif
  214. #ifdef _NEW_MANOR_LAW
  215. fmMomentumIndex[i] = i;
  216. #endif
  217.    fmpopularindex[i] = i;
  218.    fmadvindex[i] = i;
  219.    fmfeedindex[i] = i;
  220.    fmsynthesizeindex[i] = i;
  221.    fmdealfoodindex[i] = i;
  222.    fmpkindex[i] = i;
  223.   }
  224. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  225.   qsort(fmtotalfameindex, MAX_FAMILY, sizeof(int), &fmtotalfamecompar);
  226. #endif
  227.   qsort(fmpopularindex, MAX_FAMILY, sizeof(int), &fmpopularcompar);
  228.   qsort(fmadvindex, MAX_FAMILY, sizeof(int), &fmadvcompar);
  229.   qsort(fmfeedindex, MAX_FAMILY, sizeof(int), &fmfeedcompar);
  230.   qsort(fmsynthesizeindex, MAX_FAMILY, sizeof(int), &fmsynthesizecompar);
  231.   qsort(fmdealfoodindex, MAX_FAMILY, sizeof(int), &fmdealfoodcompar);
  232.   qsort(fmpkindex, MAX_FAMILY, sizeof(int), &fmpkcompar);
  233. #ifdef _NEW_MANOR_LAW
  234. qsort(fmMomentumIndex,MAX_FAMILY,sizeof(int),&fmMomentumcompar);
  235. #endif
  236. }
  237. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  238. int fmtotalfamecompar(const void *indexa, const void *indexb)
  239. {
  240.   int famea,fameb;
  241.   
  242.   if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record
  243.   if ( CheckFMUse(* (int*) indexb)==0 ) return -1;
  244.   famea = family[ * (int*) indexa ].fmtotalfame;
  245.   fameb = family[ * (int*) indexb ].fmtotalfame;
  246.   return (famea>fameb)? -1 : 1;
  247. }
  248. #endif
  249. #ifdef _NEW_MANOR_LAW
  250. int fmMomentumcompar(const void *indexa, const void *indexb)
  251. {
  252.   int momentumA,momentumB;
  253.   
  254.   if(CheckFMUse(*(int*)indexa) == 0) return 1; // empty record
  255.   if(CheckFMUse(*(int*)indexb) == 0) return -1;
  256.   momentumA = family[*(int*)indexa].fmmomentum;
  257.   momentumB = family[*(int*)indexb].fmmomentum;
  258.   return (momentumA > momentumB) ? -1:1;
  259. }
  260. #endif
  261. int fmpopularcompar(const void *indexa, const void *indexb)
  262. {
  263.   int fmpopulara,fmpopularb;
  264.   
  265.   if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record
  266.   if ( CheckFMUse(* (int*) indexb)==0 ) return -1;
  267.   fmpopulara = family[ * (int*) indexa ].fmpopular;
  268.   fmpopularb = family[ * (int*) indexb ].fmpopular;
  269.   return (fmpopulara>fmpopularb)? -1 : 1;
  270. }
  271. int fmadvcompar(const void *indexa, const void *indexb)
  272. {
  273.   int fmadva,fmadvb;
  274.   
  275.   if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record
  276.   if ( CheckFMUse(* (int*) indexb)==0 ) return -1;
  277.   fmadva = family[ * (int*) indexa ].fmadv;
  278.   fmadvb = family[ * (int*) indexb ].fmadv;
  279.   return (fmadva>fmadvb)? -1 : 1;
  280. }
  281. int fmfeedcompar(const void *indexa, const void *indexb)
  282. {
  283.   int fmfeeda,fmfeedb;
  284.   
  285.   if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record
  286.   if ( CheckFMUse(* (int*) indexb)==0 ) return -1;
  287.   fmfeeda = family[ * (int*) indexa ].fmfeed;
  288.   fmfeedb = family[ * (int*) indexb ].fmfeed;
  289.   return (fmfeeda>fmfeedb)? -1 : 1;
  290. }
  291. int fmsynthesizecompar(const void *indexa, const void *indexb)
  292. {
  293.   int fmsynthesizea,fmsynthesizeb;
  294.   
  295.   if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record
  296.   if ( CheckFMUse(* (int*) indexb)==0 ) return -1;
  297.   fmsynthesizea = family[ * (int*) indexa ].fmsynthesize;
  298.   fmsynthesizeb = family[ * (int*) indexb ].fmsynthesize;
  299.   return (fmsynthesizea>fmsynthesizeb)? -1 : 1;
  300. }
  301. int fmdealfoodcompar(const void *indexa, const void *indexb)
  302. {
  303.   int fmdealfooda,fmdealfoodb;
  304.   
  305.   if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record
  306.   if ( CheckFMUse(* (int*) indexb)==0 ) return -1;
  307.   fmdealfooda = family[ * (int*) indexa ].fmdealfood;
  308.   fmdealfoodb = family[ * (int*) indexb ].fmdealfood;
  309.   return (fmdealfooda>fmdealfoodb)? -1 : 1;
  310. }
  311. int fmpkcompar(const void *indexa, const void *indexb)
  312. {
  313.   int fmpka,fmpkb;
  314.   
  315.   if ( CheckFMUse(* (int*) indexa)==0 ) return 1; // empty record
  316.   if ( CheckFMUse(* (int*) indexb)==0 ) return -1;
  317.   fmpka = family[ * (int*) indexa ].fmpk;
  318.   fmpkb = family[ * (int*) indexb ].fmpk;
  319.   return (fmpka>fmpkb)? -1 : 1;
  320. }
  321. // getFMsortedlist
  322. // arg: buf=returned list (format: "index 名次 家族名 族长名 popular|...")
  323. //      bufsize=sizeof(buf)
  324. //      bp=begin point (bp=-1 -> begin at 0)
  325. //      ep=end point   (ep=-1 -> end at MAX_FAMILY-1)
  326. // ret: 1=success; 0=failed
  327. // Arminius end
  328. // 取得家族各声望值列表
  329. // kindflag 1:综合 2:冒险 3:饲育 4:合成 5:料理 6:PK 7:总合(综合+个人)
  330. int ACShowTopFMList(char *data, int datasize, int kindflag)
  331. {
  332.    int i = 0, j = 0;
  333.    char t1[4096];
  334.    
  335.    strcpy(data, "");
  336.    if (kindflag == 1)
  337.    {
  338.       for (i = 0; i < MAX_FAMILY; i++) {
  339.          if (strcmp(family[fmpopularindex[i]].fmname, "") == 0)
  340.          {
  341.           j++;
  342.           continue;
  343.          }
  344. #ifdef _PERSONAL_FAME   // Arminius: 家族个人声望
  345. #ifdef _NEW_MANOR_LAW
  346.  sprintf(t1, "%d|%d|%s|%s|%d|%d|%d",fmtotalfameindex[i], i + 1,
  347.           family[fmtotalfameindex[i]].fmname,
  348.           family[fmtotalfameindex[i]].fmleadername,
  349.        (family[fmtotalfameindex[i]].fmpopular / 100),
  350.        (family[fmtotalfameindex[i]].fmtotalfame / 100),
  351. (family[fmtotalfameindex[i]].fmmomentum));
  352. #else
  353.          sprintf(t1, "%d|%d|%s|%s|%d|%d",fmtotalfameindex[i], i + 1,
  354.           family[fmtotalfameindex[i]].fmname,
  355.           family[fmtotalfameindex[i]].fmleadername,
  356.        (family[fmtotalfameindex[i]].fmpopular / 100),
  357.        (family[fmtotalfameindex[i]].fmtotalfame / 100));
  358. #endif
  359. #else
  360.          sprintf(t1, "%d|%d|%s|%s|%d", fmpopularindex[i], i + 1,
  361.           family[fmpopularindex[i]].fmname,
  362.           family[fmpopularindex[i]].fmleadername,
  363.        (family[fmpopularindex[i]].fmpopular / 100));
  364. #endif
  365.         if (i < MAX_FAMILY) strcat(t1, " ");
  366.         if (strlen(data) + strlen(t1) >= datasize){
  367.            log("getFMsortedlist: datafer overflow.");
  368.            return -1;
  369.         }
  370.         strcat(data, t1);
  371.       }
  372.    }
  373.    else if (kindflag == 2)
  374.    {
  375.       for (i = 0; i < TOPFMLISTNUM; i++) {
  376.          if (strcmp(family[fmadvindex[i]].fmname, "") == 0)
  377.          {
  378.           j++;
  379.          continue;
  380.          }
  381.          sprintf(t1, "%d|%d|%s|%s|%d", fmadvindex[i], i + 1,
  382.           family[fmadvindex[i]].fmname,
  383.           family[fmadvindex[i]].fmleadername,
  384.        (family[fmadvindex[i]].fmadv / 100));
  385.         if (i < TOPFMLISTNUM) strcat(t1, " ");
  386.         if (strlen(data) + strlen(t1) >= datasize)
  387.         {
  388.            log("getFMsortedlist: datafer overflow.");
  389.            return -1;
  390.         }
  391.         strcat(data, t1);
  392.       }
  393.    }
  394.    else if (kindflag == 3)
  395.    {
  396.       for (i = 0; i < TOPFMLISTNUM; i++) {
  397.          if (strcmp(family[fmfeedindex[i]].fmname, "") == 0)
  398.          {
  399.           j++;
  400.           continue;
  401.          }
  402.          sprintf(t1, "%d|%d|%s|%s|%d", fmfeedindex[i], i + 1,
  403.           family[fmfeedindex[i]].fmname,
  404.           family[fmfeedindex[i]].fmleadername,
  405.        (family[fmfeedindex[i]].fmfeed / 100));
  406.         if (i < TOPFMLISTNUM) strcat(t1, " ");
  407.         if (strlen(data) + strlen(t1) >= datasize)
  408.         {
  409.            log("getFMsortedlist: datafer overflow.");
  410.            return -1;
  411.         }
  412.         strcat(data, t1);
  413.       }
  414.    }
  415.    else if (kindflag == 4)
  416.    {
  417.       for (i = 0; i < TOPFMLISTNUM; i++) {
  418.          if (strcmp(family[fmsynthesizeindex[i]].fmname, "") == 0)
  419.          {
  420.           j++;
  421.           continue;
  422.          }
  423.          sprintf(t1, "%d|%d|%s|%s|%d", fmsynthesizeindex[i], i + 1,
  424.           family[fmsynthesizeindex[i]].fmname,
  425.           family[fmsynthesizeindex[i]].fmleadername,
  426.        (family[fmsynthesizeindex[i]].fmsynthesize / 100));
  427.         if (i < TOPFMLISTNUM) strcat(t1, " ");
  428.         if (strlen(data) + strlen(t1) >= datasize)
  429.         {
  430.            log("getFMsortedlist: datafer overflow.");
  431.            return -1;
  432.         }
  433.         strcat(data, t1);
  434.       }
  435.    }
  436.    else if (kindflag == 5)
  437.    {
  438.       for (i = 0; i < TOPFMLISTNUM; i++) {
  439.          if (strcmp(family[fmdealfoodindex[i]].fmname, "") == 0)
  440.          {
  441.           j++;
  442.           continue;
  443.          }
  444.          sprintf(t1, "%d|%d|%s|%s|%d", fmdealfoodindex[i], i + 1,
  445.           family[fmdealfoodindex[i]].fmname,
  446.           family[fmdealfoodindex[i]].fmleadername,
  447.        (family[fmdealfoodindex[i]].fmdealfood / 100));
  448.         if (i < TOPFMLISTNUM) strcat(t1, " ");
  449.         if (strlen(data) + strlen(t1) >= datasize)
  450.         {
  451.            log("getFMsortedlist: datafer overflow.");
  452.            return -1;
  453.         }
  454.         strcat(data, t1);
  455.       }
  456.    }
  457.    else if (kindflag == 6)
  458.    {
  459.       for (i = 0; i < TOPFMLISTNUM; i++) {
  460.          if (strcmp(family[fmpkindex[i]].fmname, "") == 0)
  461.          {
  462.           j++;
  463.           continue;
  464.          }
  465.          sprintf(t1, "%d|%d|%s|%s|%d", fmpkindex[i], i + 1,
  466.           family[fmpkindex[i]].fmname,
  467.           family[fmpkindex[i]].fmleadername,
  468.        (family[fmpkindex[i]].fmpk / 100));
  469.         if (i < TOPFMLISTNUM) strcat(t1, " ");
  470.         if (strlen(data) + strlen(t1) >= datasize)
  471.         {
  472.            log("getFMsortedlist: datafer overflow.");
  473.            return -1;
  474.         }
  475.         strcat(data, t1);
  476.       }
  477.    }
  478. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  479.    else if (kindflag == 7)
  480.    {
  481.       for (i = 0; i < MAX_FAMILY; i++) {
  482.          if (strcmp(family[fmtotalfameindex[i]].fmname, "") == 0)
  483.          {
  484.           j++;
  485.           continue;
  486.          }
  487.          sprintf(t1, "%d|%d|%s|%s|%d", fmtotalfameindex[i], i + 1,
  488.           family[fmtotalfameindex[i]].fmname,
  489.           family[fmtotalfameindex[i]].fmleadername,
  490.        (family[fmtotalfameindex[i]].fmtotalfame / 100));
  491.         if (i < MAX_FAMILY) strcat(t1, " ");
  492.         if (strlen(data) + strlen(t1) >= datasize)
  493.         {
  494.            log("getFMsortedlist: datafer overflow.");
  495.            return -1;
  496.         }
  497.         strcat(data, t1);
  498.       }
  499.    }
  500. #endif
  501. #ifdef _NEW_MANOR_LAW
  502.  else if(kindflag == 8){ // 十大气势家族(全部气势排名都传给game server)
  503.  for(i=0;i<MAX_FAMILY;i++){
  504.  if(strcmp(family[fmMomentumIndex[i]].fmname, "") == 0){
  505.  j++;
  506.  continue;
  507.  }
  508.  sprintf(t1,"%d|%d|%s|%s|%d",fmMomentumIndex[i], i + 1,
  509.  family[fmMomentumIndex[i]].fmname,
  510.  family[fmMomentumIndex[i]].fmleadername,
  511.  (family[fmMomentumIndex[i]].fmmomentum)/100);
  512.  if(i < MAX_FAMILY) strcat(t1," ");
  513.  if(strlen(data) + strlen(t1) >= datasize){
  514.  log("getFMsortedlist: datafer overflow.");
  515.  return -1;
  516.  }
  517.  strcat(data, t1);
  518.  }
  519.  }
  520. #endif
  521.    return i - j;
  522. }
  523. void AddFMMaintainSort(int index)
  524. {
  525.    int i = 0, j = MAX_FAMILY - 1, k;
  526.    // modify popular sort
  527.    while ((family[fmpopularindex[i]].fmpopular >= family[index].fmpopular)
  528.     && (i < MAX_FAMILY) && CheckFMUse(fmpopularindex[i]))
  529.    {
  530.     if (i == MAX_FAMILY -1) break;
  531.     i++;
  532.    }
  533.    while ((fmpopularindex[j] != index) && (j > 0)) j--;
  534.    if (j > i)
  535.    {
  536.     for (k = j; k > i; k--) fmpopularindex[k] = fmpopularindex[k - 1];
  537.     fmpopularindex[i] = index;
  538.    } else if (j < i) {
  539.     log("ACAddFM: fmpopularindex add error (j < i)");
  540.    } else log("ACAddFM: fmpopularindex add error (j = i)");
  541.    // modify adv sort
  542.    i = 0;j = MAX_FAMILY;k = 0;
  543.    while ((family[fmadvindex[i]].fmadv >= family[index].fmadv)
  544.     && (i < MAX_FAMILY) && CheckFMUse(fmadvindex[i]))
  545.    {
  546.     if (i == MAX_FAMILY -1) break;
  547.     i++;
  548.    }
  549.    while ((fmadvindex[j] != index) && (j > 0)) j--;
  550.    if (j > i)
  551.    {
  552.     for (k = j; k > i; k--) fmadvindex[k] = fmadvindex[k - 1];
  553.     fmadvindex[i] = index;
  554.    } else if (j < i) {
  555.     log("ACAddFM: fmadvindex add error (j < i)");
  556.    } else log("ACAddFM: fmadvindex add error (j = i)");
  557.    // modify feed sort
  558.    i = 0; j = MAX_FAMILY; k = 0;
  559.    while ((family[fmfeedindex[i]].fmfeed >= family[index].fmfeed)
  560.     && (i < MAX_FAMILY) && CheckFMUse(fmfeedindex[i]))
  561.    {
  562.     if (i == MAX_FAMILY -1) break;
  563.     i++;
  564.    }
  565.    while ((fmfeedindex[j] != index) && (j > 0)) j--;
  566.    if (j > i)
  567.    {
  568.     for (k = j; k > i; k--) fmfeedindex[k] = fmfeedindex[k - 1];
  569.     fmfeedindex[i] = index;
  570.    } else if (j < i) {
  571.     log("ACAddFM: fmfeedindex add error (j < i)");
  572.    } else log("ACAddFM: fmfeedindex add error (j = i)");
  573.    // modify synthesize sort
  574.    i = 0;j = MAX_FAMILY;k = 0;
  575.    while ((family[fmsynthesizeindex[i]].fmsynthesize >= family[index].fmsynthesize)
  576.     && (i < MAX_FAMILY) && CheckFMUse(fmsynthesizeindex[i]))
  577.    {
  578.     if (i == MAX_FAMILY -1) break;
  579.     i++;
  580.    }
  581.    while ((fmsynthesizeindex[j] != index) && (j > 0)) j--;
  582.    if (j > i)
  583.    {
  584.     for (k = j; k > i; k--) fmsynthesizeindex[k] = fmsynthesizeindex[k - 1];
  585.     fmsynthesizeindex[i] = index;
  586.    } else if (j < i) {
  587.     log("ACAddFM: fmsynthesizeindex add error (j < i)");
  588.    } else log("ACAddFM: fmsynthesizeindex add error (j = i)");
  589.    // modify dealfood sort
  590.    i = 0;j = MAX_FAMILY;k = 0;
  591.    while ((family[fmdealfoodindex[i]].fmdealfood >= family[index].fmdealfood)
  592.     && (i < MAX_FAMILY) && CheckFMUse(fmdealfoodindex[i]))
  593.    {
  594.     if (i == MAX_FAMILY -1) break;
  595.     i++;
  596.    }
  597.    while ((fmdealfoodindex[j] != index) && (j > 0)) j--;
  598.    if (j > i)
  599.    {
  600.     for (k = j; k > i; k--) fmdealfoodindex[k] = fmdealfoodindex[k - 1];
  601.     fmdealfoodindex[i] = index;
  602.    } else if (j < i) {
  603.     log("ACAddFM: fmdealfoodindex add error (j < i)");
  604.    } else log("ACAddFM: fmdealfoodindex add error (j = i)");
  605.    // modify pk sort
  606.    i = 0;j = MAX_FAMILY;k = 0;
  607.    while ((family[fmpkindex[i]].fmpk >= family[index].fmpk)
  608.     && (i < MAX_FAMILY) && CheckFMUse(fmpkindex[i]))
  609.    {
  610.     if (i == MAX_FAMILY -1) break;
  611.     i++;
  612.    }
  613.    while ((fmpkindex[j] != index) && (j > 0)) j--;
  614.    if (j > i)
  615.    {
  616.     for (k = j; k > i; k--) fmpkindex[k] = fmpkindex[k - 1];
  617.     fmpkindex[i] = index;
  618.    } else if (j < i) {
  619.     log("ACAddFM: fmpkindex add error (j < i)");
  620.    } else log("ACAddFM: fmpkindex add error (j = i)");
  621. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  622.    // modify pk sort
  623.    i = 0;j = MAX_FAMILY;k = 0;
  624.    while ((family[fmtotalfameindex[i]].fmtotalfame >= family[index].fmtotalfame)
  625.     && (i < MAX_FAMILY) && CheckFMUse(fmtotalfameindex[i]))
  626.    {
  627.     if (i == MAX_FAMILY -1) break;
  628.     i++;
  629.    }
  630.    while ((fmtotalfameindex[j] != index) && (j > 0)) j--;
  631.    if (j > i)
  632.    {
  633.     for (k = j; k > i; k--) fmtotalfameindex[k] = fmtotalfameindex[k - 1];
  634.     fmtotalfameindex[i] = index;
  635.    } else if (j < i) {
  636.     log("ACAddFM: fmtotalfameindex add error (j < i)");
  637.    } else log("ACAddFM: fmtotalfameindex add error (j = i)");
  638. #endif
  639. #ifdef _NEW_MANOR_LAW
  640.    // modify momentum sort
  641.    i = 0;j = MAX_FAMILY;k = 0;
  642.    while ((family[fmMomentumIndex[i]].fmmomentum >= family[index].fmmomentum)
  643.     && (i < MAX_FAMILY) && CheckFMUse(fmMomentumIndex[i]))
  644.    {
  645.     if (i == MAX_FAMILY -1) break;
  646.     i++;
  647.    }
  648.    while ((fmMomentumIndex[j] != index) && (j > 0)) j--;
  649.    if (j > i)
  650.    {
  651.     for (k = j; k > i; k--) fmMomentumIndex[k] = fmMomentumIndex[k - 1];
  652.     fmMomentumIndex[i] = index;
  653.    } else if (j < i) {
  654.     log("ACAddFM: fmMomentumIndex add error (j < i)");
  655.    } else log("ACAddFM: fmMomentumIndex add error (j = i)");
  656. #endif
  657. }
  658. void DelFMMaintainSort(int index)
  659. {
  660.      int i = 0,j;
  661.      // modify popular sort
  662.      while ((fmpopularindex[i] != index) && (i < MAX_FAMILY)) i++;
  663.      if (fmpopularindex[i] == index)
  664.      {
  665.         for (j = i; j < MAX_FAMILY - 1; j++) 
  666.          fmpopularindex[j] = fmpopularindex[j + 1];
  667.         fmpopularindex[MAX_FAMILY - 1] = index; // move to last one
  668.      }
  669.      // modify adv sort
  670.      i = 0;j = 0;
  671.      while ((fmadvindex[i] != index) && (i < MAX_FAMILY)) i++;
  672.      if (fmadvindex[i] == index)
  673.      {
  674.         for (j = i; j < MAX_FAMILY - 1; j++) 
  675.          fmadvindex[j] = fmadvindex[j + 1];
  676.         fmadvindex[MAX_FAMILY - 1] = index; // move to last one
  677.      }
  678.      // modify feed sort
  679.      i = 0;j = 0;
  680.      while ((fmfeedindex[i] != index) && (i < MAX_FAMILY)) i++;
  681.      if (fmfeedindex[i] == index)
  682.      {
  683.         for (j = i; j < MAX_FAMILY - 1; j++) 
  684.          fmfeedindex[j] = fmfeedindex[j + 1];
  685.         fmfeedindex[MAX_FAMILY - 1] = index; // move to last one
  686.      }
  687.      // modify synthesize sort
  688.      i = 0;j = 0;
  689.      while ((fmsynthesizeindex[i] != index) && (i < MAX_FAMILY)) i++;
  690.      if (fmsynthesizeindex[i] == index)
  691.      {
  692.         for (j = i; j < MAX_FAMILY - 1; j++) 
  693.          fmsynthesizeindex[j] = fmsynthesizeindex[j + 1];
  694.         fmsynthesizeindex[MAX_FAMILY - 1] = index; // move to last one
  695.      }
  696.      // modify dealfood sort
  697.      i = 0;j = 0;
  698.      while ((fmdealfoodindex[i] != index) && (i < MAX_FAMILY)) i++;
  699.      if (fmdealfoodindex[i] == index)
  700.      {
  701.         for (j = i; j < MAX_FAMILY - 1; j++) 
  702.          fmdealfoodindex[j] = fmdealfoodindex[j + 1];
  703.         fmdealfoodindex[MAX_FAMILY - 1] = index; // move to last one
  704.      }
  705.      // modify pk sort
  706.      i = 0;j = 0;
  707.      while ((fmpkindex[i] != index) && (i < MAX_FAMILY)) i++;
  708.      if (fmpkindex[i] == index)
  709.      {
  710.         for (j = i; j < MAX_FAMILY - 1; j++) 
  711.          fmpkindex[j] = fmpkindex[j + 1];
  712.         fmpkindex[MAX_FAMILY - 1] = index; // move to last one
  713.      }
  714. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  715.      // modify pk sort
  716.      i = 0;j = 0;
  717.      while ((fmtotalfameindex[i] != index) && (i < MAX_FAMILY)) i++;
  718.      if (fmtotalfameindex[i] == index)
  719.      {
  720.         for (j = i; j < MAX_FAMILY - 1; j++) 
  721.          fmtotalfameindex[j] = fmtotalfameindex[j + 1];
  722.         fmtotalfameindex[MAX_FAMILY - 1] = index; // move to last one
  723.      }
  724. #endif
  725. #ifdef _NEW_MANOR_LAW
  726.  // modify momentum sort
  727.      i = 0;j = 0;
  728.      while ((fmMomentumIndex[i] != index) && (i < MAX_FAMILY)) i++;
  729.      if (fmMomentumIndex[i] == index){
  730.         for (j = i; j < MAX_FAMILY - 1; j++) 
  731.          fmMomentumIndex[j] = fmMomentumIndex[j + 1];
  732.         fmMomentumIndex[MAX_FAMILY - 1] = index; // move to last one
  733.      }
  734. #endif
  735. }
  736. // 从档案读取家族资料(启动时读取)
  737. int readFamily(char *dir)
  738. {
  739. char dirname[256];
  740. DIR  *d;
  741. struct dirent *de;
  742. int i = 0, fmnum = 0, fmmaxnum = 0;
  743. {
  744. char tmp[256];
  745. snprintf(tmp, sizeof(tmp), "%s", dir);
  746. if (mkdir(tmp, 0755) == 0)
  747. log("create %sn", tmp);
  748. }
  749. snprintf(dirname, sizeof(dirname), "%s", dir);
  750. d = opendir(dirname);
  751. if (d == NULL){
  752. log("cannot open %sn", dirname);
  753. return -1;
  754. }
  755. de = readdir(d);
  756. if(de == NULL){
  757. log("de == NULLn");
  758. return -1;
  759. }
  760. {
  761. char filename[256];
  762. struct stat s;
  763. for (i = 0; i < MAX_FAMILY; i++){
  764. // FILE *fp;
  765. snprintf(filename, sizeof(filename), "%s/Family.%d", dirname, i);
  766. if (stat(filename, &s) < 0)continue;
  767. if (!(s.st_mode & S_IFREG)){
  768. log("%s is not a regular filen", filename);
  769. continue;
  770. }
  771. if( readOneFamily( filename, i) != 1 ){
  772. if (remove(filename) == -1)   
  773.    log("cannot open file %s %sn", filename, strerror(errno));
  774. continue;
  775. }
  776.         fmnum = fmnum + 1;
  777.         fmmaxnum = i;
  778. }
  779.     fmindexmaxnum = fmmaxnum;
  780.     fmnownum = fmnum;
  781. }
  782.    closedir(d);
  783.    
  784. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  785.    // 计算家族总合声望 = 家族综合声望 + 家族个人声望
  786.    {
  787.      int i,j;
  788.      for (i = 0; i < MAX_FAMILY; i++) {
  789.        family[i].fmpopular=family[i].fmadv+family[i].fmfeed
  790.          +family[i].fmsynthesize+family[i].fmdealfood
  791.  +family[i].fmpk;
  792.        family[i].fmtotalfame=family[i].fmpopular;
  793.        for (j = 0; j < MAX_MEMBERNUM; j++) {
  794.          if ((family[i].fmmemberindex[j].charflag!=FMMEMBER_NONE) &&
  795.              (family[i].fmmemberindex[j].charflag!=FMMEMBER_APPLY) )
  796.            family[i].fmtotalfame += family[i].fmmemberindex[j].popular;
  797.        }
  798.      }
  799.    }
  800. #endif
  801.    
  802.    sortFamily(); // Arminius: sort it
  803.    return 0;
  804. }
  805. // 将家族资料写入档案
  806. int writeFamily(char *dir)
  807. {
  808.    int i = 0, j = 0, k = 0;
  809.    FILE *fp;
  810.    char filename[256];
  811.    for (i = 0; i < MAX_FAMILY; i++)
  812.    {
  813.       if (db_familyupdate[i] == 0) continue;
  814.       sprintf(filename, "%s/Family.%d", dir, i);
  815.       fp = fopen(filename, "w");
  816.       if (fp == NULL) continue;
  817.       if ((family[i].fmindex != -1) && (strcmp(family[i].fmname, "") != 0))
  818.       {
  819.      fprintf(fp, "fmindex=%d|fmname=%s|fmleadername=%s|fmleaderid=%s|"
  820.     "fmleadergrano=%d|petname=%s|petattr=%s|fmnum=%d|fmjoinnum=%d|"
  821.     "fmacceptflag=%d|fmsetupflag=%d|fmrule=%s|fmsprite=%d|"
  822.     "fmpointindex=%d|fmpopular=%d|fmgold=%d|fmmemberindexmaxnum=%d|"
  823.     "apply_time=%d|setup_time=%d|predel_time=%d|memonowwritenum=%d|"
  824.     "memonum=%d|fmadv=%d|fmfeed=%d|fmsynthesize=%d|fmdealfood=%d|fmpk=%d"
  825. #ifdef _NEW_MANOR_LAW
  826. "|fmmomentum=%d"
  827. #endif
  828.         ,family[i].fmindex, family[i].fmname, family[i].fmleadername, 
  829.         family[i].fmleaderid, family[i].fmleadergrano, family[i].petname,
  830.         family[i].petattr, family[i].fmnum, family[i].fmjoinnum,
  831.         family[i].fmacceptflag, family[i].fmsetupflag, family[i].fmrule,
  832.         family[i].fmsprite, family[i].fmpointindex, family[i].fmpopular,
  833.         family[i].fmgold, family[i].fmmemberindexmaxnum,
  834.         family[i].apply_time, family[i].setup_time, family[i].predel_time,
  835.         family[i].memonowwritenum, family[i].memonum, family[i].fmadv,
  836.         family[i].fmfeed, family[i].fmsynthesize, family[i].fmdealfood,
  837.         family[i].fmpk
  838. #ifdef _NEW_MANOR_LAW
  839. ,family[i].fmmomentum
  840. #endif
  841. );
  842.      for (j = 0; j < family[i].memonum; j++)
  843.         fprintf(fp, "|%s%d=%s", FMMEMOLIST, j, family[i].memolist[j]);
  844.      for (k = 0; k < family[i].fmmemberindexmaxnum; k++)
  845.      {
  846.     if ((strcmp(family[i].fmmemberindex[k].charname, "") != 0)
  847.      && (strcmp(family[i].fmmemberindex[k].charid, "") != 0)
  848.      && (family[i].fmmemberindex[k].charflag != FMMEMBER_NONE))
  849.     {
  850. #ifdef _FMVER21
  851. #ifndef _NEW_MANOR_LAW
  852.            fprintf(fp, "|%s%d=charname=%s charid=%s charlv=%d charflag=%d onlineflag=%d predeltime=%d popular=%d eventflag=%d",
  853. #else
  854.  fprintf(fp, "|%s%d=charname=%s charid=%s charlv=%d charflag=%d onlineflag=%d predeltime=%d popular=%d eventflag=%d momentum=%d",
  855. #endif
  856. #else
  857.  fprintf(fp, "|%s%d=charname=%s charid=%s charlv=%d charflag=%d onlineflag=%d predeltime=%d popular=%d",
  858. #endif
  859.               FMMEMBERINDEX, k, family[i].fmmemberindex[k].charname,
  860.               family[i].fmmemberindex[k].charid,
  861.               family[i].fmmemberindex[k].charlv,
  862.               family[i].fmmemberindex[k].charflag,
  863.               family[i].fmmemberindex[k].onlineflag,
  864.               family[i].fmmemberindex[k].predeltime,
  865.               family[i].fmmemberindex[k].popular
  866. #ifdef _FMVER21
  867. ,family[i].fmmemberindex[k].eventflag
  868. #endif
  869. #ifdef _NEW_MANOR_LAW
  870. ,family[i].fmmemberindex[k].momentum
  871. #endif
  872.  );
  873.         }
  874.      } // for
  875.          fprintf(fp, "n");
  876.       } // if
  877.       fclose(fp);
  878.       db_familyupdate[i] = 0;
  879.    }
  880.    return 0;
  881. }
  882. // 从档案读取家族庄园(启动时读取)
  883. int readFMPoint(char *dir)
  884. {
  885.    char dirname[256];
  886.    DIR  *d;
  887.    struct dirent *de;
  888.    int i = 0;
  889.    {
  890.     char tmp[256];
  891.     snprintf(tmp, sizeof(tmp), "%s", dir);
  892.     if (mkdir(tmp, 0755) == 0)
  893.     log("create %sn", tmp);
  894.    }
  895.    snprintf(dirname, sizeof(dirname), "%s", dir);
  896.    d = opendir(dirname);
  897.    if (d == NULL)
  898.    {
  899.     log("无法打开文件 %sn", dirname);
  900.     return -1;
  901.    }
  902.    while(1)
  903.    {
  904.     de = readdir(d);
  905.     if(de == NULL) break;
  906.     if (de -> d_name[0] != '.')
  907.     {
  908.        char filename[256];
  909.        FILE *fp;
  910.        struct stat s;
  911.        snprintf(filename, sizeof(filename), "%s/%s", dirname, de -> d_name);
  912.        if (stat(filename, &s) < 0){
  913.           continue;
  914.        }
  915.        if (!(s.st_mode & S_IFREG))
  916.        {
  917.           log("%s is not a regular filen", filename);
  918.           continue;
  919.        }
  920.        fp = fopen(filename, "r");
  921.        if (fp == NULL)
  922.        {
  923.           log("无法打开文件 %s %sn", filename, strerror(errno));
  924.           continue;
  925.        }
  926.        while(1)
  927.        {
  928.           char line[1024];
  929.           char data[1024];
  930.           if (fgets(line, sizeof(line), fp) == NULL)
  931.              break;
  932.           chop(line);
  933.           easyGetTokenFromBuf(line, "|", 1, data, sizeof(data));
  934.           fmpoint[i].fl = atoi(data);
  935.           easyGetTokenFromBuf(line, "|", 2, data, sizeof(data));
  936.           fmpoint[i].x = atoi(data);
  937.           easyGetTokenFromBuf(line, "|", 3, data, sizeof(data));
  938.           fmpoint[i].y = atoi(data);
  939.           easyGetTokenFromBuf(line, "|", 4, data, sizeof(data));
  940.           fmpoint[i].fmfl = atoi(data);
  941.           easyGetTokenFromBuf(line, "|", 5, data, sizeof(data));
  942.           fmpoint[i].village = atoi(data);
  943.           easyGetTokenFromBuf(line, "|", 6, data, sizeof(data));
  944.           fmpoint[i].hadfmindex = atoi(data);
  945.           easyGetTokenFromBuf(line, "|", 7, data, sizeof(data));
  946.           strcpy(fmpoint[i].hadfmname, data);
  947.           easyGetTokenFromBuf(line, "|", 8, data, sizeof(data));
  948.           fmpoint[i].hadfmpopular = atoi(data);
  949.           i++;
  950.        }
  951.        fclose(fp);
  952.     }
  953.    }
  954.    closedir(d);
  955.    return 0;
  956. }
  957. // 将家族庄园写入档案
  958. int writeFMPoint(char *dir)
  959. {
  960.    int i = 0;
  961.    FILE *fp;
  962.    char filename[256];
  963.    sprintf(filename, "%s/db_fmpoint", dir);
  964.    if (db_fmpointupdate == 0)
  965.       return 0;
  966.    else
  967.     log("已将更新资料db_fmpoint写入文件.n");
  968.    fp = fopen(filename, "w");
  969.    if (fp == NULL)
  970.    {
  971. log("无法打开文件: %s %sn", filename, strerror(errno));
  972. return -1;
  973.    }
  974.    for(i = 0; i < MAX_FMPOINT; i++)
  975.    {
  976. fprintf(fp, "%d|%d|%d|%d|%d|%d|%s|%dn",
  977. fmpoint[i].fl, fmpoint[i].x, fmpoint[i].y, fmpoint[i].fmfl,
  978. fmpoint[i].village, fmpoint[i].hadfmindex, fmpoint[i].hadfmname,
  979. fmpoint[i].hadfmpopular);
  980.    } // for
  981.    fclose(fp);
  982.    db_fmpointupdate = 0;
  983.    return 0;
  984. }
  985. // 从档案中读取家族之间留言资料(启动时读取)
  986. int readFMSMemo(char *dir)
  987. {
  988.    char dirname[256];
  989.    DIR  *d;
  990.    struct dirent *de;
  991.    int i = 0;
  992.    {
  993.     char tmp[256];
  994.     snprintf(tmp, sizeof(tmp), "%s", dir);
  995.     if (mkdir(tmp, 0755) == 0)
  996.     log("create %sn", tmp);
  997.    }
  998.    snprintf(dirname, sizeof(dirname), "%s", dir);
  999.    d = opendir(dirname);
  1000.    if (d == NULL)
  1001.    {
  1002.     log("无法打开文件 %sn", dirname);
  1003.     return -1;
  1004.    }
  1005.    while(1)
  1006.    {
  1007.     de = readdir(d);
  1008.     if(de == NULL) break;
  1009.     if (de -> d_name[0] != '.')
  1010.     {
  1011.        char filename[256];
  1012.        FILE *fp;
  1013.        struct stat s;
  1014.        snprintf(filename, sizeof(filename), "%s/%s", dirname, de -> d_name);
  1015.        if (stat(filename, &s) < 0){
  1016.           continue;
  1017.        }
  1018.        if (!(s.st_mode & S_IFREG))
  1019.        {
  1020.           log("%s 不是正常文件n", filename);
  1021.           continue;
  1022.        }
  1023.        fp = fopen(filename, "r");
  1024.        if (fp == NULL)
  1025.        {
  1026.           log("无法打开文件 %s %sn", filename, strerror(errno));
  1027.           continue;
  1028.        }
  1029.        {
  1030.           char line[15000];
  1031.           char data[15000];
  1032.           if (fgets(line, sizeof(line), fp) == NULL)
  1033.              break;
  1034.           chop(line);
  1035.           easyGetTokenFromBuf(line, "|", 1, data, sizeof(data));
  1036.           fmsmemo.num = atoi(data);
  1037.           easyGetTokenFromBuf(line, "|", 2, data, sizeof(data));
  1038.           fmsmemo.fmsnowwritenum = atoi(data);
  1039.           for (i = 0; i < fmsmemo.num; i++){
  1040.              easyGetTokenFromBuf(line, "|", 3 + i, data, sizeof(data));
  1041.              strcpy(fmsmemo.memodata[i], data);
  1042.           }
  1043.        }
  1044.        fclose(fp);
  1045.     }
  1046.    }
  1047.    closedir(d);
  1048.    return 0;
  1049. }
  1050. // 将家族之间留言资料写入档案
  1051. int writeFMSMemo(char *dir)
  1052. {
  1053.    int i = 0;
  1054.    FILE *fp;
  1055.    char filename[256];
  1056.    sprintf(filename, "%s/db_fmsmemo", dir);
  1057.    if (db_fmsmemoupdate == 0)
  1058.       return 0;
  1059.    else
  1060.     log("已将更新资料db_fmsmemo写入文件.n");
  1061.    fp = fopen(filename, "w");
  1062.    if (fp == NULL)
  1063.    {
  1064. log("无法打开文件: %s %sn", filename, strerror(errno));
  1065. return -1;
  1066.    }
  1067.    fprintf(fp, "%d|%d", fmsmemo.num, fmsmemo.fmsnowwritenum);
  1068.    for(i = 0; i < fmsmemo.num; i++)
  1069.    {
  1070. fprintf(fp, "|%s", fmsmemo.memodata[i]);
  1071. log("%sn", fmsmemo.memodata[i]);
  1072.    } // for
  1073.    fprintf(fp, "n");
  1074.    fclose(fp);
  1075.    db_fmsmemoupdate = 0;
  1076.    return 0;
  1077. }
  1078. // 取得未使用的 index
  1079. int getblankindex()
  1080. {
  1081.    int i = 0;
  1082.    for(i = 0; i < MAX_FAMILY; i++)
  1083.     if (((family[i].fmindex <= 0) || (family[i].fmindex > MAX_FAMILY))
  1084.        && (strcmp(family[i].fmname, "") == 0))
  1085. return i;
  1086.    return -1;
  1087. }
  1088. // 取得未使用的 fmindex
  1089. int getblankfmindex()
  1090. {
  1091.    int i = 0, j = 0;
  1092.    for (i = 1; i <= MAX_FAMILY; i++)
  1093.    {
  1094.     int useflag = 0;
  1095. for (j = 0; j < MAX_FAMILY; j++)
  1096. {
  1097.        if (family[j].fmindex == i)
  1098.        {
  1099.           useflag = 1;
  1100.           continue;
  1101.        }
  1102.     }
  1103.     if (useflag == 0)
  1104.           return i;
  1105.    }
  1106.    return -1;
  1107. }
  1108. // 从 fmindex, fmname 取得 index
  1109. int getindex(int fmindex, char *fmname)
  1110. {
  1111.    int i = 0;
  1112.    for (i = 0; i <= fmindexmaxnum; i++)
  1113.    {
  1114.       if ((family[i].fmindex == fmindex)
  1115.          && (strcmp(family[i].fmname, fmname) == 0))
  1116. return i;
  1117.    }
  1118.    return -1;
  1119. }
  1120. // 删除庄园的家族 fmindex
  1121. int delfmpointindex(int fmindex)
  1122. {
  1123.    int i;
  1124.    for (i = 0; i < MAX_FMPOINT; i++)
  1125.    {
  1126.     if (fmpoint[i].hadfmindex == fmindex)
  1127.     {
  1128.     fmpoint[i].hadfmindex = -1;
  1129.     strcpy(fmpoint[i].hadfmname, "-1");
  1130.     fmpoint[i].hadfmpopular = -1;
  1131.     db_fmpointupdate = 1;
  1132.     return 0;
  1133.     }
  1134.    }
  1135.    return -1;
  1136. }
  1137. // 检查 index 是否已使用
  1138. int CheckFMUse(int index)
  1139. {
  1140.    if ((index >= MAX_FAMILY) || (index < 0))
  1141.     return -1;
  1142.    if ((family[index].fmindex < 0) || (strcmp(family[index].fmname, "") == 0))
  1143.     return 0;
  1144.    else
  1145.     return 1;
  1146. }
  1147. // 检查 index fmindex, fmname资料是否正确
  1148. int CheckFM(int *index, char *fmname, int fmindex)
  1149. {
  1150.    if (*index == -1){
  1151.       *index = getindex(fmindex, fmname);
  1152.    }
  1153.    if ((*index > MAX_FAMILY) || (*index < 0)){
  1154.       log ("CheckFM_2 *index: big small? %dn", *index);
  1155.       return -1;
  1156.    }else {
  1157.       if ((family[*index].fmindex != fmindex) 
  1158.      || strcmp(family[*index].fmname, fmname) != 0)
  1159.       {
  1160.          log("CheckFM_3 [*index].fmindex:%d fmindex:%d [index].fmname:%s fmname:%sn",
  1161.           family[*index].fmindex, fmindex, family[*index].fmname, fmname);
  1162.          return -1;
  1163.       }
  1164.    }
  1165.    if (*index == -1){
  1166.       log ("CheckFM_4 index: -1 ? %dn", *index);
  1167.       return -1;
  1168.    }
  1169.    if(CheckFMUse(*index) == 0)
  1170.    {
  1171. log ("CheckFM_5 index: -1 ? %dn", *index);
  1172. return -1;
  1173.    }
  1174.    if (family[*index].fmnum > MAX_MEMBERNUM || family[*index].fmjoinnum > MAX_MEMBERNUM)
  1175.    {
  1176.     log ("CheckFM_6 fmnum: -1 ? %dn", family[*index].fmnum);
  1177. return -1;
  1178.    }
  1179.    return 0;
  1180. }
  1181. // 删除人数不足之家族或太久未上站之成员
  1182. void delovertimeFMMem(int time)
  1183. {
  1184.    int i = 0, j = 0, k = 0;
  1185.    char data[150 * MAX_FAMILY];
  1186.    extern gmsv gs[MAXCONNECTION];
  1187.    for (i = 0 ; i <= fmindexmaxnum; i++){
  1188.       if(CheckFMUse(i) == 0)
  1189.          continue;
  1190. if ( ( (family[i].predel_time < time) && (family[i].predel_time != -1)
  1191.   && (family[i].fmsetupflag != 1)) || (family[i].fmjoinnum==0) ){
  1192. log("ACDelOverTimeFM fmindex:%d fmname:%s fmjoinnum:%d flag:%d n",
  1193. family[i].fmindex, family[i].fmname,
  1194. family[i].fmjoinnum, family[i].fmsetupflag );
  1195. ACDelFM(i, family[i].fmname, family[i].fmindex);
  1196. // 传送家族已删除之讯息至各 GMSV
  1197. for (k = 0; k < MAXCONNECTION; k++){
  1198. if (gs[k].use && gs[k].name[0])
  1199. saacproto_ACFMAnnounce_send(k, SUCCESSFUL,
  1200. family[i].fmname, family[i].fmindex, i,
  1201. 2, "", 0);
  1202. }
  1203.                                                 
  1204. db_familyupdate[i] = 1;
  1205. continue;
  1206. }
  1207.       for (j = 1; j < family[i].fmmemberindexmaxnum; j++){
  1208.          if (family[i].fmmemberindex[j].charflag == FMMEMBER_NONE)
  1209.           continue;
  1210.          if ((family[i].fmmemberindex[j].predeltime < time)
  1211.             && (family[i].fmmemberindex[j].predeltime != -1)){
  1212. #ifdef _FMVER21
  1213.             ACMemberLeaveFM(i, family[i].fmname, family[i].fmindex,
  1214.              family[i].fmmemberindex[j].charname, 0, j, 0);
  1215. #else
  1216.             ACMemberLeaveFM(i, family[i].fmname, family[i].fmindex,
  1217.              family[i].fmmemberindex[j].charname, 0, j);
  1218. #endif         
  1219.             db_familyupdate[i] = 1;
  1220. /*
  1221. // 通知族长有玩家已被删除
  1222. if (family[i].fmmemberindex[0].onlineflag > 0)
  1223. {
  1224. char buf[256];
  1225. sprintf(buf, "(%s)因太久未上线而离开您的家族了!目前家族人数:%4d人",
  1226. family[i].fmmemberindex[j].charname, family[i].fmjoinnum);
  1227. saacproto_ACFMAnnounce_send(family[i].fmmemberindex[0].onlineflag,
  1228. SUCCESSFUL, family[i].fmname, family[i].fmindex, i, 3, buf,
  1229. family[i].fmmemberindex[0].charfdid);
  1230. }
  1231. */
  1232.          } // if
  1233.       } // for
  1234.    } // for
  1235.    if (db_familyupdate[i] == 1)
  1236.    {
  1237.       strcpy(data, "");
  1238.       for (i = 0; i <= fmindexmaxnum; i++)
  1239.       {
  1240.          char msg[256];
  1241.          if ((strcmp(family[i].fmname, "") != 0) && (family[i].fmindex != -1))
  1242.          {
  1243. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1244.             sprintf(msg, "%d %s %s %d %d %d %d %d|", family[i].fmindex, family[i].fmname,
  1245.                family[i].fmleadername, family[i].fmtotalfame, family[i].fmjoinnum, i,
  1246.                family[i].fmsetupflag, family[i].fmacceptflag);
  1247. #else
  1248.             sprintf(msg, "%d %s %s %d %d %d %d %d|", family[i].fmindex, family[i].fmname,
  1249.                family[i].fmleadername, family[i].fmpopular, family[i].fmjoinnum, i,
  1250.                family[i].fmsetupflag, family[i].fmacceptflag);
  1251. #endif
  1252.             strcat(data, msg);
  1253.          }
  1254.       }
  1255.       for (i = 0; i < MAXCONNECTION; i++)
  1256.       {
  1257.          if (gs[i].use && gs[i].name[0])
  1258.             saacproto_ACShowFMList_send(i, SUCCESSFUL, fmnownum, data);
  1259.       }
  1260.    }
  1261. }
  1262. // 成立家族
  1263. #ifdef _PERSONAL_FAME
  1264. int ACAddFM(int fd, int *workindex, char *fmname, char *fmleadername,
  1265. char *fmleaderid, int fmleaderlv, char *petname, char *petattr,
  1266. char *fmrule, int fmsprite, int fmleadergrano, int fame, int charfdid)
  1267. #else
  1268. int ACAddFM(int fd, int *workindex, char *fmname, char *fmleadername,
  1269. char *fmleaderid, int fmleaderlv, char *petname, char *petattr,
  1270. char *fmrule, int fmsprite, int fmleadergrano, int charfdid)
  1271. #endif
  1272. {
  1273. int i = 0, index, fmindex;
  1274. time_t t1;
  1275. index = getblankindex();
  1276. if (index == -1) {
  1277.     return -1; // 家族数量已满
  1278. }
  1279. fmindex = getblankfmindex();
  1280. if (fmindex == -1){
  1281.     return -1; // 家族数量已满,无空的 fmindex
  1282. }
  1283. for (i = 0; i <= fmindexmaxnum; i++){
  1284.     if (strcmp(family[i].fmname, fmname) == 0)
  1285. return -2; // 已有相同家族名称存在
  1286. }
  1287. *workindex = index;
  1288. family[index].fmindex = fmindex;
  1289. strcpy(family[index].fmname, fmname);
  1290. strcpy(family[index].fmleadername, fmleadername);
  1291. strcpy(family[index].fmleaderid, fmleaderid);
  1292. family[index].fmleadergrano = fmleadergrano;
  1293. strcpy(family[index].petname, petname);
  1294. strcpy(family[index].petattr, petattr);
  1295. family[index].fmnum = 1;
  1296. family[index].fmjoinnum = 1;
  1297. family[index].fmacceptflag = 1;
  1298. strcpy(family[index].fmrule, fmrule);
  1299. family[index].fmsprite = fmsprite;
  1300. family[index].fmpointindex = -1;
  1301. family[index].fmgold = 0;
  1302. family[index].fmmemberindexmaxnum = 1;
  1303. time(&t1);
  1304. family[index].apply_time = t1;
  1305. family[index].predel_time = t1 + PREDEL_TIME;
  1306. family[index].fmmemberindex[0].charlv = fmleaderlv;
  1307. #ifdef _FMVER21
  1308. family[index].fmmemberindex[0].charflag = FMMEMBER_LEADER;
  1309. family[index].fmmemberindex[0].eventflag = 1;
  1310. #else
  1311. family[index].fmmemberindex[0].charflag = 1;
  1312. #endif
  1313. family[index].fmmemberindex[0].onlineflag = fd;
  1314. strcpy(family[index].fmmemberindex[0].charid, fmleaderid);   
  1315. strcpy(family[index].fmmemberindex[0].charname, fmleadername);
  1316. family[index].fmmemberindex[0].charfdid = charfdid;
  1317. family[index].fmmemberindex[0].predeltime = -1;
  1318. family[index].memonowwritenum = 0;
  1319. family[index].memonum = 0;
  1320. family[index].fmpopular = 0;
  1321. family[index].fmadv = 0;
  1322. family[index].fmfeed = 0;
  1323. family[index].fmsynthesize = 0;
  1324. family[index].fmdealfood = 0;
  1325. family[index].fmpk = 0;
  1326. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1327. family[index].fmmemberindex[0].popular = fame;
  1328. family[index].fmtotalfame = fame;
  1329. #endif
  1330. #ifdef _NEW_MANOR_LAW
  1331. family[index].fmmomentum = 0;
  1332. #endif
  1333. db_familyupdate[index] = 1;
  1334. fmnownum++;
  1335. if (fmindexmaxnum <= index) fmindexmaxnum = index + 1;
  1336. log("AddFM fmindexmaxnum:%d fmnownum:%dn", fmindexmaxnum, fmnownum);
  1337. AddFMMaintainSort(index);
  1338. return fmindex;
  1339. }
  1340. // 加入家族
  1341. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1342. int ACJoinFM(int fd, int index, char *fmname, int fmindex,
  1343. char *charname, char *charid, int charlv, int fame, int charfdid)
  1344. #else
  1345. int ACJoinFM(int fd, int index, char *fmname, int fmindex,
  1346. char *charname, char *charid, int charlv, int charfdid)
  1347. #endif
  1348. {
  1349. int i = 0;
  1350. time_t t1;
  1351. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  1352. if (family[index].fmacceptflag == 0) return -2;
  1353. if (family[index].fmnum >= MAX_MEMBERNUM || family[index].fmjoinnum >= MAX_MEMBERNUM)
  1354.     return -3;
  1355. // 防止族长加入自己的家族  code:shan
  1356. if ((strcmp(family[index].fmmemberindex[0].charname, charname) == 0)
  1357. && (strcmp(family[index].fmmemberindex[0].charid, charid) == 0))
  1358. return -1;
  1359. for (i = 1; i < MAX_MEMBERNUM; i++){
  1360. if ((strcmp(family[index].fmmemberindex[i].charname, "") == 0)
  1361. && (strcmp(family[index].fmmemberindex[i].charid, "") == 0)){
  1362. strcpy(family[index].fmmemberindex[i].charname, charname);
  1363. strcpy(family[index].fmmemberindex[i].charid, charid);
  1364. family[index].fmmemberindex[i].charlv = charlv;
  1365. #ifdef _FMVER21
  1366. family[index].fmmemberindex[i].charflag = FMMEMBER_APPLY;
  1367. family[index].fmmemberindex[i].eventflag = 0;
  1368. #else
  1369. family[index].fmmemberindex[i].charflag = 2;
  1370. #endif
  1371. family[index].fmmemberindex[i].onlineflag = fd;
  1372. family[index].fmmemberindex[i].charfdid = charfdid;
  1373. time(&t1);
  1374. family[index].fmmemberindex[i].predeltime = t1 + PREDEL_TIME;
  1375. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1376. family[index].fmmemberindex[i].popular = fame;
  1377. log("fame:%dn", fame);
  1378. // 这个时候还不可以把这个人的声望加到家族
  1379. #endif
  1380. #ifdef _NEW_MANOR_LAW
  1381. family[index].fmmemberindex[i].momentum = 0;
  1382. #endif
  1383. family[index].fmnum = family[index].fmnum + 1;
  1384. if (family[index].fmmemberindexmaxnum <= i) family[index].fmmemberindexmaxnum = i + 1;
  1385. db_familyupdate[index] = 1;
  1386. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1387. // 更新玩家资料
  1388. saacproto_ACFMCharLogin_send(
  1389. family[index].fmmemberindex[i].onlineflag,
  1390. SUCCESSFUL, index,ACgetFMFloor(fmindex), family[index].fmtotalfame,
  1391. family[index].fmmemberindex[i].charflag,
  1392. family[index].fmsetupflag, 1, i,
  1393. family[index].fmmemberindex[i].popular, // Arminius 9.11
  1394. family[index].fmmemberindex[i].charfdid
  1395. #ifdef _NEW_MANOR_LAW
  1396. ,family[index].fmmemberindex[i].momentum
  1397. #endif
  1398. );
  1399. #else
  1400. saacproto_ACFMCharLogin_send(
  1401. family[index].fmmemberindex[i].onlineflag,
  1402. SUCCESSFUL, index,ACgetFMFloor(fmindex),family[index].fmpopular,
  1403. family[index].fmmemberindex[i].charflag,
  1404. family[index].fmsetupflag, 1, i,
  1405. family[index].fmmemberindex[i].charfdid);
  1406. #endif
  1407. // 通知族长有玩家愿意加入
  1408. if (family[index].fmmemberindex[0].onlineflag > 0){
  1409. char buf[256];
  1410. sprintf(buf, "(%s lv:%d)正要求加入您的家族喔!目前家族人数:%4d人",
  1411. charname, charlv, family[index].fmjoinnum);
  1412. saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag,
  1413. SUCCESSFUL, fmname, fmindex, index, 3, buf,
  1414. family[index].fmmemberindex[0].charfdid);
  1415. }
  1416. return 0;
  1417. }
  1418. }
  1419. return -1;
  1420. }
  1421. // 离开家族
  1422. int ACLeaveFM(int index, char *fmname, int fmindex,
  1423. char *charname, char* charid)
  1424. {
  1425. int i = 0;
  1426. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  1427. for (i = 1; i < family[index].fmmemberindexmaxnum; i++)
  1428. {
  1429.     if ((strcmp(family[index].fmmemberindex[i].charname, charname) == 0)
  1430. && (strcmp(family[index].fmmemberindex[i].charid, charid) == 0))
  1431.     {
  1432. #ifdef _FMVER21
  1433. ACMemberLeaveFM(index, fmname, fmindex, charname, 0, i, 0);
  1434. #else
  1435. ACMemberLeaveFM(index, fmname, fmindex, charname, 0, i);
  1436. #endif
  1437. db_familyupdate[index] = 1;
  1438. // 通知族长有玩家已离开家族
  1439. if (family[index].fmmemberindex[0].onlineflag > 0)
  1440. {
  1441. char buf[256];
  1442. sprintf(buf, "(%s)已经离开您的家族了!目前家族人数:%4d人",
  1443. charname, family[index].fmjoinnum);
  1444. saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag,
  1445. SUCCESSFUL, fmname, fmindex, index, 3, buf,
  1446. family[index].fmmemberindex[0].charfdid);
  1447. }
  1448. return 0;
  1449.     }
  1450. }
  1451. return -1;
  1452. }
  1453. // 修正家族资料
  1454. // kindflag 1:是否继续招募家族成员 2:家族PK声望 3:家族守护兽 4:家族主旨
  1455. //     5:解散家族时间 6:家族基金 7:家族冒险声望 8:家族饲育声望
  1456. //     9:家族合成、加工声望 10:家族料理声望 11:族长禅让
  1457. int ACFixFMData(int index, char *fmname, int fmindex, int kindflag, int charindex,
  1458. char *data1, char *data2)
  1459. {
  1460. int recvdata = 0;
  1461. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  1462. if (kindflag == 1 || kindflag == 2 || (kindflag >= 6 && kindflag <= 11)
  1463. #ifdef _NEW_MANOR_LAW
  1464. || kindflag == 12 || kindflag == 13
  1465. #endif
  1466. ){
  1467. recvdata = atoi(data1);
  1468. if (recvdata > MAXRECVPOP && (kindflag == 2 || (kindflag >= 7 && kindflag <= 10))) {
  1469. log("ACDelOverTimePOP index:%d fmname:%s kindflag:%d charindex:%d recvdata:%dn",
  1470. index, fmname, kindflag, charindex, recvdata);
  1471. return -1;
  1472. }
  1473. }
  1474. if (kindflag == 1)
  1475.     family[index].fmacceptflag = recvdata;
  1476. else if (kindflag == 2){
  1477.     family[index].fmpk = family[index].fmpk + recvdata;
  1478.     if (family[index].fmpk < MINFMPOPNUM) family[index].fmpk = MINFMPOPNUM;
  1479.     if (family[index].fmpk > MAXFMPOPNUM) family[index].fmpk = MAXFMPOPNUM;
  1480. }else if (kindflag == 3){
  1481.     if ((strcmp(data1, "") == 0) || (strcmp(data2, "") == 0)) return -1;
  1482.     strcpy(family[index].petname, data1);
  1483.     strcpy(family[index].petattr, data2);
  1484.     if (family[index].fmsetupflag == 1)
  1485. family[index].predel_time = -1;
  1486. }else if (kindflag == 4){
  1487.     if (strcmp(data1, "") == 0) return -1;
  1488.     strcpy(family[index].fmrule, data1);
  1489. }else if (kindflag == 5){
  1490.     time_t t1;
  1491.     time(&t1);
  1492.     family[index].predel_time = t1 + PREDEL_TIME;
  1493. }else if (kindflag == 6){
  1494.     if (family[index].fmgold + recvdata < 0) return -1;
  1495.     family[index].fmgold = family[index].fmgold + recvdata;
  1496.     if (family[index].fmgold > FMMAXGOLD)
  1497. family[index].fmgold = FMMAXGOLD;
  1498. sprintf(data2,"%d",family[index].fmgold);
  1499. }
  1500. else if (kindflag == 7){
  1501.     family[index].fmadv = family[index].fmadv + recvdata;
  1502.     if (family[index].fmadv < 0) family[index].fmadv = 0;
  1503.     if (family[index].fmadv > MAXFMPOPNUM) family[index].fmadv = MAXFMPOPNUM;
  1504. #ifdef _NEW_MANOR_LAW
  1505. family[index].fmmemberindex[charindex].momentum += recvdata;
  1506.     if (family[index].fmmemberindex[charindex].momentum < 0) family[index].fmmemberindex[charindex].momentum = 0;
  1507.     if (family[index].fmmemberindex[charindex].momentum > MAXFMPOPNUM) family[index].fmmemberindex[charindex].momentum = MAXFMPOPNUM;
  1508. family[index].fmmemberindex[charindex].popular = atoi(data2);
  1509. #endif
  1510. }else if (kindflag == 8){
  1511.     family[index].fmfeed = family[index].fmfeed + recvdata;
  1512.     if (family[index].fmfeed < 0) family[index].fmfeed = 0;
  1513.     if (family[index].fmfeed > MAXFMPOPNUM) family[index].fmfeed = MAXFMPOPNUM;
  1514. #ifdef _NEW_MANOR_LAW
  1515. family[index].fmmemberindex[charindex].momentum += recvdata;
  1516.     if (family[index].fmmemberindex[charindex].momentum < 0) family[index].fmmemberindex[charindex].momentum = 0;
  1517.     if (family[index].fmmemberindex[charindex].momentum > MAXFMPOPNUM) family[index].fmmemberindex[charindex].momentum = MAXFMPOPNUM;
  1518. family[index].fmmemberindex[charindex].popular = atoi(data2);
  1519. #endif
  1520. }
  1521. #ifndef _NEW_MANOR_LAW
  1522. else if (kindflag == 9){
  1523.     family[index].fmsynthesize = family[index].fmsynthesize + recvdata;
  1524.     if (family[index].fmsynthesize < 0) family[index].fmsynthesize = 0;
  1525.     if (family[index].fmsynthesize > MAXFMPOPNUM) family[index].fmsynthesize = MAXFMPOPNUM;
  1526. }
  1527. else if (kindflag == 10){
  1528. family[index].fmdealfood = family[index].fmdealfood + recvdata;
  1529. if (family[index].fmdealfood < 0) family[index].fmdealfood = 0;
  1530. if (family[index].fmdealfood > MAXFMPOPNUM) family[index].fmdealfood = MAXFMPOPNUM;
  1531.   }
  1532. #endif
  1533. #ifdef _FMVER21
  1534.   else if (kindflag == 11){
  1535. char charname[256], charid[256];
  1536. int charlv, onlineflag, charfdid, popular;
  1537. #ifdef _NEW_MANOR_LAW
  1538. int momentum;
  1539. #endif
  1540. int floor =  ACgetFMFloor(fmindex);
  1541. if (strcmp(family[index].fmmemberindex[charindex].charname, data2) != 0
  1542.  || strcmp(family[index].fmmemberindex[charindex].charid, "") == 0)
  1543.  return -1;
  1544.  // shan 2002/01/04
  1545.  log("nshan-->fmindex:%d fmname:%s newleadername:%s newleaderid->%sn", 
  1546.  fmindex, fmname, family[index].fmmemberindex[charindex].charname,
  1547.  family[index].fmmemberindex[charindex].charid );
  1548.  strcpy(charname, family[index].fmmemberindex[charindex].charname);
  1549.  strcpy(charid, family[index].fmmemberindex[charindex].charid);
  1550.  charlv = family[index].fmmemberindex[charindex].charlv;
  1551.  onlineflag = family[index].fmmemberindex[charindex].onlineflag;
  1552.  charfdid = family[index].fmmemberindex[charindex].charfdid;
  1553.  popular = family[index].fmmemberindex[charindex].popular;
  1554. #ifdef _NEW_MANOR_LAW
  1555.  momentum = family[index].fmmemberindex[charindex].momentum;
  1556. #endif
  1557.  // 资料转换
  1558.  strcpy(family[index].fmmemberindex[charindex].charname,
  1559.  family[index].fmmemberindex[0].charname);
  1560.  strcpy(family[index].fmmemberindex[charindex].charid,
  1561.  family[index].fmmemberindex[0].charid);
  1562.  family[index].fmmemberindex[charindex].charlv = family[index].fmmemberindex[0].charlv;
  1563.  family[index].fmmemberindex[charindex].charflag = FMMEMBER_MEMBER;
  1564.  family[index].fmmemberindex[charindex].onlineflag = family[index].fmmemberindex[0].onlineflag;
  1565.  family[index].fmmemberindex[charindex].charfdid = family[index].fmmemberindex[0].charfdid;
  1566.  family[index].fmmemberindex[charindex].popular = family[index].fmmemberindex[0].popular;
  1567. #ifdef _NEW_MANOR_LAW
  1568.  family[index].fmmemberindex[charindex].momentum = family[index].fmmemberindex[0].momentum;
  1569. #endif
  1570.  
  1571.  strcpy(family[index].fmmemberindex[0].charname, charname);
  1572.  strcpy(family[index].fmmemberindex[0].charid, charid);
  1573.  family[index].fmmemberindex[0].charlv = charlv;
  1574.  family[index].fmmemberindex[0].charflag = FMMEMBER_LEADER;
  1575.  family[index].fmmemberindex[0].onlineflag = onlineflag;
  1576.  family[index].fmmemberindex[0].charfdid = charfdid;
  1577.  family[index].fmmemberindex[0].popular = popular;
  1578. #ifdef _NEW_MANOR_LAW
  1579.  family[index].fmmemberindex[0].momentum = momentum;
  1580. #endif
  1581.  strcpy(family[index].fmleadername, charname);
  1582.  strcpy(family[index].fmleaderid, charid);
  1583.  family[index].fmleadergrano = recvdata;
  1584.  strcpy(family[index].petname, "");
  1585.  strcpy(family[index].petattr, "");
  1586.  
  1587.  // 更新族长资料
  1588.  if (family[index].fmmemberindex[0].onlineflag > 0)
  1589.  {
  1590. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1591.  saacproto_ACFMCharLogin_send(
  1592.         family[index].fmmemberindex[0].onlineflag,
  1593. SUCCESSFUL, index, floor, family[index].fmtotalfame,
  1594. family[index].fmmemberindex[0].charflag,
  1595. family[index].fmsetupflag, 1, 0,
  1596. family[index].fmmemberindex[0].popular, // Arminius 9.11
  1597. family[index].fmmemberindex[0].charfdid
  1598. #ifdef _NEW_MANOR_LAW
  1599. ,family[index].fmmemberindex[0].momentum
  1600. #endif
  1601. );
  1602. #else
  1603.  saacproto_ACFMCharLogin_send(
  1604.         family[index].fmmemberindex[0].onlineflag,
  1605. SUCCESSFUL, index, floor, family[index].fmpopular,
  1606. family[index].fmmemberindex[0].charflag,
  1607. family[index].fmsetupflag, 1, 0,
  1608. family[index].fmmemberindex[0].charfdid);
  1609. #endif
  1610.  }
  1611.  // 更新成员资料
  1612.  if (family[index].fmmemberindex[charindex].onlineflag > 0)
  1613.  {
  1614. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1615.  saacproto_ACFMCharLogin_send(
  1616.         family[index].fmmemberindex[charindex].onlineflag,
  1617. SUCCESSFUL, index, floor, family[index].fmtotalfame,
  1618. family[index].fmmemberindex[charindex].charflag,
  1619. family[index].fmsetupflag, 1, charindex,
  1620. family[index].fmmemberindex[charindex].popular, // Arminius 9.11
  1621. family[index].fmmemberindex[charindex].charfdid
  1622. #ifdef _NEW_MANOR_LAW
  1623. ,family[index].fmmemberindex[charindex].momentum
  1624. #endif
  1625. );
  1626. #else
  1627.  saacproto_ACFMCharLogin_send(
  1628.         family[index].fmmemberindex[charindex].onlineflag,
  1629. SUCCESSFUL, index, floor, family[index].fmpopular,
  1630. family[index].fmmemberindex[charindex].charflag,
  1631. family[index].fmsetupflag, 1, charindex,
  1632. family[index].fmmemberindex[charindex].charfdid);
  1633. #endif
  1634.  }
  1635.    }
  1636. #endif
  1637. #ifdef _NEW_MANOR_LAW
  1638. else if (kindflag == 12){
  1639. family[index].fmmemberindex[charindex].momentum = recvdata;
  1640. if(family[index].fmmemberindex[charindex].momentum < 0) family[index].fmmemberindex[charindex].momentum = 0;
  1641. if(family[index].fmmemberindex[charindex].momentum > MAXFMPOPNUM) family[index].fmmemberindex[charindex].momentum = MAXFMPOPNUM;
  1642. }
  1643. else if(kindflag == 13){
  1644.  family[index].fmmemberindex[charindex].popular = recvdata;
  1645. }
  1646. #endif
  1647.    if ((kindflag == 2) || (kindflag == 7) || (kindflag == 8) || (kindflag == 9)
  1648.  || (kindflag == 10)
  1649. #ifdef _NEW_MANOR_LAW
  1650.  || (kindflag == 12) || (kindflag == 13)
  1651. #endif
  1652.  )
  1653.    {
  1654. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1655.  // 记录玩家家族声望
  1656. #ifndef _NEW_MANOR_LAW
  1657.  if (charindex >= 0 && charindex < MAX_MEMBERNUM)
  1658.  family[index].fmmemberindex[charindex].popular += recvdata;
  1659. #endif
  1660.  // 计算家族声望
  1661.  family[index].fmpopular = family[index].fmadv + family[index].fmfeed
  1662.  + family[index].fmsynthesize + family[index].fmdealfood
  1663.  + family[index].fmpk;
  1664.  {
  1665.  int j;
  1666.  family[index].fmtotalfame=family[index].fmpopular;
  1667. #ifdef _NEW_MANOR_LAW
  1668.  family[index].fmmomentum = 0;
  1669. #endif
  1670.  for (j = 0; j < MAX_MEMBERNUM; j++) {
  1671.  if ((family[index].fmmemberindex[j].charflag!=FMMEMBER_NONE) &&
  1672.  (family[index].fmmemberindex[j].charflag!=FMMEMBER_APPLY) )
  1673.  {
  1674.  family[index].fmtotalfame += family[index].fmmemberindex[j].popular;
  1675. #ifdef _NEW_MANOR_LAW
  1676.  // 家族成员个人气势加总
  1677.  family[index].fmmomentum += family[index].fmmemberindex[j].momentum;
  1678. #endif
  1679.  }
  1680.  }
  1681. #ifdef _NEW_MANOR_LAW
  1682.  // 家族气势 = (家族人数平方) / 10 + 1 + 家族成员个人气势加总
  1683.  family[index].fmmomentum += ((family[index].fmjoinnum * family[index].fmjoinnum) / 10 + 1) * 100;
  1684. //  log("nACFixFMData total family momentum %dn",family[index].fmmomentum);
  1685. #endif
  1686.  }
  1687.  sortFamily();
  1688.  if (family[index].fmpointindex >= 0){
  1689.  fmpoint[family[index].fmpointindex].hadfmpopular = family[index].fmtotalfame;
  1690.  db_fmpointupdate = 1;
  1691.  }
  1692. #else
  1693.  family[index].fmpopular = family[index].fmadv + family[index].fmfeed
  1694.  + family[index].fmsynthesize + family[index].fmdealfood
  1695.  + family[index].fmpk;
  1696.  sortFamily();
  1697.  if (family[index].fmpointindex >= 0){
  1698.  fmpoint[family[index].fmpointindex].hadfmpopular = family[index].fmpopular;
  1699.  db_fmpointupdate = 1;
  1700.  }
  1701.  // 记录玩家家族声望
  1702.  if (charindex >= 0 && charindex < MAX_MEMBERNUM)
  1703.  family[index].fmmemberindex[charindex].popular = 
  1704.  family[index].fmmemberindex[charindex].popular + recvdata;
  1705. #endif
  1706.  // 更新族长资料
  1707.  if (family[index].fmmemberindex[0].onlineflag > 0)
  1708.  {
  1709.  int floor =  ACgetFMFloor(fmindex);
  1710. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1711.  saacproto_ACFMCharLogin_send(
  1712.         family[index].fmmemberindex[0].onlineflag,
  1713. SUCCESSFUL, index, floor, family[index].fmtotalfame,
  1714. #ifdef _FMVER21
  1715. family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0,
  1716. #else     
  1717. 1, family[index].fmsetupflag, 1, 0,
  1718. #endif
  1719. family[index].fmmemberindex[0].popular, // Arminius 9.11
  1720. family[index].fmmemberindex[0].charfdid
  1721. #ifdef _NEW_MANOR_LAW
  1722. ,family[index].fmmemberindex[0].momentum
  1723. #endif
  1724. );
  1725. #else
  1726.  saacproto_ACFMCharLogin_send(
  1727.         family[index].fmmemberindex[0].onlineflag,
  1728. SUCCESSFUL, index, floor, family[index].fmpopular,
  1729. #ifdef _FMVER21
  1730. family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0,
  1731. #else     
  1732. 1, family[index].fmsetupflag, 1, 0,
  1733. #endif
  1734. family[index].fmmemberindex[0].charfdid);
  1735. #endif
  1736.  }
  1737.    }
  1738.    db_familyupdate[index] = 1;
  1739.    return kindflag;
  1740. }
  1741. // 更改PK後家族PK值
  1742. int ACFixFMPK(int winindex, char* winfmname, int winfmindex, int loseindex,
  1743. char* losefmname, int losefmindex)
  1744. {
  1745.    int award = 0;
  1746.    if (CheckFM(&winindex, winfmname, winfmindex) < 0) return -1;
  1747.    if (CheckFM(&loseindex, losefmname, losefmindex) < 0) return -1;
  1748.    
  1749.    award = (family[loseindex].fmpopular / 10);
  1750.    if (family[loseindex].fmpopular - award < 0)
  1751.     award = family[loseindex].fmpopular;
  1752.    family[loseindex].fmpk = family[loseindex].fmpk - award;
  1753.    family[winindex].fmpk = family[winindex].fmpk + award;
  1754.    if (family[loseindex].fmpk < MINFMPOPNUM)
  1755.    {
  1756. #if 1 // Robin 2003/11/27 修正输方家族PK声望到达下限时胜方可洗声望
  1757. int overpoint;
  1758. overpoint = MINFMPOPNUM - family[loseindex].fmpk;
  1759. family[winindex].fmpk = family[winindex].fmpk - overpoint;
  1760. #endif
  1761. family[loseindex].fmpk = MINFMPOPNUM;
  1762.    }
  1763.    // CoolFish: 2001/11/28 MINFMPOPNUM -> MAXFMPOPNUM
  1764.    if (family[winindex].fmpk > MAXFMPOPNUM)
  1765. family[winindex].fmpk = MAXFMPOPNUM;
  1766.    {
  1767.     family[winindex].fmpopular = family[winindex].fmadv + family[winindex].fmfeed
  1768.     + family[winindex].fmsynthesize + family[winindex].fmdealfood
  1769.     + family[winindex].fmpk;
  1770. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1771. {
  1772.           int j;
  1773.           family[winindex].fmtotalfame=family[winindex].fmpopular;
  1774.           for (j = 0; j < MAX_MEMBERNUM; j++) {
  1775.             if ((family[winindex].fmmemberindex[j].charflag!=FMMEMBER_NONE) &&
  1776.                 (family[winindex].fmmemberindex[j].charflag!=FMMEMBER_APPLY) )
  1777.               family[winindex].fmtotalfame += family[winindex].fmmemberindex[j].popular;
  1778.           }
  1779. }
  1780. #endif
  1781.     if (family[winindex].fmmemberindex[0].onlineflag > 0)
  1782.     {
  1783.     int floor =  ACgetFMFloor(winfmindex);
  1784. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1785.       saacproto_ACFMCharLogin_send(
  1786.         family[winindex].fmmemberindex[0].onlineflag,
  1787.         SUCCESSFUL, winindex, floor, family[winindex].fmtotalfame,
  1788. #ifdef _FMVER21
  1789. family[winindex].fmmemberindex[0].charflag, family[winindex].fmsetupflag, 1, 0,
  1790. #else     
  1791.         1, family[winindex].fmsetupflag, 1, 0,
  1792. #endif
  1793. family[winindex].fmmemberindex[0].popular, // Arminius 9.11
  1794.         family[winindex].fmmemberindex[0].charfdid
  1795. #ifdef _NEW_MANOR_LAW
  1796. ,family[winindex].fmmemberindex[0].momentum
  1797. #endif
  1798. );
  1799. #else
  1800.       saacproto_ACFMCharLogin_send(
  1801.         family[winindex].fmmemberindex[0].onlineflag,
  1802.         SUCCESSFUL, winindex, floor, family[winindex].fmpopular,
  1803. #ifdef _FMVER21
  1804. family[winindex].fmmemberindex[0].charflag, family[winindex].fmsetupflag, 1, 0,
  1805. #else     
  1806.         1, family[winindex].fmsetupflag, 1, 0,
  1807. #endif
  1808.         family[winindex].fmmemberindex[0].charfdid);
  1809. #endif
  1810.     }
  1811.     family[loseindex].fmpopular = family[loseindex].fmadv + family[loseindex].fmfeed
  1812.     + family[loseindex].fmsynthesize + family[loseindex].fmdealfood
  1813.     + family[loseindex].fmpk;
  1814. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1815. {
  1816.           int j;
  1817.           family[loseindex].fmtotalfame=family[loseindex].fmpopular;
  1818.           for (j = 0; j < MAX_MEMBERNUM; j++) {
  1819.             if ((family[loseindex].fmmemberindex[j].charflag!=FMMEMBER_NONE) &&
  1820.                 (family[loseindex].fmmemberindex[j].charflag!=FMMEMBER_APPLY) )
  1821.               family[loseindex].fmtotalfame += family[loseindex].fmmemberindex[j].popular;
  1822.           }
  1823. }
  1824. #endif
  1825.     if (family[loseindex].fmmemberindex[0].onlineflag > 0)
  1826.     {
  1827.     int floor =  ACgetFMFloor(losefmindex);
  1828. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1829.       saacproto_ACFMCharLogin_send(
  1830.         family[loseindex].fmmemberindex[0].onlineflag,
  1831.         SUCCESSFUL, loseindex, floor, family[loseindex].fmtotalfame,
  1832. #ifdef _FMVER21
  1833. family[loseindex].fmmemberindex[0].charflag, family[loseindex].fmsetupflag, 1, 0,
  1834. #else     
  1835.         1, family[loseindex].fmsetupflag, 1, 0,
  1836. #endif
  1837. family[loseindex].fmmemberindex[0].popular, // Arminius 9.11
  1838.         family[loseindex].fmmemberindex[0].charfdid
  1839. #ifdef _NEW_MANOR_LAW
  1840. ,family[loseindex].fmmemberindex[0].momentum
  1841. #endif
  1842. );
  1843. #else
  1844.       saacproto_ACFMCharLogin_send(
  1845.         family[loseindex].fmmemberindex[0].onlineflag,
  1846.         SUCCESSFUL, loseindex, floor, family[loseindex].fmpopular,
  1847. #ifdef _FMVER21
  1848. family[loseindex].fmmemberindex[0].charflag, family[loseindex].fmsetupflag, 1, 0,
  1849. #else     
  1850.         1, family[loseindex].fmsetupflag, 1, 0,
  1851. #endif
  1852.         family[loseindex].fmmemberindex[0].charfdid);
  1853. #endif
  1854.     }
  1855.    }
  1856.    sortFamily();
  1857.    if (family[winindex].fmpointindex >= 0)
  1858.    {
  1859. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1860.     fmpoint[family[winindex].fmpointindex].hadfmpopular = family[winindex].fmtotalfame;
  1861. #else
  1862.     fmpoint[family[winindex].fmpointindex].hadfmpopular = family[winindex].fmpopular;
  1863. #endif
  1864.     db_fmpointupdate = 1;
  1865.    }
  1866.    if (family[loseindex].fmpointindex >= 0)
  1867.    {
  1868. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1869.     fmpoint[family[loseindex].fmpointindex].hadfmpopular = family[loseindex].fmtotalfame;
  1870. #else
  1871.     fmpoint[family[loseindex].fmpointindex].hadfmpopular = family[loseindex].fmpopular;
  1872. #endif
  1873.     db_fmpointupdate = 1;
  1874.    }
  1875.    return award;
  1876. }
  1877. // 解散家族
  1878. int ACDelFM(int index, char *fmname, int fmindex)
  1879. {
  1880. int i;
  1881. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  1882. log("nACDelFM index:%d fmname:%s fmindex:%dn", index, fmname, fmindex);
  1883. if (family[index].fmpointindex >= 0)
  1884. {
  1885.     delfmpointindex(family[index].fmindex);
  1886.     family[index].fmpointindex = -1;
  1887. }
  1888. if (family[index].memonum > 0)
  1889. {
  1890.     for (i = 0; i < family[index].memonum; i++)
  1891. memset(family[index].memolist[i], 0,
  1892. sizeof(family[index].memolist[i]));
  1893. }
  1894. family[index].fmindex = -1;
  1895. memset(family[index].fmname, 0, sizeof(family[index].fmname));
  1896. memset(family[index].memolist, 0, sizeof(family[index].memolist));
  1897. family[index].fmnum = 0;
  1898. family[index].fmjoinnum = 0;
  1899. family[index].fmsetupflag = -1;
  1900. family[index].fmpopular = 0;
  1901. family[index].fmadv = 0;
  1902. family[index].fmfeed= 0;
  1903. family[index].fmsynthesize = 0;
  1904. family[index].fmdealfood = 0;
  1905. family[index].fmpk = 0;
  1906. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1907. family[index].fmtotalfame = 0;
  1908. #endif
  1909. #ifdef _NEW_MANOR_LAW
  1910. family[index].fmmomentum = 0;
  1911. #endif
  1912. for (i = 0; i < family[index].fmmemberindexmaxnum; i++)
  1913. {
  1914.     // 传送最新状态给家族成员
  1915. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1916.     if (family[index].fmmemberindex[i].onlineflag > 0)
  1917. saacproto_ACFMCharLogin_send(
  1918.     family[index].fmmemberindex[i].onlineflag,
  1919. FAILED, index, family[index].fmpointindex,
  1920. family[index].fmtotalfame, -1, family[index].fmsetupflag, 0,
  1921. i, family[index].fmmemberindex[i].popular, // Arminius 9.11
  1922. family[index].fmmemberindex[i].charfdid
  1923. #ifdef _NEW_MANOR_LAW
  1924. ,family[index].fmmemberindex[i].momentum
  1925. #endif
  1926. );
  1927. #else
  1928.     if (family[index].fmmemberindex[i].onlineflag > 0)
  1929. saacproto_ACFMCharLogin_send(
  1930.     family[index].fmmemberindex[i].onlineflag,
  1931. FAILED, index, family[index].fmpointindex,
  1932. family[index].fmpopular, -1, family[index].fmsetupflag, 0,
  1933. i, family[index].fmmemberindex[i].charfdid);
  1934. #endif
  1935.     memset(family[index].fmmemberindex[i].charname, 0,
  1936. sizeof(family[index].fmmemberindex[i].charname));
  1937.     memset(family[index].fmmemberindex[i].charid, 0,
  1938. sizeof(family[index].fmmemberindex[i].charid));
  1939.     family[index].fmmemberindex[i].charflag = FMMEMBER_NONE;
  1940.     family[index].fmmemberindex[i].predeltime = -1;
  1941.     family[index].fmmemberindex[i].popular = 0;
  1942. #ifdef _NEW_MANOR_LAW
  1943. family[index].fmmemberindex[i].momentum = 0;
  1944. #endif
  1945. }
  1946. family[index].fmmemberindexmaxnum = 0;
  1947. fmnownum--;
  1948. if (fmindexmaxnum == index) fmindexmaxnum--;
  1949. // 传送家族已删除之讯息至各 GMSV 以清除对战排程
  1950. for (i = 0; i < MAXCONNECTION; i++)
  1951. {
  1952.     if (gs[i].use && gs[i].name[0])
  1953. saacproto_ACFMClearPK_send(i, SUCCESSFUL, fmname, fmindex, index);
  1954. }
  1955. DelFMMaintainSort(index);
  1956. db_familyupdate[i] = 1;
  1957. return 0;
  1958. }
  1959. // 显示家族列表
  1960. int ACShowFMList(char *data)
  1961. {
  1962.    int i = 0;
  1963.    strcpy(data, "");
  1964.    
  1965.    for (i = 0; i <= fmindexmaxnum; i++)
  1966.    {
  1967.       char msg[256];
  1968.       if ((strcmp(family[i].fmname, "") != 0) && (family[i].fmindex != -1))
  1969.       {
  1970. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  1971.          sprintf(msg, "%d %s %s %d %d %d %d %d|", family[i].fmindex, family[i].fmname,
  1972.           family[i].fmleadername, family[i].fmtotalfame, family[i].fmjoinnum, i,
  1973.           family[i].fmsetupflag, family[i].fmacceptflag);
  1974. #else
  1975.          sprintf(msg, "%d %s %s %d %d %d %d %d|", family[i].fmindex, family[i].fmname,
  1976.           family[i].fmleadername, family[i].fmpopular, family[i].fmjoinnum, i,
  1977.           family[i].fmsetupflag, family[i].fmacceptflag);
  1978. #endif
  1979.          strcat(data, msg);
  1980.       }
  1981.    }
  1982.    return fmnownum;
  1983. }
  1984. // 显示家族成员列表
  1985. int ACShowFMMemberList(int index, int *fmacceptflag, int *fmjoinnum, char *data)
  1986. {
  1987.    int i = 0;
  1988.    if ((index > MAX_FAMILY) || (index < 0)) return -1;
  1989.    if (CheckFMUse(index) == 0) return -1;
  1990.    
  1991.    strcpy(data, "");
  1992.    *fmjoinnum = family[index].fmjoinnum;
  1993.    for (i = 0; i < family[index].fmmemberindexmaxnum; i++)
  1994.    {
  1995.       char msg[256];
  1996.       if ((strcmp(family[index].fmmemberindex[i].charname, "") != 0)
  1997.          && (strcmp(family[index].fmmemberindex[i].charid, "") != 0)
  1998.          && (family[index].fmmemberindex[i].charflag != FMMEMBER_NONE))
  1999.       {
  2000. #ifdef _FM_MODIFY
  2001. #ifdef _NEW_MANOR_LAW
  2002. sprintf(msg, "%d|%s|%d|%d|%d|%d|%d|%d|%d ", i,
  2003. #else
  2004. sprintf(msg, "%d|%s|%d|%d|%d|%d|%d|%d ", i,
  2005. #endif
  2006.           family[index].fmmemberindex[i].charname,
  2007.           family[index].fmmemberindex[i].charlv,
  2008.           family[index].fmmemberindex[i].onlineflag,
  2009.           (family[index].fmmemberindex[i].popular / 100),
  2010.           family[index].fmmemberindex[i].eventflag,
  2011.           family[index].fmmemberindex[i].charflag,
  2012. family[index].fmmemberindex[i].gsnum
  2013. #ifdef _NEW_MANOR_LAW
  2014. ,family[index].fmmemberindex[i].momentum/100
  2015. #endif
  2016. );
  2017.           strcat(data, msg);
  2018. #else
  2019. #ifdef _FMVER21
  2020.          sprintf(msg, "%d|%s|%d|%d|%d|%d|%d ", i,
  2021.             family[index].fmmemberindex[i].charname,
  2022.             family[index].fmmemberindex[i].charlv,
  2023.             family[index].fmmemberindex[i].onlineflag,
  2024.             (family[index].fmmemberindex[i].popular / 100),
  2025.             family[index].fmmemberindex[i].eventflag,
  2026.             family[index].fmmemberindex[i].charflag);
  2027.             strcat(data, msg);
  2028. #else
  2029.          sprintf(msg, "%d|%s|%d|%d|%d|%d ", i,
  2030.             family[index].fmmemberindex[i].charname,
  2031.             family[index].fmmemberindex[i].charlv,
  2032.             family[index].fmmemberindex[i].onlineflag,
  2033.             (family[index].fmmemberindex[i].popular / 100),
  2034.             family[index].fmmemberindex[i].charflag);
  2035.             strcat(data, msg);
  2036. #endif            
  2037. #endif
  2038.       }
  2039.    } // for 
  2040.    *fmacceptflag = family[index].fmacceptflag;
  2041.    return family[index].fmnum;
  2042. }
  2043. // 显示家族详细资料
  2044. int ACFMDetail(int index, char *fmname, int fmindex, char *data)
  2045. {
  2046.    if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2047.    
  2048.    strcpy(data, "");
  2049.    sprintf(data, "%d|%d|%s|%s|%d|%s|%s|%d|%d|%s|%d", index, family[index].fmindex,
  2050.     family[index].fmname, family[index].fmleadername,
  2051.     family[index].fmleadergrano, family[index].petname, family[index].petattr,
  2052.     family[index].fmjoinnum, family[index].fmacceptflag,
  2053.     family[index].fmrule, family[index].fmsprite );
  2054.    return 0;
  2055. }
  2056. // 族长审核成员加入家族
  2057. #ifdef _FMVER21
  2058. int ACMemberJoinFM(int index, char *fmname, int fmindex,
  2059. char *charname, int charindex, int result, int meindex)
  2060. #else
  2061. int ACMemberJoinFM(int index, char *fmname, int fmindex,
  2062. char *charname, int charindex, int result)
  2063. #endif
  2064. {
  2065. time_t t1;
  2066. int floor;
  2067. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2068. floor = ACgetFMFloor(fmindex);
  2069. #ifdef _FIX_LEADER_ERR // WON ADD 修正族长问题
  2070. if (charindex == 0 ) return -1;
  2071. #endif
  2072. #ifdef _FMVER21
  2073. if (result < 0) return -1;
  2074. if (meindex < 0 || meindex > MAX_MEMBERNUM) return -1;
  2075. #endif
  2076. if (strcmp(family[index].fmmemberindex[charindex].charname, charname) == 0){
  2077. if (family[index].fmjoinnum >= MAX_MEMBERNUM) return -1;
  2078. time(&t1);
  2079. family[index].fmmemberindex[charindex].predeltime = t1 + PREDELMEMBER_TIME;
  2080. if (family[index].fmmemberindex[charindex].charflag == FMMEMBER_APPLY) family[index].fmjoinnum++;
  2081. if (family[index].fmmemberindexmaxnum <= charindex) family[index].fmmemberindexmaxnum = charindex + 1;
  2082. if (family[index].fmjoinnum >= MIN_MEMBERNUM)
  2083. {
  2084. if (family[index].fmjoinnum == MIN_MEMBERNUM) family[index].setup_time = t1;
  2085. family[index].fmsetupflag = 1;
  2086. family[index].predel_time = -1;
  2087. }
  2088. if (family[index].fmjoinnum >= MAX_MEMBERNUM) family[index].fmacceptflag = 0;
  2089. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2090. {
  2091. int j;
  2092. family[index].fmtotalfame=family[index].fmpopular;
  2093. for (j = 0; j < MAX_MEMBERNUM; j++) {
  2094. if ((family[index].fmmemberindex[j].charflag!=FMMEMBER_NONE) &&
  2095. (family[index].fmmemberindex[j].charflag!=FMMEMBER_APPLY) )
  2096. family[index].fmtotalfame += family[index].fmmemberindex[j].popular;
  2097. }
  2098. }
  2099. #endif
  2100. #ifdef _FMVER21
  2101. if (result != FMMEMBER_MEMBER)
  2102. {
  2103. if (result == FMMEMBER_ELDER && family[index].fmmemberindex[charindex].eventflag != 1)
  2104. return -1;
  2105. if (ACFMAssignOcp(index, fmname, fmindex, charname, charindex, result) >= 0)
  2106. return 0;
  2107. else return -1;
  2108. }
  2109. #endif
  2110. if (family[index].fmmemberindex[charindex].onlineflag > 0){
  2111. char buf[256];
  2112.         // 通知玩家
  2113. #ifdef _FMVER21
  2114. if (family[index].fmmemberindex[charindex].charflag != FMMEMBER_APPLY)
  2115. sprintf(buf, "%s族长已经将你的家族职等改为%s!",
  2116. family[index].fmname, MEMBERKIND_INTDATA[result]);
  2117. else
  2118. sprintf(buf, "恭喜你!%s已经审核完毕您的加入申请!",
  2119. family[index].fmmemberindex[meindex].charname);
  2120. #else
  2121.         sprintf(buf, "恭喜你!%s族长已经审核完毕您的加入申请!", family[index].fmname);
  2122. #endif
  2123.         saacproto_ACFMAnnounce_send(family[index].fmmemberindex[charindex].onlineflag,
  2124. SUCCESSFUL, fmname, fmindex, index, 3, buf,
  2125. family[index].fmmemberindex[charindex].charfdid);
  2126. #ifdef _FMVER21
  2127. family[index].fmmemberindex[charindex].charflag = FMMEMBER_MEMBER;
  2128. // 计算家族声望
  2129. family[index].fmpopular = family[index].fmadv + family[index].fmfeed
  2130.          + family[index].fmsynthesize + family[index].fmdealfood
  2131. + family[index].fmpk;
  2132. {
  2133. int j;
  2134. family[index].fmtotalfame = family[index].fmpopular;
  2135. for (j = 0; j < MAX_MEMBERNUM; j++)
  2136. {
  2137. if ((family[index].fmmemberindex[j].charflag != FMMEMBER_NONE) &&
  2138. (family[index].fmmemberindex[j].charflag != FMMEMBER_APPLY) )
  2139. family[index].fmtotalfame += family[index].fmmemberindex[j].popular;
  2140. }
  2141. }
  2142. #else
  2143. family[index].fmmemberindex[charindex].charflag = 1;
  2144. #endif
  2145. #ifdef _NEW_MANOR_LAW
  2146. {
  2147. int i;
  2148. family[index].fmmomentum = 0;
  2149. for(i=0;i<MAX_MEMBERNUM;i++){
  2150. if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) &&
  2151. (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY))
  2152. // 家族成员个人气势加总
  2153. family[index].fmmomentum += family[index].fmmemberindex[i].momentum;
  2154. }
  2155. // 家族气势 = (家族人数平方) / 10 + 1 + 家族成员个人气势加总
  2156. family[index].fmmomentum += ((family[index].fmjoinnum * family[index].fmjoinnum) / 10 + 1) * 100;
  2157. }
  2158. #endif
  2159. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2160. saacproto_ACFMCharLogin_send(
  2161. family[index].fmmemberindex[charindex].onlineflag,
  2162. SUCCESSFUL, index, floor, family[index].fmtotalfame,
  2163. #ifdef _FMVER21
  2164. family[index].fmmemberindex[charindex].charflag, family[index].fmsetupflag, 1, charindex,
  2165. #else     
  2166. 2, family[index].fmsetupflag, 1, charindex,
  2167. #endif
  2168. family[index].fmmemberindex[charindex].popular, // Arminius 9.11
  2169. family[index].fmmemberindex[charindex].charfdid
  2170. #ifdef _NEW_MANOR_LAW
  2171. ,family[index].fmmemberindex[charindex].momentum
  2172. #endif
  2173. );
  2174. #else
  2175. saacproto_ACFMCharLogin_send(
  2176. family[index].fmmemberindex[charindex].onlineflag,
  2177. SUCCESSFUL, index, floor, family[index].fmpopular,
  2178. #ifdef _FMVER21
  2179. family[index].fmmemberindex[charindex].charflag, family[index].fmsetupflag, 1, charindex,
  2180. #else     
  2181. 2, family[index].fmsetupflag, 1, charindex,
  2182. #endif
  2183. family[index].fmmemberindex[charindex].charfdid);
  2184. #endif
  2185. }
  2186. // 更新族长状态
  2187. if (family[index].fmmemberindex[charindex].onlineflag > 0)
  2188. {
  2189. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2190. saacproto_ACFMCharLogin_send(
  2191. family[index].fmmemberindex[0].onlineflag,
  2192. SUCCESSFUL, index, floor, family[index].fmtotalfame,
  2193. #ifdef _FMVER21
  2194. family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0,
  2195. #else     
  2196. 1, family[index].fmsetupflag, 1, 0,
  2197. #endif
  2198. family[index].fmmemberindex[0].popular, // Arminius 9.11
  2199. family[index].fmmemberindex[0].charfdid
  2200. #ifdef _NEW_MANOR_LAW
  2201. ,family[index].fmmemberindex[0].momentum
  2202. #endif
  2203. );
  2204. #else
  2205. saacproto_ACFMCharLogin_send(
  2206. family[index].fmmemberindex[0].onlineflag,
  2207. SUCCESSFUL, index, floor, family[index].fmpopular,
  2208. #ifdef _FMVER21
  2209. family[index].fmmemberindex[0].charflag, family[index].fmsetupflag, 1, 0,
  2210. #else     
  2211. 1, family[index].fmsetupflag, 1, 0,
  2212. #endif
  2213. family[index].fmmemberindex[0].charfdid);
  2214. #endif
  2215. }
  2216. #ifdef _FMVER21
  2217. family[index].fmmemberindex[charindex].charflag = FMMEMBER_MEMBER;
  2218. #else
  2219. family[index].fmmemberindex[charindex].charflag = 1;
  2220. #endif
  2221.    }
  2222.  db_familyupdate[index] = 1;
  2223.  return 0;
  2224.    return -1;
  2225. }
  2226. // 族长审核成员离开家族
  2227. #ifdef _FMVER21
  2228. int ACMemberLeaveFM(int index, char *fmname, int fmindex,
  2229. char *charname, int flag, int charindex, int meindex)
  2230. #else
  2231. int ACMemberLeaveFM(int index, char *fmname, int fmindex,
  2232. char *charname, int flag, int charindex)
  2233. #endif
  2234. {
  2235. time_t t1;
  2236. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2237. #ifdef _FMVER21
  2238. if (meindex < 0 || meindex > MAX_MEMBERNUM) return -1;
  2239. #endif
  2240. #ifdef _FIX_LEADER_ERR // WON ADD 修正族长问题
  2241. if (charindex == 0 ) return -1;
  2242. #endif
  2243. if (strcmp(family[index].fmmemberindex[charindex].charname, charname) == 0)
  2244. {
  2245. if (family[index].fmmemberindex[charindex].charflag <= 0) return -1;
  2246. if (family[index].fmmemberindex[charindex].onlineflag > 0)
  2247. {
  2248.       char buf[256];
  2249. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2250.       saacproto_ACFMCharLogin_send(
  2251. family[index].fmmemberindex[charindex].onlineflag,
  2252. FAILED, index, family[index].fmpointindex,
  2253. 0, -1, family[index].fmsetupflag, 1,
  2254. charindex, 
  2255. family[index].fmmemberindex[charindex].popular, // Arminius 9.11
  2256. family[index].fmmemberindex[charindex].charfdid
  2257. #ifdef _NEW_MANOR_LAW
  2258. ,family[index].fmmemberindex[charindex].momentum
  2259. #endif
  2260. );
  2261. #else
  2262.       saacproto_ACFMCharLogin_send(
  2263. family[index].fmmemberindex[charindex].onlineflag,
  2264. FAILED, index, family[index].fmpointindex,
  2265. family[index].fmpopular, -1, family[index].fmsetupflag, 1,
  2266. charindex, family[index].fmmemberindex[charindex].charfdid);
  2267. #endif
  2268. // 通知玩家
  2269. if (flag == 1)
  2270. {
  2271. #ifdef _FMVER21
  2272. sprintf(buf, "%s已经将你踢出家族了!", family[index].fmmemberindex[meindex].charname);
  2273. #else
  2274. sprintf(buf, "%s族长已经将你踢出家族了!", family[index].fmname);
  2275. #endif
  2276. saacproto_ACFMAnnounce_send(family[index].fmmemberindex[charindex].onlineflag,
  2277. SUCCESSFUL, fmname, fmindex, index, 3, buf,
  2278. family[index].fmmemberindex[charindex].charfdid);
  2279. }
  2280. }
  2281. memset(family[index].fmmemberindex[charindex].charname, 0,
  2282. sizeof(family[index].fmmemberindex[charindex].charname));
  2283. memset(family[index].fmmemberindex[charindex].charid, 0,
  2284. sizeof(family[index].fmmemberindex[charindex].charid));
  2285. family[index].fmmemberindex[charindex].onlineflag = -1;
  2286. family[index].fmmemberindex[charindex].popular = 0;
  2287. #ifdef _FMVER21
  2288. family[index].fmmemberindex[charindex].eventflag = 0;
  2289. if (family[index].fmmemberindex[charindex].charflag != FMMEMBER_APPLY)
  2290. #else
  2291. if(family[index].fmmemberindex[charindex].charflag != 2)
  2292. #endif 
  2293. family[index].fmjoinnum = family[index].fmjoinnum - 1;
  2294. family[index].fmnum = family[index].fmnum - 1;
  2295. family[index].fmmemberindex[charindex].charflag = FMMEMBER_NONE;
  2296. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2297. {
  2298. int j;
  2299. family[index].fmtotalfame=family[index].fmpopular;
  2300. for (j = 0; j < MAX_MEMBERNUM; j++) {
  2301. if ((family[index].fmmemberindex[j].charflag!=FMMEMBER_NONE) &&
  2302. (family[index].fmmemberindex[j].charflag!=FMMEMBER_APPLY) )
  2303. family[index].fmtotalfame += family[index].fmmemberindex[j].popular;
  2304. }
  2305. }
  2306. #endif
  2307. if (family[index].fmnum < 1 || family[index].fmjoinnum < 1)
  2308. {
  2309. int i = 0, fmnum1 = 0, fmnum2 = 0;
  2310. for (i = 0; i < MAX_MEMBERNUM; i++)
  2311. {
  2312. if (family[index].fmmemberindex[i].charflag <= 0) continue;
  2313. #ifdef _FMVER21
  2314. if (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY)
  2315. #else
  2316. if (family[index].fmmemberindex[i].charflag == 1)
  2317. #endif           
  2318.         fmnum1 = fmnum1 + 1;
  2319. if (family[index].fmmemberindex[i].charflag > 0)
  2320.      fmnum2 = fmnum2 + 1;
  2321. }
  2322. log("MemberLeave_fmnum err!n index:%d fmname:%s"
  2323. " orifmnum:%d orifmjoinnum:%dn fmnum1:%d fmnum2:%dn",
  2324. index, fmname, family[index].fmnum,
  2325. family[index].fmjoinnum, fmnum1, fmnum2);
  2326. family[index].fmjoinnum = fmnum1;
  2327. family[index].fmnum = fmnum2;
  2328. }
  2329. #ifdef _NEW_MANOR_LAW
  2330. // 家族成员个人气势设定为0
  2331. family[index].fmmemberindex[charindex].momentum = 0;
  2332. {
  2333. int i;
  2334. family[index].fmmomentum = 0;
  2335. for(i=0;i<MAX_MEMBERNUM;i++){
  2336. if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) &&
  2337. (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY))
  2338. // 家族成员个人气势加总
  2339. family[index].fmmomentum += family[index].fmmemberindex[i].momentum;
  2340. }
  2341. // 家族气势 = (家族人数平方) / 10 + 1 + 家族成员个人气势加总
  2342. family[index].fmmomentum += ((family[index].fmjoinnum * family[index].fmjoinnum) / 10 + 1) * 100;
  2343. }
  2344. #endif
  2345. if (family[index].fmmemberindexmaxnum == charindex) family[index].fmmemberindexmaxnum--;
  2346. if (family[index].fmjoinnum < MIN_MEMBERNUM){
  2347. time(&t1);
  2348. if( family[index].fmsetupflag != 0 ){
  2349. family[index].fmsetupflag = 0;
  2350. family[index].predel_time = t1 + PREDEL_TIME;
  2351. }
  2352. if (family[index].fmmemberindex[charindex].onlineflag > 0 ){
  2353. char token[256];
  2354. sprintf( token, "在七天之内要赶快召集10名成员,否则家族会被解散喔!剩馀%d天。",
  2355. (int)((family[index].predel_time - t1)/(60*60*24)) );
  2356. saacproto_ACFMAnnounce_send(
  2357.         family[index].fmmemberindex[0].onlineflag,
  2358. SUCCESSFUL, fmname, fmindex, index, 3,
  2359. token, family[index].fmmemberindex[0].charfdid );
  2360. }
  2361. }
  2362. db_familyupdate[index] = 1;
  2363. return 0;
  2364. }
  2365.   return -1;
  2366. }
  2367. // 族长分配职务
  2368. int ACFMAssignOcp(int index, char *fmname, int fmindex,
  2369. char *charname, int charindex, int result)
  2370. {
  2371. #ifdef _FMVER21
  2372.    int floor, count = 0, i = 0;
  2373.    char buf[256];
  2374.    if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2375.    floor = ACgetFMFloor(fmindex);
  2376.    if (result < 0) return -1;
  2377.  
  2378. #ifdef _FIX_LEADER_ERR // WON ADD 修正族长问题
  2379.    if (charindex == 0 ) return -1;
  2380. #endif  
  2381.  
  2382.    log("AsssignOcp index:%d fmindex:%d fmname:%s charname:%s charindex:%d result:%dn",
  2383.     index, fmindex, fmname, charname, charindex, result);
  2384.    for (i = 0; i < MAX_MEMBERNUM; i++)
  2385.    {
  2386. if (family[index].fmmemberindex[i].charflag == result
  2387. && result != FMMEMBER_MEMBER)
  2388. count++;
  2389.    }
  2390.    if (count >= FMELDERNUM)
  2391.    {
  2392.     sprintf(buf, "n只能指派%d位家族成员成为%s喔!",
  2393.     FMELDERNUM, MEMBERKIND_INTDATA[result]);
  2394.     saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag,
  2395.     SUCCESSFUL, fmname, fmindex, index, 4, buf,
  2396.     family[index].fmmemberindex[0].charfdid);
  2397.     return -1;
  2398.    }
  2399.    if (strcmp(family[index].fmmemberindex[charindex].charname, charname) == 0)
  2400.    {
  2401.     family[index].fmmemberindex[charindex].charflag = result;
  2402.         if (family[index].fmmemberindex[charindex].onlineflag > 0)
  2403.         {
  2404. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2405.          saacproto_ACFMCharLogin_send(
  2406.     family[index].fmmemberindex[charindex].onlineflag,
  2407.     SUCCESSFUL, index, floor, family[index].fmtotalfame,
  2408. family[index].fmmemberindex[charindex].charflag,
  2409. family[index].fmsetupflag, 1, charindex,
  2410. family[index].fmmemberindex[charindex].popular, // Arminius 9.11
  2411.     family[index].fmmemberindex[charindex].charfdid
  2412. #ifdef _NEW_MANOR_LAW
  2413. ,family[index].fmmemberindex[charindex].momentum
  2414. #endif
  2415. );
  2416. #else
  2417.          saacproto_ACFMCharLogin_send(
  2418.         family[index].fmmemberindex[charindex].onlineflag,
  2419.         SUCCESSFUL, index, floor, family[index].fmpopular,
  2420. family[index].fmmemberindex[charindex].charflag,
  2421. family[index].fmsetupflag, 1, charindex,
  2422.     family[index].fmmemberindex[charindex].charfdid);
  2423. #endif
  2424.         // 通知玩家
  2425.         sprintf(buf, "%s族长已经将你的家族职等改为%s!", family[index].fmname,
  2426.         MEMBERKIND_INTDATA[result]);
  2427.         saacproto_ACFMAnnounce_send(family[index].fmmemberindex[charindex].onlineflag,
  2428.         SUCCESSFUL, fmname, fmindex, index, 3, buf,
  2429.         family[index].fmmemberindex[charindex].charfdid);
  2430. }
  2431.         if (family[index].fmmemberindex[0].onlineflag > 0)
  2432.         {
  2433.         // 通知族长
  2434.         sprintf(buf, "n你已经将%s的职等改为%s了!", charname,
  2435.         MEMBERKIND_INTDATA[result]);
  2436.         saacproto_ACFMAnnounce_send(family[index].fmmemberindex[0].onlineflag,
  2437.         SUCCESSFUL, fmname, fmindex, index, 4, buf,
  2438.         family[index].fmmemberindex[0].charfdid);
  2439.     }
  2440.         db_familyupdate[index] = 1;
  2441.         return 0;
  2442.    }
  2443.    log("AssignOcp Failedn");
  2444. #endif
  2445.    return -1;
  2446. }
  2447. // 家族成员 login
  2448. #ifdef _FM_MODIFY
  2449. int ACFMCharLogin(int fd, int index, char *fmname, int fmindex,
  2450. char *charname, char *charid, int charlv, int *floor, int *fmpopular, 
  2451. int *joinflag, int *fmsetupflag, int *charindex, int charfdid,
  2452. int *charfame, int eventflag,int gsnum
  2453. #ifdef _NEW_MANOR_LAW
  2454. ,int *momentum
  2455. #endif
  2456. )
  2457. #else
  2458. #ifdef _PERSONAL_FAME   // Arminius: 家族个人声望
  2459. int ACFMCharLogin(int fd, int index, char *fmname, int fmindex,
  2460. char *charname, char *charid, int charlv, int *floor, int *fmpopular, 
  2461. int *joinflag, int *fmsetupflag, int *charindex, int charfdid,
  2462. int *charfame, int eventflag)
  2463. #else
  2464. int ACFMCharLogin(int fd, int index, char *fmname, int fmindex,
  2465. char *charname, char *charid, int charlv, int *floor, int *fmpopular, 
  2466. int *joinflag, int *fmsetupflag, int *charindex, int charfdid)
  2467. #endif
  2468. #endif
  2469. {
  2470. int i = 0;
  2471. time_t t1;
  2472.    
  2473. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2474.    
  2475. if (family[index].fmpointindex != -1)
  2476. *floor = ACgetFMFloor(fmindex);
  2477. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2478. *fmpopular = family[index].fmtotalfame;
  2479. #else
  2480. *fmpopular = family[index].fmpopular;
  2481. #endif
  2482. *fmsetupflag = family[index].fmsetupflag;
  2483.    
  2484. for (i = 0; i < family[index].fmmemberindexmaxnum; i++){
  2485. if ((strcmp(family[index].fmmemberindex[i].charname, charname) == 0)
  2486. && (strcmp(family[index].fmmemberindex[i].charid, charid) == 0)){
  2487. *charindex = i;
  2488. family[index].fmmemberindex[i].onlineflag = fd;
  2489. family[index].fmmemberindex[i].charfdid = charfdid;
  2490. family[index].fmmemberindex[i].charlv = charlv;
  2491. #ifdef _FM_MODIFY
  2492. family[index].fmmemberindex[i].gsnum = gsnum;
  2493. #endif
  2494. #ifdef _PERSONAL_FAME   // Arminius: 家族个人声望
  2495. *charfame = family[index].fmmemberindex[i].popular;
  2496. #endif
  2497. #ifdef _NEW_MANOR_LAW
  2498. *momentum = family[index].fmmemberindex[i].momentum;
  2499. #endif
  2500. time(&t1);
  2501. family[index].fmmemberindex[i].predeltime = t1 + PREDELMEMBER_TIME;
  2502. #ifdef _FMVER21
  2503. *joinflag = family[index].fmmemberindex[i].charflag;
  2504. family[index].fmmemberindex[i].eventflag = eventflag;
  2505. #else
  2506. if (i == 0)  *joinflag = 1;
  2507. else if ((family[index].fmmemberindex[i].charflag == 1)
  2508. || (family[index].fmmemberindex[i].charflag == 3))
  2509. *joinflag = 2;
  2510. else *joinflag = 0;
  2511. #endif
  2512. db_familyupdate[index] = 1;
  2513.    
  2514. return index;
  2515. }
  2516. }
  2517. return -1;
  2518. }
  2519. // 家族成员离线
  2520. int ACFMCharLogout(int index, char *fmname, int fmindex, char *charname,
  2521.         char *charid, int charlv, int charfdid)
  2522. {
  2523.    int i = 0;
  2524.    time_t t1;
  2525.    if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2526.    
  2527.    for (i = 0; i < family[index].fmmemberindexmaxnum; i++)
  2528.    {
  2529.     if ((strcmp(family[index].fmmemberindex[i].charname, charname) == 0)
  2530.        && (strcmp(family[index].fmmemberindex[i].charid, charid) == 0))
  2531.     {
  2532.        family[index].fmmemberindex[i].onlineflag = 0;
  2533.        family[index].fmmemberindex[i].charfdid = 0;
  2534.        family[index].fmmemberindex[i].charlv = charlv;
  2535. #ifdef _FM_MODIFY
  2536.  family[index].fmmemberindex[i].gsnum = 0;
  2537. #endif
  2538.        time(&t1);
  2539.        family[index].fmmemberindex[i].predeltime = t1 + PREDELMEMBER_TIME;
  2540.    db_familyupdate[index] = 1;
  2541.    return 0;
  2542. }
  2543.    }
  2544.    return -1;
  2545. }
  2546. // 取得家族庄园图层
  2547. int ACgetFMFloor(fmindex)
  2548. {
  2549.    int i = 0;
  2550.    for (i = 0; i < MAX_FMPOINT; i++)
  2551.    {
  2552.       if (fmindex == fmpoint[i].hadfmindex)
  2553.       return fmpoint[i].fmfl;
  2554.    }
  2555.    return -1;
  2556. }
  2557. // 玩家手动删除角色
  2558. int ACgetFMInfoFromChar(char *fmname, int *fmindex,
  2559. char *charname, char *charid, int *charindex)
  2560. {
  2561.    int i = 0, j = 0;
  2562.    for (i = 0; i < MAX_FAMILY; i++)
  2563.    {
  2564.       if (family[i].fmindex <= 0) continue;
  2565.       for (j = 0; j < MAX_MEMBERNUM; j++)
  2566.       {
  2567.          if (family[i].fmmemberindex[j].charflag <= 0) continue;
  2568.          if ((strcmp(family[i].fmmemberindex[j].charname, charname) == 0)
  2569.             && (strcmp(family[i].fmmemberindex[j].charid, charid) == 0))
  2570.          {
  2571.                strcpy(fmname, "");
  2572.                strcpy(fmname, family[i].fmname);
  2573.                *fmindex = family[i].fmindex;
  2574.                *charindex = j;
  2575.                db_familyupdate[i] = 1;
  2576.                return i;
  2577.          }
  2578.       } // for
  2579.    } // for
  2580.    return -1;
  2581. }
  2582. // 阅读家族留言
  2583. int ACFMReadMemo(int index, int *dataindex, char *data)
  2584. {
  2585.    int i = 0;
  2586.    char buf[256];
  2587.    strcpy(data, "");
  2588.    if (index == -1){
  2589. return -1;
  2590.    } else if (index == FMSMEMOINDEX){
  2591.     *dataindex = fmsmemo.fmsnowwritenum;
  2592.     for (i = 0; i < fmsmemo.num; i++){
  2593.    sprintf(buf, "%s|", fmsmemo.memodata[i]);
  2594.        strcat(data, buf);
  2595.     }
  2596.     return fmsmemo.num;
  2597.    }
  2598.    if ((index >= MAX_FAMILY) || (index < 0))
  2599.     return -1;
  2600.    if (CheckFMUse(index) == 0)
  2601.     return -1;
  2602.    *dataindex = family[index].memonowwritenum;
  2603.    for (i = 0; i < family[index].memonum; i++){
  2604.     strcpy(buf, "");
  2605.     sprintf(buf, "%s|", family[index].memolist[i]);
  2606.     strcat(data, buf);
  2607.    }
  2608.    db_familyupdate[index] = 1;
  2609.    return family[index].memonum;
  2610. }
  2611. // 写入家族留言板
  2612. int ACFMWriteMemo(int index, char *fmname, int fmindex, char *data)
  2613. {
  2614.    if (index == -1){
  2615.     return -1;
  2616.    }else if (index == FMSMEMOINDEX){
  2617.     fmsmemo.num++;
  2618.     if (fmsmemo.num > FMSMEMONUM) fmsmemo.num = FMSMEMONUM;
  2619.     strcpy(fmsmemo.memodata[fmsmemo.fmsnowwritenum], data);
  2620.     fmsmemo.fmsnowwritenum++;
  2621.     if (fmsmemo.fmsnowwritenum >= FMSMEMONUM) fmsmemo.fmsnowwritenum = 0;
  2622.     db_fmsmemoupdate = 1;
  2623.     return 0;
  2624.    }
  2625.    if ((index > MAX_FAMILY) || (index < 0))
  2626.     return -1;
  2627.    if (CheckFMUse(index) == 0)
  2628.     return -1;
  2629.    if ((family[index].fmindex != fmindex) || (strcmp(family[index].fmname, fmname) != 0)) {
  2630.     return -1;
  2631.    }
  2632.    if (strlen(data) > FAMILY_MEMOLEN) return -1;
  2633.    family[index].memonum++;
  2634.    if (family[index].memonum > FAMILY_MEMONUM) family[index].memonum = FAMILY_MEMONUM;
  2635.    strcpy(family[index].memolist[family[index].memonowwritenum], data);
  2636.    family[index].memonowwritenum++;
  2637.    if (family[index].memonowwritenum >= FAMILY_MEMONUM) family[index].memonowwritenum = 0;
  2638.    db_familyupdate[index] = 1;
  2639.    return 0;
  2640. }
  2641. // 取得庄园列表
  2642. int ACFMPointList(char *data)
  2643. {
  2644.    int i = 0;
  2645.    char msg[256];
  2646.    strcpy(data, "");
  2647.    for (i = 0; i < MAX_FMPOINT; i++)
  2648.    {
  2649.       sprintf(msg, "%d|%d|%d|%d|%d|%s|%d|%d|%d ",
  2650.          i, fmpoint[i].fl, fmpoint[i].x, fmpoint[i].y,
  2651.          fmpoint[i].hadfmindex, fmpoint[i].hadfmname,
  2652.          fmpoint[i].hadfmpopular, fmpoint[i].hadfmindex - 1,
  2653.          fmpoint[i].village);
  2654.       strcat(data, msg);
  2655.    }
  2656.    return 0;
  2657. }
  2658. // 申请庄园
  2659. int ACSetFMPoint(int index, char *fmname, int fmindex, int fmpointindex,
  2660. int fl, int x, int y)
  2661. {
  2662. int i = 0;
  2663. if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2664. if (family[index].fmpointindex >= 0) return -2;
  2665. if ((fmpoint[fmpointindex].x != x) || (fmpoint[fmpointindex].y != y))return -1;
  2666. if (fmpoint[fmpointindex].hadfmindex > 0)return -4;
  2667. if (family[index].fmjoinnum < MINAPPLYPNUM)return -5;
  2668. fmpoint[fmpointindex].hadfmindex = fmindex;
  2669. family[index].fmpointindex = fmpointindex;
  2670. strcpy(fmpoint[fmpointindex].hadfmname, fmname);
  2671. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2672. fmpoint[fmpointindex].hadfmpopular = family[index].fmtotalfame;
  2673. #else
  2674. fmpoint[fmpointindex].hadfmpopular = family[index].fmpopular;
  2675. #endif
  2676. // 更新线上家族成员状况
  2677. for (i = 0; i < MAX_MEMBERNUM; i++){
  2678. if (strcmp(family[index].fmmemberindex[i].charname, "") == 0) continue;
  2679. if (family[index].fmmemberindex[i].onlineflag > 0){
  2680. int floor =  ACgetFMFloor(fmindex);
  2681. #ifdef _FMVER21
  2682. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2683.       saacproto_ACFMCharLogin_send(
  2684. family[index].fmmemberindex[i].onlineflag,
  2685. SUCCESSFUL, index, floor, family[index].fmtotalfame,
  2686. family[index].fmmemberindex[i].charflag, family[index].fmsetupflag, 1, i,
  2687. family[index].fmmemberindex[i].popular, // Arminuis 9.11
  2688. family[index].fmmemberindex[i].charfdid
  2689. #ifdef _NEW_MANOR_LAW
  2690. ,family[index].fmmemberindex[i].momentum
  2691. #endif
  2692. );
  2693. #else
  2694.       saacproto_ACFMCharLogin_send(
  2695. family[index].fmmemberindex[i].onlineflag,
  2696. SUCCESSFUL, index, floor, family[index].fmpopular,
  2697. family[index].fmmemberindex[i].charflag, family[index].fmsetupflag, 1, i,
  2698. family[index].fmmemberindex[i].charfdid);
  2699. #endif
  2700. #else     
  2701. {
  2702. int joinflag = 0;
  2703. if (i == 0) joinflag = 1;
  2704. else joinflag = 2;
  2705. saacproto_ACFMCharLogin_send(
  2706. family[index].fmmemberindex[i].onlineflag,
  2707. SUCCESSFUL, index, floor, family[index].fmpopular,
  2708. joinflag, family[index].fmsetupflag, 1, i,
  2709. family[index].fmmemberindex[i].charfdid);
  2710. }
  2711. #endif
  2712. }
  2713. }
  2714.   // 更新庄园状况
  2715.   {
  2716. char data[15000];
  2717.     if (ACFMPointList(data) >= 0){
  2718. for (i = 0; i < MAXCONNECTION; i++)
  2719. if (gs[i].use && gs[i].name[0])
  2720. saacproto_ACFMPointList_send(i, SUCCESSFUL, data);
  2721. }
  2722. }
  2723.   db_fmpointupdate = 1;
  2724.   return 0;
  2725. }
  2726. // 设定庄园
  2727. int ACFixFMPoint(int winindex, char *winfmname, int winfmindex, int loseindex,
  2728. char* losefmname, int losefmindex, int village)
  2729. {
  2730. int i = 0;
  2731. if (CheckFM(&winindex, winfmname, winfmindex) < 0) return -1;
  2732. if (CheckFM(&loseindex, losefmname, losefmindex) < 0) return -1;
  2733. #ifdef _NEW_MANOR_LAW
  2734.  // 如果原家族守住了庄园
  2735. if(fmpoint[village -1].hadfmindex == winfmindex){
  2736. unsigned int iTotalGetGold = 0,iOldGold = 0,iTotalMamberMomentum = 0;
  2737. // 获得金钱 = (家族气势 * 10000) - (家族成员个人气势总合 * 5000)
  2738. for(i=0;i<MAX_MEMBERNUM;i++){
  2739. if(strcmp(family[winindex].fmmemberindex[i].charname,"") == 0) continue;
  2740. iTotalMamberMomentum += family[winindex].fmmemberindex[i].momentum;
  2741. }
  2742. iTotalGetGold = (family[winindex].fmmomentum / 100 * 10000) - (iTotalMamberMomentum / 100 * 5000);
  2743. iOldGold = family[winindex].fmgold;
  2744. family[winindex].fmgold += (int)iTotalGetGold;
  2745. // family[winindex].fmgold 小於零可能是溢位
  2746. if(family[winindex].fmgold < 0 || family[winindex].fmgold > FMMAXGOLD) family[winindex].fmgold = FMMAXGOLD;
  2747. log("ACFMGetMoney fmindex:%d fmname:%s fmoldgold:%d getmoney:%d fmnewgold:%dn",
  2748. family[winindex].fmindex,family[winindex].fmname,iOldGold,iTotalGetGold,family[winindex].fmgold);
  2749. }
  2750. #endif
  2751. delfmpointindex(losefmindex);
  2752. family[loseindex].fmpointindex = -1;
  2753. fmpoint[village -1].hadfmindex = winfmindex;
  2754. family[winindex].fmpointindex = village - 1;
  2755. strcpy(fmpoint[village - 1].hadfmname, winfmname);
  2756. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2757. fmpoint[village -1].hadfmpopular = family[winindex].fmtotalfame;
  2758. #else
  2759. fmpoint[village -1].hadfmpopular = family[winindex].fmpopular;
  2760. #endif
  2761. #ifdef _NEW_MANOR_LAW
  2762. // 庄园战後,家族气势全归零
  2763. family[winindex].fmmomentum = 0;
  2764. family[loseindex].fmmomentum = 0;
  2765. #endif
  2766. // 更新线上两个家族成员资料
  2767. for (i = 0; i < MAX_MEMBERNUM; i++){
  2768. if (strcmp(family[winindex].fmmemberindex[i].charname, "") == 0) continue;
  2769. #ifdef _NEW_MANOR_LAW
  2770. // 庄园战後,个人气势全归零
  2771. family[winindex].fmmemberindex[i].momentum = 0;
  2772. #endif
  2773. if (family[winindex].fmmemberindex[i].onlineflag > 0){
  2774. int floor =  ACgetFMFloor(winfmindex);
  2775. #ifdef _FMVER21
  2776. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2777. saacproto_ACFMCharLogin_send(
  2778. family[winindex].fmmemberindex[i].onlineflag,
  2779. SUCCESSFUL, winindex, floor, family[winindex].fmtotalfame,
  2780. family[winindex].fmmemberindex[i].charflag, family[winindex].fmsetupflag, 1, i,
  2781. family[winindex].fmmemberindex[i].popular, // Arminius 9.11
  2782. family[winindex].fmmemberindex[i].charfdid
  2783. #ifdef _NEW_MANOR_LAW
  2784. ,family[winindex].fmmemberindex[i].momentum
  2785. #endif
  2786. );
  2787. #else
  2788. saacproto_ACFMCharLogin_send(
  2789. family[winindex].fmmemberindex[i].onlineflag,
  2790. SUCCESSFUL, winindex, floor, family[winindex].fmpopular,
  2791. family[winindex].fmmemberindex[i].charflag, family[winindex].fmsetupflag, 1, i,
  2792. family[winindex].fmmemberindex[i].charfdid);
  2793. #endif
  2794. #else   
  2795. {
  2796. int joinflag = 0;
  2797. if (i == 0) joinflag = 1;
  2798. else joinflag = 2;
  2799. saacproto_ACFMCharLogin_send(
  2800. family[winindex].fmmemberindex[i].onlineflag,
  2801. SUCCESSFUL, winindex, floor, family[winindex].fmpopular,
  2802. joinflag, family[winindex].fmsetupflag, 1, i,
  2803. family[winindex].fmmemberindex[i].charfdid);
  2804. }
  2805. #endif
  2806. }
  2807. }
  2808. #ifdef _NEW_MANOR_LAW
  2809. if(loseindex >= 0){
  2810. #endif
  2811. for (i = 0; i < MAX_MEMBERNUM; i++){
  2812. if (strcmp(family[loseindex].fmmemberindex[i].charname, "") == 0) continue;
  2813. #ifdef _NEW_MANOR_LAW
  2814. // 庄园战後,个人气势全归零
  2815. family[loseindex].fmmemberindex[i].momentum = 0;
  2816. #endif
  2817. if (family[loseindex].fmmemberindex[i].onlineflag > 0){
  2818. #ifdef _FMVER21
  2819. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  2820. saacproto_ACFMCharLogin_send(
  2821. family[loseindex].fmmemberindex[i].onlineflag,
  2822. SUCCESSFUL, loseindex, -1, family[loseindex].fmtotalfame,
  2823. family[loseindex].fmmemberindex[i].charflag, family[loseindex].fmsetupflag, 1, i,
  2824. family[loseindex].fmmemberindex[i].popular, // Arminius 9.11
  2825. family[loseindex].fmmemberindex[i].charfdid
  2826. #ifdef _NEW_MANOR_LAW
  2827. ,family[loseindex].fmmemberindex[i].momentum
  2828. #endif
  2829. );
  2830. #else
  2831. saacproto_ACFMCharLogin_send(
  2832. family[loseindex].fmmemberindex[i].onlineflag,
  2833. SUCCESSFUL, loseindex, -1, family[loseindex].fmpopular,
  2834. family[loseindex].fmmemberindex[i].charflag, family[loseindex].fmsetupflag, 1, i,
  2835. family[loseindex].fmmemberindex[i].charfdid);
  2836. #endif
  2837. #else     
  2838. {
  2839. int joinflag = 0;
  2840. if (i == 0) joinflag = 1;
  2841. else joinflag = 2;
  2842. saacproto_ACFMCharLogin_send(
  2843. family[loseindex].fmmemberindex[i].onlineflag,
  2844. SUCCESSFUL, loseindex, -1, family[loseindex].fmpopular,
  2845. joinflag, family[loseindex].fmsetupflag, 1, i,
  2846. family[loseindex].fmmemberindex[i].charfdid);
  2847. }
  2848. #endif
  2849. }
  2850. }
  2851. #ifdef _NEW_MANOR_LAW
  2852. }
  2853. #endif
  2854. // 更新庄园状况
  2855. {
  2856. char data[15000];
  2857. if (ACFMPointList(data) >= 0){
  2858. for (i = 0; i < MAXCONNECTION; i++)
  2859. if (gs[i].use && gs[i].name[0])
  2860. saacproto_ACFMPointList_send(i, SUCCESSFUL, data);
  2861. }
  2862. }
  2863. db_fmpointupdate = 1;
  2864. return 0;
  2865. }
  2866. // 族长广播
  2867. int ACFMAnnounce(char *fmname, int fmindex, int index, char *data, int color)
  2868. {
  2869.    if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2870.    return 0;
  2871. }
  2872. // 取得家族资料
  2873. // kindflag 1:家族银行
  2874. int ACGetFMData(int index, char *fmname, int fmindex, int kindflag, int *data)
  2875. {
  2876.    if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  2877.    if (kindflag == 1)
  2878.     *data = family[index].fmgold;
  2879.    return 0;
  2880. }
  2881. void setMemberFileDataToArg(int index, int memberindex, char *data)
  2882. {
  2883.    int i = 0;
  2884.    char value[256];
  2885.    char *ptr;
  2886.    if (index < 0 || index > MAX_FAMILY) return;
  2887.    if (strcmp(data, "") == 0) return;
  2888.    ptr = (char *)strstr(data, "=");
  2889.    if (ptr == NULL) return;
  2890.    strcpy(ptr, "");
  2891.    strcpy(value, ptr + 1);
  2892.    for (i = 0; i < memberdatamaxint; i++){
  2893.       if (strcmp(data, MEMBER_INTDATA[i]) == 0){
  2894.          switch(i){
  2895.             case 0:
  2896.              family[index].fmmemberindex[memberindex].charlv = atoi(value);
  2897.              break;
  2898.             case 1:
  2899.              family[index].fmmemberindex[memberindex].charflag = atoi(value);
  2900.              break;
  2901.             case 2:
  2902.              family[index].fmmemberindex[memberindex].onlineflag = atoi(value);
  2903.              break;
  2904.             case 3:
  2905.              family[index].fmmemberindex[memberindex].charfdid = atoi(value);
  2906.              break;
  2907.             case 4:
  2908.              family[index].fmmemberindex[memberindex].predeltime = atoi(value);
  2909.              break;
  2910.             case 5:
  2911.              family[index].fmmemberindex[memberindex].popular = atoi(value);
  2912.              break;
  2913. #ifdef _FMVER21
  2914. case 6:
  2915.              family[index].fmmemberindex[memberindex].eventflag = atoi(value);
  2916.              break;
  2917. #endif
  2918. #ifdef _NEW_MANOR_LAW
  2919. case 7:
  2920. family[index].fmmemberindex[memberindex].momentum = atoi(value);
  2921. break;
  2922. #endif
  2923.             default:
  2924.              break;
  2925.          }
  2926.          return;
  2927.       }
  2928.    }
  2929.    for (i = 0; i < memberdatamaxchar; i++){
  2930.       if (strcmp(data, MEMBER_CHARDATA[i]) == 0){
  2931.          switch(i){
  2932.             case 0:
  2933.              strcpy(family[index].fmmemberindex[memberindex].charname, value);
  2934.              break;
  2935.             case 1:
  2936.              strcpy(family[index].fmmemberindex[memberindex].charid, value);
  2937.              break;
  2938.             default:
  2939.              break;
  2940.          }
  2941.          return;
  2942.       }
  2943.    }
  2944. }
  2945. void setFamilyFileDataToArg(int index, char *data)
  2946. {
  2947.    int i = 0, j = 0;
  2948.    char value[1024];
  2949.    char *ptr;
  2950.    if (index < 0 || index > MAX_FAMILY) return;
  2951.    if (strcmp(data, "") == 0) return;
  2952.    ptr = (char *)strstr(data, "=");
  2953.    if (ptr == NULL) return;
  2954.    strcpy(ptr, "");
  2955.    strcpy(value, ptr + 1);
  2956.    for (i = 0; i < familymaxint; i++){
  2957.       if (strcmp(data, FAMILY_INTDATA[i]) == 0){
  2958.         switch(i){
  2959.            case 0:
  2960.             family[index].fmindex = atoi(value);
  2961.             break;
  2962.            case 1:
  2963.             family[index].fmleadergrano = atoi(value);
  2964.             break;
  2965.            case 2:
  2966.             family[index].fmnum = atoi(value);
  2967.             break;
  2968.            case 3:
  2969.             family[index].fmjoinnum = atoi(value);
  2970.             break;
  2971.            case 4:
  2972.             family[index].fmacceptflag = atoi(value);
  2973.             break;
  2974.            case 5:
  2975.             family[index].fmsetupflag = atoi(value);
  2976.             break;
  2977.            case 6:
  2978.             family[index].fmsprite = atoi(value);
  2979.             break;
  2980.            case 7:
  2981.             family[index].fmpointindex = atoi(value);
  2982.             break;
  2983.            case 8:
  2984.             family[index].fmpopular = atoi(value);
  2985.             break;
  2986.            case 9:
  2987.             family[index].fmgold = atoi(value);
  2988.             break;
  2989.            case 10:
  2990.             family[index].fmmemberindexmaxnum = atoi(value);
  2991.             break;
  2992.            case 11:
  2993.             family[index].apply_time = atoi(value);
  2994.             break;
  2995.            case 12:
  2996.             family[index].setup_time = atoi(value);
  2997.             break;
  2998.            case 13:
  2999.             family[index].predel_time = atoi(value);
  3000.             break;
  3001.            case 14:
  3002.             family[index].memonowwritenum = atoi(value);
  3003.             break;
  3004.            case 15:
  3005.             family[index].memonum = atoi(value);
  3006.             break;
  3007.            case 16:
  3008.             family[index].fmadv = atoi(value);
  3009.             break;
  3010.            case 17:
  3011.             family[index].fmfeed = atoi(value);
  3012.             break;
  3013.            case 18:
  3014.             family[index].fmsynthesize = atoi(value);
  3015.             break;
  3016.            case 19:
  3017.             family[index].fmdealfood = atoi(value);
  3018.             break;
  3019.            case 20:
  3020.             family[index].fmpk = atoi(value);
  3021.             break;
  3022. #ifdef _NEW_MANOR_LAW
  3023. case 21:
  3024. family[index].fmmomentum = atoi(value);
  3025. break;
  3026. #endif
  3027.            default:
  3028.             break;
  3029.         }
  3030.         return;
  3031.       }
  3032.    }
  3033.    for (i = 0; i < familymaxchar; i++){
  3034.       if (strcmp(data, FAMILY_CHARDATA[i]) == 0){
  3035.         switch(i){
  3036.            case 0:
  3037.             strcpy(family[index].fmname, value);
  3038.             break;
  3039.            case 1:
  3040.             strcpy(family[index].fmleadername, value);
  3041.             break;
  3042.            case 2:
  3043.             strcpy(family[index].fmleaderid, value);
  3044.             break;
  3045.            case 3:
  3046.             strcpy(family[index].petname, value);
  3047.             break;
  3048.            case 4:
  3049.             strcpy(family[index].petattr, value);
  3050.             break;
  3051.            case 5:
  3052.             strcpy(family[index].fmrule, value);
  3053.             break;
  3054.            default:
  3055.             break;
  3056.         }
  3057.         return;
  3058.       }
  3059.    }
  3060.    for (i = 0; i < FAMILY_MEMONUM; i ++){
  3061.       char memolist[256];
  3062.       sprintf(memolist, "%s%d", FMMEMOLIST, i);
  3063.       if (strcmp(data, memolist) == 0){
  3064.         strcpy(family[index].memolist[i], value);
  3065.         return;
  3066.       }
  3067.    }
  3068.    for (i = 0; i < MAX_MEMBERNUM; i ++){
  3069.       char memberdata[256];
  3070.       sprintf(memberdata, "%s%d", FMMEMBERINDEX, i);
  3071.       if (strcmp(data, memberdata) == 0){
  3072.  for (j = 1; j < memberdatamaxint + memberdatamaxchar; j++){
  3073.     char databuf[256];
  3074.     easyGetTokenFromBuf(value, " ", j, databuf, sizeof(databuf));
  3075.     if (strcmp(databuf, "") == 0) continue;
  3076.     setMemberFileDataToArg(index, i, databuf);
  3077.  }
  3078.  return;
  3079.       }
  3080.    }
  3081.    
  3082. }
  3083. // GM修改家族资料
  3084. int ACGMFixFMData(int index, char *fmname, char *charid, char *cmd,
  3085. char *data)
  3086. {
  3087.    int i = 0,charindex = -1;
  3088.  int floor =  ACgetFMFloor(index);
  3089.    if (index < 0 || index > MAX_FAMILY) return -1;
  3090.    log("GMFixFMData index:%d charid:%s cmd:%s data:%sn",
  3091.     index, charid, cmd, data);
  3092.    strcpy(fmname, family[index].fmname);
  3093.    if (charid[0] == '-' && charid[1] == '1')
  3094.    {
  3095.       for (i = 0; i < familymaxint; i++)
  3096.       {
  3097.          if (strcmp(cmd, FAMILY_INTDATA[i]) == 0)
  3098.          {
  3099.             switch(i)
  3100.             {
  3101.                case 2:
  3102.                   family[index].fmnum = atoi(data);
  3103.                   log("fmnum:%sn", data);
  3104.                   break;
  3105.                case 3:
  3106.                   family[index].fmjoinnum = atoi(data);
  3107.                   log("fmjoinnum:%sn", data);
  3108.                   break;
  3109.                case 4:
  3110.                   family[index].fmacceptflag = atoi(data);
  3111.                   log("fmacceptflag:%sn", data);
  3112.                   break;
  3113.                case 5:
  3114.                   family[index].fmsetupflag = atoi(data);
  3115.                   log("fmsetupflag:%sn", data);
  3116.                   break;
  3117.                case 6:
  3118.                   family[index].fmsprite = atoi(data);
  3119.                   log("fmsprite:%sn", data);
  3120.                   break;
  3121.                case 7:
  3122.                   family[index].fmpointindex = atoi(data);
  3123.                   log("fmpointindex:%sn", data);
  3124.                   break;
  3125.                case 8:
  3126.                   family[index].fmpopular = atoi(data);
  3127.                   log("fmpopular:%sn", data);
  3128.                   break;
  3129.                case 9:
  3130.                   family[index].fmgold = atoi(data);
  3131.                   log("fmgold:%sn", data);
  3132.                   break;
  3133.                case 11:
  3134.                   family[index].apply_time = atoi(data);
  3135.                   log("apply_time:%sn", data);
  3136.                   break;
  3137.                case 12:
  3138.                   family[index].setup_time = atoi(data);
  3139.                   log("setup_time:%sn", data);
  3140.                   break;
  3141.                case 13:
  3142.                   family[index].predel_time = atoi(data);
  3143.                   log("predel_time:%sn", data);
  3144.                   break;
  3145.                case 16:
  3146.                   family[index].fmadv = atoi(data);
  3147.                   log("adv:%sn", data);
  3148.                   break;
  3149.                case 17:
  3150.                   family[index].fmfeed = atoi(data);
  3151.                   log("feed:%sn", data);
  3152.                   break;
  3153.                case 18:
  3154.                   family[index].fmsynthesize = atoi(data);
  3155.                   log("synthesize:%sn", data);
  3156.                   break;
  3157.                case 19:
  3158.                   family[index].fmdealfood = atoi(data);
  3159.                   log("dealfood:%sn", data);
  3160.                   break;
  3161.                case 20:
  3162.                   family[index].fmpk = atoi(data);
  3163.                   log("pk:%sn", data);
  3164.                   break;
  3165. #ifdef _NEW_MANOR_LAW
  3166.  case 21:
  3167.  family[index].fmmomentum = atoi(data);
  3168.  log("momentum:%sn", data);
  3169.  for(i=0;i<MAX_MEMBERNUM;i++){
  3170.  if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) &&
  3171.  (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY))
  3172.  // 家族成员个人气势加总
  3173.  family[index].fmmomentum += family[index].fmmemberindex[i].momentum;
  3174.  }
  3175.  // 家族气势 = (家族人数平方) / 10 + 1 + 家族成员个人气势加总
  3176.  family[index].fmmomentum += ((family[index].fmjoinnum * family[index].fmjoinnum) / 10 + 1) * 100;
  3177.  break;
  3178. #endif
  3179.                default:
  3180.                   break;
  3181.             }
  3182.             db_familyupdate[index] = 1;
  3183. // 计算家族声望
  3184. family[index].fmpopular = family[index].fmadv + family[index].fmfeed
  3185. + family[index].fmsynthesize + family[index].fmdealfood
  3186. + family[index].fmpk;
  3187. family[index].fmtotalfame = family[index].fmpopular;
  3188. for(i = 0;i < MAX_MEMBERNUM;i++){
  3189. if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) &&
  3190. (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY))
  3191. family[index].fmtotalfame += family[index].fmmemberindex[i].popular;
  3192. }
  3193. #ifdef _NEW_MANOR_LAW
  3194. sortFamily();
  3195. #endif
  3196. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  3197. saacproto_ACFMCharLogin_send(
  3198. family[index].fmmemberindex[0].onlineflag,
  3199. SUCCESSFUL,index,floor,family[index].fmtotalfame,
  3200. family[index].fmmemberindex[0].charflag,
  3201. family[index].fmsetupflag, 1, 0,
  3202. family[index].fmmemberindex[0].popular,
  3203. family[index].fmmemberindex[0].charfdid
  3204. #ifdef _NEW_MANOR_LAW
  3205. ,family[index].fmmemberindex[0].momentum
  3206. #endif
  3207. );
  3208. #else
  3209. saacproto_ACFMCharLogin_send(
  3210. family[index].fmmemberindex[0].onlineflag,
  3211. SUCCESSFUL, index, floor, family[index].fmpopular,
  3212. family[index].fmmemberindex[0].charflag,
  3213. family[index].fmsetupflag, 1, 0,
  3214. family[index].fmmemberindex[0].charfdid);
  3215. #endif
  3216.             return 0;
  3217.          }
  3218.       }
  3219.       for (i = 0; i < familymaxchar; i++)
  3220.       {
  3221.          if (strcmp(cmd, FAMILY_CHARDATA[i]) == 0)
  3222.          {
  3223.             switch(i)
  3224.             {
  3225.                case 0:
  3226.                   strncpy(family[index].fmname,data,sizeof(family[index].fmname));
  3227.                   log("fmname:%sn", data);
  3228.                   break;
  3229.                case 1:
  3230.                   strncpy(family[index].fmleadername, data,sizeof(family[index].fmleadername));
  3231.                   log("fmleadername:%sn", data);
  3232.                   break;
  3233.                case 2:
  3234.                   strncpy(family[index].fmleaderid, data,sizeof(family[index].fmleaderid));
  3235.                   log("fmleaderid:%sn", data);
  3236.                   break;
  3237.                case 3:
  3238.                   strncpy(family[index].petname, data,sizeof(family[index].petname));
  3239.                   log("petname:%sn", data);
  3240.                   break;
  3241.                case 4:
  3242.                   strncpy(family[index].petattr, data,sizeof(family[index].petattr));
  3243.                   log("petattr:%sn", data);
  3244.                   break;
  3245.                case 5:
  3246.                   strncpy(family[index].fmrule, data,sizeof(family[index].fmrule));
  3247.                   log("fmrule:%sn", data);
  3248.                   break;
  3249.                default:
  3250.                   break;
  3251.             }
  3252.             db_familyupdate[index] = 1; 
  3253.             sortFamily();
  3254. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  3255. saacproto_ACFMCharLogin_send(
  3256. family[index].fmmemberindex[0].onlineflag,
  3257. SUCCESSFUL,index,floor,family[index].fmtotalfame,
  3258. family[index].fmmemberindex[0].charflag,
  3259. family[index].fmsetupflag, 1, 0,
  3260. family[index].fmmemberindex[0].popular,
  3261. family[index].fmmemberindex[0].charfdid
  3262. #ifdef _NEW_MANOR_LAW
  3263. ,family[index].fmmemberindex[0].momentum
  3264. #endif
  3265. );
  3266. #else
  3267. saacproto_ACFMCharLogin_send(
  3268. family[index].fmmemberindex[0].onlineflag,
  3269. SUCCESSFUL, index, floor, family[index].fmpopular,
  3270. family[index].fmmemberindex[0].charflag,
  3271. family[index].fmsetupflag, 1, 0,
  3272. family[index].fmmemberindex[0].charfdid);
  3273. #endif
  3274.             return 0;
  3275.          }
  3276.       }
  3277.    }
  3278.    else{
  3279.  for(i=0;i<MAX_MEMBERNUM;i++){
  3280.  if(strcmp(family[index].fmmemberindex[i].charid,charid) == 0 && family[index].fmmemberindex[i].onlineflag > 0){
  3281.  charindex = i;
  3282.  break;
  3283.  }
  3284.  }
  3285.  // 找不到家族成员
  3286.  if(charindex == -1){
  3287.  log("FMName:%s,id:%sn",fmname,charid);
  3288.  return -1;
  3289.  }
  3290.  for(i = 0; i < memberdatamaxint; i++){
  3291.  if (strcmp(cmd, MEMBER_INTDATA[i]) == 0)
  3292.  {
  3293.  switch(i)
  3294.  {
  3295.  case 0:
  3296.  family[index].fmmemberindex[charindex].charlv = atoi(data);
  3297.  log("charlv:%sn", data);
  3298.  break;
  3299.  case 1:
  3300.  family[index].fmmemberindex[charindex].charflag = atoi(data);
  3301.  log("charflag:%sn", data);
  3302.  break;
  3303.  case 2:
  3304.  family[index].fmmemberindex[charindex].onlineflag = atoi(data);
  3305.  log("onlineflag:%sn", data);
  3306.  break;
  3307.  case 3:
  3308.  family[index].fmmemberindex[charindex].charfdid = atoi(data);
  3309.  log("charfdid:%sn", data);
  3310.  break;
  3311.  case 4:
  3312.  family[index].fmmemberindex[charindex].predeltime = atoi(data);
  3313.  log("predeltime:%sn", data);
  3314.  break;
  3315.  case 5:
  3316.  family[index].fmmemberindex[charindex].popular = atoi(data);
  3317.  log("popular:%sn", data);
  3318.  // 计算家族声望
  3319.  family[index].fmpopular = family[index].fmadv + family[index].fmfeed
  3320.  + family[index].fmsynthesize + family[index].fmdealfood
  3321.  + family[index].fmpk;
  3322.  family[index].fmtotalfame = family[index].fmpopular;
  3323.  for(i = 0;i < MAX_MEMBERNUM;i++){
  3324.  if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) &&
  3325.  (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY))
  3326.  family[index].fmtotalfame += family[index].fmmemberindex[i].popular;
  3327.  }
  3328.  break;
  3329.  case 6:
  3330.  family[index].fmmemberindex[charindex].eventflag = atoi(data);
  3331.  log("eventflag:%sn", data);
  3332.  break;
  3333. #ifdef _NEW_MANOR_LAW
  3334.  case 7:
  3335.  family[index].fmmemberindex[charindex].momentum = atoi(data);
  3336.  log("momentum:%sn", data);
  3337.  for(i=0;i<MAX_MEMBERNUM;i++){
  3338.  if((family[index].fmmemberindex[i].charflag != FMMEMBER_NONE) &&
  3339.  (family[index].fmmemberindex[i].charflag != FMMEMBER_APPLY))
  3340.  // 家族成员个人气势加总
  3341.  family[index].fmmomentum += family[index].fmmemberindex[i].momentum;
  3342.  }
  3343.  // 家族气势 = (家族人数平方) / 10 + 1 + 家族成员个人气势加总
  3344.  family[index].fmmomentum += ((family[index].fmjoinnum * family[index].fmjoinnum) / 10 + 1) * 100;
  3345.  break;
  3346. #endif
  3347.  default:
  3348.  break;
  3349.  }
  3350.  db_familyupdate[index] = 1; 
  3351. #ifdef _NEW_MANOR_LAW
  3352.  sortFamily();
  3353. #endif
  3354. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  3355.  saacproto_ACFMCharLogin_send(
  3356.  family[index].fmmemberindex[charindex].onlineflag,
  3357.  SUCCESSFUL,index,floor,family[index].fmtotalfame,
  3358.  family[index].fmmemberindex[charindex].charflag,
  3359.  family[index].fmsetupflag, 1, 0,
  3360.  family[index].fmmemberindex[charindex].popular,
  3361.  family[index].fmmemberindex[charindex].charfdid
  3362. #ifdef _NEW_MANOR_LAW
  3363.  ,family[index].fmmemberindex[charindex].momentum
  3364. #endif
  3365.  );
  3366. #else
  3367.  saacproto_ACFMCharLogin_send(
  3368.  family[index].fmmemberindex[charindex].onlineflag,
  3369.  SUCCESSFUL, index, floor, family[index].fmpopular,
  3370.  family[index].fmmemberindex[charindex].charflag,
  3371.  family[index].fmsetupflag, 1, 0,
  3372.  family[index].fmmemberindex[charindex].charfdid);
  3373. #endif
  3374.  return 0;
  3375.  }
  3376.  }
  3377.  for (i = 0; i < memberdatamaxchar; i++)
  3378.  {
  3379.  if (strcmp(cmd, MEMBER_CHARDATA[i]) == 0)
  3380.  {
  3381.  switch(i)
  3382.  {
  3383.  case 0:
  3384.  strncpy(family[index].fmmemberindex[charindex].charname, data,sizeof(family[index].fmmemberindex[charindex].charname));
  3385.  log("charname:%sn", data);
  3386.  break;
  3387.  case 1:
  3388.  strncpy(family[index].fmmemberindex[charindex].charid, data,sizeof(family[index].fmmemberindex[charindex].charid));
  3389.  log("charid:%sn", data);
  3390.  break;
  3391.  default:
  3392.  break;
  3393.  }
  3394.  db_familyupdate[index] = 1; 
  3395.  sortFamily();
  3396. #ifdef _PERSONAL_FAME // Arminius: 家族个人声望
  3397.  saacproto_ACFMCharLogin_send(
  3398.  family[index].fmmemberindex[charindex].onlineflag,
  3399.  SUCCESSFUL,index,floor,family[index].fmtotalfame,
  3400.  family[index].fmmemberindex[charindex].charflag,
  3401.  family[index].fmsetupflag, 1, 0,
  3402.  family[index].fmmemberindex[charindex].popular,
  3403.  family[index].fmmemberindex[charindex].charfdid
  3404. #ifdef _NEW_MANOR_LAW
  3405.  ,family[index].fmmemberindex[charindex].momentum
  3406. #endif
  3407.  );
  3408. #else
  3409.  saacproto_ACFMCharLogin_send(
  3410.  family[index].fmmemberindex[charindex].onlineflag,
  3411.  SUCCESSFUL, index, floor, family[index].fmpopular,
  3412.  family[index].fmmemberindex[charindex].charflag,
  3413.  family[index].fmsetupflag, 1, 0,
  3414.  family[index].fmmemberindex[charindex].charfdid);
  3415. #endif
  3416.  return 0;
  3417.  }
  3418.  }
  3419.    }
  3420.    return -1;
  3421. }
  3422. int ChangeFMLeader(int index, char *fmname, int fmindex)
  3423. {
  3424.    int i = 0;
  3425.    int tmpindex = 0;
  3426.    char buf[256];
  3427.    if (CheckFM(&index, fmname, fmindex) < 0) return -1;
  3428.    for (i = 0; i < MAX_MEMBERNUM; i++)
  3429.    {
  3430.     if (family[index].fmmemberindex[i].charflag == FMMEMBER_ELDER)
  3431.     {
  3432.        if ((strcmp(family[index].fmmemberindex[i].charname, "") == 0)
  3433.           || (strcmp(family[index].fmmemberindex[i].charid, "") == 0))
  3434.              continue;
  3435.        if (tmpindex == 0) tmpindex = i;
  3436.        else
  3437.        {
  3438.         if (family[index].fmmemberindex[i].popular > 
  3439.         family[index].fmmemberindex[tmpindex].popular)
  3440.         tmpindex = i;
  3441.        }
  3442.     }
  3443.    }
  3444.    log("ChangeFMLeader_1 tmpindex:%dn", tmpindex);
  3445.    if (tmpindex == 0) return -1;   // shan return 0 -> -1
  3446.    sprintf(buf, "%d", family[index].fmleadergrano);
  3447.    if (ACFixFMData(index, fmname, fmindex, 11, tmpindex, buf, 
  3448.    family[index].fmmemberindex[tmpindex].charname) < 0)
  3449.     return -1;
  3450.    log("ChangeFMLeader_2 tmpindex:%dn", tmpindex);
  3451.    if (family[index].fmmemberindex[tmpindex].onlineflag > 0)
  3452.    {
  3453.       char tmpbuf[256];
  3454.       sprintf(tmpbuf, "您已经退出家族了~n族长职位已让给%s,辛苦你了!",
  3455.         family[index].fmmemberindex[0].charname);
  3456.       saacproto_ACFMAnnounce_send(
  3457.         family[index].fmmemberindex[tmpindex].onlineflag,
  3458.         SUCCESSFUL, fmname, fmindex, index, 4, tmpbuf,
  3459.         family[index].fmmemberindex[tmpindex].charfdid);
  3460.    }
  3461.    ACMemberLeaveFM(index, fmname, fmindex,
  3462.     family[index].fmmemberindex[tmpindex].charname, 0, tmpindex, 0);
  3463.    return 0;
  3464. }
  3465. #ifdef _LEADERFUNCHECK
  3466. int CheckLeaderQ(int index, char *fmname, int fmindex, char *charname, char *charid)
  3467. {
  3468. int result = -1;
  3469.    if(CheckFM(&index, fmname, fmindex) < 0) return -1;
  3470.    if ((strcmp(family[index].fmmemberindex[0].charname, charname) == 0)
  3471.       && (strcmp(family[index].fmmemberindex[0].charid, charid) == 0))
  3472. result = 0;
  3473. return result;
  3474. }
  3475. #endif
  3476. #ifdef _ACFMPK_LIST
  3477. FamilyPKSchedule FMPK_List[FMPKLIST_MAXNUM];
  3478. void FMPK_InitList( void)
  3479. {
  3480. int i;
  3481. for( i=0; i<FMPKLIST_MAXNUM; i++){
  3482. FMPK_List[i].pkflg = 0;
  3483. memset( FMPK_List[i].Data, 0, sizeof(FMPK_List[i].Data) );
  3484. }
  3485. }
  3486. void FMPK_LoadList()
  3487. {
  3488. char buf[256];
  3489. int i;
  3490. char *filename="data/family/fm_pk_list.txt";
  3491. FILE *fp;
  3492. FMPK_InitList();
  3493. if( !(fp=fopen(filename, "r")))return;
  3494. for( i=0; i<FMPKLIST_MAXNUM; i++){
  3495. if( fscanf( fp, "%s", buf) == EOF ) break;
  3496. buf[strlen(buf)+1] = 0;
  3497. memcpy( FMPK_List[i].Data, buf, strlen(buf)+1);
  3498. log("庄园PK列表[%d]:%d,%sn", i, FMPK_List[i].pkflg, FMPK_List[i].Data);
  3499. }
  3500. fclose( fp);
  3501. }
  3502. void FMPK_BackUpList()
  3503. {
  3504. int i;
  3505. char *filename="data/family/fm_pk_list.txt";
  3506. FILE *fp;
  3507. if( !(fp=fopen(filename, "w"))  )return;
  3508. for( i=0; i<FMPKLIST_MAXNUM; i++){
  3509. fprintf(fp, "%sn", FMPK_List[i].Data);
  3510. printf("n%s",FMPK_List[i].Data);
  3511. }
  3512. fclose( fp);
  3513. }
  3514. int FMPK_GetTypeFlg( int ti)
  3515. {
  3516. if( ti <0 || ti >= FMPKLIST_MAXNUM ) return -1;
  3517. return FMPK_List[ti].pkflg;
  3518. }
  3519. char *FMPK_GetData( int ti)
  3520. {
  3521. if( ti <0 || ti >= FMPKLIST_MAXNUM ) return NULL;
  3522. return FMPK_List[ti].Data;
  3523. }
  3524. int FMPK_SetData( int ti, int Pkflg, char *Data, int sizes)
  3525. {
  3526. if( ti <0 || ti >= FMPKLIST_MAXNUM ) return 0;
  3527. memcpy( FMPK_List[ti].Data, Data, sizes+1);
  3528. FMPK_List[ti].pkflg = Pkflg;
  3529. return 1;
  3530. }
  3531. #endif
  3532. int readOneFamilyFromTi( int ti)
  3533. {
  3534. char filename[256];
  3535. struct stat s;
  3536. snprintf(filename, sizeof(filename), "%s/Family.%d", familydir, ti);
  3537. if (stat(filename, &s) < 0)return 0;
  3538. if (!(s.st_mode & S_IFREG)){
  3539. log("%s is not a regular filen", filename);
  3540. return 0;
  3541. }
  3542. if( readOneFamily( filename, ti) != 1 ){
  3543. log("cannot open file %s %sn", filename, strerror(errno));
  3544. return 0;
  3545. }
  3546. /*
  3547. if( readOneFamily( filename, ti) != 1 ){
  3548. log("read:%s Error !! n", filename);
  3549. }else{
  3550. log("read:%s OK !! n", filename);
  3551. }
  3552. */
  3553. return 1;
  3554. }
  3555. //andy_add 2003/06/16
  3556. int readOneFamily( char *filename, int i)
  3557. {
  3558. char line[40000], data[40000];
  3559. FILE *fp=NULL;
  3560. int j;
  3561. int m = 0, fmnum1 = 0, fmnum2 = 0;
  3562. if( (fp = fopen(filename, "r") ) == NULL ) return 0;
  3563. if (fgets(line, sizeof(line), fp) == NULL) return 0;
  3564. fclose( fp);
  3565. chop(line);
  3566. for (j = 1; j <= familymaxint + familymaxchar + MAX_MEMBERNUM + FAMILY_MEMONUM; j ++){
  3567. easyGetTokenFromBuf(line, "|", j, data, sizeof(data));
  3568. if (strcmp(data, "") == 0) continue;
  3569. setFamilyFileDataToArg( i, data);
  3570. }
  3571. if (family[i].fmgold > FMMAXGOLD) family[i].fmgold = FMMAXGOLD;
  3572. if (family[i].fmgold < 0) family[i].fmgold = 0;
  3573. for (m = 0; m < MAX_MEMBERNUM; m++){
  3574. if (family[i].fmmemberindex[m].charflag <= 0) continue;
  3575. if (family[i].fmmemberindex[m].charflag != FMMEMBER_APPLY)
  3576. fmnum1 = fmnum1 + 1;
  3577. if (family[i].fmmemberindex[m].charflag > 0 )
  3578. fmnum2 = fmnum2 + 1;
  3579. }
  3580. family[i].fmjoinnum = fmnum1;
  3581. family[i].fmnum = fmnum2;
  3582. if (family[i].fmjoinnum >= MIN_MEMBERNUM){
  3583. family[i].fmsetupflag = 1;
  3584. family[i].predel_time = -1;
  3585. db_familyupdate[i] = 1;
  3586. }else if (family[i].fmjoinnum < MIN_MEMBERNUM){
  3587. family[i].fmsetupflag = 0;
  3588. if (family[i].predel_time == -1) {
  3589. time_t t1;
  3590. time(&t1);
  3591. family[i].predel_time = t1 + PREDEL_TIME;
  3592. db_familyupdate[i] = 1;
  3593. }
  3594. }
  3595. return 1;
  3596. }