//RoomInfomationCollecionクラス\r
function RoomInfomationCollection()\r
{\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
+ database : "configure",\r
+ });\r
var collection = {};\r
this.Get = function(rno){\r
return collection[rno];\r
return retval;\r
}\r
this.Update = function(text,callfunc){\r
+ Clear();\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
+ function(next){\r
+ pool.query("TRUNCATE TABLE rooms",null,next);\r
},\r
- function(fd,callback){\r
- fs.close(fd,function(){\r
- GetRoomList(callfunc);\r
- });\r
- }\r
- ]);\r
- }\r
- function GetRoomList(callback){\r
- Clear();\r
- fs.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
+ function(result,next){\r
+ lines = text.split("\r\n");\r
+ var items = new Array();\r
+ for(var i = 0; i < lines.length; i++)\r
+ {\r
+ if(lines[i] == "")\r
+ continue;\r
+ var token = lines[i].split(":");\r
if(token.length == 1)\r
{\r
Add(token[0],null,false);\r
+ items.push(new Array(token[0],null,false));\r
}\r
else if(token.length == 2)\r
{\r
if(pass == "")\r
pass = null;\r
Add(rno, pass,false);\r
+ items.push(new Array(token[0],pass,false));\r
}\r
else if(token.length == 3)\r
{\r
if(token[2] == "true")\r
hiddenlog = true;\r
Add(rno, pass,hiddenlog);\r
+ items.push(new Array(token[0],pass,hiddenlog));\r
}\r
- })\r
- .join(function(){\r
- if(typeof(callback) == "function")\r
- callback();\r
- });\r
- });\r
+ }\r
+ pool.query("INSERT INTO rooms VALUES ?",[items],callfunc);\r
+ }\r
+ ],callfunc);\r
+ }\r
+ function GetRoomList(callback){\r
+ Clear();\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
}\r
else\r
{\r
- socket.emit("error",$not_match_password);\r
+ socket.emit("error",resource.unmatch_password);\r
return;\r
}\r
}\r