1 //RoomInfomationCollecion
\83N
\83\89\83X
2 module.exports = function()
4 var config = require("./configure.js");
5 var MySQLPool = new require("./mysql_pool.js");
6 var pool = new MySQLPool({
9 password : config.db_password,
10 port : config.db_port,
11 database : config.db_name,
14 this.Get = function(rno){
15 return collection[rno];
17 this.IsContains = function(rno){
18 return rno in collection;
20 this.GetMessage = function(){
21 var retval = new Array();
22 for(var rno in collection)
25 item.applyflag = !$rooms.Get(rno).IsVolatile();
26 item.password = collection[rno].password;
27 if(item.password == null)
29 item.hiddenlog = collection[rno].hiddenlog;
34 this.GetKeys = function(){
36 for(var rno in collection)
42 this.Update = function(data,callfunc){
44 var async = require("async");
47 pool.query("TRUNCATE TABLE rooms",null,next);
49 function(result,next){
50 var util = require("util");
51 console.log(util.inspect(data));
52 var items = new Array();
53 var config = data.config;
54 for(var i = 0; i < config.length; i++)
56 var rno = Number(config[i].applyflag);
60 if(typeof(config[rno].password)=="undefined")
62 else if(config[rno].password == "")
65 password = config[rno].password;
66 if(typeof(config[rno].hiddenlog)=="undefined")
69 romonly = config[rno].hiddenlog == "romonly";
71 Add(rno,password,romonly);
72 items.push(new Array(rno,password,romonly));
74 pool.query("INSERT INTO rooms VALUES ?",[items],callfunc);
78 function GetRoomList(callback){
80 var async = require("async");
83 pool.query("SELECT * FROM rooms",null,next);
85 function(result,next){
86 for(var i = 0; i < result.length; i++)
88 //MySQL
\82Å
\82ÍTINYINT
\82ª
\8eg
\82í
\82ê
\82Ä
\82¢
\82é
89 Add(result[i].number,result[i].password,result[i].hiddenlog != 0);
97 var config = require("./configure.js");
98 for(var i = 0; i < config.max_room_number; i++)
101 function Add(rno,pass,hiddenlogflag){
102 collection[rno] = new RoomInfomation(pass,hiddenlogflag);
104 collection[rno].owner = $system_name;
106 var $gc_interval_id = setInterval(function(){
107 for(var rno in this.rom_list)
108 collection[rno].GCRomList();
109 },$gc_time_interval);
113 //RoomInfomation
\83N
\83\89\83X
114 function RoomInfomation(pass,hiddenlogflag)
116 this.password = pass;
118 this.authed_list = {};
121 this.hiddenlog = hiddenlogflag;
122 this.GetConfig = function(){
124 if(this.IsVolatile() == false)
126 if(this.IsFixedPassword())
128 else if(this.IsHiddenLogFromRom())
132 roomconfig.IsOwned = !this.IsFirstAuth();
138 this.IsVolatile = function(){
139 return this.owner == null &&
140 this.password == null &&
142 this.hiddenlog == null;
144 this.GetRomCount = function(){
146 for(var key in this.rom_list)
150 this.AddRom = function(ip){
151 var date = new Date();
152 this.rom_list[ip] = {time:date.getTime()};
154 this.RemoveRom = function(ip){
155 delete this.rom_list[ip];
157 this.Reset = function(owner){
158 var date = new Date();
159 var time = date.getTime();
160 this.password = null;
161 this.authed_list = {};
165 this.IsFirstAuth = function(){
166 return this.owner == null;
168 this.IsAuthed = function(name){
169 return name == this.owner ||
170 name in this.authed_list;
172 this.IsHiddenLogFromRom = function(){
173 return this.hiddenlog;
175 this.IsFixedPassword = function(){
176 return this.owner == $system_name;
178 this.IsOwner = function(name){
179 return this.owner == name;
181 this.IsTimeout = function(){
182 var date = new Date();
183 var current_time = date.getTime();
184 return !this.IsFixedPassword() &&
185 current_time - this.time >= $reset_password_diff;
187 this.RemoveAuth = function(name)
189 delete this.authed_list[name];
191 this.Auth = function(name,password){
192 if(this.password != password)
194 var date = new Date();
195 var time = date.getTime();
197 this.authed_list[name] = "";
200 this.SetPassword = function(owner,password){
201 if(owner == this.owner &&
202 !this.IsFixedPassword() &&
203 !this.IsHiddenLogFromRom())
205 var date = new Date();
206 this.time = date.getTime();
207 this.password = password;
212 this.GCRomList = function(){
213 var date = new Date();
214 var current_time = date.getTime();
215 for(var ip in this.rom_list)
217 if(current_time - this.rom_list[ip].time >= $gc_time_interval)
218 delete this.rom_list[ip];