1 //RoomInfomationCollecion
\83N
\83\89\83X
2 module.exports = function()
5 var config = require("./configure.js");
6 var RoomInfomationModel = require("./init").GetRoomInfomation;
8 this.Get = function(rno){
9 return collection[rno];
11 this.IsContains = function(rno){
12 return rno in collection;
14 this.GetMessage = function(){
15 var retval = new Array();
16 for(var rno in collection)
19 item.applyflag = !_this.Get(rno).IsVolatile();
20 item.password = collection[rno].password;
21 if(item.password == null)
23 item.hiddenlog = collection[rno].hiddenlog;
28 this.GetKeys = function(){
30 for(var rno in collection)
36 this.Update = function(data,callfunc){
38 var async = require("async");
41 RoomInfomationModel.drop().done(next);
43 function(result,next){
44 var util = require("util");
45 console.log(util.inspect(data));
46 var items = new Array();
47 var config = data.config;
48 for(var i = 0; i < config.length; i++)
50 var rno = Number(config[i].applyflag);
54 if(typeof(config[rno].password)=="undefined")
56 else if(config[rno].password == "")
59 password = config[rno].password;
60 if(typeof(config[rno].hiddenlog)=="undefined")
63 romonly = config[rno].hiddenlog == "romonly";
65 Add(rno,password,romonly);
66 items.push(new Array(rno,password,romonly));
68 newRoom = RoomInfomationModel.build(items);
69 newRoom.save().done(next);
73 function GetRoomList(callback){
75 var async = require("async");
78 RoomInfomationModel.findAll().done(next);
80 function(result,next){
81 for(var i = 0; i < result.length; i++)
83 Add(result[i].number,result[i].password,result[i].hiddenlog);
91 var config = require("./configure.js");
92 for(var i = 0; i < config.max_room_number; i++)
95 function Add(rno,pass,hiddenlogflag){
96 collection[rno] = new RoomInfomation(pass,hiddenlogflag);
98 collection[rno].owner = $system_name;
100 var $gc_interval_id = setInterval(function(){
101 for(var rno in _this.rom_list)
102 collection[rno].GCRomList();
103 },$gc_time_interval);
107 //RoomInfomation
\83N
\83\89\83X
108 function RoomInfomation(pass,hiddenlogflag)
111 this.password = pass;
113 this.authed_list = {};
116 this.hiddenlog = hiddenlogflag;
117 this.GetConfig = function(){
119 if(_this.IsVolatile() == false)
121 if(_this.IsFixedPassword())
123 else if(_this.IsHiddenLogFromRom())
127 roomconfig.IsOwned = !_this.IsFirstAuth();
133 this.IsVolatile = function(){
134 return _this.owner == null &&
135 _this.password == null &&
136 _this.time == null &&
137 _this.hiddenlog == null;
139 this.GetRomCount = function(){
141 for(var key in _this.rom_list)
145 this.AddRom = function(ip){
146 var date = new Date();
147 _this.rom_list[ip] = {time:date.getTime()};
149 this.RemoveRom = function(ip){
150 delete _this.rom_list[ip];
152 this.Reset = function(owner){
153 var date = new Date();
154 var time = date.getTime();
155 _this.password = null;
156 _this.authed_list = {};
160 this.IsFirstAuth = function(){
161 return _this.owner == null;
163 this.IsAuthed = function(name){
164 return name == _this.owner ||
165 name in _this.authed_list;
167 this.IsHiddenLogFromRom = function(){
168 return _this.hiddenlog;
170 this.IsFixedPassword = function(){
171 return _this.owner == $system_name;
173 this.IsOwner = function(name){
174 return _this.owner == name;
176 this.IsTimeout = function(){
177 var date = new Date();
178 var current_time = date.getTime();
179 return !_this.IsFixedPassword() &&
180 current_time - _this.time >= $reset_password_diff;
182 this.RemoveAuth = function(name)
184 delete _this.authed_list[name];
186 this.Auth = function(name,password){
187 if(_this.password != password)
189 var date = new Date();
190 var time = date.getTime();
192 _this.authed_list[name] = "";
195 this.SetPassword = function(owner,password){
196 if(owner == _this.owner &&
197 !_this.IsFixedPassword() &&
198 !_this.IsHiddenLogFromRom())
200 var date = new Date();
201 _this.time = date.getTime();
202 _this.password = password;
207 this.GCRomList = function(){
208 var date = new Date();
209 var current_time = date.getTime();
210 for(var ip in _this.rom_list)
212 if(current_time - _this.rom_list[ip].time >= $gc_time_interval)
213 delete _this.rom_list[ip];