一个玩家为osu制作并维护的作弊检测工具!。提供从配置文件、映射或OSR文件集检测重播窃取和重新添加的支持。

circleguard的Python项目详细描述


pypi versioncodefactor

圆形孔

CircleCore是CircleGuard项目的后端,可用作PIP模块。如果您希望自己下载并开始使用circleguard程序,请参见我们的前端存储库。如果您想将CircleGuard合并到自己的项目中,请继续阅读。

为了澄清,该模块在内部称为CircleCore,以将其与CircleGuard项目作为一个整体区别开来,但在本概述中作为CircleGuard导入,并称为CircleGuard。

用法

首先,安装CircleGuard:

pip install circleguard

CircleGuard可以通过两种方式运行,一种是通过方便的方法,如CircleGuard.user_check()来运行,另一种是通过实例化check对象并将其传递给CircleGuard.run(check),后者提供了对要比较的回放方式和回放内容的更多控制。两个方法都返回一个包含结果对象的生成器。

下面的示例提供了结果对象的非常简单的用法。有关通过结果对象可以使用哪些变量的详细文档,请参阅代码中的文档。

方便方法

对于简单的用法,您可能只需要使用方便的方法。这些方法由CircleGuard的前端直接使用,并且通常在此基础上进行维护,因此在大多数情况下都会使用有用的方法。便利方法与通过check对象运行circleguard没有什么不同——在内部,便利方法所做的就是创建check对象,然后无论如何都用它们运行circleguard。它们只是为CircleGuard的常见用例提供了简单的使用方法,例如检查特定地图的排行榜。

fromcircleguardimport*# replace the example api key with your own key - this key is invalid and will not work.circleguard=Circleguard("5c626a85b077fac5d201565d5413de06b92382c4")# screen a user's top plays for replay steals and remods. (defaults to 50 top plays)forrincircleguard.user_check(12092800):ifr.ischeat:# later_replay and earlier_replay provide a reference to either replay1 or replay2, depending on which one was set before the other.print("Found a cheater! {} vs {}, {} set later.".format(r.replay1.username,r.replay2.username,r.later_replay.username))# compare the top 10 HDHR plays on a map for replay steals# Mod to int documentation: https://github.com/ppy/osu-api/wiki#modsforrincircleguard.map_check(1005542,num=10,mods=24):ifr.ischeat:print("Found a cheater on a map! {} vs {}, {} set later.".format(r.replay1.username,r.replay2.username,r.later_replay.username))# compare local files for replay stealsforrincircleguard.local_check("/absolute/path/to/folder/containing/osr/files/"):ifr.ischeat:print("Found a cheater locally! {} vs {}, {} set later.".format(r.replay1.path,r.replay2.path,r.later_replay.path))# compare two specific users' plays on a map to check for a replay stealforrincircleguard.verify(1699366,12092800,7477458):ifr.ischeat:print("Confirmed that {} is cheating".format(r.later_replay.username))else:print("Neither of those two users appear to have stolen from each other")

一般情况下

使用circleguard的更灵活的方法是创建自己的check对象并用它运行circleguard。这允许混合不同类型的重播对象(比较local.osr和online重播),还允许您自己实例化重播对象并使用自己的重播子类。有关子类化的详细信息,请参见高级用法。

fromcircleguardimport*frompathlibimportPathcircleguard=Circleguard("5c626a85b077fac5d201565d5413de06b92382c4")# assuming you have your replays folder in ../replays, relative to your script. Adjust as necessaryPATH=Path(__file__).parent/"replays"# assuming you have two files called woey.osr and ryuk.osr in the replays folder.# This example uses python Paths, but strings representing the absolute file location will work just fine.# Refer to the Pathlib documentation for reference on what constitutes a valid Path in string form.replays=[ReplayPath(PATH/"woey.osr"),ReplayPath(PATH/"ryuk.osr")]check=Check(replays)forrincircleguard.run(check):ifr.ischeat:print("Found a cheater locally! {} vs {}, {} set later.".format(r.replay1.path,r.replay2.path,r.later_replay.path))# Check objects allow mixing of Replay subclasses. circleguard only defines ReplayPath and ReplayMap,# but as we will see under Advanced Usage, you can define your own subclasses to suit your needs.replays=[ReplayPath(PATH/"woey.osr"),ReplayMap(map_id=1699366,user_id=12092800,mods=0)]forrincircleguard.run(Check(replays)):ifr.ischeat:# Replay subclasses have well defined __str__ and __repr__ methods, so we can print them directly to represent them in a human readable way if need be.print("Found a cheater! {} vs {}, {} set later.".format(r.replay1,r.replay2,r.later_replay))

缓存

CircleGuard将缓存下载的重播,如果您给它一个数据库的路径,并将缓存选项设置为true。这减少了下载时间,因为重放存储在本地,而不是等待相当大的api速率限制。您可以在设置选项下查看有关设置选项的更多信息。

# if the database given doesn't exist, it will be created at the specified location.cg=Circleguard("5c626a85b077fac5d201565d5413de06b92382c4","/path/to/your/db/file/db.db")cg.set_options(cache=True)# can also pass cache=True to a convenience method like map_check, but it will only apply for that single check. This will cache replays for all methods for this circleguard object.# all 6 replays will be loaded from the apiforrincg.map_check(221777,num=6):pass# the first 6 replays will be loaded from the cache, and only 5 will be loaded from the api, avoiding the 10 replays/min ratelimit.forrincg.map_check(221777,num=11)

由于缓存存储在一个文件而不是内存中,因此它会在运行过程中持续存在;在实例化CircleGuard时,只需将路径传递给该文件即可。

高级用法

设置选项

有四层选择。设置的最低选项对任何给定的重播或比较都具有优先权。

使用circleguard.set_options可在最高级别(全局级别)设置选项。选项可以在第二个最高级别(实例级别)使用circleguard\set\u options进行更改,这只会影响调用该方法的实例。请小心使用静态模块方法更改全局设置和实例方法更改实例设置,因为它们共享相同的名称,并且容易混淆。

通过在实例化检查时传递适当的参数,可以在第二个最低级别(检查级别)进一步指定选项。最后,当重播被实例化时,通过传递适当的参数,可以在最低级别(重播级别)更改选项。

当更改所有先前实例化的对象时,这些设置会影响它们。也就是说,如果全局更改一个选项,它将为所有过去和将来的CircleGuard实例更改该设置。

子类化重播

如果所提供的replay实现不能满足您的需要-replaypathreplaymap-您可以自己对replay(或其子类之一)进行子类划分。

下面是一个简单的子类化示例,其中每个重播都有一个唯一的ID。例如,如果要区分在12:05和12:07加载一个完全相同的重播,则为每个实例提供一个唯一的ID将有助于区分它们。这是一个有点做作的例子(将重播与重播本身进行比较总是会返回一个肯定的作弊结果),但是无论出于什么原因需要向类添加额外的属性或方法,对它们进行子类划分都很简单。

fromcircleguardimport*classIdentifiableReplay(ReplayPath):def__init__(self,id,path):self.id=idsuper().__init__(path)circleguard=Circleguard("5c626a85b077fac5d201565d5413de06b92382c4")check=Check(IdentifiableReplay(1,"/path/to/same/osr.osr"),IdentifiableReplay(2,"/path/to/same/osr.osr"))forresultincircleguard.run(check):print("id {} vs {} - cheating? {}".format(result.replay1.id,result.replay2.id,result.ischeat))

虽然回放默认不具有id属性,但由于我们进行了检查对象可识别回放,当我们运行检查时,它会向我们吐回可识别回放,我们可以访问id属性。

除了通过构造函数向重播添加信息外,还可以通过重载其load方法来控制何时以及如何加载重播。下面的例子同样是精心设计的,因为我们为您提供了一个数据库实现(如果您以前下载并缓存了任何试图通过api加载的回放,那么它们都将从数据库中加载),但希望能够达到重载的目的。跨越.< /P>

fromcircleguardimport*classReplayDatabase(Replay):def__init__(self,map_id,user_id,mods,detect=Detect.ALL):self.map_id=map_idself.user_id=user_idself.mods=modsself.detect=detectself.loaded=Falsedefload(self,loader,cache=None):# execute some sql (implementation not shown) to retrieve replay data from a local database. Assume the call returns a tuple of (replay_id, replay_data)result=load_replay_from_database(self.map_id,self.user_id,self.mods)replay_id=result[0]replay_data=result[1]Replay.__init__(self,self.user_id,self.mods,replay_id,replay_data,self.detect,loaded=True)replays=[ReplayDatabase(1699366,12092800,4),ReplayDatabase(1005542,7477458,16)]forreplayinreplays:print("loading replay from local database")replay.load()forresultincircleguard.run(Check(replys)):print(result.similarity)

为了避免同时允许用户在程序中的任何一点实例化重播子类,并且只在必要时加载它们(当调用CircleGuard Run(check)时),CircleGuard选择等待初始化重播超类,直到oad方法被调用,我们拥有replay类所需的所有必要信息,这些信息来自api、本地osr文件或其他一些方法。

