diff options
Diffstat (limited to 'plugin_example/plugin_example.c')
| -rw-r--r-- | plugin_example/plugin_example.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/plugin_example/plugin_example.c b/plugin_example/plugin_example.c new file mode 100644 index 0000000..45a2131 --- /dev/null +++ b/plugin_example/plugin_example.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +// +#include "../src/external.h" + +static void log_to_file(const char *message) { + FILE *log_file = fopen("bin/server_logs.log", "a"); + if (log_file) { + fprintf(log_file, "%s\n", message); + fclose(log_file); + } +} + +void MP_init_plugin() { // say hello to the user! + printf("hello from a plugin!\n"); +} + +void MP_modify_server_stats(struct relay_info *server_stats) { + // return a random number as motd each time + char str[] = "hello! random number: X"; + str[ sizeof(str) - 2 ] = (rand() % 10) + '0'; + memcpy(server_stats->motd, str, sizeof(str)); +} + +void MP_custom_log(int level, const char *msg) { + // log stuff to a file + char log_msg[ 512 ]; + snprintf(log_msg, sizeof(log_msg), "[level %d] %s", level, msg); + log_to_file(log_msg); +} + +void MP_on_server_shutdown() { // goodbye! + printf("bye!\n"); +}
\ No newline at end of file |
