Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

47
LINES

< > BotCompany Repo | #1015684 // Mech Changes Log For Programs (dev., LIVE)

JavaX source code (desktop) [tags: butter use-pretranspiled] - run with: x30.jar - homepage

Download Jar. Libraryless. Click here for Pure Java version (2798L/19K).

1  
!7
2  
3  
static Map<O, Long> wsToState = weakHashMap();
4  
static int interval = 200, initialChars = 65536;
5  
//static long timeout = 10*60000L; // larger timeout since we have no idle mechanism yet (todo)
6  
static long timeout = 30000+10000; // idle time + latency
7  
8  
static File fileToLog() { ret mechVersionsLog(); }
9  
10  
p {
11  
  webSocketManager = new WebSocketManager {
12  
    void onNewWebSocket(O ws, S uri) {
13  
      super.onNewWebSocket(ws, uri);
14  
      set(ws, 'timeout, timeout);
15  
    }
16  
    
17  
    void onWebSocketMessage(O ws, S s) {
18  
      File f = fileToLog();
19  
      long len = fileSize(f);
20  
      new Matches m;
21  
      if "look back * chars pw *" // TODO: filter if it appears in Eleu log
22  
        if (neq(masterPW(), $2)) {
23  
          call(ws, 'send, "bad pw");
24  
          call(ws, 'close);
25  
        } else
26  
          wsToState.put(ws, max(0, len-parseLong($1)));
27  
    }
28  
  };
29  
  doEvery(interval, f update);
30  
}
31  
32  
html { ret "Use WebSocket: " + subBot_myWebSocketURI(); }
33  
34  
svoid update {
35  
  if (webSocketManager.isEmpty()) ret;
36  
  File f = fileToLog();
37  
  long len = fileSize(f);
38  
  
39  
  for (O ws : webSocketManager.webSockets()) {
40  
    Long l = wsToState.get(ws);
41  
    if (l != null && len > l) { // no cmd yet? ignore
42  
      S newStuff = unquoteAllLines(loadTextFilePart(f, l, len));
43  
      wsToState.put(ws, len);
44  
      call(ws, 'send, "+" + newStuff);
45  
    }
46  
  }
47  
}

Author comment

Began life as a copy of #1014682

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015684
Snippet name: Mech Changes Log For Programs (dev., LIVE)
Eternal ID of this version: #1015684/11
Text MD5: 5d5b947b8f9b20afc61e138e08182980
Transpilation MD5: a3f77888bace6a0f21d38d8337d108b3
Author: stefan
Category: javax / a.i. / web
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-18 19:05:05
Source code size: 1378 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 548 / 2567
Version history: 10 change(s)
Referenced in: [show references]