Commit 1b7ee273 authored by mercury233's avatar mercury233

add text color, add jsonp support

parent a51672cb
...@@ -88,7 +88,7 @@ net.createServer (client) -> ...@@ -88,7 +88,7 @@ net.createServer (client) ->
tribute(server) tribute(server)
server.closed = true unless server.closed server.closed = true unless server.closed
unless client.closed unless client.closed
ygopro.stoc_send_chat(client, "服务器关闭了连接") ygopro.stoc_send_chat(client, "服务器关闭了连接", 11)
client.end() client.end()
return return
...@@ -97,7 +97,7 @@ net.createServer (client) -> ...@@ -97,7 +97,7 @@ net.createServer (client) ->
tribute(server) tribute(server)
server.closed = error server.closed = error
unless client.closed unless client.closed
ygopro.stoc_send_chat(client, "服务器错误: #{error}") ygopro.stoc_send_chat(client, "服务器错误: #{error}", 11)
client.end() client.end()
return return
...@@ -233,7 +233,7 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)-> ...@@ -233,7 +233,7 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)->
ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
#log.info info #log.info info
if settings.modules.stop if settings.modules.stop
ygopro.stoc_send_chat(client,settings.modules.stop) ygopro.stoc_send_chat(client,settings.modules.stop, 11)
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
code: 2 code: 2
...@@ -241,7 +241,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -241,7 +241,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.end() client.end()
else if info.version != settings.version else if info.version != settings.version
ygopro.stoc_send_chat(client,settings.modules.update) ygopro.stoc_send_chat(client,settings.modules.update, 11)
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 4 msg: 4
code: settings.version code: settings.version
...@@ -249,7 +249,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -249,7 +249,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.end() client.end()
else if !info.pass.length and !settings.modules.enable_random_duel else if !info.pass.length and !settings.modules.enable_random_duel
ygopro.stoc_send_chat(client,"房间为空,请修改房间名") ygopro.stoc_send_chat(client,"房间名为空,请填写主机密码", 11)
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
code: 2 code: 2
...@@ -261,7 +261,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -261,7 +261,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
# msg: 1 # msg: 1
# code: 1 #这返错有问题,直接双ygopro直连怎么都正常,在这里就经常弹不出提示 # code: 1 #这返错有问题,直接双ygopro直连怎么都正常,在这里就经常弹不出提示
#} #}
ygopro.stoc_send_chat(client,"房间密码不正确") ygopro.stoc_send_chat(client,"房间密码不正确", 11)
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
code: 2 code: 2
...@@ -279,14 +279,14 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -279,14 +279,14 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
#log.info 'join_game',info.pass, client.name #log.info 'join_game',info.pass, client.name
client.room = Room.find_or_create_by_name(info.pass, client.name) client.room = Room.find_or_create_by_name(info.pass, client.name)
if !client.room if !client.room
ygopro.stoc_send_chat(client,"服务器已经爆满,请稍候再试") ygopro.stoc_send_chat(client,"服务器已经爆满,请稍候再试", 11)
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
code: 2 code: 2
} }
client.end() client.end()
else if client.room.error else if client.room.error
ygopro.stoc_send_chat(client,client.room.error) ygopro.stoc_send_chat(client,client.room.error,11)
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
code: 2 code: 2
...@@ -297,11 +297,11 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -297,11 +297,11 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.is_post_watcher = true client.is_post_watcher = true
ygopro.stoc_send_chat_to_room client.room, "#{client.name} 加入了观战" ygopro.stoc_send_chat_to_room client.room, "#{client.name} 加入了观战"
client.room.watchers.push client client.room.watchers.push client
ygopro.stoc_send_chat client, "观战中", 14
for buffer in client.room.watcher_buffers for buffer in client.room.watcher_buffers
client.write buffer client.write buffer
ygopro.stoc_send_chat client, "观战中."
else else
ygopro.stoc_send_chat(client,"决斗已开始") ygopro.stoc_send_chat(client,"决斗已开始,不允许观战", 11)
ygopro.stoc_send client, 'ERROR_MSG',{ ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1 msg: 1
code: 2 code: 2
...@@ -317,7 +317,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -317,7 +317,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
if settings.modules.welcome if settings.modules.welcome
ygopro.stoc_send_chat client, settings.modules.welcome ygopro.stoc_send_chat client, settings.modules.welcome
if client.room.welcome if client.room.welcome
ygopro.stoc_send_chat client, client.room.welcome ygopro.stoc_send_chat client, client.room.welcome, 14
if settings.modules.post_start_watching and !client.room.watcher if settings.modules.post_start_watching and !client.room.watcher
client.room.watcher = watcher = net.connect client.room.port, -> client.room.watcher = watcher = net.connect client.room.port, ->
...@@ -386,7 +386,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -386,7 +386,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
val = buffer.readInt32LE(2) val = buffer.readInt32LE(2)
client.room.dueling_players[pos].lp -= val client.room.dueling_players[pos].lp -= val
if 0 < client.room.dueling_players[pos].lp <= 100 if 0 < client.room.dueling_players[pos].lp <= 100
ygopro.stoc_send_chat_to_room(client.room, "你的生命已经如风中残烛了!") ygopro.stoc_send_chat_to_room(client.room, "你的生命已经如风中残烛了!", 15)
if ygopro.constants.MSG[msg] == 'RECOVER' and client.is_host if ygopro.constants.MSG[msg] == 'RECOVER' and client.is_host
pos = buffer.readUInt8(1) pos = buffer.readUInt8(1)
...@@ -406,7 +406,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -406,7 +406,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
val = buffer.readInt32LE(2) val = buffer.readInt32LE(2)
client.room.dueling_players[pos].lp -= val client.room.dueling_players[pos].lp -= val
if 0 < client.room.dueling_players[pos].lp <= 100 if 0 < client.room.dueling_players[pos].lp <= 100
ygopro.stoc_send_chat_to_room(client.room, "背水一战!") ygopro.stoc_send_chat_to_room(client.room, "背水一战!", 15)
#登场台词 #登场台词
if settings.modules.dialogues if settings.modules.dialogues
...@@ -414,7 +414,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -414,7 +414,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
card = buffer.readUInt32LE(1) card = buffer.readUInt32LE(1)
if dialogues[card] if dialogues[card]
for line in _.lines dialogues[card][Math.floor(Math.random() * dialogues[card].length)] for line in _.lines dialogues[card][Math.floor(Math.random() * dialogues[card].length)]
ygopro.stoc_send_chat client, line ygopro.stoc_send_chat client, line, 15
return return
#房间管理 #房间管理
...@@ -477,8 +477,6 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)-> ...@@ -477,8 +477,6 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
when '/tip' when '/tip'
ygopro.stoc_send_random_tip(client) if settings.modules.tips ygopro.stoc_send_random_tip(client) if settings.modules.tips
when '/test'
log.info Room.players_oppentlist
return cancel return cancel
ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)-> ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)->
...@@ -492,57 +490,56 @@ ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)-> ...@@ -492,57 +490,56 @@ ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)->
#http #http
if settings.modules.http if settings.modules.http
http_server = http.createServer (request, response)-> http_server = http.createServer (request, response)->
u = url.parse(request.url,1) parseQueryString = true
#log.info u u = url.parse(request.url, parseQueryString)
if u.pathname == '/count.json' pass_validated = u.query.pass == settings.modules.http.password
response.writeHead(200);
response.end(Room.all.length.toString()) if u.pathname == '/api/getrooms'
if u.query.pass and !pass_validated
else if u.pathname == '/rooms.js' response.writeHead(200);
response.writeHead(200); response.end(u.query.callback+'( {"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]} );')
roomsjson = JSON.stringify rooms: (for room in Room.all when room.established else
roomid: room.port.toString(), response.writeHead(200);
roomname: room.name.split('$',2)[0], roomsjson = JSON.stringify rooms: (for room in Room.all when room.established
needpass: (room.name.indexOf('$') != -1).toString(), roomid: room.port.toString(),
users: (for player in room.players when player.pos? roomname: if pass_validated then room.name else room.name.split('$',2)[0],
id: (-1).toString(), needpass: (room.name.indexOf('$') != -1).toString(),
name: player.name, users: (for player in room.players when player.pos?
pos: player.pos id: (-1).toString(),
), name: player.name,
istart: if room.started then 'start' else 'wait' pos: player.pos
) ),
response.end("loadroom( " + roomsjson + " );"); istart: if room.started then 'start' else 'wait'
# todo: 增加JSONP支持 )
response.end(u.query.callback+"( " + roomsjson + " );")
else if u.query.operation == 'getroomjson'
response.writeHead(200); else if u.pathname == '/api/message'
response.end JSON.stringify rooms: (for room in Room.all when room.established if !pass_validated
roomid: room.port.toString(), response.writeHead(200);
roomname: room.name.split('$',2)[0], response.end(u.query.callback+"( '密码错误', 0 );");
needpass: (room.name.indexOf('$') != -1).toString(), return
users: (for player in room.players when player.pos?
id: (-1).toString(), if u.query.shout
name: player.name, for room in Room.all
pos: player.pos ygopro.stoc_send_chat_to_room(room, u.query.shout, 16)
), response.writeHead(200)
istart: if room.started then "start" else "wait" response.end(u.query.callback+"( 'shout ok', '" + u.query.shout + "' );")
)
else if u.query.stop
else if u.query.pass == settings.modules.http.password && u.query.shout if u.query.stop == 'false'
for room in Room.all u.query.stop=false
ygopro.stoc_send_chat_to_room(room, u.query.shout) settings.modules.stop = u.query.stop
response.writeHead(200) response.writeHead(200)
response.end("shout " + u.query.shout + " ok") response.end(u.query.callback+"( 'stop ok', '" + u.query.stop + "' );")
else if u.query.pass == settings.modules.http.password && u.query.stop else if u.query.welcome
settings.modules.stop = u.query.stop settings.modules.welcome = u.query.welcome
response.writeHead(200) response.writeHead(200)
response.end("stop " + u.query.stop + " ok") response.end(u.query.callback+"( 'welcome ok', '" + u.query.welcome + "' );")
else if u.query.pass == settings.modules.http.password && u.query.welcome else
settings.modules.welcome = u.query.welcome response.writeHead(404);
response.writeHead(200) response.end();
response.end("welcome " + u.query.welcome + " ok")
else else
response.writeHead(404); response.writeHead(404);
......
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
server.closed = true; server.closed = true;
} }
if (!client.closed) { if (!client.closed) {
ygopro.stoc_send_chat(client, "服务器关闭了连接"); ygopro.stoc_send_chat(client, "服务器关闭了连接", 11);
client.end(); client.end();
} }
}); });
...@@ -117,7 +117,7 @@ ...@@ -117,7 +117,7 @@
tribute(server); tribute(server);
server.closed = error; server.closed = error;
if (!client.closed) { if (!client.closed) {
ygopro.stoc_send_chat(client, "服务器错误: " + error); ygopro.stoc_send_chat(client, "服务器错误: " + error, 11);
client.end(); client.end();
} }
}); });
...@@ -258,28 +258,28 @@ ...@@ -258,28 +258,28 @@
ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) { ygopro.ctos_follow('JOIN_GAME', false, function(buffer, info, client, server) {
var k, len, ref; var k, len, ref;
if (settings.modules.stop) { if (settings.modules.stop) {
ygopro.stoc_send_chat(client, settings.modules.stop); ygopro.stoc_send_chat(client, settings.modules.stop, 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1, msg: 1,
code: 2 code: 2
}); });
client.end(); client.end();
} else if (info.version !== settings.version) { } else if (info.version !== settings.version) {
ygopro.stoc_send_chat(client, settings.modules.update); ygopro.stoc_send_chat(client, settings.modules.update, 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 4, msg: 4,
code: settings.version code: settings.version
}); });
client.end(); client.end();
} else if (!info.pass.length && !settings.modules.enable_random_duel) { } else if (!info.pass.length && !settings.modules.enable_random_duel) {
ygopro.stoc_send_chat(client, "房间为空,请修改房间名"); ygopro.stoc_send_chat(client, "房间名为空,请填写主机密码", 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1, msg: 1,
code: 2 code: 2
}); });
client.end(); client.end();
} else if (!Room.validate(info.pass)) { } else if (!Room.validate(info.pass)) {
ygopro.stoc_send_chat(client, "房间密码不正确"); ygopro.stoc_send_chat(client, "房间密码不正确", 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1, msg: 1,
code: 2 code: 2
...@@ -294,14 +294,14 @@ ...@@ -294,14 +294,14 @@
} else { } else {
client.room = Room.find_or_create_by_name(info.pass, client.name); client.room = Room.find_or_create_by_name(info.pass, client.name);
if (!client.room) { if (!client.room) {
ygopro.stoc_send_chat(client, "服务器已经爆满,请稍候再试"); ygopro.stoc_send_chat(client, "服务器已经爆满,请稍候再试", 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1, msg: 1,
code: 2 code: 2
}); });
client.end(); client.end();
} else if (client.room.error) { } else if (client.room.error) {
ygopro.stoc_send_chat(client, client.room.error); ygopro.stoc_send_chat(client, client.room.error, 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1, msg: 1,
code: 2 code: 2
...@@ -312,14 +312,14 @@ ...@@ -312,14 +312,14 @@
client.is_post_watcher = true; client.is_post_watcher = true;
ygopro.stoc_send_chat_to_room(client.room, client.name + " 加入了观战"); ygopro.stoc_send_chat_to_room(client.room, client.name + " 加入了观战");
client.room.watchers.push(client); client.room.watchers.push(client);
ygopro.stoc_send_chat(client, "观战中", 14);
ref = client.room.watcher_buffers; ref = client.room.watcher_buffers;
for (k = 0, len = ref.length; k < len; k++) { for (k = 0, len = ref.length; k < len; k++) {
buffer = ref[k]; buffer = ref[k];
client.write(buffer); client.write(buffer);
} }
ygopro.stoc_send_chat(client, "观战中.");
} else { } else {
ygopro.stoc_send_chat(client, "决斗已开始"); ygopro.stoc_send_chat(client, "决斗已开始,不允许观战", 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1, msg: 1,
code: 2 code: 2
...@@ -341,7 +341,7 @@ ...@@ -341,7 +341,7 @@
ygopro.stoc_send_chat(client, settings.modules.welcome); ygopro.stoc_send_chat(client, settings.modules.welcome);
} }
if (client.room.welcome) { if (client.room.welcome) {
ygopro.stoc_send_chat(client, client.room.welcome); ygopro.stoc_send_chat(client, client.room.welcome, 14);
} }
if (settings.modules.post_start_watching && !client.room.watcher) { if (settings.modules.post_start_watching && !client.room.watcher) {
client.room.watcher = watcher = net.connect(client.room.port, function() { client.room.watcher = watcher = net.connect(client.room.port, function() {
...@@ -415,7 +415,7 @@ ...@@ -415,7 +415,7 @@
val = buffer.readInt32LE(2); val = buffer.readInt32LE(2);
client.room.dueling_players[pos].lp -= val; client.room.dueling_players[pos].lp -= val;
if ((0 < (ref = client.room.dueling_players[pos].lp) && ref <= 100)) { if ((0 < (ref = client.room.dueling_players[pos].lp) && ref <= 100)) {
ygopro.stoc_send_chat_to_room(client.room, "你的生命已经如风中残烛了!"); ygopro.stoc_send_chat_to_room(client.room, "你的生命已经如风中残烛了!", 15);
} }
} }
if (ygopro.constants.MSG[msg] === 'RECOVER' && client.is_host) { if (ygopro.constants.MSG[msg] === 'RECOVER' && client.is_host) {
...@@ -442,7 +442,7 @@ ...@@ -442,7 +442,7 @@
val = buffer.readInt32LE(2); val = buffer.readInt32LE(2);
client.room.dueling_players[pos].lp -= val; client.room.dueling_players[pos].lp -= val;
if ((0 < (ref1 = client.room.dueling_players[pos].lp) && ref1 <= 100)) { if ((0 < (ref1 = client.room.dueling_players[pos].lp) && ref1 <= 100)) {
ygopro.stoc_send_chat_to_room(client.room, "背水一战!"); ygopro.stoc_send_chat_to_room(client.room, "背水一战!", 15);
} }
} }
if (settings.modules.dialogues) { if (settings.modules.dialogues) {
...@@ -452,7 +452,7 @@ ...@@ -452,7 +452,7 @@
ref2 = _.lines(dialogues[card][Math.floor(Math.random() * dialogues[card].length)]); ref2 = _.lines(dialogues[card][Math.floor(Math.random() * dialogues[card].length)]);
for (k = 0, len = ref2.length; k < len; k++) { for (k = 0, len = ref2.length; k < len; k++) {
line = ref2[k]; line = ref2[k];
ygopro.stoc_send_chat(client, line); ygopro.stoc_send_chat(client, line, 15);
} }
} }
} }
...@@ -535,9 +535,6 @@ ...@@ -535,9 +535,6 @@
if (settings.modules.tips) { if (settings.modules.tips) {
ygopro.stoc_send_random_tip(client); ygopro.stoc_send_random_tip(client);
} }
break;
case '/test':
log.info(Room.players_oppentlist);
} }
return cancel; return cancel;
}); });
...@@ -566,102 +563,82 @@ ...@@ -566,102 +563,82 @@
if (settings.modules.http) { if (settings.modules.http) {
http_server = http.createServer(function(request, response) { http_server = http.createServer(function(request, response) {
var k, len, player, ref, room, roomsjson, u; var k, len, parseQueryString, pass_validated, player, ref, room, roomsjson, u;
u = url.parse(request.url, 1); parseQueryString = true;
if (u.pathname === '/count.json') { u = url.parse(request.url, parseQueryString);
response.writeHead(200); pass_validated = u.query.pass === settings.modules.http.password;
response.end(Room.all.length.toString()); if (u.pathname === '/api/getrooms') {
} else if (u.pathname === '/rooms.js') { if (u.query.pass && !pass_validated) {
response.writeHead(200); response.writeHead(200);
roomsjson = JSON.stringify({ response.end(u.query.callback + '( {"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]} );');
rooms: (function() { } else {
var k, len, ref, results; response.writeHead(200);
ref = Room.all; roomsjson = JSON.stringify({
results = []; rooms: (function() {
for (k = 0, len = ref.length; k < len; k++) { var k, len, ref, results;
room = ref[k]; ref = Room.all;
if (room.established) { results = [];
results.push({ for (k = 0, len = ref.length; k < len; k++) {
roomid: room.port.toString(), room = ref[k];
roomname: room.name.split('$', 2)[0], if (room.established) {
needpass: (room.name.indexOf('$') !== -1).toString(), results.push({
users: (function() { roomid: room.port.toString(),
var l, len1, ref1, results1; roomname: pass_validated ? room.name : room.name.split('$', 2)[0],
ref1 = room.players; needpass: (room.name.indexOf('$') !== -1).toString(),
results1 = []; users: (function() {
for (l = 0, len1 = ref1.length; l < len1; l++) { var l, len1, ref1, results1;
player = ref1[l]; ref1 = room.players;
if (player.pos != null) { results1 = [];
results1.push({ for (l = 0, len1 = ref1.length; l < len1; l++) {
id: (-1).toString(), player = ref1[l];
name: player.name, if (player.pos != null) {
pos: player.pos results1.push({
}); id: (-1).toString(),
} name: player.name,
} pos: player.pos
return results1; });
})(), }
istart: room.started ? 'start' : 'wait'
});
}
}
return results;
})()
});
response.end("loadroom( " + roomsjson + " );");
} else if (u.query.operation === 'getroomjson') {
response.writeHead(200);
response.end(JSON.stringify({
rooms: (function() {
var k, len, ref, results;
ref = Room.all;
results = [];
for (k = 0, len = ref.length; k < len; k++) {
room = ref[k];
if (room.established) {
results.push({
roomid: room.port.toString(),
roomname: room.name.split('$', 2)[0],
needpass: (room.name.indexOf('$') !== -1).toString(),
users: (function() {
var l, len1, ref1, results1;
ref1 = room.players;
results1 = [];
for (l = 0, len1 = ref1.length; l < len1; l++) {
player = ref1[l];
if (player.pos != null) {
results1.push({
id: (-1).toString(),
name: player.name,
pos: player.pos
});
} }
} return results1;
return results1; })(),
})(), istart: room.started ? 'start' : 'wait'
istart: room.started ? "start" : "wait" });
}); }
} }
} return results;
return results; })()
})() });
})); response.end(u.query.callback + "( " + roomsjson + " );");
} else if (u.query.pass === settings.modules.http.password && u.query.shout) { }
ref = Room.all; } else if (u.pathname === '/api/message') {
for (k = 0, len = ref.length; k < len; k++) { if (!pass_validated) {
room = ref[k]; response.writeHead(200);
ygopro.stoc_send_chat_to_room(room, u.query.shout); response.end(u.query.callback + "( '密码错误', 0 );");
return;
}
if (u.query.shout) {
ref = Room.all;
for (k = 0, len = ref.length; k < len; k++) {
room = ref[k];
ygopro.stoc_send_chat_to_room(room, u.query.shout, 16);
}
response.writeHead(200);
response.end(u.query.callback + "( 'shout ok', '" + u.query.shout + "' );");
} else if (u.query.stop) {
if (u.query.stop === 'false') {
u.query.stop = false;
}
settings.modules.stop = u.query.stop;
response.writeHead(200);
response.end(u.query.callback + "( 'stop ok', '" + u.query.stop + "' );");
} else if (u.query.welcome) {
settings.modules.welcome = u.query.welcome;
response.writeHead(200);
response.end(u.query.callback + "( 'welcome ok', '" + u.query.welcome + "' );");
} else {
response.writeHead(404);
response.end();
} }
response.writeHead(200);
response.end("shout " + u.query.shout + " ok");
} else if (u.query.pass === settings.modules.http.password && u.query.stop) {
settings.modules.stop = u.query.stop;
response.writeHead(200);
response.end("stop " + u.query.stop + " ok");
} else if (u.query.pass === settings.modules.http.password && u.query.welcome) {
settings.modules.welcome = u.query.welcome;
response.writeHead(200);
response.end("welcome " + u.query.welcome + " ok");
} else { } else {
response.writeHead(404); response.writeHead(404);
response.end(); response.end();
......
...@@ -114,6 +114,8 @@ for name, declaration of structs_declaration ...@@ -114,6 +114,8 @@ for name, declaration of structs_declaration
console.log "err stoc_send_chat" console.log "err stoc_send_chat"
return return
for line in _.lines(msg) for line in _.lines(msg)
if player>=10
line="[System]: "+line
@stoc_send client, 'CHAT', { @stoc_send client, 'CHAT', {
player: player player: player
msg: line msg: line
......
...@@ -178,6 +178,9 @@ ...@@ -178,6 +178,9 @@
ref = _.lines(msg); ref = _.lines(msg);
for (j = 0, len1 = ref.length; j < len1; j++) { for (j = 0, len1 = ref.length; j < len1; j++) {
line = ref[j]; line = ref[j];
if (player >= 10) {
line = "[System]: " + line;
}
this.stoc_send(client, 'CHAT', { this.stoc_send(client, 'CHAT', {
player: player, player: player,
msg: line msg: line
......
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