clean up code

This commit is contained in:
deardrops 2017-04-10 21:15:52 +08:00 committed by WEBXOSS
parent 1d8fe4e4c6
commit 345c1750ab
6 changed files with 358 additions and 599 deletions

View file

@ -2274,46 +2274,6 @@ Player.prototype.setCoin = function(count) {
}
};
// For test:
Player.prototype.matchCard = function (arg) {
var cid = 0;
for (var i = 0; i < this.game.cards.length; i++) {
var card = this.game.cards[i];
var info = CardInfo[card.cid];
var matched = info.name === arg ||
info.name_zh_CN === arg ||
info.cid === arg ||
info.wxid === arg;
if (matched) {
cid = card.cid;
break;
}
}
if (!cid) return null;
var cards = concat(this.mainDeck.cards,this.trashZone.cards,this.enerZone.cards,this.lifeClothZone.cards);
for (var i = 0; i < cards.length; i++) {
var card = cards[i];
if (card.cid === cid) {
return card;
}
}
return null;
};
Player.prototype.getCard = function (arg) {
var card = this.matchCard(arg);
if (!card) return null;
card.moveTo(this.handZone);
return card;
};
Player.prototype.putCardToLifeCloth = function (arg) {
var card = this.matchCard(arg);
if (!card) return null;
card.moveTo(this.lifeClothZone);
return card;
};
Player.prototype.getInfectedZones = function() {
return this.signiZones.filter(function (zone) {
return zone.virus;

173
dango.js Normal file
View file

@ -0,0 +1,173 @@
// function require (file) {
// return window[file.replace(/^\.[\/\\]/,'').replace(/.js$/,'')];
// }
function handleCardInfo() {
// var defaultValueMap = {
// "rarity": "LR",
// "cardType": "SIGNI",
// "color": "white",
// "level": 0,
// "limit": 0,
// "power": 0,
// "limiting": "",
// "classes": [],
// "costWhite": 0,
// "costBlack": 0,
// "costRed": 0,
// "costBlue": 0,
// "costGreen": 0,
// "costColorless": 0,
// "guardFlag": false,
// "multiEner": false,
// };
for (var x in CardInfo) {
var info = CardInfo[x];
delete info.timestamp;
delete info.kana;
delete info.imgUrl;
delete info.cardText;
delete info.cardText_zh_CN;
delete info.cardText_en;
delete info.constEffects;
delete info.actionEffects;
delete info.startUpEffects;
delete info.spellEffect;
delete info.artsEffect;
delete info.burstEffect
delete info.faqs;
delete info.cardSkills;
delete info.growCondition;
delete info.useCondition;
delete info.costChange;
delete info.costChangeBeforeUseAsyn;
delete info.resonaPhase;
delete info.resonaCondition;
delete info.resonaAsyn;
delete info.encore;
delete info.bettedCost;
if (info.rise) info.rise = true;
// for (var key in defaultValueMap) {
// if (info[key] === defaultValueMap[key]) {
// delete info[key];
// }
// }
}
// var textarea = document.createElement('textarea');
// textarea.value = JSON.stringify(CardInfo);
// document.body.appendChild(textarea);
// textarea.select();
}
function handleCardInfo_ko(min, max) {
var props = [
"name",
"actionEffectTexts",
"constEffectTexts",
"startUpEffectTexts",
"spellEffectTexts",
"artsEffectTexts",
"burstEffectTexts",
"attachedEffectTexts",
"extraTexts",
];
var suffix = [
"",
"_zh_CN",
"_en"
]
var arr = [];
for (var x in CardInfo) {
// if (x <= 1762) continue;
if (x < min || x > max) continue;
var info = CardInfo[x];
var obj = {
pid: info.pid,
wxid: info.wxid,
};
props.forEach(function(rawprop) {
// suffix.forEach(function (suf) {
// var prop = rawprop + suf;
// if (!info[prop]) return;
// obj[prop] = info[prop];
// });
obj[rawprop + "_ko"] = info[rawprop + "_en"];
});
arr.push(obj);
}
down(arr, `${min}-${max}.json`)
}
function fetchAndHandleRuJson(url) {
let CardInfo_ru = {};
fetch(url).then(res => res.json()).then(arr => {
arr.forEach(info => {
let info_ru = {};
for (let prop in info) {
if (!prop.match(/_ru$/)) continue;
info_ru[prop] = info[prop];
}
CardInfo_ru[info.pid] = info_ru;
});
window.ru = JSON.stringify(CardInfo_ru);
});
}
function getPrCards() {
let ids = [];
for (let pid in CardInfo) {
let card = CardInfo[pid];
let id = +card.wxid.replace('PR-', '');
if (id) ids.push(id);
}
ids.sort((a, b) => a - b);
let ranges = [];
let start = ids[0];
let end = ids[0];
ids.slice(1).concat(0).forEach(id => {
if ((id - end) === 1) {
end = id;
} else {
let range = `${('000'+start).slice(-3)}-${('000'+end).slice(-3)}`;
if (start === end) range = ('000' + start).slice(-3);
ranges.push(range);
start = end = id;
}
})
return ranges;
}
function getUntestedPr() {
let ids = [];
for (let pid in CardInfo) {
if (pid <= 1762) continue;
let card = CardInfo[pid];
if (card.pid !== card.cid) continue;
if (/^PR-/.test(card.wxid)) ids.push(card.wxid);
}
return ids;
}
function getNewCardNames() {
let names = [];
for (let pid in CardInfo) {
if (pid <= 1762) continue;
let card = CardInfo[pid];
if (card.pid !== card.cid) continue;
names.push(card.name_zh_CN);
}
return names;
}
function down(content, filename = 'down.txt') {
if (typeof content === 'object') {
content = JSON.stringify(content, null, ' ')
}
let blob = new Blob([content], {
type: 'application/octet-stream'
})
let url = URL.createObjectURL(blob)
let link = document.createElement('a')
link.href = url
link.download = filename
link.click()
}

View file

@ -6,179 +6,6 @@
<title>Server</title>
<script>
var global = window;
// function require (file) {
// return window[file.replace(/^\.[\/\\]/,'').replace(/.js$/,'')];
// }
function handleCardInfo() {
// var defaultValueMap = {
// "rarity": "LR",
// "cardType": "SIGNI",
// "color": "white",
// "level": 0,
// "limit": 0,
// "power": 0,
// "limiting": "",
// "classes": [],
// "costWhite": 0,
// "costBlack": 0,
// "costRed": 0,
// "costBlue": 0,
// "costGreen": 0,
// "costColorless": 0,
// "guardFlag": false,
// "multiEner": false,
// };
for (var x in CardInfo) {
var info = CardInfo[x];
delete info.timestamp;
delete info.kana;
delete info.imgUrl;
delete info.cardText;
delete info.cardText_zh_CN;
delete info.cardText_en;
delete info.constEffects;
delete info.actionEffects;
delete info.startUpEffects;
delete info.spellEffect;
delete info.artsEffect;
delete info.burstEffect
delete info.faqs;
delete info.cardSkills;
delete info.growCondition;
delete info.useCondition;
delete info.costChange;
delete info.costChangeBeforeUseAsyn;
delete info.resonaPhase;
delete info.resonaCondition;
delete info.resonaAsyn;
delete info.encore;
delete info.bettedCost;
if (info.rise) info.rise = true;
// for (var key in defaultValueMap) {
// if (info[key] === defaultValueMap[key]) {
// delete info[key];
// }
// }
}
// var textarea = document.createElement('textarea');
// textarea.value = JSON.stringify(CardInfo);
// document.body.appendChild(textarea);
// textarea.select();
}
function handleCardInfo_ko(min, max) {
var props = [
"name",
"actionEffectTexts",
"constEffectTexts",
"startUpEffectTexts",
"spellEffectTexts",
"artsEffectTexts",
"burstEffectTexts",
"attachedEffectTexts",
"extraTexts",
];
var suffix = [
"",
"_zh_CN",
"_en"
]
var arr = [];
for (var x in CardInfo) {
// if (x <= 1762) continue;
if (x < min || x > max) continue;
var info = CardInfo[x];
var obj = {
pid: info.pid,
wxid: info.wxid,
};
props.forEach(function(rawprop) {
// suffix.forEach(function (suf) {
// var prop = rawprop + suf;
// if (!info[prop]) return;
// obj[prop] = info[prop];
// });
obj[rawprop + "_ko"] = info[rawprop + "_en"];
});
arr.push(obj);
}
down(arr, `${min}-${max}.json`)
}
function fetchAndHandleRuJson(url) {
let CardInfo_ru = {};
fetch(url).then(res => res.json()).then(arr => {
arr.forEach(info => {
let info_ru = {};
for (let prop in info) {
if (!prop.match(/_ru$/)) continue;
info_ru[prop] = info[prop];
}
CardInfo_ru[info.pid] = info_ru;
});
window.ru = JSON.stringify(CardInfo_ru);
});
}
function getPrCards() {
let ids = [];
for (let pid in CardInfo) {
let card = CardInfo[pid];
let id = +card.wxid.replace('PR-', '');
if (id) ids.push(id);
}
ids.sort((a, b) => a - b);
let ranges = [];
let start = ids[0];
let end = ids[0];
ids.slice(1).concat(0).forEach(id => {
if ((id - end) === 1) {
end = id;
} else {
let range = `${('000'+start).slice(-3)}-${('000'+end).slice(-3)}`;
if (start === end) range = ('000' + start).slice(-3);
ranges.push(range);
start = end = id;
}
})
return ranges;
}
function getUntestedPr() {
let ids = [];
for (let pid in CardInfo) {
if (pid <= 1762) continue;
let card = CardInfo[pid];
if (card.pid !== card.cid) continue;
if (/^PR-/.test(card.wxid)) ids.push(card.wxid);
}
return ids;
}
function getNewCardNames() {
let names = [];
for (let pid in CardInfo) {
if (pid <= 1762) continue;
let card = CardInfo[pid];
if (card.pid !== card.cid) continue;
names.push(card.name_zh_CN);
}
return names;
}
function down(content, filename = 'down.txt') {
if (typeof content === 'object') {
content = JSON.stringify(content, null, ' ')
}
let blob = new Blob([content], {
type: 'application/octet-stream'
})
let url = URL.createObjectURL(blob)
let link = document.createElement('a')
link.href = url
link.download = filename
link.click()
}
</script>
<script src="util.js"></script>
<script src="random.min.js"></script>
@ -200,8 +27,8 @@
<script src="Client.js"></script>
<script src="Room.js"></script>
<script src="RoomManager.js"></script>
<script src="test.js"></script>
<script src="testHelper.js"></script>
<script src="dango.js"></script>
</head>
<body>

200
test.html
View file

@ -1,200 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Server</title>
<script>
var global = window;
// function require (file) {
// return window[file.replace(/^\.[\/\\]/,'').replace(/.js$/,'')];
// }
function handleCardInfo () {
// var defaultValueMap = {
// "rarity": "LR",
// "cardType": "SIGNI",
// "color": "white",
// "level": 0,
// "limit": 0,
// "power": 0,
// "limiting": "",
// "classes": [],
// "costWhite": 0,
// "costBlack": 0,
// "costRed": 0,
// "costBlue": 0,
// "costGreen": 0,
// "costColorless": 0,
// "guardFlag": false,
// "multiEner": false,
// };
for (var x in CardInfo) {
var info = CardInfo[x];
delete info.timestamp;
delete info.kana;
delete info.imgUrl;
delete info.cardText;
delete info.cardText_zh_CN;
delete info.cardText_en;
delete info.constEffects;
delete info.actionEffects;
delete info.startUpEffects;
delete info.spellEffect;
delete info.artsEffect;
delete info.burstEffect
delete info.faqs;
delete info.cardSkills;
delete info.growCondition;
delete info.useCondition;
delete info.costChange;
delete info.costChangeBeforeUseAsyn;
delete info.resonaPhase;
delete info.resonaCondition;
delete info.resonaAsyn;
delete info.encore;
delete info.bettedCost;
if (info.rise) info.rise = true;
// for (var key in defaultValueMap) {
// if (info[key] === defaultValueMap[key]) {
// delete info[key];
// }
// }
}
// var textarea = document.createElement('textarea');
// textarea.value = JSON.stringify(CardInfo);
// document.body.appendChild(textarea);
// textarea.select();
}
function handleCardInfo_ko (min, max) {
var props = [
"name",
"actionEffectTexts",
"constEffectTexts",
"startUpEffectTexts",
"spellEffectTexts",
"artsEffectTexts",
"burstEffectTexts",
"attachedEffectTexts",
"extraTexts",
];
var suffix = [
"",
"_zh_CN",
"_en"
]
var arr = [];
for (var x in CardInfo) {
// if (x <= 1762) continue;
if (x < min || x > max) continue;
var info = CardInfo[x];
var obj = {
pid: info.pid,
wxid: info.wxid,
};
props.forEach(function (rawprop) {
// suffix.forEach(function (suf) {
// var prop = rawprop + suf;
// if (!info[prop]) return;
// obj[prop] = info[prop];
// });
obj[rawprop+"_ko"] = info[rawprop+"_en"];
});
arr.push(obj);
}
down(arr, `${min}-${max}.json`)
}
function fetchAndHandleRuJson (url) {
let CardInfo_ru = {};
fetch(url).then(res => res.json()).then(arr => {
arr.forEach(info => {
let info_ru = {};
for (let prop in info) {
if (!prop.match(/_ru$/)) continue;
info_ru[prop] = info[prop];
}
CardInfo_ru[info.pid] = info_ru;
});
window.ru = JSON.stringify(CardInfo_ru);
});
}
function getPrCards () {
let ids = [];
for (let pid in CardInfo) {
let card = CardInfo[pid];
let id = +card.wxid.replace('PR-','');
if (id) ids.push(id);
}
ids.sort((a,b) => a-b);
let ranges = [];
let start = ids[0];
let end = ids[0];
ids.slice(1).concat(0).forEach(id => {
if ((id - end) === 1) {
end = id;
} else {
let range = `${('000'+start).slice(-3)}-${('000'+end).slice(-3)}`;
if (start === end) range = ('000'+start).slice(-3);
ranges.push(range);
start = end = id;
}
})
return ranges;
}
function getUntestedPr () {
let ids = [];
for (let pid in CardInfo) {
if (pid <= 1762) continue;
let card = CardInfo[pid];
if (card.pid !== card.cid) continue;
if (/^PR-/.test(card.wxid)) ids.push(card.wxid);
}
return ids;
}
function getNewCardNames () {
let names = [];
for (let pid in CardInfo) {
if (pid <= 1762) continue;
let card = CardInfo[pid];
if (card.pid !== card.cid) continue;
names.push(card.name_zh_CN);
}
return names;
}
function down (content, filename = 'down.txt') {
if (typeof content === 'object') {
content = JSON.stringify(content, null, ' ')
}
let blob = new Blob([content], { type: 'application/octet-stream' })
let url = URL.createObjectURL(blob)
let link = document.createElement('a')
link.href = url
link.download = filename
link.click()
}
</script>
<script src="util.js"></script>
<script src="random.min.js"></script>
<script src="Callback.js"></script>
<script src="Game.js"></script>
<script src="Phase.js"></script>
<script src="IO.js"></script>
<script src="Player.js"></script>
<script src="Card.js"></script>
<script src="Zone.js"></script>
<script src="CardInfo.js"></script>
<script src="Timming.js"></script>
<script src="Mask.js"></script>
<script src="ConstEffect.js"></script>
<script src="ConstEffectManager.js"></script>
<script src="Effect.js"></script>
<script src="EffectManager.js"></script>
<script src="FakeSocket.js"></script>
<script src="Client.js"></script>
<script src="Room.js"></script>
<script src="RoomManager.js"></script>
<script src="test.js"></script>
</head>
<body>
<button onclick="newClient();">newClient</button>
</body>
</html>

325
test.js
View file

@ -1,192 +1,167 @@
'use strict';
if (!global.window) {
global.Random = require("random-js");
require("./util.js");
require("./Callback.js");
require("./Game.js");
require("./Phase.js");
require("./IO.js");
require("./Player.js");
require("./Card.js");
require("./Zone.js");
require("./CardInfo.js");
require("./Timming.js");
require("./Mask.js");
require("./ConstEffect.js");
require("./ConstEffectManager.js");
require("./Effect.js");
require("./EffectManager.js");
require("./Client.js");
require("./Room.js");
require("./RoomManager.js");
}
// node env only
var io;
if (global.window) {
io = {
on: function (name,handler) {
io._handler = handler;
},
use: function () {}
};
global.window.newClient = function () {
var win = window.open('./webxoss-client/?local=true');
win.addEventListener('load',function () {
var socket = new FakeSocket(win);
win.addEventListener('unload',function () {
socket._doEmit('disconnect');
});
win.document.title = 'Client' + socket.id;
io._handler(socket);
});
}
} else {
var noStaticServe = process.argv.slice(2).some(function (arg) {
return arg === 'no-static-server';
});
// static server
if (!noStaticServe) {
var express = require('express');
var compression = require('compression');
var app = express();
var server = require('http').Server(app);
app.use(compression());
app.use('/background',express.static(__dirname + '/webxoss-client/images',{
maxAge: '2h'
}));
app.use('/images',express.static(__dirname + '/webxoss-client/images',{
maxAge: '30d'
}));
app.use(express.static(__dirname + '/webxoss-client'));
var port = 80;
process.argv.slice(2).forEach(function (arg) {
var match = arg.match(/^port=(\d+)/)
if (match) {
port = +match[1];
}
});
server.listen(port);
}
// game server
var getArg = function (key) {
var value = '';
process.argv.slice(2).forEach(function (arg) {
if (arg.indexOf(key + '=') === 0) {
value = arg.replace(key + '=', '');
}
});
return value;
};
var gameServer
if (getArg('key')) {
var fs = require('fs');
gameServer = require('https').createServer({
key: fs.readFileSync(getArg('key')),
cert: fs.readFileSync(getArg('cert')),
ca: fs.readFileSync(getArg('ca')),
});
} else {
gameServer = require('http').createServer();
}
io = require('socket.io')(gameServer,{
pingTimeout: 30000,
maxHttpBufferSize: 1024*1024,
});
gameServer.listen(2015);
global.Random = require("random-js");
require("./util.js");
require("./Callback.js");
require("./Game.js");
require("./Phase.js");
require("./IO.js");
require("./Player.js");
require("./Card.js");
require("./Zone.js");
require("./CardInfo.js");
require("./Timming.js");
require("./Mask.js");
require("./ConstEffect.js");
require("./ConstEffectManager.js");
require("./Effect.js");
require("./EffectManager.js");
require("./Client.js");
require("./Room.js");
require("./RoomManager.js");
var noStaticServe = process.argv.slice(2).some(function(arg) {
return arg === 'no-static-server';
});
// static server
if (!noStaticServe) {
var express = require('express');
var compression = require('compression');
var app = express();
var server = require('http').Server(app);
app.use(compression());
app.use('/background', express.static(__dirname + '/webxoss-client/images', {
maxAge: '2h'
}));
app.use('/images', express.static(__dirname + '/webxoss-client/images', {
maxAge: '30d'
}));
app.use(express.static(__dirname + '/webxoss-client'));
var port = 80;
process.argv.slice(2).forEach(function(arg) {
var match = arg.match(/^port=(\d+)/)
if (match) {
port = +match[1];
}
});
server.listen(port);
console.log('server listen on 127.0.0.1:' + port);
}
// game server
var getArg = function(key) {
var value = '';
process.argv.slice(2).forEach(function(arg) {
if (arg.indexOf(key + '=') === 0) {
value = arg.replace(key + '=', '');
}
});
return value;
};
var gameServer
if (getArg('key')) {
var fs = require('fs');
gameServer = require('https').createServer({
key: fs.readFileSync(getArg('key')),
cert: fs.readFileSync(getArg('cert')),
ca: fs.readFileSync(getArg('ca')),
});
} else {
gameServer = require('http').createServer();
}
var io = require('socket.io')(gameServer, {
pingTimeout: 30000,
maxHttpBufferSize: 1024 * 1024,
});
gameServer.listen(2015);
var cfg = {
MAX_ROOMS: 100,
MAX_CLIENTS: 500,
MAX_ROOM_NAME_LENGTH: 15,
MAX_NICKNAME_LENGTH: 10,
MAX_PASSWORD_LENGTH: 15
MAX_ROOMS: 100,
MAX_CLIENTS: 500,
MAX_ROOM_NAME_LENGTH: 15,
MAX_NICKNAME_LENGTH: 10,
MAX_PASSWORD_LENGTH: 15
};
var roomManager = new RoomManager(cfg);
var MAX_SOCKETS = 500;
// var MAX_SOCKETS_PER_IP = 50;
// var ipTable = {};
function getSocketCount () {
if (!io.sockets) return 0;
return Object.keys(io.sockets.connected).length;
function getSocketCount() {
if (!io.sockets) return 0;
return Object.keys(io.sockets.connected).length;
}
io.use(function (socket,next) {
if (getSocketCount() >= MAX_SOCKETS) {
next(new Error('MAX_SOCKETS'));
return;
}
// var handshake = socket.request;
// var ip = handshake.connection.remoteAddress;
// if (!ip) {
// next();
// return;
// }
// if (ip in ipTable) {
// if (ipTable[ip] >= MAX_SOCKETS_PER_IP) {
// console.log('MAX_SOCKETS_PER_IP: %s',ip);
// next(new Error('MAX_SOCKETS_PER_IP'));
// return;
// } else {
// ipTable[ip]++;
// }
// } else {
// ipTable[ip] = 1;
// }
// socket.on('disconnect',function () {
// console.log('disconnect: %s, count: %s',ip,getSocketCount());
// if (ip in ipTable) {
// if (ipTable[ip] <= 1) {
// delete ipTable[ip];
// } else {
// ipTable[ip]--;
// }
// }
// });
next();
io.use(function(socket, next) {
if (getSocketCount() >= MAX_SOCKETS) {
next(new Error('MAX_SOCKETS'));
return;
}
// var handshake = socket.request;
// var ip = handshake.connection.remoteAddress;
// if (!ip) {
// next();
// return;
// }
// if (ip in ipTable) {
// if (ipTable[ip] >= MAX_SOCKETS_PER_IP) {
// console.log('MAX_SOCKETS_PER_IP: %s',ip);
// next(new Error('MAX_SOCKETS_PER_IP'));
// return;
// } else {
// ipTable[ip]++;
// }
// } else {
// ipTable[ip] = 1;
// }
// socket.on('disconnect',function () {
// console.log('disconnect: %s, count: %s',ip,getSocketCount());
// if (ip in ipTable) {
// if (ipTable[ip] <= 1) {
// delete ipTable[ip];
// } else {
// ipTable[ip]--;
// }
// }
// });
next();
});
io.on('connect',function (socket) {
if (global.window) {
return roomManager.createClient(socket);
}
var req = socket.request;
if (req.connection.destroyed) {
console.log('req.connection.destroyed');
return;
}
var query = require('url').parse(req.url,true).query;
// console.log('connect: %s, count: %s',req.connection.remoteAddress,getSocketCount());
// console.log(query.clientId);
roomManager.createClient(socket,+query.clientId);
io.on('connect', function(socket) {
var req = socket.request;
if (req.connection.destroyed) {
console.log('req.connection.destroyed');
return;
}
var query = require('url').parse(req.url, true).query;
// console.log('connect: %s, count: %s',req.connection.remoteAddress,getSocketCount());
// console.log(query.clientId);
roomManager.createClient(socket, +query.clientId);
// test
// socket.on('force disconnect',function () {
// socket.disconnect();
// });
// test
// socket.on('force disconnect',function () {
// socket.disconnect();
// });
// for debug
if (typeof process === 'undefined') return;
var password = '';
process.argv.slice(2).forEach(function (arg) {
var match = arg.match(/^debug_password=(\S+)/)
if (match) {
password = match[1];
}
});
if (!password) return;
socket.on('debug',function (psw) {
if (psw !== password) return;
try {
var path = require('path');
var filePath = './debug.js';
delete require.cache[path.resolve(filePath)];
require(filePath);
} catch (e) {
console.log(e);
}
});
// for debug
if (typeof process === 'undefined') return;
var password = '';
process.argv.slice(2).forEach(function(arg) {
var match = arg.match(/^debug_password=(\S+)/)
if (match) {
password = match[1];
}
});
if (!password) return;
socket.on('debug', function(psw) {
if (psw !== password) return;
try {
var path = require('path');
var filePath = './debug.js';
delete require.cache[path.resolve(filePath)];
require(filePath);
} catch (e) {
console.log(e);
}
});
});
if (!global.window) {
exports.roomManager = roomManager;
}
exports.roomManager = roomManager;

View file

@ -2,10 +2,39 @@
// browser only
var $ = document.getElementById.bind(document);
// server
var io = {
on: function (name,handler) {
io._handler = handler;
},
use: function () {}
};
var cfg = {
MAX_ROOMS: 100,
MAX_CLIENTS: 500,
MAX_ROOM_NAME_LENGTH: 15,
MAX_NICKNAME_LENGTH: 10,
MAX_PASSWORD_LENGTH: 15
};
var roomManager = new RoomManager(cfg);
var MAX_SOCKETS = 500;
function getSocketCount () {
if (!io.sockets) return 0;
return Object.keys(io.sockets.connected).length;
}
io.use(function (socket,next) {
if (getSocketCount() >= MAX_SOCKETS) {
next(new Error('MAX_SOCKETS'));
return;
}
next();
});
io.on('connect',function (socket) {
return roomManager.createClient(socket);
});
// client
var noBGM = true;
function disableAudio(doc) {
// disable BGM
if (!noBGM) {
@ -20,7 +49,6 @@ function disableAudio(doc) {
sound.click();
}
}
function initClient(win) {
var doc = win.document;
var socket = new FakeSocket(win);
@ -58,7 +86,6 @@ function startBattle() {
initClient(win);
});
}
function oben() {
if (sockets.length !== 2) {
log('two client needed.');
@ -100,7 +127,6 @@ function handleBattle() {
log('Handle game successfully.');
log('Now you can use helper function.');
}
function skipDiscards() {
Player.prototype.redrawAsyn = function() {
return new Callback.immediately();
@ -176,13 +202,14 @@ function matchCard(arg) {
return null;
}
var $ = document.getElementById.bind(document);
var zones = [
'handZone',
'enerZone',
'trashZone',
'lifeClothZone',
];
function addTo(zone) {
if (zones.indexOf(zone) === -1) {
log('no such zone: ' + zone);
@ -202,7 +229,6 @@ function addTo(zone) {
log('card\'s wxid / pid / cid needed.');
}
}
function resetLrigDeck() {
var p = selectPlayer();
game.moveCards(p.lrigTrashZone.cards, p.lrigDeck);
@ -258,7 +284,6 @@ function changeLanguage() {
log('set language to ' + lang + '.');
location.reload();
}
function handleDeckEditor() {
var iFrame = $('deck-editor');
@ -277,7 +302,6 @@ function handleDeckEditor() {
}
});
}
function enableButtons() {
var buttons = document.getElementsByTagName('button');
for (var i = 0; i < buttons.length; i++) {
@ -286,7 +310,6 @@ function enableButtons() {
}
}
}
function disableButtons() {
var buttons = document.getElementsByTagName('button');
for (var i = 0; i < buttons.length; i++) {
@ -295,6 +318,7 @@ function disableButtons() {
}
}
}
window.onload = function() {
$('select-language').value = localStorage.getItem('language');
updateDeckSelect();