Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
srvpro
Commits
b6b8122a
Commit
b6b8122a
authored
Aug 15, 2015
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
for 8.15 weekly game
parent
1423a319
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
105 deletions
+108
-105
room.coffee
room.coffee
+4
-2
room.js
room.js
+4
-2
ygopro-server.coffee
ygopro-server.coffee
+18
-11
ygopro-server.js
ygopro-server.js
+82
-90
No files found.
room.coffee
View file @
b6b8122a
...
...
@@ -54,9 +54,9 @@ class Room
@
status
=
'starting'
@
established
=
false
@
watcher_buffers
=
[]
@
watcher_stanzas
=
[]
#
@watcher_stanzas = []
@
watchers
=
[]
@
ws_watchers
=
[]
#
@ws_watchers = []
Room
.
all
.
push
this
@
hostinfo
=
...
...
@@ -75,6 +75,7 @@ class Room
@
hostinfo
.
mode
=
1
else
if
name
[
0
...
2
]
==
'T#'
@
hostinfo
.
mode
=
2
@
hostinfo
.
start_lp
=
16000
else
if
(
param
=
name
.
match
/^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i
)
@
hostinfo
.
rule
=
parseInt
(
param
[
1
])
@
hostinfo
.
mode
=
parseInt
(
param
[
2
])
...
...
@@ -107,6 +108,7 @@ class Room
@
save_match
()
if
_
.
startsWith
(
@
name
,
'M#'
)
and
@
started
and
settings
.
modules
.
database
index
=
_
.
indexOf
(
Room
.
all
,
this
)
Room
.
all
[
index
]
=
null
unless
index
==
-
1
Room
.
all
.
splice
(
index
,
1
)
unless
index
==
-
1
@
deleted
=
true
...
...
room.js
View file @
b6b8122a
...
...
@@ -72,9 +72,7 @@
this
.
status
=
'
starting
'
;
this
.
established
=
false
;
this
.
watcher_buffers
=
[];
this
.
watcher_stanzas
=
[];
this
.
watchers
=
[];
this
.
ws_watchers
=
[];
Room
.
all
.
push
(
this
);
this
.
hostinfo
=
{
lflist
:
0
,
...
...
@@ -92,6 +90,7 @@
this
.
hostinfo
.
mode
=
1
;
}
else
if
(
name
.
slice
(
0
,
2
)
===
'
T#
'
)
{
this
.
hostinfo
.
mode
=
2
;
this
.
hostinfo
.
start_lp
=
16000
;
}
else
if
((
param
=
name
.
match
(
/^
(\d)(\d)(
T|F
)(
T|F
)(
T|F
)(\d
+
)
,
(\d
+
)
,
(\d
+
)
/i
)))
{
this
.
hostinfo
.
rule
=
parseInt
(
param
[
1
]);
this
.
hostinfo
.
mode
=
parseInt
(
param
[
2
]);
...
...
@@ -143,6 +142,9 @@
this
.
save_match
();
}
index
=
_
.
indexOf
(
Room
.
all
,
this
);
if
(
index
!==
-
1
)
{
Room
.
all
[
index
]
=
null
;
}
if
(
index
!==
-
1
)
{
Room
.
all
.
splice
(
index
,
1
);
}
...
...
ygopro-server.coffee
View file @
b6b8122a
...
...
@@ -18,6 +18,8 @@ request = require 'request'
bunyan
=
require
'bunyan'
#heapdump = require 'heapdump'
#配置文件
settings
=
require
'./config.json'
...
...
@@ -183,6 +185,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code
:
settings
.
version
}
client
.
end
()
else
if
!
info
.
pass
.
length
ygopro
.
stoc_send_chat
(
client
,
"房间为空,请修改房间名"
)
ygopro
.
stoc_send
client
,
'ERROR_MSG'
,{
...
...
@@ -267,15 +270,17 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
}
ygopro
.
ctos_send
watcher
,
'HS_TOOBSERVER'
###
watcher.ws_buffer = new Buffer(0)
watcher.ws_message_length = 0
client.room.watcher_stanzas = []
###
watcher
.
on
'data'
,
(
data
)
->
client
.
room
.
watcher_buffers
.
push
data
for
w
in
client
.
room
.
watchers
w
.
write
data
if
w
#a WTF fix
###
watcher.ws_buffer = Buffer.concat([watcher.ws_buffer, data], watcher.ws_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
while true
...
...
@@ -295,13 +300,14 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
watcher.ws_message_length = 0
else
break
###
watcher
.
on
'error'
,
(
error
)
->
#log.error "watcher error", error
###
watcher.on 'close', (had_error)->
for w in client.room.ws_watchers
w.close()
###
#登场台词
if
settings
.
modules
.
dialogues
...
...
@@ -315,7 +321,7 @@ if settings.modules.dialogues
else
if
error
or
!
body
log
.
warn
'dialogues error'
,
error
,
response
else
log
.
info
"dialogues loaded"
,
_
.
size
body
#
log.info "dialogues loaded", _.size body
dialogues
=
body
ygopro
.
stoc_follow
'GAME_MSG'
,
false
,
(
buffer
,
info
,
client
,
server
)
->
...
...
@@ -533,7 +539,7 @@ if settings.modules.http
for
i
of
level_points
waiting
.
push
[]
log
.
info
'level_points loaded'
,
level_points
#
log.info 'level_points loaded', level_points
http_server
=
http
.
createServer
(
request
,
response
)
->
#http://122.0.65.70:7922/?operation=getroomjson
u
=
url
.
parse
(
request
.
url
,
1
)
...
...
@@ -652,7 +658,7 @@ if settings.modules.http
, 2000
###
###
originIsAllowed = (origin) ->
# allow all origin, for debug
true
...
...
@@ -684,8 +690,8 @@ if settings.modules.http
for stanza in room.watcher_stanzas
connection.sendBytes stanza
###
###
###
connection.on "message", (message) ->
if message.type is "utf8"
console.log "Received Message: " + message.utf8Data
...
...
@@ -693,12 +699,13 @@ if settings.modules.http
else if message.type is "binary"
console.log "Received Binary Message of " + message.binaryData.length + " bytes"
connection.sendBytes message.binaryData
###
###
###
connection.on "close", (reasonCode, description) ->
index = _.indexOf(room.ws_watchers, connection)
room.ws_watchers.splice(index, 1) unless index == -1
console.log (new Date()) + " Peer " + connection.remoteAddress + " disconnected."
###
#清理90s没活动的房间
###
inotify = new Inotify()
...
...
ygopro-server.js
View file @
b6b8122a
// Generated by CoffeeScript 1.9.3
(
function
()
{
var
Deck
,
Room
,
User
,
WebSocketServer
,
_
,
bunyan
,
debug
,
dialogues
,
execFile
,
fs
,
http
,
http_server
,
i
,
level_points
,
log
,
mycard
,
net
,
o
riginIsAllowed
,
os
,
path
,
request
,
settings
,
tips
,
url
,
victories
,
waiting
,
wsServer
,
ygopro
,
var
Deck
,
Room
,
User
,
WebSocketServer
,
_
,
bunyan
,
debug
,
dialogues
,
execFile
,
fs
,
http
,
http_server
,
i
,
level_points
,
log
,
mycard
,
net
,
o
s
,
path
,
request
,
settings
,
tips
,
url
,
victories
,
waiting
,
ygopro
,
indexOf
=
[].
indexOf
||
function
(
item
)
{
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
if
(
i
in
this
&&
this
[
i
]
===
item
)
return
i
;
}
return
-
1
;
};
net
=
require
(
'
net
'
);
...
...
@@ -324,59 +324,56 @@
});
return
ygopro
.
ctos_send
(
watcher
,
'
HS_TOOBSERVER
'
);
});
watcher
.
ws_buffer
=
new
Buffer
(
0
);
watcher
.
ws_message_length
=
0
;
client
.
room
.
watcher_stanzas
=
[];
/*
watcher.ws_buffer = new Buffer(0)
watcher.ws_message_length = 0
client.room.watcher_stanzas = []
*/
watcher
.
on
(
'
data
'
,
function
(
data
)
{
var
j
,
k
,
len
,
len1
,
ref
,
ref1
,
results
,
stanza
,
w
;
var
j
,
len
,
ref
,
results
,
w
;
client
.
room
.
watcher_buffers
.
push
(
data
);
ref
=
client
.
room
.
watchers
;
results
=
[];
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
w
=
ref
[
j
];
if
(
w
)
{
w
.
write
(
data
);
}
}
watcher
.
ws_buffer
=
Buffer
.
concat
([
watcher
.
ws_buffer
,
data
],
watcher
.
ws_buffer
.
length
+
data
.
length
);
results
=
[];
while
(
true
)
{
if
(
watcher
.
ws_message_length
===
0
)
{
if
(
watcher
.
ws_buffer
.
length
>=
2
)
{
results
.
push
(
watcher
.
ws_message_length
=
watcher
.
ws_buffer
.
readUInt16LE
(
0
));
}
else
{
break
;
}
results
.
push
(
w
.
write
(
data
));
}
else
{
if
(
watcher
.
ws_buffer
.
length
>=
2
+
watcher
.
ws_message_length
)
{
stanza
=
watcher
.
ws_buffer
.
slice
(
2
,
watcher
.
ws_message_length
+
2
);
ref1
=
client
.
room
.
ws_watchers
;
for
(
k
=
0
,
len1
=
ref1
.
length
;
k
<
len1
;
k
++
)
{
w
=
ref1
[
k
];
if
(
w
)
{
w
.
sendBytes
(
stanza
);
}
}
client
.
room
.
watcher_stanzas
.
push
(
stanza
);
watcher
.
ws_buffer
=
watcher
.
ws_buffer
.
slice
(
2
+
watcher
.
ws_message_length
);
results
.
push
(
watcher
.
ws_message_length
=
0
);
}
else
{
break
;
}
results
.
push
(
void
0
);
}
}
return
results
;
});
watcher
.
on
(
'
error
'
,
function
(
error
)
{});
return
watcher
.
on
(
'
close
'
,
function
(
had_error
)
{
var
j
,
len
,
ref
,
results
,
w
;
ref
=
client
.
room
.
ws_watchers
;
results
=
[];
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
w
=
ref
[
j
];
results
.
push
(
w
.
close
());
}
return
results
;
});
/*
watcher.ws_buffer = Buffer.concat([watcher.ws_buffer, data], watcher.ws_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
while true
if watcher.ws_message_length == 0
if watcher.ws_buffer.length >= 2
watcher.ws_message_length = watcher.ws_buffer.readUInt16LE(0)
else
break
else
if watcher.ws_buffer.length >= 2 + watcher.ws_message_length
stanza = watcher.ws_buffer.slice(2, watcher.ws_message_length + 2)
for w in client.room.ws_watchers
w.sendBytes stanza if w #a WTF fix
client.room.watcher_stanzas.push stanza
watcher.ws_buffer = watcher.ws_buffer.slice(2 + watcher.ws_message_length)
watcher.ws_message_length = 0
else
break
*/
return
watcher
.
on
(
'
error
'
,
function
(
error
)
{});
/*
watcher.on 'close', (had_error)->
for w in client.room.ws_watchers
w.close()
*/
}
});
...
...
@@ -391,7 +388,6 @@
}
else
if
(
error
||
!
body
)
{
return
log
.
warn
(
'
dialogues error
'
,
error
,
response
);
}
else
{
log
.
info
(
"
dialogues loaded
"
,
_
.
size
(
body
));
return
dialogues
=
body
;
}
});
...
...
@@ -674,7 +670,6 @@
for
(
i
in
level_points
)
{
waiting
.
push
([]);
}
log
.
info
(
'
level_points loaded
'
,
level_points
);
http_server
=
http
.
createServer
(
function
(
request
,
response
)
{
var
j
,
len
,
level
,
name
,
password
,
player
,
ref
,
ref1
,
ref2
,
room
,
roomsjson
,
u
;
u
=
url
.
parse
(
request
.
url
,
1
);
...
...
@@ -861,43 +856,42 @@
, 2000
*/
originIsAllowed
=
function
(
origin
)
{
return
true
;
};
wsServer
=
new
WebSocketServer
({
httpServer
:
http_server
,
/*
originIsAllowed = (origin) ->
* allow all origin, for debug
true
wsServer = new WebSocketServer(
httpServer: http_server
autoAcceptConnections: false
});
wsServer
.
on
(
"
request
"
,
function
(
request
)
{
var
connection
,
j
,
len
,
ref
,
room
,
room_name
,
stanza
;
if
(
!
originIsAllowed
(
request
.
origin
))
{
request
.
reject
();
console
.
log
((
new
Date
())
+
"
Connection from origin
"
+
request
.
origin
+
"
rejected.
"
);
return
;
}
room_name
=
decodeURIComponent
(
request
.
resource
.
slice
(
1
));
if
(
room_name
===
'
started
'
)
{
room
=
_
.
find
(
Room
.
all
,
function
(
room
)
{
return
room
.
started
;
});
}
else
{
room
=
Room
.
find_by_name
(
room_name
);
}
if
(
!
room
)
{
request
.
reject
();
console
.
log
((
new
Date
())
+
"
Connection from origin
"
+
request
.
origin
+
(
"
rejected.
"
+
room_name
));
return
;
}
connection
=
request
.
accept
(
null
,
request
.
origin
);
console
.
log
((
new
Date
())
+
(
"
Connection accepted.
"
+
room
.
name
));
room
.
ws_watchers
.
push
(
connection
);
ref
=
room
.
watcher_stanzas
;
for
(
j
=
0
,
len
=
ref
.
length
;
j
<
len
;
j
++
)
{
stanza
=
ref
[
j
];
connection
.
sendBytes
(
stanza
);
}
)
wsServer.on "request", (request) ->
unless originIsAllowed(request.origin)
* Make sure we only accept requests from an allowed origin
request.reject()
console.log (new Date()) + " Connection from origin " + request.origin + " rejected."
return
room_name = decodeURIComponent(request.resource.slice(1))
if room_name == 'started'
room = _.find Room.all, (room)->
room.started
else
room = Room.find_by_name room_name
unless room
request.reject()
console.log (new Date()) + " Connection from origin " + request.origin + " rejected. #{room_name}"
return
connection = request.accept(null, request.origin)
console.log (new Date()) + " Connection accepted. #{room.name}"
room.ws_watchers.push connection
for stanza in room.watcher_stanzas
connection.sendBytes stanza
*/
/*
/*
connection.on "message", (message) ->
if message.type is "utf8"
console.log "Received Message: " + message.utf8Data
...
...
@@ -905,16 +899,14 @@
else if message.type is "binary"
console.log "Received Binary Message of " + message.binaryData.length + " bytes"
connection.sendBytes message.binaryData
*/
return
connection
.
on
(
"
close
"
,
function
(
reasonCode
,
description
)
{
var
index
;
index
=
_
.
indexOf
(
room
.
ws_watchers
,
connection
);
if
(
index
!==
-
1
)
{
room
.
ws_watchers
.
splice
(
index
,
1
);
}
return
console
.
log
((
new
Date
())
+
"
Peer
"
+
connection
.
remoteAddress
+
"
disconnected.
"
);
});
});
*/
/*
connection.on "close", (reasonCode, description) ->
index = _.indexOf(room.ws_watchers, connection)
room.ws_watchers.splice(index, 1) unless index == -1
console.log (new Date()) + " Peer " + connection.remoteAddress + " disconnected."
*/
}
...
...
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