summaryrefslogtreecommitdiff
path: root/plugin_example/plugin_example.c
blob: 45a21315cd5c6fddaca57ac6e977aecded5a83bf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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");
}