API 管理

说明:所有接口均返回 JSON;在线状态基于 last_upload_at(30 秒无上报视为离线)。卡密仅能在面板中手动编辑保存,不提供 API 修改。

读取站点卡密(仅文本显示)

GET /api/get_card_key.php
curl -s https://newstate.codey.vip/api/get_card_key.php

读取坐标

GET /api/get_coords.php
curl -s https://newstate.codey.vip/api/get_coords.php

读取当前状态

GET /api/get_status.php
curl -s https://newstate.codey.vip/api/get_status.php

上报状态(推荐每 5~10 秒一次)

POST /api/push.php
curl -s https://newstate.codey.vip/api/push.php \
  -H "Content-Type: application/json; charset=UTF-8" \
  -d '{"name":"玩家一号","server":2,"match":3,"match_id":"MCH123","x":123.456,"y":78.9,"z":5.432}'

心跳(仅查看在线/离线)

GET /api/heartbeat.php
curl -s https://newstate.codey.vip/api/heartbeat.php

读取自瞄状态

GET /api/get_aim.php
curl -s https://newstate.codey.vip/api/get_aim.php

房间 API

房间从首次创建开始计时 30 分钟后自动删除;重复上报同房间号不刷新时间。

上报房间与玩家

POST /api/room_push.php
curl -s https://newstate.codey.vip/api/room_push.php \
  -H "Content-Type: application/json" \
  -d '{"room_id":"ABC123","player_name":"玩家一号"}'

列出房间与玩家

GET /api/rooms_list.php[?q=关键字]
curl -s 'https://newstate.codey.vip/api/rooms_list.php?q=123'

C++ 示例:上报房间并打印玩家列表

适用于以 .cpp 编译的环境(如 Visual Studio)。示例向 /api/room_push.php 上报 room_idplayer_name,再解析返回并逐行打印该房间所有玩家名。
// 依赖:libcurl
// VS(MSVC)或 MinGW 均可编译,需链接 libcurl
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <curl/curl.h>

struct Buffer {
    char* data;
    size_t size;
    Buffer(): data(nullptr), size(0) {}
};

// 写回调:把响应写入可增长缓冲
static size_t write_cb(void* ptr, size_t size, size_t nmemb, void* userdata) {
    size_t total = size * nmemb;
    Buffer* buf = static_cast<Buffer*>(userdata);
    char* newp = static_cast<char*>(std::realloc(buf->data, buf->size + total + 1));
    if (!newp) return 0;
    buf->data = newp;
    std::memcpy(buf->data + buf->size, ptr, total);
    buf->size += total;
    buf->data[buf->size] = '\0';
    return total;
}

// 极简解析:从 JSON 里把 "players": ["A","B"] 打印(仅适配本接口)
static void print_players_from_json(const char* json) {
    if (!json) { std::puts("无响应"); return; }
    const char* p = std::strstr(json, "\"players\"");
    if (!p) { std::puts("未找到 players 字段"); return; }
    p = std::strchr(p, '[');
    if (!p) { std::puts("players 不是数组"); return; }
    const char* q = p; int depth = 0;
    while (*q) { if (*q=='[') depth++; else if (*q==']'){ depth--; if(!depth) break; } ++q; }
    if (!*q) { std::puts("JSON 不完整"); return; }
    const char* s = p; int idx = 1;
    while (s < q) {
        const char* a = std::strchr(s, '\"'); if (!a || a > q) break;
        const char* b = std::strchr(a+1, '\"'); if (!b || b > q) break;
        if (*(b-1) == '\\') { s = b + 1; continue; }
        size_t len = static_cast<size_t>(b - (a+1));
        char* name = static_cast<char*>(std::malloc(len + 1));
        if (!name) break;
        std::memcpy(name, a+1, len); name[len] = '\0';
        std::printf("玩家 %d:%s\n", idx++, name);
        std::free(name);
        s = b + 1;
    }
}

int main(){
    const char* url = "https://newstate.codey.vip/api/room_push.php";
    // 演示数据:替换为你的房间号与玩家名
    const char* room_id = "ABC123";
    const char* player  = "玩家一号";

    // 构造 JSON 请求体
    char json[512];
    std::snprintf(json, sizeof(json), "{\"room_id\":\"%s\",\"player_name\":\"%s\"}", room_id, player);

    CURL* curl = curl_easy_init();
    if (!curl) { std::fprintf(stderr, "初始化 curl 失败\n"); return 1; }

    struct curl_slist* headers = nullptr;
    headers = curl_slist_append(headers, "Content-Type: application/json; charset=UTF-8");

    Buffer resp;
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resp);

    CURLcode rc = curl_easy_perform(curl);
    if (rc != CURLE_OK) {
        std::fprintf(stderr, "请求失败: %s\n", curl_easy_strerror(rc));
    } else {
        std::printf("服务器返回:%s\n", resp.data ? resp.data : "(空)");
        std::puts("—— 当前房间玩家列表 ——");
        print_players_from_json(resp.data);
    }

    std::free(resp.data);
    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
    return 0;
}

最新 C 语言上报示例(含对局ID)

// 依赖:libcurl
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
static void build_json(char *buf, size_t buflen,
                       const char *name,
                       int server, int match,
                       const char *match_id,
                       double x, double y, double z) {
    snprintf(buf, buflen,
        "{\"name\":\"%s\",\"server\":%d,\"match\":%d,\"match_id\":\"%s\",\"x\":%.3f,\"y\":%.3f,\"z\":%.3f}",
        name ? name : "", server, match, match_id ? match_id : "", x, y, z);
}
int main(void){
    const char *url = "https://newstate.codey.vip/api/push.php";
    const char *player_name = "玩家一号";
    int server = 2, match = 3;
    const char *match_id = "MCH20250814A";
    double x=123.456, y=78.900, z=5.432;
    CURL *curl = curl_easy_init();
    if(!curl) return 1;
    char json[256];
    build_json(json, sizeof(json), player_name, server, match, match_id, x, y, z);
    struct curl_slist *headers=NULL;
    headers = curl_slist_append(headers, "Content-Type: application/json; charset=UTF-8");
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
    curl_easy_perform(curl);
    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
    return 0;
}