Skip to content

Commit fb2ac8a

Browse files
wavetrywavetry
authored andcommitted
commit change files
1 parent 6b00823 commit fb2ac8a

1,983 files changed

Lines changed: 215932 additions & 100 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

js/node_modules/express

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/node_modules/socket.io

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/test.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
2+
// var http = require("http")
3+
4+
// http.createServer(function (request , response) {
5+
// response.writeHead(200,{
6+
// "Content-Type" : "text/plain"
7+
// });
8+
// response.write("Welcome to Nodejs");
9+
// response.end();
10+
11+
// }).listen(8000,"127.0.0.1");
12+
// console.log("Create server on localhost");
13+
14+
'use strict'
15+
16+
let app = require('express')();
17+
let server = require('http').Server(app);
18+
let io = require('socket.io')(server);
19+
20+
server.listen(4747, function() {
21+
console.log('listening on:4747');
22+
});
23+
24+
let MAX = 30;//最大支持连接房间数
25+
let hall = null;//大厅
26+
let queue = null;//匹配队列
27+
let rooms = [];//游戏房间
28+
29+
function Hall() {
30+
this.people = 0;
31+
this.socket = null;
32+
}
33+
34+
function Room(){
35+
this.people = 0;
36+
this.socket = null;
37+
}
38+
39+
function Queue(){
40+
this.people = 0;
41+
this.socket = null;
42+
}
43+
44+
hall = new Hall();
45+
46+
queue = new Queue();
47+
48+
for(let n = 0;n < MAX;n++){
49+
rooms[n] = new Room();
50+
}
51+
52+
function getFreeRoom(){
53+
for(let n = 0;n < MAX;n++){
54+
if(rooms[n].people === 0){
55+
return n;
56+
}
57+
}
58+
return -1;
59+
}
60+
61+
io.people = 0;
62+
io.on('connection',function(socket){
63+
io.people++;
64+
console.log('someone connected');
65+
socket.on('disconnect',function(){
66+
io.people--;
67+
console.log('someone disconnected');
68+
});
69+
})
70+
71+
hall.socket = io.of('/hall').on('connection', function(socket) {
72+
73+
hall.people++;
74+
75+
console.log('a player connected.There are '+hall.people+' people in hall');
76+
77+
hall.socket.emit('people changed',hall.people);
78+
79+
socket.on('disconnect',function(){
80+
hall.people--;
81+
console.log('a player disconnected.There are '+hall.people+' people in hall');
82+
hall.socket.emit('people changed',hall.people);
83+
});
84+
});
85+
86+
queue.socket = io.of('/queue').on('connection',function(socket){
87+
88+
queue.people++;
89+
90+
console.log('someone connect queue socket.There are '+queue.people+' people in queue');
91+
92+
if(queue.people === 1){
93+
socket.emit('set stand','black');
94+
}else if(queue.people === 2){
95+
socket.emit('set stand','white');
96+
let roomId = getFreeRoom();
97+
console.log(roomId+"roomId");
98+
if(roomId >= 0){
99+
queue.socket.emit('match success',roomId);
100+
console.log('match success.There are '+queue.people+' people in queue');
101+
}else{
102+
console.log('no free room!');
103+
}
104+
}
105+
106+
socket.on('cancel match',function(){
107+
queue.people--;
108+
console.log('someone cancel match.There are '+queue.people+' people in queue');
109+
});
110+
111+
socket.on('disconnect',function(){
112+
queue.people--;
113+
console.log('someone disconnected match.There are '+queue.people+' people in queue');
114+
});
115+
116+
});
117+
118+
for(let i = 0;i < MAX;i++){
119+
rooms[i].socket = io.of('/rooms'+i).on('connection',function(socket){
120+
121+
rooms[i].people++;
122+
console.log('some one connected room'+i+'.There are '+rooms[i].people+' people in the room');
123+
124+
socket.on('update chessboard',function(chessCoor){
125+
socket.broadcast.emit('update chessboard',chessCoor);
126+
});
127+
128+
socket.on('force change turn',function(){
129+
socket.broadcast.emit('force change turn');
130+
});
131+
132+
socket.on('disconnect',function(){
133+
rooms[i].people--;
134+
console.log('someone disconnected room'+i+'.There are '+rooms[i].people+' people in the room');
135+
});
136+
137+
});
138+
}

lua/b2

263 KB
Binary file not shown.

lua/bjam

263 KB
Binary file not shown.

