summaryrefslogtreecommitdiff
path: root/src/plugins/sample.c
blob: 8e6b8fc8629ed1f02dcc63ba5b2587b0262f3c02 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// See the LICENSE file
// Sample Hercules Plugin

#include <stdio.h>
#include <string.h>
#include "../common/HPMi.h"
#include "../map/script.h"
#include "../map/pc.h"

HPExport struct hplugin_info pinfo = {
	"Sample",		// Plugin name
	SERVER_TYPE_MAP,// Which server types this plugin works with?
	"0.1",			// Plugin version
	HPM_VERSION,	// HPM Version (don't change, macro is automatically updated)
};
ACMD(sample) {//@sample command - 5 params: const int fd, struct map_session_data* sd, const char* command, const char* message, struct AtCommandInfo *info
	printf("I'm being run! message -> '%s' by %s\n",message,sd->status.name);
	return true;
}
BUILDIN(sample) {//script command 'sample(num);' - 1 param: struct script_state* st
	int arg = script_getnum(st,2);
	ShowInfo("I'm being run! arg -> '%d'\n",arg);
	return true;
}
CPCMD(sample) {//console command 'sample' - 1 param: char *line
	ShowInfo("I'm being run! arg -> '%s'\n",line?line:"NONE");
}
struct script_interface *script;/* used by script commands */
/* run when server starts */
HPExport void plugin_init (void) {
	char *server_type;
	char *server_name;
	
	//get the symbols from the server
	server_type = GET_SYMBOL("SERVER_TYPE");
	server_name = GET_SYMBOL("SERVER_NAME");

	script = GET_SYMBOL("script");
	
	if( !(script = GET_SYMBOL("script")) ) {
		ShowError("Failed to load script interface var!\n");
	}
	
	ShowInfo ("Server type is ");
	
	switch (*server_type) {
		case SERVER_TYPE_LOGIN: printf ("Login Server\n"); break;
		case SERVER_TYPE_CHAR: printf ("Char Server\n"); break;
		case SERVER_TYPE_MAP: printf ("Map Server\n"); break;
	}
	
	ShowInfo ("I'm being run from the '%s' filename\n", server_name);
	
	if( HPMi->addCommand != NULL ) {//link our '@sample' command
		HPMi->addCommand("sample",ACMD_A(sample));
	}
	
	if( HPMi->addScript != NULL ) {//link our 'sample' script command
		HPMi->addScript("sample","i",BUILDIN_A(sample));
	}
	
	if( HPMi->addCPCommand != NULL ) {//link our 'sample' console command
		HPMi->addCPCommand("this:is:a:sample",CPCMD_A(sample));
	}
}
/* run when server is ready (online) */
HPExport void server_online (void) {
	
}
/* run when server is shutting down */
HPExport void plugin_final (void) {
	ShowInfo ("%s says ~Bye world\n",pinfo.name);
}