head	1.39;
access;
symbols
	tonic_4:1.39
	tonic_3:1.39
	tonic_2:1.39
	demo:1.38.0.2
	design_report:1.33
	oral_presentation_freeze:1.2.0.2;
locks; strict;
comment	@ * @;


1.39
date	95.12.14.09.07.22;	author jered;	state Exp;
branches;
next	1.38;

1.38
date	95.12.13.00.26.59;	author daveg;	state Exp;
branches;
next	1.37;

1.37
date	95.12.13.00.00.45;	author daveg;	state Exp;
branches;
next	1.36;

1.36
date	95.12.12.23.30.30;	author hartmans;	state Exp;
branches;
next	1.35;

1.35
date	95.12.12.23.18.08;	author jered;	state Exp;
branches;
next	1.34;

1.34
date	95.12.12.14.40.33;	author hartmans;	state Exp;
branches;
next	1.33;

1.33
date	95.12.11.21.08.54;	author daveg;	state Exp;
branches;
next	1.32;

1.32
date	95.12.11.20.53.48;	author rgmisra;	state Exp;
branches;
next	1.31;

1.31
date	95.12.11.20.51.22;	author rgmisra;	state Exp;
branches;
next	1.30;

1.30
date	95.12.11.20.34.22;	author rgmisra;	state Exp;
branches;
next	1.29;

1.29
date	95.12.11.20.12.48;	author rgmisra;	state Exp;
branches;
next	1.28;

1.28
date	95.12.11.15.28.53;	author rgmisra;	state Exp;
branches;
next	1.27;

1.27
date	95.12.11.15.10.03;	author rgmisra;	state Exp;
branches;
next	1.26;

1.26
date	95.12.11.13.15.07;	author rgmisra;	state Exp;
branches;
next	1.25;

1.25
date	95.12.11.13.14.08;	author rgmisra;	state Exp;
branches;
next	1.24;

1.24
date	95.12.11.12.57.10;	author rgmisra;	state Exp;
branches;
next	1.23;

1.23
date	95.12.11.12.40.21;	author rgmisra;	state Exp;
branches;
next	1.22;

1.22
date	95.12.11.11.22.49;	author rgmisra;	state Exp;
branches;
next	1.21;

1.21
date	95.12.11.10.16.57;	author hartmans;	state Exp;
branches;
next	1.20;

1.20
date	95.12.11.08.18.58;	author rgmisra;	state Exp;
branches;
next	1.19;

1.19
date	95.12.11.07.25.05;	author rgmisra;	state Exp;
branches;
next	1.18;

1.18
date	95.12.11.07.15.31;	author rgmisra;	state Exp;
branches;
next	1.17;

1.17
date	95.12.11.07.12.26;	author hartmans;	state Exp;
branches;
next	1.16;

1.16
date	95.12.11.05.49.45;	author rgmisra;	state Exp;
branches;
next	1.15;

1.15
date	95.12.11.04.54.13;	author rgmisra;	state Exp;
branches;
next	1.14;

1.14
date	95.12.11.02.37.27;	author rgmisra;	state Exp;
branches;
next	1.13;

1.13
date	95.12.10.01.36.10;	author jered;	state Exp;
branches;
next	1.12;

1.12
date	95.12.10.00.16.48;	author rgmisra;	state Exp;
branches;
next	1.11;

1.11
date	95.12.10.00.06.23;	author hartmans;	state Exp;
branches;
next	1.10;

1.10
date	95.12.09.19.54.35;	author hartmans;	state Exp;
branches;
next	1.9;

1.9
date	95.12.08.00.26.24;	author rgmisra;	state Exp;
branches;
next	1.8;

1.8
date	95.12.07.23.03.32;	author hartmans;	state Exp;
branches;
next	1.7;

1.7
date	95.12.07.22.11.09;	author rgmisra;	state Exp;
branches;
next	1.6;

1.6
date	95.12.06.01.53.31;	author hartmans;	state Exp;
branches;
next	1.5;

1.5
date	95.12.03.05.03.00;	author hartmans;	state Exp;
branches;
next	1.4;

1.4
date	95.12.02.09.47.55;	author hartmans;	state Exp;
branches;
next	1.3;

1.3
date	95.12.01.03.39.20;	author hartmans;	state Exp;
branches;
next	1.2;

1.2
date	95.11.30.04.33.32;	author hartmans;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	95.11.28.08.20.32;	author hartmans;	state Exp;
branches;
next	;

1.2.2.1
date	95.11.30.08.36.03;	author hartmans;	state Exp;
branches;
next	;


desc
@Implement root web node
@


1.39
log
@top_node, chess_capture_move, etc fixes, machine_player speedups.
@
text
@// This is -*- c++ -*- code

// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.38 1995/12/13 00:26:59 daveg Exp $

#include <6170.h>
#include "top_node.h"
#include <ps5/url_ops.h>
#include <machine_player.h>
#include <ps5/error_response.h>
#include <ctype.h>
#include <antichess_board.h>
#include <human_player.h>
http_response * top_node::get_self(string query, extensions *ext)
{
    return welcome(ext);
}

top_node::top_node(string uri, string image_base):
dir_node(uri){
    open_games = new map <string, open>;
#ifdef HAVE_RANDOM
    randomizing_mask = random()&0x1000;
    #else
    randomizing_mask = 666;	// Why not
#endif
image_uri = image_base;
}

http_response *top_node::get( string request, extensions *ext) {
    // We handle overides first; there should never be a conflict, but we don't want to lose the ability to create new games.
    string first;
    if (!unescape_uri(first_component(request), first))
	return new error_response (http_response::BAD_REQUEST,
				   "<strong> Your request contained a URIthat could not be escape decoded; throw away your browser and get a life.</strong>");

    if ( first == "new_game")
      return new_game (extract_query(request), ext);
    else if (first == "welcome")
      return welcome(ext);
    else if (first == "incomplete_games")
      return incomplete_games(ext);
    else if (first == "ref_new_game")
	return ref_new_game(extract_query(request), ext);
    // Add additional overide requests above this line
    else return dir_node::get(request, ext);
}



http_response * top_node::new_game (string qa, extensions *ext) {
    map <string, string> * q = parse_query(qa);
    ifstream brd;
    if (!q)
      return new error_response(http_response::BAD_REQUEST, "Improperly formatted query string");
    string filename;
    
    if (!q->contains("name"))
	return new error_response(http_response::BAD_REQUEST, "<strong> Request contained no player name.</strong>");
    if (q->find("load", filename))
	brd.open(safeify_filename(q->fetch("load")).get_chars(), ios::in|ios::nocreate);
    else brd.open("initial.brd", ios::in|ios::nocreate);
    
    string s_opponent;
    
    if ((!q->find("opponent", s_opponent))||s_opponent.length() == 0)
	return new error_response(http_response::BAD_REQUEST, "<strong> Request contained no opponent specification.</strong>");
bool human_human;
    if (toupper(s_opponent[0]) == 'H')
	human_human  = true;
    else if (toupper(s_opponent[0]) == 'C')
	human_human = false;
    else return new error_response(http_response::BAD_REQUEST, "<strong> Request contained invalid opponent.</string>");
    bool player_white;
string color;
    if ( (!q->find("side",color))||color.length() == 0)
	return new error_response(http_response::BAD_REQUEST, "<strong> Request contained missing or invalid side specification.</strong>");
if (toupper(color[0]) == 'W')
    player_white = true;
    else if (toupper(color[0]) == 'B')
	player_white = false;
else return new error_response(http_response::BAD_REQUEST,"<strong> Invalid player side specified.</strong>");
// Read in current turn from stream.
    char current_player;	// W or B
    brd >> current_player;
    if ((!brd.good())&&(current_player == 'B'||current_player == 'W'))
	return new error_response(http_response::BAD_REQUEST,
				  "Unable to load active color from board.");
    int wtime ;
    brd>>wtime;
    int btime;
    brd >> btime;
    if (!brd.good()&& !brd.eof() )
	return new error_response(http_response::INTERNAL_ERROR,
				  "Unable to read times from board file.");
    
    string tmp;
    if ( q->find("wtime", tmp))
	wtime = atoi(tmp.get_chars())*1000;
    if (q->find("btime", tmp))
	btime = atoi(tmp.get_chars())*1000;
    antichess_board *b = new antichess_board(brd);
    if ( b->initialized_correctly() == false) {
	delete b; b= 0;
	return new error_response(http_response::INTERNAL_ERROR, "<strong>  The initial board position file is in an invalid format. </strong>");
    }
    
    player *initiator = new human_player(q->fetch("name"), player_white?wtime:btime, this,false);
    player *opponent;
    if (human_human)
    opponent = new human_player("detached",player_white?btime:wtime,this,true);
    else opponent = new machine_player(player_white?btime:wtime,false);
    char gnum_buf[25];
    // We convert the board pointer to be an int, because it should be
    // a unique integer identifying the board.  We then xor it with
    // this because this will hopefully remove a lot of the high-order
    // bits; then we xor it with randomizing_mask so that you don't
    // always get the same game number for the first gameyou start each time the server is run.
    unsigned long  game_num = (unsigned long ) b;
    game_num ^= (unsigned long ) this;
    game_num ^= randomizing_mask;
    sprintf(gnum_buf, "%lu", game_num);
    string game_uri = gnum_buf;
    game_uri = base_uri()+game_uri+"/";
    game *g;
    if (player_white)
	g = new game(b, initiator, opponent, game_uri, image_uri, true);
    else  g = new game(b, opponent, initiator, game_uri, image_uri, false);
    check (add(gnum_buf, g), "Aargh!  I'm confused trying to add a game; I'm going to waste disk space.");
    return g->display(ext, player_white?0:1);
}