lua/bootstrap.log

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
###
2+
### Using 'darwin' toolset.
3+
###
4+
rm -rf bootstrap
5+
mkdir bootstrap
6+
cc -o bootstrap/jam0 command.c compile.c constants.c debug.c execcmd.c frames.c function.c glob.c hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c object.c option.c output.c parse.c pathsys.c regexp.c rules.c scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c class.c cwd.c native.c md5.c w32_getreg.c modules/set.c modules/path.c modules/regex.c modules/property-set.c modules/sequence.c modules/order.c execunix.c fileunix.c pathunix.c
7+
./bootstrap/jam0 -f build.jam --toolset=darwin --toolset-root= clean
8+
...found 1 target...
9+
...updating 1 target...
10+
...updated 1 target...
11+
./bootstrap/jam0 -f build.jam --toolset=darwin --toolset-root=
12+
...found 160 targets...
13+
...updating 3 targets...
14+
[MKDIR] bin.macosxx86_64
15+
[COMPILE] bin.macosxx86_64/b2
16+
clang: warning: optimization flag '-finline-functions' is not supported
17+
clang: warning: optimization flag '-finline-functions' is not supported
18+
clang: warning: optimization flag '-finline-functions' is not supported
19+
clang: warning: optimization flag '-finline-functions' is not supported
20+
clang: warning: optimization flag '-finline-functions' is not supported
21+
clang: warning: optimization flag '-finline-functions' is not supported
22+
clang: warning: optimization flag '-finline-functions' is not supported
23+
clang: warning: optimization flag '-finline-functions' is not supported
24+
clang: warning: optimization flag '-finline-functions' is not supported
25+
clang: warning: optimization flag '-finline-functions' is not supported
26+
clang: warning: optimization flag '-finline-functions' is not supported
27+
clang: warning: optimization flag '-finline-functions' is not supported
28+
clang: warning: optimization flag '-finline-functions' is not supported
29+
clang: warning: optimization flag '-finline-functions' is not supported
30+
clang: warning: optimization flag '-finline-functions' is not supported
31+
clang: warning: optimization flag '-finline-functions' is not supported
32+
clang: warning: optimization flag '-finline-functions' is not supported
33+
clang: warning: optimization flag '-finline-functions' is not supported
34+
clang: warning: optimization flag '-finline-functions' is not supported
35+
clang: warning: optimization flag '-finline-functions' is not supported
36+
clang: warning: optimization flag '-finline-functions' is not supported
37+
clang: warning: optimization flag '-finline-functions' is not supported
38+
clang: warning: optimization flag '-finline-functions' is not supported
39+
clang: warning: optimization flag '-finline-functions' is not supported
40+
clang: warning: optimization flag '-finline-functions' is not supported
41+
clang: warning: optimization flag '-finline-functions' is not supported
42+
clang: warning: optimization flag '-finline-functions' is not supported
43+
clang: warning: optimization flag '-finline-functions' is not supported
44+
clang: warning: optimization flag '-finline-functions' is not supported
45+
clang: warning: optimization flag '-finline-functions' is not supported
46+
clang: warning: optimization flag '-finline-functions' is not supported
47+
clang: warning: optimization flag '-finline-functions' is not supported
48+
clang: warning: optimization flag '-finline-functions' is not supported
49+
clang: warning: optimization flag '-finline-functions' is not supported
50+
clang: warning: optimization flag '-finline-functions' is not supported
51+
clang: warning: optimization flag '-finline-functions' is not supported
52+
clang: warning: optimization flag '-finline-functions' is not supported
53+
clang: warning: optimization flag '-finline-functions' is not supported
54+
clang: warning: optimization flag '-finline-functions' is not supported
55+
clang: warning: optimization flag '-finline-functions' is not supported
56+
clang: warning: optimization flag '-finline-functions' is not supported
57+
clang: warning: optimization flag '-finline-functions' is not supported
58+
clang: warning: optimization flag '-finline-functions' is not supported
59+
clang: warning: optimization flag '-finline-functions' is not supported
60+
clang: warning: optimization flag '-finline-functions' is not supported
61+
clang: warning: optimization flag '-finline-functions' is not supported
62+
clang: warning: optimization flag '-finline-functions' is not supported
63+
clang: warning: optimization flag '-finline-functions' is not supported
64+
clang: warning: optimization flag '-finline-functions' is not supported
65+
clang: warning: optimization flag '-finline-functions' is not supported
66+
[COPY] bin.macosxx86_64/bjam
67+
...updated 3 targets...

lua/client.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--
2+
-- Author: Deadline
3+
-- Date: 2017-09-05 11:45:57
4+
--
5+
package.path = '/Users/diego/build/macosx/share/lua/5.1/?.lua;'
6+
package.cpath = '/Users/diego/build/macosx/lib/lua/5.1/?.so;'
7+
local socket = require("socket")
8+
local host = "127.0.0.1"
9+
-- local host = "10.20.202.169"
10+
local port = 8888
11+
local sock = assert(socket.connect(host, port))
12+
sock:settimeout(0)
13+
14+
function main()
15+
print("Press enter after input something:")
16+
local input, recvt, sendt, status
17+
while true do
18+
input = io.read()
19+
if #input > 0 then
20+
assert(sock:send(input .. "\n"))
21+
end
22+
recvt, sendt, status = socket.select({sock}, nil, 1)
23+
while #recvt > 0 do
24+
local response, receive_status = sock:receive()
25+
if receive_status ~= "closed" then
26+
if response then
27+
print ('recv from server:'..response)
28+
recvt, sendt, status = socket.select({sock}, nil, 1)
29+
end
30+
else
31+
break
32+
end
33+
end
34+
end
35+
end
36+
main()

