8-ball script php js ajax - script billiard php5.6 php8.0 download v. 10.10.2026

Multiplayer game 8-ball two players on the internet. Backend: json and sql. Frontend: JavaScript ES5 + Canvas 2D. The server is the state authority server (anti-cheat).


Table of Contents
  1. Screenshots
  2. Files and architecture
  3. 8-ball rules
  4. Table geometry and pockets
  5. Physics engine
  6. Controls and hit point
  7. Multiplayer — state machine and time
  8. API — complete list of actions
  9. Economy: entry fee, pool, balance
  10. Ranks and VIP calculator
  11. Admin panel
  12. Security layer
  13. Technical notes

1. Screenshots

Game screen — 8-ball table, player bar, hit point panel
Fig. 1 — Game screen. From the left: player bar above the table (avatar + login + pool), table with racked balls and the cue ball on the break line, right panel: HIT POINT (large white ball for setting spin), POTTED BALLS (order) and ROUND. Below the table, the status message "Waiting for players" and the "Sit at the table" button.
Physics engine test results — trajectories and potted ball detection
Fig. 2 — Shot engine tests (A–H). For each shot, the engine reports: pocket hit/miss, end position, end velocity, and full ball trajectory. Tested scenarios: potting into corner and middle pockets (A, F, G, H), cushion rebound (B), rolling along the cushion without dropping (C, D), and trajectory missing the pocket (E).

2. Files and architecture

File / directoryRole
index.phpRegistration, login, lobby with table list, balance, and player rank
(plik1).phpGame page: canvas, rendering, client physics, aiming, UI panels
(plik2).phpGame API: table state, sitting, shots, score validation, pools, time limits
(plik3).phpLobby API: table list with parameters, logged-in player's balance
admin.phpAdmin panel: tables (parameters), players, ranks, table preview
(plik4).phpShared security layer: domain license, session, CSRF, rate-limit, headers
stolyTable configuration (stake, min. balance, color, ball Ø, time, dimensions)
pamiecActive table game state (balls, seats, turn, phase, pool)
bazyPlayer account: user data (login + password hash), account state (balance), rank (vip)
hashAdministrator password hash (bcrypt)
logowanie/_ratelimit/Attempt counters (login/registration throttling, per IP)
<login>.pngPlayer avatar (optional, in the root directory)
bilard2.png / bilard3.pngDocumentation images (physics tests / game screenshot)
index.php login + lobby game canvas + physics api validation + authority stoly stol konta admin.php management
Fig. 3 — Flow: PHP pages → API → file storage (JSON/TXT) → admin panel.

3. 8-ball rules

Fouls (consequence: opponent gets cue ball in hand)

Game end

4. Table geometry and pockets

Physics coordinates are always in the logical system 1000×620 px (cloth from (53,53) to (947,547)); screen scaling does not change physics. Each of the 6 pockets is a guide corridor with funnel-shaped jaws — not a point. A ball in the corridor rolls down a gutter to a dark hole (radius ~25 px) and only disappears there; channel walls bounce it towards the center (no "invisible cushions").

x=260 break line x=700 triangle 0 1 2 3 4 5 diagonal pocket pairs for the black ball: 0↔4, 1↔3, 2↔5
Fig. 4 — Table geometry: cloth, 6 numbered pockets, and diagonal pocket rule for the black ball.
ElementValueNotes
Cloth (FELT)(53,53)–(947,547)area of legal ball positions
Hole centers (PHOLES)(35,35) (965,35) (500,28) (35,565) (965,565) (500,572)point where the ball actually drops
Pocket corridorwidth ~15–16 px + jaw funnel + margin +8 pxaxis along PAXIS; corners have an "apron" up to t=34
Pocket diagonals0↔4, 1↔3, 2↔5required pocket for the black ball
Cue ball placement lockPCAP + radius ≈ cueR+15forbidden to place near a pocket / on another ball

5. Physics engine (client, deterministic)

ConstantValueMeaning
SIM_DT1/240 sfixed simulation step — determinism on both clients
FRICTION0.997 / steprolling friction
RAIL_REST0.8cushion restitution coefficient
STOP_V8 px/s (scaled with Ø)ball stop threshold
MAX_SPEED1600 px/s (scaled with Ø)shot power = 1.0

6. Controls and hit point

