Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sejong25
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Tear of Sejong
sejong25
Commits
9f7bd07c
Commit
9f7bd07c
authored
Jul 08, 2019
by
18류지석
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'server'
# Conflicts: # js/Input.js # js/WordSpace.js # js/main.js
parents
7c1db744
a9ecd857
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
272 additions
and
164 deletions
+272
-164
GameServer.js
GameServer.js
+102
-0
menuBackground.png
assets/placeholder/menuBackground.png
+0
-0
index.html
index.html
+1
-0
Background.js
js/Background.js
+8
-7
Client.js
js/Client.js
+25
-0
Input.js
js/Input.js
+25
-8
ScenesData.js
js/ScenesData.js
+5
-8
WordSpace.js
js/WordSpace.js
+9
-10
main.js
js/main.js
+46
-53
server.js
server.js
+51
-78
No files found.
GameServer.js
0 → 100644
View file @
9f7bd07c
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
2
;
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
GameServer
.
getPlayerNumber
=
function
()
{
do
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
if
(
!
this
.
currentPlayer
.
includes
(
num
))
return
num
;
}
while
(
true
)
}
GameServer
.
findPlayer
=
function
(
playerId
)
{
var
idx
=
this
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
socket
;
});
if
(
idx
!=
-
1
)
return
this
.
currentPlayer
[
idx
];
else
{
console
.
log
(
'
[ERR] wrong playerId to find
'
);
return
null
;
}
}
GameServer
.
nextRoomNumber
=
0
;
GameServer
.
makeRoom
=
function
()
{
var
roomOption
=
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
maxPlayer
:
3
,
currentPlayer
:
[],
currnetPhase
:
GameServer
.
Phase
.
READY
,
rateArrangePoint
:
300
,
maxTypingPlayer
:
null
,
minTypingPlayer
:
null
}
this
.
playingRoom
.
push
(
roomOption
);
console
.
log
(
'
[SERVER] new room #
'
+
roomOption
.
roomNum
+
'
made, roomCount:
'
+
this
.
playingRoom
.
length
);
return
this
.
playingRoom
.
length
-
1
;
}
GameServer
.
findRoomIndex
=
function
(
roomNum
)
{
return
GameServer
.
playingRoom
.
findIndex
(
function
(
element
)
{
return
element
.
roomNum
===
roomNum
;
});
}
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
push
(
playerData
);
playerData
.
currentRoom
=
this
.
playingRoom
[
roomIdx
];
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
this
.
playingRoom
[
roomIdx
].
roomNum
);
if
(
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
length
>=
this
.
startCount
&&
this
.
playingRoom
[
roomIdx
].
Phase
!=
GameServer
.
Phase
.
START
)
GameServer
.
startRoom
(
roomIdx
);
return
this
.
playingRoom
[
roomIdx
];
}
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
{
var
toEnter
=
-
1
;
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
{
if
(
this
.
playingRoom
[
i
].
currentPlayer
.
length
<
this
.
playingRoom
[
i
].
maxPlayer
)
{
toEnter
=
i
;
break
;
}
}
if
(
toEnter
===
-
1
)
{
toEnter
=
this
.
makeRoom
();
}
return
this
.
enterRoom
(
toEnter
,
playerData
);
}
GameServer
.
startRoom
=
function
(
roomIdx
)
{
let
room
=
this
.
playingRoom
[
roomIdx
];
this
.
playingRoom
[
roomIdx
].
Phase
=
this
.
Phase
.
START
;
this
.
playingRoom
[
roomIdx
].
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
this
.
playingRoom
[
roomIdx
].
mimTypingPlayer
=
room
.
currentPlayer
[
0
];
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start
'
);
this
.
announceToRoom
(
roomIdx
,
'
phaseChange
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
// 데이터 동기화도
}
GameServer
.
announceToRoom
=
function
(
roomIdx
,
message
,
data
=
null
)
{
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
forEach
(
element
=>
{
element
.
socketId
.
emit
(
message
,
data
);
});
}
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
module
.
exports
=
GameServer
;
\ No newline at end of file
assets/placeholder/menuBackground.png
0 → 100644
View file @
9f7bd07c
130 KB
index.html
View file @
9f7bd07c
...
...
@@ -14,6 +14,7 @@
<script
src=
"js/SelectWord.js"
></script>
</head>
<body>
<script
src=
"js/Client.js"
></script>
<script
src=
"js/Main.js"
></script>
</body>
</html>
\ No newline at end of file
js/Background.js
View file @
9f7bd07c
var
BackGround
=
BackGround
||
{}
BackGround
.
isImageLoaded
=
false
;
BackGround
.
brainGroup
=
null
;
BackGround
.
loadImage
=
function
(
scene
)
{
if
(
!
this
.
isImageLoaded
)
{
scene
.
load
.
image
(
'
brainGround0
'
,
'
assets/placeholder/playback.png
'
);
}
scene
.
load
.
image
(
'
brainGround
'
,
'
assets/placeholder/playback.png
'
);
scene
.
load
.
image
(
'
menuBackground
'
,
'
assets/placeholder/menuBackground.png
'
)
}
BackGround
.
drawBrain
=
function
(
scene
)
{
brains
=
scene
.
add
.
sprite
(
640
,
360
,
'
brainGround0
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
brains
=
scene
.
add
.
sprite
(
640
,
360
,
'
brainGround
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
}
BackGround
.
drawMenu
=
function
(
scene
)
{
scene
.
add
.
sprite
(
640
,
360
,
'
menuBackground
'
).
setDisplaySize
(
1282
,
722
).
setDepth
(
1
);
}
\ No newline at end of file
js/Client.js
0 → 100644
View file @
9f7bd07c
var
socket
=
io
.
connect
();
socket
.
emit
(
'
idRequest
'
);
socket
.
on
(
'
idSet
'
,
function
(
msg
)
// {str, num playerNum}
{
console
.
log
(
msg
.
str
);
playerNum
=
msg
.
num
;
});
socket
.
on
(
'
setPlayerTypingRate
'
,
function
(
msg
)
// number playerTypingRate
{
WordSpace
.
PlayerTypingRate
=
msg
;
});
socket
.
on
(
'
phaseChange
'
,
function
(
msg
)
// number Phase
{
console
.
log
(
'
phase changed from
'
+
WordSpace
.
CurrentPhase
+
'
to
'
+
msg
);
WordSpace
.
CurrentPhase
=
msg
;
});
socket
.
on
(
'
startGame
'
,
function
()
{
game
.
scene
.
start
(
'
gameScene
'
);
});
socket
.
on
(
'
userDisconnect
'
,
function
(
msg
)
// {num id, str nickname}
{
console
.
log
(
msg
.
id
+
'
/
'
+
msg
.
nickname
+
'
disconnected
'
);
});
\ No newline at end of file
js/Input.js
View file @
9f7bd07c
...
...
@@ -11,6 +11,29 @@ Input.maxInput = 5;
Input
.
attackMode
=
false
;
Input
.
attackOption
=
null
;
Input
.
gameSceneEnterReaction
=
function
()
{
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
if
(
Input
.
attackMode
)
WordSpace
.
attack
(
Input
.
convInput
,
Input
.
attackOption
.
wordGrade
);
else
WordSpace
.
findWord
(
Input
.
convInput
);
Input
.
reset
();
}
Input
.
menuSceneEnterReaction
=
function
()
{
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
if
(
Input
.
convInput
.
length
>
0
)
{
socket
.
emit
(
'
setNickname
'
,
Input
.
convInput
);
Input
.
reset
();
game
.
scene
.
remove
(
'
menuScene
'
);
}
else
{
alert
(
'
정확한 가명을 입력해주세요.
'
);
Input
.
reset
();
}
}
Input
.
reset
=
function
()
{
Input
.
input
=
[];
...
...
@@ -275,7 +298,7 @@ Input.removeConVow = function(_wordText)
Input
.
inputField
=
{
generate
:
function
(
scene
)
generate
:
function
(
scene
,
enterCallback
)
{
this
.
background
=
scene
.
add
.
sprite
(
640
,
550
,
'
inputfield
'
).
setDepth
(
10
);
this
.
text
=
scene
.
add
.
text
(
640
,
550
,
"
안녕하세요
"
,
{
font
:
'
25pt 궁서
'
}).
setOrigin
(
0.5
,
0.5
).
setColor
(
'
#000000
'
).
setDepth
(
10
);
...
...
@@ -293,13 +316,7 @@ Input.inputField =
Input
.
inputField
.
text
.
setText
(
Input
.
convInput
);
}
});
scene
.
input
.
keyboard
.
on
(
'
keydown-ENTER
'
,
function
()
{
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
if
(
Input
.
attackMode
)
WordSpace
.
attack
(
Input
.
convInput
,
Input
.
attackOption
.
wordGrade
);
else
WordSpace
.
findWord
(
Input
.
convInput
);
Input
.
reset
();
});
scene
.
input
.
keyboard
.
on
(
'
keydown-ENTER
'
,
enterCallback
);
// upside 10 keys
scene
.
input
.
keyboard
.
on
(
'
keydown-Q
'
,
function
()
{
Input
.
pushInput
(
'
ㅂ
'
)});
scene
.
input
.
keyboard
.
on
(
'
keydown-W
'
,
function
()
{
Input
.
pushInput
(
'
ㅈ
'
)});
...
...
js/ScenesData.js
View file @
9f7bd07c
...
...
@@ -11,17 +11,14 @@ var menuScene = new Phaser.Class(
preload
:
function
()
{
//Input.inputField.loadImage(this);
Input
.
inputField
.
loadImage
(
this
);
BackGround
.
loadImage
(
this
);
},
create
:
function
()
{
//Input.inputField.generate(this);
},
update
:
function
()
{
Input
.
inputField
.
generate
(
this
,
Input
.
menuSceneEnterReaction
);
BackGround
.
drawMenu
(
this
);
}
});
...
...
@@ -51,7 +48,7 @@ var gameScene = new Phaser.Class(
WordSpace
.
wordPhysicsGroup
=
this
.
physics
.
add
.
group
();
Input
.
inputField
.
generate
(
this
);
Input
.
inputField
.
generate
(
this
,
Input
.
gameSceneEnterReaction
);
WordSpace
.
attackGauge
.
generate
(
this
);
WordSpace
.
spaceInitiate
(
this
);
WordSpace
.
attackGauge
.
resetCycle
(
this
);
...
...
js/WordSpace.js
View file @
9f7bd07c
...
...
@@ -70,8 +70,8 @@ WordSpace.nameCycle = new cycle(function()
WordSpace
.
varAdjustCycle
=
new
cycle
(
function
()
{
//나중에는 메세지 분석해서 Phase랑 PlayerTypingRate 받겠지만 일단 이렇게 해둠
WordSpace
.
GetPhase
();
WordSpace
.
GetPlayerTypingRate
();
//
WordSpace.GetPhase();
//
WordSpace.GetPlayerTypingRate();
WordSpace
.
AdjustVarByPhase
(
WordSpace
.
PlayerTypingRate
,
WordSpace
.
CurrentPhase
);
});
...
...
@@ -104,7 +104,12 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase)
{
if
(
phase
==
WordSpace
.
Phase
.
READY
)
{
WordSpace
.
WordSpawnDelay
=
10000
;
WordSpace
.
NameSpawnDelay
=
10000
;
WordSpace
.
NameSpawnReduce
=
0
;
WordSpace
.
GradeProb
[
0
]
=
1
;
WordSpace
.
GradeProb
[
1
]
=
1
;
WordSpace
.
GradeProb
[
2
]
=
1
;
}
else
if
(
phase
==
WordSpace
.
Phase
.
START
)
{
...
...
@@ -137,13 +142,6 @@ WordSpace.AdjustVarByPhase = function(typingRate, phase)
WordSpace
.
nameCycle
.
resetCycle
(
WordSpace
.
gameSceneForTest
,
WordSpace
.
NameSpawnDelay
,
WordSpace
.
nameCycle
.
currentCycle
.
getElapsed
(),
true
);
}
WordSpace
.
GetPhase
=
function
()
{
//서버통신하셈~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//임시
WordSpace
.
CurrentPhase
=
WordSpace
.
Phase
.
START
;
}
WordSpace
.
GetPlayerTypingRate
=
function
()
{
//서버통신하셈~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
...
@@ -346,6 +344,7 @@ WordSpace.setPlayerTyping =
{
this
.
totalTyping
+=
wordText
!=
null
?
WordReader
.
getWordTyping
(
wordText
)
:
0
;
WordSpace
.
playerTyping
=
this
.
totalTyping
/
WordSpace
.
gameTimer
.
now
*
1000
;
socket
.
emit
(
'
setPlayerTyping
'
,
this
.
playerTyping
);
this
.
text
.
setText
(
'
현재 타수 :
'
+
WordSpace
.
playerTyping
.
toFixed
(
1
));
},
initiate
:
function
(
scene
)
...
...
js/main.js
View file @
9f7bd07c
...
...
@@ -9,7 +9,7 @@ var config = {
}
},
backgroundColor
:
Phaser
.
Display
.
Color
.
GetColor
(
0
,
0
,
0
),
scene
:
[
gameScene
,
menu
Scene
]
scene
:
[
menuScene
,
game
Scene
]
};
var
game
=
new
Phaser
.
Game
(
config
)
...
...
@@ -20,41 +20,34 @@ var playerNum = -1; //플레이어 아이디, 고유 번호
var
playerName
=
'
임시아이디
'
//플레이어 닉네임
// client side
var
socket
=
io
.
connect
();
socket
.
emit
(
'
idRequest
'
);
socket
.
on
(
'
idSet
'
,
function
(
msg
)
// {str, num}
{
console
.
log
(
msg
.
str
);
this
.
playerNum
=
msg
.
num
;
});
//test
/*window.addEventListener("message", function(event)
{
window.addEventListener("message", function (event) {
var sub = 0;
if
(event.data == "tick")
{
if(window.lafcb)
if
((new Date().getTime()/1000) - window.lafcb.started > 0.5)
{
window.lafcb.func(new Date().getTime()
+
16)
if
(event.data == "tick")
{
if
(window.lafcb)
if
((new Date().getTime() / 1000) - window.lafcb.started > 0.5)
{
window.lafcb.func(new Date().getTime()
+
16)
window.lafcb = null;
}
var i = window.timeouts.length;
while (i--) {
if
(window.timeouts[i].ran)
{
window.timeouts.splice(i,1);
if
(window.timeouts[i].ran)
{
window.timeouts.splice(i,
1);
}
}
var i = window.timeouts.length;
while (i--) {
if
(new Date().getTime() - window.timeouts[i].started >= window.timeouts[i].delay && window.timeouts[i])
{
if
(new Date().getTime() - window.timeouts[i].started >= window.timeouts[i].delay && window.timeouts[i])
{
window.timeouts[i].func();
window.timeouts[i].ran = true;
}
}
for
(var i in window.intervals)
{
for
(var i in window.intervals)
{
var currTime = new Date().getTime();
if
(currTime - window.intervals[i].last >= window.intervals[i].delay && window.intervals[i])
{
if
(currTime - window.intervals[i].last >= window.intervals[i].delay && window.intervals[i])
{
window.intervals[i].last = currTime;
window.intervals[i].func();
}
...
...
@@ -62,63 +55,63 @@ socket.on('idSet', function(msg) // {str, num}
window.postMessage('tick', '*');
}
}, false);
(function(context) {
'use strict';
(function
(context) {
'use strict';
window.lafcb = null;
context.timeouts = [];
context.intervals = [];
var lastTime = new Date().getTime();
context.old = {};
old.setTimeout = (i,
ii)=> context.setTimeout(i,
ii);
old.setInterval = (i,
ii) =>context.setInterval(i,
ii);
old.clearTimeout = (i) =>context.clearTimeout(i);
old.clearInterval = (i) =>context.clearInterval(i);
if
(typeof(context.postMessage) == 'function')
{
context.setTimeout = function(fn, millis) {
var id = timeouts.length
timeouts[id] = {
id: id,func: fn, delay: millis,started: new Date().getTime()
};
old.setTimeout = (i,
ii) => context.setTimeout(i,
ii);
old.setInterval = (i,
ii) => context.setInterval(i,
ii);
old.clearTimeout = (i) =>
context.clearTimeout(i);
old.clearInterval = (i) =>
context.clearInterval(i);
if
(typeof (context.postMessage) == 'function')
{
context.setTimeout = function
(fn, millis) {
var id = timeouts.length
timeouts[id] = {
id: id, func: fn, delay: millis, started: new Date().getTime()
};
return id;
};
context.clearTimeout = function(cancel) {
for
(var i in timeouts)
{
if
(timeouts[i].id == cancel)
{
timeouts.splice(i,1);
context.clearTimeout = function
(cancel) {
for
(var i in timeouts)
{
if
(timeouts[i].id == cancel)
{
timeouts.splice(i,
1);
break;
}
}
};
context.setInterval = function
(fn, delay
) {
intervals[intervals.length] = {
func: fn, delay: delay,last: new Date().getTime()
};
return intervals[intervals.length
-
1];
context.setInterval = function
(fn, delay
) {
intervals[intervals.length] = {
func: fn, delay: delay, last: new Date().getTime()
};
return intervals[intervals.length
-
1];
};
context.clearInterval = function(cancel) {
for
(var i in intervals)
{
if
(intervals[i] == cancel)
{
intervals.splice(i,1);
context.clearInterval = function
(cancel) {
for
(var i in intervals)
{
if
(intervals[i] == cancel)
{
intervals.splice(i,
1);
break;
}
}
};
}
context.requestAnimationFrame = function
( callback, element
) {
lafcb = {
started: new Date().getTime()/1000,func: callback
};
context.requestAnimationFrame = function
(callback, element
) {
lafcb = {
started: new Date().getTime() / 1000, func: callback
};
var currTime = new Date().getTime();
var timeToCall = 16;
var id = context.setTimeout(
function
() {
callback(
currTime+
timeToCall);
}, timeToCall
);
var id = context.setTimeout(
function
() {
callback(
currTime +
timeToCall);
}, timeToCall);
return id;
};
context.cancelAnimationFrame = function
( id
) {
lafcb
context.clearTimeout(
id
);
context.cancelAnimationFrame = function
(id
) {
lafcb
context.clearTimeout(
id
);
};
context.addEventListener("load",
function()
{
if
(typeof(context.postMessage) == 'function')
{
context.addEventListener("load",
function ()
{
if
(typeof (context.postMessage) == 'function')
{
context.postMessage('tick', '*');
}
else
{
}
else
{
context.setTimeout = old.setTimeout
context.setInterval = old.setInterval
context.clearTimeout = old.clearTimeout
...
...
server.js
View file @
9f7bd07c
...
...
@@ -2,6 +2,7 @@ var express = require('express');
var
app
=
express
();
var
server
=
require
(
'
http
'
).
Server
(
app
);
var
io
=
require
(
'
socket.io
'
).
listen
(
server
);
var
GameServer
=
require
(
'
./GameServer
'
);
app
.
use
(
'
/css
'
,
express
.
static
(
__dirname
+
'
/css
'
));
app
.
use
(
'
/js
'
,
express
.
static
(
__dirname
+
'
/js
'
));
...
...
@@ -13,103 +14,75 @@ app.get('/', function(req, res) {
// http 기본 포트(80)에 서버 열기
server
.
listen
(
80
,
function
()
{
console
.
log
(
'
Listening on port
'
+
server
.
address
().
port
);
console
.
log
(
'
[SERVER]
Listening on port
'
+
server
.
address
().
port
);
});
var
GameServer
=
GameServer
||
{};
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
GameServer
.
getPlayerNumber
=
function
()
{
do
{
var
num
=
Math
.
floor
(
Math
.
random
()
*
1000
+
1
);
if
(
!
this
.
currentPlayer
.
includes
(
num
))
return
num
;
}
while
(
true
)
}
GameServer
.
findPlayer
=
function
(
playerId
)
{
var
idx
=
this
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
socket
;
});
if
(
idx
!=
-
1
)
return
this
.
currentPlayer
[
idx
];
else
{
console
.
log
(
'
[ERR] wrong playerId to find
'
);
return
null
;
}
}
GameServer
.
nextRoomNumber
=
0
;
GameServer
.
makeRoom
=
function
()
{
var
roomOption
=
{
roomNum
:
GameServer
.
nextRoomNumber
++
,
maxPlayer
:
25
,
currentPlayer
:
[]
}
this
.
playingRoom
.
push
(
roomOption
);
console
.
log
(
'
new room made, roomCount:
'
+
this
.
playingRoom
.
length
);
return
this
.
playingRoom
.
length
-
1
;
}
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
this
.
playingRoom
[
roomIdx
].
currentPlayer
.
push
(
playerData
);
console
.
log
(
playerData
.
id
+
'
entered to room#
'
+
this
.
playingRoom
[
roomIdx
].
roomNum
);
return
this
.
playingRoom
[
roomIdx
];
}
GameServer
.
enterEmptyRoom
=
function
(
playerData
)
{
var
toEnter
=
-
1
;
for
(
let
i
=
0
;
i
<
this
.
playingRoom
.
length
;
i
++
)
{
if
(
this
.
playingRoom
[
i
].
currentPlayer
.
length
<
this
.
playingRoom
[
i
].
maxPlayer
)
{
toEnter
=
i
;
break
;
}
}
if
(
toEnter
===
-
1
)
{
toEnter
=
this
.
makeRoom
();
}
return
this
.
enterRoom
(
toEnter
,
playerData
);
}
// 클라이언트 요청에 대한 콜백 정의
io
.
on
(
'
connection
'
,
function
(
socket
)
{
socket
.
on
(
'
idRequest
'
,
function
()
{
var
playerSocket
=
socket
.
playerData
=
{
id
:
GameServer
.
getPlayerNumber
(),
nickname
:
'
게스트
'
,
socketId
:
socket
}
GameServer
.
currentPlayer
.
push
(
playerSocket
);
console
.
log
(
'
client request, id:
'
+
playerSocket
.
id
);
socketId
:
socket
,
currentRoom
:
null
,
playerTyping
:
0
};
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
socket
.
emit
(
'
idSet
'
,
{
str
:
'
your number is
'
+
playerSocket
.
id
+
'
, your nickname is
'
+
playerSocket
.
nickname
,
num
:
playerSocket
.
id
str
:
'
your number is
'
+
socket
.
playerData
.
id
,
num
:
socket
.
playerData
.
id
});
GameServer
.
enterEmptyRoom
(
playerSocket
);
});
socket
.
on
(
'
setNickname
'
,
function
(
msg
)
// string new_nickname
{
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
GameServer
.
enterEmptyRoom
(
socket
.
playerData
);
});
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
{
socket
.
playerData
.
playerTyping
=
msg
;
//console.log(socket.playerData.currentRoom);
console
.
log
(
socket
.
playerData
.
currentRoom
.
currentPlayer
.
length
);
//let playerTypingRate = (msg - (socket.playerData.currentRoom.minTypingPlayer.playerTyping - socket.playerData.currentRoom.rateArrangePoint)) /
//(socket.playerData.currentRoom.maxTypingPlayer.playerTyping - socket.playerData.currentRoom.minTypingPlayer.playerTyping + socket.playerData.currentRoom.rateArrangePoint * 2);
//socket.emit('setPlayerTypingRate', playerTypingRate);
});
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
{
var
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
socketId
===
socket
;
}
);
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
socket
.
playerData
.
id
;
});
if
(
idxToDel
!=
-
1
)
{
console
.
log
(
'
client disconnected, id:
'
+
GameServer
.
currentPlayer
[
idxToDel
].
id
+
'
, reason:
'
+
reason
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client disconnected
, reason:
'
+
reason
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
if
(
socket
.
playerData
.
currentRoom
!=
null
)
{
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
socket
.
playerData
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
{
id
:
socket
.
playerData
.
id
,
nickname
:
socket
.
playerData
.
nickname
});
let
_idxToDel
=
socket
.
playerData
.
currentRoom
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
id
===
socket
.
playerData
.
id
;
});
if
(
idxToDel
!=
-
1
)
{
socket
.
playerData
.
currentRoom
.
currentPlayer
.
splice
(
_idxToDel
,
1
);
}
}
}
});
});
\ No newline at end of file
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