fixed amb1475 - inconsistent root console menu usage

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401908
This commit is contained in:
David Anderson 2008-03-01 05:42:25 +00:00
parent a87628654d
commit f30d3d1901
5 changed files with 87 additions and 331 deletions

View File

@ -914,12 +914,11 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &co
{
const char *text = command.Arg(2);
int id = atoi(text);
CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(id);
CPlugin *pPlugin = g_PluginSys.FindPluginByConsoleArg(text);
if (!pPlugin)
{
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id);
g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", text);
return;
}
@ -946,7 +945,7 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &co
g_RootMenu.ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]");
for (iter=pList->begin();
iter!=pList->end();
iter++, id++)
iter++)
{
PlCmdInfo &cmd = (*iter);
if (cmd.type == Cmd_Server)
@ -978,140 +977,3 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &co
g_RootMenu.ConsolePrint("[SM] Usage: sm cmds <plugin #>");
}
static int g_yam_state = 0;
void _YamState(int state)
{
if (state == 0)
{
g_RootMenu.ConsolePrint("Welcome to the SourceMod Text Adventure.");
g_RootMenu.ConsolePrint("Type sm_text to see the last message.");
g_RootMenu.ConsolePrint("Type sm_text <word> to follow a capital word.");
g_RootMenu.ConsolePrint("-------------------------------");
g_RootMenu.ConsolePrint("You are at VALVE HEADQUARTERS.");
g_RootMenu.ConsolePrint("To your LEFT is BAILOPAN, rearranging the letters to spell");
g_RootMenu.ConsolePrint("\"A HARD VEAL QUEST\". FORWARD is the entrance to the building.");
g_RootMenu.ConsolePrint("To your RIGHT is your last chance to flee in terror.");
} else if (state == 1) {
g_RootMenu.ConsolePrint("BAILOPAN tells you that his name his pronounced");
g_RootMenu.ConsolePrint("\"bye low pahn,\" not \"bay low pan.\" Do you ");
g_RootMenu.ConsolePrint("MOCK him, or NOD quietly?");
} else if (state == 2) {
g_RootMenu.ConsolePrint("You enter the Valve building. You hear screams coming from within.");
g_RootMenu.ConsolePrint("A grotesque figure lumbers up to greet you; it is Gabe Newell.");
g_RootMenu.ConsolePrint("\"Welcome,\" he belches, \"to my lair.\"");
g_RootMenu.ConsolePrint("Do you SHAKE Gaben's hand, WALK past him, or OFFER a donut?");
} else if (state == 3) {
g_RootMenu.ConsolePrint("You walk into the break room. Alfred \"Alf is from Melmac\" Reynolds and");
g_RootMenu.ConsolePrint("Yahn \"Yeti\" Bernier are discussing something (you overhear ");
g_RootMenu.ConsolePrint("the phrase \"and next Steam update, here's what we should break\").");
g_RootMenu.ConsolePrint("Should you DIE in a fire, REPORT a bug, REQUEST a feature, or ");
g_RootMenu.ConsolePrint("SPRAY them with butter?");
}
g_yam_state = state;
}
#if defined ORANGEBOX_BUILD
void _IntExt_CallYams(const CCommand &cmd)
{
#else
void _IntExt_CallYams()
{
CCommand cmd;
#endif
const char *arg = cmd.Arg(1);
/* should be impossible */
if (!arg || arg[0] == '\0')
{
_YamState(g_yam_state);
}
if (g_yam_state == 1)
{
if (strcasecmp(arg, "mock") == 0)
{
g_RootMenu.ConsolePrint("You mock BAILOPAN's pronunciation. In a fit of rage, ");
g_RootMenu.ConsolePrint("he sticks an INT 3 call into your chest, rendering you broken.");
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
g_yam_state = 0;
} else if (strcasecmp(arg, "nod") == 0) {
g_RootMenu.ConsolePrint("You nod quietly, and then slowly back away into the Valve headquarters.");
_YamState(2);
} else {
g_RootMenu.ConsolePrint("Commands are MOCK and NOD.");
}
} else if (g_yam_state == 3) {
if (strcasecmp(arg, "report") == 0)
{
g_RootMenu.ConsolePrint("You report a bug to Alfred and Yeti. Immediately, both fall asleep.");
g_RootMenu.ConsolePrint("You decay in the break room for two years while they sleep.");
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
g_yam_state = 0;
} else if (strcasecmp(arg, "request") == 0) {
g_RootMenu.ConsolePrint("You request a feature to Alfred and Yeti. They both mutter something");
g_RootMenu.ConsolePrint("about it being implemented \"soon.\" Then, by accident, someone sends");
g_RootMenu.ConsolePrint("a message over \"Friends.\" The entire building catches fire.");
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
g_yam_state = 0;
} else if (strcasecmp(arg, "die") == 0) {
g_RootMenu.ConsolePrint("For no reason, you suddenly catch fire. Alfred and Yeti find this");
g_RootMenu.ConsolePrint("deeply disturbing, and cover your flaming corpse with Episode 2");
g_RootMenu.ConsolePrint("advertisements. Coming soon, with Team Fortress 2, and Portal!");
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
g_yam_state = 0;
} else if (strcasecmp(arg, "spray") == 0) {
g_RootMenu.ConsolePrint("You spray Alfred and Yeti with butter. Like Jack Thompson to an");
g_RootMenu.ConsolePrint("ambulance, Gabe Newell instantly appears and devours them both.");
g_RootMenu.ConsolePrint("You run away, just in time, as Gabe Newell explodes, registering ");
g_RootMenu.ConsolePrint("a 5.6 earthquake. Outside, world peace is achieved.");
g_RootMenu.ConsolePrint("YOU HAVE WON.");
g_yam_state = 0;
}
} else if (g_yam_state == 2) {
if (strcasecmp(arg, "shake") == 0)
{
g_RootMenu.ConsolePrint("You shake Gaben's hand. It is a terrifying and disgusting experience.");
g_RootMenu.ConsolePrint("However, you survive, and continue on.");
_YamState(3);
} else if (strcasecmp(arg, "offer") == 0) {
g_RootMenu.ConsolePrint("You offer Gabe Newell one (1) donut. With a gleam in his eyes, ");
g_RootMenu.ConsolePrint("he picks you up and devours you whole.");
g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER.");
g_yam_state = 0;
} else if (strcasecmp(arg, "walk") == 0) {
g_RootMenu.ConsolePrint("You walk past Gabe Newell. He can't keep up with your pace!");
_YamState(3);
} else {
g_RootMenu.ConsolePrint("Commands are SHAKE, OFFER, and WALK.");
}
} else if (g_yam_state == 0) {
if (strcasecmp(arg, "left") == 0)
{
_YamState(1);
} else if (strcasecmp(arg, "right") == 0) {
g_RootMenu.ConsolePrint("You run away from the Valve headquarters in sheer terror.");
g_RootMenu.ConsolePrint("While running, you smash into an unknown person, who turns out to be your soul mate.");
g_RootMenu.ConsolePrint("You marry and raise a family of 3 kids.");
g_RootMenu.ConsolePrint("Many years later, you look back, and realize this was your best choice.");
g_RootMenu.ConsolePrint("YOU HAVE WON.");
g_yam_state = 0;
} else if (strcasecmp(arg, "forward") == 0) {
_YamState(2);
} else if (arg[0] != '\0') {
g_RootMenu.ConsolePrint("Commands are FORWARD, LEFT, and RIGHT.");
}
}
}
void _IntExt_EnableYams()
{
static ConCommand *pCmd = NULL;
if (!pCmd)
{
pCmd = new ConCommand("sm_text", _IntExt_CallYams, "Fountain of Yams Adventure Game", FCVAR_GAMEDLL);
g_RootMenu.ConsolePrint("Something is now enabled...");
} else {
g_RootMenu.ConsolePrint("Something is already enabled...");
}
}

View File

@ -270,14 +270,14 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &co
if (argcount >= 3)
{
/* Get plugin index that was passed */
int id = atoi(command.Arg(2));
const char *arg = command.Arg(2);
/* Get plugin object */
CPlugin *plugin = g_PluginSys.GetPluginByOrder(id);
CPlugin *plugin = g_PluginSys.FindPluginByConsoleArg(arg);
if (!plugin)
{
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id);
g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", arg);
return;
}
@ -705,159 +705,3 @@ HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar)
return error;
}
static int s_YamagramState = 0;
void _YamagramPrinterTwoPointOhOh(int yamagram)
{
switch (yamagram)
{
case 0:
g_RootMenu.ConsolePrint("Answer the following questions correctly and Gaben may not eat you after all.");
g_RootMenu.ConsolePrint("You will be given one hint in the form of my patented yamagrams.");
g_RootMenu.ConsolePrint("Type sm_nana to see the last question.");
g_RootMenu.ConsolePrint("Type sm_nana <answer> to attempt an answer of the question.");
g_RootMenu.ConsolePrint("-------------------------------");
_YamagramPrinterTwoPointOhOh(1);
return;
case 1:
g_RootMenu.ConsolePrint("Question Ichi (1)");
g_RootMenu.ConsolePrint("One can turn into a cow by doing what action?");
g_RootMenu.ConsolePrint("Hint: AGE SANS GRIT");
break;
case 2:
g_RootMenu.ConsolePrint("Question Ni (2)");
g_RootMenu.ConsolePrint("What kind of hat should you wear when using the Internet?");
g_RootMenu.ConsolePrint("Hint: BRR MOOSE");
break;
case 3:
g_RootMenu.ConsolePrint("Question San (3)");
g_RootMenu.ConsolePrint("Who is the lead developer of SourceMod?");
g_RootMenu.ConsolePrint("Hint: VEAL BANDANA DID RIP SOON");
break;
case 4:
g_RootMenu.ConsolePrint("Question Yon (4)");
g_RootMenu.ConsolePrint("A terrible translation of 'SVN Revision' to Japanese romaji might be ...");
g_RootMenu.ConsolePrint("Hint: I TAKE IN AN AIR OK");
break;
case 5:
g_RootMenu.ConsolePrint("Question Go (5)");
g_RootMenu.ConsolePrint("What is a fundamental concept in the game of Go?");
g_RootMenu.ConsolePrint("Hint: AD LADEN THIEF");
break;
case 6:
g_RootMenu.ConsolePrint("Question Roku (6)");
g_RootMenu.ConsolePrint("Why am I asking all these strange questions?");
g_RootMenu.ConsolePrint("Hint: CHUBBY TITAN EATS EWE WAGE DATA");
break;
case 7:
g_RootMenu.ConsolePrint("Question Nana (7)");
g_RootMenu.ConsolePrint("What is my name?");
g_RootMenu.ConsolePrint("Hint: AD MODE LAG US");
break;
default:
break;
}
s_YamagramState = yamagram;
}
#if defined ORANGEBOX_BUILD
void _IntExt_CallYamagrams(const CCommand &cmd)
{
#else
void _IntExt_CallYamagrams()
{
CCommand cmd;
#endif
bool correct = false;
const char *arg = cmd.ArgS();
if (!arg || arg[0] == '\0')
{
_YamagramPrinterTwoPointOhOh(s_YamagramState);
return;
}
switch (s_YamagramState)
{
case 1:
correct = !strcasecmp(arg, "eating grass");
break;
case 2:
correct = !strcasecmp(arg, "sombrero");
break;
case 3:
correct = !strcasecmp(arg, "david bailopan anderson");
break;
case 4:
correct = !strcasecmp(arg, "kaitei no kairan");
break;
case 5:
correct = !strcasecmp(arg, "life and death");
break;
case 6:
correct = !strcasecmp(arg, "because gabe wanted it that way");
if (correct)
{
g_RootMenu.ConsolePrint("Congratulations, you have answered 6 of my questions.");
g_RootMenu.ConsolePrint("However, I have one final question for you. It wouldn't be nana without it.");
g_RootMenu.ConsolePrint("-------------------------------");
_YamagramPrinterTwoPointOhOh(7);
return;
}
break;
case 7:
correct = !strcasecmp(arg, "damaged soul");
if (correct)
{
g_RootMenu.ConsolePrint("You don't know how lucky you are to still be alive!");
g_RootMenu.ConsolePrint("Congratulations. You have answered all 7 questions correctly.");
g_RootMenu.ConsolePrint("The SourceMod Dev Team will be at your door with anti-Gaben grenades");
g_RootMenu.ConsolePrint("within seconds. You will also be provided with a rocket launcher,");
g_RootMenu.ConsolePrint("just in case Alfred decides to strike you with a blitzkrieg in retaliation.");
s_YamagramState = 0;
return;
}
break;
default:
break;
}
if (s_YamagramState > 0)
{
if (correct)
{
g_RootMenu.ConsolePrint("Correct! You are one step closer to avoiding the deadly jaws of Gaben.");
g_RootMenu.ConsolePrint("-------------------------------");
s_YamagramState++;
} else {
g_RootMenu.ConsolePrint("Wrong! You better be more careful. Gaben may be at your door at any minute.");
return;
}
}
_YamagramPrinterTwoPointOhOh(s_YamagramState);
}
void _IntExt_EnableYamagrams()
{
static ConCommand *pCmd = NULL;
if (!pCmd)
{
pCmd = new ConCommand("sm_nana", _IntExt_CallYamagrams, "Try these yamagrams!", FCVAR_GAMEDLL);
g_RootMenu.ConsolePrint("[SM] Warning: Gaben has been alerted of your actions. You may be eaten.");
} else {
g_RootMenu.ConsolePrint("[SM] Gaben has already been alerted of your actions...");
}
}
void _IntExt_OnHostnameChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
{
if (strcmp(oldValue, "Good morning, DS-san.") == 0
&& strcmp(pConVar->GetString(), "Good night, talking desk lamp.") == 0)
{
_IntExt_EnableYamagrams();
}
}

View File

@ -59,17 +59,6 @@ RootConsoleMenu::~RootConsoleMenu()
m_Menu.clear();
}
extern void _IntExt_OnHostnameChanged(ConVar *var, const char *pOldValue, float flOldValue);
class DetectHostNameChanges : public IConVarChangeListener
{
public:
void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue)
{
_IntExt_OnHostnameChanged(pConVar, oldValue, flOldValue);
}
} s_HostnameChangeDetector;
void RootConsoleMenu::OnSourceModStartup(bool late)
{
#if defined ORANGEBOX_BUILD
@ -82,13 +71,11 @@ void RootConsoleMenu::OnSourceModStartup(bool late)
void RootConsoleMenu::OnSourceModAllInitialized()
{
g_ConVarManager.AddConVarChangeListener("hostname", &s_HostnameChangeDetector);
g_ShareSys.AddInterface(NULL, this);
}
void RootConsoleMenu::OnSourceModShutdown()
{
g_ConVarManager.RemoveConVarChangeListener("hostname", &s_HostnameChangeDetector);
RemoveRootConsoleCommand("credits", this);
RemoveRootConsoleCommand("version", this);
}
@ -227,8 +214,6 @@ unsigned int RootConsoleMenu::GetInterfaceVersion()
return SMINTERFACE_ROOTCONSOLE_VERSION;
}
extern void _IntExt_EnableYams();
void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
{
unsigned int argnum = cmd.ArgC();
@ -236,12 +221,7 @@ void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
if (argnum >= 2)
{
const char *cmdname = cmd.Arg(1);
if (strcmp(cmdname, "text") == 0)
{
_IntExt_EnableYams();
return;
}
else if (strcmp(cmdname, "internal") == 0)
if (strcmp(cmdname, "internal") == 0)
{
if (argnum >= 3)
{

View File

@ -2305,14 +2305,33 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
return;
}
int num = atoi(command.Arg(3));
if (num < 1 || num > (int)GetPluginCount())
CPlugin *pl;
char *end;
const char *arg = command.Arg(3);
int id = strtol(arg, &end, 10);
if (*end == '\0')
{
g_RootMenu.ConsolePrint("[SM] Plugin index not found.");
pl = GetPluginByOrder(id);
if (!pl)
{
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id);
return;
}
}
else
{
char pluginfile[256];
const char *ext = g_LibSys.GetFileExtension(arg) ? "" : ".smx";
UTIL_Format(pluginfile, sizeof(pluginfile), "%s%s", arg, ext);
if (!sm_trie_retrieve(m_LoadLookup, pluginfile, (void **)&pl))
{
g_RootMenu.ConsolePrint("[SM] Plugin %s is not loaded.", pluginfile);
return;
}
}
CPlugin *pl = GetPluginByOrder(num);
const sm_plugininfo_t *info = pl->GetPublicInfo();
g_RootMenu.ConsolePrint(" Filename: %s", pl->GetFilename());
@ -2388,12 +2407,32 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
return;
}
int num = atoi(command.Arg(3));
if (num < 1 || num > (int)GetPluginCount())
CPlugin *pl;
char *end;
const char *arg = command.Arg(3);
int id = strtol(arg, &end, 10);
if (*end == '\0')
{
g_RootMenu.ConsolePrint("[SM] Plugin index not found.");
pl = GetPluginByOrder(id);
if (!pl)
{
g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id);
return;
}
}
else
{
char pluginfile[256];
const char *ext = g_LibSys.GetFileExtension(arg) ? "" : ".smx";
UTIL_Format(pluginfile, sizeof(pluginfile), "%s%s", arg, ext);
if (!sm_trie_retrieve(m_LoadLookup, pluginfile, (void **)&pl))
{
g_RootMenu.ConsolePrint("[SM] Plugin %s is not loaded.", pluginfile);
return;
}
}
int res;
const char *mode = command.Arg(4);
@ -2413,7 +2452,6 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
debug = false;
}
CPlugin *pl = GetPluginByOrder(num);
if (debug && pl->IsDebugging())
{
g_RootMenu.ConsolePrint("[SM] This plugin is already in debug mode.");
@ -2807,3 +2845,33 @@ int CPluginManager::GetOrderOfPlugin(IPlugin *pl)
return -1;
}
CPlugin *CPluginManager::FindPluginByConsoleArg(const char *arg)
{
int id;
char *end;
CPlugin *pl;
id = strtol(arg, &end, 10);
if (*end == '\0')
{
pl = GetPluginByOrder(id);
if (!pl)
{
return NULL;
}
}
else
{
char pluginfile[256];
const char *ext = g_LibSys.GetFileExtension(arg) ? "" : ".smx";
UTIL_Format(pluginfile, sizeof(pluginfile), "%s%s", arg, ext);
if (!sm_trie_retrieve(m_LoadLookup, pluginfile, (void **)&pl))
{
return NULL;
}
}
return pl;
}

View File

@ -443,6 +443,8 @@ public:
bool ReloadPlugin(CPlugin *pl);
void UnloadAll();
CPlugin *FindPluginByConsoleArg(const char *arg);
private:
LoadRes _LoadPlugin(CPlugin **pPlugin, const char *path, bool debug, PluginType type, char error[], size_t maxlength);