| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /* vcc/plugins/emerg/emerg.c
- *
- * This file is part of vcc.
- *
- * vcc is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * vcc is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with vcc. If not, see <https://www.gnu.org/licenses/>
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <vcc/vcc.h>
- #include <vcc/pretty.h>
- #include <vcc/hooks.h>
- #include <vcc/plugin.h>
- #include <vcc/interfaces.h>
- #include <vcc/version.h>
- int do_cmd_emerg(int argc, char **argv);
- struct cmdtable emerg_cmdtab[] = {
- { "-emerg", do_cmd_emerg, "Enter emergency mode. " },
- { NULL, NULL, NULL }
- };
- static char *emergtab[] = {
- "NEARLY DIED. PREPARE FOR THE ARMAGEDDON. ",
- "EMERGENCY. NO MESSAGES INCLUDING ENGLISH. ",
- "DANGEROUS. LATIUM OR OTHER LANGUAGES. ",
- "WARNING. ENGLISH IS OK. ",
- "EARLY WARNING. CHINESE IS OK. ",
- "NOTHING. ",
- NULL,
- };
- #define EMERGLEVELS 5
- struct plugin plg_emerg = {
- .state = 0,
- .name = "emerg",
- .descr = "Emergency mode control. ",
- .cmdtab = emerg_cmdtab,
- };
- #define this_plg (&plg_emerg)
- static int clear_screen(void) {
- int pid, status;
- /* it's the fastest way. */
- system("clear");
- switch ((pid = fork())) {
- case 0:
- execlp("bash", "bash", NULL);
- perror("execlp");
- abort();
- case -1:
- perror("fork");
- return 1;
- default:
- wait4(pid, &status, 0, NULL);
- send_msg("-cqd#emergency mode out. \n", usrname);
- }
- return 0;
- }
- static int enter_emergency_mode(int level) {
- char msg[MSG_SIZE];
- sprintf(msg, "-cqd#%s is on emergency mode %d. %s\n", usrname, level, emergtab[level]);
- send_msg(msg, usrname);
- clear_screen();
- return 0;
- }
- int do_cmd_emerg(int argc, char **argv) {
- int level;
- plg_check_enabled();
- switch (argc) {
- case 1:
- /* the max level */
- level = 0;
- break;
- case 2:
- level = atoi(argv[1]);
- break;
- default:
- /* enter the max level because people often do wrong things
- * when they're in a hurry */
- level = 0;
- break;
- }
- if (level > EMERGLEVELS)
- /* who care these things when they're going to die? */
- level = 0;
- enter_emergency_mode(level);
- return 0;
- }
|