1 | // Copyright (c) Athena Dev Teams - Licensed under GNU GPL |
---|
2 | // For more information, see LICENCE in the main folder |
---|
3 | |
---|
4 | #include "../common/cbasetypes.h" |
---|
5 | #include "../common/mmo.h" |
---|
6 | #include "../common/malloc.h" |
---|
7 | #include "../common/socket.h" |
---|
8 | #include "../common/db.h" |
---|
9 | #include "../common/lock.h" |
---|
10 | #include "../common/showmsg.h" |
---|
11 | #include "char.h" |
---|
12 | #include "inter.h" |
---|
13 | #include "int_party.h" |
---|
14 | |
---|
15 | #include <stdio.h> |
---|
16 | #include <stdlib.h> |
---|
17 | #include <string.h> |
---|
18 | |
---|
19 | char party_txt[1024] = "save/party.txt"; |
---|
20 | #ifndef TXT_SQL_CONVERT |
---|
21 | struct party_data { |
---|
22 | struct party party; |
---|
23 | unsigned int min_lv, max_lv; |
---|
24 | int family; //Is this party a family? if so, this holds the child id. |
---|
25 | unsigned char size; //Total size of party. |
---|
26 | }; |
---|
27 | |
---|
28 | static DBMap* party_db; // int party_id -> struct party_data* |
---|
29 | static int party_newid = 100; |
---|
30 | |
---|
31 | int mapif_party_broken(int party_id, int flag); |
---|
32 | int party_check_empty(struct party *p); |
---|
33 | int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id); |
---|
34 | int party_check_exp_share(struct party_data *p); |
---|
35 | int mapif_party_optionchanged(int fd,struct party *p, int account_id, int flag); |
---|
36 | |
---|
37 | //Updates party's level range and unsets even share if broken. |
---|
38 | static int int_party_check_lv(struct party_data *p) { |
---|
39 | int i; |
---|
40 | unsigned int lv; |
---|
41 | p->min_lv = UINT_MAX; |
---|
42 | p->max_lv = 0; |
---|
43 | for(i=0;i<MAX_PARTY;i++){ |
---|
44 | if(!p->party.member[i].online) |
---|
45 | continue; |
---|
46 | |
---|
47 | lv=p->party.member[i].lv; |
---|
48 | if (lv < p->min_lv) p->min_lv = lv; |
---|
49 | if (lv > p->max_lv) p->max_lv = lv; |
---|
50 | } |
---|
51 | |
---|
52 | if (p->party.exp && !party_check_exp_share(p)) { |
---|
53 | p->party.exp = 0; |
---|
54 | mapif_party_optionchanged(0, &p->party, 0, 0); |
---|
55 | return 0; |
---|
56 | } |
---|
57 | return 1; |
---|
58 | } |
---|
59 | |
---|
60 | //Calculates the state of a party. |
---|
61 | static void int_party_calc_state(struct party_data *p) |
---|
62 | { |
---|
63 | int i; |
---|
64 | unsigned int lv; |
---|
65 | p->min_lv = UINT_MAX; |
---|
66 | p->max_lv = 0; |
---|
67 | p->party.count = |
---|
68 | p->size = |
---|
69 | p->family = 0; |
---|
70 | |
---|
71 | //Check party size. |
---|
72 | for(i=0;i<MAX_PARTY;i++){ |
---|
73 | if (!p->party.member[i].lv) continue; |
---|
74 | p->size++; |
---|
75 | if(p->party.member[i].online) |
---|
76 | p->party.count++; |
---|
77 | } |
---|
78 | if(p->size == 3) { |
---|
79 | //Check Family State. |
---|
80 | p->family = char_family( |
---|
81 | p->party.member[0].char_id, |
---|
82 | p->party.member[1].char_id, |
---|
83 | p->party.member[2].char_id |
---|
84 | ); |
---|
85 | } |
---|
86 | //max/min levels. |
---|
87 | for(i=0;i<MAX_PARTY;i++){ |
---|
88 | lv=p->party.member[i].lv; |
---|
89 | if (!lv) continue; |
---|
90 | if(p->party.member[i].online && |
---|
91 | //On families, the kid is not counted towards exp share rules. |
---|
92 | p->party.member[i].char_id != p->family) |
---|
93 | { |
---|
94 | if( lv < p->min_lv ) p->min_lv=lv; |
---|
95 | if( p->max_lv < lv ) p->max_lv=lv; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | if (p->party.exp && !party_check_exp_share(p)) { |
---|
100 | p->party.exp = 0; //Set off even share. |
---|
101 | mapif_party_optionchanged(0, &p->party, 0, 0); |
---|
102 | } |
---|
103 | return; |
---|
104 | } |
---|
105 | |
---|
106 | // p?eBf?^̶ñÖÌ?· |
---|
107 | int inter_party_tostr(char *str, struct party *p) { |
---|
108 | int i, len; |
---|
109 | |
---|
110 | len = sprintf(str, "%d\t%s\t%d,%d\t", p->party_id, p->name, p->exp, p->item); |
---|
111 | for(i = 0; i < MAX_PARTY; i++) { |
---|
112 | struct party_member *m = &p->member[i]; |
---|
113 | len += sprintf(str + len, "%d,%d,%d\t", m->account_id, m->char_id, m->leader); |
---|
114 | } |
---|
115 | |
---|
116 | return 0; |
---|
117 | } |
---|
118 | #endif //TXT_SQL_CONVERT |
---|
119 | // p?eBf?^̶ñ©çÌ?· |
---|
120 | int inter_party_fromstr(char *str, struct party *p) { |
---|
121 | int i, j; |
---|
122 | int tmp_int[16]; |
---|
123 | char tmp_str[256]; |
---|
124 | #ifndef TXT_SQL_CONVERT |
---|
125 | struct mmo_charstatus* status; |
---|
126 | #endif |
---|
127 | |
---|
128 | memset(p, 0, sizeof(struct party)); |
---|
129 | |
---|
130 | if (sscanf(str, "%d\t%255[^\t]\t%d,%d\t", &tmp_int[0], tmp_str, &tmp_int[1], &tmp_int[2]) != 4) |
---|
131 | return 1; |
---|
132 | |
---|
133 | p->party_id = tmp_int[0]; |
---|
134 | memcpy(p->name, tmp_str, NAME_LENGTH); |
---|
135 | p->exp = tmp_int[1]?1:0; |
---|
136 | p->item = tmp_int[2]; |
---|
137 | |
---|
138 | for(j = 0; j < 3 && str != NULL; j++) |
---|
139 | str = strchr(str + 1, '\t'); |
---|
140 | |
---|
141 | for(i = 0; i < MAX_PARTY; i++) { |
---|
142 | struct party_member *m = &p->member[i]; |
---|
143 | if (str == NULL) |
---|
144 | return 1; |
---|
145 | |
---|
146 | if (sscanf(str + 1, "%d,%d,%d\t", &tmp_int[0], &tmp_int[1], &tmp_int[2]) != 3) |
---|
147 | return 1; |
---|
148 | |
---|
149 | m->account_id = tmp_int[0]; |
---|
150 | m->char_id = tmp_int[1]; |
---|
151 | m->leader = tmp_int[2]?1:0; |
---|
152 | |
---|
153 | str = strchr(str + 1, '\t'); |
---|
154 | #ifndef TXT_SQL_CONVERT |
---|
155 | if (!m->account_id) continue; |
---|
156 | //Lookup player for rest of data. |
---|
157 | status = search_character(m->account_id, m->char_id); |
---|
158 | if (!status) continue; |
---|
159 | |
---|
160 | memcpy(m->name, status->name, NAME_LENGTH); |
---|
161 | m->class_ = status->class_; |
---|
162 | m->map = status->last_point.map; |
---|
163 | m->lv = status->base_level; |
---|
164 | #endif //TXT_SQL_CONVERT |
---|
165 | } |
---|
166 | |
---|
167 | return 0; |
---|
168 | } |
---|
169 | #ifndef TXT_SQL_CONVERT |
---|
170 | // p?eBf?^Ì?h |
---|
171 | int inter_party_init() { |
---|
172 | char line[8192]; |
---|
173 | struct party_data *p; |
---|
174 | FILE *fp; |
---|
175 | int c = 0; |
---|
176 | int i, j; |
---|
177 | |
---|
178 | party_db = idb_alloc(DB_OPT_RELEASE_DATA); |
---|
179 | |
---|
180 | if ((fp = fopen(party_txt, "r")) == NULL) |
---|
181 | return 1; |
---|
182 | |
---|
183 | while(fgets(line, sizeof(line), fp)) |
---|
184 | { |
---|
185 | j = 0; |
---|
186 | if (sscanf(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0 && party_newid <= i) { |
---|
187 | party_newid = i; |
---|
188 | continue; |
---|
189 | } |
---|
190 | |
---|
191 | p = (struct party_data*)aCalloc(sizeof(struct party_data), 1); |
---|
192 | if (p == NULL){ |
---|
193 | ShowFatalError("int_party: out of memory!\n"); |
---|
194 | exit(EXIT_FAILURE); |
---|
195 | } |
---|
196 | memset(p, 0, sizeof(struct party_data)); |
---|
197 | if (inter_party_fromstr(line, &p->party) == 0 && p->party.party_id > 0) { |
---|
198 | int_party_calc_state(p); |
---|
199 | if (p->party.party_id >= party_newid) |
---|
200 | party_newid = p->party.party_id + 1; |
---|
201 | idb_put(party_db, p->party.party_id, p); |
---|
202 | party_check_empty(&p->party); |
---|
203 | } else { |
---|
204 | ShowError("int_party: broken data [%s] line %d\n", party_txt, c + 1); |
---|
205 | aFree(p); |
---|
206 | } |
---|
207 | c++; |
---|
208 | } |
---|
209 | fclose(fp); |
---|
210 | |
---|
211 | return 0; |
---|
212 | } |
---|
213 | |
---|
214 | void inter_party_final() |
---|
215 | { |
---|
216 | party_db->destroy(party_db, NULL); |
---|
217 | return; |
---|
218 | } |
---|
219 | |
---|
220 | // p?eB?f?^ÌZ?up |
---|
221 | int inter_party_save_sub(DBKey key, void *data, va_list ap) { |
---|
222 | char line[8192]; |
---|
223 | FILE *fp; |
---|
224 | |
---|
225 | inter_party_tostr(line, &((struct party_data*)data)->party); |
---|
226 | fp = va_arg(ap, FILE *); |
---|
227 | fprintf(fp, "%s\n", line); |
---|
228 | |
---|
229 | return 0; |
---|
230 | } |
---|
231 | |
---|
232 | // p?eB?f?^ÌZ?u |
---|
233 | int inter_party_save() { |
---|
234 | FILE *fp; |
---|
235 | int lock; |
---|
236 | |
---|
237 | if ((fp = lock_fopen(party_txt, &lock)) == NULL) { |
---|
238 | ShowError("int_party: can't write [%s] !!! data is lost !!!\n", party_txt); |
---|
239 | return 1; |
---|
240 | } |
---|
241 | party_db->foreach(party_db, inter_party_save_sub, fp); |
---|
242 | lock_fclose(fp,party_txt, &lock); |
---|
243 | return 0; |
---|
244 | } |
---|
245 | |
---|
246 | // Search for the party according to its name |
---|
247 | struct party_data* search_partyname(char *str) |
---|
248 | { |
---|
249 | struct DBIterator* iter; |
---|
250 | struct party_data* p; |
---|
251 | struct party_data* result = NULL; |
---|
252 | |
---|
253 | iter = party_db->iterator(party_db); |
---|
254 | for( p = (struct party_data*)iter->first(iter,NULL); iter->exists(iter); p = (struct party_data*)iter->next(iter,NULL) ) |
---|
255 | { |
---|
256 | if( strncmpi(p->party.name, str, NAME_LENGTH) == 0 ) |
---|
257 | { |
---|
258 | result = p; |
---|
259 | break; |
---|
260 | } |
---|
261 | } |
---|
262 | iter->destroy(iter); |
---|
263 | |
---|
264 | return result; |
---|
265 | } |
---|
266 | |
---|
267 | // Returns whether this party can keep having exp share or not. |
---|
268 | int party_check_exp_share(struct party_data *p) { |
---|
269 | return (p->party.count < 2|| p->max_lv - p->min_lv <= party_share_level); |
---|
270 | } |
---|
271 | |
---|
272 | // p?eBªó©Ç€©`FbN |
---|
273 | int party_check_empty(struct party *p) { |
---|
274 | int i; |
---|
275 | |
---|
276 | for(i = 0; i < MAX_PARTY; i++) { |
---|
277 | if (p->member[i].account_id > 0) { |
---|
278 | return 0; |
---|
279 | } |
---|
280 | } |
---|
281 | mapif_party_broken(p->party_id, 0); |
---|
282 | idb_remove(party_db, p->party_id); |
---|
283 | |
---|
284 | return 1; |
---|
285 | } |
---|
286 | |
---|
287 | // LÌ£ªÈ¢©`FbN |
---|
288 | int party_check_conflict(int party_id, int account_id, int char_id) |
---|
289 | { |
---|
290 | DBIterator* iter; |
---|
291 | struct party_data* p; |
---|
292 | int i; |
---|
293 | |
---|
294 | iter = party_db->iterator(party_db); |
---|
295 | for( p = (struct party_data*)iter->first(iter,NULL); iter->exists(iter); p = (struct party_data*)iter->next(iter,NULL) ) |
---|
296 | { |
---|
297 | if (p->party.party_id == party_id) //No conflict to check |
---|
298 | continue; |
---|
299 | |
---|
300 | ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == account_id && p->party.member[i].char_id == char_id ); |
---|
301 | if( i < MAX_PARTY ) |
---|
302 | { |
---|
303 | ShowWarning("int_party: party conflict! %d %d %d\n", account_id, party_id, p->party.party_id); |
---|
304 | mapif_parse_PartyLeave(-1, p->party.party_id, account_id, char_id); |
---|
305 | } |
---|
306 | } |
---|
307 | iter->destroy(iter); |
---|
308 | |
---|
309 | return 0; |
---|
310 | } |
---|
311 | |
---|
312 | //------------------------------------------------------------------- |
---|
313 | // map serverÖÌÊM |
---|
314 | |
---|
315 | // p?eBì¬ÂÛ |
---|
316 | int mapif_party_created(int fd,int account_id, int char_id, struct party *p) |
---|
317 | { |
---|
318 | WFIFOHEAD(fd, 39); |
---|
319 | WFIFOW(fd,0) = 0x3820; |
---|
320 | WFIFOL(fd,2) = account_id; |
---|
321 | WFIFOL(fd,6) = char_id; |
---|
322 | if (p != NULL) { |
---|
323 | WFIFOB(fd,10) = 0; |
---|
324 | WFIFOL(fd,11) = p->party_id; |
---|
325 | memcpy(WFIFOP(fd,15), p->name, NAME_LENGTH); |
---|
326 | ShowInfo("Created party (%d - %s)\n", p->party_id, p->name); |
---|
327 | } else { |
---|
328 | WFIFOB(fd,10) = 1; |
---|
329 | WFIFOL(fd,11) = 0; |
---|
330 | memset(WFIFOP(fd,15), 0, NAME_LENGTH); |
---|
331 | } |
---|
332 | WFIFOSET(fd,39); |
---|
333 | return 0; |
---|
334 | } |
---|
335 | |
---|
336 | // p?eBîñ©Â©çž |
---|
337 | int mapif_party_noinfo(int fd, int party_id) { |
---|
338 | WFIFOHEAD(fd, 8); |
---|
339 | WFIFOW(fd,0) = 0x3821; |
---|
340 | WFIFOW(fd,2) = 8; |
---|
341 | WFIFOL(fd,4) = party_id; |
---|
342 | WFIFOSET(fd,8); |
---|
343 | ShowWarning("int_party: info not found %d\n", party_id); |
---|
344 | |
---|
345 | return 0; |
---|
346 | } |
---|
347 | |
---|
348 | // p?eBîñÜÆßè |
---|
349 | int mapif_party_info(int fd, struct party *p) { |
---|
350 | unsigned char buf[2048]; |
---|
351 | |
---|
352 | WBUFW(buf,0) = 0x3821; |
---|
353 | memcpy(buf + 4, p, sizeof(struct party)); |
---|
354 | WBUFW(buf,2) = 4 + sizeof(struct party); |
---|
355 | if (fd < 0) |
---|
356 | mapif_sendall(buf, WBUFW(buf,2)); |
---|
357 | else |
---|
358 | mapif_send(fd, buf, WBUFW(buf,2)); |
---|
359 | return 0; |
---|
360 | } |
---|
361 | |
---|
362 | // p?eBoÇÁÂÛ |
---|
363 | int mapif_party_memberadded(int fd, int party_id, int account_id, int char_id, int flag) { |
---|
364 | WFIFOHEAD(fd, 15); |
---|
365 | WFIFOW(fd,0) = 0x3822; |
---|
366 | WFIFOL(fd,2) = party_id; |
---|
367 | WFIFOL(fd,6) = account_id; |
---|
368 | WFIFOL(fd,10) = char_id; |
---|
369 | WFIFOB(fd,14) = flag; |
---|
370 | WFIFOSET(fd,15); |
---|
371 | |
---|
372 | return 0; |
---|
373 | } |
---|
374 | |
---|
375 | // p?eBÝè?XÊm |
---|
376 | int mapif_party_optionchanged(int fd,struct party *p, int account_id, int flag) { |
---|
377 | unsigned char buf[15]; |
---|
378 | |
---|
379 | WBUFW(buf,0) = 0x3823; |
---|
380 | WBUFL(buf,2) = p->party_id; |
---|
381 | WBUFL(buf,6) = account_id; |
---|
382 | WBUFW(buf,10) = p->exp; |
---|
383 | WBUFW(buf,12) = p->item; |
---|
384 | WBUFB(buf,14) = flag; |
---|
385 | if (flag == 0) |
---|
386 | mapif_sendall(buf, 15); |
---|
387 | else |
---|
388 | mapif_send(fd, buf, 15); |
---|
389 | return 0; |
---|
390 | } |
---|
391 | |
---|
392 | // p?eB?ÞÊm |
---|
393 | int mapif_party_leaved(int party_id,int account_id, int char_id) { |
---|
394 | unsigned char buf[16]; |
---|
395 | |
---|
396 | WBUFW(buf,0) = 0x3824; |
---|
397 | WBUFL(buf,2) = party_id; |
---|
398 | WBUFL(buf,6) = account_id; |
---|
399 | WBUFL(buf,10) = char_id; |
---|
400 | mapif_sendall(buf, 14); |
---|
401 | return 0; |
---|
402 | } |
---|
403 | |
---|
404 | // p?eB}bvXVÊm |
---|
405 | int mapif_party_membermoved(struct party *p, int idx) { |
---|
406 | unsigned char buf[20]; |
---|
407 | |
---|
408 | WBUFW(buf,0) = 0x3825; |
---|
409 | WBUFL(buf,2) = p->party_id; |
---|
410 | WBUFL(buf,6) = p->member[idx].account_id; |
---|
411 | WBUFL(buf,10) = p->member[idx].char_id; |
---|
412 | WBUFW(buf,14) = p->member[idx].map; |
---|
413 | WBUFB(buf,16) = p->member[idx].online; |
---|
414 | WBUFW(buf,17) = p->member[idx].lv; |
---|
415 | mapif_sendall(buf, 19); |
---|
416 | return 0; |
---|
417 | } |
---|
418 | |
---|
419 | // p?eBðUÊm |
---|
420 | int mapif_party_broken(int party_id, int flag) { |
---|
421 | unsigned char buf[7]; |
---|
422 | WBUFW(buf,0) = 0x3826; |
---|
423 | WBUFL(buf,2) = party_id; |
---|
424 | WBUFB(buf,6) = flag; |
---|
425 | mapif_sendall(buf, 7); |
---|
426 | ShowInfo("Party broken (%d)\n", party_id); |
---|
427 | |
---|
428 | return 0; |
---|
429 | } |
---|
430 | |
---|
431 | // p?eB??Ÿ |
---|
432 | int mapif_party_message(int party_id, int account_id, char *mes, int len, int sfd) { |
---|
433 | unsigned char buf[2048]; |
---|
434 | |
---|
435 | WBUFW(buf,0) = 0x3827; |
---|
436 | WBUFW(buf,2) = len + 12; |
---|
437 | WBUFL(buf,4) = party_id; |
---|
438 | WBUFL(buf,8) = account_id; |
---|
439 | memcpy(WBUFP(buf,12), mes, len); |
---|
440 | mapif_sendallwos(sfd, buf,len + 12); |
---|
441 | |
---|
442 | return 0; |
---|
443 | } |
---|
444 | |
---|
445 | //------------------------------------------------------------------- |
---|
446 | // map server©çÌÊM |
---|
447 | |
---|
448 | |
---|
449 | // p?eB |
---|
450 | int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct party_member *leader) |
---|
451 | { |
---|
452 | struct party_data *p; |
---|
453 | int i; |
---|
454 | |
---|
455 | //FIXME: this should be removed once the savefiles can handle all symbols |
---|
456 | for(i = 0; i < NAME_LENGTH && name[i]; i++) { |
---|
457 | if (!(name[i] & 0xe0) || name[i] == 0x7f) { |
---|
458 | ShowInfo("int_party: illegal party name [%s]\n", name); |
---|
459 | mapif_party_created(fd, leader->account_id, leader->char_id, NULL); |
---|
460 | return 0; |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | if ((p = search_partyname(name)) != NULL) { |
---|
465 | ShowInfo("int_party: same name party exists [%s]\n", name); |
---|
466 | mapif_party_created(fd, leader->account_id, leader->char_id, NULL); |
---|
467 | return 0; |
---|
468 | } |
---|
469 | |
---|
470 | // Check Authorised letters/symbols in the name of the character |
---|
471 | if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorised |
---|
472 | for (i = 0; i < NAME_LENGTH && name[i]; i++) |
---|
473 | if (strchr(char_name_letters, name[i]) == NULL) { |
---|
474 | mapif_party_created(fd, leader->account_id, leader->char_id, NULL); |
---|
475 | return 0; |
---|
476 | } |
---|
477 | } else if (char_name_option == 2) { // letters/symbols in char_name_letters are forbidden |
---|
478 | for (i = 0; i < NAME_LENGTH && name[i]; i++) |
---|
479 | if (strchr(char_name_letters, name[i]) != NULL) { |
---|
480 | mapif_party_created(fd, leader->account_id, leader->char_id, NULL); |
---|
481 | return 0; |
---|
482 | } |
---|
483 | } |
---|
484 | |
---|
485 | p = (struct party_data *) aCalloc(sizeof(struct party_data), 1); |
---|
486 | if (p == NULL) { |
---|
487 | ShowFatalError("int_party: out of memory !\n"); |
---|
488 | mapif_party_created(fd,leader->account_id,leader->char_id,NULL); |
---|
489 | return 0; |
---|
490 | } |
---|
491 | p->party.party_id = party_newid++; |
---|
492 | memcpy(p->party.name, name, NAME_LENGTH); |
---|
493 | p->party.exp = 0; |
---|
494 | p->party.item=(item?1:0)|(item2?2:0); |
---|
495 | memcpy(&p->party.member[0], leader, sizeof(struct party_member)); |
---|
496 | p->party.member[0].leader = 1; |
---|
497 | int_party_calc_state(p); |
---|
498 | idb_put(party_db, p->party.party_id, p); |
---|
499 | |
---|
500 | mapif_party_created(fd, leader->account_id, leader->char_id, &p->party); |
---|
501 | mapif_party_info(fd, &p->party); |
---|
502 | |
---|
503 | return 0; |
---|
504 | } |
---|
505 | |
---|
506 | // p?eBîñv |
---|
507 | int mapif_parse_PartyInfo(int fd, int party_id) |
---|
508 | { |
---|
509 | struct party_data *p; |
---|
510 | |
---|
511 | p = (struct party_data*)idb_get(party_db, party_id); |
---|
512 | if (p != NULL) |
---|
513 | mapif_party_info(fd, &p->party); |
---|
514 | else { |
---|
515 | mapif_party_noinfo(fd, party_id); |
---|
516 | char_clearparty(party_id); |
---|
517 | } |
---|
518 | |
---|
519 | return 0; |
---|
520 | } |
---|
521 | |
---|
522 | // p[eBÇÁv |
---|
523 | int mapif_parse_PartyAddMember(int fd, int party_id, struct party_member *member) |
---|
524 | { |
---|
525 | struct party_data *p; |
---|
526 | int i; |
---|
527 | |
---|
528 | p = (struct party_data*)idb_get(party_db, party_id); |
---|
529 | if( p == NULL || p->size == MAX_PARTY ) { |
---|
530 | mapif_party_memberadded(fd, party_id, member->account_id, member->char_id, 1); |
---|
531 | return 0; |
---|
532 | } |
---|
533 | |
---|
534 | ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == 0 ); |
---|
535 | if( i == MAX_PARTY ) |
---|
536 | {// Party full |
---|
537 | mapif_party_memberadded(fd, party_id, member->account_id, member->char_id, 1); |
---|
538 | return 0; |
---|
539 | } |
---|
540 | |
---|
541 | memcpy(&p->party.member[i], member, sizeof(struct party_member)); |
---|
542 | p->party.member[i].leader = 0; |
---|
543 | if (p->party.member[i].online) p->party.count++; |
---|
544 | p->size++; |
---|
545 | if (p->size == 3) //Check family state. |
---|
546 | int_party_calc_state(p); |
---|
547 | else //Check even share range. |
---|
548 | if (member->lv < p->min_lv || member->lv > p->max_lv || p->family) { |
---|
549 | if (p->family) p->family = 0; //Family state broken. |
---|
550 | int_party_check_lv(p); |
---|
551 | } |
---|
552 | |
---|
553 | mapif_party_memberadded(fd, party_id, member->account_id, member->char_id, 0); |
---|
554 | mapif_party_info(-1, &p->party); |
---|
555 | |
---|
556 | return 0; |
---|
557 | } |
---|
558 | |
---|
559 | // p?eB?Ýè?Xv |
---|
560 | int mapif_parse_PartyChangeOption(int fd, int party_id, int account_id, int exp, int item) |
---|
561 | { |
---|
562 | struct party_data *p; |
---|
563 | int flag = 0; |
---|
564 | |
---|
565 | p = (struct party_data*)idb_get(party_db, party_id); |
---|
566 | if (p == NULL) |
---|
567 | return 0; |
---|
568 | |
---|
569 | p->party.exp = exp; |
---|
570 | if (exp>0 && !party_check_exp_share(p)) { |
---|
571 | flag |= 0x01; |
---|
572 | p->party.exp = 0; |
---|
573 | } |
---|
574 | p->party.item = item&0x3; |
---|
575 | mapif_party_optionchanged(fd, &p->party, account_id, flag); |
---|
576 | return 0; |
---|
577 | } |
---|
578 | |
---|
579 | // p?eB?Þv |
---|
580 | int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id) |
---|
581 | { |
---|
582 | struct party_data *p; |
---|
583 | int i,lv; |
---|
584 | |
---|
585 | p = (struct party_data*)idb_get(party_db, party_id); |
---|
586 | if (!p) return 0; |
---|
587 | |
---|
588 | for(i = 0; i < MAX_PARTY; i++) { |
---|
589 | if(p->party.member[i].account_id == account_id && |
---|
590 | p->party.member[i].char_id == char_id) |
---|
591 | { |
---|
592 | mapif_party_leaved(party_id, account_id, char_id); |
---|
593 | lv = p->party.member[i].lv; |
---|
594 | if(p->party.member[i].online) p->party.count--; |
---|
595 | memset(&p->party.member[i], 0, sizeof(struct party_member)); |
---|
596 | p->size--; |
---|
597 | if (lv == p->min_lv || lv == p->max_lv || p->family) |
---|
598 | { |
---|
599 | if(p->family) p->family = 0; //Family state broken. |
---|
600 | int_party_check_lv(p); |
---|
601 | } |
---|
602 | if (party_check_empty(&p->party) == 0) |
---|
603 | mapif_party_info(-1, &p->party); |
---|
604 | return 0; |
---|
605 | } |
---|
606 | } |
---|
607 | return 0; |
---|
608 | } |
---|
609 | |
---|
610 | int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id, unsigned short map, int online, unsigned int lv) |
---|
611 | { |
---|
612 | struct party_data *p; |
---|
613 | int i; |
---|
614 | |
---|
615 | p = (struct party_data*)idb_get(party_db, party_id); |
---|
616 | if (p == NULL) |
---|
617 | return 0; |
---|
618 | |
---|
619 | for(i = 0; i < MAX_PARTY && |
---|
620 | (p->party.member[i].account_id != account_id || |
---|
621 | p->party.member[i].char_id != char_id); i++); |
---|
622 | |
---|
623 | if (i == MAX_PARTY) return 0; |
---|
624 | |
---|
625 | if (p->party.member[i].online != online) |
---|
626 | { |
---|
627 | p->party.member[i].online = online; |
---|
628 | if (online) |
---|
629 | p->party.count++; |
---|
630 | else |
---|
631 | p->party.count--; |
---|
632 | // Even share check situations: Family state (always breaks) |
---|
633 | // character logging on/off is max/min level (update level range) |
---|
634 | // or character logging on/off has a different level (update level range using new level) |
---|
635 | if (p->family || |
---|
636 | (p->party.member[i].lv <= p->min_lv || p->party.member[i].lv >= p->max_lv) || |
---|
637 | (p->party.member[i].lv != lv && (lv <= p->min_lv || lv >= p->max_lv)) |
---|
638 | ) |
---|
639 | { |
---|
640 | p->party.member[i].lv = lv; |
---|
641 | int_party_check_lv(p); |
---|
642 | } |
---|
643 | //Send online/offline update. |
---|
644 | mapif_party_membermoved(&p->party, i); |
---|
645 | } |
---|
646 | if (p->party.member[i].lv != lv) { |
---|
647 | if(p->party.member[i].lv == p->min_lv || |
---|
648 | p->party.member[i].lv == p->max_lv) |
---|
649 | { |
---|
650 | p->party.member[i].lv = lv; |
---|
651 | int_party_check_lv(p); |
---|
652 | } else |
---|
653 | p->party.member[i].lv = lv; |
---|
654 | //There is no need to send level update to map servers |
---|
655 | //since they do nothing with it. |
---|
656 | } |
---|
657 | if (p->party.member[i].map != map) { |
---|
658 | p->party.member[i].map = map; |
---|
659 | mapif_party_membermoved(&p->party, i); |
---|
660 | } |
---|
661 | return 0; |
---|
662 | } |
---|
663 | |
---|
664 | // p?eBðUv |
---|
665 | int mapif_parse_BreakParty(int fd, int party_id) { |
---|
666 | |
---|
667 | idb_remove(party_db, party_id); |
---|
668 | mapif_party_broken(fd, party_id); |
---|
669 | |
---|
670 | return 0; |
---|
671 | } |
---|
672 | |
---|
673 | // p?eBbZ?WM |
---|
674 | int mapif_parse_PartyMessage(int fd, int party_id, int account_id, char *mes, int len) { |
---|
675 | return mapif_party_message(party_id, account_id, mes, len, fd); |
---|
676 | } |
---|
677 | // p?eB`FbNv |
---|
678 | int mapif_parse_PartyCheck(int fd, int party_id, int account_id, int char_id) { |
---|
679 | return party_check_conflict(party_id, account_id, char_id); |
---|
680 | } |
---|
681 | |
---|
682 | int mapif_parse_PartyLeaderChange(int fd,int party_id,int account_id,int char_id) |
---|
683 | { |
---|
684 | struct party_data *p; |
---|
685 | int i; |
---|
686 | |
---|
687 | p = (struct party_data*)idb_get(party_db, party_id); |
---|
688 | if (p == NULL) |
---|
689 | return 0; |
---|
690 | |
---|
691 | for (i = 0; i < MAX_PARTY; i++) |
---|
692 | { |
---|
693 | if(p->party.member[i].leader) |
---|
694 | p->party.member[i].leader = 0; |
---|
695 | if(p->party.member[i].account_id == account_id && |
---|
696 | p->party.member[i].char_id == char_id) |
---|
697 | p->party.member[i].leader = 1; |
---|
698 | } |
---|
699 | return 1; |
---|
700 | } |
---|
701 | |
---|
702 | // map server ©çÌÊM |
---|
703 | // ?PpPbgÌÝðÍ·é±Æ |
---|
704 | // ?pPbg·f?^Íinter.cÉZbgµÄ𱯠|
---|
705 | // ?pPbg·`FbNâARFIFOSKIPÍÄÑoµ³ÅsíêéÌÅsÁÄÍÈçÈ¢ |
---|
706 | // ?G?Èç0(false)A»€ÅÈ¢Èç1(true)𩊳ȯêÎÈçÈ¢ |
---|
707 | int inter_party_parse_frommap(int fd) { |
---|
708 | RFIFOHEAD(fd); |
---|
709 | switch(RFIFOW(fd,0)) { |
---|
710 | case 0x3020: mapif_parse_CreateParty(fd, (char*)RFIFOP(fd,4), RFIFOB(fd,28), RFIFOB(fd,29), (struct party_member*)RFIFOP(fd,30)); break; |
---|
711 | case 0x3021: mapif_parse_PartyInfo(fd, RFIFOL(fd,2)); break; |
---|
712 | case 0x3022: mapif_parse_PartyAddMember(fd, RFIFOL(fd,4), (struct party_member*)RFIFOP(fd,8)); break; |
---|
713 | case 0x3023: mapif_parse_PartyChangeOption(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOW(fd,10), RFIFOW(fd,12)); break; |
---|
714 | case 0x3024: mapif_parse_PartyLeave(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; |
---|
715 | case 0x3025: mapif_parse_PartyChangeMap(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOW(fd,14), RFIFOB(fd,16), RFIFOW(fd,17)); break; |
---|
716 | case 0x3026: mapif_parse_BreakParty(fd, RFIFOL(fd,2)); break; |
---|
717 | case 0x3027: mapif_parse_PartyMessage(fd, RFIFOL(fd,4), RFIFOL(fd,8), (char*)RFIFOP(fd,12), RFIFOW(fd,2)-12); break; |
---|
718 | case 0x3028: mapif_parse_PartyCheck(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; |
---|
719 | case 0x3029: mapif_parse_PartyLeaderChange(fd, RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); break; |
---|
720 | default: |
---|
721 | return 0; |
---|
722 | } |
---|
723 | |
---|
724 | return 1; |
---|
725 | } |
---|
726 | |
---|
727 | // T?o?©ç?ÞviLípj |
---|
728 | int inter_party_leave(int party_id, int account_id, int char_id) { |
---|
729 | return mapif_parse_PartyLeave(-1, party_id, account_id, char_id); |
---|
730 | } |
---|
731 | #endif //TXT_SQL_CONVERT |
---|