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
379b7204
Commit
379b7204
authored
Aug 13, 2019
by
18신대성
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
서버 안정화
parent
5020b7bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
38 deletions
+50
-38
GameServer.js
GameServer.js
+2
-0
server.js
server.js
+48
-38
No files found.
GameServer.js
View file @
379b7204
var
GameServer
=
GameServer
||
{};
GameServer
.
Phase
=
{
READY
:
0
,
COUNT
:
-
1
,
START
:
1
,
MAIN
:
2
,
MUSIC
:
3
};
GameServer
.
connectCount
=
0
;
GameServer
.
disconnectCount
=
0
;
GameServer
.
currentPlayer
=
[];
GameServer
.
playingRoom
=
[];
...
...
server.js
View file @
379b7204
...
...
@@ -36,6 +36,7 @@ io.on('connection', function(socket)
str
:
'
your number is
'
+
socket
.
playerData
.
id
,
num
:
socket
.
playerData
.
id
});
GameServer
.
connectCount
++
;
});
socket
.
on
(
'
setNickname
'
,
function
(
msg
)
// string new_nickname
...
...
@@ -80,7 +81,7 @@ io.on('connection', function(socket)
socket
.
playerData
.
currentRoom
.
announceToRoom
(
'
attackMode
'
,
socket
.
playerData
.
id
);
}
}
catch
(
e
)
{
console
.
log
(
'
[ERR] error catched on setPlayerTyping
'
)}
catch
(
e
)
{
console
.
error
(
'
[ERR] error catched on setPlayerTyping
'
)}
});
socket
.
on
(
'
endCount
'
,
function
()
...
...
@@ -137,51 +138,60 @@ io.on('connection', function(socket)
socket
.
on
(
'
disconnect
'
,
function
(
reason
)
{
GameServer
.
disconnectCount
++
;
let
data
=
socket
.
playerData
;
if
(
typeof
data
.
id
===
undefined
)
if
(
typeof
data
===
undefined
)
{
console
.
log
(
'
[ERROR] data.id
is undefined
'
);
console
.
log
(
GameServer
.
currentPlayer
);
console
.
error
(
'
[ERROR] data
is undefined
'
);
console
.
table
(
GameServer
.
currentPlayer
);
}
else
// data.id is not undefined
{
console
.
log
(
'
[
'
+
data
.
id
+
'
] client disconnected, reason:
'
+
reason
);
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
playerData
.
id
===
data
.
id
;
});
if
(
idxToDel
!=
-
1
)
disconnectUser
(
data
,
reason
);
}
const
connectDiff
=
GameServer
.
connectCount
-
GameServer
.
disconnectCount
;
const
playerCount
=
GameServer
.
currentPlayer
.
length
console
.
log
({
connectDiff
,
playerCount
});
});
});
var
disconnectUser
=
function
(
data
,
reason
)
{
console
.
log
(
'
[
'
+
data
.
id
+
'
] client disconnected, reason:
'
+
reason
);
let
idxToDel
=
GameServer
.
currentPlayer
.
findIndex
(
function
(
element
)
{
return
element
.
playerData
.
id
===
data
.
id
;
});
if
(
idxToDel
!=
-
1
)
{
// 룸에서도 제거
if
(
data
.
currentRoom
!=
null
)
{
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
{
// 룸에서도 제거
if
(
data
.
currentRoom
!=
null
)
data
.
currentRoom
.
exitRoom
(
data
.
id
);
if
(
data
.
currentRoom
.
aliveCount
<
data
.
currentRoom
.
startCount
)
{
if
(
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
READY
||
data
.
currentRoom
.
currentPhase
===
GameServer
.
Phase
.
COUNT
)
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
data
.
currentRoom
.
exitRoom
(
data
.
id
);
if
(
data
.
currentRoom
.
aliveCount
<
data
.
currentRoom
.
startCount
)
{
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
false
,
endTime
:
0
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
data
.
currentRoom
.
currentPhase
=
GameServer
.
Phase
.
READY
;
}
else
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
data
.
currentRoom
.
endTime
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
}
else
if
(
data
.
playingData
.
isAlive
)
{
data
.
playingData
.
defeat
();
data
.
currentRoom
.
announceToRoom
(
'
userDisconnect
'
,
data
.
playingData
);
}
isEnable
:
false
,
endTime
:
0
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
data
.
currentRoom
.
currentPhase
=
GameServer
.
Phase
.
READY
;
}
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
else
data
.
currentRoom
.
announceToRoom
(
'
setRoomCount
'
,
{
isEnable
:
true
,
endTime
:
data
.
currentRoom
.
endTime
,
playerCount
:
data
.
currentRoom
.
currentPlayer
.
length
,
isEnter
:
false
,
player
:
data
.
playingData
});
}
else
if
(
data
.
playingData
.
isAlive
)
{
data
.
playingData
.
defeat
();
data
.
currentRoom
.
announceToRoom
(
'
userDisconnect
'
,
data
.
playingData
);
}
console
.
log
(
'
[
'
+
data
.
id
+
'
] disconnect complete
'
);
}
});
});
\ No newline at end of file
GameServer
.
currentPlayer
.
splice
(
idxToDel
,
1
);
}
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