Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-match
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
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
ygopro-match
Commits
624aaed2
Commit
624aaed2
authored
Jan 26, 2016
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
brand new
parent
a242cd83
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
42 deletions
+59
-42
config.js
config.js
+0
-6
main.js
main.js
+55
-0
mycard-server-match.coffee
mycard-server-match.coffee
+0
-36
package.json
package.json
+4
-0
No files found.
config.js
deleted
100644 → 0
View file @
a242cd83
module
.
exports
=
{
port
:
9997
,
servers
:
[
{
ip
:
'
122.0.65.70
'
,
port
:
7977
}
]
}
\ No newline at end of file
main.js
0 → 100644
View file @
624aaed2
/**
* Created by zh99998 on 16/1/25.
*/
const
http
=
require
(
'
http
'
);
const
crypto
=
require
(
'
crypto
'
);
// Create an HTTP tunneling proxy
var
servers
=
[{
"
address
"
:
"
122.0.65.73
"
,
"
port
"
:
233
}];
var
pending
=
null
;
http
.
createServer
((
req
,
res
)
=>
{
try
{
var
credentials
=
new
Buffer
(
req
.
headers
[
'
authorization
'
].
split
(
'
'
)[
1
],
'
base64
'
).
toString
().
split
(
'
:
'
);
var
username
=
credentials
[
0
];
var
password
=
credentials
[
1
];
if
(
!
username
||
!
password
)
{
throw
'
auth
'
;
}
//TODO: Auth
console
.
log
(
username
+
'
requested match.
'
);
}
catch
(
error
)
{
res
.
statusCode
=
403
;
res
.
end
();
return
;
}
if
(
pending
)
{
var
server
=
servers
[
Math
.
floor
(
Math
.
random
()
*
servers
.
length
)];
var
result
=
JSON
.
stringify
({
"
address
"
:
server
.
address
,
"
port
"
:
server
.
port
,
"
password
"
:
crypto
.
randomBytes
(
12
).
toString
(
'
base64
'
)
});
for
(
var
client
of
[
res
,
pending
])
{
client
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
application/json
'
,
'
Cache-Control
'
:
'
no-cache
'
});
client
.
end
(
result
)
}
pending
=
null
;
console
.
log
(
'
matched
'
+
result
);
}
else
{
pending
=
res
;
res
.
on
(
'
close
'
,
()
=>
{
console
.
log
(
'
connection closed.
'
)
if
(
pending
==
res
)
{
pending
=
null
;
}
})
}
}).
listen
(
3001
);
\ No newline at end of file
mycard-server-match.coffee
deleted
100644 → 0
View file @
a242cd83
http
=
require
(
"http"
)
url
=
require
(
"url"
)
_
=
require
(
"underscore"
)
settings
=
require
(
"./config"
)
room_index
=
0
waiting
=
[]
server
=
http
.
createServer
(
request
,
response
)
->
console
.
log
"
#{
new
Date
()
}
Received request for
#{
request
.
url
}
from
#{
request
.
connection
.
remoteAddress
}
)"
if
url
.
parse
(
request
.
url
).
pathname
!=
'/match.json'
response
.
writeHead
(
404
);
response
.
end
();
return
response
.
writeHead
(
200
,
{
"Content-Type"
:
"application/json"
})
if
waiting
.
length
==
0
waiting
.
push
response
request
.
connection
.
addListener
'close'
,
->
index
=
waiting
.
indexOf
(
response
);
if
index
!=
-
1
waiting
.
splice
(
response
,
1
);
console
.
log
"
#{
new
Date
()
}
Peer
#{
request
.
connection
.
remoteAddress
}
disconnected during waiting."
response
.
connection
.
setTimeout
(
0
)
else
s
=
settings
.
servers
[
0
]
room
=
"mycard://
#{
s
.
ip
}
:
#{
s
.
port
}
/M#
#{
room_index
}
$
#{
Math
.
floor
(
Math
.
random
()
*
1000
)
}
"
#new Buffer("Hello World").toString('base64'));
console
.
log
"matched:
#{
room
}
"
opponent_response
=
waiting
.
pop
()
opponent_response
.
end
room
response
.
end
room
room_index
=
room_index
+
1
%
100000
.
listen
(
settings
.
port
)
package.json
0 → 100644
View file @
624aaed2
{
"name"
:
"ygopro-match"
,
"version"
:
"0.0.1"
}
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