소스 검색

prepare multiple boards (rooms)

dev_h
Ophir LOJKINE 12 년 전
부모
커밋
c2024c6c7a
1개의 변경된 파일6개의 추가작업 그리고 5개의 파일을 삭제
  1. 6
    5
      server/boardData.js

+ 6
- 5
server/boardData.js 파일 보기

35
     @default
35
     @default
36
     Path to the file where boards will be saved by default
36
     Path to the file where boards will be saved by default
37
 */
37
 */
38
-var HISTORY_FILE = path.join(__dirname, "../server-data/history.txt");
38
+var HISTORY_DIR = path.join(__dirname, "../server-data/");
39
 
39
 
40
 /** @constant
40
 /** @constant
41
     @type {Number}
41
     @type {Number}
44
 */
44
 */
45
 var SAVE_INTERVAL = 1000 * 2; //Save every 2 seconds of inactivity
45
 var SAVE_INTERVAL = 1000 * 2; //Save every 2 seconds of inactivity
46
 
46
 
47
+
47
 /**
48
 /**
48
  * Represents a board.
49
  * Represents a board.
49
  * @constructor
50
  * @constructor
53
 	this.name = name;
54
 	this.name = name;
54
 	this.board = {};
55
 	this.board = {};
55
 	this.ready = false;
56
 	this.ready = false;
57
+	this.file = path.join(HISTORY_DIR, "board-" + encodeURIComponent(name) + ".json");
56
 
58
 
57
 	//Loads the file. This will emit the "ready" event
59
 	//Loads the file. This will emit the "ready" event
58
-	this.load(HISTORY_FILE);
60
+	this.load(this.file);
59
 
61
 
60
 	this.on("ready", function(){
62
 	this.on("ready", function(){
61
 		that.ready = true;
63
 		that.ready = true;
62
 	});
64
 	});
63
-
64
 };
65
 };
65
 
66
 
66
 //Allows to use BoardData.emit() and BoardData.on()
67
 //Allows to use BoardData.emit() and BoardData.on()
157
 };
158
 };
158
 
159
 
159
 /** Saves the data in the board to a file.
160
 /** Saves the data in the board to a file.
160
- * @param {string} [file=HISTORY_FILE] - Path to the file where the board data will be saved.
161
+ * @param {string} [file=this.file] - Path to the file where the board data will be saved.
161
 */
162
 */
162
 BoardData.prototype.save = function (file) {
163
 BoardData.prototype.save = function (file) {
163
-	if (!file) file = HISTORY_FILE;
164
+	if (!file) file = this.file;
164
 	var board_txt = JSON.stringify(this.board);
165
 	var board_txt = JSON.stringify(this.board);
165
 	var that = this;
166
 	var that = this;
166
 	fs.writeFile(file, board_txt, function (err) {
167
 	fs.writeFile(file, board_txt, function (err) {

Loading…
취소
저장