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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "../common/socket.h"
#include "../common/timer.h"
#include "../common/nullpo.h"
#include "log.h"
#include "clif.h"
#include "chrif.h"
#include "intif.h"
#include "itemdb.h"
#include "map.h"
#include "pc.h"
#include "skill.h"
#include "mob.h"
#include "pet.h"
#include "battle.h"
#include "party.h"
#include "guild.h"
#include "charcommand.h"
#include "atcommand.h"
#include "script.h"
#include "npc.h"
#include "trade.h"
#include "core.h"
static char command_symbol = '#';
static char msg_table[1000][1024]; // Server messages (0-499 reserved for GM commands, 500-999 reserved for others)
#define CHARCOMMAND_FUNC(x) int charcommand_ ## x (const int fd, struct map_session_data* sd, const char* command, const char* message)
CHARCOMMAND_FUNC(jobchange);
CHARCOMMAND_FUNC(petrename);
#ifdef TXT_ONLY
/* TXT_ONLY */
/* TXT_ONLY */
#else
/* SQL-only */
/* SQL Only */
#endif
/*==========================================
*CharCommandInfo charcommand_info[]�\���̂̒�`
*------------------------------------------
*/
// First char of commands is configured in charcommand_athena.conf. Leave @ in this list for default value.
// to set default level, read charcommand_athena.conf first please.
static CharCommandInfo charcommand_info[] = {
{ CharCommandJobChange, "#job", 60, charcommand_jobchange },
{ CharCommandJobChange, "#jobchange", 60, charcommand_jobchange },
{ CharCommandPetRename, "#petrename", 50, charcommand_petrename },
#ifdef TXT_ONLY
/* TXT_ONLY */
/* TXT_ONLY */
#else
/* SQL-only */
/* SQL Only */
#endif
// add new commands before this line
{ CharCommand_Unknown, NULL, 1, NULL }
};
int get_charcommand_level(const CharCommandType type) {
int i;
for (i = 0; charcommand_info[i].type != CharCommand_None; i++)
if (charcommand_info[i].type == type)
return charcommand_info[i].level;
return 100; // 100: command can not be used
}
/*==========================================
*is_charcommand @�R�}���h�ɑ��݂��邩�ǂ����m�F����
*------------------------------------------
*/
CharCommandType
is_charcommand(const int fd, struct map_session_data* sd, const char* message, int gmlvl) {
const char* str = message;
int s_flag = 0;
CharCommandInfo info;
CharCommandType type;
nullpo_retr(CharCommand_None, sd);
if (!message || !*message)
return CharCommand_None;
memset(&info, 0, sizeof(info));
str += strlen(sd->status.name);
while (*str && (isspace(*str) || (s_flag == 0 && *str == ':'))) {
if (*str == ':')
s_flag = 1;
str++;
}
if (!*str)
return CharCommand_None;
type = charcommand(gmlvl > 0 ? gmlvl : pc_isGM(sd), str, &info);
if (type != CharCommand_None) {
char command[100];
char output[200];
const char* p = str;
memset(command, '\0', sizeof(command));
memset(output, '\0', sizeof(output));
while (*p && !isspace(*p))
p++;
if (p - str >= sizeof(command)) // too long
return CharCommand_Unknown;
strncpy(command, str, p - str);
while (isspace(*p))
p++;
if (type == CharCommand_Unknown || info.proc == NULL) {
sprintf(output, msg_table[153], command); // %s is Unknown Command.
clif_displaymessage(fd, output);
} else {
if (info.proc(fd, sd, command, p) != 0) {
// Command can not be executed
sprintf(output, msg_table[154], command); // %s failed.
clif_displaymessage(fd, output);
}
}
return info.type;
}
return CharCommand_None;
}
/*==========================================
*
*------------------------------------------
*/
CharCommandType charcommand(const int level, const char* message, struct CharCommandInfo* info) {
char* p = (char *)message;
if (!info)
return CharCommand_None;
if (battle_config.atc_gmonly != 0 && !level) // level = pc_isGM(sd)
return CharCommand_None;
if (!p || !*p) {
fprintf(stderr, "char command message is empty\n");
return CharCommand_None;
}
if (*p == command_symbol) { // check first char.
char command[101];
int i = 0;
memset(info, 0, sizeof(CharCommandInfo));
sscanf(p, "%100s", command);
command[sizeof(command)-1] = '\0';
while (charcommand_info[i].type != CharCommand_Unknown) {
if (strcmpi(command+1, charcommand_info[i].command+1) == 0 && level >= charcommand_info[i].level) {
p[0] = charcommand_info[i].command[0]; // set correct first symbol for after.
break;
}
i++;
}
if (charcommand_info[i].type == CharCommand_Unknown) {
// doesn't return Unknown if player is normal player (display the text, not display: unknown command)
if (level == 0)
return CharCommand_None;
else
return CharCommand_Unknown;
}
memcpy(info, &charcommand_info[i], sizeof charcommand_info[i]);
} else {
return CharCommand_None;
}
return info->type;
}
/*==========================================
*
*------------------------------------------
*/
static CharCommandInfo* get_charcommandinfo_byname(const char* name) {
int i;
for (i = 0; charcommand_info[i].type != CharCommand_Unknown; i++)
if (strcmpi(charcommand_info[i].command + 1, name) == 0)
return &charcommand_info[i];
return NULL;
}
/*==========================================
*
*------------------------------------------
*/
int charcommand_config_read(const char *cfgName) {
char line[1024], w1[1024], w2[1024];
CharCommandInfo* p;
FILE* fp;
if ((fp = fopen(cfgName, "r")) == NULL) {
printf("Char commands configuration file not found: %s\n", cfgName);
return 1;
}
while (fgets(line, sizeof(line)-1, fp)) {
if (line[0] == '/' && line[1] == '/')
continue;
if (sscanf(line, "%1023[^:]:%1023s", w1, w2) != 2)
continue;
p = get_charcommandinfo_byname(w1);
if (p != NULL) {
p->level = atoi(w2);
if (p->level > 100)
p->level = 100;
else if (p->level < 0)
p->level = 0;
}
if (strcmpi(w1, "import") == 0)
charcommand_config_read(w2);
else if (strcmpi(w1, "command_symbol") == 0 && w2[0] > 31 &&
w2[0] != '/' && // symbol of standard ragnarok GM commands
w2[0] != '%' && // symbol of party chat speaking
w2[0] != '@') // symbol for @commands
command_symbol = w2[0];
}
fclose(fp);
return 0;
}
/*==========================================
// # command processing functions
*------------------------------------------
*/
int
charcommand_test (const int fd, struct map_session_data* sd,
const char* command, const char* message) {
clif_displaymessage(fd,"Works!");
return 0;
}
/*==========================================
* �ΏۃL�����N�^�[��]�E������ upper�w��œ]����{�q���\
*------------------------------------------
*/
int charcommand_jobchange(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
char character[100];
struct map_session_data* pl_sd;
int job = 0, upper = -1;
memset(character, '\0', sizeof(character));
if (!message || !*message) {
clif_displaymessage(fd, "Please, enter a job and a player name (usage: #job/#jobchange <job ID> <char name>).");
return -1;
}
if (sscanf(message, "%d %d %99[^\n]", &job, &upper, character) < 3) { //upper�w�肵�Ă���
upper = -1;
if (sscanf(message, "%d %99[^\n]", &job, character) < 2) { //upper�w�肵�ĂȂ���ɉ�������Ȃ�
clif_displaymessage(fd, "Please, enter a job and a player name (usage: #job/#jobchange <job ID> <char name>).");
return -1;
}
}
if ((pl_sd = map_nick2sd(character)) != NULL) {
if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can change job only to lower or same level
if ((job >= 0 && job < MAX_PC_CLASS)) {
// fix pecopeco display
if ((job != 13 && job != 21 && job != 4014 && job != 4022)) {
if (pc_isriding(sd)) {
if (pl_sd->status.class == 13)
pl_sd->status.class = pl_sd->view_class = 7;
if (pl_sd->status.class == 21)
pl_sd->status.class = pl_sd->view_class = 14;
if (pl_sd->status.class == 4014)
pl_sd->status.class = pl_sd->view_class = 4008;
if (pl_sd->status.class == 4022)
pl_sd->status.class = pl_sd->view_class = 4015;
pl_sd->status.option &= ~0x0020;
clif_changeoption(&pl_sd->bl);
pc_calcstatus(pl_sd, 0);
}
} else {
if (!pc_isriding(sd)) {
if (job == 13)
job = 7;
if (job == 21)
job = 14;
if (job == 4014)
job = 4008;
if (job == 4022)
job = 4015;
}
}
if (pc_jobchange(pl_sd, job, upper) == 0)
clif_displaymessage(fd, msg_table[48]); // Character's job changed.
else {
clif_displaymessage(fd, msg_table[192]); // Impossible to change the character's job.
return -1;
}
} else {
clif_displaymessage(fd, msg_table[49]); // Invalid job ID.
return -1;
}
} else {
clif_displaymessage(fd, msg_table[81]); // Your GM level don't authorise you to do this action on this player.
return -1;
}
} else {
clif_displaymessage(fd, msg_table[3]); // Character not found.
return -1;
}
return 0;
}
/*==========================================
*
*------------------------------------------
*/
int charcommand_petrename(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
char character[100];
struct map_session_data *pl_sd;
memset(character, '\0', sizeof(character));
if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) {
clif_displaymessage(fd, "Please, enter a player name (usage: #petrename <char name>).");
return -1;
}
if ((pl_sd = map_nick2sd(character)) != NULL) {
if (pl_sd->status.pet_id > 0 && pl_sd->pd) {
if (pl_sd->pet.rename_flag != 0) {
pl_sd->pet.rename_flag = 0;
intif_save_petdata(pl_sd->status.account_id, &pl_sd->pet);
clif_send_petstatus(pl_sd);
clif_displaymessage(fd, msg_table[189]); // This player can now rename his/her pet.
} else {
clif_displaymessage(fd, msg_table[190]); // This player can already rename his/her pet.
return -1;
}
} else {
clif_displaymessage(fd, msg_table[191]); // Sorry, but this player has no pet.
return -1;
}
} else {
clif_displaymessage(fd, msg_table[3]); // Character not found.
return -1;
}
return 0;
}
|