我正在努力改写eAthena的一些来源。我需要在数据包的末尾添加4个字节。我试图了解如何。不会WFIFOL(sd-> fd,len)= 0加4个字节?我需要在这上面做一个SWAP32吗?还在学习谢谢。
int clif_sendadditem(USER *sd, int num) {
char buf[128];
char buf2[128];
char *name = NULL;
char* owner = NULL;
int namelen;
int len;
int id;
//if(!sd->status.inventory[num].custom) {
id=sd->status.inventory[num].id;
//} else {
// id=sd->status.inventory[num].custom;
//}
if (id > 0 && !strcmpi(itemdb_name(id), "??")) {
memset(&sd->status.inventory[num], 0, sizeof(sd->status.inventory[num]));
return 0;
}
if (strlen(sd->status.inventory[num].real_name)) {
name = sd->status.inventory[num].real_name;
} else {
//if(!sd->status.inventory[num].custom) {
name = itemdb_name(id);
//} else {
// name = itemdb_namec(id);
//}
}
if (sd->status.inventory[num].amount > 1) {
sprintf(buf, "%s (%d)", name, sd->status.inventory[num].amount);
} else if(itemdb_type(sd->status.inventory[num].id)==ITM_SMOKE) {
//if(!sd->status.inventory[num].custom) {
sprintf(buf, "%s [%d %s]",name,sd->status.inventory[num].dura,itemdb_text(sd->status.inventory[num].id));
//} else {
// sprintf(buf, "%s [%d %s]",name,sd->status.inventory[num].dura,itemdb_textc(sd->status.inventory[num].custom));
//}
} else {
strcpy(buf, name);
}
namelen = strlen(buf);
if (!session[sd->fd])
{
session[sd->fd]->eof = 8;
return 0;
}
WFIFOHEAD(sd->fd, 255);
WFIFOB(sd->fd, 0) = 0xAA;
WFIFOB(sd->fd, 3) = 0x0F;
//WFIFOB(sd->fd, 4) = 0x03;
WFIFOB(sd->fd, 5) = num+1;
//if(!sd->status.inventory[num].custom) {
WFIFOW(sd->fd, 6) = SWAP16(itemdb_icon(id));
WFIFOB(sd->fd, 8) = itemdb_iconcolor(id);
//} else {
// WFIFOW(sd->fd, 6) = SWAP16(itemdb_iconc(id));
// WFIFOB(sd->fd, 8) = itemdb_iconcolorc(id);
//}
WFIFOB(sd->fd, 9) = namelen;
memcpy(WFIFOP(sd->fd, 10), buf, namelen);
len=namelen+1;
//if(!sd->status.inventory[num].custom) {
WFIFOB(sd->fd,len+9)=strlen(itemdb_name(id));
strcpy(WFIFOP(sd->fd,len+10),itemdb_name(id));
len+=strlen(itemdb_name(id))+1;
//} else {
// WFIFOB(sd->fd,len+9)=strlen(itemdb_namec(id));
// strcpy(WFIFOP(sd->fd,len+10),itemdb_namec(id));
// len+=strlen(itemdb_namec(id))+1;
//}
WFIFOL(sd->fd,len+9)=SWAP32(sd->status.inventory[num].amount);
len+=4;
if((itemdb_type(id)<3) || (itemdb_type(id)>17)) {
WFIFOB(sd->fd,len+9)=1;
WFIFOL(sd->fd,len+10)=0;
WFIFOB(sd->fd, len + 14) = 0;
len+=6;
} else {
WFIFOB(sd->fd,len+9)=0;
WFIFOL(sd->fd,len+10)=SWAP32(sd->status.inventory[num].dura);
WFIFOB(sd->fd, len + 14) = 0; //REPLACE WITH PROTECTED
len+=6;
}
if(sd->status.inventory[num].owner_id) {
owner=map_id2name(sd->status.inventory[num].owner_id);
WFIFOB(sd->fd,len+9)=strlen(owner);
strcpy(WFIFOP(sd->fd,len+10),owner);
len+=strlen(owner)+1;
FREE(owner);
} else {
WFIFOB(sd->fd,len+9)=0; //len of owner
len+=1;
}
//WFIFOW(sd->fd, len + 9) = SWAP16(0);
WFIFOW(sd->fd, 1) = SWAP16(len + 6);
WFIFOSET(sd->fd, encrypt(sd->fd));
return 0;
}
答案 0 :(得分:0)
我错误计算并更改了评论
//WFIFOW(sd->fd, len + 9) = SWAP16(0);
到
WFIFOL(sd->fd, len + 9) = SWAP32(0);
然后在结束时改为len + 10