[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pbmserv-dev] Adding a command to a game



In your yourgamenamehere.h file (go.h?):

	virtual int UnknownCommand(int argc, char **argv);

Here's what my routine does.  You'd be looking for
"sgf" instead of "set".  Return 0 on success, and if
the compare does not work be sure to return to the
default behavior.  I'd probably keep this routine to
about 10 lines just to see if the command was sgf and
defer the guts to its own method!

Cheers,

Lyman

// Command used to set options.

int OctiLite::UnknownCommand(int argc, char **argv)
{
	Mail mail;

	if (!strncasecmp(argv[1],"set",3))
	{
	  if (argc < 5)
	  {
		  return Error(
			  "Syntax: %s set <userid> <password>
<display_option>\n where <display_option> is one of:
flip, noflip\n",
			  GameType());
	  }

	  switch(CheckUserid(player = argv[2],argv[3]))
	  {
	    case BAD_PASSWORD: return Error("Invalid password
entered");
	    case BAD_USER: return Error("Invalid userid
entered");
	  }

	  if (!strncasecmp(argv[4],"flip",4))
	  {
	    SetOption("flip", 1 );
	  }
	  else if (!strncasecmp(argv[4],"noflip",6))
	  {
	    SetOption("flip", 0 );
	  }
	  else
	  {
		  return Error("Invalid option (%s)\n Valid options
are: flip, noflip.\n",argv[4]);
	  }

	  mail.AddUser(player);
	  fprintf(mail.fp(),"Subject: %s option has been
set.\n\n",GameType());
	  fprintf(mail.fp(),"Current %s option for display is
%s.\n\n",GameType(),
		  argv[4] );

	  return 0;
	}
    return Game::UnknownCommand(argc,argv); 
}


--- Robert Barrell <games@rdbhn.org> wrote:

> Lyman Hurd wrote:
> 
> >Or OctiLite.  That was the embarassing part.  I
> didn't
> >think of it and I have used the sucker!
> >
> That being the case, what *is* the proper way to add
> a command, so I may 
> make the necessary changes?
> 
> 
> To unsubscribe, send a message to esquire@gamerz.net
> with
> 	unsubscribe pbmserv-dev@gamerz.net
> as the BODY of the message.  The SUBJECT is ignored.
> 
>