Commit 709ef083 authored by 神楽坂玲奈's avatar 神楽坂玲奈

init

parents
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
#################
## Jetbrains
#################
/.idea/
#################
## Node
#################
/node_modules/
\ No newline at end of file
module.exports = {
port: 9997,
servers: [
{ip: '122.0.65.70', port: 7977}
]
}
\ No newline at end of file
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}/#{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)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment