From 06c100e280e7174095ce40745231f14326862010 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 19 Jul 2017 19:14:11 +0300 Subject: Load commands for each group from groups.xml --- src/CMakeLists.txt | 2 + src/Makefile.am | 1 + src/enums/resources/servercommandtype.h | 278 +----------------------------- src/resources/db/groupdb.cpp | 98 +++++++++++ src/resources/servercommands.inc | 288 ++++++++++++++++++++++++++++++++ 5 files changed, 398 insertions(+), 269 deletions(-) create mode 100644 src/resources/servercommands.inc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de4ee210c..65d84e1b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -834,6 +834,7 @@ SET(SRCS resources/db/unitsdb.h resources/db/weaponsdb.cpp resources/db/weaponsdb.h + resources/servercommands.inc resources/soundeffect.cpp resources/soundeffect.h resources/soundinfo.h @@ -1793,6 +1794,7 @@ SET(DYE_CMD_SRCS resources/sdlmusic.cpp resources/sdlmusic.h resources/skillconsts.h + resources/servercommands.inc resources/soundeffect.cpp resources/soundeffect.h resources/image/subimage.cpp diff --git a/src/Makefile.am b/src/Makefile.am index fe9a52b3d..ad74aa51a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -549,6 +549,7 @@ BASE_SRC += events/actionevent.h \ enums/resources/skill/skillsettype.h \ enums/resources/skill/skilltype.h \ enums/resources/skill/skilltype2.h \ + resources/servercommands.inc \ resources/soundeffect.cpp \ resources/soundeffect.h \ resources/soundinfo.h \ diff --git a/src/enums/resources/servercommandtype.h b/src/enums/resources/servercommandtype.h index 81ea79bf8..a22408709 100644 --- a/src/enums/resources/servercommandtype.h +++ b/src/enums/resources/servercommandtype.h @@ -23,279 +23,19 @@ #include "enums/simpletypes/enumdefines.h" +#define servercommandFirst(name) name = 0, +#define servercommand(name) name, +#define servercommand2(name1, name2) name1, + enumStart(ServerCommandType) { -// Hercules commands - warp = 0, - where, - jumpto, - jump, - who, - who2, - who3, - whomap, - whomap2, - whomap3, - whogm, - save, - load, - speed, - storage, - guildstorage, - option, - hide, - jobchange, - kill, - alive, - kami, - kamib, - kamic, - lkami, - heal, - item, - item2, - itembound, - itembound2, - itemreset, - clearstorage, - cleargstorage, - clearcart, - blvl, - jlvl, - help, - pvpoff, - pvpon, - gvgoff, - gvgon, - model, - go, - monster, - monstersmall, - monsterbig, - killmonster, - killmonster2, - refine, - produce, - memo, - gat, - displaystatus, - stpoint, - skpoint, - zeny, - str, - agi, - vit, - int_, - dex, - luk, - glvl, - makeegg, - hatch, - petfriendly, - pethungry, - petrename, - recall, - night, - day, - doom, - doommap, - raise, - raisemap, - kick, - kickall, - allskill, - questskill, - lostskill, - spiritball, - party, - guild, - breakguild, - agitstart, - agitend, - mapexit, - idsearch, - broadcast, - localbroadcast, - recallall, - reloaditemdb, - reloadmobdb, - reloadskilldb, - reloadscript, - reloadatcommand, - reloadbattleconf, - reloadstatusdb, - reloadpcdb, - mapinfo, - dye, - hairstyle, - haircolor, - allstats, - block, - ban, - charban, - unblock, - charunban, - unban, - mount, - guildspy, - partyspy, - repairall, - guildrecall, - partyrecall, - nuke, - shownpc, - hidenpc, - loadnpc, - unloadnpc, - time, - jail, - unjail, - jailfor, - jailtime, - disguise, - undisguise, - email, - effect, - follow, - addwarp, - skillon, - skilloff, - killer, - npcmove, - killable, - dropall, - storeall, - skillid, - useskill, - displayskill, - snow, - sakura, - clouds, - clouds2, - fog, - fireworks, - leaves, - summon, - adjgroup, - trade, - send, - setbattleflag, - unmute, - clearweather, - uptime, - changesex, - mute, - refresh, - refreshall, - identify, - misceffect, - mobsearch, - cleanmap, - cleanarea, - npctalk, - pettalk, - users, - reset, - skilltree, - marry, - divorce, - sound, - undisguiseall, - disguiseall, - changelook, - autoloot, - alootid, - autoloottype, - mobinfo, - exp, - version, - mutearea, - rates, - iteminfo, - whodrops, - whereis, - mapflag, - me, - monsterignore, - fakename, - size, - showexp, - showzeny, - showdelay, - autotrade, - changegm, - changeleader, - partyoption, - invite, - duel, - leave, - accept, - reject, - clone, - slaveclone, - evilclone, - tonpc, - commands, - noask, - request, - homlevel, - homevolution, - hommutate, - makehomun, - homfriendly, - homhungry, - homtalk, - hominfo, - homstats, - homshuffle, - showmobs, - feelreset, - auction, - mail, - noks, - allowks, - cash, - points, - agitstart2, - agitend2, - skreset, - streset, - storagelist, - cartlist, - itemlist, - stats, - delitem, - charcommands, - font, - accinfo, - set, - reloadquestdb, - undisguiseguild, - disguiseguild, - sizeall, - sizeguild, - addperm, - rmvperm, - unloadnpcfile, - cart, - cashmount, - join, - channel, - fontcolor, - searchstore, - costume, - skdebug, - cddebug, - lang, - bodystyle, - setskill, - -// Evol commands - slide, - serverexit, - +#include "resources/servercommands.inc" Max } enumEnd(ServerCommandType); +#undef servercommandFirst +#undef servercommand +#undef servercommand2 + #endif // ENUMS_RESOURCES_SERVERCOMMANDTYPE_H diff --git a/src/resources/db/groupdb.cpp b/src/resources/db/groupdb.cpp index 461a26ed4..f3e2852e0 100644 --- a/src/resources/db/groupdb.cpp +++ b/src/resources/db/groupdb.cpp @@ -47,6 +47,103 @@ void GroupDb::load() mLoaded = true; } +#define servercommandFirst(name) \ + if (str == #name) \ + return ServerCommandType::name; \ + else +#define servercommand(name) \ + if (str == #name) \ + return ServerCommandType::name; \ + else +#define servercommand2(name1, name2) \ + if (str == #name2) \ + return ServerCommandType::name1; \ + else + +static ServerCommandTypeT parseName(const std::string &str, + const int id) +{ +#include "resources/servercommands.inc" + { + reportAlways("GroupsDb: unknown command name: '%s' in group id '%d'.", + str.c_str(), + id); + } + + return ServerCommandType::Max; +} + +#undef servercommandFirst +#undef servercommand +#undef servercommand2 + +static ServerCommandEnable::Type parseUseFlag(const std::string &str, + const int id) +{ + if (str == "self") + { + return ServerCommandEnable::Self; + } + else if (str == "other") + { + return ServerCommandEnable::Other; + } + else if (str == "both") + { + return ServerCommandEnable::Both; + } + else + { + reportAlways("GroupsDb: unknown use flag: '%s' in group id '%d'." + "Possible values 'self', 'other', 'both'.", + str.c_str(), + id); + return ServerCommandEnable::No; + } +} + +static void loadCommands(XmlNodePtr rootNode, + const int id, + GroupInfo *groupInfo) A_NONNULL(3); +static void loadCommands(XmlNodePtr rootNode, + const int id, + GroupInfo *groupInfo) +{ + for_each_xml_child_node(node, rootNode) + { + if (xmlNameEqual(node, "command")) + { + const std::string nameStr = XML::getProperty(node, + "name", + ""); + const std::string useStr = XML::getProperty(node, + "use", + ""); + ServerCommandTypeT name = parseName(nameStr, id); + if (name == ServerCommandType::Max) + continue; + ServerCommandEnable::Type useFlag = parseUseFlag(useStr, id); + if (useFlag == ServerCommandEnable::No) + continue; + groupInfo->mCommands[CAST_SIZE(name)] = useFlag; + } + } +} + +static void loadSubNodes(XmlNodePtr groupNode, + const int id, + GroupInfo *groupInfo) A_NONNULL(3); +static void loadSubNodes(XmlNodePtr groupNode, + const int id, + GroupInfo *groupInfo) +{ + for_each_xml_child_node(node, groupNode) + { + if (xmlNameEqual(node, "commands")) + loadCommands(node, id, groupInfo); + } +} + void GroupDb::loadXmlFile(const std::string &fileName, const SkipError skipError) { @@ -115,6 +212,7 @@ void GroupDb::loadXmlFile(const std::string &fileName, group->showBadge = XML::getBoolProperty(node, "showBadge", false); + loadSubNodes(node, id, group); } } } diff --git a/src/resources/servercommands.inc b/src/resources/servercommands.inc new file mode 100644 index 000000000..a8c9efa5b --- /dev/null +++ b/src/resources/servercommands.inc @@ -0,0 +1,288 @@ +/* + * The ManaPlus Client + * Copyright (C) 2017 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Hercules commands +servercommandFirst(warp) +servercommand(where) +servercommand(jumpto) +servercommand(jump) +servercommand(who) +servercommand(who2) +servercommand(who3) +servercommand(whomap) +servercommand(whomap2) +servercommand(whomap3) +servercommand(whogm) +servercommand(save) +servercommand(load) +servercommand(speed) +servercommand(storage) +servercommand(guildstorage) +servercommand(option) +servercommand(hide) +servercommand(jobchange) +servercommand(kill) +servercommand(alive) +servercommand(kami) +servercommand(kamib) +servercommand(kamic) +servercommand(lkami) +servercommand(heal) +servercommand(item) +servercommand(item2) +servercommand(itembound) +servercommand(itembound2) +servercommand(itemreset) +servercommand(clearstorage) +servercommand(cleargstorage) +servercommand(clearcart) +servercommand(blvl) +servercommand(jlvl) +servercommand(help) +servercommand(pvpoff) +servercommand(pvpon) +servercommand(gvgoff) +servercommand(gvgon) +servercommand(model) +servercommand(go) +servercommand(monster) +servercommand(monstersmall) +servercommand(monsterbig) +servercommand(killmonster) +servercommand(killmonster2) +servercommand(refine) +servercommand(produce) +servercommand(memo) +servercommand(gat) +servercommand(displaystatus) +servercommand(stpoint) +servercommand(skpoint) +servercommand(zeny) +servercommand(str) +servercommand(agi) +servercommand(vit) +servercommand2(int_, "int") +servercommand(dex) +servercommand(luk) +servercommand(glvl) +servercommand(makeegg) +servercommand(hatch) +servercommand(petfriendly) +servercommand(pethungry) +servercommand(petrename) +servercommand(recall) +servercommand(night) +servercommand(day) +servercommand(doom) +servercommand(doommap) +servercommand(raise) +servercommand(raisemap) +servercommand(kick) +servercommand(kickall) +servercommand(allskill) +servercommand(questskill) +servercommand(lostskill) +servercommand(spiritball) +servercommand(party) +servercommand(guild) +servercommand(breakguild) +servercommand(agitstart) +servercommand(agitend) +servercommand(mapexit) +servercommand(idsearch) +servercommand(broadcast) +servercommand(localbroadcast) +servercommand(recallall) +servercommand(reloaditemdb) +servercommand(reloadmobdb) +servercommand(reloadskilldb) +servercommand(reloadscript) +servercommand(reloadatcommand) +servercommand(reloadbattleconf) +servercommand(reloadstatusdb) +servercommand(reloadpcdb) +servercommand(mapinfo) +servercommand(dye) +servercommand(hairstyle) +servercommand(haircolor) +servercommand(allstats) +servercommand(block) +servercommand(ban) +servercommand(charban) +servercommand(unblock) +servercommand(charunban) +servercommand(unban) +servercommand(mount) +servercommand(guildspy) +servercommand(partyspy) +servercommand(repairall) +servercommand(guildrecall) +servercommand(partyrecall) +servercommand(nuke) +servercommand(shownpc) +servercommand(hidenpc) +servercommand(loadnpc) +servercommand(unloadnpc) +servercommand(time) +servercommand(jail) +servercommand(unjail) +servercommand(jailfor) +servercommand(jailtime) +servercommand(disguise) +servercommand(undisguise) +servercommand(email) +servercommand(effect) +servercommand(follow) +servercommand(addwarp) +servercommand(skillon) +servercommand(skilloff) +servercommand(killer) +servercommand(npcmove) +servercommand(killable) +servercommand(dropall) +servercommand(storeall) +servercommand(skillid) +servercommand(useskill) +servercommand(displayskill) +servercommand(snow) +servercommand(sakura) +servercommand(clouds) +servercommand(clouds2) +servercommand(fog) +servercommand(fireworks) +servercommand(leaves) +servercommand(summon) +servercommand(adjgroup) +servercommand(trade) +servercommand(send) +servercommand(setbattleflag) +servercommand(unmute) +servercommand(clearweather) +servercommand(uptime) +servercommand(changesex) +servercommand(mute) +servercommand(refresh) +servercommand(refreshall) +servercommand(identify) +servercommand(misceffect) +servercommand(mobsearch) +servercommand(cleanmap) +servercommand(cleanarea) +servercommand(npctalk) +servercommand(pettalk) +servercommand(users) +servercommand(reset) +servercommand(skilltree) +servercommand(marry) +servercommand(divorce) +servercommand(sound) +servercommand(undisguiseall) +servercommand(disguiseall) +servercommand(changelook) +servercommand(autoloot) +servercommand(alootid) +servercommand(autoloottype) +servercommand(mobinfo) +servercommand(exp) +servercommand(version) +servercommand(mutearea) +servercommand(rates) +servercommand(iteminfo) +servercommand(whodrops) +servercommand(whereis) +servercommand(mapflag) +servercommand(me) +servercommand(monsterignore) +servercommand(fakename) +servercommand(size) +servercommand(showexp) +servercommand(showzeny) +servercommand(showdelay) +servercommand(autotrade) +servercommand(changegm) +servercommand(changeleader) +servercommand(partyoption) +servercommand(invite) +servercommand(duel) +servercommand(leave) +servercommand(accept) +servercommand(reject) +servercommand(clone) +servercommand(slaveclone) +servercommand(evilclone) +servercommand(tonpc) +servercommand(commands) +servercommand(noask) +servercommand(request) +servercommand(homlevel) +servercommand(homevolution) +servercommand(hommutate) +servercommand(makehomun) +servercommand(homfriendly) +servercommand(homhungry) +servercommand(homtalk) +servercommand(hominfo) +servercommand(homstats) +servercommand(homshuffle) +servercommand(showmobs) +servercommand(feelreset) +servercommand(auction) +servercommand(mail) +servercommand(noks) +servercommand(allowks) +servercommand(cash) +servercommand(points) +servercommand(agitstart2) +servercommand(agitend2) +servercommand(skreset) +servercommand(streset) +servercommand(storagelist) +servercommand(cartlist) +servercommand(itemlist) +servercommand(stats) +servercommand(delitem) +servercommand(charcommands) +servercommand(font) +servercommand(accinfo) +servercommand(set) +servercommand(reloadquestdb) +servercommand(undisguiseguild) +servercommand(disguiseguild) +servercommand(sizeall) +servercommand(sizeguild) +servercommand(addperm) +servercommand(rmvperm) +servercommand(unloadnpcfile) +servercommand(cart) +servercommand(cashmount) +servercommand(join) +servercommand(channel) +servercommand(fontcolor) +servercommand(searchstore) +servercommand(costume) +servercommand(skdebug) +servercommand(cddebug) +servercommand(lang) +servercommand(bodystyle) +servercommand(setskill) + +// Evol commands +servercommand(slide) +servercommand(serverexit) -- cgit v1.2.3-60-g2f50