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

插件基本功能实现 #3

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 68 additions & 9 deletions plugins/login.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,84 @@
from mcdreforged.api.command import SimpleCommandBuilder
from mcdreforged.api.command import *
from mcdreforged.command.command_source import CommandSource
from mcdreforged.info_reactor.info import Info
from mcdreforged.minecraft.rcon.rcon_connection import RconConnection
from threading import Thread
import time
import requests
import json
import os
PLUGIN_METADATA = {
'id': 'login',
'id': 'unionWhitelist',
'version': '1.0.0',
'name': 'My Plugin',
'name': 'login',
'description': 'MPWA联盟验证mcdr端',
'author': 'ZQHD',
'link': 'https://github.com',

}
rcon = RconConnection("127.0.0.123",38324,"123456")
jsonFile = open('setting.json', "r")
json = json.load(jsonFile)
rconSetting = json['rcon']
rcon = RconConnection(rconSetting['address'], rconSetting['port'], rconSetting['password'])
userKeys = ""
serverName = ""
accountName = ""
password = ""

def on_load(server, old):
buider = SimpleCommandBuilder()
# buider.command("mpwa bind",bind)
server.logger.info('Hello world!')
buider.command("!!mpwa ban <name> <description>", ban) # 永封
buider.command("!!mpwa prosecute <level> <description>", prosecute) # 处罚
buider.arg("name", Text)
buider.arg("description", Text)
buider.arg("level", Integer)
server.logger.info('load is successful')
buider.register(server)
setting = json['setting']
serverName = setting['serverName']
accountName = setting['accountName']
password = setting['password']
# response = requests.get("https://www.mpwa.cn/McServerSig",headers={
# "sname":serverName,
# "lname":accountName,
# "lpwd":password
# })
# userKeys = response.text
thread = Thread(target=loop)
thread.start()
def on_user_info(server, info:Info):
if info.content == 'mpwa bind':
user = info.player
server.reply(info, '绑定开始!用户名:{},时间:{}'.format(user,time.time()))
# def bind():
# print("succeed")
timeNow = time.time()
server.reply(info, '绑定开始!用户名:{},时间:{}'.format(user, time.strftime("%Y.%m.%d %h:%n:%s")))


def ban(source: CommandSource, context: CommandContext):
name = context['name']
description = context['description']
# Todo : 请求接口,推送黑名单


def prosecute(source: CommandSource, context: CommandContext):
level = context['level']
description = ['description']


def on_server_stop(server, server_return_code: int):
json.close()


def loop():
"""
循环执行部分的代码,如请求接口
:return:
"""
while True:
# todo:编写请求白名单黑名单的接口
newWhitelist = [] # 新白名单表单
Copy link
Contributor

@Zhou-Shilin Zhou-Shilin May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注意到你在各种地方都喜欢使用小驼峰命名法(如someName)。但在Python中变量名和类名使用小驼峰命名法是不规范的。
在Python中常用的命名:
变量名、模块、方法和参数应为全小写、空格用下划线代替,如my_var
类名和异常名应为每个单词首字母大写、空格不表示,如MyClass
详见:https://www.python.org/dev/peps/pep-0008/

newBanList = [] # 新黑名单表单
for whitelist in newWhitelist:
rcon.send_command("whitelist add {}".format(whitelist))
for banList in newBanList:
rcon.send_command("ban {}".format(banList))
time.sleep(300)
12 changes: 12 additions & 0 deletions setting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"setting": {
"serverName": "",
"accountName": "",
"password": ""
},
"rcon": {
"address": "",
"port": 38324,
"password": ""
}
}