/
chat_timestamp.c
192 lines (155 loc) · 4.74 KB
/
chat_timestamp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//===== Hercules Plugin ======================================
//= Chat Timestamp
//===== By: ==================================================
//= Dastgir/Hercules
//===== Current Version: =====================================
//= 1.1
//===== Description: =========================================
//= Will add Timestamp to Party/Guild Chats
//===== Changelog: ===========================================
//= v1.0 - Initial Release.
//= v1.1 - Timestamp can be added to whisper. Fixed PM to NPC.
//===== Repo Link: ===========================================
//= https://github.com/dastgir/HPM-Plugins
//============================================================
#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/guild.h"
#include "map/map.h"
#include "map/party.h"
#include "map/pc.h"
#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 ALL_MESSAGE_TIMESTAMP
// Timestamp for Whispers
// Message Appears as "Name: [Time] Message"
//#define WHISPER_TIMESTAMP
// Timestamp for Party Chats
#define PARTY_MESSAGE_TIMESTAMP
// Timestamp for Guild Chats
#define GUILD_MESSAGE_TIMESTAMP
HPExport struct hplugin_info pinfo =
{
"Chat TimeStamp",
SERVER_TYPE_MAP,
"1.1",
HPM_VERSION,
};
// Don't touch below this
#ifdef ALL_MESSAGE_TIMESTAMP
#undef PARTY_MESSAGE_TIMESTAMP
#undef GUILD_MESSAGE_TIMESTAMP
// Whisper is handled in different function
#ifndef WHISPER_TIMESTAMP
#define WHISPER_TIMESTAMP
#endif
#endif
void get_timestamp(char* string)
{
time_t t;
t = time(NULL);
strftime(string, sizeof(string), "[%H:%M] ", localtime(&t));
return;
}
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 time_prefix[CHAT_SIZE_MAX + NAME_LENGTH + 3 + 1 + 10];
nullpo_ret(sd);
if (retVal == NULL)
return NULL;
get_timestamp(time_prefix);
strcat(time_prefix, out_buf);
safestrncpy(out_buf, time_prefix, strlen(time_prefix)+1);
retVal = out_buf;
return retVal;
}
int guild_send_message_pre(struct map_session_data **sd, const char **mes)
{
char prefix[CHAT_SIZE_MAX + NAME_LENGTH + 3 + 1];
nullpo_ret(*sd);
if ((*sd)->status.guild_id == 0)
return 0;
get_timestamp(prefix);
strcat(prefix, *mes);
*mes = (const char*)prefix;
return 1;
}
int party_send_message_pre(struct map_session_data **sd, const char **mes)
{
char prefix[CHAT_SIZE_MAX + NAME_LENGTH + 3 + 1];
nullpo_ret(*sd);
if ((*sd)->status.party_id == 0)
return 0;
get_timestamp(prefix);
strcat(prefix, *mes);
*mes = (const char*)prefix;
return 1;
}
/// Whisper is transmitted to the destination player (ZC_WHISPER).
/// 0097 <packet len>.W <nick>.24B <message>.?B
/// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
void clif_wis_message_pre(int *fd_, const char **nick_, const char **mes_, int *mes_len_)
{
char prefix[CHAT_SIZE_MAX + NAME_LENGTH + 3 + 1];
int fd = *fd_, mes_len = *mes_len_;
const char *nick = *nick_, *mes = *mes_;
#if PACKETVER >= 20091104
struct map_session_data *ssd = NULL;
#endif // PACKETVER >= 20091104
nullpo_retv(nick);
nullpo_retv(mes);
get_timestamp(prefix);
mes_len += strlen(prefix);
strcat(prefix, mes);
mes = (const char*)prefix;
#if PACKETVER < 20091104
WFIFOHEAD(fd, mes_len + NAME_LENGTH + 5);
WFIFOW(fd,0) = 0x97;
WFIFOW(fd,2) = mes_len + NAME_LENGTH + 5;
safestrncpy(WFIFOP(fd,4), nick, NAME_LENGTH);
safestrncpy(WFIFOP(fd,28), mes, mes_len + 1);
WFIFOSET(fd,WFIFOW(fd,2));
#else
ssd = map->nick2sd(nick, false);
WFIFOHEAD(fd, mes_len + NAME_LENGTH + 9);
WFIFOW(fd,0) = 0x97;
WFIFOW(fd,2) = mes_len + NAME_LENGTH + 9;
safestrncpy(WFIFOP(fd,4), nick, NAME_LENGTH);
WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
safestrncpy(WFIFOP(fd,32), mes, mes_len + 1);
WFIFOSET(fd,WFIFOW(fd,2));
#endif
hookStop();
}
HPExport void plugin_init(void)
{
#ifdef PARTY_MESSAGE_TIMESTAMP
addHookPre(party, send_message, party_send_message_pre);
#endif
#ifdef GUILD_MESSAGE_TIMESTAMP
addHookPre(guild, send_message, guild_send_message_pre);
#endif
#ifdef ALL_MESSAGE_TIMESTAMP
addHookPost(clif, process_chat_message, clif_process_chat_message_post);
#endif
#ifdef WHISPER_TIMESTAMP
addHookPre(clif, wis_message, clif_wis_message_pre);
#endif
}
HPExport void server_online(void)
{
ShowInfo("'%s' Plugin by Dastgir/Hercules. Version '%s'\n", pinfo.name, pinfo.version);
}