/* 
 * Thomas Pantzer: kalah_main.cc, v0.1b  27.1.98 22:12 
 * 
 * 
 * Copyright 1998 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@aix520.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */





#include "forms.h"
#include "mkopts.h"


#ifndef KALAH_PORT
#define KALAH_PORT	4321
#endif

#ifndef KALAH_SERVICE
#define KALAH_SERVICE	"kalah"
#endif


#define MAIN_G
  #include "kalah.h"
  #include "stuff.h"
  #include "netutils.h"
#include "copyright.h"



t_opts opts[] = {
	{empty_func,e_integer,'p',"port" ,"use port number\t",false,KALAH_PORT,0.0,"\0"},
#define port opts[0].i

	{empty_func,e_string ,'c',"client", "client mode, connect to",false,0,0.0,"localhost\0                                                                                                                           \0"},
#define host opts[1].s
#define client_mode opts[1].b

	{empty_func,e_boolean ,'s',"server" ,"start as server\t",false,0,0.0,"\0"},
#define server_mode opts[2].b




//	{empty_func,e_string ,'m',"mail", "your mail address",false,0,0.0,"\0                                                                                                                           \0"},
//#define mail opts[5].s

//	{empty_func,e_string ,'h',"host", "your primary host",false,0,0.0,"\0                                                                                                                           \0"},
//#define host opts[6].s

//	{empty_func,e_boolean,'s',"short_org", "abbreviation of org.",false,0,0.0,"\0"},
//#define S_ORG opts[7].b

	{empty_func,e_unknown,'\0',"\0","\0",0,0,0.0,"\0"}
	};
 



int main(int argc, char *argv[])
{
   peer = 0; // we start in single player mode
   ssock = 0;

	port = GetTCPPort(KALAH_SERVICE,KALAH_PORT);

	scan_args(argc,argv,opts);	

   fl_initialize(&argc, argv, 0, 0, 0);
   fd_kalah = create_form_kalah();

   /* fill-in form initialization code */
//   char host[256];
//   int port;
   
   /* show the first form */
   fl_show_form(fd_kalah->kalah,FL_PLACE_CENTER,FL_FULLBORDER,"The Game of Kalah");

	if (client_mode == true)
	   {
	    server_mode = false;
	    peer = clConnect_to(host,port); 	
	   }

	if (server_mode == true)
           { // server mode
            ssock = svListen(port,false);
            peer = svAccept(ssock);

            switch_cb(); // peer has first move
           }   
	
   fl_set_idle_callback(idle_cb,0);

   while (true)
     fl_do_forms();

   return 0;
}