lua/coro.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--
2+
-- Author: Deadline
3+
-- Date: 2017-09-05 10:16:33
4+
--
5+
coro = {}
6+
coro.main = function() end
7+
8+
coro.current = coro.main
9+
function coro.create( f )
10+
return coroutine.wrap(function ( val )
11+
return nil,f(val)
12+
end)
13+
end
14+
15+
function coro.transfer(k,val)
16+
if coro.current ~= coro.main then
17+
return coroutine.yield(k,val)
18+
else
19+
while k do
20+
coro.current = k
21+
if k == coro.main then
22+
return val
23+
end
24+
k,val = k(val)
25+
end
26+
error("coroutine ended without transfering control...")
27+
end
28+
end

lua/corotest.lua

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package.path = '/Users/diego/build/macosx/share/lua/5.1/?.lua;'
2+
package.cpath = '/Users/diego/build/macosx/lib/lua/5.1/?.so;'
3+
local socket = require('socket')
4+
-- function producer( ... )
5+
-- return coroutine.create(
6+
-- function ( ... )
7+
-- while true do
8+
-- local a = io.read()
9+
-- coroutine.yield(a)
10+
-- end
11+
-- end)
12+
-- end
13+
14+
-- function consumer( pro )
15+
-- while true do
16+
-- local s,v = coroutine.resume(pro)
17+
-- print('s='..tostring(s)..',v='..v)
18+
-- end
19+
20+
21+
-- end
22+
-- p = producer()
23+
-- consumer(p)
24+
local socket = require("socket")
25+
local host = "127.0.0.1"
26+
local port = "8888"
27+
local connections = {}
28+
local threads = {}
29+
30+
function receive_data(sock_id)
31+
local conn = connections[sock_id]
32+
if conn ~= nil then
33+
local recvt, t, status = socket.select({conn}, nil, 1)
34+
if #recvt > 0 then
35+
local receive, receive_status = conn:receive()
36+
37+
if receive_status ~= "closed" then
38+
if receive then
39+
assert(conn:send(receive .. "\n"))
40+
print("Receive Client " .. sock_id.. " : " ..receive)
41+
end
42+
--disconnect
43+
else
44+
print("Client " .. sock_id .. " disconnect!")
45+
connections[sock_id].close()
46+
connections[sock_id] = nil
47+
threads[sock_id] = nil
48+
end
49+
end
50+
--yield, stop execution of this coroutine
51+
coroutine.yield()
52+
end
53+
end
54+
55+
--handle data from client: send data back to client
56+
function connection_handler(sock_id)
57+
while true do
58+
--print ('connection_handler.. id=' .. sock_id)
59+
local conn = connections[sock_id]
60+
if conn == nil then
61+
break
62+
end
63+
local data, status = receive_data(sock_id)
64+
end
65+
end
66+
67+
--create coroutine to handle data from client
68+
function create_handler(sock_id)
69+
--print 'create_handler..'
70+
local handler = coroutine.create(function ()
71+
connection_handler(sock_id)
72+
end)
73+
return handler
74+
end
75+
76+
function accept_connection(sock_id, conn)
77+
print("accepted new socket ,id = " .. sock_id)
78+
connections[sock_id] = conn
79+
threads[sock_id] = create_handler(sock_id)
80+
end
81+
82+
--schedule all clients
83+
function dispatch()
84+
for _sock_id, _thread in ipairs(threads) do
85+
--print ('dispatch, _sock_id = '.. _sock_id)
86+
coroutine.resume(threads[_sock_id])
87+
end
88+
end
89+
90+
function start_server()
91+
local server = assert(socket.bind(host, port, 1024))
92+
print("Server Start " .. host .. ":" .. port)
93+
server:settimeout(0)
94+
95+
local conn_count = 0
96+
while true do
97+
--accept new connection
98+
local conn = server:accept()
99+
if conn then
100+
conn_count = conn_count + 1
101+
accept_connection(conn_count, conn)
102+
end
103+
--deal data from connection
104+
dispatch()
105+
end
106+
end
107+
108+
function main()
109+
start_server()
110+
end
111+
main()

lua/luac.out

1.26 KB
Binary file not shown.

0 commit comments

Comments
 (0)