Explorar o código

vcc: add emergency mode

intirain %!s(int64=4) %!d(string=hai) anos
pai
achega
df4641b89c
Modificáronse 6 ficheiros con 150 adicións e 7 borrados
  1. 2 2
      Makefile
  2. 2 2
      include/vcc/version.h
  3. 2 2
      plugins.c
  4. 1 1
      plugins/Makefile
  5. 14 0
      plugins/emerg/Makefile
  6. 129 0
      plugins/emerg/emerg.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 40
-VCC_PATCH 		= 1
+VCC_MINOR 		= 41
+VCC_PATCH 		= 0
 VCC_STR 		= -rc
 
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "vcc 1.40.1 Mon Jul 11 06:09:02 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.40.1-rc"
+#define VCC_VERSION "vcc 1.41.0 Wed Jul 13 09:30:48 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.41.0-rc"

+ 2 - 2
plugins.c

@@ -44,11 +44,11 @@
 
 
 extern struct plugin plg_hello, plg_robot, plg_m4, plg_script, plg_hist, 
-       plg_cqd, plg_beep, plg_ban, plg_vcr;
+       plg_cqd, plg_beep, plg_ban, plg_vcr, plg_emerg;
 
 struct plugin *plugins[] = {
 	&plg_hello, &plg_robot, &plg_m4, &plg_script, &plg_hist, 
-	&plg_cqd, &plg_beep, &plg_ban, &plg_vcr, 
+	&plg_cqd, &plg_beep, &plg_ban, &plg_vcr, &plg_emerg, 
 	(struct plugin *) NULL
 };
 

+ 1 - 1
plugins/Makefile

@@ -1,4 +1,4 @@
-plugins 	= hello robot m4 script hist cqd beep ban vcr 
+plugins 	= hello robot m4 script hist cqd beep ban vcr emerg
 target 		= libplugins.a 
 
 all: 

+ 14 - 0
plugins/emerg/Makefile

@@ -0,0 +1,14 @@
+objs 	= emerg.o 
+target 	= ../plg_emerg.o 
+CFLAGS 	= -std=gnu11 -Wall -Wextra -Werror -I../../include -g 
+
+$(target): $(objs)
+	@cp $(objs) $(target)
+
+%.o: %.c
+	@$(CC) -c $*.c $(CFLAGS)
+	@echo -e "CC\t\t\t$*.c"
+
+.PHONY clean: 
+	rm -f $(target) $(objs)
+

+ 129 - 0
plugins/emerg/emerg.c

@@ -0,0 +1,129 @@
+/* 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;
+}
+
+