-
Notifications
You must be signed in to change notification settings - Fork 0
/
S2-2.js
1493 lines (1474 loc) · 52.1 KB
/
S2-2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// MikeDEV's CloudLink API Suite
// This extension combines the CloudLink API, the CloudCoin API, and the CloudDisk API in an all-in-one solution.
// Original Source Code built upon KingdomPi's Scratch-websockets repo.
// See https://github.com/KingdomPy/scratch_websockets/blob/master/index.js for the original script!
// DO NOT USE ON OLDER WEB BROWSERS! CloudLink is designed to run best on a modern web browser.
const vers = 'S2.2'; // Suite version number
const defIP = "ws://127.0.0.1:3000/"; // Default IP address
const testIP = "wss://ef4e5a473455.ngrok.io/"; // Public test server IP.
const enableSpecialHandshake = true; // Experimental direct-linking mode support.
console.log("[CloudLink Suite] Loading 1/3: Initializing the extension...")
// CloudLink block and icon dataURIs
const cl_block_icon = 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSI2OS43NjY3MSIgaGVpZ2h0PSI1MS41Mzk5NCIgdmlld0JveD0iMCwwLDY5Ljc2NjcxLDUxLjUzOTk0Ij48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgtMjA1LjExNjY1LC0xNTQuMjMwMDMpIj48ZyBkYXRhLXBhcGVyLWRhdGE9InsmcXVvdDtpc1BhaW50aW5nTGF5ZXImcXVvdDs6dHJ1ZX0iIGZpbGwtcnVsZT0ibm9uemVybyIgc3Ryb2tlPSIjZmZmZmZmIiBzdHJva2Utd2lkdGg9IjQiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTI3Mi44ODMzNiwxODguODA3NTJjMCw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LjAxMzkyIi8+PC9nPjwvZz48L2c+PC9zdmc+';
// Booleans for signifying an update to the global or private data streams, as well as the disk and coin data.
var gotNewGlobalData = false;
var gotNewPrivateData = false;
var gotNewTrade = false;
var gotDiskData = false;
var gotCoinData = false;
var gotAccountData = false;
var gotNewGlobalLinkedData = false;
var gotNewPrivateLinkedData = false;
// Variables storing global and private stream data transmitted from the server.
var sGData = "";
var sPData = "";
var sGLinkedData = "";
var sPLinkedData = "";
// System variables needed for basic functionality
var sys_status = 0; // System status reporter, 0 = Ready, 1 = Connecting, 2 = Connected, 3 = Disconnected OK, 4 = Disconnected ERR
var userNames = ""; // Usernames list
var myName = ""; // Username reporter
var servIP = defIP; // Default server IP
var isRunning = false; // Boolean for determining if the connection is alive and well
var wss = null; // Websocket object that enables communications
// Special Features that work when enableSpecialHandshake is set to true (If false, it enables backward-compatibility mode for older application servers)
var linkTo = ''; // Variable for linking to a specific client ID.
var specialHandshakeAcquired = false; // Determines if new blocks are supported on the server.
var serverVersion = ''; // Diagnostics, gets the server's value for 'vers'.
var globalVars = {}; // Custom globally-readable variables.
var privateVars = {}; // Custom private variables.
var gotNewGlobalVarData = {}; // Booleans for checking if a new value has been written to a global var.
var gotNewPrivateVarData = {}; // Booleans for checking if a new value has been written to a private var.
// Variables for storing CloudAccount data
var isAuth = false;
var accountData = "";
var accMode = "";
// Variables for storing CloudCoin data
var coinData = '';
var tradeReturn = '';
// Variables for storing CloudDisk data
var diskData = '';
var runningFtp = false;
var ftpData = '';
console.log("[CloudLink Suite] Loading 2/3: Now loading classes...")
// CloudLink class for the primary extension.
class cloudlink {
constructor(runtime, extensionId) {
this.runtime = runtime;
}
static get STATE_KEY() {
return 'Scratch.websockets';
}
getInfo() {
return {
id: 'cloudlink',
name: 'CloudLink',
color1: '#054c63',
color2: '#054c63',
color3: '#043444',
blockIconURI: cl_block_icon,
menuIconURI: cl_menu_icon,
blocks: [
{
opcode: 'returnGlobalData',
blockType: Scratch.BlockType.REPORTER,
text: 'Global data',
}, {
opcode: 'returnPrivateData',
blockType: Scratch.BlockType.REPORTER,
text: 'Private data',
}, {
opcode: 'returnGlobalLinkedData',
blockType: Scratch.BlockType.REPORTER,
text: 'Linked Global Data',
}, {
opcode: 'returnPrivateLinkedData',
blockType: Scratch.BlockType.REPORTER,
text: 'Linked Private Data',
}, {
opcode: 'returnLinkData',
blockType: Scratch.BlockType.REPORTER,
text: 'Link Status',
}, {
opcode: 'returnUserListData',
blockType: Scratch.BlockType.REPORTER,
text: 'Usernames',
}, {
opcode: 'returnUsernameData',
blockType: Scratch.BlockType.REPORTER,
text: 'My Username',
}, {
opcode: 'returnVersionData',
blockType: Scratch.BlockType.REPORTER,
text: 'Extension Version',
}, {
opcode: 'returnServerVersion',
blockType: Scratch.BlockType.REPORTER,
text: 'Server Version',
}, {
opcode: 'returnLinkedID',
blockType: Scratch.BlockType.REPORTER,
text: 'Linked ID',
}, {
opcode: 'returnTestIPData',
blockType: Scratch.BlockType.REPORTER,
text: 'Test IP',
}, {
opcode: 'returnVarData',
blockType: Scratch.BlockType.REPORTER,
text: '[TYPE] var [VAR] data',
arguments: {
VAR: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple',
},
TYPE: {
type: Scratch.ArgumentType.STRING,
menu: 'varmenu',
defaultValue: 'Global',
},
},
}, {
opcode: 'parseJSON',
blockType: Scratch.BlockType.REPORTER,
text: '[PATH] of [JSON_STRING]',
arguments: {
PATH: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'fruit/apples',
},
JSON_STRING: {
type: Scratch.ArgumentType.STRING,
defaultValue: '{"fruit": {"apples": 2, "bananas": 3}, "total_fruit": 5}',
},
},
}, {
opcode: 'getComState',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Connected?',
}, {
opcode: 'getUsernameState',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Username synced?',
}, {
opcode: 'returnIsLinked',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Linked to ID?',
}, {
opcode: 'returnIsNewData',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Got New [TYPE] Data?',
arguments: {
TYPE: {
type: Scratch.ArgumentType.STRING,
menu: 'datamenu',
defaultValue: 'Global',
},
},
}, {
opcode: 'returnIsNewVarData',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Got New [TYPE] Var [VAR] Data?',
arguments: {
VAR: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple',
},
TYPE: {
type: Scratch.ArgumentType.STRING,
menu: 'varmenu',
defaultValue: 'Global',
},
},
}, {
opcode: 'openSocket',
blockType: Scratch.BlockType.COMMAND,
text: 'Connect to [IP]',
arguments: {
IP: {
type: Scratch.ArgumentType.STRING,
defaultValue: defIP,
},
},
}, {
opcode: 'closeSocket',
blockType: Scratch.BlockType.COMMAND,
text: 'Disconnect',
}, {
opcode: 'setMyName',
blockType: Scratch.BlockType.COMMAND,
text: 'Set [NAME] as username',
arguments: {
NAME: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'A name',
},
},
}, {
opcode: 'sendGData',
blockType: Scratch.BlockType.COMMAND,
text: 'Send [DATA]',
arguments: {
DATA: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple',
},
},
}, {
opcode: 'sendPData',
blockType: Scratch.BlockType.COMMAND,
text: 'Send [DATA] to [ID]',
arguments: {
DATA: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple',
},
ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'A name',
},
},
}, {
opcode: 'sendGDataAsVar',
blockType: Scratch.BlockType.COMMAND,
text: 'Send Var [VAR] with Data [DATA]',
arguments: {
DATA: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Banana',
},
VAR: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple',
},
},
}, {
opcode: 'sendPDataAsVar',
blockType: Scratch.BlockType.COMMAND,
text: 'Send Var [VAR] to [ID] with Data [DATA]',
arguments: {
DATA: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Banana',
},
ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'A name',
},
VAR: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple',
},
},
}, {
opcode: 'refreshUserList',
blockType: Scratch.BlockType.COMMAND,
text: 'Refresh User List',
}, {
opcode: 'resetNewData',
blockType: Scratch.BlockType.COMMAND,
text: 'Reset Got New [TYPE] Data',
arguments: {
TYPE: {
type: Scratch.ArgumentType.STRING,
menu: 'datamenu',
defaultValue: 'Global',
},
},
}, {
opcode: 'resetNewVarData',
blockType: Scratch.BlockType.COMMAND,
text: 'Reset Got New [TYPE] Var [VAR] Data',
arguments: {
TYPE: {
type: Scratch.ArgumentType.STRING,
menu: 'varmenu',
defaultValue: 'Global',
},
VAR: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple',
},
},
}, {
opcode: 'linkWithID',
blockType: Scratch.BlockType.COMMAND,
text: 'Link with ID [ID]',
arguments: {
ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: '%MS%',
},
},
}, /*{
opcode: 'runCMD',
blockType: Scratch.BlockType.COMMAND,
text: 'Send CMD [CMD] to ID [ID] with data [DATA]',
arguments: {
CMD: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'PING',
},
ID: {
type: Scratch.ArgumentType.STRING,
defaultValue: '%MS%',
},
DATA: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Banana',
},
},
}, */
],
menus: {
coms: {
items: ["Connected", "Username Synced"]
},
datamenu: {
items: ['Global', 'Private', 'Global (Linked)', 'Private (Linked)'],
},
varmenu: {
items: ['Global', 'Private'],
},
}
};
};
openSocket(args) {
servIP = args.IP; // Begin the main updater scripts
if (!isRunning) {
sys_status = 1;
console.log("[CloudLink] Establishing connection...");
try {
wss = new WebSocket(servIP);
wss.onopen = function(e) {
isRunning = true;
sys_status = 2; // Connected OK value
console.log("[CloudLink] Connected.");
if (enableSpecialHandshake) {
wss.send("<%sh>\n") // request for special features to be enabled
console.log("[CloudLink] Attempting special features handshake...")
};
};
wss.onmessage = function(event) {
var rawpacket = String(event.data)
var obj = JSON.parse(event.data);
if (obj["type"] == "gs") {
sGData = String(obj["data"]);
gotNewGlobalData = true;
} else if (obj["type"] == "ps") {
if (String(obj["id"]) == String(myName)) {
sPData = String(obj["data"]);
gotNewPrivateData = true;
};
} else if (obj["type"] == "dd") {
if (String(obj["id"]) == String(myName)) {
diskData = String(obj["data"]);
gotDiskData = true;
};
} else if (obj["type"] == "ftp") {
if (String(obj["id"]) == String(myName)) {
if (runningFtp) {
if (String(obj['data']) != "<TX>") {
ftpData = String(String(ftpData) + String(obj["data"]));
} else {
runningFtp = false;
};
};
};
} else if (obj["type"] == "ca") {
if (String(obj["id"]) == String(myName)) {
if (String(obj["data"]) == "OK") {
if (accMode == "LI"){
isAuth = true;
accMode = "";
} if (accMode == "LO") {
isAuth = false;
accMode = "";
} else {
accMode = "";
accountData = String(obj["data"]);
gotAccountData = true;
};
} else {
accMode = "";
accountData = String(obj["data"]);
gotAccountData = true;
};
};
} else if (obj["type"] == "cd") {
if (String(obj["id"]) == String(myName)) {
coinData = String(obj["data"]);
gotCoinData = true;
};
} else if (obj["type"] == "ul") {
userNames = String(obj["data"]);
} else if (obj["type"] == "ru") {
if (myName != "") {
wss.send("<%sn>\n" + myName);
};
} else if (obj["type"] == "direct") {
var ddata = obj['data'];
if (ddata['type'] == "vers") {
specialHandshakeAcquired = true;
console.log("[CloudLink] Special features handshake acknowledged!")
serverVersion = ddata["data"];
console.log("[CloudLink] Server version: " + String(serverVersion));
};
} else if (obj["type"] == "sf") {
try {
var ddata = obj['data'];
if (ddata['type'] == "gs") {
sGData = String(ddata['data']);
gotNewGlobalData = true;
} else if (ddata['type'] == "lm") {
if (ddata['mode'] == "g") {
sGLinkedData = String(ddata['data']);
gotNewGlobalLinkedData = true;
} else if (ddata['mode'] == "p") {
sPLinkedData = String(ddata['data']);
gotNewPrivateLinkedData = true;
}
} else if (ddata['type'] == "vm") {
if (ddata['mode'] == "g") {
globalVars[ddata['var']] = ddata['data'];
gotNewGlobalVarData[ddata['var']] = true;
} else if (ddata['mode'] == "p") {
privateVars[ddata['var']] = ddata['data'];
gotNewPrivateVarData[ddata['var']] = true;
}
} else if (ddata['type'] == "ps") {
sPData = String(ddata['data']);
gotNewPrivateData = true;
}
} catch(err) {
console.log("[CloudLink] Oops! An error occured. "+String(err));
}
} else {
console.log("[CloudLink] Error! Unknown packet data: " + String(rawpacket));
};
};
wss.onclose = function(event) {
isRunning = false;
myName = "";
gotNewGlobalData = false;
gotNewPrivateData = false;
gotNewGlobalLinkedData = false;
gotNewPrivateLinkedData = false;
gotNewTrade = false;
gotDiskData = false;
gotCoinData = false;
gotAccountData = false;
userNames = "";
sGData = "";
sPData = "";
sGLinkedData = "";
sPLinkedData = "";
coinData = "";
tradeReturn = "";
diskData = "";
accountData = "";
accMode = "";
isAuth = false;
sys_status = 3; // Disconnected OK value
runningFtp = false;
ftpData = '';
serverVersion = '';
linkTo = '';
globalVars = {};
privateVars = {};
specialHandshakeAcquired = false;
gotNewGlobalVarData = {};
gotNewPrivateVarData = {};
if (event.wasClean) {
sys_status = 3; // Disconnected OK value
console.log("[CloudLink] Disconnected: Safely disconnected.");
} else {
sys_status = 4; // Connection lost value
console.log("[CloudLink] Disconnected: Lost connection.");
};
};
} catch(err) {
throw(err)
};
} else {
return "Connection already established.";
};
}; // end the updater scripts
closeSocket() {
if (isRunning) {
wss.send("<%ds>\n" + myName); // send disconnect command in header before shutting down link
wss.close(1000);
isRunning = false;
myName = "";
gotNewGlobalData = false;
gotNewPrivateData = false;
gotNewGlobalLinkedData = false;
gotNewPrivateLinkedData = false;
gotNewTrade = false;
gotDiskData = false;
gotCoinData = false;
gotAccountData = false;
userNames = "";
sGData = "";
sPData = "";
sGLinkedData = "";
sPLinkedData = "";
coinData = "";
tradeReturn = "";
diskData = "";
accountData = "";
accMode = "";
isAuth = false;
sys_status = 3; // Disconnected OK value
runningFtp = false;
ftpData = '';
serverVersion = '';
linkTo = '';
globalVars = {};
privateVars = {};
specialHandshakeAcquired = false;
gotNewGlobalVarData = {};
gotNewPrivateVarData = {};
return ("Connection closed.");
} else {
return ("Connection already closed.");
};
};
getComState() {
return isRunning;
};
getUsernameState() {
if (isRunning) {
if (myName != '') {
return (userNames.indexOf(String(myName)) >= 0);
} else {
return false;
}
} else {
return false;
};
};
sendGData(args) {
if (isRunning) {
if (linkTo == "") {
wss.send("<%gs>\n" + myName + "\n" + args.DATA);
} else {
wss.send("<%l_g>\n0\n" + myName + "\n" + args.DATA);
};
return "Sent data successfully.";
} else {
return "Connection closed, no action taken.";
}
};
sendPData(args) {
if (isRunning) {
if (myName != "") {
if (args.ID != myName) {
if (linkTo == "") {
wss.send("<%ps>\n" + myName + "\n" + args.ID + "\n" + args.DATA);
} else {
wss.send("<%l_p>\n0\n" + myName + "\n" + args.ID + "\n" + args.DATA);
};
return "Sent data successfully.";
} else {
return "Can't send data to yourself!";
};
} else {
return "Username not set, no action taken.";
}
} else {
return "Connection closed, no action taken.";
};
};
sendGDataAsVar(args) {
if (isRunning && specialHandshakeAcquired) {
if (linkTo != "") {
wss.send("<%l_g>\n2\n" + myName + "\n" + args.VAR + "\n" + args.DATA);
} else {
wss.send("<%l_g>\n1\n" + myName + "\n" + args.VAR + "\n" + args.DATA);
}
return "Sent data successfully.";
} else {
if (isRunning) {
return "Server is out-of-date / Doesn't support special features!";
} else {
return "Connection closed, no action taken.";
}
}
};
sendPDataAsVar(args) {
if (isRunning && specialHandshakeAcquired) {
if (myName != "") {
if (args.ID != myName) {
if (linkTo != "") {
wss.send("<%l_p>\n2\n" + myName + "\n" + args.ID + "\n" + args.VAR + "\n" + args.DATA);
} else {
wss.send("<%l_p>\n1\n" + myName + "\n" + args.ID + "\n" + args.VAR + "\n" + args.DATA);
}
return "Sent data successfully.";
} else {
return "Can't send data to yourself!";
}
} else {
return "Username not set, no action taken.";
}
} else {
if (isRunning) {
return "Server is out-of-date / Doesn't support special features!";
} else {
return "Connection closed, no action taken.";
}
};
};
runCMD(args) {
if (isRunning) {
if (myName != "") {
if (args.ID != myName) {
wss.send("<%ps>\n" + myName + "\n" + args.ID + '\n{"cmd":"' + args.CMD + '","id":"' + myName + '","data":"' + args.DATA + '"}');
return "Sent data successfully.";
} else {
return "Can't send data to yourself!";
};
} else {
return "Username not set, no action taken.";
}
} else {
return "Connection closed, no action taken.";
};
};
returnGlobalData() {
return sGData;
};
returnPrivateData() {
return sPData;
};
returnGlobalLinkedData() {
return sGLinkedData;
};
returnPrivateLinkedData() {
return sPLinkedData;
};
returnVarData(args) {
if (args.TYPE == "Global") {
if (args.VAR in globalVars) {
return globalVars[args.VAR];
} else {
return "";
}
} else if (args.TYPE == "Private") {
if (args.VAR in privateVars) {
return privateVars[args.VAR];
} else {
return "";
}
}
};
returnIsNewVarData(args) {
if (args.TYPE == "Global") {
if (args.VAR in globalVars) {
return gotNewGlobalVarData[args.VAR];
} else {
return false;
}
} else if (args.TYPE == "Private") {
if (args.VAR in privateVars) {
return gotNewPrivateVarData[args.VAR];
} else {
return false;
}
};
};
returnLinkData() {
return sys_status;
};
returnUserListData() {
return userNames;
};
returnUsernameData() {
return myName;
};
returnVersionData() {
return vers;
};
returnTestIPData() {
return testIP;
};
returnServerVersion() {
return serverVersion;
};
returnIsNewData(args) {
if (args.TYPE == "Global") {
return gotNewGlobalData;
};
if (args.TYPE == "Private") {
return gotNewPrivateData;
};
if (args.TYPE == "Global (Linked)") {
return gotNewGlobalLinkedData;
};
if (args.TYPE == "Private (Linked)") {
return gotNewPrivateLinkedData;
};
}
setMyName(args) {
if (myName == "") {
if (isRunning) {
if (args.NAME != "") {
if (!(userNames.indexOf(args.NAME) >= 0)) {
if (args.NAME.length > 20) {
return "Your username must be 20 characters or less!"
} else {
if (args.NAME.length != 0) {
if (args.NAME == "%CA%" || args.NAME == "%CC%" || args.NAME == "%CD%" || args.NAME == "%MS%"){
return "That ID is reserved.";
} else {
wss.send("<%sn>\n" + args.NAME); // begin packet data with setname command in the header
myName = args.NAME;
return "Set username on server successfully.";
}
} else {
return "You can't have a blank username!";
}
}
} else {
return "You can't have the same name as someone else!";
}
} else {
return "You cannot have a blank username!";
}
} else {
return "Connection closed, no action taken.";
}
} else {
return "Username already set!";
};
};
parseJSON({
PATH,
JSON_STRING
}) {
try {
const path = PATH.toString().split('/').map(prop => decodeURIComponent(prop));
if (path[0] === '') path.splice(0, 1);
if (path[path.length - 1] === '') path.splice(-1, 1);
let json;
try {
json = JSON.parse(' ' + JSON_STRING);
} catch (e) {
return e.message;
}
path.forEach(prop => json = json[prop]);
if (json === null) return 'null';
else if (json === undefined) return '';
else if (typeof json === 'object') return JSON.stringify(json);
else return json.toString();
} catch (err) {
return '';
}
};
refreshUserList() {
if (isRunning == true) {
wss.send("<%rf>\n"); // begin packet data with global stream idenifier in the header
return "Sent request successfully.";
} else {
return "Connection closed, no action taken.";
}
};
resetNewData(args) {
if (args.TYPE == "Global") {
if (gotNewGlobalData == true) {
gotNewGlobalData = false;
};
};
if (args.TYPE == "Private") {
if (gotNewPrivateData == true) {
gotNewPrivateData = false;
};
};
if (args.TYPE == "Global (Linked)") {
if (gotNewGlobalLinkedData == true) {
gotNewGlobalLinkedData = false;
};
};
if (args.TYPE == "Private (Linked)") {
if (gotNewPrivateLinkedData == true) {
gotNewPrivateLinkedData = false;
};
};
};
resetNewVarData(args) {
if (args.TYPE == "Global") {
if (args.VAR in globalVars) {
gotNewGlobalVarData[args.VAR] = false;
}
} else if (args.TYPE == "Private") {
if (args.VAR in privateVars) {
gotNewPrivateVarData[args.VAR] = false;
}
}
};
linkWithID(args) {
if (isRunning && specialHandshakeAcquired) {
if (myName != "") {
if (args.ID == "") {
if (linkTo != "") {
linkTo = "";
sGLinkedData = "";
sPLinkedData = "";
gotNewGlobalLinkedData = false;
gotNewPrivateLinkedData = false;
globalVars = {};
privateVars = {};
gotNewGlobalVarData = {};
gotNewPrivateVarData = {};
wss.send("<%rt>\n" + myName);
return "Now linked to main link.";
} else {
return "Already linked to main link!";
}
} else {
if (userNames.indexOf(args.ID) >= 0) {
if (myName != args.ID) {
if (linkTo != args.ID) {
linkTo = args.ID;
sGLinkedData = "";
sPLinkedData = "";
gotNewGlobalLinkedData = false;
gotNewPrivateLinkedData = false;
globalVars = {};
privateVars = {};
gotNewGlobalVarData = {};
gotNewPrivateVarData = {};
wss.send("<%rl>\n" + myName + "\n" + args.ID);
return ("Now linked to ID: "+String(args.ID)+".");
} else {
return ("Already linked to ID: "+String(args.ID)+"!");
}
} else {
return "Can't link to yourself!";
}
} else {
return "ID does not exist!";
}
}
} else {
return "Username not set! No action taken.";
}
} else {
if (isRunning) {
return "Server is out-of-date / Doesn't support special features!";
} else {
return "Connection closed, no action taken.";
}
};
};
returnIsLinked() {
return ((linkTo != "") && specialHandshakeAcquired);
};
returnLinkedID() {
return linkTo;
};
};
// CloudAccount class for enabling access to the Disk and Coin APIs.
class cloudaccount {
constructor(runtime, extensionId) {
this.runtime = runtime;
}
static get STATE_KEY() {
return 'Scratch.websockets';
}
getInfo() {
return {
id: 'cloudaccount',
name: 'CloudAccount',
color1: '#054c63',
color2: '#054c63',
color3: '#043444',
blockIconURI: ca_block_icon,
menuIconURI: ca_menu_icon,
blocks: [
{
opcode: 'reportData',
blockType: Scratch.BlockType.REPORTER,
text: 'Account data',
}, {
opcode: 'getComState',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Connected?',
}, {
opcode: 'gotData',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Got new Account data?',
}, {
opcode: 'returnAuth',
blockType: Scratch.BlockType.BOOLEAN,
text: 'Logged in?',
}, {
opcode: 'resetNewData',
blockType: Scratch.BlockType.COMMAND,
text: 'Reset Got New Account Data',
}, {
opcode: 'doAcc',
blockType: Scratch.BlockType.COMMAND,
text: '[ACCMODE] with password [pswd]',
arguments: {
ACCMODE: {
type: Scratch.ArgumentType.STRING,
menu: 'accmenu',
defaultValue: 'Login',
},
pswd: {
type: Scratch.ArgumentType.STRING,
defaultValue: ' ',
},
},
}, {
opcode: 'checkAcc',
blockType: Scratch.BlockType.COMMAND,
text: 'Check account',
}, {
opcode: 'logoutAcc',
blockType: Scratch.BlockType.COMMAND,
text: 'Logout',
},
],
menus: {
accmenu: {
items: ['Login', 'Register / Change Password', 'Delete Account'],
},
},
};
};
reportData() {
return accountData;
};
gotData() {
return gotAccountData;
};
getComState() {
if (isRunning) {
if (userNames.indexOf("%CA%") >= 0) {
return true;
} else {
return false;
}
} else {
return false;
}
};
returnAuth() {
return isAuth;
};
resetNewData() {
if (gotAccountData) {
gotAccountData = false;
}
};
doAcc(args) {
if (args.ACCMODE == "Login") {
if (isRunning) {
if (!isAuth) {
if (myName != ""){
accMode = "LI"
wss.send("<%ps>\n" + myName + '\n%CA%\n{"cmd":"LOGIN","id":"'+ myName+'", "data":"'+args.pswd+'"}\n');
return "Sent request successfully.";