The time before a message in game chat

Grimmjow

New member
Messages
17
Points
0
Github
Jeagerjaques
I want to ask help from experts to adapt code for the latest version of Hercules.

I tried to change, but not enough knowledge in src.

Please help.

Code:
Open clif.c
Найти void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)

After:

char *name, *message;
int namelen, messagelen;

Add:

char prefix[255]; // prefix for timestamp [Qwadrat]
time_t t = time(NULL); // time var [Qwadrat]

Continue to find:

// send message to others (using the send buffer for temp. storage)
And to prepend:

// timestamp feature by Qwadrat
strftime(prefix, 10, "[%H:%M] ", localtime(&t));
strcat(prefix,text);
textlen = strlen(prefix)+1;

Further:

// send message to others (using the send buffer for temp. storage)
Replace the original piece of code:

WFIFOHEAD(fd, 8 + textlen);
WFIFOW(fd,0) = 0x8d;
WFIFOW(fd,2) = 8 + textlen;
WFIFOL(fd,4) = sd->bl.id;
safestrncpy((char*)WFIFOP(fd,8), prefix, textlen);
clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
// send back message to the speaker
//memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));-original
memcpy(WFIFOP(fd,4), prefix, textlen); // [Qwadrat]
WFIFOW(fd,0) = 0x8e;
WFIFOW(fd,2) = RFIFOW(fd,2) + 8; // 8 - textlen [Qwadrat]
WFIFOSET(fd, WFIFOW(fd,2));
 
Last edited by a moderator:
yeah, just saw the code and found out that it works with guild and party chat only for now..
default_biggrin.png


hmm, will try to do a plugin for normal chat.

 
And you probably already got why the plugin is done that way... getting a timestamp for every single ramble in common chat would load the the server.

Hence, all the spamming / flooding happens in common chat.

 
Last edited by a moderator:
dastgir updated the plugin, try it!

 
dastgir updated the plugin, try it!
tried it but it's not working.. well he said in his commit that it's in trial..

try this:

#include "common/hercules.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common/HPMi.h"
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/nullpo.h"
#include "common/strlib.h"
#include "common/socket.h"

#include "map/clif.h"
#include "map/map.h"
#include "map/pc.h"

#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"

HPExport struct hplugin_info pinfo =
{
"Chat TimeStamp",
SERVER_TYPE_MAP,
"1.0",
HPM_VERSION,
};

const char *clif_process_chat_message_post(const char *retVal___, struct map_session_data *sd, const struct packet_chat_message *packet, char *out_buf, int out_buflen)
{
char prefix[CHAT_SIZE_MAX + NAME_LENGTH + 3 + 1];
time_t t;
int textlen = 0, namelen = 0;

nullpo_ret(sd);

if (retVal___ == NULL)
return NULL;
#if PACKETVER >= 20151001
// Packet doesn't include a NUL terminator
textlen = packet->packet_len - 4;
#else // PACKETVER < 20151001
// Packet includes a NUL terminator
textlen = packet->packet_len - 4 - 1;
#endif // PACKETVER > 20151001
safestrncpy(out_buf,packet->message,textlen+1);

t = time(NULL);
strftime(prefix, 10, "[%H:%M] ", localtime(&t));

strcat(prefix, out_buf);

safestrncpy(out_buf,prefix,textlen+10);

retVal___ = out_buf;

return retVal___;
}

HPExport void plugin_init (void)
{
addHookPost(clif, process_chat_message, clif_process_chat_message_post);
}



Edit: It's working as I have tested it, the only thing that bothers me is this warning I get when I compile with Visual Studio 2011

warning C4090: 'function' : different 'const' qualifiers

Edit2: how to use code with code select?
default_biggrin.png


 
Last edited by a moderator:
Back
Top