ActionPCMobile (touch)
Aimingmouse sets direction; target line + ghost ball + rebound pathdrag sets direction and power in a single gesture ("slingshot")
Shot powerhold and pull back along the cue (forward decreases); release = shotsame as aiming
Hit pointlarge white ball in panel: top = follow, bottom = draw, sides = curve and cushion spin
Cue ball in handclick places immediatelydrag ghost and release finger to place

Server validation of cue ball position (place_cue): within cloth, not too close to a pocket, does not overlap another ball.

7. Multiplayer — state machine and time

waiting waiting for players playing phases: aim ↔ moving finished pool paid out start_game (2 players) black / walkover rematch / both players leave → reset
Fig. 5 — Table state machine.
LimitConstant / configurationConsequence
Move timeturn_time per table (5–300 s, def. 30)foul: turn + opponent gets cue ball in hand
Return to tableSEAT_TIMEOUT = 30 sseat held for 30 s; then released, in-game = walkover
Shot resultSHOT_TIMEOUT = 150 sshot expires → time foul
Heartbeatpolling get_status every ~1.2 srefreshes player's last_activity

Move time counted only after all balls stop moving (aim phase) — the timer bar appears after simulation. All state operations atomic under flock (withState) — no write race conditions.

8. API — complete list of actions

bilard_api.php?table=<id>&action=<action> (requires session; POST actions require CSRF token)

ActionMethodEffect
get_statusGETFull state: balls, seats (+rank/balance/idle), turn, phase, pool, time_left/time_limit, pending_shot, potted_order, moves/round, config (felt, ball_r, cue_r, table_w/h), caller balance and rank
test_sessionGETDiagnostics: user, userId, balance
sitPOSTTake a seat (checks min. balance, table lock, free seat)
leave_tablePOSTRelease seat; during a game = surrender (walkover)
start_gamePOSTStart when both are seated; collects entry fee, pool = 2× stake, draws breaker
place_cuePOSTPlace cue ball in hand; position validation (cloth, pockets, collisions)
shootPOSTRegister shot (angle, power, spin) → pending_shot, moving phase
shot_resultPOSTSimulation result (balls + events) → validation → new state; reported by any seated player (deterministic result)

Anti-cheat — server-side validation of shot_result

api.php?action=… (requires session)

ActionEffect
get_tablesTable list: seats, status, blind, min_balance, color, ball Ø, time, dimensions, stopped
get_balance&user=<md5>Balance — own only (or admin); userId format validation

admin.php?api=… (requires admin session; POST with CSRF token)

ActionEffect
stateDashboard: table parameters, players at tables, pool, statistics (registered / online)
playersPlayer list: login, balance, current table, rank
set_rankChange player rank (normal/silver/gold/vip)
createNew table with parameters
deleteDelete table; during an ongoing game, refund pool to seated players (half each)
toggle_stopStop/resume table; upon resumption, fresh move timer

9. Economy: entry fee, pool, balance

10. Ranks and VIP calculator

RankAssignedPrivilege
normalautomatically upon registration—
silver / goldadmin (player list)badge next to login
VIPadmindynamic % pocketing chance while aiming
VIP calculator (client, preview only): calculates the path of the targeted ball — directly, after cushion rebound, and in combination (ball knocked by the targeted one). Percentage results from the physical intersection of the path with the pocket throat, entry angle, and obstacles on the way. Calculated only for legal balls (group / any when groups not assigned). Green ≥ 50%, red below; horizontal text also in portrait mode.

11. Admin panel (admin.php)

Tables

ParameterRangeNotes
Entry fee (blind)≥ 1 currencypool = 2× stake
Min. balance≥ entry feeblocks sitting below threshold
Cloth colorHEXcloth, gutters, and shadows calculated from this color
Ball diameter18–44 pxphysics scales proportionally
Move time5–300 s"X s/move"
Table size320–1600 × 280–1400 pxtable only — round balls, UI fixed size (letterbox)

Game interface

Portrait mode (mobile): when the screen is taller than it is wide on a mobile device, the table renders rotated by −90°, fitted to the screen. Shadows/reflections compensate for rotation (lighting remains screen-oriented), labels and VIP % are counter-rotated. Always horizontal on PC.

12. Security layer

(plik6).php shared module included by every public PHP file:

13. Technical notes