\r
var clients = new Array();\r
\r
+var ipbanlist = new require("./ipban.js").IpBanCollecion();\r
+var $rooms = new require("./room.js").new RoomInfomationCollection();\r
+\r
+createLogDirectory();\r
+\r
var sessionStore;\r
\r
module.exports = function(app,server,express,session){\r
});\r
}\r
\r
-//RoomInfomationCollecionクラス\r
-function RoomInfomationCollection()\r
-{\r
- var config = require("./configure.js");\r
- var MySQLPool = new require("./mysql_pool.js");\r
- var pool = new MySQLPool({\r
- host : config.db_host,\r
- user : config.db_user,\r
- password : config.db_password,\r
- port : config.db_port,\r
- database : config.db_name,\r
- });\r
- var collection = {};\r
- this.Get = function(rno){\r
- return collection[rno];\r
- }\r
- this.IsContains = function(rno){\r
- return rno in collection;\r
- };\r
- this.GetMessage = function(){\r
- var retval = new Array();\r
- for(var rno in collection)\r
- {\r
- item={};\r
- item.applyflag = !$rooms.Get(rno).IsVolatile();\r
- item.password = collection[rno].password;\r
- if(item.password == null)\r
- item.password = "";\r
- item.hiddenlog = collection[rno].hiddenlog;\r
- retval.push(item);\r
- }\r
- return retval;\r
- };\r
- this.GetKeys = function(){\r
- var retval = {};\r
- for(var rno in collection)\r
- {\r
- retval[rno] = {};\r
- }\r
- return retval;\r
- }\r
- this.Update = function(data,callfunc){\r
- Clear();\r
- var async = require("async");\r
- async.waterfall([\r
- function(next){\r
- pool.query("TRUNCATE TABLE rooms",null,next);\r
- },\r
- function(result,next){\r
- var util = require("util");\r
- console.log(util.inspect(data));\r
- var items = new Array();\r
- var config = data.config;\r
- for(var i = 0; i < config.length; i++)\r
- {\r
- var rno = Number(config[i].applyflag);\r
- if(isNaN(rno))\r
- continue;\r
- var password,romonly;\r
- if(typeof(config[rno].password)=="undefined")\r
- password = null;\r
- else if(config[rno].password == "")\r
- password = null;\r
- else\r
- password = config[rno].password;\r
- if(typeof(config[rno].hiddenlog)=="undefined")\r
- romonly = false;\r
- else\r
- romonly = config[rno].hiddenlog == "romonly";\r
-\r
- Add(rno,password,romonly);\r
- items.push(new Array(rno,password,romonly));\r
- }\r
- pool.query("INSERT INTO rooms VALUES ?",[items],callfunc);\r
- }\r
- ],callfunc);\r
- }\r
- function GetRoomList(callback){\r
- Clear();\r
- var async = require("async");\r
- async.waterfall([\r
- function(next){\r
- pool.query("SELECT * FROM rooms",null,next);\r
- },\r
- function(result,next){\r
- for(var i = 0; i < result.length; i++)\r
- {\r
- //MySQLではTINYINTが使われている\r
- Add(result[i].number,result[i].password,result[i].hiddenlog != 0);\r
- }\r
- next(null,null);\r
- }\r
- ],callback);\r
- }\r
- function Clear(){\r
- collection = {};\r
- var config = require("./configure.js");\r
- for(var i = 0; i < config.max_room_number; i++)\r
- Add(i,null,null);\r
- };\r
- function Add(rno,pass,hiddenlogflag){\r
- collection[rno] = new RoomInfomation(pass,hiddenlogflag);\r
- if(pass != null)\r
- collection[rno].owner = $system_name;\r
- };\r
- var $gc_interval_id = setInterval(function(){\r
- for(var rno in this.rom_list)\r
- collection[rno].GCRomList();\r
- },$gc_time_interval);\r
- GetRoomList();\r
-}\r
-\r
-//RoomInfomationクラス\r
-function RoomInfomation(pass,hiddenlogflag)\r
-{\r
- this.password = pass;\r
- this.rom_list = {};\r
- this.authed_list = {};\r
- this.owner = null;\r
- this.time = null;\r
- this.hiddenlog = hiddenlogflag;\r
- this.GetConfig = function(){\r
- var roomconfig = {};\r
- if(this.IsVolatile() == false)\r
- {\r
- if(this.IsFixedPassword())\r
- roomconfig.type = 2;\r
- else if(this.IsHiddenLogFromRom())\r
- roomconfig.type = 3;\r
- else\r
- roomconfig.type = 1;\r
- roomconfig.IsOwned = !this.IsFirstAuth();\r
- }else{\r
- roomconfig.type = 0;\r
- }\r
- return roomconfig;\r
- }\r
- this.IsVolatile = function(){\r
- return this.owner == null &&\r
- this.password == null &&\r
- this.time == null &&\r
- this.hiddenlog == null;\r
- }\r
- this.GetRomCount = function(){\r
- var count = 0;\r
- for(var key in this.rom_list)\r
- count++;\r
- return count;\r
- };\r
- this.AddRom = function(ip){\r
- var date = new Date();\r
- this.rom_list[ip] = {time:date.getTime()};\r
- };\r
- this.RemoveRom = function(ip){\r
- delete this.rom_list[ip];\r
- };\r
- this.Reset = function(owner){\r
- var date = new Date();\r
- var time = date.getTime();\r
- this.password = null;\r
- this.authed_list = {};\r
- this.owner = owner;\r
- this.time = time;\r
- };\r
- this.IsFirstAuth = function(){\r
- return this.owner == null;\r
- };\r
- this.IsAuthed = function(name){\r
- return name == this.owner ||\r
- name in this.authed_list;\r
- };\r
- this.IsHiddenLogFromRom = function(){\r
- return this.hiddenlog;\r
- };\r
- this.IsFixedPassword = function(){\r
- return this.owner == $system_name;\r
- };\r
- this.IsOwner = function(name){\r
- return this.owner == name;\r
- };\r
- this.IsTimeout = function(){\r
- var date = new Date();\r
- var current_time = date.getTime();\r
- return !this.IsFixedPassword() &&\r
- current_time - this.time >= $reset_password_diff;\r
- };\r
- this.RemoveAuth = function(name)\r
- {\r
- delete this.authed_list[name];\r
- };\r
- this.Auth = function(name,password){\r
- if(this.password != password)\r
- return false;\r
- var date = new Date();\r
- var time = date.getTime();\r
- this.time = time;\r
- this.authed_list[name] = "";\r
- return true;\r
- };\r
- this.SetPassword = function(owner,password){\r
- if(owner == this.owner &&\r
- !this.IsFixedPassword() &&\r
- !this.IsHiddenLogFromRom())\r
- {\r
- var date = new Date();\r
- this.time = date.getTime();\r
- this.password = password;\r
- return true;\r
- }\r
- return false;\r
- };\r
- this.GCRomList = function(){\r
- var date = new Date();\r
- var current_time = date.getTime();\r
- for(var ip in this.rom_list)\r
- {\r
- if(current_time - this.rom_list[ip].time >= $gc_time_interval)\r
- delete this.rom_list[ip];\r
- }\r
- };\r
-}\r
-\r
-//IPBANクラス\r
-function IpBanCollecion()\r
-{\r
- var config = require("./configure.js");\r
- var MySQLPool = new require("./mysql_pool.js");\r
- var pool = new MySQLPool({\r
- host : config.db_host,\r
- user : config.db_user,\r
- password : config.db_password,\r
- port : config.db_port,\r
- database : config.db_name,\r
- });\r
- var collection = {};\r
- this.IsBaned = function(ip){\r
- return collection[ip] == "r";\r
- }\r
- this.IsBlockedToWrite = function(ip){\r
- return ip in collection;\r
- }\r
- this.GetText = function(){\r
- var text = "";\r
- for(var key in collection)\r
- {\r
- if(collection[key] == "")\r
- text += key + "\r\n";\r
- else\r
- text += key + ":" + collection[key] + "\r\n";\r
- }\r
- return text;\r
- }\r
- this.Update = function(text,callfunc){\r
- collection = {};\r
- var async = require("async");\r
- async.waterfall([\r
- function(next){\r
- pool.query("TRUNCATE TABLE ipbanlist",null,next);\r
- },\r
- function(result,next){\r
- var items = new Array();\r
- lines = text.split("\r\n");\r
- for(var i = 0; i < lines.length; i++)\r
- {\r
- var token = lines[i].split(":");\r
- var ip = token[0];\r
- if(ip == "")\r
- continue;\r
- if(token.length == 1)\r
- collection[ip] = "";\r
- else\r
- collection[ip] = token[1];\r
- items.push(new Array(ip,collection[ip]));\r
- }\r
- pool.query("INSERT INTO ipbanlist VALUES ?",[items],next);\r
- },\r
- ],callfunc);\r
- }\r
- function GetIpBanList(callfunc)\r
- {\r
- var async = require("async");\r
- async.waterfall([\r
- function(next){\r
- pool.query("SELECT * FROM ipbanlist",null,next);\r
- },\r
- function(result,next){\r
- for(var i = 0; i < result.length; i++)\r
- collection[result[i].ip] = result[i].type;\r
- next(null,null);\r
- },\r
- ],callfunc);\r
- }\r
- GetIpBanList();\r
-}\r
-\r
-var ipbanlist = new IpBanCollecion();\r
-var $rooms = new RoomInfomationCollection();\r
-\r
-createLogDirectory();\r
-\r
function createLogDirectory()\r
{\r
var fs = require("fs");\r
--- /dev/null
+//RoomInfomationCollecion\83N\83\89\83X
+module.exports.RoomInfomationCollection = function()
+{
+ var config = require("./configure.js");
+ var MySQLPool = new require("./mysql_pool.js");
+ var pool = new MySQLPool({
+ host : config.db_host,
+ user : config.db_user,
+ password : config.db_password,
+ port : config.db_port,
+ database : config.db_name,
+ });
+ var collection = {};
+ this.Get = function(rno){
+ return collection[rno];
+ }
+ this.IsContains = function(rno){
+ return rno in collection;
+ };
+ this.GetMessage = function(){
+ var retval = new Array();
+ for(var rno in collection)
+ {
+ item={};
+ item.applyflag = !$rooms.Get(rno).IsVolatile();
+ item.password = collection[rno].password;
+ if(item.password == null)
+ item.password = "";
+ item.hiddenlog = collection[rno].hiddenlog;
+ retval.push(item);
+ }
+ return retval;
+ };
+ this.GetKeys = function(){
+ var retval = {};
+ for(var rno in collection)
+ {
+ retval[rno] = {};
+ }
+ return retval;
+ }
+ this.Update = function(data,callfunc){
+ Clear();
+ var async = require("async");
+ async.waterfall([
+ function(next){
+ pool.query("TRUNCATE TABLE rooms",null,next);
+ },
+ function(result,next){
+ var util = require("util");
+ console.log(util.inspect(data));
+ var items = new Array();
+ var config = data.config;
+ for(var i = 0; i < config.length; i++)
+ {
+ var rno = Number(config[i].applyflag);
+ if(isNaN(rno))
+ continue;
+ var password,romonly;
+ if(typeof(config[rno].password)=="undefined")
+ password = null;
+ else if(config[rno].password == "")
+ password = null;
+ else
+ password = config[rno].password;
+ if(typeof(config[rno].hiddenlog)=="undefined")
+ romonly = false;
+ else
+ romonly = config[rno].hiddenlog == "romonly";
+
+ Add(rno,password,romonly);
+ items.push(new Array(rno,password,romonly));
+ }
+ pool.query("INSERT INTO rooms VALUES ?",[items],callfunc);
+ }
+ ],callfunc);
+ }
+ function GetRoomList(callback){
+ Clear();
+ var async = require("async");
+ async.waterfall([
+ function(next){
+ pool.query("SELECT * FROM rooms",null,next);
+ },
+ function(result,next){
+ for(var i = 0; i < result.length; i++)
+ {
+ //MySQL\82Å\82ÍTINYINT\82ª\8eg\82í\82ê\82Ä\82¢\82é
+ Add(result[i].number,result[i].password,result[i].hiddenlog != 0);
+ }
+ next(null,null);
+ }
+ ],callback);
+ }
+ function Clear(){
+ collection = {};
+ var config = require("./configure.js");
+ for(var i = 0; i < config.max_room_number; i++)
+ Add(i,null,null);
+ };
+ function Add(rno,pass,hiddenlogflag){
+ collection[rno] = new RoomInfomation(pass,hiddenlogflag);
+ if(pass != null)
+ collection[rno].owner = $system_name;
+ };
+ var $gc_interval_id = setInterval(function(){
+ for(var rno in this.rom_list)
+ collection[rno].GCRomList();
+ },$gc_time_interval);
+ GetRoomList();
+}
+
+//RoomInfomation\83N\83\89\83X
+function RoomInfomation(pass,hiddenlogflag)
+{
+ this.password = pass;
+ this.rom_list = {};
+ this.authed_list = {};
+ this.owner = null;
+ this.time = null;
+ this.hiddenlog = hiddenlogflag;
+ this.GetConfig = function(){
+ var roomconfig = {};
+ if(this.IsVolatile() == false)
+ {
+ if(this.IsFixedPassword())
+ roomconfig.type = 2;
+ else if(this.IsHiddenLogFromRom())
+ roomconfig.type = 3;
+ else
+ roomconfig.type = 1;
+ roomconfig.IsOwned = !this.IsFirstAuth();
+ }else{
+ roomconfig.type = 0;
+ }
+ return roomconfig;
+ }
+ this.IsVolatile = function(){
+ return this.owner == null &&
+ this.password == null &&
+ this.time == null &&
+ this.hiddenlog == null;
+ }
+ this.GetRomCount = function(){
+ var count = 0;
+ for(var key in this.rom_list)
+ count++;
+ return count;
+ };
+ this.AddRom = function(ip){
+ var date = new Date();
+ this.rom_list[ip] = {time:date.getTime()};
+ };
+ this.RemoveRom = function(ip){
+ delete this.rom_list[ip];
+ };
+ this.Reset = function(owner){
+ var date = new Date();
+ var time = date.getTime();
+ this.password = null;
+ this.authed_list = {};
+ this.owner = owner;
+ this.time = time;
+ };
+ this.IsFirstAuth = function(){
+ return this.owner == null;
+ };
+ this.IsAuthed = function(name){
+ return name == this.owner ||
+ name in this.authed_list;
+ };
+ this.IsHiddenLogFromRom = function(){
+ return this.hiddenlog;
+ };
+ this.IsFixedPassword = function(){
+ return this.owner == $system_name;
+ };
+ this.IsOwner = function(name){
+ return this.owner == name;
+ };
+ this.IsTimeout = function(){
+ var date = new Date();
+ var current_time = date.getTime();
+ return !this.IsFixedPassword() &&
+ current_time - this.time >= $reset_password_diff;
+ };
+ this.RemoveAuth = function(name)
+ {
+ delete this.authed_list[name];
+ };
+ this.Auth = function(name,password){
+ if(this.password != password)
+ return false;
+ var date = new Date();
+ var time = date.getTime();
+ this.time = time;
+ this.authed_list[name] = "";
+ return true;
+ };
+ this.SetPassword = function(owner,password){
+ if(owner == this.owner &&
+ !this.IsFixedPassword() &&
+ !this.IsHiddenLogFromRom())
+ {
+ var date = new Date();
+ this.time = date.getTime();
+ this.password = password;
+ return true;
+ }
+ return false;
+ };
+ this.GCRomList = function(){
+ var date = new Date();
+ var current_time = date.getTime();
+ for(var ip in this.rom_list)
+ {
+ if(current_time - this.rom_list[ip].time >= $gc_time_interval)
+ delete this.rom_list[ip];
+ }
+ };
+}