int_guild.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. // $Id: int_guild.c,v 1.2 2004/09/25 19:36:53 Akitasha Exp $
  2. #include "inter.h"
  3. #include "int_guild.h"
  4. #include "int_storage.h"
  5. #include "mmo.h"
  6. #include "char.h"
  7. #include "socket.h"
  8. #include "db.h"
  9. #include "lock.h"
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. char guild_txt[1024] = "save/guild.txt";
  14. char castle_txt[1024] = "save/castle.txt";
  15. static struct dbt *guild_db;
  16. static struct dbt *castle_db;
  17. static int guild_newid = 10000;
  18. static int guild_exp[100];
  19. int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes);
  20. int mapif_guild_broken(int guild_id, int flag);
  21. int guild_check_empty(struct guild *g);
  22. int guild_calcinfo(struct guild *g);
  23. int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len);
  24. int mapif_guild_info(int fd, struct guild *g);
  25. int guild_break_sub(void *key, void *data, va_list ap);
  26. // ギルドデータの文字列への変換
  27. int inter_guild_tostr(char *str, struct guild *g) {
  28. int i, c, len;
  29. // 基本データ
  30. len = sprintf(str, "%d\t%s\t%s\t%d,%d,%d,%d,%d\t%s#\t%s#\t",
  31. g->guild_id, g->name, g->master,
  32. g->guild_lv, g->max_member, g->exp, g->skill_point, g->castle_id,
  33. g->mes1, g->mes2);
  34. // メンバー
  35. for(i = 0; i < g->max_member; i++) {
  36. struct guild_member *m = &g->member[i];
  37. len += sprintf(str + len, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\t%s\t",
  38. m->account_id, m->char_id,
  39. m->hair, m->hair_color, m->gender,
  40. m->class_, m->lv, m->exp, m->exp_payper, m->position,
  41. ((m->account_id > 0) ? m->name : "-"));
  42. }
  43. // 役職
  44. for(i = 0; i < MAX_GUILDPOSITION; i++) {
  45. struct guild_position *p = &g->position[i];
  46. len += sprintf(str + len, "%d,%d\t%s#\t", p->mode, p->exp_mode, p->name);
  47. }
  48. // エンブレム
  49. len += sprintf(str + len, "%d,%d,", g->emblem_len, g->emblem_id);
  50. for(i = 0; i < g->emblem_len; i++) {
  51. len += sprintf(str + len, "%02x", (unsigned char)(g->emblem_data[i]));
  52. }
  53. len += sprintf(str + len, "$\t");
  54. // 同盟リスト
  55. c = 0;
  56. for(i = 0; i < MAX_GUILDALLIANCE; i++)
  57. if (g->alliance[i].guild_id > 0)
  58. c++;
  59. len += sprintf(str + len, "%d\t", c);
  60. for(i = 0; i < MAX_GUILDALLIANCE; i++) {
  61. struct guild_alliance *a = &g->alliance[i];
  62. if (a->guild_id > 0)
  63. len += sprintf(str + len, "%d,%d\t%s\t", a->guild_id, a->opposition, a->name);
  64. }
  65. // 追放リスト
  66. c = 0;
  67. for(i = 0; i < MAX_GUILDEXPLUSION; i++)
  68. if (g->explusion[i].account_id > 0)
  69. c++;
  70. len += sprintf(str + len, "%d\t", c);
  71. for(i = 0; i < MAX_GUILDEXPLUSION; i++) {
  72. struct guild_explusion *e = &g->explusion[i];
  73. if (e->account_id > 0)
  74. len += sprintf(str + len, "%d,%d,%d,%d\t%s\t%s\t%s#\t",
  75. e->account_id, e->rsv1, e->rsv2, e->rsv3,
  76. e->name, e->acc, e->mes );
  77. }
  78. // ギルドスキル
  79. for(i = 0; i < MAX_GUILDSKILL; i++) {
  80. len += sprintf(str + len, "%d,%d ", g->skill[i].id, g->skill[i].lv);
  81. }
  82. len += sprintf(str + len, "\t");
  83. return 0;
  84. }
  85. // ギルドデータの文字列からの変換
  86. int inter_guild_fromstr(char *str, struct guild *g) {
  87. int i, j, c;
  88. int tmp_int[16];
  89. char tmp_str[4][256];
  90. char tmp_str2[4096];
  91. char *pstr;
  92. // 基本データ
  93. memset(g, 0, sizeof(struct guild));
  94. if (sscanf(str, "%d\t%[^\t]\t%[^\t]\t%d,%d,%d,%d,%d\t%[^\t]\t%[^\t]\t", &tmp_int[0],
  95. tmp_str[0], tmp_str[1],
  96. &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5],
  97. tmp_str[2], tmp_str[3]) < 8)
  98. return 1;
  99. g->guild_id = tmp_int[0];
  100. g->guild_lv = tmp_int[1];
  101. g->max_member = tmp_int[2];
  102. g->exp = tmp_int[3];
  103. g->skill_point = tmp_int[4];
  104. g->castle_id = tmp_int[5];
  105. memcpy(g->name, tmp_str[0], 24);
  106. memcpy(g->master, tmp_str[1], 24);
  107. memcpy(g->mes1, tmp_str[2], 60);
  108. memcpy(g->mes2, tmp_str[3], 120);
  109. g->mes1[strlen(g->mes1)-1] = 0;
  110. g->mes2[strlen(g->mes2)-1] = 0;
  111. for(j = 0; j < 6 && str != NULL; j++) // 位置スキップ
  112. str = strchr(str + 1, '\t');
  113. // printf("GuildBaseInfo OK\n");
  114. // メンバー
  115. for(i = 0; i < g->max_member; i++) {
  116. struct guild_member *m = &g->member[i];
  117. if (sscanf(str + 1, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\t%[^\t]\t",
  118. &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4],
  119. &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9],
  120. tmp_str[0]) < 11)
  121. return 1;
  122. m->account_id = tmp_int[0];
  123. m->char_id = tmp_int[1];
  124. m->hair = tmp_int[2];
  125. m->hair_color = tmp_int[3];
  126. m->gender = tmp_int[4];
  127. m->class_ = tmp_int[5];
  128. m->lv = tmp_int[6];
  129. m->exp = tmp_int[7];
  130. m->exp_payper = tmp_int[8];
  131. m->position = tmp_int[9];
  132. memcpy(m->name, tmp_str[0], 24);
  133. for(j = 0; j < 2 && str != NULL; j++) // 位置スキップ
  134. str = strchr(str + 1, '\t');
  135. }
  136. // printf("GuildMemberInfo OK\n");
  137. // 役職
  138. i = 0;
  139. while (sscanf(str+1, "%d,%d%n", &tmp_int[0], &tmp_int[1], &j) == 2 && str[1+j] == '\t') {
  140. struct guild_position *p = &g->position[i];
  141. if (sscanf(str+1, "%d,%d\t%[^\t]\t", &tmp_int[0], &tmp_int[1], tmp_str[0]) < 3)
  142. return 1;
  143. p->mode = tmp_int[0];
  144. p->exp_mode = tmp_int[1];
  145. tmp_str[0][strlen(tmp_str[0])-1] = 0;
  146. memcpy(p->name, tmp_str[0], 24);
  147. for(j = 0; j < 2 && str != NULL; j++) // 位置スキップ
  148. str = strchr(str+1, '\t');
  149. i++;
  150. }
  151. // printf("GuildPositionInfo OK\n");
  152. // エンブレム
  153. tmp_int[1] = 0;
  154. if (sscanf(str + 1, "%d,%d,%[^\t]\t", &tmp_int[0], &tmp_int[1], tmp_str2)< 3 &&
  155. sscanf(str + 1, "%d,%[^\t]\t", &tmp_int[0], tmp_str2) < 2)
  156. return 1;
  157. g->emblem_len = tmp_int[0];
  158. g->emblem_id = tmp_int[1];
  159. for(i = 0, pstr = tmp_str2; i < g->emblem_len; i++, pstr += 2) {
  160. int c1 = pstr[0], c2 = pstr[1], x1 = 0, x2 = 0;
  161. if (c1 >= '0' && c1 <= '9') x1 = c1 - '0';
  162. if (c1 >= 'a' && c1 <= 'f') x1 = c1 - 'a' + 10;
  163. if (c1 >= 'A' && c1 <= 'F') x1 = c1 - 'A' + 10;
  164. if (c2 >= '0' && c2 <= '9') x2 = c2 - '0';
  165. if (c2 >= 'a' && c2 <= 'f') x2 = c2 - 'a' + 10;
  166. if (c2 >= 'A' && c2 <= 'F') x2 = c2 - 'A' + 10;
  167. g->emblem_data[i] = (x1<<4) | x2;
  168. }
  169. // printf("GuildEmblemInfo OK\n");
  170. str=strchr(str + 1, '\t'); // 位置スキップ
  171. // 同盟リスト
  172. if (sscanf(str + 1, "%d\t", &c) < 1)
  173. return 1;
  174. str = strchr(str + 1, '\t'); // 位置スキップ
  175. for(i = 0; i < c; i++) {
  176. struct guild_alliance *a = &g->alliance[i];
  177. if (sscanf(str + 1, "%d,%d\t%[^\t]\t", &tmp_int[0], &tmp_int[1], tmp_str[0]) < 3)
  178. return 1;
  179. a->guild_id = tmp_int[0];
  180. a->opposition = tmp_int[1];
  181. memcpy(a->name, tmp_str[0], 24);
  182. for(j = 0; j < 2 && str != NULL; j++) // 位置スキップ
  183. str = strchr(str + 1, '\t');
  184. }
  185. // printf("GuildAllianceInfo OK\n");
  186. // 追放リスト
  187. if (sscanf(str+1, "%d\t", &c) < 1)
  188. return 1;
  189. str = strchr(str + 1, '\t'); // 位置スキップ
  190. for(i = 0; i < c; i++) {
  191. struct guild_explusion *e = &g->explusion[i];
  192. if (sscanf(str + 1, "%d,%d,%d,%d\t%[^\t]\t%[^\t]\t%[^\t]\t",
  193. &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3],
  194. tmp_str[0], tmp_str[1], tmp_str[2]) < 6)
  195. return 1;
  196. e->account_id = tmp_int[0];
  197. e->rsv1 = tmp_int[1];
  198. e->rsv2 = tmp_int[2];
  199. e->rsv3 = tmp_int[3];
  200. memcpy(e->name, tmp_str[0], 24);
  201. memcpy(e->acc, tmp_str[1], 24);
  202. tmp_str[2][strlen(tmp_str[2])-1] = 0;
  203. memcpy(e->mes, tmp_str[2], 40);
  204. for(j = 0; j < 4 && str != NULL; j++) // 位置スキップ
  205. str = strchr(str + 1, '\t');
  206. }
  207. // printf("GuildExplusionInfo OK\n");
  208. // ギルドスキル
  209. for(i = 0; i < MAX_GUILDSKILL; i++) {
  210. if (sscanf(str+1,"%d,%d ", &tmp_int[0], &tmp_int[1]) < 2)
  211. break;
  212. g->skill[i].id = tmp_int[0];
  213. g->skill[i].lv = tmp_int[1];
  214. str = strchr(str + 1, ' ');
  215. }
  216. str = strchr(str + 1, '\t');
  217. // printf("GuildSkillInfo OK\n");
  218. return 0;
  219. }
  220. // ギルド城データの文字列への変換
  221. int inter_guildcastle_tostr(char *str, struct guild_castle *gc) {
  222. int len;
  223. len = sprintf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", // added Guardian HP [Valaris]
  224. gc->castle_id, gc->guild_id, gc->economy, gc->defense, gc->triggerE,
  225. gc->triggerD, gc->nextTime, gc->payTime, gc->createTime, gc->visibleC,
  226. gc->visibleG0, gc->visibleG1, gc->visibleG2, gc->visibleG3, gc->visibleG4,
  227. gc->visibleG5, gc->visibleG6, gc->visibleG7, gc->Ghp0, gc->Ghp1, gc->Ghp2,
  228. gc->Ghp3, gc->Ghp4, gc->Ghp5, gc->Ghp6, gc->Ghp7);
  229. return 0;
  230. }
  231. // ギルド城データの文字列からの変換
  232. int inter_guildcastle_fromstr(char *str, struct guild_castle *gc) {
  233. int tmp_int[26];
  234. memset(gc, 0, sizeof(struct guild_castle));
  235. // new structure of guild castle
  236. if (sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
  237. &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6],
  238. &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13],
  239. &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17], &tmp_int[18], &tmp_int[19], &tmp_int[20],
  240. &tmp_int[21], &tmp_int[22], &tmp_int[23], &tmp_int[24], &tmp_int[25]) == 26) {
  241. gc->castle_id = tmp_int[0];
  242. gc->guild_id = tmp_int[1];
  243. gc->economy = tmp_int[2];
  244. gc->defense = tmp_int[3];
  245. gc->triggerE = tmp_int[4];
  246. gc->triggerD = tmp_int[5];
  247. gc->nextTime = tmp_int[6];
  248. gc->payTime = tmp_int[7];
  249. gc->createTime = tmp_int[8];
  250. gc->visibleC = tmp_int[9];
  251. gc->visibleG0 = tmp_int[10];
  252. gc->visibleG1 = tmp_int[11];
  253. gc->visibleG2 = tmp_int[12];
  254. gc->visibleG3 = tmp_int[13];
  255. gc->visibleG4 = tmp_int[14];
  256. gc->visibleG5 = tmp_int[15];
  257. gc->visibleG6 = tmp_int[16];
  258. gc->visibleG7 = tmp_int[17];
  259. gc->Ghp0 = tmp_int[18];
  260. gc->Ghp1 = tmp_int[19];
  261. gc->Ghp2 = tmp_int[20];
  262. gc->Ghp3 = tmp_int[21];
  263. gc->Ghp4 = tmp_int[22];
  264. gc->Ghp5 = tmp_int[23];
  265. gc->Ghp6 = tmp_int[24];
  266. gc->Ghp7 = tmp_int[25]; // end additions [Valaris]
  267. // old structure of guild castle
  268. } else if (sscanf(str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
  269. &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6],
  270. &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &tmp_int[12], &tmp_int[13],
  271. &tmp_int[14], &tmp_int[15], &tmp_int[16], &tmp_int[17]) == 18) {
  272. gc->castle_id = tmp_int[0];
  273. gc->guild_id = tmp_int[1];
  274. gc->economy = tmp_int[2];
  275. gc->defense = tmp_int[3];
  276. gc->triggerE = tmp_int[4];
  277. gc->triggerD = tmp_int[5];
  278. gc->nextTime = tmp_int[6];
  279. gc->payTime = tmp_int[7];
  280. gc->createTime = tmp_int[8];
  281. gc->visibleC = tmp_int[9];
  282. gc->visibleG0 = tmp_int[10];
  283. gc->visibleG1 = tmp_int[11];
  284. gc->visibleG2 = tmp_int[12];
  285. gc->visibleG3 = tmp_int[13];
  286. gc->visibleG4 = tmp_int[14];
  287. gc->visibleG5 = tmp_int[15];
  288. gc->visibleG6 = tmp_int[16];
  289. gc->visibleG7 = tmp_int[17];
  290. if (gc->visibleG0 == 1)
  291. gc->Ghp0 = 15670 + 2000 * gc->defense;
  292. else
  293. gc->Ghp0 = 0;
  294. if (gc->visibleG1 == 1)
  295. gc->Ghp1 = 15670 + 2000 * gc->defense;
  296. else
  297. gc->Ghp1 = 0;
  298. if (gc->visibleG2 == 1)
  299. gc->Ghp2 = 15670 + 2000 * gc->defense;
  300. else
  301. gc->Ghp2 = 0;
  302. if (gc->visibleG3 == 1)
  303. gc->Ghp3 = 30214 + 2000 * gc->defense;
  304. else
  305. gc->Ghp3 = 0;
  306. if (gc->visibleG4 == 1)
  307. gc->Ghp4 = 30214 + 2000 * gc->defense;
  308. else
  309. gc->Ghp4 = 0;
  310. if (gc->visibleG5 == 1)
  311. gc->Ghp5 = 28634 + 2000 * gc->defense;
  312. else
  313. gc->Ghp5 = 0;
  314. if (gc->visibleG6 == 1)
  315. gc->Ghp6 = 28634 + 2000 * gc->defense;
  316. else
  317. gc->Ghp6 = 0;
  318. if (gc->visibleG7 == 1)
  319. gc->Ghp7 = 28634 + 2000 * gc->defense;
  320. else
  321. gc->Ghp7 = 0;
  322. } else {
  323. return 1;
  324. }
  325. return 0;
  326. }
  327. // ギルド関連データベース読み込み
  328. int inter_guild_readdb() {
  329. int i;
  330. FILE *fp;
  331. char line[1024];
  332. char path[1024];
  333. sprintf(path, "%s%s", db_path, "/exp_guild.txt");
  334. fp = fopen(path, "r");
  335. if (fp == NULL) {
  336. printf("can't read db/exp_guild.txt\n");
  337. return 1;
  338. }
  339. i = 0;
  340. while(fgets(line, sizeof(line)-1, fp) && i < 100){
  341. if (line[0] == '/' && line[1] == '/')
  342. continue;
  343. guild_exp[i] = atoi(line);
  344. i++;
  345. }
  346. fclose(fp);
  347. return 0;
  348. }
  349. // ギルドデータの読み込み
  350. int inter_guild_init() {
  351. char line[16384];
  352. struct guild *g;
  353. struct guild_castle *gc;
  354. FILE *fp;
  355. int i, j, c = 0;
  356. inter_guild_readdb();
  357. guild_db = numdb_init();
  358. castle_db = numdb_init();
  359. if ((fp = fopen(guild_txt,"r")) == NULL)
  360. return 1;
  361. while(fgets(line, sizeof(line)-1, fp)) {
  362. j = 0;
  363. if (sscanf(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0 && guild_newid <= i) {
  364. guild_newid = i;
  365. continue;
  366. }
  367. g = aCalloc(sizeof(struct guild), 1);
  368. if(g == NULL){
  369. printf("int_guild: out of memory!\n");
  370. exit(0);
  371. }
  372. memset(g, 0, sizeof(struct guild));
  373. if (inter_guild_fromstr(line, g) == 0 && g->guild_id > 0) {
  374. if (g->guild_id >= guild_newid)
  375. guild_newid = g->guild_id + 1;
  376. numdb_insert(guild_db, g->guild_id, g);
  377. guild_check_empty(g);
  378. guild_calcinfo(g);
  379. } else {
  380. printf("int_guild: broken data [%s] line %d\n", guild_txt, c);
  381. aFree(g);
  382. }
  383. c++;
  384. }
  385. fclose(fp);
  386. // printf("int_guild: %s read done (%d guilds)\n", guild_txt, c);
  387. c = 0;//カウンタ初期化
  388. if ((fp = fopen(castle_txt, "r")) == NULL) {
  389. return 1;
  390. }
  391. while(fgets(line, sizeof(line)-1, fp)) {
  392. gc = aCalloc(sizeof(struct guild_castle), 1);
  393. if(gc == NULL){
  394. printf("int_guild: out of memory!\n");
  395. exit(0);
  396. }
  397. memset(gc, 0, sizeof(struct guild_castle));
  398. if (inter_guildcastle_fromstr(line, gc) == 0) {
  399. numdb_insert(castle_db, gc->castle_id, gc);
  400. } else {
  401. printf("int_guild: broken data [%s] line %d\n", castle_txt, c);
  402. aFree(gc);
  403. }
  404. c++;
  405. }
  406. if (!c) {
  407. printf(" %s - making Default Data...\n", castle_txt);
  408. //デフォルトデータを作成
  409. for(i = 0; i < MAX_GUILDCASTLE; i++) {
  410. gc = aCalloc(sizeof(struct guild_castle), 1);
  411. if (gc == NULL) {
  412. printf("int_guild: out of memory!\n");
  413. exit(0);
  414. }
  415. memset(gc, 0, sizeof(struct guild_castle));
  416. gc->castle_id = i;
  417. gc->guild_id = 0;
  418. gc->economy = 0;
  419. gc->defense = 0;
  420. gc->triggerE = 0;
  421. gc->triggerD = 0;
  422. gc->nextTime = 0;
  423. gc->payTime = 0;
  424. gc->createTime = 0;
  425. gc->visibleC = 0;
  426. gc->visibleG0 = 0;
  427. gc->visibleG1 = 0;
  428. gc->visibleG2 = 0;
  429. gc->visibleG3 = 0;
  430. gc->visibleG4 = 0;
  431. gc->visibleG5 = 0;
  432. gc->visibleG6 = 0;
  433. gc->visibleG7 = 0;
  434. gc->Ghp0 = 0; // guardian HP [Valaris]
  435. gc->Ghp1 = 0;
  436. gc->Ghp2 = 0;
  437. gc->Ghp3 = 0;
  438. gc->Ghp4 = 0;
  439. gc->Ghp5 = 0;
  440. gc->Ghp6 = 0;
  441. gc->Ghp7 = 0; // end additions [Valaris]
  442. numdb_insert(castle_db, gc->castle_id, gc);
  443. }
  444. printf(" %s - making done\n",castle_txt);
  445. return 0;
  446. }
  447. fclose(fp);
  448. return 0;
  449. }
  450. struct guild *inter_guild_search(int guild_id) {
  451. struct guild *g;
  452. g=numdb_search(guild_db, guild_id);
  453. return g;
  454. }
  455. // ギルドデータのセーブ用
  456. int inter_guild_save_sub(void *key,void *data,va_list ap) {
  457. char line[16384];
  458. FILE *fp;
  459. inter_guild_tostr(line,(struct guild *)data);
  460. fp=va_arg(ap,FILE *);
  461. fprintf(fp,"%s" RETCODE,line);
  462. return 0;
  463. }
  464. // ギルド城データのセーブ用
  465. int inter_castle_save_sub(void *key, void *data, va_list ap) {
  466. char line[16384];
  467. FILE *fp;
  468. inter_guildcastle_tostr(line, (struct guild_castle *)data);
  469. fp = va_arg(ap, FILE *);
  470. fprintf(fp, "%s" RETCODE, line);
  471. return 0;
  472. }
  473. // ギルドデータのセーブ
  474. int inter_guild_save() {
  475. FILE *fp;
  476. int lock;
  477. if ((fp = lock_fopen(guild_txt, &lock)) == NULL) {
  478. printf("int_guild: cant write [%s] !!! data is lost !!!\n", guild_txt);
  479. return 1;
  480. }
  481. numdb_foreach(guild_db, inter_guild_save_sub, fp);
  482. // fprintf(fp, "%d\t%%newid%%\n", guild_newid);
  483. lock_fclose(fp, guild_txt, &lock);
  484. // printf("int_guild: %s saved.\n", guild_txt);
  485. if ((fp = lock_fopen(castle_txt,&lock)) == NULL) {
  486. printf("int_guild: cant write [%s] !!! data is lost !!!\n", castle_txt);
  487. return 1;
  488. }
  489. numdb_foreach(castle_db, inter_castle_save_sub, fp);
  490. lock_fclose(fp, castle_txt, &lock);
  491. return 0;
  492. }
  493. // ギルド名検索用
  494. int search_guildname_sub(void *key, void *data, va_list ap) {
  495. struct guild *g = (struct guild *)data, **dst;
  496. char *str;
  497. str = va_arg(ap, char *);
  498. dst = va_arg(ap, struct guild **);
  499. if (strcmpi(g->name, str) == 0)
  500. *dst = g;
  501. return 0;
  502. }
  503. // ギルド名検索
  504. struct guild* search_guildname(char *str) {
  505. struct guild *g = NULL;
  506. numdb_foreach(guild_db, search_guildname_sub, str, &g);
  507. return g;
  508. }
  509. // ギルドが空かどうかチェック
  510. int guild_check_empty(struct guild *g) {
  511. int i;
  512. for(i = 0; i < g->max_member; i++) {
  513. if (g->member[i].account_id > 0) {
  514. return 0;
  515. }
  516. }
  517. // 誰もいないので解散
  518. numdb_foreach(guild_db, guild_break_sub, g->guild_id);
  519. numdb_erase(guild_db, g->guild_id);
  520. inter_guild_storage_delete(g->guild_id);
  521. mapif_guild_broken(g->guild_id, 0);
  522. aFree(g);
  523. return 1;
  524. }
  525. // キャラの競合がないかチェック用
  526. int guild_check_conflict_sub(void *key, void *data, va_list ap) {
  527. struct guild *g = (struct guild *)data;
  528. int guild_id, account_id, char_id, i;
  529. guild_id = va_arg(ap, int);
  530. account_id = va_arg(ap, int);
  531. char_id = va_arg(ap, int);
  532. if (g->guild_id == guild_id) // 本来の所属なので問題なし
  533. return 0;
  534. for(i = 0; i < MAX_GUILD; i++) {
  535. if (g->member[i].account_id == account_id && g->member[i].char_id == char_id) {
  536. // 別のギルドに偽の所属データがあるので脱退
  537. printf("int_guild: guild conflict! %d,%d %d!=%d\n", account_id, char_id, guild_id, g->guild_id);
  538. mapif_parse_GuildLeave(-1, g->guild_id, account_id, char_id, 0, "**データ競合**");
  539. }
  540. }
  541. return 0;
  542. }
  543. // キャラの競合がないかチェック
  544. int guild_check_conflict(int guild_id, int account_id, int char_id) {
  545. numdb_foreach(guild_db, guild_check_conflict_sub, guild_id, account_id, char_id);
  546. return 0;
  547. }
  548. int guild_nextexp(int level) {
  549. if (level < 100)
  550. return guild_exp[level-1];
  551. return 0;
  552. }
  553. // ギルドスキルがあるか確認
  554. int guild_checkskill(struct guild *g, int id) {
  555. int idx = id - GD_SKILLBASE;
  556. if(idx < 0 || idx >= MAX_GUILDSKILL)
  557. return 0;
  558. return g->skill[idx].lv;
  559. }
  560. // ギルドの情報の再計算
  561. int guild_calcinfo(struct guild *g) {
  562. int i, c, nextexp;
  563. struct guild before = *g;
  564. // スキルIDの設定
  565. for(i = 0; i < MAX_GUILDSKILL; i++)
  566. g->skill[i].id=i+GD_SKILLBASE;
  567. // ギルドレベル
  568. if (g->guild_lv <= 0)
  569. g->guild_lv = 1;
  570. nextexp = guild_nextexp(g->guild_lv);
  571. if (nextexp > 0) {
  572. while(g->exp >= nextexp) { // レベルアップ処理
  573. g->exp -= nextexp;
  574. g->guild_lv++;
  575. g->skill_point++;
  576. nextexp = guild_nextexp(g->guild_lv);
  577. }
  578. }
  579. // ギルドの次の経験値
  580. g->next_exp = guild_nextexp(g->guild_lv);
  581. // メンバ上限(ギルド拡張適用)
  582. g->max_member = 16 + guild_checkskill(g, GD_EXTENSION) * 6; //Lupus 2 -> 6
  583. // 平均レベルとオンライン人数
  584. g->average_lv = 0;
  585. g->connect_member = 0;
  586. c = 0;
  587. for(i = 0; i < g->max_member; i++) {
  588. if (g->member[i].account_id > 0) {
  589. g->average_lv += g->member[i].lv;
  590. c++;
  591. if (g->member[i].online > 0)
  592. g->connect_member++;
  593. }
  594. }
  595. if(c) g->average_lv /= c;
  596. // 全データを送る必要がありそう
  597. if (g->max_member != before.max_member ||
  598. g->guild_lv != before.guild_lv ||
  599. g->skill_point != before.skill_point) {
  600. mapif_guild_info(-1, g);
  601. return 1;
  602. }
  603. return 0;
  604. }
  605. //-------------------------------------------------------------------
  606. // map serverへの通信
  607. // ギルド作成可否
  608. int mapif_guild_created(int fd, int account_id, struct guild *g) {
  609. WFIFOW(fd,0) = 0x3830;
  610. WFIFOL(fd,2) = account_id;
  611. if (g != NULL) {
  612. WFIFOL(fd,6) = g->guild_id;
  613. printf("int_guild: created! %d %s\n", g->guild_id, g->name);
  614. }else{
  615. WFIFOL(fd,6) = 0;
  616. }
  617. WFIFOSET(fd,10);
  618. return 0;
  619. }
  620. // ギルド情報見つからず
  621. int mapif_guild_noinfo(int fd, int guild_id) {
  622. WFIFOW(fd,0) = 0x3831;
  623. WFIFOW(fd,2) = 8;
  624. WFIFOL(fd,4) = guild_id;
  625. WFIFOSET(fd,8);
  626. printf("int_guild: info not found %d\n", guild_id);
  627. return 0;
  628. }
  629. // ギルド情報まとめ送り
  630. int mapif_guild_info(int fd, struct guild *g) {
  631. unsigned char buf[4 + sizeof(struct guild)];
  632. WBUFW(buf,0) = 0x3831;
  633. memcpy(buf + 4, g, sizeof(struct guild));
  634. WBUFW(buf,2) = 4 + sizeof(struct guild);
  635. // printf("int_guild: sizeof(guild)=%d\n", sizeof(struct guild));
  636. if (fd < 0)
  637. mapif_sendall(buf, WBUFW(buf,2));
  638. else
  639. mapif_send(fd, buf, WBUFW(buf,2));
  640. // printf("int_guild: info %d %s\n", p->guild_id, p->name);
  641. return 0;
  642. }
  643. // メンバ追加可否
  644. int mapif_guild_memberadded(int fd, int guild_id, int account_id, int char_id, int flag) {
  645. WFIFOW(fd,0) = 0x3832;
  646. WFIFOL(fd,2) = guild_id;
  647. WFIFOL(fd,6) = account_id;
  648. WFIFOL(fd,10) = char_id;
  649. WFIFOB(fd,14) = flag;
  650. WFIFOSET(fd, 15);
  651. return 0;
  652. }
  653. // 脱退/追放通知
  654. int mapif_guild_leaved(int guild_id, int account_id, int char_id, int flag, const char *name, const char *mes) {
  655. unsigned char buf[79];
  656. WBUFW(buf, 0) = 0x3834;
  657. WBUFL(buf, 2) = guild_id;
  658. WBUFL(buf, 6) = account_id;
  659. WBUFL(buf,10) = char_id;
  660. WBUFB(buf,14) = flag;
  661. memcpy(WBUFP(buf,15), mes, 40);
  662. memcpy(WBUFP(buf,55), name, 24);
  663. mapif_sendall(buf, 79);
  664. printf("int_guild: guild leaved %d %d %s %s\n", guild_id, account_id, name, mes);
  665. return 0;
  666. }
  667. // オンライン状態とLv更新通知
  668. int mapif_guild_memberinfoshort(struct guild *g, int idx) {
  669. unsigned char buf[19];
  670. WBUFW(buf, 0) = 0x3835;
  671. WBUFL(buf, 2) = g->guild_id;
  672. WBUFL(buf, 6) = g->member[idx].account_id;
  673. WBUFL(buf,10) = g->member[idx].char_id;
  674. WBUFB(buf,14) = (unsigned char)g->member[idx].online;
  675. WBUFW(buf,15) = g->member[idx].lv;
  676. WBUFW(buf,17) = g->member[idx].class_;
  677. mapif_sendall(buf, 19);
  678. return 0;
  679. }
  680. // 解散通知
  681. int mapif_guild_broken(int guild_id, int flag) {
  682. unsigned char buf[7];
  683. WBUFW(buf,0) = 0x3836;
  684. WBUFL(buf,2) = guild_id;
  685. WBUFB(buf,6) = flag;
  686. mapif_sendall(buf, 7);
  687. printf("int_guild: broken %d\n", guild_id);
  688. return 0;
  689. }
  690. // ギルド内発言
  691. int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sfd) {
  692. unsigned char buf[len+12];
  693. WBUFW(buf,0) = 0x3837;
  694. WBUFW(buf,2) = len + 12;
  695. WBUFL(buf,4) = guild_id;
  696. WBUFL(buf,8) = account_id;
  697. memcpy(WBUFP(buf,12), mes, len);
  698. mapif_sendallwos(sfd, buf, len + 12);
  699. return 0;
  700. }
  701. // ギルド基本情報変更通知
  702. int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len) {
  703. unsigned char buf[2048];
  704. WBUFW(buf,0) = 0x3839;
  705. WBUFW(buf,2) = len+10;
  706. WBUFL(buf,4) = guild_id;
  707. WBUFW(buf,8) = type;
  708. memcpy(WBUFP(buf,10),data,len);
  709. mapif_sendall(buf,len+10);
  710. return 0;
  711. }
  712. // ギルドメンバ情報変更通知
  713. int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int type, const void *data, int len) {
  714. unsigned char buf[len + 18];
  715. WBUFW(buf, 0) = 0x383a;
  716. WBUFW(buf, 2) = len + 18;
  717. WBUFL(buf, 4) = guild_id;
  718. WBUFL(buf, 8) = account_id;
  719. WBUFL(buf,12) = char_id;
  720. WBUFW(buf,16) = type;
  721. memcpy(WBUFP(buf,18), data, len);
  722. mapif_sendall(buf,len+18);
  723. return 0;
  724. }
  725. // ギルドスキルアップ通知
  726. int mapif_guild_skillupack(int guild_id, int skill_num, int account_id) {
  727. unsigned char buf[14];
  728. WBUFW(buf, 0) = 0x383c;
  729. WBUFL(buf, 2) = guild_id;
  730. WBUFL(buf, 6) = skill_num;
  731. WBUFL(buf,10) = account_id;
  732. mapif_sendall(buf, 14);
  733. return 0;
  734. }
  735. // ギルド同盟/敵対通知
  736. int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag, const char *name1, const char *name2) {
  737. unsigned char buf[67];
  738. WBUFW(buf, 0) = 0x383d;
  739. WBUFL(buf, 2) = guild_id1;
  740. WBUFL(buf, 6) = guild_id2;
  741. WBUFL(buf,10) = account_id1;
  742. WBUFL(buf,14) = account_id2;
  743. WBUFB(buf,18) = flag;
  744. memcpy(WBUFP(buf,19), name1, 24);
  745. memcpy(WBUFP(buf,43), name2, 24);
  746. mapif_sendall(buf, 67);
  747. return 0;
  748. }
  749. // ギルド役職変更通知
  750. int mapif_guild_position(struct guild *g, int idx) {
  751. unsigned char buf[sizeof(struct guild_position) + 12];
  752. WBUFW(buf,0) = 0x383b;
  753. WBUFW(buf,2) = sizeof(struct guild_position) + 12;
  754. WBUFL(buf,4) = g->guild_id;
  755. WBUFL(buf,8) = idx;
  756. memcpy(WBUFP(buf,12), &g->position[idx], sizeof(struct guild_position));
  757. mapif_sendall(buf, WBUFW(buf,2));
  758. return 0;
  759. }
  760. // ギルド告知変更通知
  761. int mapif_guild_notice(struct guild *g) {
  762. unsigned char buf[186];
  763. WBUFW(buf,0) = 0x383e;
  764. WBUFL(buf,2) = g->guild_id;
  765. memcpy(WBUFP(buf,6), g->mes1, 60);
  766. memcpy(WBUFP(buf,66), g->mes2, 120);
  767. mapif_sendall(buf, 186);
  768. return 0;
  769. }
  770. // ギルドエンブレム変更通知
  771. int mapif_guild_emblem(struct guild *g) {
  772. unsigned char buf[2048];
  773. WBUFW(buf,0) = 0x383f;
  774. WBUFW(buf,2) = g->emblem_len + 12;
  775. WBUFL(buf,4) = g->guild_id;
  776. WBUFL(buf,8) = g->emblem_id;
  777. memcpy(WBUFP(buf,12), g->emblem_data, g->emblem_len);
  778. mapif_sendall(buf, WBUFW(buf,2));
  779. return 0;
  780. }
  781. int mapif_guild_castle_dataload(int castle_id, int index, int value) {
  782. unsigned char buf[9];
  783. WBUFW(buf,0) = 0x3840;
  784. WBUFW(buf,2) = castle_id;
  785. WBUFB(buf,4) = index;
  786. WBUFL(buf,5) = value;
  787. mapif_sendall(buf,9);
  788. return 0;
  789. }
  790. int mapif_guild_castle_datasave(int castle_id, int index, int value) {
  791. unsigned char buf[9];
  792. WBUFW(buf,0) = 0x3841;
  793. WBUFW(buf,2) = castle_id;
  794. WBUFB(buf,4) = index;
  795. WBUFL(buf,5) = value;
  796. mapif_sendall(buf,9);
  797. return 0;
  798. }
  799. int mapif_guild_castle_alldataload_sub(void *key, void *data, va_list ap) {
  800. int fd = va_arg(ap, int);
  801. int *p = va_arg(ap, int*);
  802. memcpy(WFIFOP(fd,*p), (struct guild_castle*)data, sizeof(struct guild_castle));
  803. (*p) += sizeof(struct guild_castle);
  804. return 0;
  805. }
  806. int mapif_guild_castle_alldataload(int fd) {
  807. int len = 4;
  808. WFIFOW(fd,0) = 0x3842;
  809. numdb_foreach(castle_db, mapif_guild_castle_alldataload_sub, fd, &len);
  810. WFIFOW(fd,2) = len;
  811. WFIFOSET(fd, len);
  812. return 0;
  813. }
  814. //-------------------------------------------------------------------
  815. // map serverからの通信
  816. // ギルド作成要求
  817. int mapif_parse_CreateGuild(int fd, int account_id, char *name, struct guild_member *master) {
  818. struct guild *g;
  819. int i;
  820. for(i = 0; i < 24 && name[i]; i++) {
  821. if (!(name[i] & 0xe0) || name[i] == 0x7f) {
  822. printf("int_guild: illeagal guild name [%s]\n", name);
  823. mapif_guild_created(fd, account_id, NULL);
  824. return 0;
  825. }
  826. }
  827. if ((g = search_guildname(name)) != NULL) {
  828. printf("int_guild: same name guild exists [%s]\n", name);
  829. mapif_guild_created(fd, account_id, NULL);
  830. return 0;
  831. }
  832. g = aCalloc(sizeof(struct guild), 1);
  833. if (g == NULL) {
  834. printf("int_guild: CreateGuild: out of memory !\n");
  835. mapif_guild_created(fd, account_id, NULL);
  836. exit(0);
  837. }
  838. memset(g, 0, sizeof(struct guild));
  839. g->guild_id = guild_newid++;
  840. memcpy(g->name, name, 24);
  841. memcpy(g->master, master->name, 24);
  842. memcpy(&g->member[0], master, sizeof(struct guild_member));
  843. g->position[0].mode = 0x11;
  844. strcpy(g->position[ 0].name, "GuildMaster");
  845. strcpy(g->position[MAX_GUILDPOSITION-1].name, "Newbie");
  846. for(i = 1; i < MAX_GUILDPOSITION-1; i++)
  847. sprintf(g->position[i].name, "Position %d", i + 1);
  848. // ここでギルド情報計算が必要と思われる
  849. g->max_member = 16;
  850. g->average_lv = master->lv;
  851. for(i = 0; i < MAX_GUILDSKILL; i++)
  852. g->skill[i].id=i + GD_SKILLBASE;
  853. numdb_insert(guild_db, g->guild_id, g);
  854. mapif_guild_created(fd, account_id, g);
  855. mapif_guild_info(fd, g);
  856. if(log_inter)
  857. inter_log("guild %s (id=%d) created by master %s (id=%d)" RETCODE,
  858. name, g->guild_id, master->name, master->account_id);
  859. return 0;
  860. }
  861. // ギルド情報要求
  862. int mapif_parse_GuildInfo(int fd, int guild_id) {
  863. struct guild *g;
  864. g = numdb_search(guild_db, guild_id);
  865. if (g != NULL){
  866. guild_calcinfo(g);
  867. mapif_guild_info(fd, g);
  868. } else
  869. mapif_guild_noinfo(fd, guild_id);
  870. return 0;
  871. }
  872. // ギルドメンバ追加要求
  873. int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m) {
  874. struct guild *g;
  875. int i;
  876. g = numdb_search(guild_db, guild_id);
  877. if (g == NULL) {
  878. mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1);
  879. return 0;
  880. }
  881. for(i = 0; i < g->max_member; i++) {
  882. if (g->member[i].account_id == 0) {
  883. memcpy(&g->member[i], m, sizeof(struct guild_member));
  884. mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 0);
  885. guild_calcinfo(g);
  886. mapif_guild_info(-1, g);
  887. return 0;
  888. }
  889. }
  890. mapif_guild_memberadded(fd, guild_id, m->account_id, m->char_id, 1);
  891. return 0;
  892. }
  893. // ギルド脱退/追放要求
  894. int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, int flag, const char *mes) {
  895. struct guild *g = NULL;
  896. int i, j;
  897. g = numdb_search(guild_db, guild_id);
  898. if (g != NULL) {
  899. for(i = 0; i < MAX_GUILD; i++) {
  900. if (g->member[i].account_id == account_id && g->member[i].char_id == char_id) {
  901. // printf("%d %d\n", i, (int)(&g->member[i]));
  902. // printf("%d %s\n", i, g->member[i].name);
  903. if (flag) { // 追放の場合追放リストに入れる
  904. for(j = 0; j < MAX_GUILDEXPLUSION; j++) {
  905. if (g->explusion[j].account_id == 0)
  906. break;
  907. }
  908. if (j == MAX_GUILDEXPLUSION) { // 一杯なので古いのを消す
  909. for(j = 0; j < MAX_GUILDEXPLUSION - 1; j++)
  910. g->explusion[j] = g->explusion[j+1];
  911. j = MAX_GUILDEXPLUSION - 1;
  912. }
  913. g->explusion[j].account_id = account_id;
  914. memcpy(g->explusion[j].acc, "dummy", 24);
  915. memcpy(g->explusion[j].name, g->member[i].name, 24);
  916. memcpy(g->explusion[j].mes, mes, 40);
  917. }
  918. mapif_guild_leaved(guild_id, account_id, char_id, flag, g->member[i].name, mes);
  919. // printf("%d %d\n", i, (int)(&g->member[i]));
  920. // printf("%d %s\n", i, (&g->member[i])->name);
  921. memset(&g->member[i], 0, sizeof(struct guild_member));
  922. if (guild_check_empty(g) == 0)
  923. mapif_guild_info(-1,g);// まだ人がいるのでデータ送信
  924. return 0;
  925. }
  926. }
  927. }
  928. return 0;
  929. }
  930. // オンライン/Lv更新
  931. int mapif_parse_GuildChangeMemberInfoShort(int fd, int guild_id, int account_id, int char_id, int online, int lv, int class_) {
  932. struct guild *g;
  933. int i, alv, c;
  934. g = numdb_search(guild_db, guild_id);
  935. if (g == NULL)
  936. return 0;
  937. g->connect_member = 0;
  938. alv = 0;
  939. c = 0;
  940. for(i = 0; i < MAX_GUILD; i++) {
  941. if (g->member[i].account_id == account_id && g->member[i].char_id == char_id) {
  942. g->member[i].online = online;
  943. g->member[i].lv = lv;
  944. g->member[i].class_ = class_;
  945. mapif_guild_memberinfoshort(g, i);
  946. }
  947. if (g->member[i].account_id > 0) {
  948. alv += g->member[i].lv;
  949. c++;
  950. }
  951. if (g->member[i].online)
  952. g->connect_member++;
  953. }
  954. if (c)
  955. // 平均レベル
  956. g->average_lv = alv / c;
  957. return 0;
  958. }
  959. // ギルド解散処理用(同盟/敵対を解除)
  960. int guild_break_sub(void *key, void *data, va_list ap) {
  961. struct guild *g = (struct guild *)data;
  962. int guild_id = va_arg(ap, int);
  963. int i;
  964. for(i = 0; i < MAX_GUILDALLIANCE; i++) {
  965. if (g->alliance[i].guild_id == guild_id)
  966. g->alliance[i].guild_id = 0;
  967. }
  968. return 0;
  969. }
  970. // ギルド解散要求
  971. int mapif_parse_BreakGuild(int fd, int guild_id) {
  972. struct guild *g;
  973. g = numdb_search(guild_db, guild_id);
  974. if(g == NULL)
  975. return 0;
  976. numdb_foreach(guild_db, guild_break_sub, guild_id);
  977. numdb_erase(guild_db, guild_id);
  978. inter_guild_storage_delete(guild_id);
  979. mapif_guild_broken(guild_id, 0);
  980. if(log_inter)
  981. inter_log("guild %s (id=%d) broken" RETCODE, g->name, guild_id);
  982. aFree(g);
  983. return 0;
  984. }
  985. // ギルドメッセージ送信
  986. int mapif_parse_GuildMessage(int fd, int guild_id, int account_id, char *mes, int len) {
  987. return mapif_guild_message(guild_id, account_id, mes, len, fd);
  988. }
  989. // ギルド基本データ変更要求
  990. int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const char *data, int len) {
  991. struct guild *g;
  992. short dw = *((short *)data);
  993. g = numdb_search(guild_db, guild_id);
  994. if (g == NULL)
  995. return 0;
  996. switch(type) {
  997. case GBI_GUILDLV:
  998. if (dw > 0 && g->guild_lv + dw <= 50) {
  999. g->guild_lv+=dw;
  1000. g->skill_point+=dw;
  1001. } else if (dw < 0 && g->guild_lv + dw >= 1)
  1002. g->guild_lv += dw;
  1003. mapif_guild_info(-1, g);
  1004. return 0;
  1005. default:
  1006. printf("int_guild: GuildBasicInfoChange: Unknown type %d\n", type);
  1007. break;
  1008. }
  1009. mapif_guild_basicinfochanged(guild_id, type, data, len);
  1010. return 0;
  1011. }
  1012. // ギルドメンバデータ変更要求
  1013. int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int char_id, int type, const char *data, int len) {
  1014. int i;
  1015. struct guild *g;
  1016. g = numdb_search(guild_db, guild_id);
  1017. if(g == NULL)
  1018. return 0;
  1019. for(i = 0; i < g->max_member; i++)
  1020. if (g->member[i].account_id == account_id && g->member[i].char_id == char_id)
  1021. break;
  1022. if (i == g->max_member) {
  1023. printf("int_guild: GuildMemberChange: Not found %d,%d in %d[%s]\n", account_id, char_id, guild_id, g->name);
  1024. return 0;
  1025. }
  1026. switch(type) {
  1027. case GMI_POSITION: // 役職
  1028. g->member[i].position = *((int *)data);
  1029. break;
  1030. case GMI_EXP: // EXP
  1031. {
  1032. int exp, oldexp = g->member[i].exp;
  1033. exp = g->member[i].exp = *((unsigned int *)data);
  1034. g->exp += (exp - oldexp);
  1035. guild_calcinfo(g); // Lvアップ判断
  1036. mapif_guild_basicinfochanged(guild_id, GBI_EXP, &g->exp, 4);
  1037. }
  1038. break;
  1039. default:
  1040. printf("int_guild: GuildMemberInfoChange: Unknown type %d\n", type);
  1041. break;
  1042. }
  1043. mapif_guild_memberinfochanged(guild_id, account_id, char_id, type, data, len);
  1044. return 0;
  1045. }
  1046. // ギルド役職名変更要求
  1047. int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_position *p) {
  1048. struct guild *g = numdb_search(guild_db, guild_id);
  1049. if (g == NULL || idx < 0 || idx >= MAX_GUILDPOSITION) {
  1050. return 0;
  1051. }
  1052. memcpy(&g->position[idx], p, sizeof(struct guild_position));
  1053. mapif_guild_position(g, idx);
  1054. printf("int_guild: position changed %d\n", idx);
  1055. return 0;
  1056. }
  1057. // ギルドスキルアップ要求
  1058. int mapif_parse_GuildSkillUp(int fd, int guild_id, int skill_num, int account_id) {
  1059. struct guild *g = numdb_search(guild_db, guild_id);
  1060. int idx = skill_num - GD_SKILLBASE;
  1061. if (g == NULL || idx < 0 || idx >= MAX_GUILDSKILL)
  1062. return 0;
  1063. if (g->skill_point > 0 && g->skill[idx].id > 0 && g->skill[idx].lv < 10) {
  1064. g->skill[idx].lv++;
  1065. g->skill_point--;
  1066. if (guild_calcinfo(g) == 0)
  1067. mapif_guild_info(-1, g);
  1068. mapif_guild_skillupack(guild_id, skill_num, account_id);
  1069. printf("int_guild: skill %d up\n", skill_num);
  1070. }
  1071. return 0;
  1072. }
  1073. // ギルド同盟要求
  1074. int mapif_parse_GuildAlliance(int fd, int guild_id1, int guild_id2, int account_id1, int account_id2, int flag) {
  1075. struct guild *g[2];
  1076. int j, i;
  1077. g[0] = numdb_search(guild_db, guild_id1);
  1078. g[1] = numdb_search(guild_db, guild_id2);
  1079. if (g[0] == NULL || g[1] == NULL)
  1080. return 0;
  1081. if (!(flag & 0x8)) {
  1082. for(i = 0; i < 2 - (flag & 1); i++) {
  1083. for(j = 0; j < MAX_GUILDALLIANCE; j++)
  1084. if (g[i]->alliance[j].guild_id == 0) {
  1085. g[i]->alliance[j].guild_id = g[1-i]->guild_id;
  1086. memcpy(g[i]->alliance[j].name, g[1-i]->name, 24);
  1087. g[i]->alliance[j].opposition = flag & 1;
  1088. break;
  1089. }
  1090. }
  1091. } else { // 関係解消
  1092. for(i = 0; i < 2 - (flag & 1); i++) {
  1093. for(j = 0; j < MAX_GUILDALLIANCE; j++)
  1094. if (g[i]->alliance[j].guild_id == g[1-i]->guild_id && g[i]->alliance[j].opposition == (flag & 1)) {
  1095. g[i]->alliance[j].guild_id = 0;
  1096. break;
  1097. }
  1098. }
  1099. }
  1100. mapif_guild_alliance(guild_id1, guild_id2, account_id1, account_id2, flag, g[0]->name, g[1]->name);
  1101. return 0;
  1102. }
  1103. // ギルド告知変更要求
  1104. int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char *mes2) {
  1105. struct guild *g;
  1106. g = numdb_search(guild_db, guild_id);
  1107. if (g == NULL)
  1108. return 0;
  1109. memcpy(g->mes1, mes1, 60);
  1110. memcpy(g->mes2, mes2, 120);
  1111. return mapif_guild_notice(g);
  1112. }
  1113. // ギルドエンブレム変更要求
  1114. int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char *data) {
  1115. struct guild *g;
  1116. g = numdb_search(guild_db, guild_id);
  1117. if (g == NULL)
  1118. return 0;
  1119. memcpy(g->emblem_data, data, len);
  1120. g->emblem_len = len;
  1121. g->emblem_id++;
  1122. return mapif_guild_emblem(g);
  1123. }
  1124. int mapif_parse_GuildCastleDataLoad(int fd, int castle_id, int index) {
  1125. struct guild_castle *gc = numdb_search(castle_db, castle_id);
  1126. if (gc == NULL) {
  1127. return mapif_guild_castle_dataload(castle_id, 0, 0);
  1128. }
  1129. switch(index) {
  1130. case 1: return mapif_guild_castle_dataload(gc->castle_id, index, gc->guild_id);
  1131. case 2: return mapif_guild_castle_dataload(gc->castle_id, index, gc->economy);
  1132. case 3: return mapif_guild_castle_dataload(gc->castle_id, index, gc->defense);
  1133. case 4: return mapif_guild_castle_dataload(gc->castle_id, index, gc->triggerE);
  1134. case 5: return mapif_guild_castle_dataload(gc->castle_id, index, gc->triggerD);
  1135. case 6: return mapif_guild_castle_dataload(gc->castle_id, index, gc->nextTime);
  1136. case 7: return mapif_guild_castle_dataload(gc->castle_id, index, gc->payTime);
  1137. case 8: return mapif_guild_castle_dataload(gc->castle_id, index, gc->createTime);
  1138. case 9: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleC);
  1139. case 10: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG0);
  1140. case 11: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG1);
  1141. case 12: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG2);
  1142. case 13: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG3);
  1143. case 14: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG4);
  1144. case 15: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG5);
  1145. case 16: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG6);
  1146. case 17: return mapif_guild_castle_dataload(gc->castle_id, index, gc->visibleG7);
  1147. case 18: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp0); // guardian HP [Valaris]
  1148. case 19: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp1);
  1149. case 20: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp2);
  1150. case 21: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp3);
  1151. case 22: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp4);
  1152. case 23: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp5);
  1153. case 24: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp6);
  1154. case 25: return mapif_guild_castle_dataload(gc->castle_id, index, gc->Ghp7); // end additions [Valaris]
  1155. default:
  1156. printf("mapif_parse_GuildCastleDataLoad ERROR!! (Not found index=%d)\n", index);
  1157. return 0;
  1158. }
  1159. return 0;
  1160. }
  1161. int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value) {
  1162. struct guild_castle *gc=numdb_search(castle_db, castle_id);
  1163. if (gc == NULL) {
  1164. return mapif_guild_castle_datasave(castle_id, index, value);
  1165. }
  1166. switch(index) {
  1167. case 1:
  1168. if (gc->guild_id != value) {
  1169. int gid = (value) ? value : gc->guild_id;
  1170. struct guild *g = numdb_search(guild_db, gid);
  1171. if(log_inter)
  1172. inter_log("guild %s (id=%d) %s castle id=%d" RETCODE,
  1173. (g) ? g->name : "??", gid, (value) ? "occupy" : "abandon", castle_id);
  1174. }
  1175. gc->guild_id = value;
  1176. break;
  1177. case 2: gc->economy = value; break;
  1178. case 3: gc->defense = value; break;
  1179. case 4: gc->triggerE = value; break;
  1180. case 5: gc->triggerD = value; break;
  1181. case 6: gc->nextTime = value; break;
  1182. case 7: gc->payTime = value; break;
  1183. case 8: gc->createTime = value; break;
  1184. case 9: gc->visibleC = value; break;
  1185. case 10: gc->visibleG0 = value; break;
  1186. case 11: gc->visibleG1 = value; break;
  1187. case 12: gc->visibleG2 = value; break;
  1188. case 13: gc->visibleG3 = value; break;
  1189. case 14: gc->visibleG4 = value; break;
  1190. case 15: gc->visibleG5 = value; break;
  1191. case 16: gc->visibleG6 = value; break;
  1192. case 17: gc->visibleG7 = value; break;
  1193. case 18: gc->Ghp0 = value; break; // guardian HP [Valaris]
  1194. case 19: gc->Ghp1 = value; break;
  1195. case 20: gc->Ghp2 = value; break;
  1196. case 21: gc->Ghp3 = value; break;
  1197. case 22: gc->Ghp4 = value; break;
  1198. case 23: gc->Ghp5 = value; break;
  1199. case 24: gc->Ghp6 = value; break;
  1200. case 25: gc->Ghp7 = value; break; // end additions [Valaris]
  1201. default:
  1202. printf("mapif_parse_GuildCastleDataSave ERROR!! (Not found index=%d)\n", index);
  1203. return 0;
  1204. }
  1205. return mapif_guild_castle_datasave(gc->castle_id, index, value);
  1206. }
  1207. // ギルドチェック要求
  1208. int mapif_parse_GuildCheck(int fd, int guild_id, int account_id, int char_id) {
  1209. return guild_check_conflict(guild_id, account_id, char_id);
  1210. }
  1211. // map server からの通信
  1212. // ・1パケットのみ解析すること
  1213. // ・パケット長データはinter.cにセットしておくこと
  1214. // ・パケット長チェックや、RFIFOSKIPは呼び出し元で行われるので行ってはならない
  1215. // ・エラーなら0(false)、そうでないなら1(true)をかえさなければならない
  1216. int inter_guild_parse_frommap(int fd) {
  1217. switch(RFIFOW(fd,0)) {
  1218. case 0x3030: mapif_parse_CreateGuild(fd, RFIFOL(fd,4), (char*)RFIFOP(fd,8), (struct guild_member *)RFIFOP(fd,32)); break;
  1219. case 0x3031: mapif_parse_GuildInfo(fd, RFIFOL(fd,2)); break;
  1220. case 0x3032: mapif_parse_GuildAddMember(fd, RFIFOL(fd,4), (struct guild_member *)RFIFOP(fd,8)); break;
  1221. case 0x3034: mapif_parse_GuildLeave(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOB(fd,14), (const char*)RFIFOP(fd,15)); break;
  1222. case 0x3035: mapif_parse_GuildChangeMemberInfoShort(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOB(fd,14), RFIFOW(fd,15), RFIFOW(fd,17)); break;
  1223. case 0x3036: mapif_parse_BreakGuild(fd, RFIFOL(fd,2)); break;
  1224. case 0x3037: mapif_parse_GuildMessage(fd, RFIFOL(fd,4), RFIFOL(fd,8), (char*)RFIFOP(fd,12), RFIFOW(fd,2)-12); break;
  1225. case 0x3038: mapif_parse_GuildCheck(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break;
  1226. case 0x3039: mapif_parse_GuildBasicInfoChange(fd, RFIFOL(fd,4), RFIFOW(fd,8), (const char*)RFIFOP(fd,10), RFIFOW(fd,2)-10); break;
  1227. case 0x303A: mapif_parse_GuildMemberInfoChange(fd, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOL(fd,12), RFIFOW(fd,16), (const char*)RFIFOP(fd,18), RFIFOW(fd,2)-18); break;
  1228. case 0x303B: mapif_parse_GuildPosition(fd, RFIFOL(fd,4), RFIFOL(fd,8), (struct guild_position *)RFIFOP(fd,12)); break;
  1229. case 0x303C: mapif_parse_GuildSkillUp(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break;
  1230. case 0x303D: mapif_parse_GuildAlliance(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOB(fd,18)); break;
  1231. case 0x303E: mapif_parse_GuildNotice(fd, RFIFOL(fd,2), (const char*)RFIFOP(fd,6), (const char*)RFIFOP(fd,66)); break;
  1232. case 0x303F: mapif_parse_GuildEmblem(fd, RFIFOW(fd,2)-12, RFIFOL(fd,4), RFIFOL(fd,8), (const char*)RFIFOP(fd,12)); break;
  1233. case 0x3040: mapif_parse_GuildCastleDataLoad(fd, RFIFOW(fd,2), RFIFOB(fd,4)); break;
  1234. case 0x3041: mapif_parse_GuildCastleDataSave(fd, RFIFOW(fd,2), RFIFOB(fd,4), RFIFOL(fd,5)); break;
  1235. default:
  1236. return 0;
  1237. }
  1238. return 1;
  1239. }
  1240. // マップサーバーの接続時処理
  1241. int inter_guild_mapif_init(int fd) {
  1242. return mapif_guild_castle_alldataload(fd);
  1243. }
  1244. // サーバーから脱退要求(キャラ削除用)
  1245. int inter_guild_leave(int guild_id, int account_id, int char_id) {
  1246. return mapif_parse_GuildLeave(-1, guild_id, account_id, char_id, 0, "**サーバー命令**");
  1247. }