-
-
Notifications
You must be signed in to change notification settings - Fork 9
Manual testing
Manuele Vaccari edited this page Sep 14, 2020
·
3 revisions
First clone the project
git clone https://github.com/D3strukt0r/votifier-client-php.git
Inside the root directory create a file called ManualTest.php
and put the following content inside:
<?php
/**
* Votifier PHP Client
*
* @package VotifierClient
* @author Manuele Vaccari <[email protected]>
* @copyright Copyright (c) 2017-2020 Manuele Vaccari <[email protected]>
* @license https://github.com/D3strukt0r/votifier-client-php/blob/master/LICENSE.txt GNU General Public License v3.0
* @link https://github.com/D3strukt0r/votifier-client-php
*/
define('DS', DIRECTORY_SEPARATOR);
spl_autoload_register(
function ($class) {
include getcwd() . DS . 'src' . DS . mb_substr(str_replace('\\', DS, $class), mb_strlen('D3strukt0r\\Votifier\\Client')) . '.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\NuVotifier;
use D3strukt0r\Votifier\Client\Server\Votifier;
use D3strukt0r\Votifier\Client\Vote\ClassicVote;
$host = '127.0.0.1';
$publicKey = file_get_contents(
'C:' . DS . 'Users' . DS . 'Manuele' . DS . 'Desktop' . DS . 'MC-Server' . DS . 'plugins' . DS . 'Votifier' . DS . 'rsa' . DS . 'public.key'
);
$token = 'kv0iek01cebj0jjk68hl6m9225';
$testName = $argv[1] ? $argv[1] : 'votifier';
echo 'Run test: ' . $testName . "\n";
switch ($testName) {
case 'votifier':
$server = (new Votifier())
->setHost($host)
->setPublicKey($publicKey)
;
break;
case 'nuvotifier':
case 'nuvotifierv1':
$server = (new NuVotifier())
->setHost($host)
->setPublicKey($publicKey)
;
break;
case 'nuvotifierv2':
$server = (new NuVotifier())
->setHost($host)
->setProtocolV2(true)
->setToken($token)
;
break;
default:
echo 'Doesn\'t exist';
exit(1);
}
// To test multi-vote capabilities
$vote1 = (new ClassicVote())->setUsername('test')->setServiceName('Your vote list')->setAddress('0.0.0.0');
$vote2 = (new ClassicVote())->setUsername('test2')->setServiceName('Your vote list')->setAddress('0.0.0.1');
$vote3 = (new ClassicVote())->setUsername('test3')->setServiceName('Your vote list')->setAddress('0.0.0.2');
try {
$server->sendVote($vote1, $vote2, $vote3);
} catch (NoConnectionException $e) {
echo "No connection\n";
} catch (NotVotifierException $e) {
echo "Not votifier\n";
} catch (NuVotifierChallengeInvalidException $e) {
echo "Challenge invalid\n";
} catch (NuVotifierSignatureInvalidException $e) {
echo "Signature invalid\n";
} catch (NuVotifierUnknownServiceException $e) {
echo "Unknown service\n";
} catch (NuVotifierUsernameTooLongException $e) {
echo "Long username\n";
} catch (NuVotifierException $e) {
echo "Other NuVotifier exception\n";
} catch (PackageNotReceivedException $e) {
echo "Package not received\n";
} catch (PackageNotSentException $e) {
echo "Package not sent\n";
} catch (InvalidArgumentException $e) {
echo "Invalid arguments: {$e->getMessage()}\n";
} catch (Exception $e) {
echo "Nani?\n";
}
You'll still need to change the location of the public key file, or maybe just put the file contents in there.
You now also just need an instance of Minecraft running with one of the supported Votifier plugins (or multiple ones if that even works).
With this you can now run
php ManualTest.php
php ManualTest.php votifier
php ManualTest.php nuvotifierv1
php ManualTest.php nuvotifierv2