Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin support #1328

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open

Plugin support #1328

wants to merge 44 commits into from

Conversation

ray73864
Copy link
Contributor

@ray73864 ray73864 commented May 2, 2020

It's kinda rough.

Needs a directory in the rootdir called 'plugins', all works though.

Also needs 3 flags added to root/Makefile:
2 in LDFLAGS:
-Wl,--unresolved-symbols=ignore-in-object-files
-rdynamic

1 in CLIBS:
-ldl

An example test plugin:

#include <stdio.h>
#include <stdbool.h>
#include "config.h"
#include "conf.h"
#include "dbdefs.h"
#include "strutil.h"
#include "parse.h"
#include "function.h"
#include "notify.h"
#include "log.h"
#include "game.h"

void test_notify() {
  dbref player;
  player = 1;
  notify_format(player, "Hi %d!!", player);
}

FUNCTION(local_test_notify)
{
  test_notify();
  return;
}

int plugin_init(void) {
  function_add("TESTNOTIFY", local_test_notify, 0, 0, FN_REG);
//  do_rawlog(LT_ERR, "Hi");
  return 1;
}

Test plugin is compiled by doing

gcc -shared -fPIC -I.. -I../hdrs -o test.so test.c

in the plugins directory.

At that point you can either start up your game or @shutdown/reboot your game.

Plugin requires a 'plugin_init()' function, and can optionally have a 'plugin_timer()' function if you need to run something in your plugin every second.

@HarryCordewener
Copy link
Contributor

Why not add the flags to the Makefile for the submission?

@ray73864
Copy link
Contributor Author

ray73864 commented May 2, 2020

There, the configure script does the flags for Makefile now.

hdrs/conf.h Outdated Show resolved Hide resolved
src/bsd.c Outdated Show resolved Hide resolved
…hatever size it needs to be to handle the number of plugins.

Also added further error checking to the various for-loops.
@ray73864
Copy link
Contributor Author

ray73864 commented May 2, 2020

Now allocates memory for the array on a needs basis as it finds more plugins to load instead of defaulting the array size to only allowing 100 max

@talvo
Copy link
Member

talvo commented May 2, 2020

I haven't really looked at the code yet, but I'd like to see a more robust interface for this, particularly with some kind of versioning for future-proofing so more features can be added and we can tell what level of support any given plugin provides. It would also be nice if plugins had a method to report their own name, plugin version, interface version, etc, that could be displayed somewhere (probably in something like @config/plugins or the like). Linked list of a struct to store that info rather than a calloced array may be an easier approach for storing that.

…t need to go backwards, but it's an easy thing to implement.
@ray73864
Copy link
Contributor Author

ray73864 commented May 3, 2020

Have switched to using a doubly linked list instead of the array.

Will look at a better way of handling the plugins that support certain features, especially the timer feature, it's not really a problem when you only have 1 or 2 plugins, but if you have lots of plugins, it would be handy if the penn local_timer() knew ahead of time exactly which plugins to target instead of going through the entire linked list each time.

@ray73864
Copy link
Contributor Author

ray73864 commented May 3, 2020

Will look at the version support later on, for now the basics :)

…_register_loop(), move unloading of plugins from local.dst:local_shutdown() to bsd.c:unload_plugins().

Plugin management will eventually need to be moved to a new file called plugins.c, and with minor changes to necessary penn files for loading, unloading, etc...
…file not marked as 'extern' where the header file is included in multiple source files will return a 'Multiple definitions' error.
…at in bsd.c since for now bsd.c is the only file that cares about it.
…stead, that way it doesn't conflict with Penn's own next_token() function.
src/bsd.c Outdated Show resolved Hide resolved
src/bsd.c Outdated Show resolved Hide resolved
src/bsd.c Outdated Show resolved Hide resolved
src/bsd.c Outdated Show resolved Hide resolved
src/bsd.c Outdated Show resolved Hide resolved
plugins/bdv/bdv_funcs.c Outdated Show resolved Hide resolved
@ray73864
Copy link
Contributor Author

The latest PR should never have happened :)

I was trying to figure out Githubs changes since I last actively used it for doing commits, etc...

@ray73864
Copy link
Contributor Author

Closing for now. I dislike the fact that the PR keeps getting updated everytime I push a change.

@ray73864 ray73864 closed this Oct 10, 2021
…'t be since d->name is set at 256 internally) we bail out
…cription and long description.

Start of @plugin/list command.
… called by cmd_plugin.

Loop through the plugins directory so that each plugin can show whether it has been loaded into the game or not.
… so that they can be used by load/unload/reload and initial starting up/@shutdown/reboot
…ce warnings.

Fix up do_real_unload_plugin as it wasn't removing the plugin from the hashtab due to using the wrong key.
Finish implementing @plugin/reload and @plugin/unload.
Start of implementing @plugin/load <.so file>
Update do_real_load_plugin so that it returns a success or fail to denote if the plugin was loaded or not so that @plugin/load can provide feedback.
…en, also changes to the example math plugin to work on FreeBSD.
…or(), that way in cases where we are manually loading the plugin, we can display the error to the executor of @plugin/load
…nce all the plugin ids, that way it remains 1...n instead of having gaps.
…, then looping through the plugins directory where we have to eventually hashfind() anyway, just loop through the plugins directory and hashfind() on each file found.
…n/list.

Move resequence_plugin_ids() so that it is defined before it is used.
@ray73864 ray73864 reopened this May 28, 2022
@ray73864 ray73864 requested a review from talvo May 28, 2022 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants