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
47bb8f98
Commit
47bb8f98
authored
Jul 10, 2019
by
18류지석
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'server'
parents
13860f74
9ff5a83c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
27 deletions
+84
-27
GameServer.js
GameServer.js
+29
-7
Client.js
js/Client.js
+8
-0
Input.js
js/Input.js
+1
-2
WordObject.js
js/WordObject.js
+1
-1
server.js
server.js
+45
-17
No files found.
GameServer.js
View file @
47bb8f98
var
GameServer
=
GameServer
||
{};
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
Phase
=
{
READY
:
0
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
startCount
=
4
;
GameServer
.
startCount
=
2
;
GameServer
.
currentPlayer
=
[];
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
GameServer
.
playingRoom
=
[];
...
@@ -57,14 +57,32 @@ GameServer.findRoomIndex = function(roomNum)
...
@@ -57,14 +57,32 @@ GameServer.findRoomIndex = function(roomNum)
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
GameServer
.
enterRoom
=
function
(
roomIdx
,
playerData
)
{
{
let
room
=
this
.
playingRoom
[
roomIdx
];
let
room
=
this
.
playingRoom
[
roomIdx
];
let
player
=
new
Player
(
room
.
currentPlayer
.
length
,
playerData
);
let
nextIdx
=
-
1
;
for
(
let
i
=
0
;
i
<
room
.
currentPlayer
.
length
;
i
++
)
{
if
(
room
.
currentPlayer
[
i
]
===
null
)
{
nextIdx
=
i
;
break
}
}
let
player
=
new
Player
((
nextIdx
!=
-
1
?
nextIdx
:
room
.
currentPlayer
.
length
),
playerData
);
if
(
nextIdx
!=
-
1
)
{
room
.
currentPlayer
[
nextIdx
]
=
player
;
room
.
currentSocket
[
nextIdx
]
=
playerData
;
}
else
{
room
.
currentPlayer
.
push
(
player
);
room
.
currentPlayer
.
push
(
player
);
room
.
currentSocket
.
push
(
playerData
);
room
.
currentSocket
.
push
(
playerData
);
}
playerData
.
playingData
=
player
;
playerData
.
playingData
=
player
;
playerData
.
currentRoom
=
room
;
playerData
.
currentRoom
=
room
;
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
room
.
roomNum
);
console
.
log
(
'
[
'
+
playerData
.
id
+
'
] entered to room #
'
+
room
.
roomNum
);
playerData
.
socketId
.
emit
(
'
enterRoom
'
);
if
(
room
.
currentPlayer
.
length
>=
this
.
startCount
)
GameServer
.
startRoom
(
roomIdx
);
if
(
room
.
currentPlayer
.
length
>=
this
.
startCount
)
GameServer
.
startRoom
(
roomIdx
);
return
room
;
return
room
;
}
}
...
@@ -91,6 +109,10 @@ GameServer.startRoom = function(roomIdx)
...
@@ -91,6 +109,10 @@ GameServer.startRoom = function(roomIdx)
room
.
currentPhase
=
this
.
Phase
.
START
;
room
.
currentPhase
=
this
.
Phase
.
START
;
room
.
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
maxTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
minTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
minTypingPlayer
=
room
.
currentPlayer
[
0
];
room
.
currentSocket
.
forEach
(
function
(
element
)
{
element
.
isReceivable
=
true
;
});
// sync roomData
// sync roomData
let
toSync
=
let
toSync
=
...
@@ -98,10 +120,10 @@ GameServer.startRoom = function(roomIdx)
...
@@ -98,10 +120,10 @@ GameServer.startRoom = function(roomIdx)
roomNum
:
room
.
roomNum
,
roomNum
:
room
.
roomNum
,
players
:
room
.
currentPlayer
players
:
room
.
currentPlayer
};
};
console
.
log
(
toSync
);
//
console.log(toSync);
this
.
announceToRoom
(
roomIdx
,
'
syncRoomData
'
,
toSync
);
this
.
announceToRoom
(
roomIdx
,
'
syncRoomData
'
,
toSync
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start
'
);
console
.
log
(
'
[ROOM#
'
+
room
.
roomNum
+
'
] Game Start
with
'
+
room
.
currentPlayer
.
length
+
'
players
'
);
this
.
announceToRoom
(
roomIdx
,
'
changePhase
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
changePhase
'
,
this
.
Phase
.
START
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
this
.
announceToRoom
(
roomIdx
,
'
startGame
'
);
}
}
...
@@ -118,7 +140,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul
...
@@ -118,7 +140,7 @@ GameServer.announceToTarget = function(roomIdx, targetNum, _message, _data = nul
{
{
return
element
.
id
===
targetNum
;
return
element
.
id
===
targetNum
;
});
});
if
(
targetSocket
!=
undefined
)
targetSocket
.
socketId
.
emit
(
_message
,
_data
);
if
(
targetSocket
!=
undefined
&&
targetSocket
.
isReceivable
)
targetSocket
.
socketId
.
emit
(
_message
,
_data
);
}
}
// 데이터 동기화 함수 만들기
// 데이터 동기화 함수 만들기
// 동기화할것: 유저리스트(id - nickname 쌍)
// 동기화할것: 유저리스트(id - nickname 쌍)
...
...
js/Client.js
View file @
47bb8f98
...
@@ -7,6 +7,14 @@ socket.on('setId', function(msg) // {str, num playerNum}
...
@@ -7,6 +7,14 @@ socket.on('setId', function(msg) // {str, num playerNum}
console
.
log
(
msg
.
str
);
console
.
log
(
msg
.
str
);
PlayerData
.
idNum
=
msg
.
num
;
PlayerData
.
idNum
=
msg
.
num
;
});
});
socket
.
on
(
'
errNicknameOverlaped
'
,
function
()
{
alert
(
'
이미 사용중인 닉네임입니다.
'
);
});
socket
.
on
(
'
enterRoom
'
,
function
()
{
game
.
scene
.
remove
(
'
menuScene
'
);
});
// init game
// init game
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
socket
.
on
(
'
syncRoomData
'
,
function
(
msg
)
// {num roomNum, [] players}
...
...
js/Input.js
View file @
47bb8f98
...
@@ -26,12 +26,11 @@ Input.gameSceneEnterReaction = function()
...
@@ -26,12 +26,11 @@ Input.gameSceneEnterReaction = function()
Input
.
menuSceneEnterReaction
=
function
()
Input
.
menuSceneEnterReaction
=
function
()
{
{
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
Input
.
convInput
=
Input
.
removeConVow
(
Input
.
convInput
);
if
(
Input
.
convInput
.
length
>
0
)
if
(
Input
.
convInput
.
length
>
1
)
{
{
socket
.
emit
(
'
setNickname
'
,
Input
.
convInput
);
socket
.
emit
(
'
setNickname
'
,
Input
.
convInput
);
PlayerData
.
nickname
=
Input
.
convInput
;
PlayerData
.
nickname
=
Input
.
convInput
;
Input
.
reset
();
Input
.
reset
();
game
.
scene
.
remove
(
'
menuScene
'
);
}
}
else
else
{
{
...
...
js/WordObject.js
View file @
47bb8f98
...
@@ -14,7 +14,7 @@ class WordObject
...
@@ -14,7 +14,7 @@ class WordObject
instantiate
(
scene
,
lenRate
)
instantiate
(
scene
,
lenRate
)
{
{
let
p
=
[{
x
:
3
,
y
:
0.7
},
{
x
:
20
,
y
:
1.
8
}];
let
p
=
[{
x
:
3
,
y
:
0.7
},
{
x
:
20
,
y
:
1.
2
}];
let
scale
=
((
p
[
1
].
y
-
p
[
0
].
y
)
/
(
p
[
1
].
x
-
p
[
0
].
x
))
*
(
this
.
wordWeight
-
p
[
0
].
x
)
+
p
[
0
].
y
;
let
scale
=
((
p
[
1
].
y
-
p
[
0
].
y
)
/
(
p
[
1
].
x
-
p
[
0
].
x
))
*
(
this
.
wordWeight
-
p
[
0
].
x
)
+
p
[
0
].
y
;
let
fontscale
=
25
;
let
fontscale
=
25
;
var
random
=
WordSpace
.
getSpawnPoint
(
lenRate
);
var
random
=
WordSpace
.
getSpawnPoint
(
lenRate
);
...
...
server.js
View file @
47bb8f98
...
@@ -28,8 +28,7 @@ io.on('connection', function(socket)
...
@@ -28,8 +28,7 @@ io.on('connection', function(socket)
socketId
:
socket
,
socketId
:
socket
,
currentRoom
:
null
,
currentRoom
:
null
,
playingData
:
null
,
playingData
:
null
,
isReceivable
:
false
playerTyping
:
0
};
};
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
GameServer
.
currentPlayer
.
push
(
socket
.
playerData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client request
'
);
...
@@ -41,10 +40,20 @@ io.on('connection', function(socket)
...
@@ -41,10 +40,20 @@ io.on('connection', function(socket)
});
});
socket
.
on
(
'
setNickname
'
,
function
(
msg
)
// string new_nickname
socket
.
on
(
'
setNickname
'
,
function
(
msg
)
// string new_nickname
{
let
isAlreadyHave
=
false
;
GameServer
.
currentPlayer
.
forEach
(
function
(
element
)
{
if
(
element
.
nickname
===
msg
)
isAlreadyHave
=
true
;
});
if
(
isAlreadyHave
)
socket
.
emit
(
'
errNicknameOverlaped
'
);
else
{
{
socket
.
playerData
.
nickname
=
msg
;
socket
.
playerData
.
nickname
=
msg
;
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] nickname set to
'
+
msg
);
GameServer
.
enterEmptyRoom
(
socket
.
playerData
);
GameServer
.
enterEmptyRoom
(
socket
.
playerData
);
}
});
});
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
socket
.
on
(
'
setPlayerTyping
'
,
function
(
msg
)
// number playerTyping
...
@@ -72,29 +81,48 @@ io.on('connection', function(socket)
...
@@ -72,29 +81,48 @@ io.on('connection', function(socket)
{
{
socket
.
playerData
.
playingData
.
isAlive
=
false
;
socket
.
playerData
.
playingData
.
isAlive
=
false
;
socket
.
playerData
.
playingData
.
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
socket
.
playerData
.
playingData
.
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
socket
.
playerData
.
isReceivable
=
false
;
// 패배단어 체크
// 패배단어 체크
GameServer
.
announceToRoom
(
socket
.
playerData
.
currentRoom
.
roomNum
,
'
defeat
'
,
socket
.
playerData
.
playingData
);
GameServer
.
announceToRoom
(
socket
.
playerData
.
currentRoom
.
roomNum
,
'
defeat
'
,
socket
.
playerData
.
playingData
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
]
'
+
'
defeated
'
);
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
]
'
+
'
defeated
'
);
});
});
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
{
let
data
=
socket
.
playerData
;
console
.
log
(
'
[
'
+
data
.
id
+
'
] client disconnected, reason:
'
+
reason
);
if
(
typeof
data
.
id
===
undefined
)
{
console
.
log
(
'
[ERROR] data.id is undefined
'
);
console
.
log
(
GameServer
.
currentPlayer
);
}
else
// data.id is not undefined
{
{
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
{
return
element
.
id
===
socket
.
playerD
ata
.
id
;
return
element
.
id
===
d
ata
.
id
;
});
});
if
(
idxToDel
!=
-
1
)
if
(
idxToDel
!=
-
1
)
{
{
console
.
log
(
'
[
'
+
socket
.
playerData
.
id
+
'
] client disconnected, reason:
'
+
reason
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
// 룸에서도 제거
// 룸에서도 제거
if
(
socket
.
playerD
ata
.
currentRoom
!=
null
)
if
(
d
ata
.
currentRoom
!=
null
)
{
{
socket
.
playerData
.
playingData
.
isAlive
=
false
;
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
)
if
(
socket
.
playerData
.
playingData
.
rank
===
-
1
)
socket
.
playerData
.
playingData
.
rank
=
socket
.
playerData
.
currentRoom
.
nextRank
--
;
{
socket
.
playerData
.
currentRoom
.
currentSocket
.
splice
(
socket
.
playerData
.
playingData
.
index
,
1
);
data
.
currentRoom
.
currentPlayer
[
data
.
playingData
.
index
]
=
null
;
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
socket
.
playerData
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
socket
.
playerData
.
playingData
);
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
]
=
null
;
}
else
{
data
.
playingData
.
isAlive
=
false
;
if
(
data
.
playingData
.
rank
===
-
1
)
data
.
playingData
.
rank
=
data
.
currentRoom
.
nextRank
--
;
data
.
currentRoom
.
currentSocket
[
data
.
playingData
.
index
].
isReceivable
=
false
;
GameServer
.
announceToRoom
(
GameServer
.
findRoomIndex
(
data
.
currentRoom
.
roomNum
),
'
userDisconnect
'
,
data
.
playingData
);
}
}
}
}
console
.
log
(
'
[
'
+
data
.
id
+
'
] disconnect complete
'
);
}
}
});
});
});
});
\ 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