TamaniDamani Core 接入說明

所有遊戲共用的回報總站。遊戲把玩家的回報、匿名統計、錯誤送到這裡,從這裡拿線上資訊和設定檔;我在後台(admin.tamanidamani.com)看。

這份是給每款遊戲的開發者和它的 AI 看的:照這裡的格式送,不用改 Core。Core 沒有寫死任何一款遊戲的欄位,遊戲自己決定要送什麼,後台照原樣顯示。原文在 guide.md,AI 直接讀原文。

網址

網址做什麼誰能用
https://core.tamanidamani.com/v1/…遊戲送東西、拿東西遊戲(帶 X-Game-Key)
https://admin.tamanidamani.com後台:回報、錯誤、統計、應用程式目錄、線上資訊只有我(Cloudflare Access)
https://docs.tamanidamani.com這一頁公開

接一款新遊戲

  1. 後台的「遊戲」分頁新增一款:id 是小寫英數(例如 iconlings),會拿到一串 X-Game-Key。
  2. 把 id 和 key 寫進遊戲(key 不是祕密,只擋不是遊戲送的;真正的限制是每個 IP 每小時的次數)。
  3. 照下面接:第一次開遊戲問同意 → 匿名統計和錯誤定期送 → 設定裡放「回報問題」 → 開遊戲時讀線上資訊。
  4. 送一份測試回報,到後台確認看得到、截圖和檔案打得開,再標成「已處理」。

共通規則

同意和隱私

回報:POST /v1/<遊戲>/report

multipart/form-data。一個叫 meta 的欄位放 JSON,其餘每個欄位是一個檔案(截圖、紀錄、存檔…)。

POST https://core.tamanidamani.com/v1/iconlings/report
X-Game-Key: …
Content-Type: multipart/form-data; boundary=…

meta = {"version":"0.9.3","platform":"windows","body":"玩家打的字","contact":"選填","player":"Steam 名稱","install":"…", …}
screen_1.png = <PNG>
log.txt = <文字>
save.json = <存檔>

回應 {"ok": true, "id": "20261206-ab12cd34"}:把 id 顯示給玩家(「回報編號 …」),他之後跟我說的時候對得上。

meta 的欄位

固定的幾個(後台列表用):

key內容
version遊戲版本(含建置編號,例如 0.9.3+a1b2c3d)
platformwindows、mac、linux
body玩家打的問題(可以空)
contact玩家選填的聯絡方式
playerSteam 名稱(有的話自動帶)
install匿名安裝 id(對得上錯誤和統計)

其餘的 key 遊戲自己決定,後台每個 key 一個可以展開的區塊(summary、error、system 預設展開)。目標是只看這份回報就能很有自信地查出問題,所以下面這些能拿到的都要送:

key內容
summary遊戲自己判斷的重點:有沒有錯誤、目前的狀態、效能有沒有異常(一行一件事)
system作業系統和版本、語言和地區、CPU 型號和核心數、記憶體總量、顯示卡型號和驅動版本、繪圖 API、螢幕(數量、每個的解析度、縮放、更新率、主螢幕)、電源(有沒有接電、電量)
settings遊戲設定的全部(就是設定檔的內容)
state送出當下遊戲在做什麼:場景、畫面上有什麼、開著的面板、玩了多久
perf最近的每格時間(平均、最差、超過門檻的次數)、繪製呼叫、顯示卡記憶體、程序記憶體(工作集、私有)、目前的效能等級
errors這次開遊戲以來的錯誤和警告(訊息、堆疊、次數、第一次和最後一次的時間)
events最近的事件時間軸(最後幾百筆:玩家做了什麼、系統發生什麼,像是螢幕改變、睡眠喚醒、換前景視窗)
env跟問題有關的環境:例如桌面上有幾個圖示、幾個視窗、其他相關的程式(只送數量和種類,不送檔名)

檔案

匿名統計和錯誤:POST /v1/<遊戲>/events

application/json,一次一批。建議:開遊戲時送一次,之後每 30 分鐘送一次,關遊戲時能送就送(不等)。

{
  "install": "3f1c…(UUID)",
  "version": "0.9.3",
  "platform": "windows",
  "info": {"os": "Windows 11 26200", "gpu": "NVIDIA RTX 4070", "ram_gb": 32, "screens": 2, "lang": "zh_TW"},
  "counts": [
    {"kind": "session", "name": "start", "n": 1},
    {"kind": "feature", "name": "panel.shop", "n": 3},
    {"kind": "perf", "name": "tier.high", "n": 1}
  ],
  "errors": [
    {"sig": "a1b2c3d4", "kind": "error", "message": "Invalid call. Nonexistent function 'foo'", "sample": "堆疊和前後幾行紀錄", "n": 4}
  ],
  "apps": [
    {"app": "blender.exe", "name": "Blender 4.5", "kind": "", "auto": "modeling"},
    {"app": "steam://rungameid/730", "name": "Counter-Strike 2", "kind": "shooter", "auto": "generic"}
  ]
}

