d3strukt0r/votifier-client

发送投票请求到带有 Votifier 插件服务器的简单工具。

3.0.0 2020-10-26 13:37 UTC

This package is auto-updated.

Last update: 2024-09-14 10:01:17 UTC


README

此 PHP 脚本允许轻松使用 Bukkit 插件 Votifier

项目

License Version Version (including pre-releases) Downloads on Packagist Required PHP version

master 分支(别名稳定、最新)

GH Action CI/CD Coveralls Scrutinizer build status Scrutinizer code quality Codacy grade Docs build status

develop 分支(别名夜间版)

GH Action CI/CD Coveralls Scrutinizer build status Scrutinizer code quality Codacy grade Docs build status

入门指南

以下说明将帮助您在本地机器上获取项目副本并运行它,以便进行开发和测试。有关如何将项目部署到实际系统上的说明,请参阅部署。

完整文档可在此处找到。

先决条件

安装软件需要安装哪些东西以及如何安装

  • PHP 项目(PHP 7.1+)
  • 带有 Votifier 插件的 Minecraft 服务器

安装

使用 Composer 添加客户端。

composer require d3strukt0r/votifier-client

用法

只需创建一个包含所有信息的对象

对于使用经典 Votifier 插件的服务器

<?php

use D3strukt0r\Votifier\Client\Server\Votifier;

$server = (new Votifier())
    ->setHost('127.0.0.1')
    ->setPublicKey('MIIBIjANBgkq...')
;

对于使用 NuVotifier 插件(v1 协议)的服务器(提示:它与方法 1 不同)

<?php

use D3strukt0r\Votifier\Client\Server\NuVotifier;

$server = (new NuVotifier())
    ->setHost('127.0.0.1')
    ->setPublicKey('MIIBIjANBgkq...')
;

对于使用 NuVotifier 插件(v2 协议)的服务器

<?php

use D3strukt0r\Votifier\Client\Server\NuVotifier;

$server = (new NuVotifier())
    ->setHost('127.0.0.1')
    ->setProtocolV2(true)
    ->setToken('7j302r4n...')
;

最后,只需发送即可。

<?php

use D3strukt0r\Votifier\Client\Exception\NotVotifierException;
use D3strukt0r\Votifier\Client\Exception\NuVotifierChallengeInvalidException;
use D3strukt0r\Votifier\Client\Exception\NuVotifierException;
use D3strukt0r\Votifier\Client\Exception\NuVotifierSignatureInvalidException;
use D3strukt0r\Votifier\Client\Exception\NuVotifierUnknownServiceException;
use D3strukt0r\Votifier\Client\Exception\NuVotifierUsernameTooLongException;
use D3strukt0r\Votifier\Client\Exception\Socket\NoConnectionException;
use D3strukt0r\Votifier\Client\Exception\Socket\PackageNotReceivedException;
use D3strukt0r\Votifier\Client\Exception\Socket\PackageNotSentException;
use D3strukt0r\Votifier\Client\Server\ServerInterface;
use D3strukt0r\Votifier\Client\Vote\ClassicVote;

$vote = (new ClassicVote())
    ->setUsername($_GET['username'])
    ->setServiceName('Your vote list')
    ->setAddress($_SERVER['REMOTE_ADDR'])
;

try {
    /** @var ServerInterface $server */
    $server->sendVote($vote);
    // Connection created, and vote sent. Doesn't mean the server handled it correctly, but the client did.
} catch (InvalidArgumentException $e) {
    // Not all variables that are needed have been set. See $e->getMessage() for all errors.
} catch (NoConnectionException $e) {
    // Could not create a connection (socket) to the specified server
} catch (PackageNotReceivedException $e) {
    // If the package couldn't be received, for whatever reason.
} catch (PackageNotSentException $e) {
    // If the package couldn't be send, for whatever reason.
} catch (NotVotifierException $e) {
    // The server didn't give a standard Votifier response
} catch (NuVotifierChallengeInvalidException $e) {
    // Specific for NuVotifier: The challenge was invalid (Shouldn't happen by default, but it's here in case).
} catch (NuVotifierSignatureInvalidException $e) {
    // Specific for NuVotifier: The signature was invalid (Shouldn't happen by default, but it's here in case).
} catch (NuVotifierUnknownServiceException $e) {
    // Specific for NuVotifier: A token can be specific for a list, so if the list isn't supposed to use the given token, this message appears.
} catch (NuVotifierUsernameTooLongException $e) {
    // Specific for NuVotifier: A username cannot be over 16 characters (Why? Don't ask me)
} catch (NuVotifierException $e) {
    // In case there is a new error message that wasn't added to the library, this will take care of that.
}

运行测试

说明如何为此系统运行自动化测试

分解为端到端测试

运行测试脚本

./vendor/bin/phpunit

编码风格测试和修复

为了检查代码是否符合 PSR-12 标准,已在开发环境中添加了 PHP_CodeSniffer 库,但您也可以从此处此处单独下载。

要查看代码中存在的错误,请运行

./vendor/bin/phpcs

要修复代码

./vendor/bin/phpcbf

此库已附带 php-cs-fixer,但由于无法将其设置为遵循 PSR-12 标准,它不再是必需的。它只保留在项目中,以提供可能应用的一些额外的样式信息。您也可以从此处单独下载。

./vendor/bin/php-cs-fixer fix --diff --dry-run -v

代码文档

此处安装 Python v3。

如文档所述,安装 Sphinx 此处

pip install -U sphinx

要构建文档

cd docs
pip install -r requirements.txt
make html

旧代码文档

您还可以使用 phpDocumentor 创建文档。为此,请从此处下载至少 v3+ 版本才能运行。然后您只需运行它即可。

curl -fsSL -o /usr/local/bin/phpdoc https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.0.0-rc/phpDocumentor.phar
phpdoc

构建使用

贡献

请阅读 CONTRIBUTING.md 了解我们的行为准则以及向我们提交pull请求的流程。

版本控制

我们使用 SemVer 进行版本控制。有关可用的版本,请参阅本存储库上的标签

作者

也可以查看参与此项目的贡献者列表

许可证

本项目采用GNU通用公共许可证v3.0许可 - 详细内容请参阅LICENSE.txt文件。

致谢

  • 向任何使用过其代码的人表示感谢
  • 灵感来源