summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char_sql/char.c44
-rw-r--r--src/map/chrif.c28
-rw-r--r--src/map/chrif.h1
-rw-r--r--src/map/pc.c32
4 files changed, 75 insertions, 30 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index d5b837d33..73907cf22 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -1277,6 +1277,26 @@ int make_new_char_sql(struct char_session_data* sd, char* name_, int str, int ag
}
/*----------------------------------------------------------------------------------------------------------*/
+/* Divorce Players */
+/*----------------------------------------------------------------------------------------------------------*/
+int divorce_char_sql(int partner_id1, int partner_id2)
+{
+ unsigned char buf[64];
+
+ if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `partner_id`='0' WHERE `char_id`='%d' OR `char_id`='%d'", char_db, partner_id1, partner_id2) )
+ Sql_ShowDebug(sql_handle);
+ if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE (`nameid`='%d' OR `nameid`='%d') AND (`char_id`='%d' OR `char_id`='%d')", inventory_db, WEDDING_RING_M, WEDDING_RING_F, partner_id1, partner_id2) )
+ Sql_ShowDebug(sql_handle);
+
+ WBUFW(buf,0) = 0x2b12;
+ WBUFL(buf,2) = partner_id1;
+ WBUFL(buf,6) = partner_id2;
+ mapif_sendall(buf,10);
+
+ return 0;
+}
+
+/*----------------------------------------------------------------------------------------------------------*/
/* Delete char - davidsiaw */
/*----------------------------------------------------------------------------------------------------------*/
/* Returns 0 if successful
@@ -1323,19 +1343,7 @@ int delete_char_sql(int char_id)
/* Divorce [Wizputer] */
if( partner_id )
- {
- unsigned char buf[64];
-
- if( SQL_ERROR == Sql_Query(sql_handle, "UPDATE `%s` SET `partner_id`='0' WHERE `char_id`='%d'", char_db, partner_id) )
- Sql_ShowDebug(sql_handle);
- if( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE (`nameid`='%d' OR `nameid`='%d') AND `char_id`='%d'", inventory_db, WEDDING_RING_M, WEDDING_RING_F, partner_id) )
- Sql_ShowDebug(sql_handle);
-
- WBUFW(buf,0) = 0x2b12;
- WBUFL(buf,2) = char_id;
- WBUFL(buf,6) = partner_id;
- mapif_sendall(buf,10);
- }
+ divorce_char_sql(char_id, partner_id);
/* De-addopt [Zephyrus] */
if( father_id || mother_id )
@@ -1857,7 +1865,6 @@ int parse_fromlogin(int fd)
{ //Receive account_reg2 registry, forward to map servers.
unsigned char buf[ACCOUNT_REG2_NUM*(256+32+2)+16];
memcpy(buf,RFIFOP(fd,0), RFIFOW(fd,2));
-// WBUFW(buf,0) = 0x2b11;
WBUFW(buf,0) = 0x3804; //Map server can now receive all kinds of reg values with the same packet. [Skotlex]
mapif_sendall(buf, WBUFW(buf,2));
}
@@ -2659,6 +2666,15 @@ int parse_frommap(int fd)
}
break;
+ // Divorce chars
+ case 0x2b11:
+ if( RFIFOREST(fd) < 10 )
+ return 0;
+
+ divorce_char_sql(RFIFOL(fd,2), RFIFOL(fd,6));
+ RFIFOSKIP(fd,10);
+ break;
+
case 0x2b16: // Receive rates [Wizputer]
if (RFIFOREST(fd) < 6 || RFIFOREST(fd) < RFIFOW(fd,8))
return 0;
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 4ae98408e..b923b427e 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -33,7 +33,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,35,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
- 11, 9,10, 6,11,-1,266,10, // 2b10-2b17: U->2b10, F->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17
+ 11,10,10, 6,11,-1,266,10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, U->2b13, U->2b14, U->2b15, U->2b16, U->2b17
2,10, 2,-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, 2, 2,14,-1,-1, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, U->2b24, U->2b25, F->2b26, F->2b27
};
@@ -64,8 +64,8 @@ static const int packet_len_table[0x3d] = { // U - used, F - free
//2b0e: Outgoing, chrif_char_ask_name -> 'Do some operations (change sex, ban / unban etc)'
//2b0f: Incoming, chrif_char_ask_name_answer -> 'answer of the 2b0e'
//2b10: Outgoing, chrif_updatefamelist -> 'Update the fame ranking lists and send them'
-//2b11: FREE
-//2b12: Incoming, chrif_divorce -> 'divorce a wedding of charid X and partner id X'
+//2b11: Outgoing, chrif_divorce -> 'tell the charserver to do divorce'
+//2b12: Incoming, chrif_divorceack -> 'divorce chars
//2b13: Incoming, chrif_accountdeletion -> 'Delete acc XX, if the player is on, kick ....'
//2b14: Incoming, chrif_accountban -> 'not sure: kick the player with message XY'
//2b15: Incoming, chrif_recvgmaccounts -> 'receive gm accs from charserver (seems to be incomplete !)'
@@ -85,7 +85,8 @@ static const int packet_len_table[0x3d] = { // U - used, F - free
//2b23: Outgoing, chrif_keepalive. charserver ping.
//2b24: Incoming, chrif_keepalive_ack. charserver ping reply.
//2b25: Incoming, chrif_deadopt -> 'Removes baby from Father ID and Mother ID'
-//2b26-2b27: FREE
+//2b26: FREE
+//2b27: FREE
int chrif_connected = 0;
int char_fd = 0; //Using 0 instead of -1 is safer against crashes. [Skotlex]
@@ -875,11 +876,26 @@ int chrif_changedsex(int fd)
}
return 0;
}
+/*==========================================
+ * Request Char Server to Divorce Players
+ *------------------------------------------*/
+int chrif_divorce(int partner_id1, int partner_id2)
+{
+ chrif_check(-1);
+
+ WFIFOHEAD(char_fd,10);
+ WFIFOW(char_fd,0) = 0x2b11;
+ WFIFOL(char_fd,2) = partner_id1;
+ WFIFOL(char_fd,6) = partner_id2;
+ WFIFOSET(char_fd,10);
+
+ return 0;
+}
/*==========================================
* Divorce players
*------------------------------------------*/
-int chrif_divorce(int char_id, int partner_id)
+int chrif_divorceack(int char_id, int partner_id)
{
struct map_session_data* sd;
int i;
@@ -1433,7 +1449,7 @@ int chrif_parse(int fd)
case 0x2b0b: chrif_changedgm(fd); break;
case 0x2b0d: chrif_changedsex(fd); break;
case 0x2b0f: chrif_char_ask_name_answer(RFIFOL(fd,2), (char*)RFIFOP(fd,6), RFIFOW(fd,30), RFIFOW(fd,32)); break;
- case 0x2b12: chrif_divorce(RFIFOL(fd,2), RFIFOL(fd,6)); break;
+ case 0x2b12: chrif_divorceack(RFIFOL(fd,2), RFIFOL(fd,6)); break;
case 0x2b13: chrif_accountdeletion(fd); break;
case 0x2b14: chrif_accountban(fd); break;
case 0x2b15: chrif_recvgmaccounts(fd); break;
diff --git a/src/map/chrif.h b/src/map/chrif.h
index bf1dbb108..661b4c809 100644
--- a/src/map/chrif.h
+++ b/src/map/chrif.h
@@ -57,6 +57,7 @@ int chrif_char_online(struct map_session_data *sd);
int chrif_changesex(struct map_session_data *sd);
int chrif_chardisconnect(struct map_session_data *sd);
int check_connect_char_server(int tid, unsigned int tick, int id, int data);
+int chrif_divorce(int partner_id1, int partner_id2);
int do_final_chrif(void);
int do_init_chrif(void);
diff --git a/src/map/pc.c b/src/map/pc.c
index 782446c42..a06f1c474 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -6668,34 +6668,46 @@ int pc_marriage(struct map_session_data *sd,struct map_session_data *dstsd)
}
/*==========================================
- * sd‚ª—£¥(‘ŠŽè‚Ísd->status.partner_id‚Ɉ˂é)(‘ŠŽè‚à“¯ŽbÉ—£¥?Œ‹¥Žw—ÖŽ©“®?’D)
+ * Divorce sd from its partner
*------------------------------------------*/
int pc_divorce(struct map_session_data *sd)
{
struct map_session_data *p_sd;
+ int i;
+
if (sd == NULL || !pc_ismarried(sd))
return -1;
- if ((p_sd = map_charid2sd(sd->status.partner_id)) != NULL) {
- int i;
- if (p_sd->status.partner_id != sd->status.char_id || sd->status.partner_id != p_sd->status.char_id) {
- ShowWarning("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n", sd->status.partner_id, p_sd->status.partner_id);
+ if( !sd->status.partner_id )
+ return -1; // Char is not married
+
+ if( (p_sd = map_charid2sd(sd->status.partner_id)) == NULL )
+ { // Lets char server do the divorce
+#ifndef TXT_ONLY
+ if( chrif_divorce(sd->status.char_id, sd->status.partner_id) )
+ return -1; // No char server connected
+
+ return 0;
+#else
+ ShowError("pc_divorce: p_sd nullpo\n");
return -1;
+#endif
}
+
+ // Both players online, lets do the divorce manually
sd->status.partner_id = 0;
p_sd->status.partner_id = 0;
- for (i = 0; i < MAX_INVENTORY; i++) {
+ 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);
if (p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F)
pc_delitem(p_sd, i, 1, 0);
}
+
clif_divorced(sd, p_sd->status.name);
clif_divorced(p_sd, sd->status.name);
- } else {
- ShowError("pc_divorce: p_sd nullpo\n");
- return -1;
- }
+
return 0;
}