Commit 91a665a5 authored by mercury233's avatar mercury233

auto kick host who don't start

parent 4c110c08
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"CTOS":{ "CTOS":{
"PLAYER_INFO": "CTOS_PlayerInfo", "PLAYER_INFO": "CTOS_PlayerInfo",
"JOIN_GAME":"CTOS_JoinGame", "JOIN_GAME":"CTOS_JoinGame",
"HS_KICK":"CTOS_Kick",
"UPDATE_DECK": "deck", "UPDATE_DECK": "deck",
"CHANGE_SIDE":"", "CHANGE_SIDE":"",
"CHAT": "chat" "CHAT": "chat"
......
...@@ -79,7 +79,7 @@ class Room ...@@ -79,7 +79,7 @@ class Room
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 and moment()<bannedplayer.time
return {"error":"因为您在近期游戏中#{bannedplayer.reason},您已被禁止使用随机对战功能,将在#{moment(bannedplayer.time).fromNow(true)}后解封"} return {"error":"因为您近期在游戏中#{bannedplayer.reason},您已被禁止使用随机对战功能,将在#{moment(bannedplayer.time).fromNow(true)}后解封"}
max_player = if type == 'T' then 4 else 2 max_player = if type == 'T' then 4 else 2
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().remoteAddress != Room.players_oppentlist[player_ip] 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().remoteAddress != Room.players_oppentlist[player_ip]
...@@ -91,6 +91,7 @@ class Room ...@@ -91,6 +91,7 @@ class Room
name = type + ',RANDOM#' + Math.floor(Math.random()*100000) name = type + ',RANDOM#' + Math.floor(Math.random()*100000)
result = new Room(name) result = new Room(name)
result.random_type = type result.random_type = type
result.max_player = max_player
result.welcome = '已建立随机对战房间,正在等待对手!' result.welcome = '已建立随机对战房间,正在等待对手!'
#log.info 'create room', player_name, name #log.info 'create room', player_name, name
return result return result
......
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
}); });
if (bannedplayer && moment() < bannedplayer.time) { if (bannedplayer && moment() < bannedplayer.time) {
return { return {
"error": "因为您在近期游戏中" + bannedplayer.reason + ",您已被禁止使用随机对战功能,将在" + (moment(bannedplayer.time).fromNow(true)) + "后解封" "error": "因为您近期在游戏中" + bannedplayer.reason + ",您已被禁止使用随机对战功能,将在" + (moment(bannedplayer.time).fromNow(true)) + "后解封"
}; };
} }
max_player = type === 'T' ? 4 : 2; max_player = type === 'T' ? 4 : 2;
...@@ -123,6 +123,7 @@ ...@@ -123,6 +123,7 @@
name = type + ',RANDOM#' + Math.floor(Math.random() * 100000); name = type + ',RANDOM#' + Math.floor(Math.random() * 100000);
result = new Room(name); result = new Room(name);
result.random_type = type; result.random_type = type;
result.max_player = max_player;
result.welcome = '已建立随机对战房间,正在等待对手!'; result.welcome = '已建立随机对战房间,正在等待对手!';
} }
return result; return result;
......
...@@ -443,6 +443,13 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -443,6 +443,13 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
return return
#房间管理 #房间管理
ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server)->
return unless client.room
for player in client.room.players
if player.pos==info.pos and player != client
ygopro.stoc_send_chat_to_room client.room, "#{player.name} 被请出了房间", 11
return false
ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)-> ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)->
selftype = info.type & 0xf; selftype = info.type & 0xf;
is_host = ((info.type >> 4) & 0xf) != 0; is_host = ((info.type >> 4) & 0xf) != 0;
...@@ -451,6 +458,37 @@ ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)-> ...@@ -451,6 +458,37 @@ ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)->
#console.log "TYPE_CHANGE to #{client.name}:", info, selftype, is_host #console.log "TYPE_CHANGE to #{client.name}:", info, selftype, is_host
return return
ygopro.stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)->
return unless client.room and client.room.max_player
pos = info.status >> 4;
is_ready = (info.status & 0xf) == 9;
if pos < client.room.max_player
client.room.ready_player_count_without_host = 0
for player in client.room.players
if player.pos==pos
player.is_ready = is_ready
unless player.is_host
client.room.ready_player_count_without_host+=player.is_ready
if client.is_host and client.room.ready_player_count_without_host >= client.room.max_player - 1
#log.info "all ready"
setTimeout (()->wait_room_start(client.room,20);return), 1000
return
wait_room_start = (room,time)->
unless !room or room.started or room.ready_player_count_without_host < room.max_player - 1
time-=1
if time
unless time % 5
ygopro.stoc_send_chat_to_room room, "#{if time <= 9 then ' ' else ''}#{time}秒后若房主不开始游戏将被请出房间", if time <= 9 then 11 else 8
setTimeout (()->wait_room_start(room,time);return), 1000
else
for player in room.players
if player.is_host
Room.ban_player(player.name, player.ip, "挂机")
ygopro.stoc_send_chat_to_room room, "#{player.name} 被请出了房间", 11
player.end()
return
#tip #tip
ygopro.stoc_send_random_tip = (client)-> ygopro.stoc_send_random_tip = (client)->
ygopro.stoc_send_chat client, "Tip: " + tips[Math.floor(Math.random() * tips.length)] if tips ygopro.stoc_send_chat client, "Tip: " + tips[Math.floor(Math.random() * tips.length)] if tips
......
// 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, ygopro; var Graveyard, Room, _, bunyan, debug, dialogues, execFile, fs, http, http_server, log, net, os, path, request, settings, tips, tribute, url, wait_room_start, ygopro;
net = require('net'); net = require('net');
...@@ -484,6 +484,21 @@ ...@@ -484,6 +484,21 @@
} }
}); });
ygopro.ctos_follow('HS_KICK', true, function(buffer, info, client, server) {
var k, len, player, ref;
if (!client.room) {
return;
}
ref = client.room.players;
for (k = 0, len = ref.length; k < len; k++) {
player = ref[k];
if (player.pos === info.pos && player !== client) {
ygopro.stoc_send_chat_to_room(client.room, player.name + " 被请出了房间", 11);
}
}
return false;
});
ygopro.stoc_follow('TYPE_CHANGE', false, function(buffer, info, client, server) { ygopro.stoc_follow('TYPE_CHANGE', false, function(buffer, info, client, server) {
var is_host, selftype; var is_host, selftype;
selftype = info.type & 0xf; selftype = info.type & 0xf;
...@@ -492,6 +507,58 @@ ...@@ -492,6 +507,58 @@
client.pos = selftype; client.pos = selftype;
}); });
ygopro.stoc_follow('HS_PLAYER_CHANGE', false, function(buffer, info, client, server) {
var is_ready, k, len, player, pos, ref;
if (!(client.room && client.room.max_player)) {
return;
}
pos = info.status >> 4;
is_ready = (info.status & 0xf) === 9;
if (pos < client.room.max_player) {
client.room.ready_player_count_without_host = 0;
ref = client.room.players;
for (k = 0, len = ref.length; k < len; k++) {
player = ref[k];
if (player.pos === pos) {
player.is_ready = is_ready;
}
if (!player.is_host) {
client.room.ready_player_count_without_host += player.is_ready;
}
}
if (client.is_host && client.room.ready_player_count_without_host >= client.room.max_player - 1) {
setTimeout((function() {
wait_room_start(client.room, 20);
}), 1000);
}
}
});
wait_room_start = function(room, time) {
var k, len, player, ref;
if (!(!room || room.started || room.ready_player_count_without_host < room.max_player - 1)) {
time -= 1;
if (time) {
if (!(time % 5)) {
ygopro.stoc_send_chat_to_room(room, "" + (time <= 9 ? ' ' : '') + time + "秒后若房主不开始游戏将被请出房间", time <= 9 ? 11 : 8);
}
setTimeout((function() {
wait_room_start(room, time);
}), 1000);
} else {
ref = room.players;
for (k = 0, len = ref.length; k < len; k++) {
player = ref[k];
if (player.is_host) {
Room.ban_player(player.name, player.ip, "挂机");
ygopro.stoc_send_chat_to_room(room, player.name + " 被请出了房间", 11);
player.end();
}
}
}
}
};
ygopro.stoc_send_random_tip = function(client) { ygopro.stoc_send_random_tip = function(client) {
if (tips) { if (tips) {
ygopro.stoc_send_chat(client, "Tip: " + tips[Math.floor(Math.random() * tips.length)]); ygopro.stoc_send_chat(client, "Tip: " + tips[Math.floor(Math.random() * tips.length)]);
......
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