void SCR_CheckDefaultMode(void) { INT32 scr_forcex, scr_forcey; // resolution asked from the cmd-line if (dedicated) return; // 0 means not set at the cmd-line scr_forcex = scr_forcey = 0; if (M_CheckParm("-width") && M_IsNextParm()) scr_forcex = atoi(M_GetNextParm()); if (M_CheckParm("-height") && M_IsNextParm()) scr_forcey = atoi(M_GetNextParm()); if (scr_forcex && scr_forcey) { CONS_Printf(M_GetText("Using resolution: %d x %d\n"), scr_forcex, scr_forcey); // returns -1 if not found, thus will be 0 (no mode change) if not found setmodeneeded = VID_GetModeForSize(scr_forcex, scr_forcey) + 1; } else { CONS_Printf(M_GetText("Default resolution: %d x %d (%d bits)\n"), cv_scr_width.value, cv_scr_height.value, cv_scr_depth.value); // see note above setmodeneeded = VID_GetModeForSize(cv_scr_width.value, cv_scr_height.value) + 1; } }
boolean LoadGL(void) { #ifndef STATIC_OPENGL const char *OGLLibname = NULL; const char *GLULibname = NULL; if (M_CheckParm ("-OGLlib") && M_IsNextParm()) OGLLibname = M_GetNextParm(); if (SDL_GL_LoadLibrary(OGLLibname) != 0) { DEBPRINT(va("Could not load OpenGL Library: %s\n" "Falling back to Software mode.\n", SDL_GetError())); if (!M_CheckParm ("-OGLlib")) DEBPRINT("If you know what is the OpenGL library's name, use -OGLlib\n"); return 0; } #if 0 GLULibname = "/proc/self/exe"; #elif defined (_WIN32) GLULibname = "GLU32.DLL"; #elif defined (__MACH__) GLULibname = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib"; #elif defined (macintos) GLULibname = "OpenGLLibrary"; #elif defined (__unix__) GLULibname = "libGLU.so.1"; #elif defined (__HAIKU__) GLULibname = "libGLU.so"; #else GLULibname = NULL; #endif if (M_CheckParm ("-GLUlib") && M_IsNextParm()) GLULibname = M_GetNextParm(); if (GLULibname) { GLUhandle = hwOpen(GLULibname); if (GLUhandle) return SetupGLfunc(); else { DEBPRINT(va("Could not load GLU Library: %s\n", GLULibname)); if (!M_CheckParm ("-GLUlib")) DEBPRINT("If you know what is the GLU library's name, use -GLUlib\n"); } } else { DEBPRINT("Could not load GLU Library\n"); DEBPRINT("If you know what is the GLU library's name, use -GLUlib\n"); } #endif return SetupGLfunc(); }
boolean LoadGL(void) { const char *OGLLibname = NULL; const char *GLULibname = NULL; if (M_CheckParm ("-OGLlib") && M_IsNextParm()) OGLLibname = M_GetNextParm(); if (SDL_GL_LoadLibrary(OGLLibname) != 0) { I_OutputMsg("Could not load OpenGL Library: %s\n", SDL_GetError()); I_OutputMsg("falling back to Software mode\n"); if (!M_CheckParm ("-OGLlib")) I_OutputMsg("if you know what is the OpenGL library's name, use -OGLlib\n"); return 0; } #if 0 GLULibname = "/proc/self/exe"; #elif defined (_WIN32) GLULibname = "GLU32.DLL"; #elif defined (__MACH__) GLULibname = "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib"; #elif defined (macintos) GLULibname = "OpenGLLibrary"; #elif defined (__unix__) || defined (__HAIKU__) GLULibname = "libGLU.so"; #else GLULibname = NULL; #endif if (M_CheckParm ("-GLUlib") && M_IsNextParm()) GLULibname = M_GetNextParm(); if (GLULibname) { GLUhandle = hwOpen(GLULibname); if (GLUhandle) return SetupGLfunc(); else { I_OutputMsg("Could not load GLU Library: %s\n", GLULibname); I_OutputMsg("falling back to Software mode\n"); if (!M_CheckParm ("-GLUlib")) I_OutputMsg("if you know what is the GLU library's name, use -GLUlib\n"); } } else { I_OutputMsg("Please fill a bug report to tell SRB2 where to find the default GLU library for this unknown OS\n"); I_OutputMsg("falling back to Software mode\n"); I_OutputMsg("if you know what is the GLU library's name, use -GLUlib\n"); } return 0; }
const char *D_Home(void) { const char *userhome = NULL; #ifdef ANDROID return "/data/data/org.srb2/"; #endif #ifdef _arch_dreamcast char VMUHOME[] = "HOME=/vmu/a1"; putenv(VMUHOME); //don't use I_PutEnv #endif if (M_CheckParm("-home") && M_IsNextParm()) userhome = M_GetNextParm(); else { #if defined (GP2X) usehome = false; //let use the CWD return NULL; #elif !((defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON)) && !defined (__APPLE__) && !defined(_WIN32_WCE) if (FIL_FileOK(CONFIGFILENAME)) usehome = false; // Let's NOT use home else #endif userhome = I_GetEnv("HOME"); //Alam: my new HOME for srb2 } #if defined (_WIN32) && !defined(_WIN32_WCE) //Alam: only Win32 have APPDATA and USERPROFILE if (!userhome && usehome) //Alam: Still not? { char *testhome = NULL; testhome = I_GetEnv("APPDATA"); if (testhome != NULL && (FIL_FileOK(va("%s" PATHSEP "%s" PATHSEP CONFIGFILENAME, testhome, DEFAULTDIR)))) { userhome = testhome; } } #ifndef __CYGWIN__ if (!userhome && usehome) //Alam: All else fails? { char *testhome = NULL; testhome = I_GetEnv("USERPROFILE"); if (testhome != NULL && (FIL_FileOK(va("%s" PATHSEP "%s" PATHSEP CONFIGFILENAME, testhome, DEFAULTDIR)))) { userhome = testhome; } } #endif// !__CYGWIN__ #endif// _WIN32 if (usehome) return userhome; else return NULL; }
static UDPsocket NET_Socket(void) { UDPsocket temp = NULL; Uint16 portnum = 0; IPaddress tempip = {INADDR_BROADCAST,0}; //Hurdler: I'd like to put a server and a client on the same computer //Logan: Me too //BP: in fact for client we can use any free port we want i have read // in some doc that connect in udp can do it for us... //Alam: where? if (M_CheckParm("-clientport")) { if (!M_IsNextParm()) I_Error("syntax: -clientport <portnum>"); portnum = atoi(M_GetNextParm()); } else portnum = sock_port; temp = SDLNet_UDP_Open(portnum); if (!temp) { CONS_Printf("SDL_Net: %s",SDLNet_GetError()); return NULL; } if (SDLNet_UDP_Bind(temp,BROADCASTADDR-1,&tempip) == -1) { CONS_Printf("SDL_Net: %s",SDLNet_GetError()); SDLNet_UDP_Close(temp); return NULL; } clientaddress[BROADCASTADDR].port = sock_port; clientaddress[BROADCASTADDR].host = INADDR_BROADCAST; doomcom->extratics = 1; // internet is very high ping return temp; }
// // D_CheckNetGame // Works out player numbers among the net participants // boolean D_CheckNetGame(void) { boolean ret = false; InitAck(); rebound_tail = rebound_head = 0; statstarttic = I_GetTime(); I_NetGet = Internal_Get; I_NetSend = Internal_Send; I_NetCanSend = NULL; I_NetCloseSocket = NULL; I_NetFreeNodenum = Internal_FreeNodenum; I_NetMakeNodewPort = NULL; hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; net_bandwidth = 30000; // I_InitNetwork sets doomcom and netgame // check and initialize the network driver multiplayer = false; // only dos version with external driver will return true netgame = I_InitNetwork(); if (!netgame && !I_NetOpenSocket) { D_SetDoomcom(); netgame = I_InitTcpNetwork(); } if (netgame) ret = true; if (!server && netgame) netgame = false; server = true; // WTF? server always true??? // no! The deault mode is server. Client is set elsewhere // when the client executes connect command. doomcom->ticdup = 1; if (M_CheckParm("-extratic")) { if (M_IsNextParm()) doomcom->extratics = (INT16)atoi(M_GetNextParm()); else doomcom->extratics = 1; CONS_Printf(M_GetText("Set extratics to %d\n"), doomcom->extratics); } if (M_CheckParm("-bandwidth")) { if (M_IsNextParm()) { net_bandwidth = atoi(M_GetNextParm()); if (net_bandwidth < 1000) net_bandwidth = 1000; if (net_bandwidth > 100000) hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; CONS_Printf(M_GetText("Network bandwidth set to %d\n"), net_bandwidth); } else I_Error("usage: -bandwidth <byte_per_sec>"); } software_MAXPACKETLENGTH = hardware_MAXPACKETLENGTH; if (M_CheckParm("-packetsize")) { if (M_IsNextParm()) { INT32 p = atoi(M_GetNextParm()); if (p < 75) p = 75; if (p > hardware_MAXPACKETLENGTH) p = hardware_MAXPACKETLENGTH; software_MAXPACKETLENGTH = (UINT16)p; } else I_Error("usage: -packetsize <bytes_per_packet>"); } if (netgame) multiplayer = true; if (doomcom->id != DOOMCOM_ID) I_Error("Doomcom buffer invalid!"); if (doomcom->numnodes > MAXNETNODES) I_Error("Too many nodes (%d), max:%d", doomcom->numnodes, MAXNETNODES); netbuffer = (doomdata_t *)(void *)&doomcom->data; #ifdef DEBUGFILE #ifdef _arch_dreamcast //debugfile = stderr; if (debugfile) CONS_Printf(M_GetText("debug output to: %s\n"), "STDERR"); #else if (M_CheckParm("-debugfile")) { char filename[20]; INT32 k = doomcom->consoleplayer - 1; if (M_IsNextParm()) k = atoi(M_GetNextParm()) - 1; while (!debugfile && k < MAXPLAYERS) { k++; sprintf(filename, "debug%d.txt", k); debugfile = fopen(filename, "w"); } if (debugfile) CONS_Printf(M_GetText("debug output to: %s\n"), filename); else CONS_Alert(CONS_WARNING, M_GetText("cannot debug output to file %s!\n"), filename); } #endif #endif D_ClientServerInit(); return ret; }
// // D_SRB2Main // void D_SRB2Main(void) { INT32 p; char srb2[82]; // srb2 title banner char title[82]; INT32 pstartmap = 1; boolean autostart = false; // keep error messages until the final flush(stderr) #if !defined (PC_DOS) && !defined (_WIN32_WCE) && !defined(NOTERMIOS) if (setvbuf(stderr, NULL, _IOFBF, 1000)) I_OutputMsg("setvbuf didnt work\n"); #endif #ifdef GETTEXT // initialise locale code M_StartupLocale(); #endif // get parameters from a response file (eg: srb2 @parms.txt) M_FindResponseFile(); // MAINCFG is now taken care of where "OBJCTCFG" is handled G_LoadGameSettings(); // Test Dehacked lists DEH_Check(); // identify the main IWAD file to use IdentifyVersion(); #if !defined (_WIN32_WCE) && !defined(NOTERMIOS) setbuf(stdout, NULL); // non-buffered output #endif #if defined (_WIN32_WCE) //|| defined (_DEBUG) || defined (GP2X) devparm = !M_CheckParm("-nodebug"); #else devparm = M_CheckParm("-debug"); #endif // for dedicated server #if !defined (_WINDOWS) //already check in win_main.c dedicated = M_CheckParm("-dedicated") != 0; #endif strcpy(title, "Sonic Robo Blast 2"); strcpy(srb2, "Sonic Robo Blast 2"); D_MakeTitleString(srb2); #ifdef PC_DOS D_Titlebar(srb2, title); #endif #if defined (__OS2__) && !defined (SDL) // set PM window title snprintf(pmData->title, sizeof (pmData->title), "Sonic Robo Blast 2" VERSIONSTRING ": %s", title); pmData->title[sizeof (pmData->title) - 1] = '\0'; #endif if (devparm) CONS_Printf(M_GetText("Development mode ON.\n")); // default savegame strcpy(savegamename, SAVEGAMENAME"%u.ssg"); { const char *userhome = D_Home(); //Alam: path to home if (!userhome) { #if ((defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON)) && !defined (__CYGWIN__) && !defined (DC) && !defined (PSP) && !defined(GP2X) I_Error("Please set $HOME to your home directory\n"); #elif defined (_WIN32_WCE) && 0 if (dedicated) snprintf(configfile, sizeof configfile, "/Storage Card/SRB2DEMO/d"CONFIGFILENAME); else snprintf(configfile, sizeof configfile, "/Storage Card/SRB2DEMO/"CONFIGFILENAME); #else if (dedicated) snprintf(configfile, sizeof configfile, "d"CONFIGFILENAME); else snprintf(configfile, sizeof configfile, CONFIGFILENAME); #endif } else { // use user specific config file #ifdef DEFAULTDIR snprintf(srb2home, sizeof srb2home, "%s" PATHSEP DEFAULTDIR, userhome); snprintf(downloaddir, sizeof downloaddir, "%s" PATHSEP "DOWNLOAD", srb2home); if (dedicated) snprintf(configfile, sizeof configfile, "%s" PATHSEP "d"CONFIGFILENAME, srb2home); else snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2home); // can't use sprintf since there is %u in savegamename strcatbf(savegamename, srb2home, PATHSEP); I_mkdir(srb2home, 0700); #else snprintf(srb2home, sizeof srb2home, "%s", userhome); snprintf(downloaddir, sizeof downloaddir, "%s", userhome); if (dedicated) snprintf(configfile, sizeof configfile, "%s" PATHSEP "d"CONFIGFILENAME, userhome); else snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, userhome); // can't use sprintf since there is %u in savegamename strcatbf(savegamename, userhome, PATHSEP); #endif } configfile[sizeof configfile - 1] = '\0'; #ifdef _arch_dreamcast strcpy(downloaddir, "/ram"); // the dreamcast's TMP #endif } // rand() needs seeded regardless of password srand((unsigned int)time(NULL)); if (M_CheckParm("-password") && M_IsNextParm()) D_SetPassword(M_GetNextParm()); else { size_t z; char junkpw[25]; for (z = 0; z < 24; z++) junkpw[z] = (char)(rand() & 64)+32; junkpw[24] = '\0'; D_SetPassword(junkpw); } // add any files specified on the command line with -file wadfile // to the wad list if (!(M_CheckParm("-connect"))) { if (M_CheckParm("-file")) { // the parms after p are wadfile/lump names, // until end of parms or another - preceded parm while (M_IsNextParm()) { const char *s = M_GetNextParm(); if (s) // Check for NULL? { if (!W_VerifyNMUSlumps(s)) G_SetGameModified(true); D_AddFile(s); } } } } // get map from parms if (M_CheckParm("-server") || dedicated) netgame = server = true; if (M_CheckParm("-warp") && M_IsNextParm()) { const char *word = M_GetNextParm(); if (fastncmp(word, "MAP", 3)) pstartmap = M_MapNumber(word[3], word[4]); else pstartmap = atoi(word); // Don't check if lump exists just yet because the wads haven't been loaded! // Just do a basic range check here. if (pstartmap < 1 || pstartmap > NUMMAPS) I_Error("Cannot warp to map %d (out of range)\n", pstartmap); else { if (!M_CheckParm("-server")) G_SetGameModified(true); autostart = true; } } CONS_Printf("Z_Init(): Init zone memory allocation daemon. \n"); Z_Init(); // adapt tables to SRB2's needs, including extra slots for dehacked file support P_PatchInfoTables(); //---------------------------------------------------- READY TIME // we need to check for dedicated before initialization of some subsystems CONS_Printf("I_StartupTimer()...\n"); I_StartupTimer(); // Make backups of some SOCcable tables. P_BackupTables(); // Setup default unlockable conditions M_SetupDefaultConditionSets(); // load wad, including the main wad file CONS_Printf("W_InitMultipleFiles(): Adding IWAD and main PWADs.\n"); if (!W_InitMultipleFiles(startupwadfiles)) #ifdef _DEBUG CONS_Error("A WAD file was not found or not valid.\nCheck the log to see which ones.\n"); #else I_Error("A WAD file was not found or not valid.\nCheck the log to see which ones.\n"); #endif D_CleanFile(); #if 1 // md5s last updated 3/15/14 // Yes, you read that right, that's the day of release. // Aren't we batshit insane? // Check MD5s of autoloaded files W_VerifyFileMD5(0, "ac309fb3c7d4b5b685e2cd26beccf0e8"); // srb2.srb/srb2.wad W_VerifyFileMD5(1, "a894044b555dfcc71865cee16a996e88"); // zones.dta W_VerifyFileMD5(2, "4c410c1de6e0440cc5b2858dcca80c3e"); // player.dta W_VerifyFileMD5(3, "85901ad4bf94637e5753d2ac2c03ea26"); // rings.dta W_VerifyFileMD5(4, "c529930ee5aed6dbe33625dc8075520b"); // patch.dta // don't check music.dta because people like to modify it, and it doesn't matter if they do // ...except it does if they slip maps in there, and that's what W_VerifyNMUSlumps is for. #endif mainwads = 5; // there are 5 wads not to unload cht_Init(); //---------------------------------------------------- READY SCREEN // we need to check for dedicated before initialization of some subsystems CONS_Printf("I_StartupGraphics()...\n"); I_StartupGraphics(); //--------------------------------------------------------- CONSOLE // setup loading screen SCR_Startup(); // we need the font of the console CONS_Printf("HU_Init(): Setting up heads up display.\n"); HU_Init(); COM_Init(); // libogc has a CON_Init function, we must rename SRB2's CON_Init in WII/libogc #ifndef _WII CON_Init(); #else CON_InitWii(); #endif D_RegisterServerCommands(); D_RegisterClientCommands(); // be sure that this is called before D_CheckNetGame R_RegisterEngineStuff(); S_RegisterSoundStuff(); I_RegisterSysCommands(); //--------------------------------------------------------- CONFIG.CFG M_FirstLoadConfig(); // WARNING : this do a "COM_BufExecute()" G_LoadGameData(); #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (SDL) VID_PrepareModeList(); // Regenerate Modelist according to cv_fullscreen #endif // set user default mode or mode set at cmdline SCR_CheckDefaultMode(); wipegamestate = gamestate; P_InitMapHeaders(); savedata.lives = 0; // flag this as not-used //------------------------------------------------ COMMAND LINE PARAMS // Initialize CD-Audio if (M_CheckParm("-usecd") && !dedicated) I_InitCD(); if (M_CheckParm("-noupload")) COM_BufAddText("downloading 0\n"); CONS_Printf("M_Init(): Init miscellaneous info.\n"); M_Init(); CONS_Printf("R_Init(): Init SRB2 refresh daemon.\n"); R_Init(); // setting up sound CONS_Printf("S_Init(): Setting up sound.\n"); if (M_CheckParm("-nosound")) nosound = true; if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic nomidimusic = nodigimusic = true; else { if (M_CheckParm("-nomidimusic")) nomidimusic = true; ; // WARNING: DOS version initmusic in I_StartupSound if (M_CheckParm("-nodigmusic")) nodigimusic = true; // WARNING: DOS version initmusic in I_StartupSound } I_StartupSound(); I_InitMusic(); S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); if (M_CheckParm("-room")) { if (!M_IsNextParm()) I_Error("usage: -room <room_id>\nCheck the Master Server's webpage for room ID numbers.\n"); #ifdef UPDATE_ALERT GetMODVersion_Console(); #endif ms_RoomId = atoi(M_GetNextParm()); } // init all NETWORK CONS_Printf("D_CheckNetGame(): Checking network game status.\n"); if (D_CheckNetGame()) autostart = true; // check for a driver that wants intermission stats // start the apropriate game based on parms if (M_CheckParm("-metal")) { G_RecordMetal(); autostart = true; } else if (M_CheckParm("-record") && M_IsNextParm()) { G_RecordDemo(M_GetNextParm()); autostart = true; } // user settings come before "+" parameters. if (dedicated) COM_ImmedExecute(va("exec \"%s"PATHSEP"adedserv.cfg\"\n", srb2home)); else COM_ImmedExecute(va("exec \"%s"PATHSEP"autoexec.cfg\" -noerror\n", srb2home)); if (!autostart) M_PushSpecialParameters(); // push all "+" parameters at the command buffer // demo doesn't need anymore to be added with D_AddFile() p = M_CheckParm("-playdemo"); if (!p) p = M_CheckParm("-timedemo"); if (p && M_IsNextParm()) { char tmp[MAX_WADPATH]; // add .lmp to identify the EXTERNAL demo file // it is NOT possible to play an internal demo using -playdemo, // rather push a playdemo command.. to do. strcpy(tmp, M_GetNextParm()); // get spaced filename or directory while (M_IsNextParm()) { strcat(tmp, " "); strcat(tmp, M_GetNextParm()); } FIL_DefaultExtension(tmp, ".lmp"); CONS_Printf(M_GetText("Playing demo %s.\n"), tmp); if (M_CheckParm("-playdemo")) { singledemo = true; // quit after one demo G_DeferedPlayDemo(tmp); } else G_TimeDemo(tmp); G_SetGamestate(GS_NULL); wipegamestate = GS_NULL; return; } if (M_CheckParm("-ultimatemode")) { autostart = true; ultimatemode = true; } if (autostart || netgame || M_CheckParm("+connect") || M_CheckParm("-connect")) { gameaction = ga_nothing; CV_ClearChangedFlags(); // Do this here so if you run SRB2 with eg +timelimit 5, the time limit counts // as having been modified for the first game. M_PushSpecialParameters(); // push all "+" parameter at the command buffer if (M_CheckParm("-gametype") && M_IsNextParm()) { // from Command_Map_f INT32 j; INT16 newgametype = -1; const char *sgametype = M_GetNextParm(); for (j = 0; gametype_cons_t[j].strvalue; j++) if (!strcasecmp(gametype_cons_t[j].strvalue, sgametype)) { newgametype = (INT16)gametype_cons_t[j].value; break; } if (!gametype_cons_t[j].strvalue) // reached end of the list with no match { j = atoi(sgametype); // assume they gave us a gametype number, which is okay too if (j >= 0 && j < NUMGAMETYPES) newgametype = (INT16)j; } if (newgametype != -1) { j = gametype; gametype = newgametype; D_GameTypeChanged(j); } } if (server && !M_CheckParm("+map") && !M_CheckParm("+connect") && !M_CheckParm("-connect")) { // Prevent warping to nonexistent levels if (W_CheckNumForName(G_BuildMapName(pstartmap)) == LUMPERROR) I_Error("Could not warp to %s (map not found)\n", G_BuildMapName(pstartmap)); // Prevent warping to locked levels // ... unless you're in a dedicated server. Yes, technically this means you can view any level by // running a dedicated server and joining it yourself, but that's better than making dedicated server's // lives hell. else if (!dedicated && M_MapLocked(pstartmap)) I_Error("You need to unlock this level before you can warp to it!\n"); else D_MapChange(pstartmap, gametype, ultimatemode, true, 0, false, false); } } else if (M_CheckParm("-skipintro")) { CON_ToggleOff(); CON_ClearHUD(); F_StartTitleScreen(); } else F_StartIntro(); // Tails 03-03-2002 if (dedicated && server) { pagename = "TITLESKY"; levelstarttic = gametic; G_SetGamestate(GS_LEVEL); if (!P_SetupLevel(false)) I_Quit(); // fail so reset game stuff } }
// // I_InitNetwork // Only required for DOS, so this is more a dummy // boolean I_InitNetwork(void) { #ifdef HAVE_SDLNET char serverhostname[255]; boolean ret = false; SDL_version SDLcompiled; const SDL_version *SDLlinked = SDLNet_Linked_Version(); SDL_NET_VERSION(&SDLcompiled) CONS_Printf("Compiled for SDL_Net version: %d.%d.%d\n", SDLcompiled.major, SDLcompiled.minor, SDLcompiled.patch); CONS_Printf("Linked with SDL_Net version: %d.%d.%d\n", SDLlinked->major, SDLlinked->minor, SDLlinked->patch); //if (!M_CheckParm ("-sdlnet")) // return false; // initilize the driver I_InitSDLNetDriver(); I_AddExitFunc(I_ShutdownSDLNetDriver); if (!init_SDLNet_driver) return false; if (M_CheckParm("-udpport")) { if (M_IsNextParm()) sock_port = (UINT16)atoi(M_GetNextParm()); else sock_port = 0; } // parse network game options, if (M_CheckParm("-server") || dedicated) { server = true; // If a number of clients (i.e. nodes) is specified, the server will wait for the clients // to connect before starting. // If no number is specified here, the server starts with 1 client, and others can join // in-game. // Since Boris has implemented join in-game, there is no actual need for specifying a // particular number here. // FIXME: for dedicated server, numnodes needs to be set to 0 upon start /* if (M_IsNextParm()) doomcom->numnodes = (INT16)atoi(M_GetNextParm()); else */if (dedicated) doomcom->numnodes = 0; else doomcom->numnodes = 1; if (doomcom->numnodes < 0) doomcom->numnodes = 0; if (doomcom->numnodes > MAXNETNODES) doomcom->numnodes = MAXNETNODES; // server servernode = 0; // FIXME: // ??? and now ? // server on a big modem ??? 4*isdn net_bandwidth = 16000; hardware_MAXPACKETLENGTH = INETPACKETLENGTH; ret = true; } else if (M_CheckParm("-connect")) { if (M_IsNextParm()) strcpy(serverhostname, M_GetNextParm()); else serverhostname[0] = 0; // assuming server in the LAN, use broadcast to detect it // server address only in ip if (serverhostname[0]) { COM_BufAddText("connect \""); COM_BufAddText(serverhostname); COM_BufAddText("\"\n"); // probably modem hardware_MAXPACKETLENGTH = INETPACKETLENGTH; } else { // so we're on a LAN COM_BufAddText("connect any\n"); net_bandwidth = 800000; hardware_MAXPACKETLENGTH = MAXPACKETLENGTH; } } mypacket.maxlen = hardware_MAXPACKETLENGTH; I_NetOpenSocket = NET_OpenSocket; I_Ban = NET_Ban; I_ClearBans = NET_ClearBans; I_GetNodeAddress = NET_GetNodeAddress; I_GetBenAddress = NET_GetBenAddress; I_SetBanAddress = NET_SetBanAddress; bannednode = NET_bannednode; return ret; #else if ( M_CheckParm ("-net") ) { I_Error("-net not supported, use -server and -connect\n" "see docs for more\n"); } return false; #endif }
// // D_SRB2Main // void D_SRB2Main(void) { INT32 p; char srb2[82]; // srb2 title banner char title[82]; INT32 pstartmap = 1; boolean autostart = false; // keep error messages until the final flush(stderr) #if !defined (PC_DOS) && !defined (_WIN32_WCE) && !defined(NOTERMIOS) if (setvbuf(stderr, NULL, _IOFBF, 1000)) DEBPRINT("setvbuf didnt work\n"); #endif #ifdef GETTEXT // initialise locale code M_StartupLocale(); #endif // get parameters from a response file (eg: srb2 @parms.txt) M_FindResponseFile(); // MAINCFG is now taken care of where "OBJCTCFG" is handled G_LoadGameSettings(); // identify the main IWAD file to use IdentifyVersion(); #if !defined (_WIN32_WCE) && !defined(NOTERMIOS) setbuf(stdout, NULL); // non-buffered output #endif #if defined (_WIN32_WCE) //|| defined (_DEBUG) || defined (GP2X) devparm = !M_CheckParm("-nodebug"); #else devparm = M_CheckParm("-debug"); #endif // for dedicated server #if !defined (_WINDOWS) //already check in win_main.c dedicated = M_CheckParm("-dedicated") != 0; #endif strcpy(title, "Sonic Robo Blast 2"); strcpy(srb2, "Sonic Robo Blast 2"); D_MakeTitleString(srb2); #ifdef PC_DOS D_Titlebar(srb2, title); #else CONS_Printf("SRB2"VERSIONSTRING"\n"); #endif #if defined (__OS2__) && !defined (SDL) // set PM window title snprintf(pmData->title, sizeof (pmData->title), "Sonic Robo Blast 2" VERSIONSTRING ": %s", title); pmData->title[sizeof (pmData->title) - 1] = '\0'; #endif if (devparm) CONS_Printf("%s", M_GetText("Development mode ON.\n")); // default savegame strcpy(savegamename, SAVEGAMENAME"%u.ssg"); { const char *userhome = D_Home(); //Alam: path to home if (!userhome) { #if ((defined (__unix__) && !defined (MSDOS)) || defined(__APPLE__) || defined (UNIXCOMMON)) && !defined (__CYGWIN__) && !defined (DC) && !defined (PSP) && !defined(GP2X) I_Error("%s", M_GetText("Please set $HOME to your home directory\n")); #elif defined (_WIN32_WCE) && 0 if (dedicated) snprintf(configfile, sizeof configfile, "/Storage Card/SRB2DEMO/d"CONFIGFILENAME); else snprintf(configfile, sizeof configfile, "/Storage Card/SRB2DEMO/"CONFIGFILENAME); #else if (dedicated) snprintf(configfile, sizeof configfile, "d"CONFIGFILENAME); else snprintf(configfile, sizeof configfile, CONFIGFILENAME); #endif } else { // use user specific config file #ifdef DEFAULTDIR snprintf(srb2home, sizeof srb2home, "%s" PATHSEP DEFAULTDIR, userhome); snprintf(downloaddir, sizeof downloaddir, "%s" PATHSEP "DOWNLOAD", srb2home); if (dedicated) snprintf(configfile, sizeof configfile, "%s" PATHSEP "d"CONFIGFILENAME, srb2home); else snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2home); // can't use sprintf since there is %u in savegamename strcatbf(savegamename, srb2home, PATHSEP); I_mkdir(srb2home, 0700); #else snprintf(srb2home, sizeof srb2home, "%s", userhome); snprintf(downloaddir, sizeof downloaddir, "%s", userhome); if (dedicated) snprintf(configfile, sizeof configfile, "%s" PATHSEP "d"CONFIGFILENAME, userhome); else snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, userhome); // can't use sprintf since there is %u in savegamename strcatbf(savegamename, userhome, PATHSEP); #endif } configfile[sizeof configfile - 1] = '\0'; #ifdef _arch_dreamcast strcpy(downloaddir, "/ram"); // the dreamcast's TMP #endif } if (M_CheckParm("-password") && M_IsNextParm()) { const char *pw = M_GetNextParm(); strncpy(adminpassword, pw, 8); if (strlen(pw) < 8) { size_t z; for (z = strlen(pw); z < 8; z++) adminpassword[z] = 'a'; } } else { size_t z; srand((unsigned int)time(NULL)); for (z = 0; z < 8; z++) adminpassword[z] = (char)(rand() & 127); } adminpassword[8] = '\0'; // add any files specified on the command line with -file wadfile // to the wad list if (!(M_CheckParm("-connect"))) { if (M_CheckParm("-file")) { // the parms after p are wadfile/lump names, // until end of parms or another - preceded parm while (M_IsNextParm()) { const char *s = M_GetNextParm(); if (s) // Check for NULL? { if (!W_VerifyNMUSlumps(s)) modifiedgame = true; D_AddFile(s); } } } } // get map from parms if (M_CheckParm("-server") || dedicated) netgame = server = true; if (M_CheckParm("-warp") && M_IsNextParm()) { pstartmap = atoi(M_GetNextParm()); if (!M_CheckParm("-server")) modifiedgame = true; autostart = true; savemoddata = false; } CONS_Printf("%s", M_GetText("Z_Init: Init zone memory allocation daemon. \n")); Z_Init(); // adapt tables to SRB2's needs, including extra slots for dehacked file support P_PatchInfoTables(); CONS_Printf("%s", M_GetText("W_Init: Init WADfiles.\n")); //---------------------------------------------------- READY TIME // we need to check for dedicated before initialization of some subsystems CONS_Printf("I_StartupTimer...\n"); I_StartupTimer(); // Make backups of some SOCcable tables. P_BackupTables(); // load wad, including the main wad file if (!W_InitMultipleFiles(startupwadfiles)) #ifdef _DEBUG CONS_Error(M_GetText("A WAD file was not found or not valid\n")); #else I_Error("%s", M_GetText("A WAD file was not found or not valid\n")); #endif D_CleanFile(); // Check MD5s of autoloaded files W_VerifyFileMD5(0, "1f698dd35bcedb04631568a84a97d72b"); // srb2.srb W_VerifyFileMD5(1, "86ae3f9179c64358d1c88060e41bd415"); // zones.dta W_VerifyFileMD5(2, "f699d4702b9b505db621e5ad5af4f352"); // sonic.plr W_VerifyFileMD5(3, "dfbbc38080485c70a84a57bb734ceee9"); // tails.plr W_VerifyFileMD5(4, "1ea958e2aee87b6995226a120ba3eaac"); // knux.plr W_VerifyFileMD5(5, "8f702416c15060cd3c53c71b91116914"); // rings.wpn W_VerifyFileMD5(6, "6b1cf9b41e41a46ac58606dc6e7c9e05"); // drill.dta W_VerifyFileMD5(7, "8d080c050ecf03691562aa7b60156fec"); // soar.dta // don't check music.dta because people like to modify it, and it doesn't matter if they do // ...except it does if they slip maps in there, and that's what W_VerifyNMUSlumps is for. mainwads = 8; // there are 8 wads not to unload /* TODO: incorporate this! CONS_Printf("%s", "===========================================================================\n" " Sonic Robo Blast II!\n" " by Sonic Team Junior\n" " http://www.srb2.org\n" " This is a modified version. Go to our site for the original.\n" "===========================================================================\n"); */ // Check and print which version is executed. CONS_Printf("%s", "===========================================================================\n" " We hope you enjoy this game as\n" " much as we did making it!\n" " ...wait. =P\n" "===========================================================================\n"); cht_Init(); //---------------------------------------------------- READY SCREEN // we need to check for dedicated before initialization of some subsystems CONS_Printf("I_StartupGraphics...\n"); I_StartupGraphics(); //--------------------------------------------------------- CONSOLE // setup loading screen SCR_Startup(); // we need the font of the console CONS_Printf("%s", M_GetText("HU_Init: Setting up heads up display.\n")); HU_Init(); COM_Init(); // libogc has a CON_Init function, we must rename SRB2's CON_Init in WII/libogc #ifndef _WII CON_Init(); #else CON_InitWii(); #endif D_RegisterServerCommands(); D_RegisterClientCommands(); // be sure that this is called before D_CheckNetGame R_RegisterEngineStuff(); S_RegisterSoundStuff(); I_RegisterSysCommands(); //--------------------------------------------------------- CONFIG.CFG M_FirstLoadConfig(); // WARNING : this do a "COM_BufExecute()" if (!M_CheckParm("-resetdata")) G_LoadGameData(); #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (SDL) VID_PrepareModeList(); // Regenerate Modelist according to cv_fullscreen #endif // set user default mode or mode set at cmdline SCR_CheckDefaultMode(); wipegamestate = gamestate; P_InitMapHeaders(); savedata.lives = 0; // flag this as not-used //------------------------------------------------ COMMAND LINE PARAMS // Initialize CD-Audio if (M_CheckParm("-usecd") && !dedicated) I_InitCD(); if (M_CheckParm("-nodownloading")) COM_BufAddText("downloading 0\n"); CONS_Printf("%s", M_GetText("M_Init: Init miscellaneous info.\n")); M_Init(); CONS_Printf("%s", M_GetText("R_Init: Init SRB2 refresh daemon - ")); R_Init(); // setting up sound CONS_Printf("%s", M_GetText("S_Init: Setting up sound.\n")); if (M_CheckParm("-nosound")) nosound = true; if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic nomidimusic = nodigimusic = true; else { if (M_CheckParm("-nomidimusic")) nomidimusic = true; ; // WARNING: DOS version initmusic in I_StartupSound if (M_CheckParm("-nodigmusic")) nodigimusic = true; // WARNING: DOS version initmusic in I_StartupSound } I_StartupSound(); I_InitMusic(); S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); CONS_Printf("%s", M_GetText("ST_Init: Init status bar.\n")); ST_Init(); if (M_CheckParm("-internetserver")) CV_SetValue(&cv_internetserver, 1); // init all NETWORK CONS_Printf("%s", M_GetText("D_CheckNetGame: Checking network game status.\n")); if (D_CheckNetGame()) autostart = true; // check for a driver that wants intermission stats // start the apropriate game based on parms if (M_CheckParm("-record") && M_IsNextParm()) { G_RecordDemo(M_GetNextParm()); autostart = true; } p = M_CheckParm("-timetic"); if (p) CV_Set(&cv_timetic, "On"); if (!autostart) M_PushSpecialParameters(); // push all "+" parameters at the command buffer // demo doesn't need anymore to be added with D_AddFile() p = M_CheckParm("-playdemo"); if (!p) p = M_CheckParm("-timedemo"); if (p && M_IsNextParm()) { char tmp[MAX_WADPATH]; // add .lmp to identify the EXTERNAL demo file // it is NOT possible to play an internal demo using -playdemo, // rather push a playdemo command.. to do. strcpy(tmp, M_GetNextParm()); // get spaced filename or directory while (M_IsNextParm()) { strcat(tmp, " "); strcat(tmp, M_GetNextParm()); } FIL_DefaultExtension(tmp, ".lmp"); CONS_Printf(M_GetText("Playing demo %s.\n"), tmp); if (M_CheckParm("-playdemo")) { singledemo = true; // quit after one demo G_DeferedPlayDemo(tmp); } else G_TimeDemo(tmp); G_SetGamestate(GS_NULL); wipegamestate = GS_NULL; return; } if (M_CheckParm("-ultimatemode")) { autostart = true; ultimatemode = true; } if (autostart || netgame || M_CheckParm("+connect") || M_CheckParm("-connect")) { gameaction = ga_nothing; CV_ClearChangedFlags(); // Do this here so if you run SRB2 with eg +timelimit 5, the time limit counts // as having been modified for the first game. M_PushSpecialParameters(); // push all "+" parameter at the command buffer if (M_CheckParm("-gametype") && M_IsNextParm()) { // from Command_Map_f INT32 j; INT16 newgametype = -1; const char *sgametype = M_GetNextParm(); for (j = 0; gametype_cons_t[j].strvalue; j++) if (!strcasecmp(gametype_cons_t[j].strvalue, sgametype)) { if (gametype_cons_t[j].value == GTF_TEAMMATCH) { newgametype = GT_MATCH; CV_SetValue(&cv_matchtype, 1); } else if (gametype_cons_t[j].value == GTF_CLASSICRACE) { newgametype = GT_RACE; CV_SetValue(&cv_racetype, 1); } else if (gametype_cons_t[j].value == GTF_HIDEANDSEEK) { newgametype = GT_TAG; CV_SetValue(&cv_tagtype, 1); } else newgametype = (INT16)gametype_cons_t[j].value; break; } if (!gametype_cons_t[j].strvalue) // reached end of the list with no match { j = atoi(sgametype); // assume they gave us a gametype number, which is okay too if (j >= 0 && j < NUMGAMETYPES) newgametype = (INT16)j; } if (newgametype != -1) { j = gametype; gametype = newgametype; D_GameTypeChanged(j); } } if (server && !M_CheckParm("+map") && !M_CheckParm("+connect") && !M_CheckParm("-connect")) { D_MapChange(pstartmap, gametype, ultimatemode, 1, 0, false, false); } } else F_StartIntro(); // Tails 03-03-2002 if (dedicated && server) { pagename = "TITLESKY"; levelstarttic = gametic; G_SetGamestate(GS_LEVEL); if (!P_SetupLevel(gamemap, false)) I_Quit(); // fail so reset game stuff } }
/** Tries to register the local game server on the master server. */ static INT32 AddToMasterServer(boolean firstadd) { #ifdef NONET (void)firstadd; #else static INT32 retry = 0; int i, res; socklen_t j; msg_t msg; msg_server_t *info = (msg_server_t *)msg.buffer; INT32 room = -1; fd_set tset; time_t timestamp = time(NULL); UINT32 signature, tmp; const char *insname; M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); if (res != ERRSOCKET && !res) { if (retry++ > 30) // an about 30 second timeout { retry = 0; CONS_Printf("Timeout on masterserver\n"); MSLastPing = timestamp; return ConnectionFailed(); } return MS_CONNECT_ERROR; } retry = 0; if (res == ERRSOCKET) { if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) { CONS_Printf("Mastserver error on select #%u: %s\n", errno, strerror(errno)); MSLastPing = timestamp; return ConnectionFailed(); } } // so, the socket is writable, but what does that mean, that the connection is // ok, or bad... let see that! j = (socklen_t)sizeof (i); getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j); if (i) // it was bad { CONS_Printf("Masterserver getsockopt error #%u: %s\n", errno, strerror(errno)); MSLastPing = timestamp; return ConnectionFailed(); } if (dedicated && (M_CheckParm("-room") && M_IsNextParm())) { room = atoi(M_GetNextParm()); if(room == 0) room = -1; } else if(dedicated) room = -1; else room = cv_chooseroom.value; for(signature = 0, insname = cv_servername.string; *insname; signature += *insname++); tmp = (UINT32)(signature * (size_t)&MSLastPing); signature *= tmp; signature &= 0xAAAAAAAA; M_Memcpy(&info->header.signature, &signature, sizeof (UINT32)); strcpy(info->ip, ""); strcpy(info->port, int2str(current_port)); strcpy(info->name, cv_servername.string); M_Memcpy(&info->room, & room, sizeof (INT32)); sprintf(info->version, "%d.%d.%d", VERSION/100, VERSION%100, SUBVERSION); strcpy(registered_server.name, cv_servername.string); if(firstadd) msg.type = ADD_SERVER_MSG; else msg.type = PING_SERVER_MSG; msg.length = (UINT32)sizeof (msg_server_t); msg.room = 0; if (MS_Write(&msg) < 0) { MSLastPing = timestamp; return ConnectionFailed(); } if(con_state != MSCS_REGISTERED) CONS_Printf("Master Server Updated Successfully!\n"); MSLastPing = timestamp; con_state = MSCS_REGISTERED; CloseConnection(); #endif return MS_NO_ERROR; }