Для разработчиков: награда за голос
Как получать голоса игроков на свой сервер и выдавать награду автоматически. Настройка — в кабинете владельца, раздел «Награда за голос».
Webhook
На каждый голос с ником за ваш сервер отправляем POST с JSON (поля ниже). Подпись — в заголовке X-Mmohub-Signature: sha256= и HMAC-SHA256 тела запроса по вашему секретному ключу. Ответьте 2xx — голос отметится «доставлен». При ошибке повторим через 1, 10 и 30 минут. Адрес — только https, перенаправления не выполняем.
Тело запроса (POST, JSON){
"id": 81234,
"project": "veloria",
"server": "veloria-x50",
"nickname": "DarkElfRogue",
"votedAt": "2026-09-25T14:31:18+03:00"
} Приём и проверка подписи — PHP <?php
// mmohub-vote.php: set https://your-site/mmohub-vote.php as the webhook address
$secret = 'mmh_your_key'; // the secret key from the owner cabinet
function giveReward(string $nickname, int $voteId): void {
// Your delivery: a row in the game database, mail to the character, etc.
// Give it once per $voteId (a unique key on the vote id).
error_log("MMOHUB reward for $nickname, vote $voteId");
}
$body = file_get_contents('php://input');
$sign = 'sha256=' . hash_hmac('sha256', $body, $secret);
if (!hash_equals($sign, $_SERVER['HTTP_X_MMOHUB_SIGNATURE'] ?? '')) {
http_response_code(401);
exit;
}
$vote = json_decode($body, true);
if (empty($vote['test'])) { // test: true is the cabinet's test vote
giveReward($vote['nickname'], $vote['id']);
}
http_response_code(200);
Приём и проверка подписи — Node.js // mmohub-vote.mjs: MMOHUB_SECRET=mmh_your_key PORT=8080 node mmohub-vote.mjs (Node 18+)
import { createServer } from 'node:http';
import { createHmac, timingSafeEqual } from 'node:crypto';
const SECRET = process.env.MMOHUB_SECRET; // the secret key from the owner cabinet
const PORT = Number(process.env.PORT ?? 8080);
function giveReward(nickname, voteId) {
// Your delivery: a row in the game database, mail to the character, etc.
// Give it once per voteId (a unique key on the vote id).
console.log(`MMOHUB reward for ${nickname}, vote ${voteId}`);
}
createServer((req, res) => {
const chunks = [];
req.on('data', (c) => chunks.push(c));
req.on('end', () => {
const body = Buffer.concat(chunks);
const want = Buffer.from('sha256=' + createHmac('sha256', SECRET).update(body).digest('hex'));
const got = Buffer.from(String(req.headers['x-mmohub-signature'] ?? ''));
if (got.length !== want.length || !timingSafeEqual(got, want)) {
res.writeHead(401).end();
return;
}
const vote = JSON.parse(body.toString('utf8'));
if (!vote.test) giveReward(vote.nickname, vote.id); // test: true is the cabinet's test vote
res.writeHead(200).end();
});
}).listen(PORT);
API
Если webhook неудобен, выберите способ «API»: забирайте новые голоса запросом GET и отмечайте выданные запросом POST. Ключ передаётся в заголовке Authorization: Bearer.
Забор голосов (способ «API»)GET https://mmohub.gg/api/v1/rewards/votes?server=<slug>&after=<id> POST https://mmohub.gg/api/v1/rewards/votes/<id>/delivered?server=<slug> Authorization: Bearer <key>
Вручную
Способ «Вручную» — выгрузка голосов за день в CSV из кабинета.
Безопасность
Проверяйте подпись каждого запроса и не выдавайте награду дважды за один id. Голос с полем test: true — тестовый из кабинета, награду за него не выдавайте. Ключ можно заменить в кабинете в любой момент.