@@ -190,75 +190,149 @@ public void doChecks() {
190190 ConfigEntry entry ;
191191 ConfigGroup sysgroup = configManager .getGroup ("system" );
192192 if (sysgroup != null ) {
193- if ((entry = sysgroup .getEntry ("whazzup" )) != null ) {
194- whazzupFile = entry .getData ();
195- String whazzupTemp = String .format ("%s%s" , whazzupFile , ".tmp" );
196- prevWhazzup = now ;
197- if (fileOpen == 0 ) {
198- try (FileOutputStream wzfile = new FileOutputStream (whazzupTemp )) {
199- fileOpen = 1 ;
200- wzfile .write (String .format ("%s%s\n " , "![DateStamp]" , Support .sprintGmtDate (now )).getBytes ());
201- wzfile .write (String .format ("%s\n " , "!GENERAL" ).getBytes ());
202- wzfile .write (String .format ("%s = %d\n " , "VERSION" , 1 ).getBytes ());
203- wzfile .write (String .format ("%s = %d\n " , "RELOAD" , 1 ).getBytes ());
204- wzfile .write (String .format ("%s = %s\n " , "UPDATE" , Support .sprintGmt (now )).getBytes ());
205- wzfile .write (String .format ("%s = %d\n " , "CONNECTED CLIENTS" , Client .clients .size ()).getBytes ());
206- wzfile .write (String .format ("%s = %d\n " , "CONNECTED SERVERS" , Server .servers .size ()).getBytes ());
207- wzfile .write (String .format ("%s\n " , "!CLIENTS" ).getBytes ());
208- String dataSeg1 , dataSeg2 , dataSeg3 , dataSeg4 , dataSeg5 , dataSeg6 , dataSeg7 ;
209- for (Client tempClient : Client .clients ) {
210- dataSeg1 = String .format ("%s:%s:%s:%s" , tempClient .getCallsign (), tempClient .getCid (),
211- tempClient .getRealName (), tempClient .getType () == ClientConstants .CLIENT_ATC ? "ATC" : "PILOT" );
212- if (tempClient .getFrequency () != 0 && tempClient .getFrequency () < 100_000 ) {
213- dataSeg2 = String .format ("1%02d.%03d" , tempClient .getFrequency () / 1000 , tempClient .getFrequency () % 1000 );
214- } else {
215- dataSeg2 = "" ;
216- }
217-
218- Flightplan tempFlightplan = tempClient .getPlan ();
219- if (tempClient .getLat () != 0 && tempClient .getAltitude () < 100_000 && tempClient .getLon () != 0 ) {
220- dataSeg3 = String .format ("%f:%f:%d:%d" , tempClient .getLat (), tempClient .getLon (), tempClient .getAltitude (), tempClient .getGroundSpeed ());
221- } else {
222- dataSeg3 = ":::" ;
223- }
224-
225- if (tempFlightplan != null ) {
226- dataSeg4 = String .format ("%s:%d:%s:%s:%s" , tempFlightplan .getAircraft (),
227- tempFlightplan .getTasCruise (), tempFlightplan .getDepAirport (),
228- tempFlightplan .getAlt (), tempFlightplan .getDestAirport ());
229- } else {
230- dataSeg4 = "::::" ;
193+ String os = System .getProperty ("os.name" );
194+ if (os != null && os .toLowerCase ().startsWith ("windows" )) {
195+ if ((entry = sysgroup .getEntry ("whazzup" )) != null ) {
196+ whazzupFile = entry .getData ();
197+ String whazzupTemp = String .format ("%s%s" , whazzupFile , ".tmp" );
198+ prevWhazzup = now ;
199+ if (fileOpen == 0 ) {
200+ try (FileOutputStream wzfile = new FileOutputStream (whazzupTemp )) {
201+ fileOpen = 1 ;
202+ wzfile .write (String .format ("%s%s\r \n " , "![DateStamp]" , Support .sprintGmtDate (now )).getBytes ());
203+ wzfile .write (String .format ("%s\r \n " , "!GENERAL" ).getBytes ());
204+ wzfile .write (String .format ("%s = %d\r \n " , "VERSION" , 1 ).getBytes ());
205+ wzfile .write (String .format ("%s = %d\r \n " , "RELOAD" , 1 ).getBytes ());
206+ wzfile .write (String .format ("%s = %s\r \n " , "UPDATE" , Support .sprintGmt (now )).getBytes ());
207+ wzfile .write (String .format ("%s = %d\r \n " , "CONNECTED CLIENTS" , Client .clients .size ()).getBytes ());
208+ wzfile .write (String .format ("%s = %d\r \n " , "CONNECTED SERVERS" , Server .servers .size ()).getBytes ());
209+ wzfile .write (String .format ("%s\r \n " , "!CLIENTS" ).getBytes ());
210+ String dataSeg1 , dataSeg2 , dataSeg3 , dataSeg4 , dataSeg5 , dataSeg6 , dataSeg7 ;
211+ for (Client tempClient : Client .clients ) {
212+ dataSeg1 = String .format ("%s:%s:%s:%s" , tempClient .getCallsign (), tempClient .getCid (),
213+ tempClient .getRealName (), tempClient .getType () == ClientConstants .CLIENT_ATC ? "ATC" : "PILOT" );
214+ if (tempClient .getFrequency () != 0 && tempClient .getFrequency () < 100_000 ) {
215+ dataSeg2 = String .format ("1%02d.%03d" , tempClient .getFrequency () / 1000 , tempClient .getFrequency () % 1000 );
216+ } else {
217+ dataSeg2 = "" ;
218+ }
219+
220+ Flightplan tempFlightplan = tempClient .getPlan ();
221+ if (tempClient .getLat () != 0 && tempClient .getAltitude () < 100_000 && tempClient .getLon () != 0 ) {
222+ dataSeg3 = String .format ("%f:%f:%d:%d" , tempClient .getLat (), tempClient .getLon (), tempClient .getAltitude (), tempClient .getGroundSpeed ());
223+ } else {
224+ dataSeg3 = ":::" ;
225+ }
226+
227+ if (tempFlightplan != null ) {
228+ dataSeg4 = String .format ("%s:%d:%s:%s:%s" , tempFlightplan .getAircraft (),
229+ tempFlightplan .getTasCruise (), tempFlightplan .getDepAirport (),
230+ tempFlightplan .getAlt (), tempFlightplan .getDestAirport ());
231+ } else {
232+ dataSeg4 = "::::" ;
233+ }
234+ dataSeg5 = String .format ("%s:%s:%d:%d:%d:%d" , tempClient .getLocation ().getIdent (), tempClient .getProtocol (), tempClient .getRating (), tempClient .getTransponder (), tempClient .getFacilityType (), tempClient .getVisualRange ());
235+
236+ if (tempFlightplan != null ) {
237+ dataSeg6 = String .format ("%d:%c:%d:%d:%d:%d:%d:%d:%s:%s:%s" , tempFlightplan .getRevision (),
238+ tempFlightplan .getType (), tempFlightplan .getDepTime (), tempFlightplan .getActDepTime (),
239+ tempFlightplan .getHrsEnroute (), tempFlightplan .getMinEnroute (), tempFlightplan .getHrsFuel (),
240+ tempFlightplan .getMinFuel (), tempFlightplan .getAltAirport (), tempFlightplan .getRemarks (), tempFlightplan .getRoute ());
241+ } else {
242+ dataSeg6 = "::::::::::" ;
243+ }
244+
245+ dataSeg7 = String .format ("::::::%s:%s" , Support .sprintGmt (tempClient .getStartTime ()), tempClient .getPbh ());
246+ wzfile .write (String .format ("%s:%s:%s:%s:%s:%s:%s\r \n " , dataSeg1 , dataSeg2 , dataSeg3 , dataSeg4 , dataSeg5 , dataSeg6 , dataSeg7 ).getBytes ());
231247 }
232- dataSeg5 = String .format ("%s:%s:%d:%d:%d:%d" , tempClient .getLocation ().getIdent (), tempClient .getProtocol (), tempClient .getRating (), tempClient .getTransponder (), tempClient .getFacilityType (), tempClient .getVisualRange ());
233-
234- if (tempFlightplan != null ) {
235- dataSeg6 = String .format ("%d:%c:%d:%d:%d:%d:%d:%d:%s:%s:%s" , tempFlightplan .getRevision (),
236- tempFlightplan .getType (), tempFlightplan .getDepTime (), tempFlightplan .getActDepTime (),
237- tempFlightplan .getHrsEnroute (), tempFlightplan .getMinEnroute (), tempFlightplan .getHrsFuel (),
238- tempFlightplan .getMinFuel (), tempFlightplan .getAltAirport (), tempFlightplan .getRemarks (), tempFlightplan .getRoute ());
239- } else {
240- dataSeg6 = "::::::::::" ;
248+ wzfile .write ("!SERVERS\r \n " .getBytes ());
249+ for (Server tempServer : Server .servers ) {
250+ if ("n/a" .equals (tempServer .getHostName ())) {
251+ String dataLine = String .format ("%s:%s:%s:%s:%d" , tempServer .getIdent (), tempServer .getHostName (), tempServer .getLocation (), tempServer .getName (), (tempServer .getFlags () & ServerConstants .SERVER_SILENT ) != 0 ? 0 : 1 );
252+ wzfile .write (String .format ("%s\r \n " , dataLine ).getBytes ());
253+ }
241254 }
242-
243- dataSeg7 = String .format ("::::::%s:%s" , Support .sprintGmt (tempClient .getStartTime ()), tempClient .getPbh ());
244- wzfile .write (String .format ("%s:%s:%s:%s:%s:%s:%s\n " , dataSeg1 , dataSeg2 , dataSeg3 , dataSeg4 , dataSeg5 , dataSeg6 , dataSeg7 ).getBytes ());
255+ } catch (IOException e ) {
256+ LOGGER .warn ("[BetterFSD]: Open whazzup file failed." , e );
245257 }
246- wzfile .write ("!SERVERS\n " .getBytes ());
247- for (Server tempServer : Server .servers ) {
248- if ("n/a" .equals (tempServer .getHostName ())) {
249- String dataLine = String .format ("%s:%s:%s:%s:%d" , tempServer .getIdent (), tempServer .getHostName (), tempServer .getLocation (), tempServer .getName (), (tempServer .getFlags () & ServerConstants .SERVER_SILENT ) != 0 ? 0 : 1 );
250- wzfile .write (String .format ("%s\n " , dataLine ).getBytes ());
258+ File realFile = new File (whazzupFile );
259+ realFile .delete ();
260+ File tempFile = new File (whazzupTemp );
261+ tempFile .renameTo (realFile );
262+ }
263+ fileOpen = 0 ;
264+ }
265+ } else {
266+ if ((entry = sysgroup .getEntry ("whazzup" )) != null ) {
267+ whazzupFile = entry .getData ();
268+ String whazzupTemp = String .format ("%s%s" , whazzupFile , ".tmp" );
269+ prevWhazzup = now ;
270+ if (fileOpen == 0 ) {
271+ try (FileOutputStream wzfile = new FileOutputStream (whazzupTemp )) {
272+ fileOpen = 1 ;
273+ wzfile .write (String .format ("%s%s\n " , "![DateStamp]" , Support .sprintGmtDate (now )).getBytes ());
274+ wzfile .write (String .format ("%s\n " , "!GENERAL" ).getBytes ());
275+ wzfile .write (String .format ("%s = %d\n " , "VERSION" , 1 ).getBytes ());
276+ wzfile .write (String .format ("%s = %d\n " , "RELOAD" , 1 ).getBytes ());
277+ wzfile .write (String .format ("%s = %s\n " , "UPDATE" , Support .sprintGmt (now )).getBytes ());
278+ wzfile .write (String .format ("%s = %d\n " , "CONNECTED CLIENTS" , Client .clients .size ()).getBytes ());
279+ wzfile .write (String .format ("%s = %d\n " , "CONNECTED SERVERS" , Server .servers .size ()).getBytes ());
280+ wzfile .write (String .format ("%s\n " , "!CLIENTS" ).getBytes ());
281+ String dataSeg1 , dataSeg2 , dataSeg3 , dataSeg4 , dataSeg5 , dataSeg6 , dataSeg7 ;
282+ for (Client tempClient : Client .clients ) {
283+ dataSeg1 = String .format ("%s:%s:%s:%s" , tempClient .getCallsign (), tempClient .getCid (),
284+ tempClient .getRealName (), tempClient .getType () == ClientConstants .CLIENT_ATC ? "ATC" : "PILOT" );
285+ if (tempClient .getFrequency () != 0 && tempClient .getFrequency () < 100_000 ) {
286+ dataSeg2 = String .format ("1%02d.%03d" , tempClient .getFrequency () / 1000 , tempClient .getFrequency () % 1000 );
287+ } else {
288+ dataSeg2 = "" ;
289+ }
290+
291+ Flightplan tempFlightplan = tempClient .getPlan ();
292+ if (tempClient .getLat () != 0 && tempClient .getAltitude () < 100_000 && tempClient .getLon () != 0 ) {
293+ dataSeg3 = String .format ("%f:%f:%d:%d" , tempClient .getLat (), tempClient .getLon (), tempClient .getAltitude (), tempClient .getGroundSpeed ());
294+ } else {
295+ dataSeg3 = ":::" ;
296+ }
297+
298+ if (tempFlightplan != null ) {
299+ dataSeg4 = String .format ("%s:%d:%s:%s:%s" , tempFlightplan .getAircraft (),
300+ tempFlightplan .getTasCruise (), tempFlightplan .getDepAirport (),
301+ tempFlightplan .getAlt (), tempFlightplan .getDestAirport ());
302+ } else {
303+ dataSeg4 = "::::" ;
304+ }
305+ dataSeg5 = String .format ("%s:%s:%d:%d:%d:%d" , tempClient .getLocation ().getIdent (), tempClient .getProtocol (), tempClient .getRating (), tempClient .getTransponder (), tempClient .getFacilityType (), tempClient .getVisualRange ());
306+
307+ if (tempFlightplan != null ) {
308+ dataSeg6 = String .format ("%d:%c:%d:%d:%d:%d:%d:%d:%s:%s:%s" , tempFlightplan .getRevision (),
309+ tempFlightplan .getType (), tempFlightplan .getDepTime (), tempFlightplan .getActDepTime (),
310+ tempFlightplan .getHrsEnroute (), tempFlightplan .getMinEnroute (), tempFlightplan .getHrsFuel (),
311+ tempFlightplan .getMinFuel (), tempFlightplan .getAltAirport (), tempFlightplan .getRemarks (), tempFlightplan .getRoute ());
312+ } else {
313+ dataSeg6 = "::::::::::" ;
314+ }
315+
316+ dataSeg7 = String .format ("::::::%s:%s" , Support .sprintGmt (tempClient .getStartTime ()), tempClient .getPbh ());
317+ wzfile .write (String .format ("%s:%s:%s:%s:%s:%s:%s\n " , dataSeg1 , dataSeg2 , dataSeg3 , dataSeg4 , dataSeg5 , dataSeg6 , dataSeg7 ).getBytes ());
318+ }
319+ wzfile .write ("!SERVERS\n " .getBytes ());
320+ for (Server tempServer : Server .servers ) {
321+ if ("n/a" .equals (tempServer .getHostName ())) {
322+ String dataLine = String .format ("%s:%s:%s:%s:%d" , tempServer .getIdent (), tempServer .getHostName (), tempServer .getLocation (), tempServer .getName (), (tempServer .getFlags () & ServerConstants .SERVER_SILENT ) != 0 ? 0 : 1 );
323+ wzfile .write (String .format ("%s\n " , dataLine ).getBytes ());
324+ }
251325 }
326+ } catch (IOException e ) {
327+ LOGGER .warn ("[BetterFSD]: Open whazzup file failed." , e );
252328 }
253- } catch (IOException e ) {
254- LOGGER .warn ("[BetterFSD]: Open whazzup file failed." , e );
329+ File realFile = new File (whazzupFile );
330+ realFile .delete ();
331+ File tempFile = new File (whazzupTemp );
332+ tempFile .renameTo (realFile );
255333 }
256- File realFile = new File (whazzupFile );
257- realFile .delete ();
258- File tempFile = new File (whazzupTemp );
259- tempFile .renameTo (realFile );
334+ fileOpen = 0 ;
260335 }
261- fileOpen = 0 ;
262336 }
263337 if ((entry = sysgroup .getEntry ("whazzupjson" )) != null ) {
264338 whazzupjsonFile = entry .getData ();
0 commit comments