?? atcommand.c
字號:
//atcommand.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "socket.h"
#include "timer.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 "atcommand.h"
#define OPTION_HIDE 0x40
#define STATE_BLIND 0x10
static char msg_table[200][1024]; /* Server message */
#define ATCOMMAND_FUNC(x) int atcommand_ ## x \
(const int fd, struct map_session_data* sd, \
const char* command, const char* message)
//ATCOMMAND_FUNC(broadcast);
//ATCOMMAND_FUNC(localbroadcast);
ATCOMMAND_FUNC(rurap);
ATCOMMAND_FUNC(rura);
ATCOMMAND_FUNC(where);
ATCOMMAND_FUNC(jumpto);
ATCOMMAND_FUNC(jump);
ATCOMMAND_FUNC(who);
ATCOMMAND_FUNC(save);
ATCOMMAND_FUNC(load);
ATCOMMAND_FUNC(speed);
ATCOMMAND_FUNC(storage);
ATCOMMAND_FUNC(guildstorage);
ATCOMMAND_FUNC(option);
ATCOMMAND_FUNC(hide);
ATCOMMAND_FUNC(jobchange);
ATCOMMAND_FUNC(die);
ATCOMMAND_FUNC(kill);
ATCOMMAND_FUNC(alive);
ATCOMMAND_FUNC(kami);
ATCOMMAND_FUNC(heal);
ATCOMMAND_FUNC(item);
ATCOMMAND_FUNC(item2);
ATCOMMAND_FUNC(itemreset);
ATCOMMAND_FUNC(itemcheck);
ATCOMMAND_FUNC(baselevelup);
ATCOMMAND_FUNC(joblevelup);
ATCOMMAND_FUNC(help);
ATCOMMAND_FUNC(gm);
ATCOMMAND_FUNC(pvpoff);
ATCOMMAND_FUNC(pvpon);
ATCOMMAND_FUNC(gvgoff);
ATCOMMAND_FUNC(gvgon);
ATCOMMAND_FUNC(model);
ATCOMMAND_FUNC(go);
ATCOMMAND_FUNC(monster);
ATCOMMAND_FUNC(killmonster);
ATCOMMAND_FUNC(killmonster2);
ATCOMMAND_FUNC(refine);
ATCOMMAND_FUNC(produce);
ATCOMMAND_FUNC(memo);
ATCOMMAND_FUNC(gat);
ATCOMMAND_FUNC(packet);
ATCOMMAND_FUNC(statuspoint);
ATCOMMAND_FUNC(skillpoint);
ATCOMMAND_FUNC(zeny);
ATCOMMAND_FUNC(param);
ATCOMMAND_FUNC(guildlevelup);
ATCOMMAND_FUNC(makepet);
ATCOMMAND_FUNC(petfriendly);
ATCOMMAND_FUNC(pethungry);
ATCOMMAND_FUNC(petrename);
ATCOMMAND_FUNC(recall);
ATCOMMAND_FUNC(character_job);
ATCOMMAND_FUNC(revive);
ATCOMMAND_FUNC(character_stats);
ATCOMMAND_FUNC(character_option);
ATCOMMAND_FUNC(character_save);
ATCOMMAND_FUNC(night);
ATCOMMAND_FUNC(day);
ATCOMMAND_FUNC(doom);
ATCOMMAND_FUNC(doommap);
ATCOMMAND_FUNC(raise);
ATCOMMAND_FUNC(raisemap);
ATCOMMAND_FUNC(character_baselevel);
ATCOMMAND_FUNC(character_joblevel);
ATCOMMAND_FUNC(kick);
ATCOMMAND_FUNC(kickall);
ATCOMMAND_FUNC(allskill);
ATCOMMAND_FUNC(questskill);
ATCOMMAND_FUNC(lostskill);
ATCOMMAND_FUNC(spiritball);
ATCOMMAND_FUNC(party);
ATCOMMAND_FUNC(guild);
ATCOMMAND_FUNC(agitstart);
ATCOMMAND_FUNC(agitend);
static AtCommandInfo atcommand_info[] = {
{ AtCommand_RuraP, "@rura+", 0, atcommand_rurap },
{ AtCommand_Rura, "@rura", 0, atcommand_rura },
{ AtCommand_Where, "@where", 0, atcommand_where },
{ AtCommand_JumpTo, "@jumpto", 0, atcommand_jumpto },
{ AtCommand_Jump, "@jump", 0, atcommand_jump },
{ AtCommand_Who, "@who", 0, atcommand_who },
{ AtCommand_Save, "@save", 0, atcommand_save },
{ AtCommand_Load, "@load", 0, atcommand_load },
{ AtCommand_Speed, "@speed", 0, atcommand_speed },
{ AtCommand_Storage, "@storage", 0, atcommand_storage },
{ AtCommand_GuildStorage, "@gstorage", 0, atcommand_guildstorage },
{ AtCommand_Option, "@option", 0, atcommand_option },
{ AtCommand_Hide, "@hide", 0, atcommand_hide },
{ AtCommand_JobChange, "@jobchange", 0, atcommand_jobchange },
{ AtCommand_Die, "@die", 0, atcommand_die },
{ AtCommand_Kill, "@kill", 0, atcommand_kill },
{ AtCommand_Alive, "@alive", 0, atcommand_alive },
{ AtCommand_Kami, "@kami", 0, atcommand_kami },
{ AtCommand_KamiB, "@kamib", 0, atcommand_kami },
{ AtCommand_Heal, "@heal", 0, atcommand_heal },
{ AtCommand_Item, "@item", 0, atcommand_item },
{ AtCommand_Item2, "@item2", 0, atcommand_item2 },
{ AtCommand_ItemReset, "@itemreset", 0, atcommand_itemreset },
{ AtCommand_ItemCheck, "@itemcheck", 0, atcommand_itemcheck },
{ AtCommand_BaseLevelUp, "@lvup", 0, atcommand_baselevelup },
{ AtCommand_JobLevelUp, "@joblvup", 0, atcommand_joblevelup },
{ AtCommand_H, "@h", 0, atcommand_help },
{ AtCommand_Help, "@help", 0, atcommand_help },
{ AtCommand_GM, "@gm", 0, atcommand_gm },
{ AtCommand_PvPOff, "@pvpoff", 0, atcommand_pvpoff },
{ AtCommand_PvPOn, "@pvpon", 0, atcommand_pvpon },
{ AtCommand_GvGOff, "@gvgoff", 0, atcommand_gvgoff },
{ AtCommand_GvGOn, "@gvgon", 0, atcommand_gvgon },
{ AtCommand_Model, "@model", 0, atcommand_model },
{ AtCommand_Go, "@go", 0, atcommand_go },
{ AtCommand_Monster, "@monster", 0, atcommand_monster },
{ AtCommand_KillMonster, "@killmonster", 0, atcommand_killmonster },
{ AtCommand_KillMonster2, "@killmonster2", 0,
atcommand_killmonster2 },
{ AtCommand_Refine, "@refine", 0, atcommand_refine },
{ AtCommand_Produce, "@produce", 0, atcommand_produce },
{ AtCommand_Memo, "@memo", 0, atcommand_memo },
{ AtCommand_GAT, "@gat", 0, atcommand_gat },
{ AtCommand_Packet, "@packet", 0, atcommand_packet },
{ AtCommand_StatusPoint, "@stpoint", 0, atcommand_statuspoint },
{ AtCommand_SkillPoint, "@skpoint", 0, atcommand_skillpoint },
{ AtCommand_Zeny, "@zeny", 0, atcommand_zeny },
{ AtCommand_Param, "@param", 0, atcommand_param },
{ AtCommand_Strength, "@str", 0, atcommand_param },
{ AtCommand_Agility, "@agi", 0, atcommand_param },
{ AtCommand_Vitality, "@vit", 0, atcommand_param },
{ AtCommand_Intelligence, "@int", 0, atcommand_param },
{ AtCommand_Dexterity, "@dex", 0, atcommand_param },
{ AtCommand_Luck, "@luk", 0, atcommand_param },
{ AtCommand_GuildLevelUp, "@guildlvup", 0, atcommand_guildlevelup },
{ AtCommand_MakePet, "@makepet", 0, atcommand_makepet },
{ AtCommand_PetFriendly, "@petfriendly", 0, atcommand_petfriendly },
{ AtCommand_PetHungry, "@pethungry", 0, atcommand_pethungry },
{ AtCommand_PetRename, "@petrename", 0, atcommand_petrename },
{ AtCommand_Recall, "@recall", 0, atcommand_recall },
{ AtCommand_CharacterJob, "@charjob", 0, atcommand_character_job },
{ AtCommand_Revive, "@revive", 0, atcommand_revive },
{ AtCommand_CharacterStats, "@charstats", 0,
atcommand_character_stats },
{ AtCommand_CharacterOption, "@charoption", 0,
atcommand_character_option },
{ AtCommand_CharacterSave, "@charsave", 0, atcommand_character_save },
{ AtCommand_Night, "@night", 0, atcommand_night },
{ AtCommand_Day, "@day", 0, atcommand_day },
{ AtCommand_Doom, "@doom", 0, atcommand_doom },
{ AtCommand_DoomMap, "@doommap", 0, atcommand_doommap },
{ AtCommand_Raise, "@raise", 0, atcommand_raise },
{ AtCommand_RaiseMap, "@raisemap", 0, atcommand_raisemap },
{ AtCommand_CharacterBaseLevel, "@charbaselvl", 0,
atcommand_character_baselevel },
{ AtCommand_CharacterJobLevel, "@charjlvl", 0,
atcommand_character_joblevel },
{ AtCommand_Kick, "@kick", 0, atcommand_kick },
{ AtCommand_KickAll, "@kickall", 0, atcommand_kickall },
{ AtCommand_AllSkill, "@allskill", 0, atcommand_allskill },
{ AtCommand_QuestSkill, "@questskill", 0, atcommand_questskill },
{ AtCommand_LostSkill, "@lostskill", 0, atcommand_lostskill },
{ AtCommand_SpiritBall, "@spiritball", 0, atcommand_spiritball },
{ AtCommand_Party, "@party", 0, atcommand_party },
{ AtCommand_Guild, "@guild", 0, atcommand_guild },
{ AtCommand_AgitStart, "@agitstart", 0, atcommand_agitstart },
{ AtCommand_AgitEnd, "@agitend", 0, atcommand_agitend },
// add here
{ AtCommand_Broadcast, "@broadcast", 0, NULL },
{ AtCommand_LocalBroadcast, "@local_broadcast", 0, NULL },
{ AtCommand_Unknown, NULL, 0, NULL }
};
int get_atcommand_level(const AtCommandType type)
{
int i = 0;
for (i = 0; atcommand_info[i].type != AtCommand_None; i++)
if (atcommand_info[i].type == type)
return atcommand_info[i].level;
return 99;
}
AtCommandType
is_atcommand(const int fd, struct map_session_data* sd, const char* message)
{
const char* str = message;
int s_flag = 0;
AtCommandInfo info;
if (!message || !*message)
return AtCommand_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 AtCommand_None;
AtCommandType type = atcommand(pc_isGM(sd), str, &info);
if (type != AtCommand_None) {
char command[25];
char output[100];
const char* p = str;
memset(command, '\0', sizeof command);
while (*p && !isspace(*p))
p++;
if (p - str > sizeof command) // too long
return AtCommand_Unknown;
strncpy(command, str,
(p - str > sizeof command) ? sizeof command : p - str);
if (isspace(*p))
p++;
if (type == AtCommand_Unknown) {
snprintf(output, sizeof output, "%s is Unknown Command.", command);
clif_displaymessage(fd, output);
} else {
if (info.proc(fd, sd, command, p) != 0) {
// 堎忢廔椆
snprintf(output, sizeof output, "%s failed.", command);
clif_displaymessage(fd, output);
}
}
return info.type;
}
return AtCommand_None;
}
AtCommandType
atcommand(
const int level, const char* message, struct AtCommandInfo* info)
{
const char* p = message;
if (!info)
return AtCommand_None;
if (!p || !*p) {
fprintf(stderr, "at command message is empty\n");
return AtCommand_None;
}
if (!*p || *p != '@')
return AtCommand_None;
memset(info, 0, sizeof(AtCommandInfo));
{
char command[101];
int i = 0;
sscanf(p, "%100s", command);
command[100] = '\0';
while (atcommand_info[i].type != AtCommand_Unknown) {
if (strcmpi(command, atcommand_info[i].command) == 0 &&
level >= atcommand_info[i].level)
break;
i++;
}
if (atcommand_info[i].type == AtCommand_Unknown)
return AtCommand_Unknown;
memcpy(info, &atcommand_info[i], sizeof atcommand_info[i]);
}
return info->type;
}
//struct Atcommand_Config atcommand_config;
static int atkillmonster_sub(struct block_list *bl,va_list ap)
{
int flag = va_arg(ap,int);
if (flag)
mob_damage(NULL,(struct mob_data *)bl,((struct mob_data *)bl)->hp,2);
else
mob_delete((struct mob_data *)bl);
return 0;
}
/* Read Message Data */
int msg_config_read(const char *cfgName)
{
int i,msg_number;
char line[1024],w1[512],w2[1024];
FILE *fp;
fp=fopen(cfgName,"r");
if (fp==NULL) {
printf("file not found: %s\n",cfgName);
return 1;
}
while(fgets(line,1020,fp)) {
if (line[0] == '/' && line[1] == '/')
continue;
i=sscanf(line,"%d: %[^\r\n]",&msg_number,w2);
if (i!=2) {
if (sscanf(line,"%s: %[^\r\n]",w1,w2) !=2)
continue;
if (strcmpi(w1,"import") == 0) {
msg_config_read(w2);
}
continue;
}
if (msg_number>=0&&msg_number<=200)
strcpy(msg_table[msg_number],w2);
//printf("%d:%s\n",msg_number,msg);
}
fclose(fp);
return 0;
}
/*
static AtCommandInfo* getAtCommandInfoByType(const AtCommandType type)
{
int i = 0;
for (i = 0; atcommand_info[i].type != AtCommand_None; i++)
if (atcommand_info[i].type == type)
return &atcommand_info[i];
return NULL;
}
*/
static AtCommandInfo*
get_atcommandinfo_byname(const char* name)
{
int i = 0;
for (i = 0; atcommand_info[i].type != AtCommand_Unknown; i++)
if (strcmpi(atcommand_info[i].command + 1, name) == 0)
return &atcommand_info[i];
return NULL;
}
int atcommand_config_read(const char *cfgName)
{
int i;
char line[1024],w1[1024],w2[1024];
if (battle_config.atc_gmonly > 0) {
AtCommandInfo* p = NULL;
FILE* fp = fopen(cfgName,"r");
if (fp == NULL) {
printf("file not found: %s\n",cfgName);
return 1;
}
while (fgets(line, 1020, fp)) {
if (line[0] == '/' && line[1] == '/')
continue;
i=sscanf(line,"%1020[^:]:%1020s",w1,w2);
if (i!=2)
continue;
p = get_atcommandinfo_byname(w1);
if (p != NULL)
p->level = atoi(w2);
if (strcmpi(w1, "import") == 0)
atcommand_config_read(w2);
}
fclose(fp);
}
return 0;
}
// @ command 張棟娭悢孮
// @rura+
int
atcommand_rurap(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
char map[100];
char character[100];
int x = 0, y = 0;
struct map_session_data *pl_sd = NULL;
if (!message || !*message)
return -1;
memset(character, '\0', sizeof character);
if (sscanf(message, "%99s %d %d %99[^\n]", map, &x, &y, character) < 4)
return -1;
pl_sd = map_nick2sd(character);
if (pl_sd == NULL) {
clif_displaymessage(fd, msg_table[3]);
return -1;
}
if (pc_isGM(sd) > pc_isGM(pl_sd)) {
if (x >= 0 && x < 400 && y >= 0 && y < 400) {
if (pc_setpos(pl_sd, map, x, y, 3) == 0) {
clif_displaymessage(pl_sd->fd, msg_table[0]);
} else {
clif_displaymessage(fd, msg_table[1]);
}
} else {
clif_displaymessage(fd,msg_table[2]);
}
}
return 0;
}
// @rura
int
atcommand_rura(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
char map[100];
int x = 0, y = 0;
if (!message || !*message)
return -1;
if (sscanf(message, "%99s %d %d", map, &x, &y) < 1)
return -1;
if (x >= 0 && x < 400 && y >= 0 && y < 400) {
clif_displaymessage(fd,
(pc_setpos((struct map_session_data*)sd, map, x, y, 3) == 0) ?
msg_table[0] : msg_table[1]);
} else {
clif_displaymessage(fd, msg_table[2]);
}
return 0;
}
int
atcommand_where(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
char character[100];
char output[200];
if (!message || !*message)
return -1;
memset(character, '\0', sizeof character);
sscanf(message, "%99[^\n]", character);
struct map_session_data *pl_sd = map_nick2sd(character);
if (pl_sd == NULL) {
snprintf(output, sizeof output, "%s %d %d",
sd->mapname, sd->bl.x, sd->bl.y);
clif_displaymessage(fd, output);
return -1;
}
snprintf(output, sizeof output, "%s %s %d %d",
character, pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y);
clif_displaymessage(fd, output);
return 0;
}
int
atcommand_jumpto(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
char character[100];
struct map_session_data *pl_sd = NULL;
if (!message || !*message)
return -1;
memset(character, '\0', sizeof character);
if (sscanf(message, "%99[^\n]", character) < 1)
return -1;
if ((pl_sd = map_nick2sd(character)) != NULL) {
char output[200];
pc_setpos((struct map_session_data*)sd,
pl_sd->mapname, pl_sd->bl.x, pl_sd->bl.y, 3);
snprintf(output, sizeof output, msg_table[4], character);
clif_displaymessage(fd, output);
} else {
clif_displaymessage(fd, msg_table[3]);
}
return 0;
}
int
atcommand_jump(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
int x = 0, y = 0;
if (sscanf(message, "%d %d", &x, &y) < 2)
return -1;
if (x >= 0 && x < 400 && y >= 0 && y < 400) {
char output[200];
pc_setpos((struct map_session_data*)sd, (char*)sd->mapname, x, y, 3);
snprintf(output, sizeof output, msg_table[5], x, y);
clif_displaymessage(fd, output);
} else {
clif_displaymessage(fd, msg_table[2]);
}
return 0;
}
int
atcommand_who(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
struct map_session_data *pl_sd = NULL;
int i = 0;
for (i = 0; i < fd_max; i++) {
if (session[i] && (pl_sd = session[i]->session_data) &&
pl_sd->state.auth) {
clif_displaymessage(fd, pl_sd->status.name);
}
}
return 0;
}
int
atcommand_save(
const int fd, struct map_session_data* sd,
const char* command, const char* message)
{
pc_setsavepoint(sd, sd->mapname, sd->bl.x, sd->bl.y);
if (sd->status.pet_id > 0 && sd->pd)
intif_save_petdata(sd->status.account_id, &sd->pet);
pc_makesavestatus(sd);
chrif_save(sd);
storage_storage_save(sd);
clif_displaymessage(fd, msg_table[6]);
return 0;
}
int
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -