int main(int argc, char **argv) { int s, ns; unsigned short portnum; pthread_t junk; if (argc != 3 || strtol(argv[1], NULL, 0) < 1 || strtol(argv[1], NULL, 0) > 65535 || strtol(argv[2], NULL, 0) < 0 || errno) { usage(); } portnum = (unsigned short)strtol(argv[1], NULL, 0); gMaxFileSize = (size_t)strtol(argv[2], NULL, 0); s = establish(portnum); while (1) { if ((ns = accept(s, NULL, NULL)) < 0) { MAIN_ERROR("accept"); } if (pthread_create(&junk, NULL, handleConnection, &ns)) { MAIN_ERROR("pthread_create"); } } return 0; }
int establish(unsigned short portnum) { char hostName[HOST_NAME_MAX+1]; int s; struct sockaddr_in sa; struct hostent *hp; memset(&sa, 0, sizeof(struct sockaddr_in)); if (gethostname(hostName, HOST_NAME_MAX) < 0) { MAIN_ERROR("gethostname"); } if ((hp = gethostbyname(hostName)) == NULL) { MAIN_ERROR("gethostbyname"); } sa.sin_family = hp->h_addrtype; memcpy(&sa.sin_addr, hp->h_addr, hp->h_length); sa.sin_port = htons(portnum); if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { MAIN_ERROR("socket"); } if (bind(s, (struct sockaddr*)&sa, sizeof(struct sockaddr_in)) < 0) { close(s); MAIN_ERROR("bind"); } if (listen(s, BACKLOG) < 0) { MAIN_ERROR("listen"); } return s; }
//------------------------------------------------------------------------- // CheckValidity() //------------------------------------------------------------------------- void CheckValidity(char *file, Sint32 valid_checksum) { char filename[13]; Sint32 checksum; if (strlen(file) > 9) MAIN_ERROR(CHECK_FILENAME_TOO_LONG); strcpy(filename,file); strcat(filename,extension); checksum=ChecksumFile(filename,0); if (checksum != valid_checksum) #if GAME_VERSION != SHAREWARE_VERSION if (strstr(file,"MAP")) InvalidLevels(); #else BadChecksum(); #endif }
//------------------------------------------------------------------------ // PreDemo() //------------------------------------------------------------------------ void PreDemo() { #if !SKIP_TITLE_AND_CREDITS #if TECH_SUPPORT_VERSION fontnumber=4; SETFONTCOLOR(0,15*3); CenterWindow (26,7); US_Print(EnterBetaCode); VW_UpdateScreen(); CA_LoadAllSounds(); PM_CheckMainMem(); SD_PlaySound(INFORMDEATH2SND); // Nooooo! IN_UserInput(TickBase*20); ClearMemory(); #elif BETA_TEST boolean param=false; for (i=1; i<g_argc; i++) switch (US_CheckParm(g_argv[i],MainStrs)) { case 13: param=true; break; } if (!param) { char buffer[15] = {0}; fontnumber=4; CenterWindow (26,7); US_Print(EnterBetaCode); VW_UpdateScreen(); SETFONTCOLOR(0,15*3); US_LineInput(24*8,92,buffer,buffer,true,14,100); if (_fstricmp(buffer,bc_buffer)) Quit("Bad beta code!"); } #endif #if GAME_VERSION == SHAREWARE_VERSION #if IN_DEVELOPMENT || GEORGE_CHEAT if (!MS_CheckParm("nochex")) #endif { #if (!SKIP_CHECKSUMS) // CheckValidity("MAPTEMP.",MAPTEMP_CHECKSUM,"LEVELS"); CheckValidity("MAPTEMP.",MAPTEMP_CHECKSUM); #endif } #else #if (!SKIP_CHECKSUMS) if (ChecksumFile("FILE_ID.DIZ",0) != DIZFILE_CHECKSUM) gamestate.flags |= GS_BAD_DIZ_FILE; #endif #endif VL_SetPaletteIntensity(0,255,vgapal,0); if (!(gamestate.flags & GS_NOWAIT)) { #if (0) // GAME_VERSION != SHAREWARE_VERSION //--------------------- // Anti-piracy screen //--------------------- // Cache pic // CA_CacheScreen(PIRACYPIC); // Cache and set palette. AND Fade it in! // CA_CacheGrChunk(PIRACYPALETTE); VL_SetPalette (0,256,grsegs[PIRACYPALETTE]); VL_SetPaletteIntensity(0,255,grsegs[PIRACYPALETTE],0); VW_UpdateScreen(); VL_FadeOut (0, 255, 0, 0, 25, 20); VL_FadeIn(0,255,grsegs[PIRACYPALETTE],30); // Wait a little // IN_UserInput(TickBase*20); // Free palette // UNCACHEGRCHUNK(PIRACYPALETTE); VL_FadeOut (0, 255, 0, 0, 25, 20); VW_FadeOut(); // Cleanup screen for upcoming SetPalette call // { Uint16 old_bufferofs=bufferofs; bufferofs=displayofs; VL_Bar(0,0,320,200,0); bufferofs=old_bufferofs; } #endif //--------------------- // Apogee presents //--------------------- // ISG --> this fixes intro timing IN_UserInput(TickBase*1); // Cache pic // CA_CacheScreen(APOGEEPIC); // Load and start music // CA_CacheAudioChunk(STARTMUSIC+APOGFNFM_MUS); ::SD_StartMusic(APOGFNFM_MUS); // Cache and set palette. AND Fade it in! // CA_CacheGrChunk(APOGEEPALETTE); VL_SetPalette (0,256,static_cast<const Uint8*>(grsegs[APOGEEPALETTE])); VL_SetPaletteIntensity(0,255,static_cast<const Uint8*>(grsegs[APOGEEPALETTE]),0); VW_UpdateScreen(); VL_FadeOut (0, 255, 25, 29, 53, 20); VL_FadeIn(0,255,static_cast<const Uint8*>(grsegs[APOGEEPALETTE]),30); // Wait for end of fanfare // if (MusicMode==smm_AdLib) { IN_StartAck(); while ((!sqPlayedOnce) && (!IN_CheckAck())); } else IN_UserInput(TickBase*6); SD_MusicOff(); // Free palette and music. AND Restore palette // UNCACHEGRCHUNK(APOGEEPALETTE); delete [] audiosegs[STARTMUSIC + APOGFNFM_MUS]; audiosegs[STARTMUSIC + APOGFNFM_MUS] = NULL; // Do A Blue Flash! VL_FadeOut (0, 255, 25, 29, 53, 20); VL_FadeOut (0, 255, 0, 0, 0, 30); //--------------------- // JAM logo intro //--------------------- // Load and start music // CA_CacheAudioChunk(STARTMUSIC+TITLE_LOOP_MUSIC); ::SD_StartMusic(TITLE_LOOP_MUSIC); // Show JAM logo // if (!DoMovie(mv_intro,0)) MAIN_ERROR(PREDEMO_NOJAM); if (PowerBall) { Sint16 i; for (i=0;i<60 && (!DebugOk);i++) { VL_WaitVBL(1); // BBi ::in_handle_events(); if (Keyboard[sc_left_shift] && Keyboard[sc_right_shift]) { CA_LoadAllSounds(); SD_MusicOff(); ::sd_play_player_sound(SHOOTDOORSND, bstone::AC_ITEM); SD_WaitSoundDone(); ClearMemory(); DebugOk = 1; CA_CacheAudioChunk(STARTMUSIC+TITLE_LOOP_MUSIC); ::SD_StartMusic(TITLE_LOOP_MUSIC); } } } //--------------------- // PC-13 //--------------------- VL_Bar(0,0,320,200,0x14); CacheDrawPic(0,64,PC13PIC); VW_UpdateScreen(); VW_FadeIn(); IN_UserInput(TickBase*2); // Do A Red Flash! VL_FadeOut (0, 255, 39, 0, 0, 20); VW_FadeOut(); } #endif // SKIP_TITLE_AND_CREDITS }