線上資訊:GET /v1/<遊戲>/info

{"ok": true, "time": 1765000000, "info": {"latest": {"version": "0.9.4", "url": "steam://…"}, "notice": {"zh_TW": "…", "en": "…"}}}

後台「線上資訊」設定,key 和值的格式遊戲自己定(值是任意 JSON)。time 是伺服器時間,可以拿來檢查玩家的時鐘是不是差很多。快取五分鐘。開遊戲時讀一次,之後每幾小時一次就夠。

設定檔:GET /v1/<遊戲>/iconmap

遊戲的線上設定檔(名字叫 iconmap 是因為第一個用到的是圖示對照表,內容是任何 JSON)。後台「線上資訊」右邊編輯,存的時候舊的會留一份。

Godot 4 範例

const CORE := "https://core.tamanidamani.com/v1/iconlings/"
const KEY := "…"

func send_events(batch: Dictionary) -> void:
	var http := HTTPRequest.new()
	http.timeout = 15.0
	add_child(http)
	http.request_completed.connect(func(result, code, _h, _b):
		http.queue_free()
		if result != HTTPRequest.RESULT_SUCCESS or code != 200:
			_keep_for_later(batch))
	http.request(CORE + "events", ["Content-Type: application/json", "X-Game-Key: " + KEY],
		HTTPClient.METHOD_POST, JSON.stringify(batch))

# 回報:multipart 自己拼(PackedByteArray,檔案原樣放進去)
func send_report(meta: Dictionary, files: Dictionary) -> void:  # files:檔名 → PackedByteArray
	var b := "----core" + str(randi())
	var body := PackedByteArray()
	var part := func(head: String, data: PackedByteArray):
		body.append_array(("--%s\r\n%s\r\n\r\n" % [b, head]).to_utf8_buffer())
		body.append_array(data)
		body.append_array("\r\n".to_utf8_buffer())
	part.call('Content-Disposition: form-data; name="meta"\r\nContent-Type: application/json', JSON.stringify(meta).to_utf8_buffer())
	for n in files:
		var type := "image/png" if n.ends_with(".png") else "application/octet-stream" if n.ends_with(".zip") else "text/plain"
		part.call('Content-Disposition: form-data; name="%s"; filename="%s"\r\nContent-Type: %s' % [n, n, type], files[n])
	body.append_array(("--%s--\r\n" % b).to_utf8_buffer())
	var http := HTTPRequest.new()
	http.timeout = 60.0
	add_child(http)
	http.request_completed.connect(func(result, code, _h, data):
		http.queue_free()
		var j = JSON.parse_string(data.get_string_from_utf8()) if result == HTTPRequest.RESULT_SUCCESS else null
		_report_done(code == 200 and j is Dictionary and j.get("ok", false), j.get("id", "") if j is Dictionary else ""))
	http.request_raw(CORE + "report", ["Content-Type: multipart/form-data; boundary=" + b, "X-Game-Key: " + KEY],
		HTTPClient.METHOD_POST, body)

抓錯誤:Godot 4.5 起有 OS.add_logger(Logger),覆寫 _log_error(有腳本的堆疊)和 _log_message;在裡面只記到記憶體的佇列(logger 可能在別的執行緒被叫),主執行緒定期整理成 errors。完整的做法看桌布小小人的 godot/app/core/。

Unity 範例

const string CORE = "https://core.tamanidamani.com/v1/mygame/";
const string KEY = "…";

IEnumerator SendEvents(string json) {
    using var req = new UnityWebRequest(CORE + "events", "POST");
    req.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(json));
    req.downloadHandler = new DownloadHandlerBuffer();
    req.SetRequestHeader("Content-Type", "application/json");
    req.SetRequestHeader("X-Game-Key", KEY);
    req.timeout = 15;
    yield return req.SendWebRequest();
    if (req.result != UnityWebRequest.Result.Success) KeepForLater(json);
}

IEnumerator SendReport(string metaJson, Dictionary<string, byte[]> files) {
    var form = new List<IMultipartFormSection> { new MultipartFormDataSection("meta", metaJson, "application/json") };
    foreach (var f in files) form.Add(new MultipartFormFileSection(f.Key, f.Value, f.Key, f.Key.EndsWith(".png") ? "image/png" : "application/octet-stream"));
    using var req = UnityWebRequest.Post(CORE + "report", form);
    req.SetRequestHeader("X-Game-Key", KEY);
    req.timeout = 60;
    yield return req.SendWebRequest();
    // 成功:JsonUtility 讀出 id 顯示給玩家
}

抓錯誤:Application.logMessageReceivedThreaded(可能在別的執行緒),LogType.Exception/Error/Assert 進 errors;stackTrace 放 sample。

本機工具(只有我用)

在 Core 的資料夾:

改 Core 本身