Jump to content
  • 0
Grimmjow

The time before a message in game chat

Question

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.

 

 

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));
Edited by Jeagerjaques

Share this post


Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 0

I think this is the plugin you need to use for this..

 

https://github.com/dastgir/HPM-Plugins/blob/master/src/plugins/chat_timestamp.c

 

I assumed the same, but he wants it everywhere and this plugin works only in guild/party channels 

Share this post


Link to post
Share on other sites
  • 0

yeah, just saw the code and found out that it works with guild and party chat only for now.. :D

 

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

Share this post


Link to post
Share on other sites
  • 0

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.

Edited by Habilis

Share this post


Link to post
Share on other sites
  • 0

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? :D

Edited by Samuel

Share this post


Link to post
Share on other sites
  • 0

hello guys need your help

i used Hercules-master_2015-12-17--15-58.zip old libconfig 1.4.9

this plugins for my version not working

but only edited 

On 13.07.2016 at 11:47 PM, Grimmjow said:

Open clif.c

please help! need normal working plugins for libconfig 1.4.9

 

b-317.png

Edited by ucell_uz

Share this post


Link to post
Share on other sites
  • 0
On 24/11/2017 at 6:04 AM, ucell_uz said:

hello guys need your help

i used Hercules-master_2015-12-17--15-58.zip old libconfig 1.4.9

this plugins for my version not working

but only edited 

please help! need normal working plugins for libconfig 1.4.9

  Hide contents

b-317.png

That's because you have other plugin enabled (Sample plugin)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.