投票:如何在伺服器獲取投票數

玩家在 akvarium.space 為 Akvarium 伺服器投票,我們會立即將投票轉發至您的伺服器,以便您發放獎勵。有兩種方式,可同時啟用:帶有 JSON 的 HTTP 請求與 RCON 指令。

誰可以投票

  • 只有將遊戲 ID 綁定至 Akvarium 的玩家才能投票:需透過 play.akvarium.space 上的 /akvarium login 指令登入網站。因此,投票中的遊戲 ID 始終為真實有效,代表其擁有者曾進入遊戲。
  • 每個帳號每天可為每個伺服器投 1 票(以莫斯科時間為準)。
  • 每個帳號在所有伺服器每日最多投票 10 次,每個 IP (20) 亦然。
  • 同一帳號兩次投票間隔不得少於 5 秒。
  • 評分僅計算過去 30 天內的投票。

方式一:HTTP JSON

對於每次投票,我們會向您的地址發送 POST 請求。請求體為 JSON,簽名位於 X-Akv-Signature 標頭中:這是使用您的密鑰對「timestamp.請求體」字串進行的 HMAC-SHA256 運算結果。密鑰顯示在伺服器管理頁面上。

請求標頭
POST /akvarium-vote HTTP/1.1
Content-Type: application/json
User-Agent: akvarium.space-monitoring/1.0
X-Akv-Timestamp: 1764950400
X-Akv-Vote-Id: 1842
X-Akv-Signature: sha256=5d41402abc4b2a76b9719d911017c592...
請求本體
{
  "type": "vote",
  "server": "akvarium",
  "nick": "Steve",
  "voteId": 1842,
  "timestamp": 1764950400,
  "test": false
}
  • 請在 6 秒內回應 2xx 狀態碼:如此我們方能確認投票已受理。
  • 若無回應或狀態碼非 2xx,我們將重試兩次:分別於 30 秒後及 5 分鐘後。請務必核對 voteId,避免重複發放獎勵。
  • 請驗證簽名與時間戳:timestamp 不得早於 5 分鐘前。
  • 測試投票「test」的 "test": true 且 voteId 為 0,無需發放獎勵。
Node.js
// Node.js 18+ (Express)
const crypto = require('crypto');
const express = require('express');
const app = express();
const SECRET = process.env.AKV_SECRET; // secret from the server settings page
const seen = new Set(); // keep voteIds in your DB in production

app.post('/akvarium-vote', express.raw({ type: 'application/json' }), (req, res) => {
  const body = req.body.toString('utf8');
  const ts = Number(req.get('X-Akv-Timestamp'));
  const expected = 'sha256=' + crypto.createHmac('sha256', SECRET).update(ts + '.' + body).digest('hex');
  const got = req.get('X-Akv-Signature') || '';
  if (got.length !== expected.length || !crypto.timingSafeEqual(Buffer.from(got), Buffer.from(expected))) {
    return res.status(401).send('bad signature');
  }
  if (Math.abs(Date.now() / 1000 - ts) > 300) return res.status(400).send('old');
  const vote = JSON.parse(body);
  if (vote.test) return res.send('test ok');
  if (seen.has(vote.voteId)) return res.send('duplicate');
  seen.add(vote.voteId);
  // give the reward to vote.nick here
  res.send('ok');
});

app.listen(8080);
PHP
<?php
// PHP 7.4+
$secret = getenv('AKV_SECRET');
$body = file_get_contents('php://input');
$ts = (int)($_SERVER['HTTP_X_AKV_TIMESTAMP'] ?? 0);
$expected = 'sha256=' . hash_hmac('sha256', $ts . '.' . $body, $secret);
if (!hash_equals($expected, $_SERVER['HTTP_X_AKV_SIGNATURE'] ?? '')) {
  http_response_code(401); exit('bad signature');
}
if (abs(time() - $ts) > 300) { http_response_code(400); exit('old'); }
$vote = json_decode($body, true);
if ($vote['test']) { exit('test ok'); }
// check that $vote['voteId'] is new, then reward $vote['nick']
echo 'ok';
Python
# Python 3 (Flask)
import hmac, hashlib, json, os, time
from flask import Flask, request

app = Flask(__name__)
SECRET = os.environ["AKV_SECRET"].encode()

@app.post("/akvarium-vote")
def vote():
    body = request.get_data()
    ts = request.headers.get("X-Akv-Timestamp", "0")
    expected = "sha256=" + hmac.new(SECRET, ts.encode() + b"." + body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, request.headers.get("X-Akv-Signature", "")):
        return "bad signature", 401
    if abs(time.time() - int(ts)) > 300:
        return "old", 400
    data = json.loads(body)
    if data["test"]:
        return "test ok"
    # check that data["voteId"] is new, then reward data["nick"]
    return "ok"

方式二:RCON

我們將連接至您伺服器的 RCON 並執行單一指令。指令請勿以斜線「/」開頭。玩家暱稱會自動替換 {nick};若指令中未包含 {nick},則暱稱將以空格分隔附加於指令末尾。

啟用 RCON
# server.properties
enable-rcon=true
rcon.port=25575
rcon.password=long-random-password
指令範例(不含「/」)
give {nick} diamond 3
eco give {nick} 100
lp user {nick} permission settemp vote.bonus true 1d
broadcast {nick} voted for the server!
  • 投票(HTTP 與 RCON)來自 IP 185.192.247.15:您可以僅對該 IP 開放 RCON 端口。
  • RCON 密碼以加密形式儲存,不對任何人顯示,包括您自己在內。
  • 主機必須為公開 IP 位址:不接受區域網路或內部網路位址。

於本管理頁面進行測試

在伺服器管理頁面有一個「發送測試」按鈕:它會向所有已設定的目標發送測試投票,並顯示是否送達;若未送達,則指出錯誤步驟(地址、連線、RCON 密碼、伺服器回應)。

  • 每 10 秒僅可執行一次測試。
  • 總共限 50 次測試,之後測試功能將關閉 48 小時,隨後計數器重置。

新增伺服器

© 2026 akvarium.space. 非 Minecraft 官方產品。未經 Mojang AB 或 Microsoft 核准,亦與其無關。