From 6880adae9608afaae1feae2703365da6602b7de6 Mon Sep 17 00:00:00 2001
From: gaohongjun <15666598496@139.com>
Date: Tue, 9 Sep 2025 14:50:09 +0800
Subject: [PATCH] init
---
.gitignore | 38 +++
.idea/.gitignore | 8 +
.idea/vcs.xml | 4 +
pom.xml | 46 +++
src/main/java/org/example/App.java | 13 +
.../org/example/QuickResponseApplication.java | 11 +
.../org/example/config/WebSocketConfig.java | 25 ++
src/main/java/org/example/model/Player.java | 40 +++
.../java/org/example/service/GameService.java | 204 ++++++++++++++
.../ws/QuickResponseWebSocketHandler.java | 61 ++++
src/main/resources/application.properties | 1 +
src/main/resources/static/index.html | 111 ++++++++
src/main/resources/static/play.html | 264 ++++++++++++++++++
13 files changed, 826 insertions(+)
create mode 100644 .gitignore
create mode 100644 .idea/.gitignore
create mode 100644 .idea/vcs.xml
create mode 100644 pom.xml
create mode 100644 src/main/java/org/example/App.java
create mode 100644 src/main/java/org/example/QuickResponseApplication.java
create mode 100644 src/main/java/org/example/config/WebSocketConfig.java
create mode 100644 src/main/java/org/example/model/Player.java
create mode 100644 src/main/java/org/example/service/GameService.java
create mode 100644 src/main/java/org/example/ws/QuickResponseWebSocketHandler.java
create mode 100644 src/main/resources/application.properties
create mode 100644 src/main/resources/static/index.html
create mode 100644 src/main/resources/static/play.html
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..d843f34
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..00e9248
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,46 @@
+
+ 4.0.0
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.2.9
+
+
+
+ org.example
+ quick_response
+ 1.0-SNAPSHOT
+ quick_response
+ Quick response buzzer app
+
+ 17
+ UTF-8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
diff --git a/src/main/java/org/example/App.java b/src/main/java/org/example/App.java
new file mode 100644
index 0000000..5f21d2e
--- /dev/null
+++ b/src/main/java/org/example/App.java
@@ -0,0 +1,13 @@
+package org.example;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/src/main/java/org/example/QuickResponseApplication.java b/src/main/java/org/example/QuickResponseApplication.java
new file mode 100644
index 0000000..45acd6d
--- /dev/null
+++ b/src/main/java/org/example/QuickResponseApplication.java
@@ -0,0 +1,11 @@
+package org.example;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class QuickResponseApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(QuickResponseApplication.class, args);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/example/config/WebSocketConfig.java b/src/main/java/org/example/config/WebSocketConfig.java
new file mode 100644
index 0000000..93ce43a
--- /dev/null
+++ b/src/main/java/org/example/config/WebSocketConfig.java
@@ -0,0 +1,25 @@
+package org.example.config;
+
+import org.example.ws.QuickResponseWebSocketHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
+import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
+
+@Configuration
+@EnableWebSocket
+public class WebSocketConfig implements WebSocketConfigurer {
+
+ private final QuickResponseWebSocketHandler handler;
+
+ @Autowired
+ public WebSocketConfig(QuickResponseWebSocketHandler handler) {
+ this.handler = handler;
+ }
+
+ @Override
+ public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
+ registry.addHandler(handler, "/ws/quick").setAllowedOrigins("*");
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/example/model/Player.java b/src/main/java/org/example/model/Player.java
new file mode 100644
index 0000000..436dbea
--- /dev/null
+++ b/src/main/java/org/example/model/Player.java
@@ -0,0 +1,40 @@
+package org.example.model;
+
+public class Player {
+ private String id;
+ private String name;
+ private boolean host;
+
+ public Player() {
+ }
+
+ public Player(String id, String name, boolean host) {
+ this.id = id;
+ this.name = name;
+ this.host = host;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isHost() {
+ return host;
+ }
+
+ public void setHost(boolean host) {
+ this.host = host;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/example/service/GameService.java b/src/main/java/org/example/service/GameService.java
new file mode 100644
index 0000000..0338800
--- /dev/null
+++ b/src/main/java/org/example/service/GameService.java
@@ -0,0 +1,204 @@
+package org.example.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.example.model.Player;
+import org.springframework.stereotype.Service;
+import org.springframework.web.socket.TextMessage;
+import org.springframework.web.socket.WebSocketSession;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.*;
+
+@Service
+public class GameService {
+ private final ObjectMapper objectMapper = new ObjectMapper();
+
+ private final Set sessions = ConcurrentHashMap.newKeySet();
+ private final Map sessionPlayers = new ConcurrentHashMap<>();
+ private final List