http_response *top_node::welcome( extensions *) {

  class initial_response: public normal_response {
    // Overview: Produces http response that contains the "welcome" screen for
    // the game
  public:
    initial_response(string uri, string ibase_in) 
    :normal_response(true)
    {
ibase = ibase_in;
      base = uri;
    }
    virtual void body (ostream &os) {
os <<"<html> <head>"<<endl;
      os << "<title>Antichess</title>\n";
os << "</head><body>\n";
      os << "<h1>Welcome to Antichess</h1>\n";
      os << "For help with Antichess, go to the <a\n";
      os << "href=\""<<ibase<<"help.html\">Antichess Help Page</a>. Otherwise, you may\n";
      os << "start a new game, load a saved game, or \n";
      os << "<a href=" << base << "incomplete_games>join an incomplete game</a>.\n";
      os << "<hr>\n";
      os << "<h2>Start a New Game</h2>\n";
      os << "<form method=\"get\" action=\"" << base << "new_game\">\n";
      os << "\n";
      os << "Name of Human Player: <input name=\"name\">\n";
      os << "<br>\n";
      os << "Opponent type: \n";
      os << "<select name=\"opponent\">\n";
      os << "<option selected>Computer</option>\n";
      os << "<option>Human</option>\n";
      os << "</select>\n";
      os << "<br>\n";
      os << "Side you want to play: \n";
      os << "<select name=\"side\">\n";
      os << "<option selected>white</option>\n";
      os << "<option>black</option>\n";
      os << "</select>\n";
      os << "<br>\n";
      os << "Time for white (in seconds): <input name=\"wtime\" type=\"int\">\n";
      os << "<br>\n";
      os << "Time for black (in seconds): <input name=\"btime\" type=\"int\">\n";
      os << "<br>\n";
      os << "<input type=\"submit\" value=\"Enter game\">\n";
      os << "<input type=\"reset\" value=\"Reset game info\">\n";
      os << "</form>\n";

      os << "<hr>\n";
      os << "<h2>Load a Saved Game</h2>\n";
      os << "<form method=\"get\" action=\"" << base << "new_game\">\n";
      os << "\n";
      os << "File to load: <input name=\"load\">\n";
      os << "<br>\n";
      os << "Name of Human Player: <input name=\"name\">\n";
      os << "<br>\n";
      os << "Opponent type: \n";
      os << "<select name=\"opponent\">\n";
      os << "<option selected>Computer</option>\n";
      os << "<option>Human</option>\n";
      os << "</select>\n";
      os << "<br>\n";
      os << "Side you want to play: \n";
      os << "<select name=\"side\">\n";
      os << "<option selected>white</option>\n";
      os << "<option>black</option>\n";
      os << "</select>\n";
      os << "<br>\n";
      os << "<input type=\"submit\" value=\"Load game\">\n";
      os << "<input type=\"reset\" value=\"Reset game info\">\n";
      os << "</form>\n";
      os << "<hr>\n";
      os << "<address>6.170-team1@@mit.edu</address>\n";
    }
  private:
    string base;
string ibase;
  };

    return new initial_response(base_uri(), image_uri);
}


