+\r
+//RoomInfomationCollecionクラス\r
+function RoomInfomationCollection()\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.GetString = function(){\r
+ var retval = "";\r
+ for(var rno in collection)\r
+ {\r
+ if($rooms.Get(rno).IsVolatile())\r
+ continue;\r
+ var pass = collection[rno].password;\r
+ if(pass == null)\r
+ pass = "";\r
+ var hiddenlog = collection[rno].hiddenlog;\r
+ retval += rno + ":" + pass + ":" + hiddenlog + "\r\n";\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(text,callfunc){\r
+ async.waterfall([\r
+ function(callback){\r
+ fs.open($room_configure_file_name,"w",callback);\r
+ },\r
+ function(fd,callback){\r
+ var buf = new Buffer(text);\r
+ fs.write(fd,buf,0,Buffer.byteLength(text),null,function(){\r
+ callback(null,fd);\r
+ });\r
+ },\r
+ function(fd,callback){\r
+ fs.close(fd,function(){\r
+ GetRoomList(callfunc);\r
+ });\r
+ }\r
+ ]);\r
+ }\r
+ function GetRoomList(callback){\r
+ Clear();\r
+ path.exists($room_configure_file_name,function(exists){\r
+ if(exists == false)\r
+ {\r
+ if(typeof(callback) == "function")\r
+ callback();\r
+ return;\r
+ }\r
+ var stream = fs.createReadStream($room_configure_file_name);\r
+ new lazy(stream)\r
+ .lines\r
+ .forEach(function(line){\r
+ var token = line.toString().replace(/(\r|\n|\r\n)/gm, "").split(":");\r
+ if(token.length == 1)\r
+ {\r
+ Add(token[0],null,false);\r
+ }\r
+ else if(token.length == 2)\r
+ {\r
+ var rno = token[0];\r
+ var pass = token[1];\r
+ if(pass == "")\r
+ pass = null;\r
+ Add(rno, pass,false);\r
+ }\r
+ else if(token.length == 3)\r
+ {\r
+ var rno = token[0];\r
+ var pass = token[1];\r
+ if(pass == "")\r
+ pass = null;\r
+ var hiddenlog = false;\r
+ if(token[2] == "true")\r
+ hiddenlog = true;\r
+ Add(rno, pass,hiddenlog);\r
+ }\r
+ })\r
+ .join(function(){\r
+ if(typeof(callback) == "function")\r
+ callback();\r
+ });\r
+ });\r
+ }\r
+ function Clear(){\r
+ collection = {};\r
+ for(var i = 0; i < $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.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 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
+ async.waterfall([\r
+ function(callback){\r
+ fs.open($ip_ban_list_file_name,"w",callback);\r
+ },\r
+ function(fd,callback){\r
+ var buf = new Buffer(text);\r
+ fs.write(fd,buf,0,Buffer.byteLength(text),null,function(){\r
+ callback(null,fd);\r
+ });\r
+ },\r
+ function(fd,callback){\r
+ fs.close(fd,function(){\r
+ GetIpBanList(callfunc);\r
+ });\r
+ }\r
+ ]);\r
+ }\r
+ function GetIpBanList(callback)\r
+ {\r
+ collection = {};\r
+ path.exists($ip_ban_list_file_name,function(exists){\r
+ if(exists == false)\r
+ {\r
+ if(typeof(callback) == "function")\r
+ callback();\r
+ return;\r
+ }\r
+ var stream = fs.createReadStream($ip_ban_list_file_name);\r
+ new lazy(stream)\r
+ .lines\r
+ .forEach(function(line){\r
+ var token = line.toString().replace(/(\r|\n|\r\n)/gm, "").split(":");\r
+ var ip = token[0];\r
+ if(token.length == 1)\r
+ collection[ip] = "";\r
+ else\r
+ collection[ip] = token[1];\r
+ })\r
+ .join(function(){\r
+ if(typeof(callback) == "function")\r
+ callback();\r
+ });\r
+ });\r
+ }\r
+ GetIpBanList();\r
+}\r
+\r