/* should return true if 'to' found */ int LinkFiles(char *from,char *to_tmp, struct Item *inclusions,struct Item *exclusions,struct Item *copy, short nofile,struct Link *ptr) { struct stat buf,savebuf; char to[CF_BUFSIZE], linkbuf[CF_BUFSIZE]; char saved[CF_BUFSIZE],absto[CF_BUFSIZE],*lastnode; struct UidList fakeuid; struct Image ip; char stamp[CF_BUFSIZE]; time_t STAMPNOW; STAMPNOW = time((time_t *)NULL); memset(to,0,CF_BUFSIZE); memset(&ip,0, sizeof(ip)); /* links without a directory reference */ if ((*to_tmp != '/') && (*to_tmp != '.')) { strcpy(to,"./"); } if (strlen(to_tmp)+3 > CF_BUFSIZE) { printf("%s: CF_BUFSIZE boundaries exceeded in LinkFiles(%s->%s)\n", g_vprefix,from,to_tmp); return false; } strcat(to,to_tmp); Debug2("Linkfiles(%s,%s)\n",from,to); for (lastnode = from+strlen(from); *lastnode != '/'; lastnode--) { } lastnode++; if (IgnoredOrExcluded(links,lastnode,inclusions,exclusions)) { Verbose("%s: Skipping non-included pattern %s\n",g_vprefix,from); return true; } if (IsWildItemIn(g_vcopylinks,lastnode) || IsWildItemIn(copy,lastnode)) { fakeuid.uid = CF_SAME_OWNER; fakeuid.next = NULL; ip.plus = CF_SAMEMODE; ip.minus = CF_SAMEMODE; ip.uid = &fakeuid; ip.gid = (struct GidList *) &fakeuid; ip.action = "do"; ip.recurse = 0; ip.type = 't'; ip.defines = ptr->defines; ip.elsedef = ptr->elsedef; ip.backup = true; ip.exclusions = NULL; ip.inclusions = NULL; ip.symlink = NULL; ip.classes = NULL; ip.plus_flags = 0; ip.size = CF_NOSIZE; ip.linktype = 's'; ip.minus_flags = 0; ip.server = strdup("localhost"); Verbose("%s: Link item %s marked for copying instead\n", g_vprefix, from); MakeDirectoriesFor(to,'n'); CheckImage(to,from,&ip); free(ip.server); return true; } /* relative path, must still check if exists */ if (*to != '/') { Debug("Relative link destination detected: %s\n",to); strcpy(absto,AbsLinkPath(from,to)); Debug("Absolute path to relative link = %s, from %s\n",absto,from); } else { strcpy(absto,to); } if (!nofile) { if (stat(absto,&buf) == -1) { /* no error warning, since the higher level routine uses this */ return(false); } } Debug2("Trying to link %s -> %s (%s)\n",from,to,absto); if (lstat(from,&buf) == 0) { if (! S_ISLNK(buf.st_mode) && ! g_enforcelinks) { snprintf(g_output,CF_BUFSIZE*2,"Error linking %s -> %s\n",from,to); CfLog(cfsilent,g_output,""); snprintf(g_output, CF_BUFSIZE*2, "Cannot make link: %s exists and is not a link! " "(uid %d)\n", from, buf.st_uid); CfLog(cfsilent,g_output,""); return(true); } if (S_ISREG(buf.st_mode) && g_enforcelinks) { snprintf(g_output, CF_BUFSIZE*2, "Moving %s to %s%s\n", from, from, CF_SAVED); CfLog(cfsilent,g_output,""); if (g_dontdo) { return true; } saved[0] = '\0'; strcpy(saved,from); sprintf(stamp, "_%d_%s", g_cfstarttime, CanonifyName(ctime(&STAMPNOW))); strcat(saved,stamp); strcat(saved,CF_SAVED); if (rename(from,saved) == -1) { snprintf(g_output, CF_BUFSIZE*2, "Can't rename %s to %s\n", from,saved); CfLog(cferror,g_output,"rename"); return(true); } if (Repository(saved,g_vrepository)) { unlink(saved); } } if (S_ISDIR(buf.st_mode) && g_enforcelinks) { snprintf(g_output,CF_BUFSIZE*2,"Moving directory %s to %s%s.dir\n", from,from,CF_SAVED); CfLog(cfsilent,g_output,""); if (g_dontdo) { return true; } saved[0] = '\0'; strcpy(saved,from); sprintf(stamp, "_%d_%s", g_cfstarttime, CanonifyName(ctime(&STAMPNOW))); strcat(saved,stamp); strcat(saved,CF_SAVED); strcat(saved,".dir"); if (stat(saved,&savebuf) != -1) { snprintf(g_output,CF_BUFSIZE*2, "Couldn't save directory %s, " "since %s exists already\n", from,saved); CfLog(cferror,g_output,""); snprintf(g_output,CF_BUFSIZE*2, "Unable to force link to " "existing directory %s\n",from); CfLog(cferror,g_output,""); return true; } if (rename(from,saved) == -1) { snprintf(g_output, CF_BUFSIZE*2, "Can't rename %s to %s\n", from,saved); CfLog(cferror,g_output,"rename"); return(true); } } } memset(linkbuf,0,CF_BUFSIZE); if (readlink(from,linkbuf,CF_BUFSIZE-1) == -1) { /* link doesn't exist */ if (! MakeDirectoriesFor(from,'n')) { snprintf(g_output,CF_BUFSIZE*2, "Couldn't build directory tree up to %s!\n",from); CfLog(cfsilent,g_output,""); snprintf(g_output,CF_BUFSIZE*2, "One element was a plain file, not a directory!\n"); CfLog(cfsilent,g_output,""); return(true); } } else { int off1 = 0, off2 = 0; DeleteSlash(linkbuf); /* Ignore ./ at beginning */ if (strncmp(linkbuf,"./",2) == 0) { off1 = 2; } if (strncmp(to,"./",2) == 0) { off2 = 2; } if (strcmp(linkbuf+off1,to+off2) != 0) { if (g_enforcelinks) { snprintf(g_output,CF_BUFSIZE*2,"Removing link %s\n",from); CfLog(cfinform,g_output,""); if (!g_dontdo) { if (unlink(from) == -1) { perror("unlink"); return true; } return DoLink(from,to,ptr->defines); } } else { snprintf(g_output,CF_BUFSIZE*2, "Old link %s points somewhere else. Doing nothing!\n", from); CfLog(cfsilent,g_output,""); snprintf(g_output, CF_BUFSIZE*2, "(Link points to %s not %s)\n\n", linkbuf,to); CfLog(cfsilent,g_output,""); return(true); } } else { snprintf(g_output, CF_BUFSIZE*2, "Link (%s->%s) exists.\n", from, to_tmp); CfLog(cfverbose,g_output,""); if (!nofile) { /* Check whether link points somewhere */ KillOldLink(from,ptr->defines); return true; } AddMultipleClasses(ptr->elsedef); return(true); } } return DoLink(from,to,ptr->defines); }
static void LinkMeBaby( void ) /****************************/ { ResetSubSystems(); DoLink( ArgSave ); }
int CTrigger::Operate (short nObject, int nPlayer, int bShot, bool bObjTrigger) { if (m_info.flags & TF_DISABLED) return 1; //1 means don't send trigger hit to other players CObject* objP = (nObject >= 0) ? OBJECTS + nObject : NULL; bool bIsPlayer = objP && (objP->info.nType == OBJ_PLAYER); if (bIsPlayer) { if (!IsMultiGame && (nObject != LOCALPLAYER.nObject)) return 1; } else { nPlayer = -1; if ((m_info.nType != TT_TELEPORT) && (m_info.nType != TT_SPEEDBOOST)) { if (objP && (objP->info.nType != OBJ_ROBOT) && (objP->info.nType != OBJ_REACTOR) && (objP->info.nType != OBJ_HOSTAGE) && (objP->info.nType != OBJ_POWERUP)) return 1; if (!bObjTrigger) return 1; } else if (objP && (objP->info.nType != OBJ_ROBOT) && (objP->info.nType != OBJ_REACTOR) && (objP->info.nType != OBJ_HOSTAGE) && (objP->info.nType != OBJ_POWERUP)) return 1; } int nTrigger = bObjTrigger ? OBJTRIGGERS.Index (this) : TRIGGERS.Index (this); if (!bObjTrigger && (m_info.nType != TT_TELEPORT) && (m_info.nType != TT_SPEEDBOOST)) { int t = gameStates.app.nSDLTicks; if ((gameData.trigs.delay [nTrigger] >= 0) && (t - gameData.trigs.delay [nTrigger] < 750)) return 1; gameData.trigs.delay [nTrigger] = gameStates.app.nSDLTicks; } if (m_info.flags & TF_ONE_SHOT) //if this is a one-bShot... m_info.flags |= TF_DISABLED; //..then don't let it happen again if (m_info.tOperated < 0) { m_info.tOperated = gameData.time.xGame; m_info.nObject = nObject; m_info.nPlayer = nPlayer; m_info.bShot = bShot; } if (Delay () > 0) { gameData.trigs.delay [nTrigger] = -1; return 0; } switch (m_info.nType) { case TT_EXIT: if (DoExit (nPlayer)) return 1; break; case TT_SECRET_EXIT: if (DoSecretExit (nPlayer)) return 1; break; case TT_OPEN_DOOR: DoLink (); PrintMessage (nPlayer, bShot, "Door%s opened!"); break; case TT_CLOSE_DOOR: DoCloseDoor (); PrintMessage (nPlayer, bShot, "Door%s closed!"); break; case TT_UNLOCK_DOOR: DoUnlockDoors (); PrintMessage (nPlayer, bShot, "Door%s unlocked!"); break; case TT_LOCK_DOOR: DoLockDoors (); PrintMessage (nPlayer, bShot, "Door%s locked!"); break; case TT_OPEN_WALL: if (DoChangeWalls ()) { if (WallIsForceField ()) PrintMessage (nPlayer, bShot, "Force field%s deactivated!"); else PrintMessage (nPlayer, bShot, "Wall%s opened!"); } break; case TT_CLOSE_WALL: if (DoChangeWalls ()) { if (WallIsForceField ()) PrintMessage (nPlayer, bShot, "Force field%s activated!"); else PrintMessage (nPlayer, bShot, "Wall%s closed!"); } break; case TT_ILLUSORY_WALL: //don't know what to say, so say nothing DoChangeWalls (); PrintMessage (nPlayer, bShot, "Creating Illusion!"); break; case TT_MATCEN: if (!(gameData.app.nGameMode & GM_MULTI) || (gameData.app.nGameMode & GM_MULTI_ROBOTS)) DoMatCen (nPlayer == gameData.multiplayer.nLocalPlayer); break; case TT_ILLUSION_ON: DoIllusionOn (); PrintMessage (nPlayer, bShot, "Illusion%s on!"); break; case TT_ILLUSION_OFF: DoIllusionOff (); PrintMessage (nPlayer, bShot, "Illusion%s off!"); break; case TT_LIGHT_OFF: if (DoLightOff ()) PrintMessage (nPlayer, bShot, "Lights off!"); break; case TT_LIGHT_ON: if (DoLightOn ()) PrintMessage (nPlayer, bShot, "Lights on!"); break; case TT_TELEPORT: if (bObjTrigger) { DoTeleportBot (objP); PrintMessage (nPlayer, bShot, "Robot is fleeing!"); } else { if (bIsPlayer) { if (nPlayer != gameData.multiplayer.nLocalPlayer) break; if ((LOCALPLAYER.shields < 0) || gameStates.app.bPlayerIsDead) break; } audio.PlaySound (SOUND_SECRET_EXIT, I2X (1)); DoTeleport (nObject); if (bIsPlayer) PrintMessage (nPlayer, bShot, "Teleport!"); } break; case TT_SPEEDBOOST: if (bIsPlayer) { if (nPlayer != gameData.multiplayer.nLocalPlayer) break; if ((LOCALPLAYER.shields < 0) || gameStates.app.bPlayerIsDead) break; } DoSpeedBoost (nObject); if (bIsPlayer) PrintMessage (nPlayer, bShot, "Speed Boost!"); break; case TT_SHIELD_DAMAGE: if (!gameStates.app.bPlayerIsDead) { if (gameStates.app.bD1Mission) LOCALPLAYER.shields -= TRIGGERS [nTrigger].m_info.value; else LOCALPLAYER.shields -= (fix) ((float (I2X (1)) * X2F (TRIGGERS [nTrigger].m_info.value))); if (LOCALPLAYER.shields < 0) StartPlayerDeathSequence (OBJECTS + gameData.multiplayer.players [gameData.multiplayer.nLocalPlayer].nObject); } break; case TT_ENERGY_DRAIN: if (!gameStates.app.bPlayerIsDead) { if (gameStates.app.bD1Mission) LOCALPLAYER.energy -= TRIGGERS [nTrigger].m_info.value; else LOCALPLAYER.energy -= (fix) (LOCALPLAYER.energy * X2F (TRIGGERS [nTrigger].m_info.value) / 100); if (LOCALPLAYER.energy < 0) LOCALPLAYER.energy = 0; } break; case TT_CHANGE_TEXTURE: DoChangeTexture (); PrintMessage (nPlayer, 2, "Walls have been changed!"); break; case TT_SPAWN_BOT: DoSpawnBots (objP); PrintMessage (nPlayer, 1, "Robot is summoning help!"); break; case TT_SET_SPAWN: DoSetSpawnPoints (); PrintMessage (nPlayer, 1, "New spawn points set!"); break; case TT_SMOKE_LIFE: case TT_SMOKE_SPEED: case TT_SMOKE_DENS: case TT_SMOKE_SIZE: case TT_SMOKE_DRIFT: break; case TT_COUNTDOWN: InitCountdown (this, 1, -1); break; case TT_MESSAGE: DoShowMessage (); break; case TT_SOUND: DoPlaySound (nObject); break; case TT_MASTER: DoMasterTrigger (nObject); break; case TT_ENABLE_TRIGGER: DoEnableTrigger (); #if DBG PrintMessage (nPlayer, 2, "Triggers have been enabled!"); #endif break; case TT_DISABLE_TRIGGER: DoDisableTrigger (); #if DBG PrintMessage (nPlayer, 2, "Triggers have been disabled!"); #endif break; case TT_DESCENT1: OperateD1 (nObject, nPlayer, bShot); break; default: Int3 (); break; } if (m_info.flags & TF_ALTERNATE) m_info.nType = oppTrigTypes [m_info.nType]; return 0; }