Skip to content

spielinfos zum Start #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/client/src/component/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,21 @@ export const Chat = ({chatId, className}) => {
message.user ? (
<span>{message.user + ": " + message.message}</span>
) : (
<span className="italic text-gray-400">{message.message}</span>
message.type ? (
<>
<table className="table-fixed italic text-gray-400">
<th>Spiel gestartet</th>
{Object.keys(message.pair).map((key, i) => (
<tr key={i}>
<td>{key}</td>
<td>{message.pair[key]}</td>
</tr>
))}
</table>
</>
) : (
<span className="italic text-gray-400">{message.message}</span>
)
)}
</p>
))}
Expand Down
1 change: 0 additions & 1 deletion src/main/client/src/feature/game/GamePanel.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
useCallback,
useContext,
useEffect,
} from "react"
import {
useParams,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bernd/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ChatWithUsers getChat(@PathVariable String id) {
public void sendChat(ChatRequest chatRequest, Principal principal) {
String user = Auth.getPrincipal(principal);
Chat chat = chats.get(chatRequest.id());
ChatMessage message = new ChatMessage(chat.counter().getAndIncrement(), chatRequest.message(), user);
ChatMessage message = new ChatMessage(chat.counter().getAndIncrement(), chatRequest.message(), user, false, null);
chat.messages().add(message);
roomManager.updateRooms(user, chat.id());
operations.convertAndSend("/topic/chat/" + chat.id(), message);
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/bernd/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import com.bernd.model.ActiveGame;
import com.bernd.model.Chat;
import com.bernd.model.ChatMessage;
import com.bernd.model.ChatRequest;
import com.bernd.model.Game;
import com.bernd.model.Move;
import com.bernd.model.OpenGame;
import com.bernd.model.ViewGame;
import com.bernd.util.Auth;
import com.bernd.util.RandomString;
import java.util.HashMap;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.core.MessageSendingOperations;
Expand Down Expand Up @@ -88,7 +87,7 @@ public void action(Move move, Principal p) {
Move lastMove = game.getLastMove();
if (lastMove.end()) {
Chat chat = chats.get(game.id());
ChatMessage message = new ChatMessage(chat.counter().getAndIncrement(), game.getScore(), null);
ChatMessage message = new ChatMessage(chat.counter().getAndIncrement(), game.getScore(), null, false, null);
chat.messages().add(message);
operations.convertAndSend("/topic/chat/" + chat.id(), message);
}
Expand Down Expand Up @@ -136,6 +135,15 @@ public ResponseEntity<?> accept(@RequestBody AcceptRequest acceptRequest) {
OpenGame openGame = openGames.remove(acceptRequest.game().user());
Game fullGame = games.put(openGame.accept(principal, acceptRequest));
activeGames.put(ActiveGame.fromGame(fullGame));
Chat chat = chats.get(openGame.id());

HashMap<String, String> spielwerte = new HashMap<>();
spielwerte.put("Handicap", Integer.toString(fullGame.handicap()));
spielwerte.put("Black", fullGame.black());
spielwerte.put("White", fullGame.white());
ChatMessage typeMessage = new ChatMessage(chat.counter().getAndIncrement(), "", null,true, spielwerte);
chat.messages().add(typeMessage);
operations.convertAndSend("/topic/chat/" + chat.id(), typeMessage);
operations.convertAndSend("/topic/game/" + fullGame.id(), fullGame.toView());
operations.convertAndSend("/topic/lobby/open_games", openGames.games());
operations.convertAndSend("/topic/lobby/active_games", activeGames.games());
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/bernd/model/ChatMessage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.bernd.model;

import java.util.HashMap;

public record ChatMessage(
int n,
String message,
String user) {
String user,
boolean type,
HashMap<String, String> pair) {
}
Loading