diff --git a/backendcloud/backend/pom.xml b/backendcloud/backend/pom.xml index 9738650..bed35b2 100644 --- a/backendcloud/backend/pom.xml +++ b/backendcloud/backend/pom.xml @@ -12,6 +12,28 @@ com.kob.backend backend + + jar + + + + org.springframework.boot + spring-boot-maven-plugin + + + com.kob.backend.BackendApplication + + + + + repackage + + + + + + + 8 8 diff --git a/backendcloud/backend/src/main/java/com/kob/backend/config/SecurityConfig.java b/backendcloud/backend/src/main/java/com/kob/backend/config/SecurityConfig.java index 7f5e582..95180f9 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/config/SecurityConfig.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/config/SecurityConfig.java @@ -48,7 +48,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .authorizeRequests() - .antMatchers("/user/account/token/", "/user/account/register/").permitAll() + .antMatchers("/api/user/account/token/", "/api/user/account/register/").permitAll() .antMatchers("/pk/start/","/pk/receive/bot/move/").hasIpAddress("127.0.0.1") .antMatchers(HttpMethod.OPTIONS).permitAll() .anyRequest().authenticated(); diff --git a/backendcloud/backend/src/main/java/com/kob/backend/config/filter/JwtAuthenticationTokenFilter.java b/backendcloud/backend/src/main/java/com/kob/backend/config/filter/JwtAuthenticationTokenFilter.java index 670d63d..f8c8520 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/config/filter/JwtAuthenticationTokenFilter.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/config/filter/JwtAuthenticationTokenFilter.java @@ -10,7 +10,6 @@ import com.kob.backend.mapper.UserMapper; import com.kob.backend.pojo.User; import com.kob.backend.service.impl.utils.UserDetailsImpl; import com.kob.backend.utils.JwtUtil; -import com.sun.xml.internal.bind.v2.TODO; import io.jsonwebtoken.Claims; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; diff --git a/backendcloud/backend/src/main/java/com/kob/backend/consumer/WebSocketServer.java b/backendcloud/backend/src/main/java/com/kob/backend/consumer/WebSocketServer.java index 83a05dd..7923510 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/consumer/WebSocketServer.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/consumer/WebSocketServer.java @@ -46,8 +46,8 @@ public class WebSocketServer { private User user; public Game game = null; // addPlayer 添加用户到匹配池的 URL; removePlayer 从匹配池移除用户的 URL - private final static String addPlayerUrl = "http://127.0.0.1:3001/player/add/"; - private final static String removePlayerUrl = "http://127.0.0.1:3001/player/remove/"; + private final static String addPlayerUrl = "http://127.0.0.1:3002/player/add/"; + private final static String removePlayerUrl = "http://127.0.0.1:3002/player/remove/"; @Autowired public void setRestTemplate(RestTemplate restTemplate) { diff --git a/backendcloud/backend/src/main/java/com/kob/backend/consumer/utils/Game.java b/backendcloud/backend/src/main/java/com/kob/backend/consumer/utils/Game.java index a3e853d..bead1e7 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/consumer/utils/Game.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/consumer/utils/Game.java @@ -33,7 +33,7 @@ public class Game extends Thread { // 定义失败者: all(平局), A(A输), B(B输) private String loser = ""; // 传送消息给 BotRunningSystem 的链接 - private static final String addBotUrl = "http://127.0.0.1:3002/bot/add/"; + private static final String addBotUrl = "http://127.0.0.1:3003/bot/add/"; // 初始化(有参)构造函数 diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/ReceiveBotMoveController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/ReceiveBotMoveController.java index 49d416a..a7d4f3a 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/ReceiveBotMoveController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/ReceiveBotMoveController.java @@ -1,3 +1,4 @@ +// 微服务内部 api package com.kob.backend.controller.pk; import com.kob.backend.service.pk.ReceiveBotMoveService; diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/StartGameController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/StartGameController.java index 1263a2a..f692dd1 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/StartGameController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/pk/StartGameController.java @@ -1,3 +1,4 @@ +// 微服务内部 api package com.kob.backend.controller.pk; diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/ranklist/GetRankListController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/ranklist/GetRankListController.java index e9f63df..584532f 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/ranklist/GetRankListController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/ranklist/GetRankListController.java @@ -14,7 +14,7 @@ public class GetRankListController { @Autowired private GetRankListService getRankListService; - @GetMapping("/ranklist/getranklist/") + @GetMapping("/api/ranklist/getranklist/") JSONObject getRankList(@RequestParam Map data) { Integer page = Integer.parseInt(data.get("page_index")); Integer.parseInt(data.get("page_index")); diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/record/GetRecordListController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/record/GetRecordListController.java index 888bcde..59da0ba 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/record/GetRecordListController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/record/GetRecordListController.java @@ -15,7 +15,7 @@ public class GetRecordListController { private GetRecordListService getRecordListService; // 这里只需要获取,因此只需要用 get 方法(需要新建和修改数据时,使用 post 方法) - @GetMapping("/record/getlist/") + @GetMapping("/api/record/getlist/") public JSONObject getList(@RequestParam Map data) { // 解析出 page 信息 Integer page = Integer.parseInt(data.get("page_index")); diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/InfoController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/InfoController.java index e41cc7b..95e19f9 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/InfoController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/InfoController.java @@ -13,7 +13,7 @@ public class InfoController { private InfoService infoService; // 获取信息 - @GetMapping("/user/account/info/") + @GetMapping("/api/user/account/info/") public Map getInfo(){ return infoService.getInfo(); } diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/LoginController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/LoginController.java index 60acf37..39052be 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/LoginController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/LoginController.java @@ -16,7 +16,7 @@ public class LoginController { private LoginService loginService; // 登录使用 POST 请求,密文传输,更安全 - @PostMapping("/user/account/token/") + @PostMapping("/api/user/account/token/") public Map getToken(@RequestParam Map map){ String username = map.get("username"); String password = map.get("password"); diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/RegisterController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/RegisterController.java index 1ecf8dc..2e88c69 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/RegisterController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/account/RegisterController.java @@ -13,7 +13,7 @@ public class RegisterController { @Autowired private RegisterService registerService; - @PostMapping("/user/account/register/") + @PostMapping("/api/user/account/register/") public Map register(@RequestParam Map map) { String username = map.get("username"); String password = map.get("password"); diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/AddController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/AddController.java index 2a958aa..0240301 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/AddController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/AddController.java @@ -11,7 +11,7 @@ public class AddController { @Autowired private AddService addService; - @PostMapping("/user/bot/add/") + @PostMapping("/api/user/bot/add/") public Map add(@RequestParam Map data){ return addService.add(data); } diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/GetListController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/GetListController.java index 69c4848..9d278af 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/GetListController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/GetListController.java @@ -15,7 +15,7 @@ public class GetListController { @Autowired private GetListService getListService; - @GetMapping("/user/bot/getlist/") + @GetMapping("/api/user/bot/getlist/") public List getList(){ return getListService.getList(); } diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/RemoveController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/RemoveController.java index 630f709..1c9bce0 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/RemoveController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/RemoveController.java @@ -13,7 +13,7 @@ public class RemoveController { @Autowired private RemoveService removeService; - @PostMapping("/user/bot/remove/") + @PostMapping("/api/user/bot/remove/") public Map remove(@RequestParam Map data){ return removeService.remove(data); } diff --git a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/UpdateController.java b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/UpdateController.java index 8ee59e8..1351893 100644 --- a/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/UpdateController.java +++ b/backendcloud/backend/src/main/java/com/kob/backend/controller/user/bot/UpdateController.java @@ -13,7 +13,7 @@ public class UpdateController { @Autowired private UpdateService updateService; - @PostMapping("/user/bot/update/") + @PostMapping("/api/user/bot/update/") public Map update(@RequestParam Map data){ return updateService.update(data); } diff --git a/backendcloud/backend/src/main/resources/application.properties b/backendcloud/backend/src/main/resources/application.properties index 2a217c6..038f6e5 100644 --- a/backendcloud/backend/src/main/resources/application.properties +++ b/backendcloud/backend/src/main/resources/application.properties @@ -1,5 +1,5 @@ #default server port -server.port=3000 +server.port=3001 #mysql database connect profile spring.datasource.username=root diff --git a/backendcloud/backend/src/test/java/com/kob/backend/BackendApplicationTests.java b/backendcloud/backend/src/test/java/com/kob/backend/BackendApplicationTests.java deleted file mode 100644 index b7a66fd..0000000 --- a/backendcloud/backend/src/test/java/com/kob/backend/BackendApplicationTests.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.kob.backend; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; - -@SpringBootTest -class BackendApplicationTests { - -// 测试明文加密 - @Test - void contextLoads() { - PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); - System.out.println(passwordEncoder.encode("123")); - } - -} diff --git a/backendcloud/botrunningsystem/pom.xml b/backendcloud/botrunningsystem/pom.xml index 17e0917..1e03782 100644 --- a/backendcloud/botrunningsystem/pom.xml +++ b/backendcloud/botrunningsystem/pom.xml @@ -12,6 +12,28 @@ com.kob.botrunningsystem botrunningsystem + + jar + + + + org.springframework.boot + spring-boot-maven-plugin + + + com.kob.botrunningsystem.BotRunningSystemApplication + + + + + repackage + + + + + + + 8 8 diff --git a/backendcloud/botrunningsystem/src/main/java/com/kob/botrunningsystem/service/impl/utils/Consumer.java b/backendcloud/botrunningsystem/src/main/java/com/kob/botrunningsystem/service/impl/utils/Consumer.java index fc44fe1..af1d8be 100644 --- a/backendcloud/botrunningsystem/src/main/java/com/kob/botrunningsystem/service/impl/utils/Consumer.java +++ b/backendcloud/botrunningsystem/src/main/java/com/kob/botrunningsystem/service/impl/utils/Consumer.java @@ -19,7 +19,7 @@ import java.util.function.Supplier; public class Consumer extends Thread { private Bot bot; // 定义返回信息 URL - private final static String receiveBotMoveUrl = "http://127.0.0.1:3000/pk/receive/bot/move/"; + private final static String receiveBotMoveUrl = "http://127.0.0.1:3001/pk/receive/bot/move/"; //注入 RestTemplate 用于给 backend 服务发送信息 private static RestTemplate restTemplate; diff --git a/backendcloud/botrunningsystem/src/main/resources/application.properties b/backendcloud/botrunningsystem/src/main/resources/application.properties index 36f374e..4f526dd 100644 --- a/backendcloud/botrunningsystem/src/main/resources/application.properties +++ b/backendcloud/botrunningsystem/src/main/resources/application.properties @@ -1 +1 @@ -server.port=3002 \ No newline at end of file +server.port=3003 \ No newline at end of file diff --git a/backendcloud/matchingsystem/pom.xml b/backendcloud/matchingsystem/pom.xml index 4dc1bfc..b15ad7e 100644 --- a/backendcloud/matchingsystem/pom.xml +++ b/backendcloud/matchingsystem/pom.xml @@ -12,6 +12,28 @@ com.kob.matchingsystem matchingsystem + + jar + + + + org.springframework.boot + spring-boot-maven-plugin + + + com.kob.matchingsystem.MatchingSystemApplication + + + + + repackage + + + + + + + 8 8 diff --git a/backendcloud/matchingsystem/src/main/java/com/kob/matchingsystem/service/impl/utils/MatchingPool.java b/backendcloud/matchingsystem/src/main/java/com/kob/matchingsystem/service/impl/utils/MatchingPool.java index a8b284b..e956041 100644 --- a/backendcloud/matchingsystem/src/main/java/com/kob/matchingsystem/service/impl/utils/MatchingPool.java +++ b/backendcloud/matchingsystem/src/main/java/com/kob/matchingsystem/service/impl/utils/MatchingPool.java @@ -18,7 +18,7 @@ public class MatchingPool extends Thread { // 定义一个锁, Reentrant Lock 是可重入锁 private final ReentrantLock lock = new ReentrantLock(); // 定义微服务传值 URL - private static final String startGameUrl = "http://127.0.0.1:3000/pk/start/"; + private static final String startGameUrl = "http://127.0.0.1:3001/pk/start/"; // 定义 RestTemplate 用来微服务数据通信 private static RestTemplate restTemplate; @@ -27,11 +27,11 @@ public class MatchingPool extends Thread { MatchingPool.restTemplate = restTemplate; } - public void addPlayer(Integer userId, Integer rating,Integer botId) { + public void addPlayer(Integer userId, Integer rating, Integer botId) { lock.lock(); try { // 一开始匹配等待时间是 0 - playerList.add(new Player(userId, rating,botId, 0)); + playerList.add(new Player(userId, rating, botId, 0)); } finally { lock.unlock(); } @@ -65,7 +65,7 @@ public class MatchingPool extends Thread { // 判断两名玩家是否匹配 private boolean checkMatched(Player a, Player b) { - int ratingDelta = Math.abs(a.getRating() - b.getRating()); // 两名玩家的天梯积分之差 + int ratingDelta = Math.abs(a.getRating() - b.getRating()); // 两名玩家的天梯积分之差 // a b 两名玩家的等待时间最小值 // min 是两方任意一方接受等待时间就可以匹配, max 是两方都接受的匹配 int minWaitingTime = Math.min(a.getWaitingTime(), b.getWaitingTime()); @@ -79,29 +79,31 @@ public class MatchingPool extends Thread { MultiValueMap data = new LinkedMultiValueMap<>(); // 返回两名玩家的 userId 和 botId data.add("a_id", a.getUserId().toString()); - data.add("a_bot_id",a.getBotId().toString()); + data.add("a_bot_id", a.getBotId().toString()); data.add("b_id", b.getUserId().toString()); - data.add("b_bot_id",b.getBotId().toString()); + data.add("b_bot_id", b.getBotId().toString()); restTemplate.postForObject(startGameUrl, data, String.class); } // 尝试匹配所有玩家 private void matchPlayers() { - //TODO 后端调试 - System.out.println("match players: " + playerList.toString()); + // TODO 后端调试 + // System.out.println("match players: " + playerList.toString()); // havaMatched 表示玩家已经匹配过了 boolean[] haveMatched = new boolean[playerList.size()]; for (int i = 0; i < playerList.size(); i++) { - if (haveMatched[i]) continue; // 如果当前枚举到的玩家已经匹配过了,则跳过改玩家 - for (int j = i + 1; j < playerList.size(); j++) { // j 从 i+1 开始枚举 - if (haveMatched[j]) continue; + if (haveMatched[i]) + continue; // 如果当前枚举到的玩家已经匹配过了,则跳过改玩家 + for (int j = i + 1; j < playerList.size(); j++) { // j 从 i+1 开始枚举 + if (haveMatched[j]) + continue; // 如果 i 和 j 都没有匹配,则将 a 和 b 玩家取出来 Player a = playerList.get(i); Player b = playerList.get(j); // 判断 a 和 b 能否匹配:如果匹配,则将结果返回,并将 a 和 b 的位置置为 true if (checkMatched(a, b)) { haveMatched[i] = haveMatched[j] = true; // 置为已匹配 - sendResult(a, b); // 返回匹配玩家结果 + sendResult(a, b); // 返回匹配玩家结果 break; } } diff --git a/backendcloud/matchingsystem/src/main/resources/application.properties b/backendcloud/matchingsystem/src/main/resources/application.properties index 032aec6..36f374e 100644 --- a/backendcloud/matchingsystem/src/main/resources/application.properties +++ b/backendcloud/matchingsystem/src/main/resources/application.properties @@ -1 +1 @@ -server.port=3001 \ No newline at end of file +server.port=3002 \ No newline at end of file diff --git a/web/public/favicon.ico b/web/public/favicon.ico index 6432bdc..4617b4b 100644 Binary files a/web/public/favicon.ico and b/web/public/favicon.ico differ diff --git a/web/public/index.html b/web/public/index.html index 3e5a139..41e34bd 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -5,7 +5,7 @@ - <%= htmlWebpackPlugin.options.title %> + KoS