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
e65a4739
Commit
e65a4739
authored
Aug 28, 2025
by
Vũ Gia Vương
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix call end game when back in web browser, add matchId,eventId
parent
15f154ec
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
28 deletions
+49
-28
networkCtrl.js
dist/Controller/networkCtrl.js
+13
-11
User.js
dist/Model/User.js
+4
-0
gameCtrl.ts
src/Controller/gameCtrl.ts
+7
-3
networkCtrl.ts
src/Controller/networkCtrl.ts
+15
-12
User.ts
src/Model/User.ts
+8
-0
socket.ts
src/socket.ts
+2
-2
No files found.
dist/Controller/networkCtrl.js
View file @
e65a4739
...
@@ -19,18 +19,14 @@ let tokenTest = 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTI1LCJ1c2VybmFtZSI6IlFIU18wMUpEVk
...
@@ -19,18 +19,14 @@ let tokenTest = 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTI1LCJ1c2VybmFtZSI6IlFIU18wMUpEVk
+
'kZBIjpmYWxzZSwibGFzdExvZ2luVGltZSI6IjIwMjUtMDgtMDhUMTQ6MTc6MDcuNzczMTEyMjUzIiwicmVmZXJlbmNlQ29kZSI6IklRVEtUQzRkbGk4NiIsImdlbmRlciI6Ik1BTEUiLCJ2dG1BY2NvdW50'
+
'kZBIjpmYWxzZSwibGFzdExvZ2luVGltZSI6IjIwMjUtMDgtMDhUMTQ6MTc6MDcuNzczMTEyMjUzIiwicmVmZXJlbmNlQ29kZSI6IklRVEtUQzRkbGk4NiIsImdlbmRlciI6Ik1BTEUiLCJ2dG1BY2NvdW50'
+
'SWQiOiIwMUpEVkZHOE5DUEdBNEtFRUhLWDA4RUJWOCIsImRvYiI6IjE5OTktMDItMTciLCJjb2RlIjoiMTIzNDU2NzYiLCJzdWIiOiIxMjUiLCJpYXQiOjE3NTQ2Mzc0MjcsImV4cCI6MTc2MzI3NzQyN30.'
+
'SWQiOiIwMUpEVkZHOE5DUEdBNEtFRUhLWDA4RUJWOCIsImRvYiI6IjE5OTktMDItMTciLCJjb2RlIjoiMTIzNDU2NzYiLCJzdWIiOiIxMjUiLCJpYXQiOjE3NTQ2Mzc0MjcsImV4cCI6MTc2MzI3NzQyN30.'
+
'Wf7PDX2rgqRPajkTL8oHHeYFwZrLpTKmuBO8Va9OGMs'
;
+
'Wf7PDX2rgqRPajkTL8oHHeYFwZrLpTKmuBO8Va9OGMs'
;
let
timeStart
=
0
;
// let timeStart = 0;
let
userId
=
0
;
let
matchId
=
''
;
let
eventId
=
null
;
function
startGameApiCtrl
(
data
,
user
)
{
function
startGameApiCtrl
(
data
,
user
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
try
{
try
{
timeStart
=
new
Date
().
getTime
();
user
.
timeStart
=
new
Date
().
getTime
();
userId
=
(
Math
.
random
()
*
100
>>
0
)
+
10
;
user
.
matchId
=
`
${
user
.
id
}
-
${
GAME_CODE
}
-
${
user
.
timeStart
}
`
;
matchId
=
`
${
userId
}
-
${
GAME_CODE
}
-
${
timeStart
}
`
;
data
=
{
data
=
{
matchId
,
matchId
:
user
.
matchId
,
gameCode
:
GAME_CODE
,
gameCode
:
GAME_CODE
,
};
};
const
result
=
yield
callApi
(
URL_START_GAME
,
'POST'
,
data
,
user
.
token
);
const
result
=
yield
callApi
(
URL_START_GAME
,
'POST'
,
data
,
user
.
token
);
...
@@ -44,7 +40,7 @@ function startGameApiCtrl(data, user) {
...
@@ -44,7 +40,7 @@ function startGameApiCtrl(data, user) {
function
endGameApiCtrl
(
user
)
{
function
endGameApiCtrl
(
user
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
try
{
try
{
const
playedSeconds
=
(
new
Date
().
getTime
()
-
timeStart
)
/
1
e3
;
const
playedSeconds
=
(
new
Date
().
getTime
()
-
user
.
timeStart
)
/
1
e3
;
const
details
=
user
.
history
.
map
(
h
=>
({
const
details
=
user
.
history
.
map
(
h
=>
({
level
:
h
.
tower
,
level
:
h
.
tower
,
score
:
h
.
score
,
score
:
h
.
score
,
...
@@ -52,9 +48,9 @@ function endGameApiCtrl(user) {
...
@@ -52,9 +48,9 @@ function endGameApiCtrl(user) {
timePlayed
:
h
.
timePlayed
/
1
e3
,
timePlayed
:
h
.
timePlayed
/
1
e3
,
}));
}));
const
params
=
{
const
params
=
{
matchId
,
matchId
:
user
.
matchId
,
gameCode
:
GAME_CODE
,
gameCode
:
GAME_CODE
,
eventId
,
eventId
:
user
.
eventId
,
playedSeconds
,
playedSeconds
,
score
:
user
.
totalScore
,
score
:
user
.
totalScore
,
gameLevel
:
user
.
towerNumber
-
1
,
gameLevel
:
user
.
towerNumber
-
1
,
...
@@ -85,6 +81,12 @@ function callApi(url, method, data, token) {
...
@@ -85,6 +81,12 @@ function callApi(url, method, data, token) {
console
.
log
(
'error callApi: '
,
res
,
'data: '
,
data
);
console
.
log
(
'error callApi: '
,
res
,
'data: '
,
data
);
}
}
const
result
=
yield
res
.
json
();
const
result
=
yield
res
.
json
();
console
.
log
(
'-----------'
);
console
.
log
(
'url'
,
url
);
console
.
log
(
'token'
,
token
);
console
.
log
(
'data'
,
data
);
console
.
log
(
'result'
,
result
);
console
.
log
(
'-----------'
);
return
(
result
===
null
||
result
===
void
0
?
void
0
:
result
.
code
)
==
'success'
;
return
(
result
===
null
||
result
===
void
0
?
void
0
:
result
.
code
)
==
'success'
;
}
}
catch
(
error
)
{
catch
(
error
)
{
...
...
dist/Model/User.js
View file @
e65a4739
...
@@ -19,6 +19,8 @@ class User {
...
@@ -19,6 +19,8 @@ class User {
this
.
nextBlock
=
new
v2_1
.
default
(
0
,
0
);
this
.
nextBlock
=
new
v2_1
.
default
(
0
,
0
);
this
.
screenPos
=
new
v2_1
.
default
(
0
,
0
);
this
.
screenPos
=
new
v2_1
.
default
(
0
,
0
);
this
.
position
=
new
v2_1
.
default
(
0
,
0
);
this
.
position
=
new
v2_1
.
default
(
0
,
0
);
this
.
matchId
=
''
;
this
.
eventId
=
''
;
this
.
timeStart
=
0
;
this
.
timeStart
=
0
;
this
.
isStartGame
=
true
;
this
.
isStartGame
=
true
;
this
.
history
=
[];
this
.
history
=
[];
...
@@ -32,6 +34,8 @@ class User {
...
@@ -32,6 +34,8 @@ class User {
this
.
score
=
user
.
score
||
0
;
this
.
score
=
user
.
score
||
0
;
this
.
totalScore
=
user
.
totalScore
||
0
;
this
.
totalScore
=
user
.
totalScore
||
0
;
this
.
combo
=
user
.
combo
||
0
;
this
.
combo
=
user
.
combo
||
0
;
this
.
matchId
=
user
.
matchId
||
''
;
this
.
eventId
=
user
.
eventId
||
''
;
this
.
timeStart
=
user
.
timeStart
||
0
;
this
.
timeStart
=
user
.
timeStart
||
0
;
this
.
isStartGame
=
user
.
isStartGame
||
true
;
this
.
isStartGame
=
user
.
isStartGame
||
true
;
this
.
history
=
((
_a
=
user
.
history
)
===
null
||
_a
===
void
0
?
void
0
:
_a
.
map
(
h
=>
new
History
(
h
.
timeStart
,
h
.
timePlayed
,
h
.
totalScore
,
h
.
tower
,
h
.
score
)))
||
[];
this
.
history
=
((
_a
=
user
.
history
)
===
null
||
_a
===
void
0
?
void
0
:
_a
.
map
(
h
=>
new
History
(
h
.
timeStart
,
h
.
timePlayed
,
h
.
totalScore
,
h
.
tower
,
h
.
score
)))
||
[];
...
...
src/Controller/gameCtrl.ts
View file @
e65a4739
import
{
Socket
}
from
"socket.io"
;
import
{
Socket
}
from
"socket.io"
;
import
User
,
{
IDataPassTower
,
IDataSpawnTower
,
IRequestPassTower
}
from
"../Model/User"
;
import
User
,
{
IDataPassTower
,
IDataSpawnTower
,
I
DataStartGame
,
I
RequestPassTower
}
from
"../Model/User"
;
import
{
endGameApiCtrl
,
startGameApiCtrl
}
from
"./networkCtrl"
;
import
{
endGameApiCtrl
,
startGameApiCtrl
}
from
"./networkCtrl"
;
import
v2
from
"../Model/v2"
;
import
v2
from
"../Model/v2"
;
import
CONFIG
from
"../Config/config"
;
import
CONFIG
from
"../Config/config"
;
...
@@ -14,6 +14,9 @@ const RATE_BLACK_LIST = 0.15;
...
@@ -14,6 +14,9 @@ const RATE_BLACK_LIST = 0.15;
export
async
function
endGameCtrl
(
user
:
User
)
{
export
async
function
endGameCtrl
(
user
:
User
)
{
try
{
try
{
if
(
!
user
.
isStartGame
)
{
return
;
}
await
endGameApiCtrl
(
user
);
await
endGameApiCtrl
(
user
);
user
.
reset
();
user
.
reset
();
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -21,8 +24,9 @@ export async function endGameCtrl(user: User) {
...
@@ -21,8 +24,9 @@ export async function endGameCtrl(user: User) {
}
}
}
}
export
async
function
startGameCtrl
(
socket
:
Socket
,
data
:
any
,
user
:
User
)
{
export
async
function
startGameCtrl
(
socket
:
Socket
,
data
:
IDataStartGame
,
user
:
User
)
{
try
{
try
{
user
.
eventId
=
data
?.
eventId
||
''
;
const
result
=
await
startGameApiCtrl
(
data
,
user
);
const
result
=
await
startGameApiCtrl
(
data
,
user
);
if
(
result
&&
user
.
isStartGame
)
{
if
(
result
&&
user
.
isStartGame
)
{
...
@@ -132,7 +136,7 @@ export async function passTowerCtrl(socket: Socket, data: IRequestPassTower, use
...
@@ -132,7 +136,7 @@ export async function passTowerCtrl(socket: Socket, data: IRequestPassTower, use
addBlockCtrl
(
socket
,
user
);
addBlockCtrl
(
socket
,
user
);
}
else
{
}
else
{
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_HISTORY
,
user
.
history
);
socket
.
emit
(
CONFIG
.
EVT
.
REQUEST_HISTORY
,
user
.
history
);
await
endGame
Api
Ctrl
(
user
);
await
endGameCtrl
(
user
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'error'
,
error
)
console
.
log
(
'error'
,
error
)
...
...
src/Controller/networkCtrl.ts
View file @
e65a4739
import
User
from
"../Model/User"
;
import
User
,
{
IDataStartGame
}
from
"../Model/User"
;
const
URL
=
process
.
env
.
URL
||
'https://dev.gamee.vn/api/web'
;
const
URL
=
process
.
env
.
URL
||
'https://dev.gamee.vn/api/web'
;
const
URL_START_GAME
=
`
${
URL
}
/game/start`
;
const
URL_START_GAME
=
`
${
URL
}
/game/start`
;
...
@@ -8,19 +8,15 @@ let tokenTest = 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTI1LCJ1c2VybmFtZSI6IlFIU18wMUpEVk
...
@@ -8,19 +8,15 @@ let tokenTest = 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MTI1LCJ1c2VybmFtZSI6IlFIU18wMUpEVk
+
'kZBIjpmYWxzZSwibGFzdExvZ2luVGltZSI6IjIwMjUtMDgtMDhUMTQ6MTc6MDcuNzczMTEyMjUzIiwicmVmZXJlbmNlQ29kZSI6IklRVEtUQzRkbGk4NiIsImdlbmRlciI6Ik1BTEUiLCJ2dG1BY2NvdW50'
+
'kZBIjpmYWxzZSwibGFzdExvZ2luVGltZSI6IjIwMjUtMDgtMDhUMTQ6MTc6MDcuNzczMTEyMjUzIiwicmVmZXJlbmNlQ29kZSI6IklRVEtUQzRkbGk4NiIsImdlbmRlciI6Ik1BTEUiLCJ2dG1BY2NvdW50'
+
'SWQiOiIwMUpEVkZHOE5DUEdBNEtFRUhLWDA4RUJWOCIsImRvYiI6IjE5OTktMDItMTciLCJjb2RlIjoiMTIzNDU2NzYiLCJzdWIiOiIxMjUiLCJpYXQiOjE3NTQ2Mzc0MjcsImV4cCI6MTc2MzI3NzQyN30.'
+
'SWQiOiIwMUpEVkZHOE5DUEdBNEtFRUhLWDA4RUJWOCIsImRvYiI6IjE5OTktMDItMTciLCJjb2RlIjoiMTIzNDU2NzYiLCJzdWIiOiIxMjUiLCJpYXQiOjE3NTQ2Mzc0MjcsImV4cCI6MTc2MzI3NzQyN30.'
+
'Wf7PDX2rgqRPajkTL8oHHeYFwZrLpTKmuBO8Va9OGMs'
;
+
'Wf7PDX2rgqRPajkTL8oHHeYFwZrLpTKmuBO8Va9OGMs'
;
let
timeStart
=
0
;
// let timeStart = 0;
let
userId
=
0
;
let
matchId
=
''
;
let
eventId
:
string
|
null
=
null
;
export
async
function
startGameApiCtrl
(
data
:
any
,
user
:
User
)
{
export
async
function
startGameApiCtrl
(
data
:
any
,
user
:
User
)
{
try
{
try
{
timeStart
=
new
Date
().
getTime
();
user
.
timeStart
=
new
Date
().
getTime
();
userId
=
(
Math
.
random
()
*
100
>>
0
)
+
10
;
user
.
matchId
=
`
${
user
.
id
}
-
${
GAME_CODE
}
-
${
user
.
timeStart
}
`
;
matchId
=
`
${
userId
}
-
${
GAME_CODE
}
-
${
timeStart
}
`
;
data
=
{
data
=
{
matchId
,
matchId
:
user
.
matchId
,
gameCode
:
GAME_CODE
,
gameCode
:
GAME_CODE
,
};
};
const
result
=
await
callApi
(
URL_START_GAME
,
'POST'
,
data
,
user
.
token
);
const
result
=
await
callApi
(
URL_START_GAME
,
'POST'
,
data
,
user
.
token
);
...
@@ -32,7 +28,7 @@ export async function startGameApiCtrl(data: any, user: User) {
...
@@ -32,7 +28,7 @@ export async function startGameApiCtrl(data: any, user: User) {
export
async
function
endGameApiCtrl
(
user
:
User
)
{
export
async
function
endGameApiCtrl
(
user
:
User
)
{
try
{
try
{
const
playedSeconds
=
(
new
Date
().
getTime
()
-
timeStart
)
/
1
e3
;
const
playedSeconds
=
(
new
Date
().
getTime
()
-
user
.
timeStart
)
/
1
e3
;
const
details
=
user
.
history
.
map
(
h
=>
({
const
details
=
user
.
history
.
map
(
h
=>
({
level
:
h
.
tower
,
level
:
h
.
tower
,
score
:
h
.
score
,
score
:
h
.
score
,
...
@@ -41,9 +37,9 @@ export async function endGameApiCtrl(user: User) {
...
@@ -41,9 +37,9 @@ export async function endGameApiCtrl(user: User) {
}));
}));
const
params
=
{
const
params
=
{
matchId
,
matchId
:
user
.
matchId
,
gameCode
:
GAME_CODE
,
gameCode
:
GAME_CODE
,
eventId
,
eventId
:
user
.
eventId
,
playedSeconds
,
playedSeconds
,
score
:
user
.
totalScore
,
score
:
user
.
totalScore
,
gameLevel
:
user
.
towerNumber
-
1
,
gameLevel
:
user
.
towerNumber
-
1
,
...
@@ -73,6 +69,13 @@ async function callApi(url: string, method: string, data: any, token: string) {
...
@@ -73,6 +69,13 @@ async function callApi(url: string, method: string, data: any, token: string) {
console
.
log
(
'error callApi: '
,
res
,
'data: '
,
data
);
console
.
log
(
'error callApi: '
,
res
,
'data: '
,
data
);
}
}
const
result
=
await
res
.
json
();
const
result
=
await
res
.
json
();
console
.
log
(
'-----------'
)
console
.
log
(
'url'
,
url
)
console
.
log
(
'token'
,
token
)
console
.
log
(
'data'
,
data
)
console
.
log
(
'result'
,
result
)
console
.
log
(
'-----------'
)
return
result
?.
code
==
'success'
;
return
result
?.
code
==
'success'
;
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'error callApi: '
,
error
);
console
.
log
(
'error callApi: '
,
error
);
...
...
src/Model/User.ts
View file @
e65a4739
...
@@ -16,6 +16,8 @@ class User {
...
@@ -16,6 +16,8 @@ class User {
public
screenPos
:
v2
=
new
v2
(
0
,
0
);
public
screenPos
:
v2
=
new
v2
(
0
,
0
);
public
position
:
v2
=
new
v2
(
0
,
0
);
public
position
:
v2
=
new
v2
(
0
,
0
);
public
matchId
:
string
=
''
;
public
eventId
:
string
=
''
;
public
timeStart
:
number
=
0
;
public
timeStart
:
number
=
0
;
public
isStartGame
:
boolean
=
true
;
public
isStartGame
:
boolean
=
true
;
public
history
:
History
[]
=
[];
public
history
:
History
[]
=
[];
...
@@ -33,6 +35,8 @@ class User {
...
@@ -33,6 +35,8 @@ class User {
this
.
totalScore
=
user
.
totalScore
||
0
;
this
.
totalScore
=
user
.
totalScore
||
0
;
this
.
combo
=
user
.
combo
||
0
;
this
.
combo
=
user
.
combo
||
0
;
this
.
matchId
=
user
.
matchId
||
''
;
this
.
eventId
=
user
.
eventId
||
''
;
this
.
timeStart
=
user
.
timeStart
||
0
;
this
.
timeStart
=
user
.
timeStart
||
0
;
this
.
isStartGame
=
user
.
isStartGame
||
true
;
this
.
isStartGame
=
user
.
isStartGame
||
true
;
this
.
history
=
user
.
history
?.
map
(
h
=>
new
History
(
h
.
timeStart
,
h
.
timePlayed
,
h
.
totalScore
,
h
.
tower
,
h
.
score
))
||
[];
this
.
history
=
user
.
history
?.
map
(
h
=>
new
History
(
h
.
timeStart
,
h
.
timePlayed
,
h
.
totalScore
,
h
.
tower
,
h
.
score
))
||
[];
...
@@ -111,4 +115,8 @@ export interface IQuery {
...
@@ -111,4 +115,8 @@ export interface IQuery {
userId
?:
string
userId
?:
string
}
}
export
interface
IDataStartGame
{
eventId
?:
string
}
export
default
User
;
export
default
User
;
\ No newline at end of file
src/socket.ts
View file @
e65a4739
import
{
Server
,
Socket
}
from
"socket.io"
;
import
{
Server
,
Socket
}
from
"socket.io"
;
import
User
,
{
IRequestPassTower
}
from
"./Model/User"
;
import
User
,
{
I
DataStartGame
,
I
RequestPassTower
}
from
"./Model/User"
;
import
{
redis
}
from
"."
;
import
{
redis
}
from
"."
;
import
{
endGameCtrl
,
getHistory
,
passTowerCtrl
,
startGameCtrl
}
from
"./Controller/gameCtrl"
;
import
{
endGameCtrl
,
getHistory
,
passTowerCtrl
,
startGameCtrl
}
from
"./Controller/gameCtrl"
;
import
CONFIG
from
"./Config/config"
;
import
CONFIG
from
"./Config/config"
;
...
@@ -48,7 +48,7 @@ export async function setupSocket(io: Server) {
...
@@ -48,7 +48,7 @@ export async function setupSocket(io: Server) {
connectedUserCtrl
();
connectedUserCtrl
();
}
}
socket
.
on
(
CONFIG
.
EVT
.
START_GAME
,
(
data
:
string
)
=>
startGameCtrl
(
socket
,
data
,
user
));
socket
.
on
(
CONFIG
.
EVT
.
START_GAME
,
(
data
:
IDataStartGame
)
=>
startGameCtrl
(
socket
,
data
,
user
));
socket
.
on
(
CONFIG
.
EVT
.
PASS_TOWER
,
async
(
data
:
IRequestPassTower
)
=>
await
passTowerCtrl
(
socket
,
data
,
user
));
socket
.
on
(
CONFIG
.
EVT
.
PASS_TOWER
,
async
(
data
:
IRequestPassTower
)
=>
await
passTowerCtrl
(
socket
,
data
,
user
));
socket
.
on
(
CONFIG
.
EVT
.
HISTORY
,
async
()
=>
await
getHistory
(
socket
,
user
));
socket
.
on
(
CONFIG
.
EVT
.
HISTORY
,
async
()
=>
await
getHistory
(
socket
,
user
));
socket
.
on
(
CONFIG
.
EVT
.
END_GAME
,
()
=>
endGameCtrl
(
user
));
socket
.
on
(
CONFIG
.
EVT
.
END_GAME
,
()
=>
endGameCtrl
(
user
));
...
...
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