int main(int argc, char *argv[]) { if(argc <= 1) return print_usage(argv[0]); main_argc = argc; main_argv = argv; if(!strcmp(argv[1], "-c")) { if(argc <= 3) return print_usage(argv[0]); char *net_addr = argv[2]; int net_port = atoi(argv[3]); printf("TODO: connect to \"%s\" port %i\n", net_addr, net_port); main_largstart = 4; boot_mode = 1; return 101; } else if(!strcmp(argv[1], "-s")) { if(argc <= 3) return print_usage(argv[0]); int net_port = atoi(argv[2]); mod_basedir = argv[3]; printf("TODO: run a server on port %i, mod \"%s\"\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 3; } else if(!strcmp(argv[1], "-d")) { if(argc <= 3) return print_usage(argv[0]); int net_port = atoi(argv[2]); mod_basedir = argv[3]; printf("TODO: run a ded server on port %i, mod \"%s\"\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 2; return 101; } else { return print_usage(argv[0]); } if(memcmp(mod_basedir,"pkg/",4)) { fprintf(stderr, "ERROR: package base dir must start with \"pkg/\"!\n"); return 109; } if(strlen(mod_basedir) < 5) { fprintf(stderr, "ERROR: package base dir can't actually be \"pkg/\"!\n"); return 109; } if((!(boot_mode & 1)) || !platform_init()) { if(!icelua_init()) { if(!net_init()) { if((!(boot_mode & 1)) || !video_init()) { if((!(boot_mode & 1)) || !wav_init()) { if((!(boot_mode & 1)) || !render_init(screen->w, screen->h)) { run_game(); if(boot_mode & 1) render_deinit(); } if(boot_mode & 1) wav_deinit(); } if(boot_mode & 1) video_deinit(); } net_deinit(); } icelua_deinit(); } if(boot_mode & 1) platform_deinit(); } return 0; }
int main_dbghelper(int argc, char *argv[]) { main_argc = argc; main_argv = argv; #ifdef DEDI if(argc <= 1) return print_usage(argv[0]); #else if(argc <= 1) { //print_usage(argv[0]); net_port = 0; mod_basedir = "pkg/iceball/halp"; printf("Starting server on port %i, mod \"%s\"\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 3; } else #endif #ifndef DEDI if((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "--help"))) { return print_usage(argv[0]); } else if(!strcmp(argv[1], "-c")) { if(argc <= 3) return print_usage(argv[0]); net_addr = argv[2]; net_port = atoi(argv[3]); printf("Connecting to \"%s\" port %i (ENet mode)\n", net_addr, net_port); mod_basedir = NULL; main_largstart = 4; boot_mode = 1 | 16; } else if(!strcmp(argv[1], "-C")) { if(argc <= 3) return print_usage(argv[0]); net_addr = argv[2]; net_port = atoi(argv[3]); printf("Connecting to \"%s\" port %i (TCP mode)\n", net_addr, net_port); mod_basedir = NULL; main_largstart = 4; boot_mode = 1; //return 101; } else if(!strcmp(argv[1], "-s")) { if(argc <= 3) return print_usage(argv[0]); net_port = atoi(argv[2]); mod_basedir = argv[3]; printf("Starting server on port %i, mod \"%s\" (local mode client)\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 3; } else #endif if(!strcmp(argv[1], "-d")) { if(argc <= 3) return print_usage(argv[0]); net_port = atoi(argv[2]); mod_basedir = argv[3]; printf("Starting headless/dedicated server on port %i, mod \"%s\"\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 2; //return 101; } else { return print_usage(argv[0]); } if(boot_mode & 2) { if(memcmp(mod_basedir,"pkg/",4)) { fprintf(stderr, "ERROR: package base dir must start with \"pkg/\"!\n"); return 109; } if(strlen(mod_basedir) < 5) { fprintf(stderr, "ERROR: package base dir can't actually be \"pkg/\"!\n"); return 109; } } #ifndef DEDI if((!(boot_mode & 1)) || !platform_init()) { #endif if(!net_init()) { if(!icelua_init()) { if((!(boot_mode & 2)) || !net_bind()) { #ifndef DEDI if((!(boot_mode & 1)) || !net_connect()) { if((!(boot_mode & 1)) || !video_init()) { if((!(boot_mode & 1)) || !wav_init()) { if((!(boot_mode & 1)) || !render_init(screen->w, screen->h)) { #endif run_game(); #ifndef DEDI if(boot_mode & 1) render_deinit(); } if(boot_mode & 1) wav_deinit(); } if(boot_mode & 1) video_deinit(); } if(boot_mode & 1) net_disconnect(); #endif } if(boot_mode & 2) net_unbind(); } icelua_deinit(); } net_deinit(); #ifndef DEDI } if(boot_mode & 1) platform_deinit(); } #endif return 0; }