Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-server-flip-jump
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Gia Vương
game-server-flip-jump
Commits
7cd5247d
Commit
7cd5247d
authored
Aug 16, 2025
by
Vũ Gia Vương
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix disconnect
parent
2cc5435c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
16 deletions
+12
-16
networkCtrl.ts
src/Controller/networkCtrl.ts
+1
-0
User.ts
src/Model/User.ts
+2
-2
socket.ts
src/socket.ts
+9
-14
No files found.
src/Controller/networkCtrl.ts
View file @
7cd5247d
...
@@ -50,6 +50,7 @@ export async function endGameApi(user: User) {
...
@@ -50,6 +50,7 @@ export async function endGameApi(user: User) {
gameLevel
:
user
.
towerNumber
-
1
,
gameLevel
:
user
.
towerNumber
-
1
,
details
details
}
}
console
.
log
(
'END GAME'
);
const
res
=
await
callApi
(
URL_END_GAME
,
'POST'
,
params
);
const
res
=
await
callApi
(
URL_END_GAME
,
'POST'
,
params
);
return
res
;
return
res
;
...
...
src/Model/User.ts
View file @
7cd5247d
...
@@ -17,7 +17,7 @@ class User {
...
@@ -17,7 +17,7 @@ class User {
public
position
:
v2
=
new
v2
(
0
,
0
);
public
position
:
v2
=
new
v2
(
0
,
0
);
public
timeStart
:
number
=
0
;
public
timeStart
:
number
=
0
;
public
is
End
Game
:
boolean
=
true
;
public
is
Start
Game
:
boolean
=
true
;
public
history
:
History
[]
=
[];
public
history
:
History
[]
=
[];
constructor
(
token
:
string
,
id
:
string
)
{
constructor
(
token
:
string
,
id
:
string
)
{
...
@@ -30,7 +30,7 @@ class User {
...
@@ -30,7 +30,7 @@ class User {
this
.
score
=
0
;
this
.
score
=
0
;
this
.
totalScore
=
0
;
this
.
totalScore
=
0
;
this
.
combo
=
0
;
this
.
combo
=
0
;
this
.
is
EndGame
=
tru
e
;
this
.
is
StartGame
=
fals
e
;
this
.
history
=
[];
this
.
history
=
[];
this
.
timeStart
=
0
;
this
.
timeStart
=
0
;
this
.
towerNumber
=
0
;
this
.
towerNumber
=
0
;
...
...
src/socket.ts
View file @
7cd5247d
...
@@ -54,12 +54,8 @@ export function setupSocket(io: Server) {
...
@@ -54,12 +54,8 @@ export function setupSocket(io: Server) {
async
function
endGame
(
socket
:
Socket
)
{
async
function
endGame
(
socket
:
Socket
)
{
try
{
try
{
const
user
=
getUserBySocket
(
socket
);
const
user
=
getUserBySocket
(
socket
);
user
.
reset
();
await
endGameApi
(
user
);
users
.
delete
(
user
.
id
);
if
(
user
?.
isEndGame
)
{
return
;
}
endGameApi
(
user
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'error'
,
error
)
console
.
log
(
'error'
,
error
)
}
}
...
@@ -67,7 +63,7 @@ async function endGame(socket: Socket) {
...
@@ -67,7 +63,7 @@ async function endGame(socket: Socket) {
function
onDisconnect
(
socket
:
Socket
):
void
{
function
onDisconnect
(
socket
:
Socket
):
void
{
console
.
log
(
`🔴 Client disconnected:
${
socket
.
id
}
`
)
console
.
log
(
`🔴 Client disconnected:
${
socket
.
id
}
`
)
endGame
(
socket
);
//
endGame(socket);
}
}
async
function
getHistory
(
socket
:
Socket
)
{
async
function
getHistory
(
socket
:
Socket
)
{
...
@@ -79,10 +75,14 @@ async function startGame(socket: Socket, data: any) {
...
@@ -79,10 +75,14 @@ async function startGame(socket: Socket, data: any) {
try
{
try
{
const
user
=
getUserBySocket
(
socket
);
const
user
=
getUserBySocket
(
socket
);
const
result
=
await
startGameApi
(
data
);
const
result
=
await
startGameApi
(
data
);
// const result = true;
if
(
result
&&
user
.
isStartGame
)
{
user
.
reset
();
}
if
(
result
)
{
if
(
result
)
{
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_START_GAME
,
true
);
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_START_GAME
,
true
);
user
.
is
EndGame
=
fals
e
;
user
.
is
StartGame
=
tru
e
;
addBlock
(
socket
);
addBlock
(
socket
);
}
else
{
}
else
{
console
.
log
(
'start game fail'
);
console
.
log
(
'start game fail'
);
...
@@ -129,10 +129,6 @@ async function passTower(socket: Socket, data: { distance: number }) {
...
@@ -129,10 +129,6 @@ async function passTower(socket: Socket, data: { distance: number }) {
const
heightJump
=
user
.
distance2Tower
*
0.7
;
const
heightJump
=
user
.
distance2Tower
*
0.7
;
if
(
score
<=
0
)
{
user
.
isEndGame
=
true
;
}
if
(
score
==
2
)
{
if
(
score
==
2
)
{
user
.
combo
=
Math
.
min
(
user
.
combo
+
1
,
2
);
user
.
combo
=
Math
.
min
(
user
.
combo
+
1
,
2
);
score
*=
user
.
combo
;
score
*=
user
.
combo
;
...
@@ -169,7 +165,6 @@ async function passTower(socket: Socket, data: { distance: number }) {
...
@@ -169,7 +165,6 @@ async function passTower(socket: Socket, data: { distance: number }) {
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_HISTORY
,
user
.
history
);
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_HISTORY
,
user
.
history
);
await
endGameApi
(
user
);
await
endGameApi
(
user
);
user
.
reset
();
user
.
reset
();
console
.
log
(
'END'
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'error'
,
error
)
console
.
log
(
'error'
,
error
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment