[1] | 1 | // Copyright (c) Athena Dev Teams - Licensed under GNU GPL |
---|
| 2 | // For more information, see LICENCE in the main folder |
---|
| 3 | |
---|
| 4 | #include <stdio.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include "../common/plugin.h" |
---|
| 8 | //Needed for strcmpi |
---|
| 9 | #include "../common/mmo.h" |
---|
| 10 | |
---|
| 11 | // "I'm Alive" and "Flush stdout" Originally by Mugendai |
---|
| 12 | // Ported to plugin by Celest |
---|
| 13 | |
---|
| 14 | PLUGIN_INFO = { |
---|
| 15 | "AthenaGUI", |
---|
| 16 | PLUGIN_CORE, |
---|
| 17 | "1.0", |
---|
| 18 | PLUGIN_VERSION, |
---|
| 19 | "Core plugin for Athena GUI functions" |
---|
| 20 | }; |
---|
| 21 | |
---|
| 22 | PLUGIN_EVENTS_TABLE = { |
---|
| 23 | { "gui_init", "Plugin_Init" }, |
---|
| 24 | { NULL, NULL } |
---|
| 25 | }; |
---|
| 26 | |
---|
| 27 | typedef int (*TimerFunc)(int tid, unsigned int tick, int id, intptr data); |
---|
| 28 | unsigned int (*gettick)(); |
---|
| 29 | int (*add_timer_func_list)(TimerFunc func, char* name); |
---|
| 30 | int (*add_timer_interval)(unsigned int tick, TimerFunc func, int id, intptr data, int interval); |
---|
| 31 | |
---|
| 32 | //----------------------------------------------------- |
---|
| 33 | //I'm Alive Alert |
---|
| 34 | //Used to output 'I'm Alive' every few seconds |
---|
| 35 | //Intended to let frontends know if the app froze |
---|
| 36 | //----------------------------------------------------- |
---|
| 37 | int imalive_timer(int tid, unsigned int tick, int id, intptr data) |
---|
| 38 | { |
---|
| 39 | printf("I'm Alive\n"); |
---|
| 40 | return 0; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | //----------------------------------------------------- |
---|
| 44 | //Flush stdout |
---|
| 45 | //stdout buffer needs flushed to be seen in GUI |
---|
| 46 | //----------------------------------------------------- |
---|
| 47 | int flush_timer(int tid, unsigned int tick, int id, intptr data) |
---|
| 48 | { |
---|
| 49 | fflush(stdout); |
---|
| 50 | return 0; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void gui_init () |
---|
| 54 | { |
---|
| 55 | char line[1024], w1[1024], w2[1024]; |
---|
| 56 | int flush_on = 0; |
---|
| 57 | int flush_time = 100; |
---|
| 58 | int imalive_on = 0; |
---|
| 59 | int imalive_time = 30; |
---|
| 60 | char **argv; |
---|
| 61 | int *argc; |
---|
| 62 | FILE *fp; |
---|
| 63 | int i; |
---|
| 64 | |
---|
| 65 | IMPORT_SYMBOL(argc, 2); |
---|
| 66 | IMPORT_SYMBOL(argv, 3); |
---|
| 67 | IMPORT_SYMBOL(gettick, 5); |
---|
| 68 | IMPORT_SYMBOL(add_timer_interval, 8); |
---|
| 69 | IMPORT_SYMBOL(add_timer_func_list, 9); |
---|
| 70 | |
---|
| 71 | do { |
---|
| 72 | fp = fopen("plugins/gui.conf","r"); |
---|
| 73 | if (fp == NULL) |
---|
| 74 | break; |
---|
| 75 | |
---|
| 76 | while(fgets(line, sizeof(line), fp)) |
---|
| 77 | { |
---|
| 78 | if (line[0] == '/' && line[1] == '/') |
---|
| 79 | continue; |
---|
| 80 | if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2) { |
---|
| 81 | if(strcmpi(w1,"imalive_on")==0){ |
---|
| 82 | imalive_on = atoi(w2); |
---|
| 83 | } else if(strcmpi(w1,"imalive_time")==0){ |
---|
| 84 | imalive_time = atoi(w2); |
---|
| 85 | } else if(strcmpi(w1,"flush_on")==0){ |
---|
| 86 | flush_on = atoi(w2); |
---|
| 87 | } else if(strcmpi(w1,"flush_time")==0){ |
---|
| 88 | flush_time = atoi(w2); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | fclose(fp); |
---|
| 93 | } while (0); |
---|
| 94 | |
---|
| 95 | for (i = 1; i < *argc ; i++) |
---|
| 96 | if (strcmp(argv[i], "--gui") == 0) |
---|
| 97 | flush_on = imalive_on = 1; |
---|
| 98 | |
---|
| 99 | if (flush_on) { |
---|
| 100 | add_timer_func_list(flush_timer, "flush_timer"); |
---|
| 101 | add_timer_interval(gettick()+1000,flush_timer,0,0,flush_time); |
---|
| 102 | } |
---|
| 103 | if (imalive_on) { |
---|
| 104 | add_timer_func_list(imalive_timer, "imalive_timer"); |
---|
| 105 | add_timer_interval(gettick()+10, imalive_timer,0,0,imalive_time*1000); |
---|
| 106 | } |
---|
| 107 | } |
---|