char *rcsid_gtk2_main_c = "$Id: main.c,v 1.7 2005/07/04 22:42:03 mwedel Exp $"; /* Crossfire client, a client program for the crossfire program. Copyright (C) 2005 Mark Wedel & Crossfire Development Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. The author can be reached via e-mail to crossfire@metalforge.org */ /* * Initial main.c file generated by Glade. Edit as required. * Glade will not overwrite this file. */ #ifdef HAVE_CONFIG_H # include #endif #include #include #include #include "interface.h" #include "support.h" #include "main.h" #include "client.h" #include "image.h" #include "gtk2proto.h" #include "script.h" #include "metaserver.h" GtkWidget *window_root, *magic_map; /* Sets up the basic colors. */ char *colorname[NUM_COLORS] = { "Black", /* 0 */ "White", /* 1 */ "Navy", /* 2 */ "Red", /* 3 */ "Orange", /* 4 */ "DodgerBlue", /* 5 */ "DarkOrange2", /* 6 */ "SeaGreen", /* 7 */ "DarkSeaGreen", /* 8 */ /* Used for window background color */ "Grey50", /* 9 */ "Sienna", /* 10 */ "Gold", /* 11 */ "Khaki" /* 12 */ }; GdkColor root_color[NUM_COLORS]; struct timeval timeout; extern int maxfd; gint csocket_fd=0; static uint8 updatekeycodes=FALSE; extern int time_map_redraw; #ifdef WIN32 /* Win32 scripting support */ #define PACKAGE_DATA_DIR "." int do_scriptout() { script_process(NULL); return(TRUE); } #endif /* WIN32 */ int do_timeout() { if (cpl.showmagic) magic_map_flash_pos(); inventory_tick(); return TRUE; } /* main loop iteration related stuff */ void do_network() { fd_set tmp_read; int pollret; if (csocket.fd==-1) { if (csocket_fd) { gdk_input_remove(csocket_fd); csocket_fd=0; gtk_main_quit(); } return; } FD_ZERO(&tmp_read); FD_SET(csocket.fd, &tmp_read); script_fdset(&maxfd,&tmp_read); pollret = select(maxfd, &tmp_read, NULL, NULL, &timeout); if (pollret==-1) { LOG(LOG_WARNING,"gtk::do_network", "Got errno %d on select call.", errno); } else if ( pollret>0 ) { if (FD_ISSET(csocket.fd, &tmp_read)) { DoClient(&csocket); #ifndef WIN32 if ( pollret > 1 ) script_process(&tmp_read); #endif } else { script_process(&tmp_read); } } #ifdef HAVE_SDL if (use_config[CONFIG_DISPLAYMODE]==CFG_DM_SDL) sdl_gen_map(FALSE); else #endif #ifdef HAVE_OPENGL if (use_config[CONFIG_DISPLAYMODE]==CFG_DM_OPENGL) opengl_gen_map(FALSE); else #endif draw_map(FALSE); LOG(0,"gtk::do_network","Map redrawn\n"); draw_lists(); } void event_loop() { gint fleep; extern int do_timeout(); int tag; if (MAX_TIME==0) { timeout.tv_sec = 0; timeout.tv_usec = 0; } maxfd = csocket.fd + 1; if (MAX_TIME!=0) { timeout.tv_sec = 0;/* MAX_TIME / 1000000;*/ timeout.tv_usec = 0;/* MAX_TIME % 1000000;*/ } fleep = gtk_timeout_add (10, (GtkFunction) do_timeout, NULL); #ifdef WIN32 gtk_timeout_add (25, (GtkFunction) do_scriptout, NULL); #endif csocket_fd = gdk_input_add ((gint) csocket.fd, GDK_INPUT_READ, (GdkInputFunction) do_network, &csocket); tag = csocket_fd; gtk_main(); gtk_timeout_remove(tag); LOG(LOG_INFO,"gtk::event_loop","gtk_main exited, returning from event_loop"); } /* Usage routine. All clients should support server, port and * display options, with -pix and -xpm also suggested. -split * does not need to be supported - it is in this copy because * the old code supported it. */ static void usage(char *progname) { puts("Usage of gcfclient:\n\n"); puts("-cache - Cache images for future use."); puts("-nocache - Do not cache images (default action)."); puts("-darkness - Enables darkness code (default)"); puts("-nodarkness - Disables darkness code"); puts("-display - Use instead if DISPLAY environment variable."); puts("-download_all_faces - Download all needed faces before play starts"); puts("-echo - Echo the bound commands"); puts("-noecho - Do not echo the bound commands (default)"); puts("-faceset - Use faceset if available"); puts("-fasttcpsend - Send data immediately to server, may increase bandwidth"); puts("-nofasttcpsend - Disables fasttcpsend"); puts("-fog - Enable fog of war code"); puts("-help - Display this message."); puts("-iconscale %% - Set icon scale percentage"); puts("-mapscale %% - Set map scale percentage"); puts("-mapsize xXy - Set the mapsize to be X by Y spaces. (default 11x11)"); puts("-splash - Display the splash screen (default)"); puts("-nosplash - Don't display the splash screen (startup logo)"); puts("-opengl - Use opengl drawing code"); puts("-pixmap - Use pixmap drawing code"); puts("-port - Use port instead of the standard port number"); puts("-sdl - Use sdl for drawing png (may not work on all hardware"); puts("-server - Connect to instead of localhost."); puts("-showicon - Print status icons in inventory window"); puts("-sound - Enable sound output (default)."); puts("-nosound - Disable sound output."); puts("-sound_server - Executable to use to play sounds."); puts("-resists - Control look of resistances."); puts("-split - Use split windows."); puts("-splitinfo - Use two information windows, segregated by information type."); puts("-timemapredraw - Print out timing information for map generation"); puts("-triminfowindow - Trims size of information window(s)"); puts("-notriminfowindow - Do not trims size of information window(s) (default)"); puts("-updatekeycodes - Update the saved bindings for this keyboard."); exit(0); } /* parse_args: Parses the command line options, and does some * variable initialization. * * This function returns 0 on success, nonzero on failure. */ int parse_args(int argc, char **argv) { int on_arg=1; char *display_name=""; load_defaults(); #ifndef WIN32 strcpy(VERSION_INFO,"GTK2 Unix Client " VERSION); #else strcpy(VERSION_INFO,"GTK2 Win32 Client " VERSION); #endif LOG(LOG_INFO,"Client Version",VERSION_INFO); /* Set this global so we get skill experience - gtk client can display * it, so lets get the info. */ want_skill_exp=1; for (on_arg=1; on_arg200) { LOG(LOG_WARNING,"gtk::init_windows","Valid range for -iconscale is 25 through 200"); want_config[CONFIG_ICONSCALE]=100; return 1; } continue; } else if( !strcmp( argv[on_arg],"-mapscale")) { if (++on_arg == argc) { LOG(LOG_WARNING,"gtk::init_windows","-mapscale requires a percentage value"); return 1; } want_config[CONFIG_MAPSCALE] = atoi(argv[on_arg]); if (want_config[CONFIG_MAPSCALE] < 25 || want_config[CONFIG_MAPSCALE]>200) { LOG(LOG_WARNING,"gtk::init_windows","Valid range for -mapscale is 25 through 200"); want_config[CONFIG_MAPSCALE]=100; return 1; } continue; } else if (!strcmp(argv[on_arg],"-mapsize")) { char *cp, x, y=0; if (++on_arg == argc) { LOG(LOG_WARNING,"gtk::init_windows","-mapsize requires a XxY value"); return 1; } x = atoi(argv[on_arg]); for (cp = argv[on_arg]; *cp!='\0'; cp++) if (*cp == 'x' || *cp == 'X') break; if (*cp==0) { LOG(LOG_WARNING,"gtk::init_windows","-mapsize requires both and X and Y value (ie, XxY - note the\nx in between."); } else { y = atoi(cp+1); } if (x<9 || y<9) { LOG(LOG_WARNING,"gtk::init_windows","map size must be positive values of at least 9"); } else if (x>MAP_MAX_SIZE || y>MAP_MAX_SIZE) { LOG(LOG_WARNING,"gtk::init_windows","Map size can not be larger than %d x %d", MAP_MAX_SIZE, MAP_MAX_SIZE); } else { want_config[CONFIG_MAPWIDTH]=x; want_config[CONFIG_MAPHEIGHT]=y; } continue; } else if (!strcmp(argv[on_arg],"-fasttcpsend")) { want_config[CONFIG_FASTTCP] = TRUE; continue; } else if (!strcmp(argv[on_arg],"-nofasttcpsend")) { want_config[CONFIG_FASTTCP] = FALSE; continue; } else if (!strcmp(argv[on_arg],"-opengl")) { #ifndef HAVE_OPENGL LOG(LOG_WARNING,"gtk::init_windows","client not compiled with opengl support. Ignoring -opengl"); #else want_config[CONFIG_DISPLAYMODE] = CFG_DM_OPENGL; #endif continue; } else if (!strcmp(argv[on_arg],"-pixmap")) { want_config[CONFIG_DISPLAYMODE] = CFG_DM_PIXMAP; } else if (!strcmp(argv[on_arg],"-port")) { if (++on_arg == argc) { LOG(LOG_WARNING,"gtk::init_windows","-port requires a port number"); return 1; } want_config[CONFIG_PORT] = atoi(argv[on_arg]); continue; } else if (!strcmp(argv[on_arg],"-sdl")) { #ifndef HAVE_SDL LOG(LOG_WARNING,"gtk::init_windows","client not compiled with sdl support. Ignoring -sdl"); #else want_config[CONFIG_DISPLAYMODE] = CFG_DM_SDL; #endif continue; } else if (!strcmp(argv[on_arg],"-server")) { if (++on_arg == argc) { LOG(LOG_WARNING,"gtk::init_windows","-server requires a host name"); return 1; } server = argv[on_arg]; continue; } else if (!strcmp(argv[on_arg],"-showicon")) { want_config[CONFIG_SHOWICON] = TRUE; continue; } else if (!strcmp(argv[on_arg],"-sound")) { want_config[CONFIG_SOUND] = TRUE; continue; } else if (!strcmp(argv[on_arg],"-nosound")) { want_config[CONFIG_SOUND] = FALSE; continue; } else if (!strcmp(argv[on_arg],"-sound_server")) { if (++on_arg == argc) { LOG(LOG_WARNING,"gtk::init_windows","-sound_server requires an executable pathname"); return 1; } sound_server = argv[on_arg]; continue; } else if (!strcmp(argv[on_arg],"-split")) { want_config[CONFIG_SPLITWIN]=TRUE; continue; } else if (!strcmp(argv[on_arg],"-nosplit")) { want_config[CONFIG_SPLITWIN]=FALSE; continue; } else if (!strcmp(argv[on_arg],"-resists")) { if (++on_arg == argc) { LOG(LOG_WARNING,"gtk::init_windows","-resists requires a value"); return 1; } want_config[CONFIG_RESISTS]=atoi(argv[on_arg]); continue; } else if (!strcmp(argv[on_arg],"-splitinfo")) { want_config[CONFIG_SPLITINFO]=TRUE; continue; } else if (!strcmp(argv[on_arg],"-timemapredraw")) { time_map_redraw=TRUE; continue; } else if (!strcmp(argv[on_arg],"-triminfowindow")) { want_config[CONFIG_TRIMINFO] = TRUE; continue; } else if (!strcmp(argv[on_arg],"-notriminfowindow")) { want_config[CONFIG_TRIMINFO] = FALSE; continue; } else if (!strcmp(argv[on_arg],"-updatekeycodes")) { updatekeycodes=TRUE; continue; } else if (!strcmp(argv[on_arg],"-splash")) { want_config[CONFIG_SPLASH] = TRUE; continue; } else if (!strcmp(argv[on_arg],"-nosplash")) { want_config[CONFIG_SPLASH] = FALSE; continue; } else { LOG(LOG_WARNING,"gtk::init_windows","Do not understand option %s", argv[on_arg]); usage(argv[0]); return 1; } } /* Now copy over the values just loaded */ for (on_arg=0; on_argwindow, x, y, w, h, &tmp); gdk_window_get_origin (win->window, wx, wy); *wx -= *x; *wy -= *y; }