/* * External Communications Program */ #include #define CLIENT_VERSION "0.0.1" #define CLIENT_VERSION_TAGS "alpha 1" #define C_EARBUDS 1313 #define LN_EARBUDS 4 integer hearing_state = 1; integer language_state = 1; integer earbuds_state = 0; main(integer src, integer n, string m, key outs, key ins, key user) { if (n == SIGNAL_INVOKE) { list argv = split(m, " "); integer argc = count(argv); string cmd = gets(argv, 1); string output_msg = ""; if (argc == 1 || cmd == "help") { output_msg = "Syntax: " + PROGRAM_NAME + " "; } else if (cmd == "refresh") { output_msg = "Refreshing earbuds..."; if (earbuds_state) { linked(LN_EARBUDS, C_EARBUDS, "EARMUFFS_ON", user); } else { linked(LN_EARBUDS, C_EARBUDS, "EARMUFFS_OFF", user); } } else { output_msg = "Unknown command \"" + cmd + "\"."; } if(output_msg != "") print(outs, user, output_msg); } else if (n == SIGNAL_NOTIFY) { list argv = delitem(splitnulls(m, " "), 0); integer ci = count(argv); while (ci > 0) { ci -= 2; string cmd = gets(argv, ci); string status = gets(argv, ci + 1); if (cmd == "hearing") { hearing_state = (status == "y"); } } #ifdef DEBUG echo("[" + PROGRAM_NAME + "] received notify from " + (string)src + ", user " + (string)user + ": [" + concat(argv, ", ") + "]"); #endif if (hearing_state && earbuds_state) { linked(LN_EARBUDS, C_EARBUDS, "EARMUFFS_OFF", user); earbuds_state = 0; } else if (!hearing_state && !earbuds_state) { linked(LN_EARBUDS, C_EARBUDS, "EARMUFFS_ON", user); earbuds_state = 1; } } else if (n == SIGNAL_INIT) { #ifdef DEBUG echo("[" + PROGRAM_NAME + "] init event"); #endif hearing_state = 1; language_state = 1; earbuds_state = 0; } else if (n == SIGNAL_UNKNOWN_SCRIPT) { echo("[" + PROGRAM_NAME + "] failed to run '" + m + "' (kernel could not find the program specified)"); } else { echo("[" + PROGRAM_NAME + "] unimplemented signal " + (string)n + ": " + m); } } #include