-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLXChat.as
1878 lines (1575 loc) · 60.3 KB
/
LXChat.as
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
package {
import flash.display.MovieClip;
import flash.utils.ByteArray;
import com.adobe.serialization.json.JSONDecoder;
import com.adobe.serialization.json.JSONEncoder;
import flash.utils.getDefinitionByName;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.text.TextFormatAlign;
import ValveLib.Globals;
import flash.text.TextFormat;
import flash.text.TextFieldType;
import scaleform.gfx.TextFieldEx;
import ValveLib.Events.InputBoxEvent;
import ValveLib.Controls.InputBox;
import flash.events.FocusEvent;
import flash.events.TextEvent;
import flash.text.StyleSheet;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import scaleform.clik.controls.ScrollBar;
import flash.text.TextFieldAutoSize;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Dictionary;
import scaleform.gfx.FocusManager;
import scaleform.clik.managers.FocusHandler;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import ModDotaLib.Net.D2DNSClient;
public class LXChat extends MovieClip {
private var mgs:MGSocket = null;
private var BATCH_TIMER = 250;
private var BACKLOG = 30000;
private var MSG_HISTORY = 30;
private var CONN_TIMEOUT = 6000;
private var ROSTER_BATCH_COUNT = 5;
private var lx = null;
private var panel:MovieClip;
private var indent:MovieClip;
private var outer:MovieClip;
private var container:MovieClip;
private var closeButton:MovieClip;
private var title:TextField;
private var resizeClip:MovieClip;
private var historyBG:MovieClip;
private var history:MovieClip;
private var rosterBG:MovieClip;
private var roster:MovieClip;
private var input:InputBox;
private var inputBG:MovieClip;
private var participantsButton:MovieClip;
private var batchCount = ROSTER_BATCH_COUNT - 1;
private var rosterUnclean:Boolean = true;
private var rosterShown:Boolean = true;
private var resizeStartX:Number;
private var resizeStartY:Number;
private var resizeScrollLock:Boolean;
private var dragging:Boolean = false;
private var chatOpts:Object;
private var asdf:int = 1128;
private var connectionIP:String = "71.179.179.140";
private var connectionDNS:String = "lxchat.duckdns.org";
//private var connectionIP:String = "96.244.208.108";
//private var connectionIP:String = "192.168.222.3";
private var curChannel:String = "home";
private var id = null;
private var userName:String = null;
private var authed:Boolean = false;
private var authToken:String = null;
private var role:int = MGSocket.ROLE_USER;
private var channelText:Object = {};
private var channelRosterNames:Object = {};
private var channelRosterIds:Object = {};
private var channelMessageHistory:Object = {};
private var messageHistoryIndex:int = 0;
private var batchTimer:Timer;
private var lastBatchTime:Number = 0;
private var timeoutTimer:Timer;
private var lobbyLinkUser = null;
private var canJoinLobby:Boolean = true;
private var showUserNotifications:Boolean = false;
private var substitutions = {"BabyRage":20,
"Baku":20,
"BibleThump":20,
"ChaChing":20,
"DankMeme":20,
"DansGame":20,
"DendiFace":20,
"EleGiggle":20,
"EmoTA":20,
"EvilLenny":13,
"FailFish":20,
"FrankerZ":20,
"FrogGod":20,
"GreyFace":20,
"HandsomeDevil":20,
"HollaHolla":20,
"Impossibru":20,
"JohnMadden":20,
"KAPOW":20,
"Kappa":20,
"Keepo":20,
"Kreygasm":20,
"LastWord":20,
"LordGaben":20,
"MyllDerp":20,
"NoyaHammer":20,
"PeonSad":20,
"PJSalt":20,
"PogChamp":20,
"PromNight":20,
"PureSkill":20,
"PWizzy":20,
"RoyMander":20,
"ShhQuiet":20,
"SleepyTime":20,
"SMOrc":20,
"SmugCourier":20,
"SnoozeFest":20,
"TeamGomez":20,
"TinkerFi":20,
"TrashMio":20,
"TrollFace":20,
"UltraSin":20,
"VolvoPls":9,
"WinWaker":20};
//BabyRage Baku BibleThump ChaChing DankMeme DansGame DendiFace EleGiggle EmoTA EvilLenny FailFish FrankerZ FrogGod GreyFace HandsomeDevil HollaHolla Impossibru JohnMadden KAPOW Kappa Keepo Kreygasm LastWord LordGaben MyllDerp NoyaHammer PeonSad PJSalt PogChamp PromNight PureSkill PWizzy RoyMander ShhQuiet SleepyTime SMOrc SmugCourier SnoozeFest TeamGomez TinkerFi TrashMio TrollFace UltraSin VolvoPls WinWaker
/* TODO
- add password display to host in LX
- share with chat button on host display
- silent mute/ban/ipban info adds
- batch roster stuff, maytbe check batch fixer for delay causing
- add dansgame emote
- role api on lobbybot
-
-x Fixed join channel after auth i think
-x Messages in the room mentioning your name are now highlighted
-x Added escaping to ban/mute/ipban lists
-x Rewrote the string replacement/regex functions in scaleform to handle Unicode better
-x Added emotes.
- refire /connect on focus
- custom lobby warning shows on regular games, shouldn't
- tab completion
*/
public function LXChat(lx:*, authToken:String = null) {
// constructor code
trace("LXChat constructed");
trace(asdf);
this.id = int(Globals.instance.Loader_profile_mini.movieClip.ProfileMini_main.ProfileMini.Persona.steamIDNumber.text);
this.userName = Globals.instance.Loader_profile_mini.movieClip.ProfileMini_main.ProfileMini.Persona.Player.PlayerNameIngame.text;
this.lx = lx;
this.authToken = authToken;
// panels
container = new MovieClip();
var panelClass:Class = getDefinitionByName("DB_inset") as Class;
panel = new panelClass();
panel.visible = true;
panel.enabled = true;
panel.y = -5;
var indentClass:Class = getDefinitionByName("indent_hilite") as Class;
indent = new indentClass();
indent.y = -35;
indent.height = 30;
var outerClass:Class = getDefinitionByName("DB4_outerpanel") as Class;
outer = new outerClass();
outer.y = -30;
title = lx.createTextField(22, 0xFFFFFF, TextFormatAlign.CENTER);
title.y = -32;
title.text = "LX Chat";
var closeClass:Class = getDefinitionByName("CloseButton") as Class;
closeButton = new closeClass();
closeButton.width = 16;
closeButton.height = 16;
closeButton.y = -26;
var participantClass:Class = getDefinitionByName("s_ToggleParticipantsButton") as Class;
participantsButton = new participantClass();
//participantsButton.width = 16;
//participantsButton.height = 16;
participantsButton.y = -27;
participantsButton.label = "";
participantsButton.scaleX = 1.2;
participantsButton.scaleY = 1.2;
inputBG = new panelClass();
inputBG.height = 35;
inputBG.x = 5;
var tf:TextFormat = Globals.instance.Loader_chat.movieClip.chat_main.chat.ChatInputBox.textField.getTextFormat();
var ibClass:Class = getDefinitionByName("InputBoxSkinned") as Class;
input = new ibClass() as InputBox;
input.x = inputBG.x + 10;
input.height = inputBG.height;
tf.size = 16;
tf.color = 0xFFFFFF;
tf.align = TextFormatAlign.LEFT;
tf.font = "$TextFont";
input.textField.styleSheet = null;
input.defaultTextFormat = tf;
input.textField.setTextFormat(tf);
input.textField.defaultTextFormat = tf;
//input.textField.autoSize = "none";
input.maxChars = 400;
//input.textField.type = TextFieldType.INPUT;
TextFieldEx.setVerticalAlign(input.textField, TextFieldEx.VALIGN_CENTER);
//this.hostClip.addChild(field);
input.visible = true;
input.text = "";
historyBG = new panelClass();
historyBG.x = 5;
var historyClass:Class = getDefinitionByName("s_history") as Class;
history = new historyClass();
history.x = historyBG.x + 2
history.sb.width += 4;
var ss:StyleSheet = new StyleSheet();
ss.setStyle("a:link",{"textDecoration":"none"});
ss.setStyle("a:hover",{"textDecoration":"underline"});
history.taChat.styleSheet = ss;
rosterBG = new panelClass();
rosterBG.width = 140;
roster = new historyClass();
roster.sb.width += 4;
roster.sb.x = rosterBG.width - 2 - roster.sb.width;
ss = new StyleSheet();
ss.setStyle("a:link",{"textDecoration":"none"});
ss.setStyle("a:hover",{"textDecoration":"underline"});
//ss.setStyle("a:hover",{color:"#FFFFFF", "textDecoration":"none"});
roster.taChat.styleSheet = ss;
//roster.taChat.wordWrap = false;
//roster.taChat.autoSize = TextFieldAutoSize.LEFT;
var chatMask:Sprite = new Sprite();
chatMask.graphics.beginFill(0xFF0000);
chatMask.graphics.drawRect(0, 0, rosterBG.width - 25, 100);
roster.addChild(chatMask);
roster.taChat.mask = chatMask;
var resizeClass:Class = getDefinitionByName("ResizeClip") as Class;
resizeClip = new resizeClass();
container.addChild(outer);
container.addChild(title);
container.addChild(panel);
container.addChild(indent);
container.addChild(inputBG);
container.addChild(input);
container.addChild(historyBG);
container.addChild(history);
container.addChild(rosterBG);
container.addChild(roster);
container.addChild(participantsButton);
container.addChild(closeButton);
container.addChild(resizeClip);
trace("1");
var subs = new Array;
var i:int = 0;
for (var word in substitutions){
var yoff = substitutions[word];
var imgClass = getDefinitionByName(word + ".png") as Class;
var img = new imgClass();
subs[i] = { subString:word + " ", image:img, baseLineY:yoff, id:"sm=" + word };
i++;
}
//subs[0] = { subString:"Kappa ", image:kappa, baseLineY:20, id:"sm=Kappa" };
TextFieldEx.setImageSubstitutions(history.taChat, subs);
trace("=====");
/*for (var b in Globals.instance.Loader_chat.movieClip.histories){
trace(b);
var c = Globals.instance.Loader_chat.movieClip.histories[b];
if (c.hasOwnProperty("taChat")){
trace(c.taChat.htmlText);
trace("---------");
}
}*/
trace("=====");
chatOpts = lx.lxOptions.Chat;
if (chatOpts == null){
//lx.screenWidth * .65 - container.width / 2 * lx.correctedRatio;
//lx.screenHeight * .5 - container.height / 2 * lx.correctedRatio;
var clip = Globals.instance.Loader_chat.movieClip.chat_main.chat.bg;
var point = clip.localToGlobal(new Point(0,0));
var point2 = clip.localToGlobal(new Point(clip.width, clip.height));
var xpos = point.x
var ypos = point.y + 85 * lx.correctedRatio;
var xratio = 1;
switch(clip.width){
case 540:
// 16:9
xratio = .92;
break;
case 372:
// 16:10
xratio = 1.3;
break;
case 272:
// 4:3
xratio = 1.77;
}
var wid = (point2.x - point.x) / lx.correctedRatio * xratio;
var hei = (point2.y - point.y) / lx.correctedRatio * 1.46;
trace(wid, " -- ", hei);
chatOpts = {X:xpos, Y:ypos, Width:wid, Height:hei, ShowRoster:"1", ShowUserNotifications:"0"};
lx.lxOptions.Chat = chatOpts;
saveChatOpts();
}
if (chatOpts.X + chatOpts.Width * lx.correctedRatio > lx.screenWidth)
chatOpts.X = lx.screenWidth - chatOpts.Width;
if (chatOpts.Y + chatOpts.Height * lx.correctedRatio > lx.screenHeight)
chatOpts.Y = lx.screenHeight - chatOpts.Height;
rosterShown = chatOpts.ShowRoster == "1"
if (chatOpts.ShowUserNotifications == null){
chatOpts.ShowUserNotifications = "0";
saveChatOpts();
}
showUserNotifications = chatOpts.ShowUserNotifications == "1";
if (!rosterShown){
roster.visible = false;
rosterBG.visible = false;
}
resizeWindow(chatOpts.Width, chatOpts.Height);
container.addEventListener(MouseEvent.MOUSE_DOWN, handleDragDown);
container.addEventListener(MouseEvent.MOUSE_UP, handleDragUp);
resizeClip.addEventListener(MouseEvent.MOUSE_DOWN, handleResizeDown);
closeButton.addEventListener(MouseEvent.CLICK, gameCloseClicked);
participantsButton.addEventListener(MouseEvent.CLICK, rosterToggle);
input.addEventListener(InputBoxEvent.TEXT_SUBMITTED, commandInput);
input.addEventListener(TextEvent.TEXT_INPUT, fixFormat);
history.taChat.addEventListener(TextEvent.LINK, chatLinkClicked);
roster.taChat.addEventListener(TextEvent.LINK, chatLinkClicked);
input.addEventListener(FocusEvent.FOCUS_IN, inputFocusIn);
input.addEventListener(FocusEvent.FOCUS_OUT, inputFocusOut);
/*if (minigameLastPositions[gameName] != null){
container.x = minigameLastPositions[gameName].x;
container.y = minigameLastPositions[gameName].y;
}*/
//else{
container.x = chatOpts.X;
container.y = chatOpts.Y;
//}
Globals.instance.Loader_top_bar.movieClip.addChildAt(container, Globals.instance.Loader_top_bar.movieClip.getChildIndex(lx.scalingTopBarPanel) - 1);
channelText[curChannel] = "";
lastBatchTime = new Date().time;
batchTimer = new Timer(BATCH_TIMER, 0);
batchTimer.addEventListener(TimerEvent.TIMER, batchText);
batchTimer.start();
connect();
}
public override function get visible():Boolean{
return container.visible;
}
public override function set visible(value:Boolean):void{
container.visible = value;
}
public override function get scaleX():Number{
return container.scaleX;
}
public override function set scaleX(value:Number):void{
container.scaleX = value;
}
public override function get scaleY():Number{
return container.scaleY;
}
public override function set scaleY(value:Number):void{
container.scaleY = value;
}
private function keyListener(e:KeyboardEvent){
if (e.keyCode == Keyboard.UP){
if (!channelMessageHistory[curChannel] || messageHistoryIndex == channelMessageHistory[curChannel].length - 1)
return;
if (messageHistoryIndex == 0)
channelMessageHistory[curChannel][0] = input.text;
messageHistoryIndex++;
input.text = channelMessageHistory[curChannel][messageHistoryIndex];
}
else if (e.keyCode == Keyboard.DOWN){
if (!channelMessageHistory[curChannel] || messageHistoryIndex == 0)
return;
messageHistoryIndex--;
input.text = channelMessageHistory[curChannel][messageHistoryIndex];
}
else{
return;
}
inputToEnd();
}
private function inputFocusIn(e:FocusEvent){
lx.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyListener)
//input.addEventListener(KeyboardEvent.KEY_DOWN, keyListener);
}
private function inputFocusOut(e:FocusEvent){
lx.stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyListener);
}
private function handleDragDown(event:MouseEvent){
if (event.target == outer || event.target == indent || event.target == title){
dragging = true;
container.startDrag();
}
}
private function handleDragUp(event:MouseEvent){
if (dragging)
container.stopDrag();
chatOpts.X = container.x;
chatOpts.Y = container.y;
saveChatOpts();
}
private function handleResizeMove(event:MouseEvent){
var p:Point = container.localToGlobal(new Point(0,0));
var newX = event.stageX - p.x;
var newY = event.stageY - p.y;
if (newX < 325)
newX = 325;
if (newY < 150)
newY = 150;
resizeWindow(newX / lx.correctedRatio, newY / lx.correctedRatio);
if (resizeScrollLock)
history.taChat.scrollV = history.taChat.maxScrollV;
}
private function handleResizeDown(event:MouseEvent){
resizeStartX = event.stageX;
resizeStartY = event.stageY;
resizeScrollLock = history.taChat.scrollV == history.taChat.maxScrollV;
lx.stage.addEventListener(MouseEvent.MOUSE_MOVE, handleResizeMove);
lx.stage.addEventListener(MouseEvent.MOUSE_UP, handleResizeUp);
}
private function handleResizeUp(event:MouseEvent){
lx.stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleResizeMove);
lx.stage.removeEventListener(MouseEvent.MOUSE_UP, handleResizeUp);
chatOpts.Width = panel.width - 15;
chatOpts.Height = panel.height - 15;
saveChatOpts();
}
private function gameCloseClicked(e:MouseEvent){
container.visible = false;
}
private function rosterToggle(e:MouseEvent){
var scrollBottom = history.taChat.scrollV == history.taChat.maxScrollV;
historyBG.width += rosterBG.width * ((rosterShown) ? 1 : -1);
rosterShown = !rosterShown;
rosterBG.visible = rosterShown;
roster.visible = rosterShown;
chatOpts.ShowRoster = (rosterShown) ? "1" : "0";
resizeWindow(panel.width - 15, panel.height - 15);
drawRoster();
saveChatOpts();
if (scrollBottom)
history.taChat.scrollV = history.taChat.maxScrollV;
}
private function fixFormat(e:TextEvent){
var tf:TextFormat = input.textField.getTextFormat();
tf.size = 16;
input.textField.setTextFormat(tf);
input.textField.defaultTextFormat = tf;
//input.removeEventListener(FocusEvent.FOCUS_IN, focused);
}
private function chatLinkClicked(e:TextEvent) : *
{
trace("clicked: " + e.text);
if (e.text.match(/a[0-9]+/)){
var replace = "";
if (input.text.match(/^\s*$/)){
replace = "/msg ";
input.text = "";
}
var uid = e.text.substr(1);
var user = channelRosterIds[curChannel][uid];
if (user != null){
if (user.name.indexOf(" ") >= 0 || user.name.charAt(0) == "\""){
var str = "";
for (var i=0; i<user.name.length; i++){
var ch = user.name.charAt(i);
if (ch == "\"" || ch == "\\"){
str += "\\";
}
str += ch;
}
input.text += replace + "\"" + str + "\" ";
}
else
input.text += replace + user.name + " ";
fixFormat(null);
lx.stage.focus = input;
inputToEnd();
}
Globals.instance.Loader_chat.movieClip.gameAPI.ChatLinkClicked(e.text);
}
else if (e.text.match(/l([0-9]+):([0-9]+)/)){
if (canJoinLobby){
var groups = e.text.match(/l([0-9]+):([0-9]+)/);
var lobbyid = groups[1];
lobbyLinkUser = groups[2];
appendText("<i>Attempting to join lobby.</i>");
mgs.writeJSON({type:"joinLobby", fromUser:id, toUser:lobbyLinkUser, lobby:lobbyid}, MGSocket.GAME_JSON);
canJoinLobby = false;
var fun:Function = function(e:TimerEvent){
canJoinLobby = true;
}
var timer:Timer = new Timer(2000,1);
timer.addEventListener(TimerEvent.TIMER, fun);
timer.start();
}
}
}
public function appendText(text:String, batch:Boolean = false){
if (text.charAt(text.length - 1) == "\n")
channelText[curChannel] += text;
else
channelText[curChannel] += text + "\n";
var length:int = channelText[curChannel].length;
if (length > BACKLOG){
channelText[curChannel] = channelText[curChannel].substring(length - BACKLOG);
var offset:int = channelText[curChannel].indexOf("\n") + 1;
channelText[curChannel] = channelText[curChannel].substring(offset);
}
if (batch)
batchText(null);
}
private function batchText(e:TimerEvent){
batchCount++;
if (batchCount >= ROSTER_BATCH_COUNT){
batchCount = 0;
drawRoster();
}
lastBatchTime = new Date().time;
var scrollBottom = history.taChat.scrollV == history.taChat.maxScrollV;
history.taChat.htmlText = channelText[curChannel];
if (scrollBottom)
history.taChat.scrollV = history.taChat.maxScrollV;
}
private function commandInput(e:InputBoxEvent){
if (input.text == "")
return;
var line = input.text;
input.text = "";
if (channelMessageHistory[curChannel] == null)
channelMessageHistory[curChannel] = [];
channelMessageHistory[curChannel][0] = line;
if (channelMessageHistory[curChannel].unshift("") > MSG_HISTORY)
channelMessageHistory[curChannel].pop();
messageHistoryIndex = 0;
var groups = line.match(/^\/connect/);
if (groups){
if (mgs == null)
connect();
else
appendText("<B><font size='14' color='#FF0000'>Already connected to the chat server.</font></B>");
return;
}
groups = line.match(/^\/\?/);
if (groups || line.match(/^\/help/)){
appendText("<font size='10'> <font color='#FFFFFF'>/connect</font> -- Connect to the server");
switch(role){
case MGSocket.ROLE_ADMIN:
appendText(" <font color='#FFFFFF'>/own [NAME]</font> -- Change [NAME] to owner");
appendText(" <font color='#FFFFFF'>/unown [NAME]</font> -- Remove owner from [NAME]");
case MGSocket.ROLE_OWNER:
appendText(" <font color='#FFFFFF'>/mod [NAME]</font> -- Change [NAME] to moderator");
appendText(" <font color='#FFFFFF'>/unmod [NAME]</font> -- Remove moderator from [NAME]");
appendText(" <font color='#FFFFFF'>/ipban [NAME] [REASON]</font> -- IP BAN [NAME] with [REASON]");
appendText(" <font color='#FFFFFF'>/unipban [INDEX]</font> -- Lift the IP Ban given by the IP Ban List [INDEX]");
appendText(" <font color='#FFFFFF'>/ipbanlist</font> -- List of IP bans");
case MGSocket.ROLE_MODERATOR:
appendText(" <font color='#FFFFFF'>/mute [NAME] [TIME] [REASON]</font> -- Mute [NAME] for [TIME] (1m,8h,1d,etc) with [REASON]");
appendText(" <font color='#FFFFFF'>/unmute [NAME]/[ID]</font> -- Unmute user with [NAME] or [ID]");
appendText(" <font color='#FFFFFF'>/ban [NAME] [TIME] [REASON]</font> -- Ban [NAME] for [TIME] (1m,8h,1d,etc) with [REASON]");
appendText(" <font color='#FFFFFF'>/unban [NAME]/[ID]</font> -- Unban user with [NAME] or [ID]");
appendText(" <font color='#FFFFFF'>/kick [NAME] [REASON]</font> -- Kick [NAME] with [REASON]");
appendText(" <font color='#FFFFFF'>/warn [NAME] [REASON]</font> -- Warn [NAME] with [REASON] - Has no direct effect");
appendText(" <font color='#FFFFFF'>/banlist</font> -- List of bans");
appendText(" <font color='#FFFFFF'>/mutelist</font> -- List of mutes");
default:
appendText(" <font color='#FFFFFF'>/msg [NAME] MESSAGE</font> -- Send private message to [NAME]");
appendText(" <font color='#FFFFFF'>/whois [NAME]</font> -- See details about [NAME]");
appendText(" <font color='#FFFFFF'>/ignore [NAME]</font> -- Ignore messages from [NAME]");
appendText(" <font color='#FFFFFF'>/unignore [NAME]/[ID]</font> -- Unignore message from [NAME]");
appendText(" <font color='#FFFFFF'>/ignorelist</font> -- List of ignored users");
appendText(" <font color='#FFFFFF'>/ping</font> -- Display your ping to the server");
appendText(" <font color='#FFFFFF'>/notifications</font> -- Toggle displaying user join/leave/disconnects");
appendText(" <font color='#FFFFFF'>/disconnect</font> -- Disconnect from server</font>", true);
break;
}
return;
}
if (mgs == null){
appendText("<B><font size='14' color='#FF0000'>Not currently connected to the chat server. Type \"<font color='#FFFFFF'>/connect</font>\" to connect.</font></B>");
return;
}
var type = MGSocket.SYSTEM_JSON;
var obj = null;
var msg;
var chan;
var user;
var str:String;
var ret;
var uid;
var time;
if (line.charAt(0) == '/'){
// command
switch(role){
case MGSocket.ROLE_ADMIN:
groups = line.match(/^\/own (.+)/);
if (groups && line.length >= 6){
str = line.substring(5);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"ownUser", channel:curChannel, fromUser:id, user:Number(uid)};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/unown (.+)/);
if (groups && line.length >= 8){
str = line.substring(7);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"unownUser", channel:curChannel, fromUser:id, user:Number(uid)};
type = MGSocket.GAME_JSON;
}
case MGSocket.ROLE_OWNER:
groups = line.match(/^\/mod (.+)/);
if (groups && line.length >= 6){
str = line.substring(5);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"modUser", channel:curChannel, fromUser:id, user:Number(uid)};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/unmod (.+)/);
if (groups && line.length >= 8){
str = line.substring(7);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"unmodUser", channel:curChannel, fromUser:id, user:Number(uid)};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/ipban (.+)/);
if (groups && line.length >= 8){
str = line.substring(7);
ret = splitInputMessage(str);
user = ret.user;
msg = ret.msg;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"ipbanUser", fromUser:id, user:Number(uid), reason:msg};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/unipban (.+)/);
if (groups && line.length >= 10){
str = line.substring(9);
//ret = splitInputMessage(str);
//user = ret.user;
//uid = channelRosterNames[curChannel][user];
if (!Number(str)){
appendText("<font size='12' color='#FFFFFF'>No index given.</font>", true);
return;
}
obj = {type:"unipbanUser", fromUser:id, index:Number(str)};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/ipbanlist/);
if (groups){
obj = {type:"ipbanList", fromUser:id};
type = MGSocket.GAME_JSON;
}
case MGSocket.ROLE_MODERATOR:
groups = line.match(/^\/mute (.+)/);
if (groups && line.length >= 7){
str = line.substring(6);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
msg = ret.msg;
if (msg.indexOf(" ") > 0){
time = msg.substring(0, msg.indexOf(" "));
msg = msg.substring(msg.indexOf(" ") + 1);
}
else{
time = msg;
msg = "";
}
time = getTimeDelta(time);
if (time == null){
appendText("<font size='12' color='#FFFFFF'>Invalid time given.</font>", true);
return;
}
if (uid == null){
uid = user;
if (!Number(uid) || channelRosterIds[curChannel][user] == null){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"muteUser", fromUser:id, user:Number(uid), time:time, reason:msg};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/unmute (.+)/);
if (groups && line.length >= 9){
str = line.substring(8);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"unmuteUser", fromUser:id, user:Number(uid)};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/ban (.+)/);
if (groups && line.length >= 6){
str = line.substring(5);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
msg = ret.msg;
if (msg.indexOf(" ") > 0){
time = msg.substring(0, msg.indexOf(" "));
msg = msg.substring(msg.indexOf(" ") + 1);
}
else{
time = msg;
msg = "";
}
time = getTimeDelta(time);
if (time == null){
appendText("<font size='12' color='#FFFFFF'>Invalid time given.</font>", true);
return;
}
if (uid == null){
uid = user;
if (!Number(uid) || channelRosterIds[curChannel][user] == null){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"banUser", fromUser:id, user:Number(uid), time:time, reason:msg};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/unban (.+)/);
if (groups && line.length >= 8){
str = line.substring(7);
ret = splitInputMessage(str);
user = ret.user;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
}
else if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
obj = {type:"unbanUser", fromUser:id, user:Number(uid)};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/kick (.+)/);
if (groups && line.length >= 7){
str = line.substring(6);
ret = splitInputMessage(str);
user = ret.user;
msg = ret.msg;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"kickUser", fromUser:id, user:Number(uid), reason:msg};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/warn (.+)/);
if (groups && line.length >= 7){
str = line.substring(6);
ret = splitInputMessage(str);
user = ret.user;
msg = ret.msg;
uid = channelRosterNames[curChannel][user];
if (uid == null){
uid = user;
if (!Number(uid)){
appendText("<font size='12' color='#FFFFFF'>No user found.</font>", true);
return;
}
}
obj = {type:"warnUser", fromUser:id, user:Number(uid), reason:msg, toChannel:curChannel};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/banlist/);
if (groups){
obj = {type:"banList", fromUser:id};
type = MGSocket.GAME_JSON;
}
groups = line.match(/^\/mutelist/);
if (groups){
obj = {type:"muteList", fromUser:id};
type = MGSocket.GAME_JSON;
}
case MGSocket.ROLE_USER:
groups = line.match(/^\/msg (.+)/);
if (groups && line.length >= 6){
str = line.substring(5);
var replace:String = "/msg ";
ret = splitInputMessage(str);
replace += ret.replace;
user = ret.user;
msg = ret.msg;
uid = channelRosterNames[curChannel][user];
if (uid == null){
appendText("<B><font color='#FFFFFF' size='14'>No user found.</font></B>", true);
return;
}