|
@@ -66,9 +66,9 @@ int inter_recv_packet_length[] = {
|
|
|
};
|
|
|
|
|
|
struct WisData {
|
|
|
- int id, fd, count, len;
|
|
|
+ int id, fd, count, len, gmlvl;
|
|
|
unsigned long tick;
|
|
|
- unsigned char src[NAME_LENGTH], dst[NAME_LENGTH], msg[512];
|
|
|
+ char src[NAME_LENGTH], dst[NAME_LENGTH], msg[512];
|
|
|
};
|
|
|
static DBMap* wis_db = NULL; // int wis_id -> struct WisData*
|
|
|
static int wis_dellist[WISDELLIST_MAX], wis_delnum;
|
|
@@ -1045,31 +1045,22 @@ int mapif_broadcast(unsigned char *mes, int len, unsigned long fontColor, short
|
|
|
int mapif_wis_message(struct WisData *wd)
|
|
|
{
|
|
|
unsigned char buf[2048];
|
|
|
- if (wd->len > 2047-56) wd->len = 2047-56; //Force it to fit to avoid crashes. [Skotlex]
|
|
|
+ int headersize = 12 + 2 * NAME_LENGTH;
|
|
|
+
|
|
|
+ if (wd->len > 2047-headersize) wd->len = 2047-headersize; //Force it to fit to avoid crashes. [Skotlex]
|
|
|
|
|
|
WBUFW(buf, 0) = 0x3801;
|
|
|
- WBUFW(buf, 2) = 56 +wd->len;
|
|
|
+ WBUFW(buf, 2) = headersize+wd->len;
|
|
|
WBUFL(buf, 4) = wd->id;
|
|
|
- memcpy(WBUFP(buf, 8), wd->src, NAME_LENGTH);
|
|
|
- memcpy(WBUFP(buf,32), wd->dst, NAME_LENGTH);
|
|
|
- memcpy(WBUFP(buf,56), wd->msg, wd->len);
|
|
|
+ WBUFL(buf, 8) = wd->gmlvl;
|
|
|
+ safestrncpy(WBUFCP(buf,12), wd->src, NAME_LENGTH);
|
|
|
+ safestrncpy(WBUFCP(buf,12 + NAME_LENGTH), wd->dst, NAME_LENGTH);
|
|
|
+ safestrncpy(WBUFCP(buf,12 + 2*NAME_LENGTH), wd->msg, wd->len);
|
|
|
wd->count = chmapif_sendall(buf,WBUFW(buf,2));
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-// Wis sending result
|
|
|
-int mapif_wis_end(struct WisData *wd, int flag)
|
|
|
-{
|
|
|
- unsigned char buf[27];
|
|
|
-
|
|
|
- WBUFW(buf, 0)=0x3802;
|
|
|
- memcpy(WBUFP(buf, 2),wd->src,24);
|
|
|
- WBUFB(buf,26)=flag;
|
|
|
- chmapif_send(wd->fd,buf,27);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
// Send the requested account_reg
|
|
|
int mapif_account_reg_reply(int fd, uint32 account_id, uint32 char_id, int type)
|
|
|
{
|
|
@@ -1122,7 +1113,7 @@ int check_ttl_wisdata(void)
|
|
|
struct WisData *wd = (struct WisData*)idb_get(wis_db, wis_dellist[i]);
|
|
|
ShowWarning("inter: wis data id=%d time out : from %s to %s\n", wd->id, wd->src, wd->dst);
|
|
|
// removed. not send information after a timeout. Just no answer for the player
|
|
|
- //mapif_wis_end(wd, 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
|
|
|
+ //mapif_wis_reply(wd->fd, wd->src, 1); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
|
|
|
idb_remove(wis_db, wd->id);
|
|
|
}
|
|
|
} while(wis_delnum >= WISDELLIST_MAX);
|
|
@@ -1156,6 +1147,17 @@ int mapif_parse_broadcast_item(int fd) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+// Wis sending result
|
|
|
+// flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
|
|
|
+int mapif_wis_reply( int mapserver_fd, char* target, uint8 flag ){
|
|
|
+ unsigned char buf[27];
|
|
|
+
|
|
|
+ WBUFW(buf, 0) = 0x3802;
|
|
|
+ safestrncpy(WBUFCP(buf, 2), target, NAME_LENGTH);
|
|
|
+ WBUFB(buf,26) = flag;
|
|
|
+
|
|
|
+ return chmapif_send(mapserver_fd, buf, 27);
|
|
|
+}
|
|
|
|
|
|
// Wisp/page request to send
|
|
|
int mapif_parse_WisRequest(int fd)
|
|
@@ -1165,19 +1167,20 @@ int mapif_parse_WisRequest(int fd)
|
|
|
char esc_name[NAME_LENGTH*2+1];// escaped name
|
|
|
char* data;
|
|
|
size_t len;
|
|
|
+ int headersize = 8+2*NAME_LENGTH;
|
|
|
|
|
|
|
|
|
if ( fd <= 0 ) {return 0;} // check if we have a valid fd
|
|
|
|
|
|
- if (RFIFOW(fd,2)-52 >= sizeof(wd->msg)) {
|
|
|
+ if (RFIFOW(fd,2)-headersize >= sizeof(wd->msg)) {
|
|
|
ShowWarning("inter: Wis message size too long.\n");
|
|
|
return 0;
|
|
|
- } else if (RFIFOW(fd,2)-52 <= 0) { // normaly, impossible, but who knows...
|
|
|
+ } else if (RFIFOW(fd,2)-headersize <= 0) { // normaly, impossible, but who knows...
|
|
|
ShowError("inter: Wis message doesn't exist.\n");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- safestrncpy(name, RFIFOCP(fd,28), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex]
|
|
|
+ safestrncpy(name, RFIFOCP(fd,8+NAME_LENGTH), NAME_LENGTH); //Received name may be too large and not contain \0! [Skotlex]
|
|
|
|
|
|
Sql_EscapeStringLen(sql_handle, esc_name, name, strnlen(name, NAME_LENGTH));
|
|
|
if( SQL_ERROR == Sql_Query(sql_handle, "SELECT `name` FROM `%s` WHERE `name`='%s'", schema_config.char_db, esc_name) )
|
|
@@ -1186,11 +1189,7 @@ int mapif_parse_WisRequest(int fd)
|
|
|
// search if character exists before to ask all map-servers
|
|
|
if( SQL_SUCCESS != Sql_NextRow(sql_handle) )
|
|
|
{
|
|
|
- unsigned char buf[27];
|
|
|
- WBUFW(buf, 0) = 0x3802;
|
|
|
- memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), NAME_LENGTH);
|
|
|
- WBUFB(buf,26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
|
|
|
- chmapif_send(fd, buf, 27);
|
|
|
+ mapif_wis_reply(fd, RFIFOCP(fd, 8), 1);
|
|
|
}
|
|
|
else
|
|
|
{// Character exists. So, ask all map-servers
|
|
@@ -1199,13 +1198,9 @@ int mapif_parse_WisRequest(int fd)
|
|
|
memset(name, 0, NAME_LENGTH);
|
|
|
memcpy(name, data, zmin(len, NAME_LENGTH));
|
|
|
// if source is destination, don't ask other servers.
|
|
|
- if( strncmp(RFIFOCP(fd,4), name, NAME_LENGTH) == 0 )
|
|
|
+ if( strncmp(RFIFOCP(fd,8), name, NAME_LENGTH) == 0 )
|
|
|
{
|
|
|
- uint8 buf[27];
|
|
|
- WBUFW(buf, 0) = 0x3802;
|
|
|
- memcpy(WBUFP(buf, 2), RFIFOP(fd, 4), NAME_LENGTH);
|
|
|
- WBUFB(buf,26) = 1; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
|
|
|
- chmapif_send(fd, buf, 27);
|
|
|
+ mapif_wis_reply(fd, RFIFOCP(fd, 8), 1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1218,10 +1213,11 @@ int mapif_parse_WisRequest(int fd)
|
|
|
|
|
|
wd->id = ++wisid;
|
|
|
wd->fd = fd;
|
|
|
- wd->len= RFIFOW(fd,2)-52;
|
|
|
- memcpy(wd->src, RFIFOP(fd, 4), NAME_LENGTH);
|
|
|
- memcpy(wd->dst, RFIFOP(fd,28), NAME_LENGTH);
|
|
|
- memcpy(wd->msg, RFIFOP(fd,52), wd->len);
|
|
|
+ wd->len= RFIFOW(fd,2)-headersize;
|
|
|
+ wd->gmlvl = RFIFOL(fd,4);
|
|
|
+ safestrncpy(wd->src, RFIFOCP(fd,8), NAME_LENGTH);
|
|
|
+ safestrncpy(wd->dst, RFIFOCP(fd,8+NAME_LENGTH), NAME_LENGTH);
|
|
|
+ safestrncpy(wd->msg, RFIFOCP(fd,8+2*NAME_LENGTH), wd->len);
|
|
|
wd->tick = gettick();
|
|
|
idb_put(wis_db, wd->id, wd);
|
|
|
mapif_wis_message(wd);
|
|
@@ -1236,7 +1232,8 @@ int mapif_parse_WisRequest(int fd)
|
|
|
// Wisp/page transmission result
|
|
|
int mapif_parse_WisReply(int fd)
|
|
|
{
|
|
|
- int id, flag;
|
|
|
+ int id;
|
|
|
+ uint8 flag;
|
|
|
struct WisData *wd;
|
|
|
|
|
|
id = RFIFOL(fd,2);
|
|
@@ -1246,7 +1243,7 @@ int mapif_parse_WisReply(int fd)
|
|
|
return 0; // This wisp was probably suppress before, because it was timeout of because of target was found on another map-server
|
|
|
|
|
|
if ((--wd->count) <= 0 || flag != 1) {
|
|
|
- mapif_wis_end(wd, flag); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
|
|
|
+ mapif_wis_reply(wd->fd, wd->src, flag); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
|
|
|
idb_remove(wis_db, id);
|
|
|
}
|
|
|
|