int spkropen(dev_t dev, int flags, int mode, struct lwp *l) { #ifdef SPKRDEBUG printf("spkropen: entering with dev = %"PRIx64"\n", dev); #endif /* SPKRDEBUG */ if (minor(dev) != 0 || !spkr_attached) return(ENXIO); else if (spkr_active) return(EBUSY); else { playinit(); spkr_inbuf = malloc(DEV_BSIZE, M_DEVBUF, M_WAITOK); spkr_active = 1; } return(0); }
void threadmain(int argc, char *argv[]) { char *srvfile; char *srvpost; char *mntpt; int i; mntpt = "/mnt"; srvpost = nil; rfork(RFNOTEG); ARGBEGIN{ case 'a': aflag = 1; break; case 'm': mntpt = ARGF(); break; case 'd': debug = strtoul(ARGF(), nil, 0); break; case 's': srvpost = ARGF(); break; default: usage(); }ARGEND user = strdup(getuser()); quotefmtinstall(); if(debug) fmtinstall('F', fcallfmt); volumechan = chancreate(sizeof(volume), 1); playchan = chancreate(sizeof(Wmsg), 1); playlistreq = chancreate(sizeof(Wmsg), 0); /* No storage! requires rendez-vous */ workers = chancreate(sizeof(Worker*), 256); for(i = 1; i < Nqid; i++) files[i].workers = chancreate(sizeof(Worker*), 256); if(pipe(srvfd) < 0) sysfatal("pipe failed: %r"); procrfork(srv, nil, STACKSIZE, RFFDG); close(srvfd[0]); /* don't deadlock if child fails */ procrfork(volumeproc, nil, STACKSIZE, RFFDG); playinit(); if(srvpost){ srvfile = smprint("/srv/playlist.%s", srvpost); remove(srvfile); post(srvfile, srvfd[1]); free(srvfile); } if(mount(srvfd[1], -1, mntpt, MBEFORE, "") < 0) sysfatal("mount failed: %r"); threadexits(nil); }
int main(int argc, char **argv) { bool noheader = FALSE; /* set if don't want header */ bool headeronly = FALSE; /* set if only want header */ bool examine = FALSE; /* set if examine a character */ time_t seconds; /* for time of day */ double dtemp; /* for temporary calculations */ initialstate(); /* init globals */ /* process arguments */ while (--argc && (*++argv)[0] == '-') switch ((*argv)[1]) { case 's': /* short */ noheader = TRUE; break; case 'H': /* Header */ headeronly = TRUE; break; case 'a': /* all users */ activelist(); cleanup(TRUE); /* NOTREACHED */ case 'p': /* purge old players */ purgeoldplayers(); cleanup(TRUE); /* NOTREACHED */ case 'S': /* set 'Wizard' */ Wizard = !getuid(); break; case 'x': /* examine */ examine = TRUE; break; case 'm': /* monsters */ monstlist(); cleanup(TRUE); /* NOTREACHED */ case 'b': /* scoreboard */ scorelist(); cleanup(TRUE); /* NOTREACHED */ } if (!isatty(0)) /* don't let non-tty's play */ cleanup(TRUE); /* NOTREACHED */ playinit(); /* set up to catch signals, init curses */ if (examine) { changestats(FALSE); cleanup(TRUE); /* NOTREACHED */ } if (!noheader) { titlelist(); purgeoldplayers(); /* clean up old characters */ } if (headeronly) cleanup(TRUE); /* NOTREACHED */ do { /* get the player structure filled */ Fileloc = -1L; mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? "); switch (getanswer("NYQ", FALSE)) { case 'Y': Fileloc = recallplayer(); break; case 'Q': cleanup(TRUE); /* NOTREACHED */ default: Fileloc = rollnewplayer(); break; } clear(); } while (Fileloc < 0L); if (Player.p_level > 5.0) /* low level players have long timeout */ Timeout = TRUE; /* update some important player statistics */ strcpy(Player.p_login, Login); time(&seconds); Player.p_lastused = localtime(&seconds)->tm_yday; Player.p_status = S_PLAYING; writerecord(&Player, Fileloc); Statptr = &Stattable[Player.p_type]; /* initialize pointer */ /* catch interrupts */ #ifdef BSD41 sigset(SIGINT, interrupt); #endif #ifdef BSD42 signal(SIGINT, interrupt); #endif #ifdef SYS3 signal(SIGINT, interrupt); #endif #ifdef SYS5 signal(SIGINT, interrupt); #endif altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */ clear(); for (;;) { /* loop forever, processing input */ adjuststats(); /* cleanup stats */ if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING) { /* not allowed on throne -- move */ mvaddstr(5, 0, "You're not allowed in the Lord's Chamber without a crown.\n"); altercoordinates(0.0, 0.0, A_NEAR); } checktampered(); /* check for energy voids, etc. */ if (Player.p_status != S_CLOAKED /* not cloaked */ && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y) /* |x| = |y| */ && !Throne) { /* not on throne */ dtemp = sqrt(dtemp / 100.0); if (floor(dtemp) == dtemp) { /* |x| / 100 == n*n; at a trading post */ tradingpost(); clear(); } } checkbattle(); /* check for player to player battle */ neatstuff(); /* gurus, medics, etc. */ if (Player.p_status == S_CLOAKED) { /* costs 3 mana per turn to be cloaked */ if (Player.p_mana > 3.0) Player.p_mana -= 3.0; else { /* ran out of mana, uncloak */ Player.p_status = S_PLAYING; Changed = TRUE; } } if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED) { /* change status back to S_PLAYING */ Player.p_status = S_PLAYING; Changed = TRUE; } if (Changed) { /* update file only if important stuff has changed */ writerecord(&Player, Fileloc); Changed = FALSE; continue; } readmessage(); /* read message, if any */ displaystats(); /* print statistics */ move(6, 0); if (Throne) /* maybe make king, print prompt, etc. */ throneroom(); /* print status line */ addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit "); if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK) addstr("6:Cloak "); if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT) addstr("7:Teleport "); if (Player.p_specialtype >= SC_COUNCIL || Wizard) addstr("8:Intervene "); procmain(); /* process input */ } }