summaryrefslogtreecommitdiff
path: root/src/map/intif.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/intif.c')
-rw-r--r--src/map/intif.c129
1 files changed, 81 insertions, 48 deletions
diff --git a/src/map/intif.c b/src/map/intif.c
index 36ae753db..b9d4d1746 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -125,7 +125,7 @@ int intif_rename(struct map_session_data *sd, int type, char *name)
}
// GM Send a message
-int intif_broadcast(const char* mes, int len, int type)
+int intif_broadcast(const char* mes, size_t len, int type)
{
int lp = (type|BC_COLOR_MASK) ? 4 : 0;
@@ -155,7 +155,7 @@ int intif_broadcast(const char* mes, int len, int type)
return 0;
}
-int intif_broadcast2(const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY)
+int intif_broadcast2(const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY)
{
// Send to the local players
clif->broadcast2(NULL, mes, len, fontColor, fontType, fontSize, fontAlign, fontY, ALL_CLIENT);
@@ -192,7 +192,7 @@ int intif_main_message(struct map_session_data* sd, const char* message)
snprintf( output, sizeof(output), msg_txt(386), sd->status.name, message );
// send the message using the inter-server broadcast service
- intif_broadcast2( output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0 );
+ intif->broadcast2( output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0 );
// log the chat message
logs->chat( LOG_CHAT_MAINCHAT, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message );
@@ -201,7 +201,7 @@ int intif_main_message(struct map_session_data* sd, const char* message)
}
// The transmission of Wisp/Page to inter-server (player not found on this server)
-int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, int mes_len)
+int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, size_t mes_len)
{
nullpo_ret(sd);
if (intif->CheckForCharServer())
@@ -247,7 +247,7 @@ int intif_wis_replay(int id, int flag)
// The transmission of GM only Wisp/Page from server to inter-server
int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes)
{
- int mes_len;
+ size_t mes_len;
if (intif->CheckForCharServer())
return 0;
mes_len = strlen(mes) + 1; // + null
@@ -447,7 +447,7 @@ int intif_party_leave(int party_id,int account_id, int char_id)
// Request keeping party for new map ??
int intif_party_changemap(struct map_session_data *sd,int online) {
- int16 m, mapindex;
+ int16 m, map_index;
if (intif->CheckForCharServer())
return 0;
@@ -455,16 +455,16 @@ int intif_party_changemap(struct map_session_data *sd,int online) {
return 0;
if( (m=map->mapindex2mapid(sd->mapindex)) >= 0 && map->list[m].instance_id >= 0 )
- mapindex = map_id2index(map->list[m].instance_src_map);
+ map_index = map_id2index(map->list[m].instance_src_map);
else
- mapindex = sd->mapindex;
+ map_index = sd->mapindex;
WFIFOHEAD(inter_fd,19);
WFIFOW(inter_fd,0)=0x3025;
WFIFOL(inter_fd,2)=sd->status.party_id;
WFIFOL(inter_fd,6)=sd->status.account_id;
WFIFOL(inter_fd,10)=sd->status.char_id;
- WFIFOW(inter_fd,14)=mapindex;
+ WFIFOW(inter_fd,14)=map_index;
WFIFOB(inter_fd,16)=online;
WFIFOW(inter_fd,17)=sd->status.base_level;
WFIFOSET(inter_fd,19);
@@ -560,7 +560,7 @@ int intif_guild_addmember(int guild_id,struct guild_member *m)
}
// Request a new leader for guild
-int intif_guild_change_gm(int guild_id, const char* name, int len)
+int intif_guild_change_gm(int guild_id, const char* name, size_t len)
{
if (intif->CheckForCharServer())
return 0;
@@ -893,7 +893,7 @@ int mapif_parse_WisToGM_sub(struct map_session_data* sd,va_list va) {
char *message;
int len;
- if (!pc->has_permission(sd, permission))
+ if (!pc_has_permission(sd, permission))
return 0;
wisp_name = va_arg(va, char*);
message = va_arg(va, char*);
@@ -1311,50 +1311,80 @@ QUESTLOG SYSTEM FUNCTIONS
***************************************/
-int intif_request_questlog(TBL_PC *sd)
-{
+/**
+ * Requests a character's quest log entries to the inter server.
+ *
+ * @param sd Character's data
+ */
+void intif_request_questlog(TBL_PC *sd) {
WFIFOHEAD(inter_fd,6);
WFIFOW(inter_fd,0) = 0x3060;
WFIFOL(inter_fd,2) = sd->status.char_id;
WFIFOSET(inter_fd,6);
- return 0;
}
+/**
+ * Parses the received quest log entries for a character from the inter server.
+ *
+ * Received in reply to the requests made by intif_request_questlog.
+ *
+ * @see intif_parse
+ */
void intif_parse_QuestLog(int fd) {
- int char_id = RFIFOL(fd, 4);
- int i;
- TBL_PC * sd = map->charid2sd(char_id);
+ int char_id = RFIFOL(fd, 4), num_received = (RFIFOW(fd, 2)-8)/sizeof(struct quest);
+ TBL_PC *sd = map->charid2sd(char_id);
- //User not online anymore
- if(!sd)
+ if (!sd) // User not online anymore
return;
- sd->avail_quests = sd->num_quests = (RFIFOW(fd, 2)-8)/sizeof(struct quest);
-
- memset(&sd->quest_log, 0, sizeof(sd->quest_log));
-
- for( i = 0; i < sd->num_quests; i++ )
- {
- memcpy(&sd->quest_log[i], RFIFOP(fd, i*sizeof(struct quest)+8), sizeof(struct quest));
+ sd->num_quests = sd->avail_quests = 0;
- sd->quest_index[i] = quest->search_db(sd->quest_log[i].quest_id);
-
- if( sd->quest_index[i] < 0 )
- {
- ShowError("intif_parse_QuestLog: quest %d not found in DB.\n",sd->quest_log[i].quest_id);
- sd->avail_quests--;
- sd->num_quests--;
- i--;
- continue;
+ if (num_received == 0) {
+ if (sd->quest_log) {
+ aFree(sd->quest_log);
+ sd->quest_log = NULL;
+ }
+ } else {
+ struct quest *received = (struct quest *)RFIFOP(fd, 8);
+ int i, k = num_received;
+ if (sd->quest_log) {
+ RECREATE(sd->quest_log, struct quest, num_received);
+ } else {
+ CREATE(sd->quest_log, struct quest, num_received);
}
- if( sd->quest_log[i].state == Q_COMPLETE )
- sd->avail_quests--;
+ for (i = 0; i < num_received; i++) {
+ if( quest->db(received[i].quest_id) == &quest->dummy ) {
+ ShowError("intif_parse_QuestLog: quest %d not found in DB.\n", received[i].quest_id);
+ continue;
+ }
+ if (received[i].state != Q_COMPLETE) {
+ // Insert at the beginning
+ memcpy(&sd->quest_log[sd->avail_quests++], &received[i], sizeof(struct quest));
+ } else {
+ // Insert at the end
+ memcpy(&sd->quest_log[--k], &received[i], sizeof(struct quest));
+ }
+ sd->num_quests++;
+ }
+ if (sd->avail_quests < k) {
+ // sd->avail_quests and k didn't meet in the middle: some entries were skipped
+ if (k < num_received) // Move the entries at the end to fill the gap
+ memmove(&sd->quest_log[k], &sd->quest_log[sd->avail_quests], sizeof(struct quest)*(num_received - k));
+ sd->quest_log = aRealloc(sd->quest_log, sizeof(struct quest)*sd->num_quests);
+ }
}
quest->pc_login(sd);
}
+/**
+ * Parses the quest log save ack for a character from the inter server.
+ *
+ * Received in reply to the requests made by intif_quest_save.
+ *
+ * @see intif_parse
+ */
void intif_parse_QuestSave(int fd) {
int cid = RFIFOL(fd, 2);
TBL_PC *sd = map->id2sd(cid);
@@ -1365,21 +1395,24 @@ void intif_parse_QuestSave(int fd) {
sd->save_quest = false;
}
-int intif_quest_save(TBL_PC *sd)
-{
- int len;
+/**
+ * Requests to the inter server to save a character's quest log entries.
+ *
+ * @param sd Character's data
+ * @return 0 in case of success, nonzero otherwise
+ */
+int intif_quest_save(TBL_PC *sd) {
+ int len = sizeof(struct quest)*sd->num_quests + 8;
if(intif->CheckForCharServer())
- return 0;
-
- len = sizeof(struct quest)*sd->num_quests + 8;
+ return 1;
WFIFOHEAD(inter_fd, len);
WFIFOW(inter_fd,0) = 0x3061;
WFIFOW(inter_fd,2) = len;
WFIFOL(inter_fd,4) = sd->status.char_id;
if( sd->num_quests )
- memcpy(WFIFOP(inter_fd,8), &sd->quest_log, sizeof(struct quest)*sd->num_quests);
+ memcpy(WFIFOP(inter_fd,8), sd->quest_log, sizeof(struct quest)*sd->num_quests);
WFIFOSET(inter_fd, len);
return 0;
@@ -1526,7 +1559,7 @@ void intif_parse_MailDelete(int fd) {
}
if( sd->mail.inbox.full )
- intif_Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
+ intif->Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
}
clif->mail_delete(sd->fd, mail_id, failed);
@@ -1567,7 +1600,7 @@ void intif_parse_MailReturn(int fd) {
}
if( sd->mail.inbox.full )
- intif_Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
+ intif->Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
}
clif->mail_return(sd->fd, mail_id, fail);
@@ -1764,7 +1797,7 @@ void intif_parse_AuctionClose(int fd) {
if( result == 0 ) {
// FIXME: Leeching off a parse function
clif->pAuction_cancelreg(fd, sd);
- intif_Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
+ intif->Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
}
}
@@ -1801,7 +1834,7 @@ void intif_parse_AuctionBid(int fd) {
}
if( result == 1 ) { // To update the list, display your buy list
clif->pAuction_cancelreg(fd, sd);
- intif_Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
+ intif->Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
}
}