Skip to content

Commit

Permalink
Added TimeStamp on chats(Seen everywhere) (Disabled By Default).
Browse files Browse the repository at this point in the history
** Experimental **
Fixes #20
FollowUp to #21, where one function was missed out.
  • Loading branch information
dastgirp committed Jul 15, 2016
1 parent 5824dea commit c50cdae
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/plugins/chat_timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"

/**
* Enables TimeStamp in Player Messages.
* This Options Enables Timestamp everywhere a player can send message to.
**/
// #define PLAYER_MESSAGE_TIMESTAMP

HPExport struct hplugin_info pinfo =
{
"Chat TimeStamp",
Expand All @@ -40,6 +46,34 @@ HPExport struct hplugin_info pinfo =
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;

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, retVal, textlen+1); // [!] packet->message is not necessarily NUL terminated

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

strcat(prefix, out_buf);

retVal = prefix;
return retVal;
}

int guild_send_message_pre(struct map_session_data **sd, const char **mes)
{
char prefix[CHAT_SIZE_MAX + NAME_LENGTH + 3 + 1];
Expand All @@ -63,13 +97,14 @@ int guild_send_message_pre(struct map_session_data **sd, const char **mes)
int party_send_message_pre(struct map_session_data **sd, const char **mes)
{
char prefix[CHAT_SIZE_MAX + NAME_LENGTH + 3 + 1];
time_t t;

nullpo_ret(*sd);

if ((*sd)->status.party_id == 0)
return 0;

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

strcat(prefix, *mes);
Expand All @@ -80,8 +115,12 @@ int party_send_message_pre(struct map_session_data **sd, const char **mes)

HPExport void plugin_init (void)
{
#ifndef PLAYER_MESSAGE_TIMESTAMP
addHookPre(party, send_message, party_send_message_pre);
addHookPre(guild, send_message, guild_send_message_pre);
#else
addHookPost(clif, process_chat_message_pre, clif_process_chat_message_pre);

This comment has been minimized.

Copy link
@SamuelHercules

SamuelHercules Jul 16, 2016

process_chat_message_pre should be process_chat_message i think

and

clif_process_chat_message_pre should be clif_process_chat_message_post

This comment has been minimized.

Copy link
@dastgirp

dastgirp Jul 16, 2016

Author Owner

ah, good catch :P

#endif
}

HPExport void server_online (void)
Expand Down

3 comments on commit c50cdae

@SamuelHercules
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiling with const char* hooks gives this warning in Visual Studio 2011

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

@dastgirp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamuelHercules compiles fine on linux, mind showing which line does that warning redirect to?

@SamuelHercules
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dastgir the warning is directed at line 122 the addhookpost line for that function

Please sign in to comment.