diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 2 | ||||
-rw-r--r-- | src/map/chrif.c | 411 | ||||
-rw-r--r-- | src/map/chrif.h | 2 | ||||
-rw-r--r-- | src/map/clif.c | 92 | ||||
-rw-r--r-- | src/map/itemdb.h | 2 | ||||
-rw-r--r-- | src/map/map.c | 16 | ||||
-rw-r--r-- | src/map/map.h | 2 | ||||
-rw-r--r-- | src/map/mob.c | 4 | ||||
-rw-r--r-- | src/map/party.c | 48 | ||||
-rw-r--r-- | src/map/pc.c | 7 | ||||
-rw-r--r-- | src/map/script.c | 25 | ||||
-rw-r--r-- | src/map/skill.c | 2 | ||||
-rw-r--r-- | src/map/storage.h | 4 |
13 files changed, 239 insertions, 378 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index c0741a6ea..63d933538 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8358,7 +8358,7 @@ int atcommand_makehomun(const int fd, struct map_session_data* sd, const char* c /*========================================== * modify homunculus intimacy [orn] - *------------------------------------------o */ + *------------------------------------------*/ int atcommand_homfriendly(const int fd, struct map_session_data* sd, const char* command, const char* message) { int friendly = 0; diff --git a/src/map/chrif.c b/src/map/chrif.c index d6f3dea04..128966a91 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -30,7 +30,7 @@ static const int packet_len_table[0x3d] = { // U - used, F - free 60, 3,-1,27,10,-1, 6,-1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff 6,-1,18, 7,-1,49,30,10, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, U->2b07 6,30,-1,10,86, 7,44,34, // 2b08-2b0f: U->2b08, U->2b09, U->2b0a, U->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f - 0,-1,10, 6,11,-1, 0, 0, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17 + 11,-1,10, 6,11,-1, 0,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17 -1,-1,-1,-1,-1,-1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f -1,10, 8,-1,-1,-1,-1,-1, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, F->2b24, F->2b25, F->2b26, F->2b27 }; @@ -97,7 +97,7 @@ int other_mapserver_count=0; //Holds count of how many other map servers are onl //Interval at which map server sends number of connected users. [Skotlex] #define UPDATE_INTERVAL 10000 //This define should spare writing the check in every function. [Skotlex] -#define chrif_check(a) { if(!chrif_isconnect()) return a; } +#define chrif_check(a) { if(!chrif_isconnected()) return a; } // sets char-server's user id @@ -147,7 +147,7 @@ void chrif_setport(uint16 port) } // says whether the char-server is connected or not -int chrif_isconnect(void) +int chrif_isconnected(void) { return (char_fd > 0 && session[char_fd] != NULL && chrif_state == 2); } @@ -163,7 +163,8 @@ int chrif_save(struct map_session_data *sd, int flag) if (!flag) //The flag check is needed to prevent 'nosave' taking effect when a jailed player logs out. pc_makesavestatus(sd); - if(!chrif_isconnect()) + + if(!chrif_isconnected()) { if (flag) sd->state.finalsave = 1; //Will save character on reconnect. return -1; @@ -238,10 +239,9 @@ int chrif_sendmap(int fd) int chrif_recvmap(int fd) { int i, j; - uint32 ip; - uint16 port; - ip = ntohl(RFIFOL(fd,4)); - port = ntohs(RFIFOW(fd,8)); + uint32 ip = ntohl(RFIFOL(fd,4)); + uint16 port = ntohs(RFIFOW(fd,8)); + for(i = 10, j = 0; i < RFIFOW(fd,2); i += 4, j++) { map_setipport(RFIFOW(fd,i), ip, port); } @@ -256,15 +256,11 @@ int chrif_recvmap(int fd) int chrif_removemap(int fd) { int i, j; - uint32 ip; - uint16 port; + uint32 ip = RFIFOL(fd,4); + uint16 port = RFIFOW(fd,8); - ip = RFIFOL(fd, 4); - port = RFIFOW(fd, 8); - - for(i = 10, j = 0; i < RFIFOW(fd, 2); i += 4, j++){ + for(i = 10, j = 0; i < RFIFOW(fd, 2); i += 4, j++) map_eraseipport(RFIFOW(fd, i), ip, port); - } other_mapserver_count--; if(battle_config.etc_log) @@ -284,10 +280,8 @@ int chrif_save_ack(int fd) } // request to move a character between mapservers -int chrif_changemapserver(struct map_session_data *sd, short map, int x, int y, uint32 ip, uint16 port) +int chrif_changemapserver(struct map_session_data* sd, short map, int x, int y, uint32 ip, uint16 port) { - uint32 s_ip; - nullpo_retr(-1, sd); chrif_check(-1); @@ -298,11 +292,6 @@ int chrif_changemapserver(struct map_session_data *sd, short map, int x, int y, return -1; } - if (sd->fd && sd->fd < fd_max && session[sd->fd]) - s_ip = session[sd->fd]->client_addr; - else //Not connected? Can't retrieve IP - s_ip = 0; - WFIFOHEAD(char_fd,35); WFIFOW(char_fd, 0) = 0x2b05; WFIFOL(char_fd, 2) = sd->bl.id; @@ -315,7 +304,7 @@ int chrif_changemapserver(struct map_session_data *sd, short map, int x, int y, WFIFOL(char_fd,24) = htonl(ip); WFIFOW(char_fd,28) = htons(port); WFIFOB(char_fd,30) = sd->status.sex; - WFIFOL(char_fd,31) = htonl(s_ip); // not used + WFIFOL(char_fd,31) = 0; // sd's IP, not used anymore WFIFOSET(char_fd,35); return 0; @@ -337,6 +326,7 @@ int chrif_changemapserverack(int fd) clif_authfail_fd(sd->fd, 0); return 0; } + sprintf(mapname, "%s.gat", mapindex_id2name(RFIFOW(fd,18))); clif_changemapserver(sd, mapname, RFIFOW(fd,20), RFIFOW(fd,22), ntohl(RFIFOL(fd,24)), ntohs(RFIFOW(fd,28))); @@ -380,6 +370,7 @@ int chrif_sendmapack(int fd) ShowFatalError("chrif : send map list to char server failed %d\n", RFIFOB(fd,2)); exit(1); } + memcpy(wisp_server_name, RFIFOP(fd,3), NAME_LENGTH); ShowStatus("Map sending complete. Map Server is now online.\n"); chrif_state = 2; @@ -646,14 +637,10 @@ int chrif_changesex(int id, int sex) } /*========================================== - * Answer after a request about a character name to do some operations (by Yor) - * Used to answer of chrif_char_ask_name. + * R 2b0f <accid>.l <name>.24B <type>.w <answer>.w + * Reply to chrif_char_ask_name() (request to do some character operation) * type of operation: - * 1: block - * 2: ban - * 3: unblock - * 4: unban - * 5: changesex + * 1: block, 2: ban, 3: unblock, 4: unban, 5: changesex * type of answer: * 0: login-server request done * 1: player not found @@ -662,100 +649,43 @@ int chrif_changesex(int id, int sex) *------------------------------------------*/ int chrif_char_ask_name_answer(int fd) { - int acc; - struct map_session_data *sd; + struct map_session_data* sd; + char* action; char output[256]; - char player_name[NAME_LENGTH]; - - acc = RFIFOL(fd,2); // account_id of who has asked (-1 if nobody) - memcpy(player_name, RFIFOP(fd,6), NAME_LENGTH); - player_name[NAME_LENGTH-1] = '\0'; - + int acc = RFIFOL(fd,2); // account_id of who has asked (-1 if nobody) + char* player_name = (char*)RFIFOP(fd,6); + uint16 type; + uint16 answer; + + type = RFIFOW(fd,30); + answer = RFIFOW(fd,32); + sd = map_id2sd(acc); - if (acc >= 0 && sd != NULL) { - if (RFIFOW(fd, 32) == 1) // player not found - sprintf(output, "The player '%s' doesn't exist.", player_name); - else { - switch(RFIFOW(fd, 30)) { - case 1: // block - switch(RFIFOW(fd, 32)) { - case 0: // login-server request done - sprintf(output, "Login-server has been asked to block the player '%s'.", player_name); - break; - //case 1: // player not found - case 2: // gm level too low - sprintf(output, "Your GM level don't authorise you to block the player '%s'.", player_name); - break; - case 3: // login-server offline - sprintf(output, "Login-server is offline. Impossible to block the the player '%s'.", player_name); - break; - } - break; - case 2: // ban - switch(RFIFOW(fd, 32)) { - case 0: // login-server request done - sprintf(output, "Login-server has been asked to ban the player '%s'.", player_name); - break; - //case 1: // player not found - case 2: // gm level too low - sprintf(output, "Your GM level don't authorise you to ban the player '%s'.", player_name); - break; - case 3: // login-server offline - sprintf(output, "Login-server is offline. Impossible to ban the the player '%s'.", player_name); - break; - } - break; - case 3: // unblock - switch(RFIFOW(fd, 32)) { - case 0: // login-server request done - sprintf(output, "Login-server has been asked to unblock the player '%s'.", player_name); - break; - //case 1: // player not found - case 2: // gm level too low - sprintf(output, "Your GM level don't authorise you to unblock the player '%s'.", player_name); - break; - case 3: // login-server offline - sprintf(output, "Login-server is offline. Impossible to unblock the the player '%s'.", player_name); - break; - } - break; - case 4: // unban - switch(RFIFOW(fd, 32)) { - case 0: // login-server request done - sprintf(output, "Login-server has been asked to unban the player '%s'.", player_name); - break; - //case 1: // player not found - case 2: // gm level too low - sprintf(output, "Your GM level don't authorise you to unban the player '%s'.", player_name); - break; - case 3: // login-server offline - sprintf(output, "Login-server is offline. Impossible to unban the the player '%s'.", player_name); - break; - } - break; - case 5: // changesex - switch(RFIFOW(fd, 32)) { - case 0: // login-server request done - sprintf(output, "Login-server has been asked to change the sex of the player '%s'.", player_name); - break; - //case 1: // player not found - case 2: // gm level too low - sprintf(output, "Your GM level don't authorise you to change the sex of the player '%s'.", player_name); - break; - case 3: // login-server offline - sprintf(output, "Login-server is offline. Impossible to change the sex of the the player '%s'.", player_name); - break; - } - break; - } - } - if (output[0] != '\0') { - output[sizeof(output)-1] = '\0'; - clif_displaymessage(sd->fd, output); - } - } else + if (acc < 0 || sd == NULL) { ShowError("chrif_char_ask_name_answer failed - player not online.\n"); + return 0; + } + switch(type) + { + case 1: action = "block"; break; + case 2: action = "ban"; break; + case 3: action = "unblock"; break; + case 4: action = "unban"; break; + case 5: action = "change the sex of"; break; + default: action = "???"; break; + } + + switch(answer) + { + case 0: sprintf(output, "Login-server has been asked to %s the player '%20s'.", action, player_name); break; + case 1: sprintf(output, "The player '%20s' doesn't exist.", player_name); break; + case 2: sprintf(output, "Your GM level don't authorise you to %s the player '%20s'.", action, player_name); break; + case 3: sprintf(output, "Login-server is offline. Impossible to %s the player '%20s'.", action, player_name); break; + default: output[0] = '\0'; break; + } + + clif_displaymessage(sd->fd, output); return 0; } @@ -859,22 +789,19 @@ int chrif_changedsex(int fd) *------------------------------------------*/ int chrif_divorce(int char_id, int partner_id) { - struct map_session_data *sd = NULL; + struct map_session_data* sd; + int i; - if (!char_id || !partner_id) + if (!char_id || !partner_id || (sd = map_charid2sd(partner_id)) == NULL || sd->status.partner_id != char_id) return 0; - nullpo_retr(0, sd = map_charid2sd(partner_id)); - if (sd->status.partner_id == char_id) { - int i; - //離婚(相方は既にキャラが消えている筈なので) - sd->status.partner_id = 0; + //離婚(相方は既にキャラが消えている筈なので) + sd->status.partner_id = 0; - //相方の結婚指輪を剥奪 - for(i = 0; i < MAX_INVENTORY; i++) - if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F) - pc_delitem(sd, i, 1, 0); - } + //相方の結婚指輪を剥奪 + for(i = 0; i < MAX_INVENTORY; i++) + if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F) + pc_delitem(sd, i, 1, 0); return 0; } @@ -917,60 +844,40 @@ int chrif_accountban(int fd) if (battle_config.etc_log) ShowNotice("chrif_accountban %d.\n", acc); sd = map_id2sd(acc); - if (acc > 0) { - if (sd != NULL) { - sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters - if (RFIFOB(fd,6) == 0) { // 0: change of statut, 1: ban - switch (RFIFOL(fd,7)) { // status or final date of a banishment - case 1: // 0 = Unregistered ID - clif_displaymessage(sd->fd, "Your account has 'Unregistered'."); - break; - case 2: // 1 = Incorrect Password - clif_displaymessage(sd->fd, "Your account has an 'Incorrect Password'..."); - break; - case 3: // 2 = This ID is expired - clif_displaymessage(sd->fd, "Your account has expired."); - break; - case 4: // 3 = Rejected from Server - clif_displaymessage(sd->fd, "Your account has been rejected from server."); - break; - case 5: // 4 = You have been blocked by the GM Team - clif_displaymessage(sd->fd, "Your account has been blocked by the GM Team."); - break; - case 6: // 5 = Your Game's EXE file is not the latest version - clif_displaymessage(sd->fd, "Your Game's EXE file is not the latest version."); - break; - case 7: // 6 = Your are Prohibited to log in until %s - clif_displaymessage(sd->fd, "Your account has been prohibited to log in."); - break; - case 8: // 7 = Server is jammed due to over populated - clif_displaymessage(sd->fd, "Server is jammed due to over populated."); - break; - case 9: // 8 = No MSG (actually, all states after 9 except 99 are No MSG, use only this) - clif_displaymessage(sd->fd, "Your account has not more authorised."); - break; - case 100: // 99 = This ID has been totally erased - clif_displaymessage(sd->fd, "Your account has been totally erased."); - break; - default: - clif_displaymessage(sd->fd, "Your account has not more authorised."); - break; - } - } else if (RFIFOB(fd,6) == 1) { // 0: change of statut, 1: ban - time_t timestamp; - char tmpstr[2048]; - timestamp = (time_t)RFIFOL(fd,7); // status or final date of a banishment - strcpy(tmpstr, "Your account has been banished until "); - strftime(tmpstr + strlen(tmpstr), 24, "%d-%m-%Y %H:%M:%S", localtime(×tamp)); - clif_displaymessage(sd->fd, tmpstr); - } - clif_setwaitclose(sd->fd); // forced to disconnect for the change + + if (acc < 0 || sd == NULL) { + ShowError("chrif_accountban failed - player not online.\n"); + return 0; + } + + sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters + if (RFIFOB(fd,6) == 0) // 0: change of statut, 1: ban + { + switch (RFIFOL(fd,7)) { // status or final date of a banishment + case 1: clif_displaymessage(sd->fd, "Your account has 'Unregistered'."); break; + case 2: clif_displaymessage(sd->fd, "Your account has an 'Incorrect Password'..."); break; + case 3: clif_displaymessage(sd->fd, "Your account has expired."); break; + case 4: clif_displaymessage(sd->fd, "Your account has been rejected from server."); break; + case 5: clif_displaymessage(sd->fd, "Your account has been blocked by the GM Team."); break; + case 6: clif_displaymessage(sd->fd, "Your Game's EXE file is not the latest version."); break; + case 7: clif_displaymessage(sd->fd, "Your account has been prohibited to log in."); break; + case 8: clif_displaymessage(sd->fd, "Server is jammed due to over populated."); break; + case 9: clif_displaymessage(sd->fd, "Your account has not more authorised."); break; + case 100: clif_displaymessage(sd->fd, "Your account has been totally erased."); break; + default: clif_displaymessage(sd->fd, "Your account has not more authorised."); break; } - } else { - if (sd != NULL) - ShowError("chrif_accountban failed - player not online.\n"); + } + else if (RFIFOB(fd,6) == 1) // 0: change of statut, 1: ban + { + time_t timestamp; + char tmpstr[2048]; + timestamp = (time_t)RFIFOL(fd,7); // status or final date of a banishment + strcpy(tmpstr, "Your account has been banished until "); + strftime(tmpstr + strlen(tmpstr), 24, "%d-%m-%Y %H:%M:%S", localtime(×tamp)); + clif_displaymessage(sd->fd, tmpstr); } + clif_setwaitclose(sd->fd); // forced to disconnect for the change return 0; } @@ -978,13 +885,11 @@ int chrif_accountban(int fd) //packet.w AID.L WHY.B 2+4+1 = 7byte int chrif_disconnectplayer(int fd) { - struct map_session_data *sd; + struct map_session_data* sd; sd = map_id2sd(RFIFOL(fd, 2)); - - if(sd == NULL){ + if(sd == NULL) return -1; - } if (!sd->fd) { //No connection @@ -995,27 +900,13 @@ int chrif_disconnectplayer(int fd) return 0; } - switch(RFIFOB(fd, 6)){ - //clif_authfail_fd - case 1: //server closed - clif_authfail_fd(sd->fd, 1); - break; - - case 2: //someone else logged in - clif_authfail_fd(sd->fd, 2); - break; - - case 3: //server overpopulated - clif_authfail_fd(sd->fd, 4); - break; - - case 4: //out of time payd for .. (avail) - clif_authfail_fd(sd->fd, 10); - break; - - case 5: //forced to dc by gm - clif_authfail_fd(sd->fd, 15); - break; + switch(RFIFOB(fd, 6)) + { + case 1: clif_authfail_fd(sd->fd, 1); break; //server closed + case 2: clif_authfail_fd(sd->fd, 2); break; //someone else logged in + case 3: clif_authfail_fd(sd->fd, 4); break; //server overpopulated + case 4: clif_authfail_fd(sd->fd, 10); break; //out of available time paid for + case 5: clif_authfail_fd(sd->fd, 15); break; //forced to dc by gm } return 0; } @@ -1047,26 +938,21 @@ int chrif_recvgmaccounts(int fd) * Request/Receive top 10 Fame character list *------------------------------------------*/ -int chrif_updatefamelist(struct map_session_data *sd) +int chrif_updatefamelist(struct map_session_data* sd) { char type; chrif_check(-1); - switch(sd->class_&MAPID_UPPERMASK) { - case MAPID_BLACKSMITH: - type = 1; - break; - case MAPID_ALCHEMIST: - type = 2; - break; - case MAPID_TAEKWON: - type = 3; - break; + switch(sd->class_ & MAPID_UPPERMASK) + { + case MAPID_BLACKSMITH: type = 1; break; + case MAPID_ALCHEMIST: type = 2; break; + case MAPID_TAEKWON: type = 3; break; default: return 0; } - WFIFOHEAD(char_fd, 12); + WFIFOHEAD(char_fd, 11); WFIFOW(char_fd,0) = 0x2b10; WFIFOL(char_fd,2) = sd->status.char_id; WFIFOL(char_fd,6) = sd->status.fame; @@ -1124,26 +1010,19 @@ int chrif_recvfamelist(int fd) int chrif_updatefamelist_ack(int fd) { - struct fame_list *list; - char index; - switch (RFIFOB(fd, 2)) + struct fame_list* list; + uint8 index; + switch (RFIFOB(fd,2)) { - case 1: - list = smith_fame_list; - break; - case 2: - list = chemist_fame_list; - break; - case 3: - list = taekwon_fame_list; - break; - default: - return 0; + case 1: list = smith_fame_list; break; + case 2: list = chemist_fame_list; break; + case 3: list = taekwon_fame_list; break; + default: return 0; } index = RFIFOB(fd, 3); if (index < 0 || index >= MAX_FAME_LIST) return 0; - list[(int)index].fame = RFIFOL(fd, 4); + list[index].fame = RFIFOL(fd,4); return 1; } @@ -1191,8 +1070,9 @@ int chrif_save_scdata(struct map_session_data *sd) return 0; } +//Retrieve and load sc_data for a player. [Skotlex] int chrif_load_scdata(int fd) -{ //Retrieve and load sc_data for a player. [Skotlex] +{ #ifdef ENABLE_SC_SAVING struct map_session_data *sd; struct status_change_data *data; @@ -1365,24 +1245,29 @@ void chrif_update_ip(int fd) int chrif_parse(int fd) { int packet_len, cmd; - // only char-server can have an access to here. - // so, if it isn't the char-server, we disconnect the session (fd != char_fd). - if (fd != char_fd || session[fd]->eof) { - if (fd == char_fd && chrif_connected == 1) { - chrif_disconnect (fd); - } - else if (fd != char_fd) - ShowDebug("chrif_parse: Disconnecting invalid session #%d (is not the char-server)\n", fd); + // only process data from the char-server + if (fd != char_fd) + { + ShowDebug("chrif_parse: Disconnecting invalid session #%d (is not the char-server)\n", fd); do_close(fd); return 0; } - while (RFIFOREST(fd) >= 2) { //Infinite loop on broken pipe fix. [Skotlex] - cmd = RFIFOW(fd,0); - if (cmd < 0x2af8 || cmd >= 0x2af8 + (sizeof(packet_len_table) / sizeof(packet_len_table[0])) || - packet_len_table[cmd-0x2af8] == 0) { + if (session[fd]->eof) + { + if (chrif_connected == 1) + chrif_disconnect(fd); + do_close(fd); + return 0; + } + + while (RFIFOREST(fd) >= 2) + { + cmd = RFIFOW(fd,0); + if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(packet_len_table) || packet_len_table[cmd-0x2af8] == 0) + { int r = intif_parse(fd); // intifに渡す if (r == 1) continue; // intifで処理した @@ -1392,16 +1277,20 @@ int chrif_parse(int fd) ShowWarning("chrif_parse: session #%d, intif_parse failed -> disconnected.\n", fd); return 0; } + packet_len = packet_len_table[cmd-0x2af8]; - if (packet_len == -1) { + if (packet_len == -1) + { // dynamic-length packet, second WORD holds the length if (RFIFOREST(fd) < 4) return 0; packet_len = RFIFOW(fd,2); } + if ((int)RFIFOREST(fd) < packet_len) return 0; - switch(cmd) { + switch(cmd) + { case 0x2af9: chrif_connectack(fd); break; case 0x2afb: chrif_sendmapack(fd); break; case 0x2afd: chrif_authok(fd); break; @@ -1425,7 +1314,6 @@ int chrif_parse(int fd) case 0x2b20: chrif_removemap(fd); break; case 0x2b21: chrif_save_ack(fd); break; case 0x2b22: chrif_updatefamelist_ack(fd); break; - default: if (battle_config.error_log) ShowError("chrif_parse : unknown packet (session #%d): 0x%x. Disconnecting.\n", fd, cmd); @@ -1492,11 +1380,14 @@ int send_users_tochar(int tid, unsigned int tick, int id, int data) int check_connect_char_server(int tid, unsigned int tick, int id, int data) { static int displayed = 0; - if (char_fd <= 0 || session[char_fd] == NULL) { - if (!displayed) { + if (char_fd <= 0 || session[char_fd] == NULL) + { + if (!displayed) + { ShowStatus("Attempting to connect to Char Server. Please wait.\n"); displayed = 1; } + chrif_state = 0; char_fd = make_connection(char_ip, char_port); if (char_fd == -1) @@ -1504,6 +1395,7 @@ int check_connect_char_server(int tid, unsigned int tick, int id, int data) char_fd = 0; return 0; } + session[char_fd]->func_parse = chrif_parse; realloc_fifo(char_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); @@ -1519,16 +1411,8 @@ int check_connect_char_server(int tid, unsigned int tick, int id, int data) srvinfo = 1; } #endif /* not TXT_ONLY */ -/* There is no need, the connection is TCP, so the packet is assured to arrive unless the connection dies [Skotlex] - //If for some reason the next iteration (10 secs) we are still not connected, - //assume the packets got lost, so we need to resend them. [Skotlex] - if (chrif_state == 0) - chrif_connect(char_fd); - else if (chrif_state == 1) - chrif_sendmap(char_fd); -*/ } - if (chrif_isconnect()) displayed = 0; + if (chrif_isconnected()) displayed = 0; return 0; } @@ -1560,6 +1444,7 @@ int do_init_chrif(void) add_timer_func_list(send_usercount_tochar, "send_usercount_tochar"); add_timer_func_list(send_users_tochar, "send_users_tochar"); add_timer_func_list(auth_db_cleanup, "auth_db_cleanup"); + add_timer_interval(gettick() + 1000, check_connect_char_server, 0, 0, 10 * 1000); #ifdef TXT_ONLY //Txt needs this more frequently because it is used for the online.html file. diff --git a/src/map/chrif.h b/src/map/chrif.h index 5f9b4d868..179772257 100644 --- a/src/map/chrif.h +++ b/src/map/chrif.h @@ -18,7 +18,7 @@ void chrif_checkdefaultlogin(void); int chrif_setip(const char* ip); void chrif_setport(uint16 port); -int chrif_isconnect(void); +int chrif_isconnected(void); extern int chrif_connected; extern int other_mapserver_count; diff --git a/src/map/clif.c b/src/map/clif.c index 7cb9fc096..b501d76d4 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -550,7 +550,7 @@ int clif_authok(struct map_session_data *sd) * 4 - server full -> MsgStringTable[264] * 5 - underaged -> MsgStringTable[305] * 9 - too many connections from this ip -> MsgStringTable[529] - * 10 - payed time has ended -> MsgStringTable[530] + * 10 - out of available time paid for -> MsgStringTable[530] * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579] * other - disconnected -> MsgStringTable[3] */ @@ -581,17 +581,14 @@ void clif_updatemaxid(int account_id, int char_id) *------------------------------------------*/ int clif_charselectok(int id) { - struct map_session_data *sd; + struct map_session_data* sd; int fd; - if ((sd = map_id2sd(id)) == NULL) - return 1; - - if (!sd->fd) + if ((sd = map_id2sd(id)) == NULL || !sd->fd) return 1; fd = sd->fd; - WFIFOHEAD(fd, packet_len(0xb3)); + WFIFOHEAD(fd,packet_len(0xb3)); WFIFOW(fd,0) = 0xb3; WFIFOB(fd,2) = 1; WFIFOSET(fd,packet_len(0xb3)); @@ -2809,18 +2806,18 @@ int clif_initialstatus(struct map_session_data *sd) buf=WFIFOP(fd,0); WBUFW(buf,0)=0xbd; - WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point; - WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str; + WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX); + WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX); WBUFB(buf,5)=pc_need_status_point(sd,SP_STR); - WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi; + WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX); WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI); - WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit; + WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX); WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT); - WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_; + WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX); WBUFB(buf,11)=pc_need_status_point(sd,SP_INT); - WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex; + WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX); WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX); - WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk; + WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX); WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK); WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk; @@ -3797,7 +3794,7 @@ int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick, WBUFW(buf,22)=damage?div:0; WBUFW(buf,27)=damage2?div:0; } else { - WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage; + WBUFW(buf,22)=min(damage, SHRT_MAX); WBUFW(buf,27)=damage2; } WBUFW(buf,24)=div; @@ -4457,7 +4454,7 @@ int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_ WBUFW(buf,0)=0x11a; WBUFW(buf,2)=skill_id; - WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal; + WBUFW(buf,4)=min(heal, SHRT_MAX); WBUFL(buf,6)=dst->id; WBUFL(buf,10)=src?src->id:0; WBUFB(buf,14)=fail; @@ -6734,42 +6731,43 @@ int clif_guild_emblem(struct map_session_data *sd,struct guild *g) WFIFOSET(fd,WFIFOW(fd,2)); return 0; } + /*========================================== - * ギルドスキル送信 + * Send guild skills *------------------------------------------*/ -int clif_guild_skillinfo(struct map_session_data *sd) +int clif_guild_skillinfo(struct map_session_data* sd) { int fd; - int i,id,c,up=1; - struct guild *g; + struct guild* g; + int i,c; nullpo_retr(0, sd); - fd=sd->fd; - g=guild_search(sd->status.guild_id); - if(g==NULL) + fd = sd->fd; + g = guild_search(sd->status.guild_id); + if(g == NULL) return 0; + WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6); - WFIFOW(fd,0)=0x0162; - WFIFOW(fd,4)=g->skill_point; - for(i=c=0;i<MAX_GUILDSKILL;i++){ - if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){ - WFIFOW(fd,c*37+ 6) = id = g->skill[i].id; + WFIFOW(fd,0) = 0x0162; + WFIFOW(fd,4) = g->skill_point; + for(i = 0, c = 0; i < MAX_GUILDSKILL; i++) + { + if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id)) + { + int id = g->skill[i].id; + WFIFOW(fd,c*37+ 6) = id; WFIFOW(fd,c*37+ 8) = skill_get_inf(id); WFIFOW(fd,c*37+10) = 0; WFIFOW(fd,c*37+12) = g->skill[i].lv; - WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv); - WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv); + WFIFOW(fd,c*37+14) = skill_get_sp(id, g->skill[i].lv); + WFIFOW(fd,c*37+16) = skill_get_range(id, g->skill[i].lv); strncpy((char*)WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH); - if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd)) - up = 1; - else - up = 0; - WFIFOB(fd,c*37+42)= up; + WFIFOB(fd,c*37+42)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0; c++; } } - WFIFOW(fd,2)=c*37+6; + WFIFOW(fd,2) = c*37 + 6; WFIFOSET(fd,WFIFOW(fd,2)); return 0; } @@ -6778,7 +6776,7 @@ int clif_guild_skillinfo(struct map_session_data *sd) * Sends guild notice to client * R 016f <str1z>.60B <str2z>.120B *------------------------------------------*/ -int clif_guild_notice(struct map_session_data *sd,struct guild *g) +int clif_guild_notice(struct map_session_data* sd, struct guild* g) { int fd; @@ -6787,17 +6785,16 @@ int clif_guild_notice(struct map_session_data *sd,struct guild *g) fd = sd->fd; - if ( !session_isActive(fd) ) //null pointer right here [Kevin] + if ( !session_isActive(fd) ) return 0; - if (fd <= 0) - return 0; - if(*g->mes1==0 && *g->mes2==0) + if(g->mes1[0] == '\0' && g->mes2[0] == '\0') return 0; + WFIFOHEAD(fd,packet_len(0x16f)); - WFIFOW(fd,0)=0x16f; - memcpy(WFIFOP(fd,2),g->mes1,60); - memcpy(WFIFOP(fd,62),g->mes2,120); + WFIFOW(fd,0) = 0x16f; + memcpy(WFIFOP(fd,2), g->mes1, 60); + memcpy(WFIFOP(fd,62), g->mes2, 120); WFIFOSET(fd,packet_len(0x16f)); return 0; } @@ -8960,6 +8957,7 @@ void clif_parse_TakeItem(int fd, struct map_session_data *sd) if (!pc_takeitem(sd, fitem)) break; + return; } while (0); // Client REQUIRES a fail packet or you can no longer pick items. @@ -11717,10 +11715,10 @@ static int packetdb_readdb(void) //#0x0240 -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10, 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //#0x0280 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0 }; struct { void (*func)(int, struct map_session_data *); diff --git a/src/map/itemdb.h b/src/map/itemdb.h index 68c4d9ed0..bb33d1e38 100644 --- a/src/map/itemdb.h +++ b/src/map/itemdb.h @@ -116,7 +116,7 @@ struct item_data { unsigned value_notoc : 1; short no_equip; unsigned no_refine : 1; // [celest] - unsigned delay_consume : 1; // Signifies items that are not consumed inmediately upon double-click [Skotlex] + unsigned delay_consume : 1; // Signifies items that are not consumed immediately upon double-click [Skotlex] unsigned trade_restriction : 7; //Item restrictions mask [Skotlex] unsigned autoequip: 1; } flag; diff --git a/src/map/map.c b/src/map/map.c index 51ff269b8..c7173dfdb 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -792,7 +792,7 @@ int map_foreachinarea(int (*func)(struct block_list*,va_list),int m,int x0,int y if (type&~BL_MOB) for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { - for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){ + for(bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { bl = map[m].block[bx+by*map[m].bxs]; c = map[m].block_count[bx+by*map[m].bxs]; for(i=0;i<c && bl;i++,bl=bl->next){ @@ -1597,19 +1597,19 @@ static void* create_charid2nick(DBKey key, va_list args) /*========================================== * charid_dbへ追加(返信待ちがあれば返信) *------------------------------------------*/ -void map_addchariddb(int charid, char *name) +void map_addchariddb(int charid, char* name) { - struct charid2nick *p; + struct charid2nick* p; int req = 0; - p = idb_ensure(charid_db,charid,create_charid2nick); + p = idb_ensure(charid_db, charid, create_charid2nick); req = p->req_id; p->req_id = 0; //We overwrite the nick anyway in case a different one arrived. memcpy(p->nick, name, NAME_LENGTH); if (req) { - struct map_session_data *sd = map_id2sd(req); + struct map_session_data* sd = map_id2sd(req); if (sd) clif_solved_charname(sd,charid); } } @@ -2775,8 +2775,8 @@ int map_config_read(char *cfgName) fp = fopen(cfgName,"r"); if (fp == NULL) { - ShowFatalError("Map configuration file not found at: %s\n", cfgName); - exit(1); + ShowError("Map configuration file not found at: %s\n", cfgName); + return 1; } while(fgets(line, sizeof(line), fp)) { @@ -3244,7 +3244,7 @@ static int map_abort_sub(DBKey key,void * data,va_list ap) void do_abort(void) { //Save all characters and then flush the inter-connection. - if (!chrif_isconnect()) + if (!chrif_isconnected()) { if (pc_db->size(pc_db)) ShowFatalError("Server has crashed without a connection to the char-server, character data can't be saved!\n"); diff --git a/src/map/map.h b/src/map/map.h index 32fea8239..b929880d8 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -496,7 +496,7 @@ struct party_member_data { struct party_data { struct party party; struct party_member_data data[MAX_PARTY]; - unsigned char itemc; //For item distribution. + uint8 itemc; //For item distribution, position of last picker in party struct { unsigned monk : 1; //There's at least one monk in party? unsigned sg : 1; //There's at least one Star Gladiator in party? diff --git a/src/map/mob.c b/src/map/mob.c index ca6d5e23c..84764627e 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -999,7 +999,7 @@ int mob_unlocktarget(struct mob_data *md,int tick) default: mob_stop_attack(md); if (battle_config.mob_ai&0x8) - mob_stop_walking(md,1); //Inmediately stop chasing. + mob_stop_walking(md,1); //Immediately stop chasing. md->state.skillstate = MSS_IDLE; md->next_walktime=tick+rand()%3000+3000; break; @@ -2085,7 +2085,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) exp += exp*(battle_config.exp_bonus_attacker*(count-1))/100.; //[Gengar] } - mexp = (exp > UINT_MAX)?UINT_MAX:(exp<1?1:(unsigned int)exp); + mexp = (unsigned int)cap_value(exp, 1, UINT_MAX); if(use_irc && irc_announce_mvp_flag) irc_announce_mvp(mvp_sd,md); diff --git a/src/map/party.c b/src/map/party.c index cac59d2c2..5117ce5ed 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -761,43 +761,46 @@ int party_exp_share(struct party_data *p,struct block_list *src,unsigned int bas } //Does party loot. first holds the id of the player who has time priority to take the item. -int party_share_loot(struct party_data *p, TBL_PC *sd, struct item *item_data, int first) +int party_share_loot(struct party_data* p, TBL_PC* sd, struct item* item_data, int first) { - TBL_PC *target=NULL; + TBL_PC* target = NULL; int i; - if (p && p->party.item&2 && (first || !(battle_config.party_share_type&1))) { + if (p && p->party.item&2 && (first || !(battle_config.party_share_type&1))) + { //item distribution to party members. - if (battle_config.party_share_type&2) { //Round Robin - TBL_PC *psd; + if (battle_config.party_share_type&2) + { //Round Robin + TBL_PC* psd; i = p->itemc; do { i++; if (i >= MAX_PARTY) i = 0; // reset counter to 1st person in party so it'll stop when it reaches "itemc" - if ((psd=p->data[i].sd)==NULL || sd->bl.m != psd->bl.m || - pc_isdead(psd) || (battle_config.idle_no_share && ( - psd->chatID || psd->vender_id || (psd->idletime < (last_tick - battle_config.idle_no_share))) - )) + + if( (psd = p->data[i].sd) == NULL || sd->bl.m != psd->bl.m || pc_isdead(psd) || + (battle_config.idle_no_share && (psd->chatID || psd->vender_id || last_tick - battle_config.idle_no_share > psd->idletime)) ) continue; if (pc_additem(psd,item_data,item_data->amount)) continue; //Chosen char can't pick up loot. + //Successful pick. p->itemc = i; target = psd; break; } while (i != p->itemc); - } else { //Random pick - TBL_PC *psd[MAX_PARTY]; - int count=0; + } + else + { //Random pick + TBL_PC* psd[MAX_PARTY]; + int count = 0; //Collect pick candidates for (i = 0; i < MAX_PARTY; i++) { - if ((psd[count]=p->data[i].sd) && psd[count]->bl.m == sd->bl.m && - !pc_isdead(psd[count]) && (!battle_config.idle_no_share || ( - !psd[count]->chatID && !psd[count]->vender_id && - (psd[count]->idletime >= (last_tick - battle_config.idle_no_share))) - )) - count++; + if( (psd[count] = p->data[i].sd) == NULL || psd[count]->bl.m != sd->bl.m || pc_isdead(psd[count]) || + (battle_config.idle_no_share && (psd[count]->chatID || psd[count]->vender_id || last_tick - battle_config.idle_no_share > psd[count]->idletime)) ) + continue; + + count++; } while (count > 0) { //Pick a random member. i = rand()%count; @@ -812,16 +815,17 @@ int party_share_loot(struct party_data *p, TBL_PC *sd, struct item *item_data, i } } } - if (!target) { //Give it to the owner. - target = sd; + + if (!target) { + target = sd; //Give it to the char that picked it up if ((i=pc_additem(sd,item_data,item_data->amount))) return i; } if(log_config.enable_logs&0x8) //Logs items, taken by (P)layers [Lupus] log_pick_pc(target, "P", item_data->nameid, item_data->amount, item_data); - //Logs - if(battle_config.party_show_share_picker && target != sd){ + + if(battle_config.party_show_share_picker && target != sd) { char output[80]; sprintf(output, "%s acquired %s.",target->status.name, itemdb_jname(item_data->nameid)); clif_disp_onlyself(sd,output,strlen(output)); diff --git a/src/map/pc.c b/src/map/pc.c index 995bf5901..79a898cff 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -2920,8 +2920,8 @@ int pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem) } } } - //This function takes care of giving the item to whoever should have it - //considering party-share options. + + //This function takes care of giving the item to whoever should have it, considering party-share options. if ((flag = party_share_loot(p,sd,&fitem->item_data, fitem->first_get_id))) { clif_additem(sd,0,0,flag); return 1; @@ -2929,7 +2929,6 @@ int pc_takeitem(struct map_session_data *sd,struct flooritem_data *fitem) //Display pickup animation. pc_stop_attack(sd); - clif_takeitem(&sd->bl,&fitem->bl); map_clearflooritem(fitem->bl.id); return 1; @@ -3050,7 +3049,7 @@ int pc_useitem(struct map_session_data *sd,int n) sd->itemindex = n; amount = sd->status.inventory[n].amount; script = sd->inventory_data[n]->script; - //Check if the item is to be consumed inmediately [Skotlex] + //Check if the item is to be consumed immediately [Skotlex] if (sd->inventory_data[n]->flag.delay_consume) clif_useitemack(sd,n,amount,1); else { diff --git a/src/map/script.c b/src/map/script.c index 54f9e6c46..074b7e3f1 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3859,7 +3859,6 @@ BUILDIN_FUNC(charcommand); // [MouseJstr] BUILDIN_FUNC(movenpc); // [MouseJstr] BUILDIN_FUNC(message); // [MouseJstr] BUILDIN_FUNC(npctalk); // [Valaris] -BUILDIN_FUNC(hasitems); // [Valaris] BUILDIN_FUNC(getlook); //Lorky [Lupus] BUILDIN_FUNC(getsavepoint); //Lorky [Lupus] BUILDIN_FUNC(npcspeed); // [Valaris] @@ -4193,7 +4192,6 @@ struct script_function buildin_func[] = { BUILDIN_DEF(movenpc,"sii"), // [MouseJstr] BUILDIN_DEF(message,"s*"), // [MouseJstr] BUILDIN_DEF(npctalk,"*"), // [Valaris] - BUILDIN_DEF(hasitems,"*"), // [Valaris] BUILDIN_DEF(mobcount,"ss"), BUILDIN_DEF(getlook,"i"), BUILDIN_DEF(getsavepoint,"i"), @@ -11370,29 +11368,6 @@ BUILDIN_FUNC(npctalk) return 0; } -/*========================================== - * hasitems (checks to see if player has any - * items on them, if so will return a 1) - * [Valaris] - *------------------------------------------*/ -BUILDIN_FUNC(hasitems) -{ - int i; - TBL_PC *sd; - - sd=script_rid2sd(st); - - for(i=0; i<MAX_INVENTORY; i++) { - if(sd->status.inventory[i].amount && sd->status.inventory[i].nameid!=2364 && sd->status.inventory[i].nameid!=2365) { - script_pushint(st,1); - return 0; - } - } - - script_pushint(st,0); - - return 0; -} // change npc walkspeed [Valaris] BUILDIN_FUNC(npcspeed) { diff --git a/src/map/skill.c b/src/map/skill.c index f49bc36ec..95c64e89c 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -3537,7 +3537,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in ) abra_skillid = 0; // reset to get a new id } while (abra_skillid == 0); - abra_skilllv = skill_get_max(abra_skillid) > skilllv ? skilllv : skill_get_max(abra_skillid); + abra_skilllv = min(skilllv, skill_get_max(abra_skillid)); clif_skill_nodamage (src, bl, skillid, skilllv, 1); if (sd) diff --git a/src/map/storage.h b/src/map/storage.h index a9f109319..bd8c5fdc6 100644 --- a/src/map/storage.h +++ b/src/map/storage.h @@ -39,7 +39,7 @@ int storage_guild_storagesaved(int guild_id); //Ack from char server that guild int storage_comp_item(const void *_i1, const void *_i2); //int storage_comp_item(const struct item* i1, const struct item* i2); -void sortage_sortitem(struct storage* stor); -void sortage_gsortitem(struct guild_storage* gstor); +void storage_sortitem(struct storage* stor); +void storage_gsortitem(struct guild_storage* gstor); #endif /* _STORAGE_H_ */ |