1 //RoomInfomationCollecion
\83N
\83\89\83X
2 module.exports = function()
5 var config = require("./configure.js");
6 var MySQLPool = new require("./mysql_pool.js");
7 var pool = new MySQLPool({
10 password : config.db_password,
11 port : config.db_port,
12 database : config.db_name,
15 this.Get = function(rno){
16 return collection[rno];
18 this.IsContains = function(rno){
19 return rno in collection;
21 this.GetMessage = function(){
22 var retval = new Array();
23 for(var rno in collection)
26 item.applyflag = !_this.Get(rno).IsVolatile();
27 item.password = collection[rno].password;
28 if(item.password == null)
30 item.hiddenlog = collection[rno].hiddenlog;
35 this.GetKeys = function(){
37 for(var rno in collection)
43 this.Update = function(data,callfunc){
45 var async = require("async");
48 pool.query("TRUNCATE TABLE rooms",null,next);
50 function(result,next){
51 var util = require("util");
52 console.log(util.inspect(data));
53 var items = new Array();
54 var config = data.config;
55 for(var i = 0; i < config.length; i++)
57 var rno = Number(config[i].applyflag);
61 if(typeof(config[rno].password)=="undefined")
63 else if(config[rno].password == "")
66 password = config[rno].password;
67 if(typeof(config[rno].hiddenlog)=="undefined")
70 romonly = config[rno].hiddenlog == "romonly";
72 Add(rno,password,romonly);
73 items.push(new Array(rno,password,romonly));
75 pool.query("INSERT INTO rooms VALUES ?",[items],callfunc);
79 function GetRoomList(callback){
81 var async = require("async");
84 pool.query("SELECT * FROM rooms",null,next);
86 function(result,next){
87 for(var i = 0; i < result.length; i++)
89 //MySQL
\82Å
\82ÍTINYINT
\82ª
\8eg
\82í
\82ê
\82Ä
\82¢
\82é
90 Add(result[i].number,result[i].password,result[i].hiddenlog != 0);
98 var config = require("./configure.js");
99 for(var i = 0; i < config.max_room_number; i++)
102 function Add(rno,pass,hiddenlogflag){
103 collection[rno] = new RoomInfomation(pass,hiddenlogflag);
105 collection[rno].owner = $system_name;
107 var $gc_interval_id = setInterval(function(){
108 for(var rno in _this.rom_list)
109 collection[rno].GCRomList();
110 },$gc_time_interval);
114 //RoomInfomation
\83N
\83\89\83X
115 function RoomInfomation(pass,hiddenlogflag)
118 this.password = pass;
120 this.authed_list = {};
123 this.hiddenlog = hiddenlogflag;
124 this.GetConfig = function(){
126 if(_this.IsVolatile() == false)
128 if(_this.IsFixedPassword())
130 else if(_this.IsHiddenLogFromRom())
134 roomconfig.IsOwned = !_this.IsFirstAuth();
140 this.IsVolatile = function(){
141 return _this.owner == null &&
142 _this.password == null &&
143 _this.time == null &&
144 _this.hiddenlog == null;
146 this.GetRomCount = function(){
148 for(var key in _this.rom_list)
152 this.AddRom = function(ip){
153 var date = new Date();
154 _this.rom_list[ip] = {time:date.getTime()};
156 this.RemoveRom = function(ip){
157 delete _this.rom_list[ip];
159 this.Reset = function(owner){
160 var date = new Date();
161 var time = date.getTime();
162 _this.password = null;
163 _this.authed_list = {};
167 this.IsFirstAuth = function(){
168 return _this.owner == null;
170 this.IsAuthed = function(name){
171 return name == _this.owner ||
172 name in _this.authed_list;
174 this.IsHiddenLogFromRom = function(){
175 return _this.hiddenlog;
177 this.IsFixedPassword = function(){
178 return _this.owner == $system_name;
180 this.IsOwner = function(name){
181 return _this.owner == name;
183 this.IsTimeout = function(){
184 var date = new Date();
185 var current_time = date.getTime();
186 return !_this.IsFixedPassword() &&
187 current_time - _this.time >= $reset_password_diff;
189 this.RemoveAuth = function(name)
191 delete _this.authed_list[name];
193 this.Auth = function(name,password){
194 if(_this.password != password)
196 var date = new Date();
197 var time = date.getTime();
199 _this.authed_list[name] = "";
202 this.SetPassword = function(owner,password){
203 if(owner == _this.owner &&
204 !_this.IsFixedPassword() &&
205 !_this.IsHiddenLogFromRom())
207 var date = new Date();
208 _this.time = date.getTime();
209 _this.password = password;
214 this.GCRomList = function(){
215 var date = new Date();
216 var current_time = date.getTime();
217 for(var ip in _this.rom_list)
219 if(current_time - _this.rom_list[ip].time >= $gc_time_interval)
220 delete _this.rom_list[ip];