18 Aug, 2009, Lazerous wrote in the 1st comment:
Votes: 0
I am tryin to create a logout menu for my server. What I have done so far, I doubt will work.
It is still giving me bugs in the compilor, but beyond that I am unsure I am going about this
in the correct way. So I am posting what I have here and hope someone can lend a hand.
Also another worry is the 2nd option, "returning to the game", I doubt I got that right.

File: act_comm.cpp Line: 1170 The do_quit function is where I plugged this code into.
// Log Out Menu - Ryan Rae

CDescriptor *d;
ch = d->m_pCharacter;



d->WriteToBuffer("*** Welcome to: The Realm of Draenor ***\n\r\
\n\n\rLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
d->m_Connected = CON_MENU2;
return;
break;

case CON_MENU2:
switch ( argument [0] )
{
case '0':
d->WriteToBuffer( "Come back again.\n\r", 0 );
d->m_pCharacter->SetDesc (NULL);
RemoveCharacter (*d);
return;
break;

case '1':
return;
break;

case '2':
do_help( ch, "story" );
return;
break;

case '3':
do_help( ch, "motd" );
return;
break;

case '4':
do_help( ch, "code" );
return;
break;

case '5':
do_help( ch, "world" );
return;
break;

case '6':
do_help( ch, "prep" );
return;
break;

default:
d->WriteToBuffer("\nLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
return;

// End of New Log out Menu


Any help would be appreciated. I have no coder in my realm other then myself,
I can't seem to find one that is commited and does do any work.
The few I have had stuck around for 1 or 2 mods then that was it,
so if there are any out there that are not quitters and looking to help
out in that end that would be great. How ever, my main concern right
now, is this menu. You can reply to this, send me a message here, or you
can log into my realm and contact me there.

Telnet: aderon.zapto.org
Port: 23

Orrin edit: added code tags
18 Aug, 2009, JohnnyStarr wrote in the 2nd comment:
Votes: 0
You might want to use the code tags :biggrin:
What codebase are you using?
What errors do you get?
Do you know how to compile your mud yet?
18 Aug, 2009, quixadhal wrote in the 3rd comment:
Votes: 0
Obviously, that isn't the entire function, but assuming you just clipped a few parts out…

Does do_help() use the a string pager? If so, you may want to be careful that it uses a different state variable than d->m_Connected, else you'll never get back to your menu.

I notice that NONE of the options in your switch ever change state, presumably at least option '1' should set you to some other part of the login nanny case?

To know if case '0' works, we'd need to see what RemoveCharacter() does. Assuming it saves, flushes I/O buffers, and closes the socket, that should work. If it recycles the descriptor object, make sure it gets blanked out properly so it doesn't create issues when reused. Also, make sure no other code references that descriptor further down in the loop.
18 Aug, 2009, Lazerous wrote in the 4th comment:
Votes: 0
This was a start to a logout function, its all I have completed to this point.
I took my main log in menu and just adapted that and tried to make a logout menu and put it
into the do_quit function. I am not a coder by schooling, so the jargon isn't going to help me much,
this was located in act_comm.cpp not in nanny.cpp which is where the login menu is.

Codebase is as I said: smaugwiz 2.02

Mud isn't compiling now since my additions, but it was fine prior to them.
I am using ms visual c/c++ ver. 6

I want the menu to be activated when they try to quit.
Then they can either return to the game, leave the game, read some stuff, etc.

Eventually I want to make an option to leave a message, but first I want the menu to work.
19 Aug, 2009, quixadhal wrote in the 5th comment:
Votes: 0
Unfortunately, if what I wrote above sounds like jargon, you'll need to take a few steps back and read up on the C or C++ language before you dive back into this. A MUD is a fairly complex system, and trying to change it without having a decent grasp of the language it's written in, as well as the general concepts used, is going to make things very confusing and difficult.

As a general suggestion, the simplest way to accomplish this would be to add additional states to the nanny handling system, so typing "quit" puts them into a new state, which displays your menu. From there, choosing quit again would call the rest of the code that quit used to invoke, and other things would work like the regular nanny states, eventually returning to the normal game state.

Someone more familiar with smaugwiz might be able to provide more details.
19 Aug, 2009, Lazerous wrote in the 6th comment:
Votes: 0
I stated the jargon thing to slow people from getting too carried away with jargon,
I never stated that I didn't understand what you meant. I already did the substates thats not the problem.
The substates are declared, its called CON_MENU2.
I just wanted people to go over my code and see where I am missing things, but if you need the build report
for that, then no problems I can supply that. I have been coding as an amature for years, just never had to
deal with this issue before.

It happens. Just oddly for sure, it never came up. You would think a menu based code snippet would be a common
item and such, but the work I have been doing hasn't called for it. I did research it on the net but it was so radically
different then what I had in my previous menu and what I have seen in my codebase, I thought to ask you folks first
before taking out what I have done and put something foreign in that may not work at all. Where this menu works fine
in my nanny. For some dumb reason I am missin sumthin here, and I be damned if I can remember what it is…

Currently I have refined it down to two errors:

ACT_COMM.CPP(1189) : error C2043: illegal break
ACT_COMM.CPP(1191) : error C2046: illegal case


and here is the improved code:

smaug.h  line: 322

CON_PRESS_ENTER2, CON_REDO_CLASS, CON_REDO_RACE, CON_PRESS_ENTER, CON_MENU, CON_MENU2,

act_comm.cpp line: 1171 { the do_quit function }
** I added my code below this line: do_dismount (ch, "");
My code:

// Log Out Menu - Ryan Rae

CDescriptor *d;
ch = d->m_pCharacter;



d->WriteToBuffer("*** Welcome to: The Realm of Draenor ***\n\r\
\n\n\rLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
d->m_Connected = CON_MENU2;
return;
break;

case CON_MENU2:
switch ( argument [0] )
{
case '0':
d->WriteToBuffer( "Come back again.\n\r", 0 );
d->m_pCharacter->SetDesc (NULL);
RemoveCharacter (*d);
return;
break;

case '1':
return;
break;

case '2':
do_help( ch, "story" );
return;
break;

case '3':
do_help( ch, "motd" );
return;
break;

case '4':
do_help( ch, "code" );
return;
break;

case '5':
do_help( ch, "world" );
return;
break;

case '6':
do_help( ch, "prep" );
return;
break;

default:
d->WriteToBuffer("\nLog Out Menu:\n\n\r\
0) Leave the Game\n\r\
1) Return to the Game\n\n\r\
2) Read the background story\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\n\r\
5) See the World Map.\n\r\
6) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
return;

// End of New Log out Menu


The next part in the code would be the rest of the do_quit.
19 Aug, 2009, Lazerous wrote in the 7th comment:
Votes: 0
While waiting on replies I have tried sumthing else and come up with different troubles.

Here is a piece of code I adapted for my purposes:

Original from a post on the net:
——————————-
#include <iostream>
using namespace std;

void do_again(),direction(int ans);
void option_1(),option_2(),option_3(),option_4(),option_5(),option_6();

int main()
{
do_again();//call do_again function, say goodbye to main until everything else is done running

return 0;
}//end function

void do_again()
{
int ans;//declare ans variable, this will be used OVER AND OVER
do
{
cout << "What would you like to do?\n";
cout << "1: Option 1\n";
cout << "2: Option 2\n";
cout << "3: Option 3\n";
cout << "4: Option 4\n";
cout << "5: Option 5\n";
cout << "6: Option 6 - Exit\n";//print us some options
cin >> ans;
cin.ignore(80,'\n'); //take in an answer
direction(ans);//send that answer to direction!
}while(ans!=6);//keep on keepin on till they pick exit!
}//end function

void direction(int ans)
{
switch (ans)//roll thru options
{
case 1: //if they picked the number 1, its gonna go to this function,
//thats pretty much how the whole thing works
option_1();
break;
case 2:
option_2();
break;
case 3:
option_3();
break;
case 4:
option_4();
break;
case 5:
option_5();
break;
case 6:
option_6();
break;
default://THEY DIDNT READ THE MENU, WHO WOULD HAVE THOUGHT?!?!
cout << "Please read and follow all directions\n";//if directions aren't followed
break;
}
}//end function

//functions, FILL WITH VALUABLE PROGRAMMING SKILLS

void option_1()
{
}//end function

void option_2()
{
}//end function

void option_3()
{
}//end function

void option_4()
{
}//end function

void option_5()
{
}//end function

void option_6()
{
}//end function

—————————-
Now my version:

void do_menu2(),direction(int ans);

void do_menu2 (CCharacter *ch)
{
int ans;//declare ans variable, this will be used OVER AND OVER
do
{
cout << "Log Out Menu:\n";
cout << "1: Leave the game.\n";
cout << "2: Return to the game.\n";
cout << "3: Read latest realm changes.\n";
cout << "4: Read latest code changes.\n";
cout << "5: See the world map.\n";
cout << "6: See the areas in the realm.\n";
cin >> ans;
cin.ignore(80,'\n'); //take in an answer
direction(ans);//send that answer to direction!
}while(ans!=1);//keep on keepin on till they pick exit!
}//end function

void direction( CCharacter *ch, int ans)
{
switch (ans)//roll thru options
{
case 1:
break;
case 2:
break;
case 3:
do_help ( ch, "motd" );
break;
case 4:
do_help ( ch, "code" );
break;
case 5:
do_help( ch, "world" );
break;
case 6:
do_help ( ch, "prep" );
break;
default://THEY DIDNT READ THE MENU, WHO WOULD HAVE THOUGHT?!?!
cout << "Please read and follow all directions\n";//if directions aren't followed
break;
}
}//end function

Take into account I declared do_menu2 and direction in smaug.h like so:

DECLARE_DO_FUN(do_direction);
DECLARE_DO_FUN(do_menu2);


I also took:
#include <iostream>
using namespace std;

and placed that at the top of act_comm.cpp

Now these are the errors I recieved on this other method:

ACT_COMM.OBJ : error LNK2001: unresolved external symbol "void __cdecl do_menu2(class CCharacter *,char *)" (?do_menu2@@YAXPAVCCharacter@@PAD@Z)
ACT_COMM.OBJ : error LNK2001: unresolved external symbol "void __cdecl direction(int)" (?direction@@YAXH@Z)


Now personally it seems to me, the first method is the best option, but I am not a pro at c, so I take it to you folks for some help.

Which option if any of these two should I go for, then what would you sugest to rectify the build errors?
19 Aug, 2009, Dean wrote in the 8th comment:
Votes: 0
Lazerous, you should use the code formatting option for displaying your code. Makes it easier for people to read.
19 Aug, 2009, Lazerous wrote in the 9th comment:
Votes: 0
Yes and no, I found the text was way too small for me to read…
19 Aug, 2009, Orrin wrote in the 10th comment:
Votes: 0
If the code section is too small to read you could try zooming in your browser, probably ctrl + and ctrl -. One reason to use code blocks is that it includes line number information which makes it easier to refer to specific parts of the code.

In the latest code you posted you say you've declared the functions do_menu2 and direction in smaug.h, but you also have conflicting declarations at the top of the code you quoted, neither of which match the function definitions. I'm guessing the macro DECLARE_DO_FUN isn't going to provide the correct parameters either.

The previous code you posted with the break and case errors it's difficult to say without knowing where the errors occur in that code. You presumably have a case and a break outside of a switch statement so it's probably a misplaced closing brace somewhere.
19 Aug, 2009, quixadhal wrote in the 11th comment:
Votes: 0
In the first chunk of code, one of the problems is that you have a case statement outside any switch. The C construct switch/case works like this:
switch( variable ) {
case value:
stuff…
break;
case value2:
stuff…
break;
default:
stuff…
break;
}

In the above, you have a "case CON_MENU2:" at line 30, but from what you posted it doesn't seem to be inside any switch statement.

The second chunk of code uses iostreams for input and output. That won't do anything useful for your players, since anything sent to cout will ony appear on your console, not to the connected sockets. Also, as soon as you attempt to read from cin, the entire game will halt waiting for console input.

The overall concept is fine, but you'll need to rework all that. Your errors are linker errors, and probably indicate that the do_menu2() and direction() functions aren't declared with the right types, or where they are called, they have the wrong parameters (which will make C++ hunt for a different prototype, since you can have multiple functions with the same name and different parameters).

If the size of things in code tags changes, you might need to poke at your browser. All it should do is change to a fixed-width font and not expand things like smileys and such (and get a bright white background… can't win em all).
19 Aug, 2009, tphegley wrote in the 12th comment:
Votes: 0
You shouldn't have returns in your case statements right?

He has:

case '1':
return; <—
break;

case '2':
do_help( ch, "story" );
return; <—-
break;

case '3':
do_help( ch, "motd" );
return; <—-
break;


Also, quix, his con_menu might be in a bigger switch statement that he didn't post. shrug.
19 Aug, 2009, David Haley wrote in the 13th comment:
Votes: 0
Even if the font is small, it's far easier to read than plain text. Some people won't even look at more than a line or two of code if it's not in monospace font. (Also, the size could be an issue with your browser preferences, as the monospace font is actually somewhat bigger than the proportional font on my screen.)
19 Aug, 2009, Lazerous wrote in the 14th comment:
Votes: 0
Ok lets try sumthing different here then, can some one please put up abit of code for a basic menu
that should work in smaug. Then I will try to adapt that to my designs.

Currently I am rearranging the menu into its own seperate function called do_quit and made the
old do_quit changed to do_quit2 but I still gettin weird errors, so if someone would be kind enough
to put up a menu snippet to save my poor head from another head ache, that would be great.
19 Aug, 2009, tphegley wrote in the 15th comment:
Votes: 0
Just look at your nanny function (usually in comm.c) and see what it does and try to play off from that..
19 Aug, 2009, Lazerous wrote in the 16th comment:
Votes: 0
Man heh, I have been tryin to do that, been cutting and pasting stuff etc, but those illegal break and illegal case are buggin me…
I been banging my head into this code piece for days and its such a small thing, its really frustrating.
Also this is smaugwiz, not smaug, so code locations are not the same.

I like I said, reverted to the old original menu idea but have found no way to fix these errors.
19 Aug, 2009, Lazerous wrote in the 17th comment:
Votes: 0
Post#6 line 27 and 28 are where the errors are pointing, and honestly its the same as the menu i made in my nanny.cpp so why its saying that
these are wrong I cant seem to find the cause.
19 Aug, 2009, David Haley wrote in the 18th comment:
Votes: 0
That's not very likely…

Quote
ACT_COMM.CPP(1189) : error C2043: illegal break
ACT_COMM.CPP(1191) : error C2046: illegal case

That says that the two lines are not one right after the other, so it can't be lines 27 and 28 – unless you're not showing us the code you're actually compiling.
19 Aug, 2009, Lazerous wrote in the 19th comment:
Votes: 0
Here is the code from the act_com.cpp
// New Login Menu - Ryan Rae
d->WriteToBuffer("*** Welcome to: The Realm of Draenor ***\n\r\
\n\n\rMain Menu:\n\n\r\
0) Leave the Game\n\r\
1) Enter the Game\n\r\
2) Read the background story\n\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\r\
5) Read the class information.\n\r\
6) Read the race information.\n\r\
7) Read the new player information.\n\n\r\
8) See the World Map.\n\r\
9) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
d->m_Connected = CON_MENU;
break;

case CON_MENU:
switch ( argument [0] )
{
case '0':
d->WriteToBuffer( "Come back again.\n\r", 0 );
/* clear descriptor pointer to get rid of bug message in log
* while noticing that you must set teh descriptor to NULL
* to do so. I would advise NOT to tamper with this function
* i.e. the close_socket function. It seems fine so no need to mess with it.
*/
d->m_pCharacter->SetDesc (NULL);
RemoveCharacter (*d);
return;
break;

case '1':
d->m_Connected = CON_PRESS_ENTER2;
break;

case '2':
do_help( ch, "story" );
return;
break;

case '3':
do_help( ch, "motd" );
return;
break;

case '4':
do_help( ch, "code" );
return;
break;

case '5':
do_help( ch, "class" );
return;
break;

case '6':
do_help( ch, "race" );
return;
break;

case '7':
do_help( ch, "nmotd" );
return;
break;

case '8':
do_help( ch, "world" );
return;
break;

case '9':
do_help( ch, "prep" );
return;
break;

default:
d->WriteToBuffer("\nMain Menu:\n\n\r\
0) Leave the Game\n\r\
1) Enter the Game\n\r\
2) Read the background story\n\n\r\
3) Read latest realm changes.\n\r\
4) Read the latest code changes.\n\r\
5) Read the class information.\n\r\
6) Read the race information.\n\r\
7) Read the new player information.\n\n\r\
8) See the World Map.\n\r\
9) See a list of all the area's in the realm.\n\n\r\
Please select your choice: ", 0);
return;
}

case CON_PRESS_ENTER2:

// End of New Login Menu


Build errors:

ACT_COMM.CPP
E:\BuiltByRustry\Current Game Code\ACT_COMM.CPP(1143) : error C2043: illegal break
E:\BuiltByRustry\Current Game Code\ACT_COMM.CPP(1145) : error C2046: illegal case
19 Aug, 2009, David Haley wrote in the 20th comment:
Votes: 0
It would be nice if you also indented the code, it would make it a lot easier to read. Generally posted code should be indented correctly, and formatted using the code tag.

Anyhow, we need to know which of those lines are 1143 and 1145.

(The problem is perhaps that you are breaking after returns, as other posters have suggested.)
0.0/64