Skip to content
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
2 changes: 1 addition & 1 deletion backend/game/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

SCREEN_HEIGHT = 750
SCREEN_WIDTH = 1250
MAX_SCORE = 150
MAX_SCORE = 25


class GameState:
Expand Down
10 changes: 6 additions & 4 deletions backend/game/matchingConsumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

SCREEN_HEIGHT = 750
SCREEN_WIDTH = 1250
MAX_SCORE = 10
MAX_SCORE = 25


@sync_to_async
Expand All @@ -41,6 +41,7 @@ def get_user_nicknames(user1, user2):
class MatchingGameState:
async def initialize(self, user1, user2):
try:
self.game_state = 0 # 0: in game, 1: game over
self.user = [user1, user2]
self.user_authenticated = [False, False]
self.map = GameMap()
Expand Down Expand Up @@ -173,9 +174,9 @@ async def disconnect(self, close_code):
# 누가 남았는지 판별 (내가 0이라면 1이 승자, 내가 1이라면 0이 승자)
winner_index = 1 - self.user_index
state = MatchingGameConsumer.game_states[self.room_group_name]

# send_game_result를 통해 DB에 게임결과 저장 및
# 나머지(승자)에게 게임 종료 메시지 전송
if (state.game_state != 0):
return
await asyncio.sleep(0.1)
await self.send_game_result(winner_index)
await asyncio.sleep(0.1)
await self.close()
Expand Down Expand Up @@ -266,6 +267,7 @@ async def game_loop(self):

async def send_game_result(self, winner):
state = MatchingGameConsumer.game_states[self.room_group_name]
state.game_state = 1

print("Game result for", self.room_group_name, ":", state.score, "Winner:", winner)
await self.save_game_result(state, winner)
Expand Down
4 changes: 2 additions & 2 deletions backend/transcendence/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# DEBUG = True

ALLOWED_HOSTS = []

Expand Down Expand Up @@ -100,7 +100,7 @@ def custom_exception_handler(exc, context):
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

CORS_ORIGIN_ALLOW_ALL = True # TEST: 모든 도메인 허용 (보안 취약)
# CORS_ORIGIN_ALLOW_ALL = True # TEST: 모든 도메인 허용 (보안 취약)