http_response *top_node::ref_new_game(string query_args, extensions *ext) {
    map <string, string> * q = parse_query(query_args);
    if (!q)
	return new error_response(http_response::INTERNAL_ERROR,
				  "bad ref");
    
    string name;
    if ((!q->find("name", name))|| name.length() == 0)
	return new error_response(http_response::INTERNAL_ERROR,
				  "bad ref");
    
    bool player_white;
    string color;
    if ( (!q->find("side",color))||color.length() == 0)
	return new error_response(http_response::INTERNAL_ERROR,
				  "bad ref");
    if (toupper(color[0]) == 'W')
	player_white = true;
    else if (toupper(color[0]) == 'B')
	player_white = false;
    else return new error_response(http_response::INTERNAL_ERROR,
				   "bad ref");

    long wtime, btime;
    string tmp;
    if (q->find("wtime", tmp)){
	wtime = atoi(tmp.get_chars())*1000;
	if (wtime < 0)
	    wtime = 0;
    }
    else
	return new error_response(http_response::INTERNAL_ERROR,
				  "bad ref");
    
    if (q->find("btime", tmp)){
	btime = atoi(tmp.get_chars())*1000;
	if (btime < 0)
	    btime = 0;
    }
    else
	return new error_response(http_response::INTERNAL_ERROR,
				  "bad ref");
    player *initiator = new human_player(name, player_white?wtime:btime,
					 this,false);
    
    player *opponent = new machine_player(player_white?btime:wtime,true);
    ifstream brd;
    brd.open("initial.brd", ios::in|ios::nocreate);
    char dummy;
    brd >> dummy;
    int dt;
    brd>>dt >>dt;
    antichess_board *b = new antichess_board(brd);
    char gnum_buf[25];
    unsigned long  game_num = (unsigned long ) b;
    game_num ^= (unsigned long ) this;
    game_num ^= randomizing_mask;
    sprintf(gnum_buf, "%lu", game_num);
    string game_uri = gnum_buf;
    game_uri = base_uri()+game_uri+"/";
    game *g;
    if (player_white)
	g = new game(b, initiator, opponent, game_uri, image_uri, true);
    else  g = new game(b, opponent, initiator, game_uri, image_uri, false);
    check (add(gnum_buf, g), "Aargh!  I'm confused trying to add a game; I'm going to waste disk space.");
    return g->ref_display(ext);
}




void top_node::remove_from_detached(game *g) {
  string gkey = last_component(g->uri());
  struct open o;

  check (open_games->find(gkey, o), "Game is not detached, how can I remove_from_detached?");
  check (open_games->remove(gkey, o), "I cannot re-attach this game.");    
}


