简体   繁体   中英

Detect invisible glyphs from character array in C++

I am working on a simple plugin for a game emulator in C++. The purpose of the plugin is to detect if message posted by user contains more than 3 spaces or message with these strings: : or ;

The code looks like this so far:

#include "common/hercules.h"
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/socket.h"
#include "common/strlib.h"
#include "map/clif.h"
#include "map/pc.h"

#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

HPExport struct hplugin_info pinfo = {
    "GM Impersonate",   // Plugin name  
    SERVER_TYPE_MAP,    // Which server types this plugin works with?
    "1.0",              // Plugin version
    HPM_VERSION,        // HPM Version (don't change, macro is automatically updated)
};

bool my_pc_process_chat_message(bool retVal___, struct map_session_data *sd, const char *message) {
    if (retVal___ == true) {
        if (stristr(message, "    ")) {
            clif->messagecolor_self(sd->fd, COLOR_RED, "Possible GM Impersonation Detected - you cannot use more than 3 spaces in chat.");
            return false;
        }
        if (stristr(message, " : ") || stristr(message, " ; ")) {
            clif->messagecolor_self(sd->fd, COLOR_RED, "Possible GM Impersonation Detected - you cannot use : or ; in chat.");
            return false;
        }
    }
    return true;
}

HPExport void plugin_init(void) {
    addHookPost(pc, process_chat_message, my_pc_process_chat_message);
}

I am not a C++ programmer, I used a sample plugin to work this code out, which appears to be working miraculously. I am now trying to improve this little plugin to detect invisible glyphs, as if they were spaces, in the message char array.

How can I achieve this?

I found this post - https://stackoverflow.com/a/15813530/2332336 but this appears to be for string, not char array. Any ideas?

I'm not sure the solution you linked to is the same as "invisible/Non-ASCII" as it seems only to deal with stripping out 8-bit ASCII codes. However if you want to try the solution you linked to, there is no reason to let the difference in char arrays and strings stand in your way. The String class has a constructor that will work to convert for you.

string mystring(message);

Then you can feel free to use the "stripUnicode" method from the linked solution to see if that gets what you were expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM