Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jul 23, 2006 7:37 pm Post subject: Help tweak and Notify Module |
|
|
|
|
The following is what I have done to make the ?help command customizeable and add a setting akin to subgame's alertcommand.
Grelminar, if you're willing, I think that these changes (or similar) should be added to 1.4.4.
The following is a monotone diff of the changed source files.
#
# old_revision [37c001d4a136fb2bfa9735ab638b726c2aafe99e]
#
# patch "src/core/core.mk"
# from [b4c07834487cc5ad73778a4a95ae562e5f985b26]
# to [55e2c67eaa275c335104bd3b70cfc1e76001fb2a]
#
# patch "src/core/help.c"
# from [340475817fbf2b3f8e987c53e62fda1c789148a9]
# to [60b135b940a98b4c0f0d7a5041b596135f0f1d22]
#
# patch "src/core/objects.c"
# from [ea0f52c22fddc49c0952406b90db81f85f291dda]
# to [d1130a6f2064c34f31256fa54aa1860cb511c14c]
#
# patch "src/core/playercmd.c"
# from [7180db4582ddc4a3504fc8ee0b09768f47d7d227]
# to [ddcf3f68f2aa48f1d304f0ae0dc5dde3901f4f14]
#
# patch "src/database/aliasdb.c"
# from [93c9d1e9a35be7892e8c3e704de08d0a047bf943]
# to [99cf7d179bf6c2938aabf92f175ea70d0a241b03]
#
============================================================
--- src/core/core.mk b4c07834487cc5ad73778a4a95ae562e5f985b26
+++ src/core/core.mk 55e2c67eaa275c335104bd3b70cfc1e76001fb2a
@@ -13,7 +13,7 @@
cfghelp filetrans quickfix \
freqowners arenaperm auth_prefix fake chatnet \
ap_multipub sendfile auth_ban auth_file obscene \
- deadlock $(unixsignal)
+ deadlock $(unixsignal) notify
# generated file for mapdata
$(call tobuild, sparse.inc): $(builddir) $(SCRIPTS)/gensparse.py $(SCRIPTS)/sparse_params.py
============================================================
--- src/core/help.c 340475817fbf2b3f8e987c53e62fda1c789148a9
+++ src/core/help.c 60b135b940a98b4c0f0d7a5041b596135f0f1d22
@@ -6,10 +6,14 @@
#include "asss.h"
#include "cfghelp.h"
+#define MAX_COMMAND_LENGTH 32
+
+local Imodman *mm;
local Ichat *chat;
local Icmdman *cmdman;
local Icfghelp *cfghelp;
+local char command_name[MAX_COMMAND_LENGTH];
local void do_cmd_help(Player *p, const char *cmd)
{
@@ -84,8 +88,8 @@
local helptext_t help_help =
"Targets: none\n"
"Args: <command name> | <setting name (section:key)>\n"
-"Displays help on a command or config file setting. Use {?help section:}\n"
-"to list known keys in that section. Use {?help :} to list known section\n"
+"Displays help on a command or config file setting. Use {section:}\n"
+"to list known keys in that section. Use {:} to list known section\n"
"names.\n";
local void Chelp(const char *tc, const char *params, Player *p, const Target *target)
@@ -95,7 +99,7 @@
params++;
if (params[0] == '\0')
- params = "help";
+ params = command_name;
if (strchr(params, ':'))
{
@@ -123,23 +127,47 @@
do_cmd_help(p, params);
}
+//set command_name. Defaults to ?help
+local void get_command_name()
+{
+ int set = 0;
+
+ Iconfig *cfg = mm->GetInterface(I_CONFIG, ALLARENAS);
+ if (cfg)
+ {
+ char *cmd = cfg->GetStr(GLOBAL, "Help", "CommandName");
+ if (cmd)
+ {
+ astrncpy(command_name, cmd, MAX_COMMAND_LENGTH);
+ set = 1;
+ }
-EXPORT int MM_help(int action, Imodman *mm, Arena *arena)
+ mm->ReleaseInterface(cfg);
+ }
+
+ if (!set)
+ astrncpy(command_name, "help", MAX_COMMAND_LENGTH);
+}
+
+EXPORT int MM_help(int action, Imodman *_mm, Arena *arena)
{
if (action == MM_LOAD)
{
+ mm = _mm;
chat = mm->GetInterface(I_CHAT, ALLARENAS);
cmdman = mm->GetInterface(I_CMDMAN, ALLARENAS);
cfghelp = mm->GetInterface(I_CFGHELP, ALLARENAS);
if (!chat || !cmdman)
return MM_FAIL;
- cmdman->AddCommand("help", Chelp, ALLARENAS, help_help);
+ get_command_name();
+
+ cmdman->AddCommand(command_name, Chelp, ALLARENAS, help_help);
return MM_OK;
}
else if (action == MM_UNLOAD)
{
- cmdman->RemoveCommand("help", Chelp, ALLARENAS);
+ cmdman->RemoveCommand(command_name, Chelp, ALLARENAS);
mm->ReleaseInterface(chat);
mm->ReleaseInterface(cmdman);
mm->ReleaseInterface(cfghelp);
============================================================
--- src/core/objects.c ea0f52c22fddc49c0952406b90db81f85f291dda
+++ src/core/objects.c d1130a6f2064c34f31256fa54aa1860cb511c14c
@@ -209,7 +209,7 @@
char id[256];
const char *image = delimcpy(id, params, sizeof(id), ' ');
if (image) Image(target, atoi(id), atoi(image));
- else chat->SendMessage(p, "Invalid syntax. Please read ?help objimage");
+ else chat->SendMessage(p, "Invalid syntax. Please read help for ?objimage");
}
local helptext_t objlayer_help =
@@ -251,7 +251,7 @@
char id[256];
const char *timer = delimcpy(id, params, sizeof(id), ' ');
if (timer) Timer(target, atoi(id), atoi(timer));
- else chat->SendMessage(p, "Invalid syntax. Please read ?help objtimer");
+ else chat->SendMessage(p, "Invalid syntax. Please read help for ?objtimer");
}
local helptext_t objmode_help =
============================================================
--- src/core/playercmd.c 7180db4582ddc4a3504fc8ee0b09768f47d7d227
+++ src/core/playercmd.c ddcf3f68f2aa48f1d304f0ae0dc5dde3901f4f14
@@ -1084,23 +1084,6 @@
}
-local helptext_t cheater_help =
-"Targets: none\n"
-"Args: <message>\n"
-"Sends the message to all online staff members.\n";
-
-local void Ccheater(const char *tc, const char *params, Player *p, const Target *target)
-{
- Arena *arena = p->arena;
- if (IS_ALLOWED(chat->GetPlayerChatMask(p), MSG_MODCHAT))
- {
- chat->SendModMessage("cheater {%s} %s: %s",
- arena->name, p->name, params);
- chat->SendMessage(p, "Message has been sent to online staff");
- }
-}
-
-
local helptext_t warn_help =
"Targets: player\n"
"Args: <message>\n"
@@ -2179,7 +2162,6 @@
CMD(aa)
CMD(z)
CMD(az)
- CMD(cheater)
CMD(warn)
CMD(netstats)
CMD(send)
============================================================
--- src/database/aliasdb.c 93c9d1e9a35be7892e8c3e704de08d0a047bf943
+++ src/database/aliasdb.c 99cf7d179bf6c2938aabf92f175ea70d0a241b03
@@ -194,7 +194,7 @@
if (!name || !*name)
{
- chat->SendMessage(p, "Invalid syntax. See ?help alias.");
+ chat->SendMessage(p, "Invalid syntax. See help for ?alias.");
return;
}
|
The following goes into core/notify.c, a new file.
/* dist: public */
#include "asss.h"
local Ichat *chat;
local Icmdman *cmd;
local Iconfig *cfg;
local Imodman *mm;
#define NOTIFY_COMMANDS_LENGTH 255
local char notify_commands[NOTIFY_COMMANDS_LENGTH];
local helptext_t notify_help =
"Targets: none\n"
"Args: <message>\n"
"Sends the message to all online staff members.\n";
local void Cnotify(const char *tc, const char *params, Player *p, const Target *target)
{
Arena *arena = p->arena;
if (IS_ALLOWED(chat->GetPlayerChatMask(p), MSG_MODCHAT))
{
chat->SendModMessage("%s {%s} %s: %s", tc,
arena->name, p->name, params);
chat->SendMessage(p, "Message has been sent to online staff");
}
}
local void register_commands()
{
char cmds_str[NOTIFY_COMMANDS_LENGTH];
char buf[64];
const char *tmp = NULL;
const char *cfg_result;
cfg_result = cfg->GetStr(GLOBAL, "Notify", "AlertCommand");
//default to ?cheater
if (!cfg_result)
astrncpy(notify_commands, "cheater", NOTIFY_COMMANDS_LENGTH);
else
astrncpy(notify_commands, cfg_result, NOTIFY_COMMANDS_LENGTH);
//make a copy, so that strsplit doesn't destory the original
astrncpy(cmds_str, notify_commands, NOTIFY_COMMANDS_LENGTH);
while (strsplit(cmds_str, " ,:;", buf, sizeof(buf), &tmp))
{
cmd->AddCommand(ToLowerStr(buf), Cnotify, ALLARENAS, notify_help);
}
}
local void unregister_commands()
{
char cmds_str[NOTIFY_COMMANDS_LENGTH];
char buf[64];
const char *tmp = NULL;
//make a copy, so that strsplit doesn't destory the original
astrncpy(cmds_str, notify_commands, NOTIFY_COMMANDS_LENGTH);
while (strsplit(cmds_str, " ,:;", buf, sizeof(buf), &tmp))
{
cmd->RemoveCommand(ToLowerStr(buf), Cnotify, ALLARENAS);
}
}
EXPORT int MM_notify(int action, Imodman *mm_, Arena *arena)
{
if (action == MM_LOAD)
{
mm = mm_;
chat = mm->GetInterface(I_CHAT, ALLARENAS);
cmd = mm->GetInterface(I_CMDMAN, ALLARENAS);
cfg = mm->GetInterface(I_CONFIG, ALLARENAS);
if (!chat || !cmd || !cfg) return MM_FAIL;
register_commands();
return MM_OK;
}
else if (action == MM_UNLOAD)
{
unregister_commands();
mm->ReleaseInterface(chat);
mm->ReleaseInterface(cmd);
mm->ReleaseInterface(cfg);
return MM_OK;
}
return MM_FAIL;
}
|
The following needs to be added to global.conf to change ?man into ?help. Omitting these will keep the ASSS default of ?help.
[Help]
CommandName = man
[Notify]
AlertCommand = cheater,help
|
Additionally, notify needs to be added to modules.conf.
EDIT: fixed missing locals on the functions in notify.c _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|