33 * contributing/refactoring also by: @Ntwitch (github.com)
44 * started: 26Jan15
55 * alpha phase: 28Feb15
6- * beta phase:
6+ * beta phase: 13May15
77 * finished:
88 *
99 * This file is for any of the functionality that I still need to work on that
1313 */
1414
1515roomData = {
16- //properites
16+ //properites - try to determine why these are not accessible (NaN) in areas
1717 userDir : system . data_dir + "user/" ,
1818 roomSettingsFilename : "docrooms" ,
1919 maxInfoLines : 160 ,
@@ -59,7 +59,8 @@ roomData = {
5959 roomSettingsUX : {
6060 /*
6161 * summary:
62- * Call to prompt user and change room info
62+ * Calls displayRoomInfo(), determines permissions for changing the
63+ * room info, calls changeRoomInfo() if appropriate
6364 */
6465 promptUserForRoomInfo : function ( ) {
6566 this . displayRoomInfo ( ) ;
@@ -83,20 +84,29 @@ roomData = {
8384 } ,
8485 /*
8586 * summary:
86- * Resets room info
87+ * Changes room info by calling poast.getTextBlob(); then calls
88+ * roomData.fileIO.saveRoomInfo() in order to commit the changes
8789 */
8890 changeRoomInfo : function ( ) {
8991 var infoTxt = new Array ( ) ;
9092
9193 if ( ( infoTxt = poast . getTextBlob ( this . maxInfoLines ) ) != null ) {
9294 //save the new room info
93- try {
94- roomData . fileIO . saveRoomInfo ( infoTxt ) ;
95+ /* try {
96+ roomSettings[bbs.cursub_code] =
97+ roomData.fileIO.saveRoomInfo(infoTxt, bbs.cursub_code);
9598 } catch (e) {
9699 console.putmsg(red + "changeRoomInfo() exception: " +
97100 e.name + "\nmessage: " + e.message + "\tnum: " + e.number +
98101 "\n");
99- }
102+ }*/
103+ roomSettings [ bbs . cursub_code ] . info = infoTxt ;
104+ roomSettings [ bbs . cursub_code ] . moderator = user . alias ;
105+ //of course this will have to be replaced with better code to
106+ //make sure the person is authorized, sysop modification of it,
107+ //etc etc etc (re: above)
108+ //roomSettings[bbs.cursub_code].infoCreationDate =
109+ roomData . fileIO . saveRoomInfo ( ) ;
100110 }
101111 } ,
102112 /*
@@ -108,17 +118,18 @@ roomData = {
108118 this . displayRoomInfoHdr ( ) ;
109119
110120 try {
111- roomSettings = snagRoomInfoBlob ( ) ;
121+ roomSettings [ bbs . cursub_code ] = snagRoomInfoBlob ( ) ;
112122 } catch ( e ) {
113- console . putmsg ( "Unable to snagRoomInfoBlob()\n" ) ;
123+ console . putmsg ( "Unable to snagRoomInfoBlob(): " + e . name +
124+ "\nMsg: " + e . message + "\n" ) ;
114125 }
115126
116- if ( roomSettings [ bbs . cursub_code ] . settings . info . length == 0 ) {
127+ if ( roomSettings [ bbs . cursub_code ] . info . length == 0 ) {
117128 //or should we be looking for null here?
118129 console . putmsg ( green + high_intensity +
119130 "The scroll is blank!\n\n" ) ;
120131 } else {
121- for each ( var ln in roomSettings [ bbs . cursub_code ] . settings . info ) {
132+ for each ( var ln in roomSettings [ bbs . cursub_code ] . info ) {
122133 console . putmsg ( green + high_intensity + ln + "\n" ) ;
123134 }
124135 }
@@ -134,7 +145,7 @@ roomData = {
134145 displayRoomInfoHdr : function ( ) {
135146 var mBase = new MsgBase ( bbs . cursub_code ) ;
136147
137- if ( roomSettings [ bbs . cursub_code ] == null ) {
148+ /* if (roomSettings[bbs.cursub_code] == null) {
138149 if (userSettings.debug.misc) {
139150 console.putmsg(green + high_intensity +"\nNo roominfo has been " +
140151 "set yet for " + cyan + bbs.cursub_code + "\n\n");
@@ -146,10 +157,15 @@ roomData = {
146157
147158 //this will have to throw an exception after we learn to create
148159 //the new entries
149- }
160+ } this should now be unnecessary, handled in file_io areas */
161+
162+ if ( userSettings . debug . misc ) {
163+ console . putmsg ( green + "Working with roomSettings:\n" +
164+ JSON . stringify ( roomSettings ) + "\n" ) ;
165+ }
150166
151167 console . putmsg ( green + high_intensity + "\nForum Moderator is " +
152- cyan + roomSettings [ bbs . cursub_code ] . settings . moderator + ". " +
168+ cyan + roomSettings [ bbs . cursub_code ] . moderator + ". " +
153169 "Total messages: " ) ;
154170
155171 try {
@@ -163,8 +179,8 @@ roomData = {
163179
164180 console . putmsg ( red + high_intensity + mBase . total_msgs + "\n" +
165181 green + "Forum info last updated: " + magenta +
166- roomSettings [ bbs . cursub_code ] . settings . infoCreationDate + green +
167- " by " + cyan + roomSettings [ bbs . cursub_code ] . settings . moderator +
182+ roomSettings [ bbs . cursub_code ] . infoCreationDate + green +
183+ " by " + cyan + roomSettings [ bbs . cursub_code ] . moderator +
168184 "\n\n" ) ;
169185
170186 mBase . close ( ) ;
@@ -188,55 +204,41 @@ roomData = {
188204 //--++==**methods**==++--
189205 /*
190206 * summary:
191- * Method saves the text as room info
207+ * Method saves room info blob in general; if the current room
208+ * does not exist in the roomSettings object it creates a new one
209+ * with the default information
192210 */
193- saveRoomInfo : function ( roomInfo ) {
194- var blob = this . snagRoomInfoBlob ( this . roomRecFilename , bbs . cursub_code ) ;
195- var rmInfoz = { } ;
196-
197- try {
198- rmInfoz = JSON . parse ( blob ) ;
199- } catch ( e ) {
200- if ( userSettings . debug . misc ) {
201- console . putmsg ( red + "Unable to parse rmInfoz\n" ) ;
202- }
203- //no need to throw an error for now
204- rmInfoz [ bbs . cursub_code ] = {
205- "defaultSettings" : {
206- "infoCreationDate" : null ,
207- "info" : [ ]
208- }
209- } ;
210- }
211-
212- rmInfoz [ bbs . cursub_code ] . defaultSettings . infoCreationDate = Date . now ( ) ;
213- rmInfoz [ bbs . cursub_code ] . defaultSettings . info = roomInfo ;
214-
215- var infoFile = new File ( this . userDir + this . roomSettingsFilename ) ;
211+ saveRoomInfo : function ( ) {
212+ var roomInfoLoc = "/sbbs/data/user/docrooms" ; //how to fix this?
213+ var roomInfoFile = new File ( roomInfoLoc ) ;
214+ //make sure to have a special case to initialize a new room's info
215+ //if it doesn't already exist in the roomSettings (freshly created)
216+ if ( roomSettings [ bbs . cursub_code ] == null ) {
217+ roomSettings [ bbs . cursub_code ] =
218+ roomData . roomRecords . defaultSettings ( ) ;
219+ }
216220
217- try {
218- infoFile . open ( "w" ) ;
219- } catch ( e ) {
220- console . putmsg ( yellow + "Error opening info file\n" ) ;
221- throw new docIface . dDocException ( "Exception in saveRoomInfo()" ,
222- e . message , 1 ) ;
223- }
221+ try {
222+ roomInfoFile . open ( "w" ) ;
223+ } catch ( e ) {
224+ if ( userSettings . debug . file_io ) {
225+ console . putmsg ( red + "Unable to open " + roomInfoLoc +
226+ " for writing!\n" ) ;
227+ }
228+ throw new dDocException ( "saveRoomInfo() Exception" , e . message , 1 ) ;
229+ }
224230
225- try {
226- if ( userSettings . debug . misc ) {
227- console . putmsg ( yellow + "Trying to save rmInfoz blob\n" ) ;
228- }
229- infoFile . write ( rmInfoz ) ;
230- } catch ( e ) {
231- if ( userSettings . debug . misc ) {
232- console . putmsg ( red + "Error trying to save rmInfoz blob: " +
233- e . message + "\n" ) ;
234- }
235- throw new docIface . dDocException ( "Exception in saveRoomInfo()" ,
236- e . message , 2 ) ;
237- } finally {
238- infoFile . close ( ) ;
239- }
231+ try {
232+ roomInfoFile . write ( JSON . stringify ( roomSettings ) ) ;
233+ } catch ( e ) {
234+ if ( userSettings . debug . file_io ) {
235+ console . putmsg ( red + "Unable to stringify/write roomSettings " +
236+ "to " + roomInfoLoc + "!\n" ) ;
237+ }
238+ throw new dDocException ( "saveRoomInfo() Exception" , e . message , 2 ) ;
239+ } finally {
240+ roomInfoFile . close ( ) ;
241+ }
240242 } ,
241243 /*
242244 * summary:
@@ -285,53 +287,76 @@ roomData = {
285287 } ,
286288 /*
287289 * summary:
288- * Method opens room info settings file, strips the bullshit
289- * out of it, and [hopefully] parses it as a JSON blob to
290- * be returned to extract room information from
291- * returns:
292- * JSON blob specified above
290+ * Method attempts to open roomInfoLoc (not sure still why the
291+ * constant definition of this is not working :-?), read its
292+ * contents into a string, and parse into roomSettings. If the
293+ * room info file doesn't exist yet, it'll create an object with
294+ * all of the current dystopian rooms and the default settings,
295+ * then writing such.
293296 */
294- snagRoomInfoBlob : function ( roomFile , roomReq ) {
295- //var roomInfoFile = new File(this.roomRecFilename);
296- var roomInfoFile = new File ( roomFile ) ;
297-
298- if ( userSettings . debug . file_io ) {
299- console . putmsg ( "Trying to load room info file: " +
300- this . roomRecFilename + " (in snagRoomInfoBlob)\n" ) ;
297+ snagRoomInfoBlob : function ( ) {
298+ var roomInfoLoc = "/sbbs/data/user/docrooms" ; //how to fix this?
299+ var roomInfoFile = new File ( roomInfoLoc ) ;
300+ var blob = new String ( ) ;
301+
302+ if ( roomInfoFile . exists ) {
303+ try {
304+ roomInfoFile . open ( "r" ) ;
305+ } catch ( e ) {
306+ if ( userSettings . debug . file_io ) {
307+ console . putmsg ( red + "Error opening " + roomInfoLoc + "\n" +
308+ "Message: " + e . message + "\n" ) ;
309+ }
310+ throw new dDocException ( "snagRoomInfoBlob() Exception" ,
311+ e . message , 1 ) ;
312+ }
313+
314+ try {
315+ blob = roomInfoFile . read ( ) ;
316+ } catch ( e ) {
317+ if ( userSettings . debug . file_io ) {
318+ console . putmsg ( red + "Error reading from: " + roomInfoLoc +
319+ "\nMessage: " + e . message + "\n" ) ;
320+ }
321+ throw new dDocException ( "snagRoomInfoBlob() Exception" ,
322+ e . message , 2 ) ;
323+ } finally {
324+ roomInfoFile . close ( ) ;
325+ }
326+
327+ try {
328+ roomSettings = JSON . parse ( blob ) ;
329+ } catch ( e ) {
330+ if ( userSettings . debug . file_io ) {
331+ console . putmsg ( yellow + "Error parsing JSON from: " +
332+ roomInfoLoc + "\nMessage: " + e . message + "\n" ) ;
333+ }
334+ throw new dDocException ( "snagRoomInfoBlob() Exception" ,
335+ e . message , 3 ) ;
336+ }
337+ } else {
338+ //looks like the info file doesn't exist yet
339+ for each ( room in msg_area . grp_list [ topebaseno ] . sub_list ) {
340+ if ( userSettings . debug . misc ) {
341+ console . putmsg ( green + "Setting room info for " +
342+ room . code + "\n" ) ;
343+ }
344+ roomSettings [ room . code ] =
345+ roomData . roomRecords . defaultSettings ( ) ;
346+ //guess we might as well just write it now, as well
347+ try {
348+ this . saveRoomInfo ( ) ;
349+ } catch ( e ) {
350+ if ( userSettings . debug . file_io ) {
351+ console . putmsg ( red + "Unable to save " + roomInfoLoc +
352+ "\nMessage: " + e . message + "\n" ) ;
353+ }
354+ throw new dDocException ( "snagRoomInfoBlob() Exception" +
355+ " while calling saveRoomInfo()" , e . message , 4 ) ;
356+ }
357+ }
301358 }
302-
303- if ( roomInfoFile . exists ) {
304- try {
305- chunky = this . stripNRead ( roomInfoFile ) ;
306- } catch ( e ) {
307- console . putmsg ( yellow + "Error in stripNRead(): " +
308- e . message + "\nFile: " + roomInfoFile . name
309- + "\n" ) ;
310- throw new docIface . dDocException ( "Exception in stripNRead()" ,
311- e . message , 1 ) ;
312- }
313- } else {
314- return roomData . roomRecords . defaultSettings ;
315- }
316-
317-
318- if ( ( chunky == null ) || ( chunky . length == 0 ) ) {
319- //one would think that creating a template would be good here
320- /* throw new docIface.dDocException("Exception in stripNRead()",
321- "blob null or length < 30", 2); */
322- return roomData . roomRecords . defaultSettings ;
323- }
324-
325- chunky = JSON . parse ( chunky ) ;
326-
327- //any more testing here?
328- if ( chunky [ roomReq ] != null ) {
329- return chunky [ roomReq ] ;
330- } else {
331- return roomData . roomRecords . defaultSettings ;
332- }
333-
334- } ,
359+ } ,
335360 /*
336361 * summary:
337362 * Method opens file of user's zapped rooms (still need to
0 commit comments