Code Monkey home page Code Monkey logo

cod4-plugpp's Introduction

GitHub

cod4-plugpp

As the name may suggest, cod4-plugpp, or cod4-plug++, is a C++ wrapper for the CoD4x plugin system. As of now, only a fraction of the API is wrapped in C++, but it may still come in handy when developing new plugins in C++.

How to use

First of all, make sure you're using a compatible revision of the CoD4x server. This wrapper was only tested on revision 0581a7d and earlier versions may not work due to plugin API changes.

This library makes use of CMake's object libraries so that the plugin can later link the objects from this wrapper into its shared library.

In code, it's really straightforward:

class MyPlugin final : public plugpp::Plugin {
public:
    explicit MyPlugin() {
        Plugin_EnterCriticalSection();
        mMyCvar = static_cast<cvar_t*>(
            Plugin_Cvar_RegisterString("my_cvar", "default value", 0, "I'm a cool CVAR description!"));
        if (!mMyCvar->string[0]) {
            // You can throw an exception if your CVAR is mandatory and wasn't provided:
            throw plugpp::Exception("CVAR \"my_cvar\" wasn't defined");
            // This will make loading of the plugin fail and the exceptionm message will be written into the server's console.
        }
        Plugin_LeaveCriticalSection();
    }

    virtual ~MyPlugin() {}
    
    /* ======================== These virtual functions can be overridden: =========================

    virtual int onPluginLoad() override;

    virtual void onOneSecond() override;

    virtual void onTenSeconds() override;

    virtual Kick onPlayerConnect(int clientnum, netadr_t* netaddr, const char* userinfo) override;

    virtual void onPlayerDisconnect(client_t* client, const char* reason) override;

    virtual void onTerminate() override;

    ============================================================================================= */

private:
    // Overriding this function is mandatory
    virtual void onPluginInfoRequest(pluginInfo_t* info) final override {
        std::strncpy(info->fullName, "Your plugin name", sizeof(info->fullName));
        std::strncpy(info->shortDescription, "Briefly describe your plugin", sizeof(info->shortDescription));
        std::strncpy(info->longDescription, "Fully describe your plugin here", sizeof(info->longDescription));
    }

    cvar_t* mMyCvar;
};

void pluginMain(plugpp::PluginEntry& entry) {
    entry.registerPlugin<MyPlugin>(/*If your class constructor has any arguments, pass them here*/);
    // The `MyPlugin` object will live throughout the entire lifetime of the dynamic library in the memory.
}

To see an example of integrating this library into your plugin, see the cod4-pureip plugin.

cod4-plugpp's People

Contributors

proxict avatar

Watchers

 avatar

Forkers

sub20hz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.