Commit 522627c9 authored by mercury233's avatar mercury233

auto kick and ban player who hang

parent 169e8205
{ {
"CTOS":{ "CTOS":{
"RESPONSE": "",
"HAND_RESULT": "",
"TP_RESULT": "",
"PLAYER_INFO": "CTOS_PlayerInfo", "PLAYER_INFO": "CTOS_PlayerInfo",
"JOIN_GAME":"CTOS_JoinGame", "JOIN_GAME":"CTOS_JoinGame",
"HS_KICK":"CTOS_Kick", "HS_KICK":"CTOS_Kick",
...@@ -15,6 +18,8 @@ ...@@ -15,6 +18,8 @@
"HS_PLAYER_ENTER":"STOC_HS_PlayerEnter", "HS_PLAYER_ENTER":"STOC_HS_PlayerEnter",
"ERROR_MSG": "STOC_ErrorMsg", "ERROR_MSG": "STOC_ErrorMsg",
"GAME_MSG": "GameMsg_Hint_Card_only", "GAME_MSG": "GameMsg_Hint_Card_only",
"SELECT_HAND": "",
"SELECT_TP": "",
"CHAT": "STOC_Chat" "CHAT": "STOC_Chat"
} }
} }
...@@ -16,12 +16,15 @@ request = require 'request' ...@@ -16,12 +16,15 @@ request = require 'request'
bunyan = require 'bunyan' bunyan = require 'bunyan'
moment = require 'moment'
#heapdump = require 'heapdump' #heapdump = require 'heapdump'
#配置文件 #配置文件
settings = require './config.json' settings = require './config.json'
settings.BANNED_user = [] settings.BANNED_user = []
settings.BANNED_IP = [] settings.BANNED_IP = []
settings.modules.hang_timeout=90
#组件 #组件
ygopro = require './ygopro.js' ygopro = require './ygopro.js'
...@@ -388,6 +391,12 @@ if settings.modules.dialogues ...@@ -388,6 +391,12 @@ if settings.modules.dialogues
ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
msg = buffer.readInt8(0) msg = buffer.readInt8(0)
if msg>=10 and msg<30 #SELECT开头的消息
client.room.waiting_for_player=client
client.room.last_active_time=moment()
#log.info("#{ygopro.constants.MSG[msg]}等待#{client.room.waiting_for_player.name}")
#log.info 'MSG', ygopro.constants.MSG[msg] #log.info 'MSG', ygopro.constants.MSG[msg]
if ygopro.constants.MSG[msg] == 'START' if ygopro.constants.MSG[msg] == 'START'
playertype = buffer.readUInt8(1) playertype = buffer.readUInt8(1)
...@@ -527,6 +536,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)-> ...@@ -527,6 +536,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)-> ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
cancel = _.startsWith(_.trim(info.msg),"/") cancel = _.startsWith(_.trim(info.msg),"/")
client.room.last_active_time=moment() unless cancel or not client.room.random_type
switch _.trim(info.msg) switch _.trim(info.msg)
when '/ping' when '/ping'
execFile 'ss', ['-it', "dst #{client.remoteAddress}:#{client.remotePort}"], (error, stdout, stderr)-> execFile 'ss', ['-it', "dst #{client.remoteAddress}:#{client.remotePort}"], (error, stdout, stderr)->
...@@ -566,6 +576,53 @@ ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)-> ...@@ -566,6 +576,53 @@ ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)->
client.side = side client.side = side
return return
ygopro.ctos_follow 'RESPONSE', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
client.room.last_active_time=moment()
return
ygopro.ctos_follow 'HAND_RESULT', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
if client.is_host
client.room.waiting_for_player=client.room.waiting_for_player2
client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's')
return
ygopro.ctos_follow 'TP_RESULT', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
client.room.last_active_time=moment()
return
ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
if client.is_host
client.room.waiting_for_player=client
else
client.room.waiting_for_player2=client
client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's')
return
ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type
client.room.waiting_for_player=client
client.room.last_active_time=moment()
return
setInterval ()->
for room in Room.all when room.started and room.random_type
continue unless room and room.last_active_time
time_passed=Math.floor((moment()-room.last_active_time) / 1000)
#log.info time_passed
if time_passed >= settings.modules.hang_timeout
room.last_active_time=moment()
Room.ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "挂机")
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} 被系统请出了房间", 11)
room.waiting_for_player.server.end()
else if time_passed >= (settings.modules.hang_timeout-20) and not (time_passed % 10)
ygopro.stoc_send_chat_to_room(room, "#{room.waiting_for_player.name} 已经很久没有操作了,若继续挂机,将于#{settings.modules.hang_timeout-time_passed}秒后被请出房间", 11)
return
,1000
#http #http
if settings.modules.http if settings.modules.http
http_server = http.createServer (request, response)-> http_server = http.createServer (request, response)->
......
// Generated by CoffeeScript 1.10.0 // Generated by CoffeeScript 1.10.0
(function() { (function() {
var Graveyard, Room, _, bunyan, debug, dialogues, execFile, fs, http, http_server, log, net, os, path, request, settings, tips, tribute, url, wait_room_start, ygopro; var Graveyard, Room, _, bunyan, debug, dialogues, execFile, fs, http, http_server, log, moment, net, os, path, request, settings, tips, tribute, url, wait_room_start, ygopro;
net = require('net'); net = require('net');
...@@ -26,12 +26,16 @@ ...@@ -26,12 +26,16 @@
bunyan = require('bunyan'); bunyan = require('bunyan');
moment = require('moment');
settings = require('./config.json'); settings = require('./config.json');
settings.BANNED_user = []; settings.BANNED_user = [];
settings.BANNED_IP = []; settings.BANNED_IP = [];
settings.modules.hang_timeout = 90;
ygopro = require('./ygopro.js'); ygopro = require('./ygopro.js');
Room = require('./room.js'); Room = require('./room.js');
...@@ -418,6 +422,10 @@ ...@@ -418,6 +422,10 @@
ygopro.stoc_follow('GAME_MSG', false, function(buffer, info, client, server) { ygopro.stoc_follow('GAME_MSG', false, function(buffer, info, client, server) {
var card, k, len, line, msg, playertype, pos, ref, ref1, ref2, val; var card, k, len, line, msg, playertype, pos, ref, ref1, ref2, val;
msg = buffer.readInt8(0); msg = buffer.readInt8(0);
if (msg >= 10 && msg < 30) {
client.room.waiting_for_player = client;
client.room.last_active_time = moment();
}
if (ygopro.constants.MSG[msg] === 'START') { if (ygopro.constants.MSG[msg] === 'START') {
playertype = buffer.readUInt8(1); playertype = buffer.readUInt8(1);
client.is_first = !(playertype & 0xf); client.is_first = !(playertype & 0xf);
...@@ -617,6 +625,9 @@ ...@@ -617,6 +625,9 @@
ygopro.ctos_follow('CHAT', true, function(buffer, info, client, server) { ygopro.ctos_follow('CHAT', true, function(buffer, info, client, server) {
var cancel; var cancel;
cancel = _.startsWith(_.trim(info.msg), "/"); cancel = _.startsWith(_.trim(info.msg), "/");
if (!(cancel || !client.room.random_type)) {
client.room.last_active_time = moment();
}
switch (_.trim(info.msg)) { switch (_.trim(info.msg)) {
case '/ping': case '/ping':
execFile('ss', ['-it', "dst " + client.remoteAddress + ":" + client.remotePort], function(error, stdout, stderr) { execFile('ss', ['-it', "dst " + client.remoteAddress + ":" + client.remotePort], function(error, stdout, stderr) {
...@@ -679,6 +690,73 @@ ...@@ -679,6 +690,73 @@
client.side = side; client.side = side;
}); });
ygopro.ctos_follow('RESPONSE', false, function(buffer, info, client, server) {
if (!(client.room && client.room.random_type)) {
return;
}
client.room.last_active_time = moment();
});
ygopro.ctos_follow('HAND_RESULT', false, function(buffer, info, client, server) {
if (!(client.room && client.room.random_type)) {
return;
}
if (client.is_host) {
client.room.waiting_for_player = client.room.waiting_for_player2;
}
client.room.last_active_time = moment().subtract(settings.modules.hang_timeout - 19, 's');
});
ygopro.ctos_follow('TP_RESULT', false, function(buffer, info, client, server) {
if (!(client.room && client.room.random_type)) {
return;
}
client.room.last_active_time = moment();
});
ygopro.stoc_follow('SELECT_HAND', false, function(buffer, info, client, server) {
if (!(client.room && client.room.random_type)) {
return;
}
if (client.is_host) {
client.room.waiting_for_player = client;
} else {
client.room.waiting_for_player2 = client;
}
client.room.last_active_time = moment().subtract(settings.modules.hang_timeout - 19, 's');
});
ygopro.stoc_follow('SELECT_TP', false, function(buffer, info, client, server) {
if (!(client.room && client.room.random_type)) {
return;
}
client.room.waiting_for_player = client;
client.room.last_active_time = moment();
});
setInterval(function() {
var k, len, ref, room, time_passed;
ref = Room.all;
for (k = 0, len = ref.length; k < len; k++) {
room = ref[k];
if (!(room.started && room.random_type)) {
continue;
}
if (!(room && room.last_active_time)) {
continue;
}
time_passed = Math.floor((moment() - room.last_active_time) / 1000);
if (time_passed >= settings.modules.hang_timeout) {
room.last_active_time = moment();
Room.ban_player(room.waiting_for_player.name, room.waiting_for_player.ip, "挂机");
ygopro.stoc_send_chat_to_room(room, room.waiting_for_player.name + " 被系统请出了房间", 11);
room.waiting_for_player.server.end();
} else if (time_passed >= (settings.modules.hang_timeout - 20) && !(time_passed % 10)) {
ygopro.stoc_send_chat_to_room(room, room.waiting_for_player.name + " 已经很久没有操作了,若继续挂机,将于" + (settings.modules.hang_timeout - time_passed) + "秒后被请出房间", 11);
}
}
}, 1000);
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, parseQueryString, pass_validated, player, ref, room, roomsjson, u; var k, len, parseQueryString, pass_validated, player, ref, room, roomsjson, u;
......
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