sample.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Sample Athena plugin
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "../common/plugin.h"
  5. ////// Plugin information ////////
  6. //
  7. PLUGIN_INFO = {
  8. // change only the following area
  9. "Test", // Plugin name
  10. PLUGIN_ALL, // Which servers is this plugin for
  11. "0.1", // Plugin version
  12. PLUGIN_VERSION, // Minimum plugin engine version to run
  13. "A sample plugin" // Short description of plugin
  14. };
  15. ////// Plugin event list //////////
  16. // Format: <plugin function>,<event name>
  17. // All registered functions to a event gets executed
  18. // (In descending order) when its called.
  19. // Multiple functions can be called by multiple events too,
  20. // So it's up to your creativity ^^
  21. //
  22. PLUGIN_EVENTS_TABLE = {
  23. // change only the following area
  24. { "test_me", "Plugin_Test" }, // when the plugin is tested for compatibility
  25. { "do_init", "Plugin_Init" }, // when plugins are loaded
  26. { "do_final", "Plugin_Final" }, // when plugins are unloaded
  27. { "some_function", "some_event" },
  28. { "some_function", "another_event" },
  29. { NULL, NULL }
  30. };
  31. ///// Variables /////
  32. char *server_type;
  33. char *server_name;
  34. //////// Plugin functions //////////
  35. int do_init ()
  36. {
  37. // import symbols from the server
  38. IMPORT_SYMBOL(server_type, 0);
  39. IMPORT_SYMBOL(server_name, 1);
  40. printf ("Server type is ");
  41. switch (*server_type) {
  42. case PLUGIN_LOGIN: printf ("Login\n"); break;
  43. case PLUGIN_CHAR: printf ("Char\n"); break;
  44. case PLUGIN_MAP: printf ("Map\n"); break;
  45. }
  46. printf ("Filename is %s\n", server_name);
  47. return 1;
  48. }
  49. int do_final ()
  50. {
  51. printf ("Bye world\n");
  52. return 1;
  53. }
  54. int some_function ()
  55. {
  56. printf ("Some function\n");
  57. return 0;
  58. }
  59. // return 1 if the testing passes, otherwise 0
  60. // (where the plugin will be deactivated)
  61. int test_me ()
  62. {
  63. if (1 + 1 == 2)
  64. return 1;
  65. return 0;
  66. }