这意味着,如果你对重播进行子类划分,你必须确保你做了一些CircleGuard期望从任何重播子类中得到的事情。重播必须在load方法中初始化(not方法中,如您所料),并且您必须将self.weight设置为您的ratelimitweight.heavyratelimitweight.lightratelimitweight.none中的一个<代码>初始化方法(不是加载方法中的!CircleGuard需要在程序加载前知道加载此重播将对程序造成多少收费)。下面是RateLimit枚举中的文档,方便您使用:

"""How much it 'costs' to load a replay from the api. If the load method of a replay makes no api calls,the corresponding value is RatelimitWeight.NONE. If it makes only light api calls (anything but get_replay),the corresponding value is RatelimitWeight.LIGHT. If it makes any heavy api calls (get_replay), thecorresponding value is RatelimitWeight.HEAVY.    This value currently has no effect on the program and is reserved for possible future functionality."""

重播数据必须是传递到重播时类似于对象的circleparse.replayevent列表。您可以查看circleparse存储库以获取更多信息,但这意味着每个对象都必须具有自上一个操作之后的时间、x、y和attrib键。UT. < /P>

最后,重播的加载方法必须接受一个必需的参数和一个位置参数,而不管您是否分别使用它们-loadercache=none。如果需要从api加载一些信息,请使用传递的loader类来执行此操作(有关进一步的文档,请参阅loader类)。您是否应该实现自己的缓存系统,t他缓存参数处理所有讨厌的选项层次问题,并为您提供最终结果-这个单一的重播应该缓存吗?如果选择缓存重播,还必须通过在load方法中写入相应的逻辑来实现从缓存加载重播。CircleGuard没有触及这些问题—replaymap的缓存发生在与replay load完全不同的位置。只要通过在load中初始化重播,将self.loaded设置为true,CircleGuard将尊重您的重播并假定您已正确加载数据。

加载重播

通常,当您调用circleguard run(check)时,会加载check对象中的所有重播。但是,如果需要更多控制何时加载重播(或加载时加载哪些重播),可以调用circleguard.load(check,replay)加载传递的check对象中包含的单个重播。这是一种用于调用replay load(circleguard.loader,check.cache)的速记方法,建议始终使用circleguard,否则可能会导致设置层次结构未正确级联到重播时出现意外的缓存问题。有关replay加载的可选缓存选项的详细信息,请参见子类化replay的最后一节。

重放加载的顺序没有限制;当调用CircleGuard Run(check)时,它首先检查check.loaded是否为true。如果是,则假定check对象中的所有重播都已加载,并继续进行比较。否则,它将检查check对象中的每个重播是否已将replay.loaded设置为true-如果是,则继续加载下一个重播。否则,它调用replay load

加载前修改方便方法检查

在运行之前,您可能会发现希望对便利方法返回的检查执行操作。尽管标准的便利方法创建检查并立即运行它,但CircleGuard提供的方法仅创建检查CircleGuard创建映射检查CircleGuard创建用户检查,等等)。

例如,guicircleguard利用这些方法逐个加载重放,并在运行检查之前增加一个进度条,这在满足标准便利性的情况下是不可能的。HODS.

您也可以在运行前通过添加或删除重播来修改检查。在修改返回的check检查之前,您应该了解处理此问题的建议方法(例如包含方便方法的参数和check对象)是否满足您的需要。

贡献

如果您想为CircleGuard做出贡献,请加入我们的不和,并询问您可以提供哪些帮助,或者查看CircleGuard的开放问题和圆圈。如果您有任何问题,我们很高兴与您合作!

您还可以通过为bug或功能请求打开问题来提供帮助,这有助于我们和其他人跟踪下一步需要做什么。

结论

不管你是通读所有的东西还是向下滚动到底部,我希望这对你有所帮助。如果你有任何问题,我们不和的联系如下。我们欢迎任何评论,并乐于回答问题。

不协调:https://discord.gg/vnnktjm rel="nofollow">https://discord.gg/vnnktjm

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何下载多个。java中的PDF文件   linux Java打开文件,形成实际用户主页~/   java如何在时间线内维护TableView选择?   java Hibernate注释@Where vs@WhereJoinTable   Java读/写访问异常FileNotFoundException(访问被拒绝)   继承在Java中是否可以扩展最后一个类?   Android HttpClient使用java使应用程序崩溃。lang.OutOfMemoryError:pthread_create   java为什么即使我在proguardproject中添加了jar文件,也会出现这种错误。txt?   如果添加JButton,swing Java FocusListener和KeyListener将无法工作   java使用solrj检索json格式的SolrDocument   使用Microsoft Visual Studio代码进行Java编程   java NoClassDefFoundError:org/apache/log4j/Logger   哈希集中包含相等对象的java   java中的参数化构造函数是否需要有一个主体?   java类似于NetBeans不必要的代码检测器   Java实践问题   java Blackberry“[projectname].调试文件丢失”和“I/O错误:找不到程序”jar