void top_node::add_to_detached( game *g, int player_num) {
    string gkey = last_component(g->uri());
    struct open o;
    if (open_games->find(gkey, o)) {
	check (o.pn != player_num,
	       "No, you can't detach yourself twice.");
				// OK, so both players detached.
	check (open_games->remove(gkey,o),
		      "So, why am I detaching a game I don't own?");
	       delete o.g;
	       o.g = 0;
	       check(open_games->remove(gkey, o),
		     "So, I just found the element, but wasn't there when I removed it.");
    }
    else  {
	o.g = g;
	o.pn = player_num;
	open_games->add(gkey, o);
    }
}

    
http_response *top_node::incomplete_games( extensions *ext) {

  class games_response: public normal_response {
    // Overview: Produces http response that contains a list of incomplete games.
  public:
    games_response(extensions *texts, map<string, open> *&open_games) 
    :normal_response(true) {
      exts = texts;
      games_map = open_games;
    }

    virtual void body (ostream &os) {
      generator<string> *games = games_map->keys();
      string curr_uri, opp_side;
      struct top_node::open o;
      player *opponent;
      
      os << "<title>Antichess Incomplete Games</title>";
      os << "<h1>Incomplete Games</h1>";
      
      os << "<a href=/welcome>Back to the top</a>";

      if (!games->get(curr_uri)) {
	os << "<h2>No Incomplete Games to Attach to.</h2>\n";
	os << "<hr>\n";
      }
      else 
	do {
	  check (games_map->find(curr_uri, o), "Bug in map generator. It's not our fault!");
	  
	  os << "<h2>About this game</h2>\n";
	  
	  opponent = o.g->get_player(1 - o.pn);
	  
	  os << "Time left: " << o.g->get_player(o.pn)->get_time() << "<br>\n";
	  os << "Opponent's name: " << opponent->get_name() << "<br>\n";
	  opponent->get_position(opp_side);
	  os << "Opponent's side: " << opp_side << "<br>\n";
	  os << "Opponent's time left: " << opponent->get_time() << "<br>\n";
	  
	  os << "<form method=\"get\" action=\"";
	  os << o.g->uri_with_move() << "player/" << o.pn << "/attach\">\n";
	  
	  os << "Name of Human Player: <input name=\"name\"><br>\n";
	  os << "<input type=\"submit\" value=\"Join this game\">\n";
	  os << "</form>\n";
	  os << "<hr>\n";
	} while (games->get(curr_uri));
      os << "<address>6.170-team1@@mit.edu</address>\n";
      delete games;
    }
  private:
    extensions *exts;
    map<string, open> *games_map;
  };
  
  return new games_response(ext, open_games);
}
@


1.38
log
@uncommented code
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.37 1995/12/13 00:00:45 daveg Exp $
d259 1
a259 1
    player *opponent = new machine_player(player_white?btime:wtime,false);
@


1.37
log
@finished ref_*
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.36 1995/12/12 23:30:30 hartmans Exp $
d42 2
a43 2
//    else if (first == "ref_new_game")
//	return ref_new_game(extract_query(request), ext);
a213 1
/*
d279 1
a279 1
    return g->ref_game(ext);
d281 1
a281 1
*/
@


1.36
log
@Remove bogus slash from form action tag.
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.35 1995/12/12 23:18:08 jered Exp $
d42 2
a43 2
    else if (first == "ref_new_game")
	return ref_new_game(extract_query(request), ext);
d214 1
a214 1

d282 3
@


1.35
log
@Minor changes.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.34 1995/12/12 14:40:33 hartmans Exp $
d354 1
a354 1
	  os << "<form method=\"get\" action=\"/";
@


1.34
log
@Fix handling of URI to chess help page,
look over ref_newgame code.


  CVS:
----------------------------------------------------------------------
automatically CVS: CVS: Committing in base CVS: CVS: Modified Files:
----------------------------------------------------------------------
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.33 1995/12/11 21:08:54 daveg Exp $
d150 1
a150 1
      os << "href=\""<<ibase<<"help\">Antichess Help Page</a>. Otherwise, you may\n";
@


1.33
log
@it compiles
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.32 1995/12/11 20:53:48 rgmisra Exp $
d59 1
a59 1
    if (q->contains("load")) 
d138 1
a138 1
    initial_response(string uri) 
d141 1
d145 1
d147 1
d150 1
a150 1
      os << "href=\"http://web.mit.edu/6.170/groups/se01/Public/html/help\">Antichess Help Page</a>. Otherwise, you may\n";
d207 1
d210 1
a210 1
    return new initial_response(base_uri());
@


1.32
log
@*** empty log message ***
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.31 1995/12/11 20:51:22 rgmisra Exp $
d42 2
d94 1
a94 1
				  "Unablbe to read times from board file.");
d102 4
a105 5
if ( b->initialized_correctly() == false) {
    delete b; b= 0;
    return new error_response(http_response::INTERNAL_ERROR, "<strong>  The initial board position file is in an invalid format. </strong>");
}
    
a106 1

d112 1
a112 1
char gnum_buf[25];
d206 71
a276 1
  return new initial_response(base_uri());
@


1.31
log
@last one, I hope.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.30 1995/12/11 20:34:22 rgmisra Exp $
d206 1
a206 1
  return new initial_response();