CSRF_TRUSTED_ORIGINS = [
"https://localhost:443",
Expand Down
1 change: 1 addition & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Phong</title>
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="#">
</head>
<body>
<div id="app"></div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/2FA.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class TwoFA extends Component {
}
})
.catch(error => {
console.error('Error:', error);
// console.error('Error:', error);
});
});
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/Edit-Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class EditProfile extends Component {
this.state.is_2FA = data.is_2FA;
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
return { nickname: this.nickname, img_url: this.img_url, is_2FA: this.is_2FA };
Expand Down Expand Up @@ -186,7 +186,7 @@ export class EditProfile extends Component {
else throw new Error('Network response was not ok');
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
});
Expand Down Expand Up @@ -215,15 +215,15 @@ export class EditProfile extends Component {
if (response.ok) {
return response.json();
} else {
console.error('Failed to update profile. Status:', response.status);
// console.error('Failed to update profile. Status:', response.status);
throw new Error('Failed to update profile');
}
})
.then(result => {
changeUrl(`/main/profile/${this.props.uid}/edit`);
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
});
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/Friends-List.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class FriendsList extends Component {
{ className: "fList", ids: friendIdList, contents: friendNicknameList }));
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
}
Expand Down Expand Up @@ -144,22 +144,22 @@ export class FriendsList extends Component {
if (part.length !== 2)
{
// 올바르지 않은 입력입니다!
console.log("invalid input!");
// console.log("invalid input!");
return ;
}
const nickname = part[0];
const uid = parseInt(part[1]);

if (!this.users)
{
console.log("user is not loaded!");
// console.log("user is not loaded!");
return ;
}
const isFriend = this.friends.find(friend => friend.user_id === uid);
const isUser = this.users.find(user => user.user_id === uid);
if (isFriend || !isUser || isUser.nickname !== nickname)
{
console.log("invalid input!");
// console.log("invalid input!");
}
else
{
Expand All @@ -179,7 +179,7 @@ export class FriendsList extends Component {
changeUrl(window.location.pathname);
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
}
Expand Down Expand Up @@ -229,7 +229,7 @@ export class FriendsList extends Component {
});
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
})
Expand Down Expand Up @@ -263,7 +263,7 @@ export class FriendsList extends Component {
changeUrl(window.location.pathname);
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
});
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Game-Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export class GameCore extends Component {
let counter = 0;
let leftBar, rightBar, leftBall, rightBall, map, score, penaltyTime = [0, 0];

console.log(canvas)
// console.log(canvas)
function playSound(soundName) {
var sound = sounds[soundName];
if (sound) {
sound.currentTime = 0;
sound.play().catch(function (error) {
console.log('Autoplay was prevented:', error);
// console.log('Autoplay was prevented:', error);
});
}
}
Expand Down Expand Up @@ -420,7 +420,7 @@ export class GameCore extends Component {
rightBall = new Ball(data.right_ball_x, data.right_ball_y, BALL_RADIUS, BALL_COLOR[1]);
score = new Score();

console.log(SCREEN_HEIGHT, SCREEN_WIDTH, BAR_HEIGHT, BAR_WIDTH, BALL_RADIUS);
// console.log(SCREEN_HEIGHT, SCREEN_WIDTH, BAR_HEIGHT, BAR_WIDTH, BALL_RADIUS);
setInterval(interpolate, 3);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Game-Result-Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class GameResultPage extends Component {
}
})
.catch(error => {
console.error("Error sending tournament results:", error);
// console.error("Error sending tournament results:", error);
changeUrl("/");
});
changeUrl("/main/tournament");
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/Game-Tournament-Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export class GameTournamentCore extends Component {
let counter = 0;
let leftBar, rightBar, leftBall, rightBall, map, score, penaltyTime = [0, 0];

console.log(canvas)
// console.log(canvas)
function playSound(soundName) {
var sound = sounds[soundName];
if (sound) {
sound.currentTime = 0;
sound.play().catch(function (error) {
console.log('Autoplay was prevented:', error);
// console.log('Autoplay was prevented:', error);
});
}
}
Expand Down Expand Up @@ -336,8 +336,8 @@ export class GameTournamentCore extends Component {
} else if (data.type === 'game_result') {
this.gameSocket.close();
socketList.pop();
console.log("winner!!");
console.log(data.winner);
// console.log("winner!!");
// console.log(data.winner);
const winner = data.winner === 0 ? this.props.player1 : this.props.player2;
const loser = data.winner === 0 ? this.props.player2 : this.props.player1;
if (this.props.game === 1) {
Expand Down Expand Up @@ -437,7 +437,7 @@ export class GameTournamentCore extends Component {
rightBall = new Ball(data.right_ball_x, data.right_ball_y, BALL_RADIUS, BALL_COLOR[1]);
score = new Score();

console.log(SCREEN_HEIGHT, SCREEN_WIDTH, BAR_HEIGHT, BAR_WIDTH, BALL_RADIUS);
// console.log(SCREEN_HEIGHT, SCREEN_WIDTH, BAR_HEIGHT, BAR_WIDTH, BALL_RADIUS);
setInterval(interpolate, 3);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Game-Tournament.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class GameTournament extends GameDefault {
} else {
changeUrl("/main/tournament");
}
console.log(this.props);
// console.log(this.props);
new GameTournamentCore(document.querySelector("div#game"), this.props);
}
}
5 changes: 2 additions & 3 deletions frontend/src/components/Game-matching-Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export class GameMatchingCore extends Component {
let counter = 0;
let leftBar, rightBar, leftBall, rightBall, map, score, penaltyTime = [0, 0];

console.log(canvas)
// console.log(canvas)
function playSound(soundName) {
var sound = sounds[soundName];
if (sound) {
sound.currentTime = 0;
sound.play().catch(function (error) {
console.log('Autoplay was prevented:', error);
});
}
}
Expand Down Expand Up @@ -420,7 +419,7 @@ export class GameMatchingCore extends Component {
rightBall = new Ball(data.right_ball_x, data.right_ball_y, BALL_RADIUS, BALL_COLOR[1]);
score = new Score();

console.log(SCREEN_HEIGHT, SCREEN_WIDTH, BAR_HEIGHT, BAR_WIDTH, BALL_RADIUS);
// console.log(SCREEN_HEIGHT, SCREEN_WIDTH, BAR_HEIGHT, BAR_WIDTH, BALL_RADIUS);
setInterval(interpolate, 3);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component } from "../core/Component.js";
export class Input extends Component {

template () {
console.log(this.props.searchText);
// console.log(this.props.searchText);
return `
<div id="inputBox">
<input type="text" id="${this.props.inputId}" required autocomplete="off" placeholder="${this.props.searchText}">
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Main-Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Menu extends Component {
}
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});
changeUrl("/main");
Expand Down Expand Up @@ -125,7 +125,7 @@ export class Menu extends Component {
else throw new Error('Network response was not ok');
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
location.reload(true);
});
});
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/Match-Wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ export class WaitForMatch extends Component {
initState() {
if (socketList[0] !== undefined) {
setTimeout(() => {
console.log("send enter-matching");
if (window.location.pathname !== "/main/matching") {
// console.log("cancel enter-matching");
return;
}
// console.log("send enter-matching");
socketList[0].send(JSON.stringify({ 'action': 'enter-matching' }));
socketList[0].onmessage = (e) => {
const data = JSON.parse(e.data);
console.log(data);
// console.log(data);
if (data.action === 'start_game') {
console.log("start game on " + data.room_name);
// console.log("start game on " + data.room_name);
changeUrl('/game/vs/' + data.room_name);
}
};
Expand Down Expand Up @@ -71,15 +75,15 @@ export class WaitForMatch extends Component {

setEvent() {
this.addEvent('click', '#goBack', (event) => {
console.log("send leave-matching");
// console.log("send leave-matching");
if (socketList[0] !== undefined)
socketList[0].send(JSON.stringify({ 'action': 'leave-matching' }));
window.removeEventListener('popstate', handleSocketClose);
changeUrl("/main", false);
});

const handleSocketClose = (e) => {
console.log("send leave-matching");
// console.log("send leave-matching");
if (socketList[0] !== undefined)
socketList[0].send(JSON.stringify({ 'action': 'leave-matching' }));
window.removeEventListener('popstate', handleSocketClose);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Profile-Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ProfileInfo extends Component {
}

initState() {
console.log(this.props.lan.value);
// console.log(this.props.lan.value);
const payload = parseJWT();
if (!payload) this.uid = null;
else this.uid = payload.id;
Expand All @@ -63,7 +63,7 @@ x } else {
Math.round((data.user.win / (data.user.lose + data.user.win)) * 100);
})
.catch(error => {
console.error('Fetch error:', error);
// console.error('Fetch error:', error);
changeUrl("/");
});

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/Tournament-History.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ export class TournamentHistory extends Component {

setEvent(){
this.addEvent('click', '#tournament-prev-button', (event) => {
console.log("prev");
console.log(this.state.idx);
// console.log("prev");
// console.log(this.state.idx);
if (this.state.idx > 0) this.state.idx--;
console.log(this.state.idx);
// console.log(this.state.idx);
});

this.addEvent('click', '#tournament-next-button', (event) => {
console.log("next");
console.log(this.state.idx);
// console.log("next");
// console.log(this.state.idx);
if (this.state.idx < this.size) this.state.idx++;
console.log(this.state.idx);
// console.log(this.state.idx);
});
}
}
Loading