Skip to content

Commit ab4c141

Browse files
committed
refactor(client): 게임 타이머 값 config.h 에서 불러오게 수정 및 불필요한 로그 메시지 제거
1 parent a8aeea5 commit ab4c141

File tree

6 files changed

+15
-51
lines changed

6 files changed

+15
-51
lines changed

client/game_state.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string.h>
77
#include <time.h>
88

9+
#include "config.h"
910
#include "logger.h" // LOG_DEBUG 함수를 위해 추가
1011
#include "piece.h"
1112
#include "types.h"
@@ -31,14 +32,14 @@ void init_game_state(game_state_t *state) {
3132
state->local_team = TEAM_WHITE;
3233
state->game_in_progress = false;
3334
state->game_start_time = 0;
34-
state->white_time_remaining = 600; // 10분
35-
state->black_time_remaining = 600; // 10분
35+
state->white_time_remaining = DEFAULT_GAME_TIME_LIMIT; // 10분
36+
state->black_time_remaining = DEFAULT_GAME_TIME_LIMIT; // 10분
3637
state->opponent_disconnected = false;
3738

3839
// 실시간 타이머 필드 초기화
3940
state->last_timer_update = 0;
40-
state->white_time_at_last_sync = 600;
41-
state->black_time_at_last_sync = 600;
41+
state->white_time_at_last_sync = DEFAULT_GAME_TIME_LIMIT;
42+
state->black_time_at_last_sync = DEFAULT_GAME_TIME_LIMIT;
4243

4344
// 체크 상태 초기화
4445
state->white_in_check = false;

client/handlers/match.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <time.h>
55

66
#include "../client_state.h"
7+
#include "../config.h"
78
#include "../game_state.h"
89
#include "handlers.h"
910
#include "logger.h"
@@ -20,7 +21,6 @@ int handle_match_game_response(ServerMessage *msg) {
2021
// 아직 매칭 대기 중
2122
LOG_INFO("Added to matchmaking queue. Game ID: %s",
2223
msg->match_game_res->game_id ? msg->match_game_res->game_id : "unknown");
23-
add_chat_message_safe("System", "Waiting for opponent...");
2424
} else {
2525
// 매칭 성공! 게임 시작
2626
LOG_INFO("Match found! Game ID: %s, Assigned team: %s",
@@ -72,9 +72,9 @@ int handle_match_game_response(ServerMessage *msg) {
7272
client->game_state.black_time_remaining);
7373
} else {
7474
// 기본값 (10분)
75-
client->game_state.white_time_remaining = 600;
76-
client->game_state.black_time_remaining = 600;
77-
LOG_INFO("Timer initialized with default values: 600 seconds each");
75+
client->game_state.white_time_remaining = DEFAULT_GAME_TIME_LIMIT;
76+
client->game_state.black_time_remaining = DEFAULT_GAME_TIME_LIMIT;
77+
LOG_INFO("Timer initialized with default values: %d seconds each", DEFAULT_GAME_TIME_LIMIT);
7878
}
7979

8080
// 게임 시작 시간 설정 (서버에서 받은 시간이 있으면 사용)

client/handlers/move.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,12 @@ int handle_move_response(ServerMessage *msg) {
5353
result->message ? result->message : "");
5454

5555
if (result->success) {
56-
// 성공적인 이동
57-
char chat_msg[256];
58-
snprintf(chat_msg, sizeof(chat_msg), "Move successful: %s",
59-
result->message ? result->message : "");
60-
add_chat_message_safe("System", chat_msg);
61-
62-
// TODO: 게임 상태 업데이트 (FEN 파싱 등)
63-
if (result->updated_fen) {
64-
LOG_DEBUG("Updated FEN: %s", result->updated_fen);
65-
}
66-
6756
// 화면 업데이트 요청
6857
client_state_t *client = get_client_state();
6958
pthread_mutex_lock(&screen_mutex);
7059
client->screen_update_requested = true;
7160
pthread_mutex_unlock(&screen_mutex);
7261

73-
// UI는 자동으로 새로고침됩니다
74-
7562
} else {
7663
// 실패한 이동
7764
char error_msg[256];

client/ui/input.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,6 @@ void handle_board_click(int board_x, int board_y) {
109109
// 현재 플레이어의 기물인지 확인
110110
team_t piece_team = piece->team;
111111

112-
// 좌표 확인 메시지 (간단하게)
113-
char coord_msg[64];
114-
snprintf(coord_msg, sizeof(coord_msg), "Selected: %c%d (board[%d][%d])",
115-
'a' + board_x, board_y + 1, board_y, board_x);
116-
117-
// 뮤텍스 잠금을 해제한 후 채팅 메시지 추가 (데드락 방지)
118-
pthread_mutex_unlock(&screen_mutex);
119-
add_chat_message_safe("System", coord_msg);
120-
121-
// 뮤텍스 다시 잠금
122-
pthread_mutex_lock(&screen_mutex);
123-
124112
// 현재 턴인지 확인
125113
if (game->side_to_move != client->game_state.local_team) {
126114
char turn_msg[128];
@@ -184,10 +172,6 @@ void handle_board_click(int board_x, int board_y) {
184172

185173
// 서버로 이동 요청 전송
186174
if (send_move_request(from_coord, to_coord) == 0) {
187-
char move_msg[64];
188-
snprintf(move_msg, sizeof(move_msg), "Move request sent: %s -> %s", from_coord, to_coord);
189-
add_chat_message_safe("System", move_msg);
190-
191175
// 뮤텍스 다시 잠금하여 상태 변경
192176
pthread_mutex_lock(&screen_mutex);
193177
client->piece_selected = false;
@@ -221,12 +205,6 @@ void handle_mouse_input(MEVENT *event) {
221205
if (client->current_screen == SCREEN_GAME) {
222206
int board_x, board_y;
223207
if (coord_to_board_pos(event->x, event->y, &board_x, &board_y)) {
224-
// 마우스 좌표 변환 디버그
225-
char mouse_debug[256];
226-
snprintf(mouse_debug, sizeof(mouse_debug), "마우스 클릭: 화면(%d,%d) -> 보드(%d,%d)",
227-
event->x, event->y, board_x, board_y);
228-
add_chat_message_safe("System", mouse_debug);
229-
230208
handle_board_click(board_x, board_y);
231209
}
232210
}
@@ -409,9 +387,6 @@ bool handle_chess_notation(const char *notation) {
409387
to_coord[2] = '\0';
410388

411389
if (send_move_request(from_coord, to_coord) == 0) {
412-
char move_msg[64];
413-
snprintf(move_msg, sizeof(move_msg), "Move request sent: %s", notation);
414-
add_chat_message_safe("System", move_msg);
415390
return true;
416391
} else {
417392
add_chat_message_safe("System", "Failed to send move request.");

common/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ typedef struct {
3232
#define DEFAULT_CONNECTION_TIMEOUT 10
3333

3434
// 기본 게임 설정
35-
#define DEFAULT_GAME_TIME_LIMIT 600 // 10분
35+
#define DEFAULT_GAME_TIME_LIMIT 10 // 10분
3636
#define DEFAULT_MAX_CHAT_MESSAGES 50
3737
#define DEFAULT_CHAT_MESSAGE_LENGTH 256
3838

server/match_manager.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string.h>
77
#include <unistd.h>
88

9+
#include "config.h"
910
#include "logger.h"
1011
#include "network.h"
1112
#include "utils.h" // 체스판 초기화를 위해 추가
@@ -94,10 +95,10 @@ MatchResult add_player_to_matching(int fd, const char *player_id) {
9495
// 체스판 초기화 (표준 시작 위치)
9596
init_startpos(&game->game_state);
9697

97-
// 타이머 설정 (기본 10분 = 600초)
98-
game->time_limit_per_player = 600; // 10분
99-
game->white_time_remaining = 600;
100-
game->black_time_remaining = 600;
98+
// 타이머 설정
99+
game->time_limit_per_player = DEFAULT_GAME_TIME_LIMIT;
100+
game->white_time_remaining = DEFAULT_GAME_TIME_LIMIT;
101+
game->black_time_remaining = DEFAULT_GAME_TIME_LIMIT;
101102
game->last_move_time = game->game_start_time;
102103

103104
if (current_is_white) {

0 commit comments

Comments
 (0)