Code Monkey home page Code Monkey logo

monitorr's Introduction

MonitorR

A plug-in that regularly obtains the location of online players for recording, and sets a restricted area at the same time. If the player is detected in the restricted area, it will be broadcast in the server and recorded.

The functional idea of this plug-in comes from Monitor, but because the latter has some functional bugs and does not have a very user-friendly experience, we reworked it.

The plug-in will recognize the bot, and will not record and judge the location of the bot.

中文 | English

Usage

Using !!mr or !!mr help to get help messages.

image

The details of each parameter can be viewed by moving the mouse over the text in the game!

At present, the text inside the plugin does not provide English version. Be aware that if there is a strong demand, please inform the issue and I will consider providing it.

Install

Download the plug-in monitor.py file to the plugins directory of MCDR. Note that the plug-in needs to be supported by MCDRv1.3 and above.

The plug-in depends on MinecraftDataAPI, see MinecraftDataAPI.

It is recommended to use the ujson third-party json library, whose IO efficiency is much higher than the default json library. But even if it is not installed, the plugin will use the json standard library by default.

Configuration

Enabling the plugin for the first time will generate a default configuration folder and configuration file in the config directory of MCDR.

The path of the configuration file is config/monitor_reforged/config.json, and its content is:

{
    "interval": 15,
    "permissions": {
        "add": 3,
        "del": 3,
        "list": 1,
        "range": 3,
        "reload": 3
    },
    "point": {
        "radius": 200,
        "contain_y": false,
    },
    "range": {
        "contain_y": false,
    }
}

Among them, interval represents the minimum time period for repeatedly obtaining all player positions, in seconds. interval is not a strictly accurate time period. This is because obtaining the player's position information multiple times in a small time will cause lag. Therefore, every time you start acquiring all player information, you will actively wait for 200 ms when you acquire a player's information. Finally count all the waiting time, let the minimum time minus total waiting time, then actively wait for the result time, and start the next cycle of acquiring all players. There are two reasons why the time is not strict here. The first is that the calculation of the waiting time is simply adding up all the sleep time, but doesn't include the time of IO operation or player information obtaining; the second is if there are a lot of players, the actual time period will inevitably exceed the time period specified in the configuration file. For example, when the number of online players on the server exceeds 75, the total waiting time for obtaining each player's information each time exceeds the default 15 seconds. At this time, if the setting is still maintained for 15 seconds, the program will ignore this 15 seconds and strictly rely on the accumulation of waiting time to obtain each player's information. The final manifestation is that there is no delay between the loops of obtaining all player information, but only the 200 ms delay of obtaining two different players next to each other.

The permissions item has many sub-items, which respectively indicate the MCDR permission level required for each command. For details, see MCDR Permission

The sub-items of the point item indicate the configuration of the protection point. Among them, radius indicates the default protection point radius. Note that the configuration item here only indicates the default value of the radius that should be used if the radius parameter is not specified when generating the protection point. In fact, when you use the default value to generate a protection point, After changing this default value, the value of this protection point will not be modified with your modification, but still keep the previous default value. contain_y also indicates whether to calculate the y coordinate by default, the same as radius, modifying the default value after generating the protection point will not cause the previous default value to be modified.

The sub-items of the range item indicate the configuration of the protected area. Among them, contain_y indicates whether to calculate the y coordinate by default, which is the same as the radius of the point item. Modifying the default value after generating the protected area will not cause the previous default value to be modified.

If you need to modify the information of the created coordinate point/area, you can refer to the next section Generate File and directly modify the site.json file. However, it is more recommended to delete the protection point/zone and recreate it.

Generate File

After running the plug-in for the first time, the plug-in will generate its own plug-in directory in the config directory of MCDR with the name monitor_reforged. This directory contains files config.json, site.json and log folders.

See the previous section for the content of config.json.

The information of all protected points/zones is stored in site.json. The file is parsed according to an example below:

[
    {
        "type": "point",
        "name": "test",
        "x": 100,
        "y": 60,
        "z": 100,
        "world": "minecraft:overworld",
        "radius": 200,
        "contain_y": false
    },
    {
        "type": "range",
        "name": "test2",
        "x1": 100,
        "y1": 60,
        "z1": 100,
        "x2": 200,
        "y2": 60,
        "z2": 200,
        "world": "minecraft:overworld",
        "contain_y": false
    }
]

As you can see, this json text is actually a list of dicts.

Each dict has a type item, which has two values: point and range. Used to distinguish whether it is a protected point or a protected area.

Each protection point/area contains the name attribute, which is used as a unique identifier.

Each protection point/area contains the world attribute, which represents the world dimension in which the protection point/area is located.

Each protection point/area contains the attribute contain_y, which indicates whether the protection point/area calculates the y coordinate.

Since the protection point is a point, it only needs to store the 3D coordinate triples of x, y and z.

The unique radius of the protection point indicates the radius of the warning zone.

The protected area is a rectangle(cuboid), so it can be represented by two corner points. So two 3D coordinate triples of x, y and z are stored. It should be noted that the two 3D coordinates stored in the file are not necessarily equal to the parameters entered before. Because there can be multiple pairs of corner points forming the same rectangle(cuboid), the record will only record a pair of corner points on the main diagonal. Intuitively, the first 3D coordinate are all mininum values, another 3D coordinate are all maximum values. At the code level, this can simplify the logic and make the judgment process running faster and simpler. If you need to modify this part, please make sure that the result of your modification still complies with the above rules. Otherwise it will cause logic errors.

The log folder is responsible for saving the players' coordinate records, which are saved in the log.json file for subsequent review (or some other purposes, such as convicting genius). At the same time, it will also record the alarm when the player is near a protection point/area. Every time the plugin is loaded (like starting MCDR and reloading the plug-in etc.), the currently record file will be renamed according to the time to prevent a file from being too large. It should be noted here that although each record file is a json file, the text inside is not strictly json text. In fact, the text inside is divided by line breaks, and each line is a json text. If you need to parse, please pay attention.

monitorr's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lkur233

monitorr's Issues

两个bug

一个是再windows下面:不能作为文件名存在,
time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
把:去掉就可以了;
还有一个没检查records文件夹是否存在,默认之前插件留存这个文件夹就不报错,但是全新创建服务器一直报错
config_folder = f"./config/{PLUGIN_METADATA['id']}"
log_folder = f'{config_folder}/logs'
log_file = f'{log_folder}/log.json'
site_file = f'{config_folder}/site.json'
config_file = f'{config_folder}/config.json'

def split_log() -> None:
global record_fp
if os.path.exists(log_file):
time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
os.rename(log_file, f'./records/{time}.json')
if not os.path.exists(config_folder):
os.makedirs(config_folder)
if not os.path.exists(log_folder):
os.makedirs(log_folder)
record_fp = open(log_file, 'w+', encoding='utf-8')

当玩家退出时,监控依旧在查询此玩家的信息

服务器MCDR后台日志:
[MCDR] [2021-08-07 09:46:58] [MonitorR/WARNING]: [Minecraft Data API] Query for player zi_xian at path Pos timeout
[MCDR] [2021-08-07 09:47:03] [MonitorR/WARNING]: [Minecraft Data API] Query for player greenskype at path Pos timeout
[MCDR] [2021-08-07 09:47:08] [MonitorR/WARNING]: [Minecraft Data API] Query for player YiFeng1999 at path Pos timeout

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.