@


1.30
log
@hmm...
after detaching, welcome links don't work
base href should work.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.29 1995/12/11 20:12:48 rgmisra Exp $
d138 1
a138 1
    initial_response() 
d140 3
a142 1
    {}
a144 1
      os << "<base href=\"/\">\n";
d149 1
a149 1
      os << "<a href=incomplete_games>join an incomplete game</a>.\n";
d152 1
a152 1
      os << "<form method=\"get\" action=\"/new_game\">\n";
d178 1
a178 1
      os << "<form method=\"get\" action=\"/new_game\">\n";
d203 1
@


1.29
log
@added leading slashes to all methods
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.28 1995/12/11 15:28:53 rgmisra Exp $
d143 1
@


1.28
log
@got rid of duplicate address lines
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.27 1995/12/11 15:10:03 rgmisra Exp $
d150 1
a150 1
      os << "<form method=\"get\" action=\"new_game\">\n";
d176 1
a176 1
      os << "<form method=\"get\" action=\"new_game\">\n";
d277 1
a277 1
	  os << "<form method=\"get\" action=\"";
@


1.27
log
@back to top link on incomplete games
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.26 1995/12/11 13:15:07 rgmisra Exp $
a261 1
	os << "<address>6.170-team1@@mit.edu</address>\n";
@


1.26
log
@remove comment from remove_from_detached
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.25 1995/12/11 13:14:08 rgmisra Exp $
d257 2
@


1.25
log
@remove_from_detached works now...
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.24 1995/12/11 12:57:10 rgmisra Exp $
d211 1
a211 4
  check (open_games->remove(gkey, o), "I cannot re-attach this game.");
    

// Do nothing for now fixme
@


1.24
log
@oops... deleting players is bad
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.23 1995/12/11 12:40:21 rgmisra Exp $
d207 7
@


1.23
log
@cool... no core dumps.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.22 1995/12/11 11:22:49 rgmisra Exp $
a279 1
      os << "<hr>\n";
a281 1
      delete opponent;
@


1.22
log
@Load game should work, I think...
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.21 1995/12/11 10:16:57 hartmans Exp $
d51 2
a52 2
	if (!q)
	return new error_response(http_response::BAD_REQUEST, "Improperly formatted query string");
d146 2
a147 1
      os << "start a new game, load a saved game, or <a href=incomplete_games>join an incomplete game</a>.\n";
d172 1
d180 2
d196 1
d277 1
@


1.21
log
@web update for time and main
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.20 1995/12/11 08:18:58 rgmisra Exp $
d146 2
a147 2
      os << "start a new game or <a href=incomplete_games>join an incomplete game</a>.\n";
      os << "<hl>\n";
d170 21
@


1.20
log
@added address lines to welcome, incomplete_games
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.19 1995/12/11 07:25:05 rgmisra Exp $
d95 1
a95 1
    if ( q->find("btime", tmp))
@


1.19
log
@handles case of no incomplete games with a special message
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.18 1995/12/11 07:15:31 rgmisra Exp $
d171 2
d229 2
d253 2
d256 1
@


1.18
log
@static help page
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.17 1995/12/11 07:12:26 hartmans Exp $
d225 2
a226 22
      while (games->get(curr_uri)) {
	check (games_map->find(curr_uri, o), "Bug in map generator. It's not our fault!");
	
	os << "<h2>About this game</h2>\n";

	opponent = o.g->get_player(1 - o.pn);
	
	os << "Time left: " << o.g->get_player(o.pn)->get_time() << "<br>\n";
	os << "Opponent's name: " << opponent->get_name() << "<br>\n";
	opponent->get_position(opp_side);
	os << "Opponent's side: " << opp_side << "<br>\n";
	os << "Opponent's time left: " << opponent->get_time() << "<br>\n";

//	o.g->display(exts, o.pn)->body(os);
//	os << "<p>\n";

	os << "<form method=\"get\" action=\"";
	os << o.g->uri_with_move() << "player/" << o.pn << "/attach\">\n";
	
	os << "Name of Human Player: <input name=\"name\"><br>\n";
	os << "<input type=\"submit\" value=\"Join this game\">\n";
	os << "<hr>\n";
d228 21
@


1.17
log
@Handle loading of new games hopefully.
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.16 1995/12/11 05:49:45 rgmisra Exp $
d145 1
a145 1
      os << "href=help>Antichess Help Page</a>. Otherwise, you may\n";
@


1.16
log
@prettied sime things up
incomplete_games now keeps track of current status of games
doesn't return as much junk
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.15 1995/12/11 04:54:13 rgmisra Exp $
a48 1
    ifstream bstream("initial.brd", ios::in|ios::nocreate);
d50 2
a51 1
    if (!q)
d53 2
d57 4
d62 1
d80 14
a93 2
    int wtime = 300000;		// Default white time in ms
    int btime = 300000;
d99 1
a99 1
    antichess_board *b = new antichess_board(bstream);
@


1.15
log
@Oops... forgot opponent type
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.14 1995/12/11 02:37:27 rgmisra Exp $
d191 1
a191 1
    games_response(extensions *texts, map<string, open> *open_games) 
d199 1
a199 1
      string curr_uri;
d201 1
d210 2
d213 8
a220 2
	o.g->display(exts, o.pn)->body(os);
	os << "<p>\n";
@


1.14
log
@incomplete_games should work now, I hope.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.13 1995/12/10 01:36:10 jered Exp $
d133 6
@


1.13
log
@Fixed many bogosities.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.12 1995/12/10 00:16:48 rgmisra Exp $
d180 1
a180 1
http_response *top_node::incomplete_games( extensions *) {
d185 6
a190 3
    games_response() 
    :normal_response(true)
    {}
d192 23
a214 1

d217 2
d220 2
a221 2

  return new games_response();
@


1.12
log
@I'll finish this after dinner.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.11 1995/12/10 00:06:23 hartmans Exp $
d20 1
a20 1
    open_games = new map <string, game *>;
d165 1
a165 1
	check (remove(gkey,o),
@


1.11
log
@Fix compile error
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.10 1995/12/09 19:54:35 hartmans Exp $
d37 1
a37 1
	return new_game (extract_query(request), ext);
d39 3
a41 1
	return welcome(ext);
d123 6
a128 3
      os << "<title>Antichess</title>\n<h1>Welcome to Antichess</h1>\n";
      os << "For help with Antichess, go to the <a href=image_base/help>Antichess Help Page</a>.\n";
      os << "Otherwise, you may start a new game or <a href=join>join a game in progress</a>. <hl>\n";
d130 5
a134 9
      os << "<form method=\"get\" action=\"/newgame\">\n";
      os << "Time for black (in seconds): <input name=\"btime\" type=\"int\">\n";
      os << "<br>Name of Human Player: <input name=\"name\">\n";
      os << "<br>Play against: \n";
      os << "<select name=\"opponent\">\n";
      os << "<option selected>Computer</option>\n";
      os << "<option>Human</option>\n";
      os << "</select>\n";
      os << "<br>Side you want to play: \n";
d136 2
a137 2
      os << "<option selected>White</option>\n";
      os << "<option>Black</option>\n";
d139 1
d141 4
a144 1
      os << "<br><input type=\"submit\" value=\"Enter game\">\n";
d180 16
@


1.10
log
@Implement hooks for detach and reattach.
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.9 1995/12/08 00:26:24 rgmisra Exp $
a172 2

}
@


1.9
log
@Fixed newline stuff.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.8 1995/12/07 23:03:32 hartmans Exp $
d154 20
a173 1
    // do nothing: fixme
@


1.8
log
@Remove Ronnie's changes until he fixes them, fix game number generator
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.6 1995/12/06 01:53:31 hartmans Exp $
d112 34
a145 1
    return new normal_response(true);
@


1.7
log
@made welcome "non-trivial," returns an http_response
that contains welcome info for antichess.
@
text
@d3 1
a3 1
// $Header: /afs/athena.mit.edu/course/6/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.6 1995/12/06 01:53:31 hartmans Exp $
d101 1
a101 1
    string game_uri = game_num;
d110 1
d112 1
a112 41

  class initial_response: public normal_response {
    // Overview: Produces http response that contains the "welcome" screen for
    // the game
  public:
    initial_response() {}
    virtual void body (ostream &os) {
      os << "
<title>Antichess</title>
<h1>Welcome to Antichess</h1>
For help with Antichess, go to the <a
href=help>Antichess Help Page</a>. Otherwise, you may
start a new game or <a href=join>join a game in progress</a>.
<hl>
<h2>Start a New Game</h2>
<form method=\"get\" action=\"/newgame\">
Time for black (in seconds): <input name=\"btime\" type=\"int\">
<br>
Name of Human Player: <input name=\"name\">
<br>
Play against: 
<select name=\"opponent\">
<option selected>Computer</option>
<option>Human</option>
</select>
<br>
Side you want to play: 
<select name=\"side\">
<option selected>White</option>
<option>Black</option>
</select>
Time for white (in seconds): <input name=\"wtime\" type=\"int\">
<br>
<input type=\"submit\" value=\"Enter game\">
<input type=\"reset\" value=\"Reset game info\">
";
    }
  private:
  };

  return new initial_response(true);
@


1.6
log
@updates to make things compile
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.5 1995/12/03 05:03:00 hartmans Exp $
d111 41
a151 1
    return new normal_response(true);
@


1.5
log
@Correct call to game::game
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.4 1995/12/02 09:47:55 hartmans Exp $
d9 4
a12 1

d25 1
a25 1
#else
d33 1
a33 1
	return new error_response (http_response::bad_request,
d50 1
a50 1
	return new error_response(http_response::bad_request, "Improperly formatted query string");
d52 1
a52 1
	return new error_response(http_response::bad_request, "<strong> Request contained no player name.</strong>");
d55 1
a55 1
	return new error_response(http_response::bad_request, "<strong> Request contained no opponent specification.</strong>");
d61 1
a61 1
    else return new error_response(http_response::bad_request, "<strong> Request contained invalid opponent.</string>");
d65 1
a65 1
	return new error_response(http_response::bad_request, "<strong> Request contained missing or invalid side specification.</strong>");
d70 1
a70 1
else return new error_response(http_response::bad_request,"<strong> Invalid player side specified.</strong>");
d78 1
a78 1
board *b = new antichess_board(bstream);
d81 1
a81 1
    return new error_response(http_server::internal_error, "<strong>  The initial board position file is in an invalid format. </strong>");
d86 1
a86 1
    player *initiator = new human_player(name, player_white?wtime:btime, this,false);
d97 2
a98 2
    unsigned long  game_num = (unsigned long b);
    game_num ^= (unsigned long this);
d100 1
a100 1
    sprintf(gnum_buf, "%u", game_num);
d110 14
@


1.4
log
@Twiddle handling of player dispatch and construction.
@
text
@d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.3 1995/12/01 03:39:20 hartmans Exp $
d15 1
a15 1
top_node::top_node(string uri):
d18 1
d20 4
a23 1
    
d102 2
a103 2
	g = new game(b, initiator, opponent, game_uri, true);
    else  g = new game(b, opponent, initiator, game_uri, false);
@


1.3
log
@Integrate oral presentation changes into main line.
@
text
@d1 1
a1 1
/ This is -*- c++ -*- code
d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.2.2.1 1995/11/30 08:36:03 hartmans Exp $
@


1.2
log
@Implement top_node::new_game
and related methods
@
text
@d1 1
a1 1
// This is -*- c++ -*- code
d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.1 1995/11/28 08:20:32 hartmans Exp $
d8 2
d83 1
a83 1
    else opponent = new machine_player(player_white?btime:wtime);
@


1.2.2.1
log
@Make it compile if not link
@
text
@d1 1
a1 1
/ This is -*- c++ -*- code
d3 1
a3 1
// $Header: /mit/6.170/groups/se01/.cvsroot/src/web/top_node.C,v 1.2 1995/11/30 04:33:32 hartmans Exp $
a7 2
#include <machine_player.h>

d81 1
a81 1
    else opponent = new machine_player(player_white?btime:wtime,false);
@


1.1
log
@Partial implementation of a top level root node
@
text
@d3 1
a3 1
// $Header$
d13 2
a14 2
top_node::top_node():
dir_node("/"){
d16 2
a17 1

 {
    //