Commit d3b9a3f6 authored by mercury233's avatar mercury233

separate banned players

parent 522627c9
...@@ -58,12 +58,14 @@ class Room ...@@ -58,12 +58,14 @@ class Room
bannedplayer = _.find Room.players_banned, (bannedplayer)-> bannedplayer = _.find Room.players_banned, (bannedplayer)->
ip==bannedplayer.ip ip==bannedplayer.ip
if bannedplayer if bannedplayer
bantime=Math.pow(2,bannedplayer.count)*30
bannedplayer.time=if moment()<bannedplayer.time then moment(bannedplayer.time).add(bantime,'s') else moment().add(bantime,'s')
bannedplayer.count=bannedplayer.count+1 bannedplayer.count=bannedplayer.count+1
bannedplayer.reason=reason bantime=if bannedplayer.count > 3 then Math.pow(2,bannedplayer.count-3)*2 else 0
bannedplayer.time=if moment()<bannedplayer.time then moment(bannedplayer.time).add(bantime,'m') else moment().add(bantime,'m')
bannedplayer.reasons.push(reason) if not _.find bannedplayer.reasons, (bannedreason)->
bannedreason==reason
bannedplayer.need_tip=true;
else else
Room.players_banned.push {"ip": ip, "time": moment().add(30, 's'), "count": 1, "reason": reason} Room.players_banned.push {"ip": ip, "time": moment(), "count": 1, "reasons": [reason], "need_tip": true}
@find_or_create_by_name: (name, player_ip)-> @find_or_create_by_name: (name, player_ip)->
if settings.modules.enable_random_duel and (name == '' or name.toUpperCase() == 'S' or name.toUpperCase() == 'M' or name.toUpperCase() == 'T') if settings.modules.enable_random_duel and (name == '' or name.toUpperCase() == 'S' or name.toUpperCase() == 'M' or name.toUpperCase() == 'T')
...@@ -78,11 +80,21 @@ class Room ...@@ -78,11 +80,21 @@ class Room
@find_or_create_random: (type, player_ip)-> @find_or_create_random: (type, player_ip)->
bannedplayer = _.find Room.players_banned, (bannedplayer)-> bannedplayer = _.find Room.players_banned, (bannedplayer)->
return player_ip==bannedplayer.ip return player_ip==bannedplayer.ip
if bannedplayer and moment()<bannedplayer.time if bannedplayer
return {"error":"因为您近期在游戏中#{bannedplayer.reason},您已被禁止使用随机对战功能,将在#{moment(bannedplayer.time).fromNow(true)}后解封"} if bannedplayer.count > 6 and moment()<bannedplayer.time
return {"error":"因为您近期在游戏中多次#{bannedplayer.reasons.join('、')},您已被禁止使用随机对战功能,将在#{moment(bannedplayer.time).fromNow(true)}后解封"}
if bannedplayer.count > 3 and moment()<bannedplayer.time and bannedplayer.need_tip
bannedplayer.need_tip=false
return {"error":"因为您近期在游戏中#{bannedplayer.reasons.join('、')},在#{moment(bannedplayer.time).fromNow(true)}内您随机对战时只能遇到其他违规玩家"}
else if bannedplayer.need_tip
bannedplayer.need_tip=false
return {"error":"系统检测到您近期在游戏中#{bannedplayer.reasons.join('、')},若您违规超过3次,将受到惩罚"}
else if bannedplayer.count > 2
bannedplayer.need_tip=true
max_player = if type == 'T' then 4 else 2 max_player = if type == 'T' then 4 else 2
playerbanned=(bannedplayer and bannedplayer.count > 3 and moment()<bannedplayer.time)
result = _.find @all, (room)-> result = _.find @all, (room)->
room.random_type != '' and !room.started and ((type == '' and room.random_type != 'T') or room.random_type == type) and room.get_playing_player().length < max_player and (room.get_host()==null or room.get_host().remoteAddress != Room.players_oppentlist[player_ip]) return room.random_type != '' and !room.started and ((type == '' and room.random_type != 'T') or room.random_type == type) and room.get_playing_player().length < max_player and (room.get_host()==null or room.get_host().remoteAddress != Room.players_oppentlist[player_ip]) and (playerbanned == room.deprecated)
if result if result
result.welcome = '对手已经在等你了,开始决斗吧!' result.welcome = '对手已经在等你了,开始决斗吧!'
#log.info 'found room', player_name #log.info 'found room', player_name
...@@ -93,6 +105,7 @@ class Room ...@@ -93,6 +105,7 @@ class Room
result.random_type = type result.random_type = type
result.max_player = max_player result.max_player = max_player
result.welcome = '已建立随机对战房间,正在等待对手!' result.welcome = '已建立随机对战房间,正在等待对手!'
result.deprecated=playerbanned
#log.info 'create room', player_name, name #log.info 'create room', player_name, name
return result return result
......
...@@ -74,16 +74,22 @@ ...@@ -74,16 +74,22 @@
return ip === bannedplayer.ip; return ip === bannedplayer.ip;
}); });
if (bannedplayer) { if (bannedplayer) {
bantime = Math.pow(2, bannedplayer.count) * 30;
bannedplayer.time = moment() < bannedplayer.time ? moment(bannedplayer.time).add(bantime, 's') : moment().add(bantime, 's');
bannedplayer.count = bannedplayer.count + 1; bannedplayer.count = bannedplayer.count + 1;
return bannedplayer.reason = reason; bantime = bannedplayer.count > 3 ? Math.pow(2, bannedplayer.count - 3) * 2 : 0;
bannedplayer.time = moment() < bannedplayer.time ? moment(bannedplayer.time).add(bantime, 'm') : moment().add(bantime, 'm');
if (!_.find(bannedplayer.reasons, function(bannedreason) {
return bannedreason === reason;
})) {
bannedplayer.reasons.push(reason);
}
return bannedplayer.need_tip = true;
} else { } else {
return Room.players_banned.push({ return Room.players_banned.push({
"ip": ip, "ip": ip,
"time": moment().add(30, 's'), "time": moment(),
"count": 1, "count": 1,
"reason": reason "reasons": [reason],
"need_tip": true
}); });
} }
}; };
...@@ -103,18 +109,34 @@ ...@@ -103,18 +109,34 @@
}; };
Room.find_or_create_random = function(type, player_ip) { Room.find_or_create_random = function(type, player_ip) {
var bannedplayer, max_player, name, result; var bannedplayer, max_player, name, playerbanned, result;
bannedplayer = _.find(Room.players_banned, function(bannedplayer) { bannedplayer = _.find(Room.players_banned, function(bannedplayer) {
return player_ip === bannedplayer.ip; return player_ip === bannedplayer.ip;
}); });
if (bannedplayer && moment() < bannedplayer.time) { if (bannedplayer) {
return { if (bannedplayer.count > 6 && moment() < bannedplayer.time) {
"error": "因为您近期在游戏中" + bannedplayer.reason + ",您已被禁止使用随机对战功能,将在" + (moment(bannedplayer.time).fromNow(true)) + "后解封" return {
}; "error": "因为您近期在游戏中多次" + (bannedplayer.reasons.join('')) + ",您已被禁止使用随机对战功能,将在" + (moment(bannedplayer.time).fromNow(true)) + "后解封"
};
}
if (bannedplayer.count > 3 && moment() < bannedplayer.time && bannedplayer.need_tip) {
bannedplayer.need_tip = false;
return {
"error": "因为您近期在游戏中" + (bannedplayer.reasons.join('')) + ",在" + (moment(bannedplayer.time).fromNow(true)) + "内您随机对战时只能遇到其他违规玩家"
};
} else if (bannedplayer.need_tip) {
bannedplayer.need_tip = false;
return {
"error": "系统检测到您近期在游戏中" + (bannedplayer.reasons.join('')) + ",若您违规超过3次,将受到惩罚"
};
} else if (bannedplayer.count > 2) {
bannedplayer.need_tip = true;
}
} }
max_player = type === 'T' ? 4 : 2; max_player = type === 'T' ? 4 : 2;
playerbanned = bannedplayer && bannedplayer.count > 3 && moment() < bannedplayer.time;
result = _.find(this.all, function(room) { result = _.find(this.all, function(room) {
return room.random_type !== '' && !room.started && ((type === '' && room.random_type !== 'T') || room.random_type === type) && room.get_playing_player().length < max_player && (room.get_host() === null || room.get_host().remoteAddress !== Room.players_oppentlist[player_ip]); return room.random_type !== '' && !room.started && ((type === '' && room.random_type !== 'T') || room.random_type === type) && room.get_playing_player().length < max_player && (room.get_host() === null || room.get_host().remoteAddress !== Room.players_oppentlist[player_ip]) && (playerbanned === room.deprecated);
}); });
if (result) { if (result) {
result.welcome = '对手已经在等你了,开始决斗吧!'; result.welcome = '对手已经在等你了,开始决斗吧!';
...@@ -125,6 +147,7 @@ ...@@ -125,6 +147,7 @@
result.random_type = type; result.random_type = type;
result.max_player = max_player; result.max_player = max_player;
result.welcome = '已建立随机对战房间,正在等待对手!'; result.welcome = '已建立随机对战房间,正在等待对手!';
result.deprecated = playerbanned;
} }
return result; return result;
}; };
......
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