extremely claude-assisted go game based on atproto! working on cleaning up and giving a more unique design, still has a bit of a slop vibe to it.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Sync ATProto game record when player two joins

- Join endpoint now updates D1 with player_two and status='active'
- Move endpoint syncs ATProto game record with D1 when game owner makes a move
(adds playerTwo and updates status if ATProto record is out of sync)
- Pass endpoint has same sync logic for game owner

This ensures the ATProto game record reflects the actual game state.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

+97
+13
src/routes/api/games/[id]/join/+server.ts
··· 1 1 import { json, error } from '@sveltejs/kit'; 2 2 import type { RequestHandler } from './$types'; 3 3 import { getSession, getAgent } from '$lib/server/auth'; 4 + import { getDb } from '$lib/server/db'; 4 5 5 6 function generateTid(): string { 6 7 const timestamp = Date.now() * 1000; ··· 87 88 if (!result.ok) { 88 89 throw new Error(`Failed to create action record: ${result.data.message}`); 89 90 } 91 + 92 + // Update D1 index with player_two and status 93 + const db = getDb(event.platform); 94 + await db 95 + .updateTable('games') 96 + .set({ 97 + player_two: session.did, 98 + status: 'active', 99 + updated_at: now, 100 + }) 101 + .where('rkey', '=', rkey) 102 + .execute(); 90 103 91 104 return json({ success: true, uri: result.data.uri }); 92 105 } catch (err) {
+44
src/routes/api/games/[id]/move/+server.ts
··· 105 105 .where('rkey', '=', rkey) 106 106 .execute(); 107 107 108 + // If this is the game owner (player_one) and there's a player_two in D1, 109 + // update the ATProto game record to include playerTwo and status 110 + if (session.did === game.creator_did && game.player_two) { 111 + try { 112 + // Fetch current game record from ATProto 113 + const gameRecordResponse = await (agent as any).get('com.atproto.repo.getRecord', { 114 + params: { 115 + repo: game.creator_did, 116 + collection: 'boo.sky.go.game', 117 + rkey: game.rkey, 118 + }, 119 + }); 120 + 121 + if (gameRecordResponse.ok) { 122 + const currentRecord = gameRecordResponse.data.value; 123 + 124 + // Check if update is needed 125 + const needsUpdate = !currentRecord.playerTwo || currentRecord.status === 'waiting'; 126 + 127 + if (needsUpdate) { 128 + const updatedRecord = { 129 + ...currentRecord, 130 + playerTwo: game.player_two, 131 + status: 'active', 132 + }; 133 + 134 + await (agent as any).post('com.atproto.repo.putRecord', { 135 + input: { 136 + repo: game.creator_did, 137 + collection: 'boo.sky.go.game', 138 + rkey: game.rkey, 139 + record: updatedRecord, 140 + }, 141 + }); 142 + 143 + console.log('[move] Updated game record with playerTwo:', game.player_two); 144 + } 145 + } 146 + } catch (syncErr) { 147 + // Log but don't fail the move if sync fails 148 + console.error('[move] Failed to sync game record:', syncErr); 149 + } 150 + } 151 + 108 152 return json({ success: true, uri: result.data.uri }); 109 153 } catch (err) { 110 154 console.error('Failed to record move:', err);
+40
src/routes/api/games/[id]/pass/+server.ts
··· 99 99 .where('rkey', '=', rkey) 100 100 .execute(); 101 101 102 + // If this is the game owner and there's a player_two in D1, 103 + // sync the ATProto game record if needed 104 + if (session.did === game.creator_did && game.player_two && !isConsecutivePass) { 105 + try { 106 + const gameRecordResponse = await (agent as any).get('com.atproto.repo.getRecord', { 107 + params: { 108 + repo: game.creator_did, 109 + collection: 'boo.sky.go.game', 110 + rkey: game.rkey, 111 + }, 112 + }); 113 + 114 + if (gameRecordResponse.ok) { 115 + const currentRecord = gameRecordResponse.data.value; 116 + const needsUpdate = !currentRecord.playerTwo || currentRecord.status === 'waiting'; 117 + 118 + if (needsUpdate) { 119 + const updatedRecord = { 120 + ...currentRecord, 121 + playerTwo: game.player_two, 122 + status: 'active', 123 + }; 124 + 125 + await (agent as any).post('com.atproto.repo.putRecord', { 126 + input: { 127 + repo: game.creator_did, 128 + collection: 'boo.sky.go.game', 129 + rkey: game.rkey, 130 + record: updatedRecord, 131 + }, 132 + }); 133 + 134 + console.log('[pass] Updated game record with playerTwo:', game.player_two); 135 + } 136 + } 137 + } catch (syncErr) { 138 + console.error('[pass] Failed to sync game record:', syncErr); 139 + } 140 + } 141 + 102 142 if (isConsecutivePass) { 103 143 // Two consecutive passes — game over 104 144 // Extract creator DID from AT URI to update the correct repo