-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMain.cs
3509 lines (3128 loc) · 91.1 KB
/
Main.cs
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
/*
EE CM serverside codes
Copyright (C) 2013-2015 Krock/SmallJoker <mk939@ymail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Compile for indev rooms
//#define INDEV
using System;
using System.Collections.Generic;
using System.IO;
using PlayerIO.GameLibrary;
namespace EE_CM
{
// Constants
enum C
{
// Must always be higher than the highest block ID, by 1
BLOCK_MAX = 1031,
BLOCK_TYPES = 5,
WORLD_TYPES = 5,
WORLDS_PER_PLAYER = 4,
SMILIES = 66,
AWAY_SMILEY = 65,
DIAMOND_SMILEY = 31
}
enum Rights
{
Moderator = 6,
Owner = 5,
Admin = 4,
Vigilant = 3,
Normal = 2,
Edit = 1,
None = 0,
}
#if INDEV
[RoomType("Indev")]
#else
[RoomType("Game38")]
#endif
public class EENGameCode : Game<Player>
{
#region Definition of block arrays and world data
Bindex[,] blocks;
Block[,] Nblock;
Block[, ,] PBlock;
COOR[] spawnCoor;
PlayerHistory[] usernames = new PlayerHistory[16];
WorldInfo info = new WorldInfo();
int[] gravity0Id = new int[] { 4, 112, 114, 115, 116, 117, 118 };
pList<string> banned = new pList<string>(),
admins = new pList<string>();
string[] modText = new string[20],
oldChat0 = new string[5], //names
oldChat1 = new string[5], //text
logbook = new string[5],
key_colors = new string[] { "red", "green", "blue" };
bool W_isOpen = false,
W_isSaved = false,
W_crownC = false,
W_upgrade = false,
W_isLoading = false,
W_allowText = false,
W_gotEdited = false,
kill_active = false,
isEditBlocked = false,
W_resized = false,
W_can_save = false,
W_experimental_saving = false,
W_canRespawn = true;
int W_width, W_height, W_plays,
W_crown = -1,
W_chatLimit = 150,
W_Bcount = 0,
moveLimit = 20,
cSpawn = 0,
W_type = -1,
sys_msg_max = 3,
W_broadcast_level = 0;
string W_key = "",
W_rot13,
W_Owner,
W_title,
SYS = "* SYSTEM",
say_normal = "abcdefghijklmnopqurstuvwxyz ";
byte[] keys = new byte[3];
#endregion
public override void GameStarted()
{
PreloadPlayerObjects = true;
W_Owner = "";
W_title = "unknown";
W_width = 200;
W_height = 200;
W_plays = 0;
W_rot13 = generate_rot13();
string prefix = RoomId[0] + "" + RoomId[1];
RoomData["plays"] = "0";
if (prefix == "PW" || prefix == "BW") {
W_key = generate_rot13() + generate_rot13();
load_worlddata(false, true);
} else {
clear_world(true);
if (RoomData.ContainsKey("name"))
W_title = RoomData["name"];
else
RoomData["name"] = W_title = "Untitled World";
if (RoomData.ContainsKey("editkey")) {
if (!string.IsNullOrEmpty(RoomData["editkey"])) {
RoomData["needskey"] = "yup";
W_key = RoomData["editkey"];
} else {
W_key = "";
W_isOpen = true;
}
RoomData.Remove("editkey");
}
}
if (W_key == "")
W_isOpen = true;
RoomData.Save();
AddTimer(Keys_Timer, 200);
AddTimer(Cleanup_Timer, 20000);
AddTimer(initPlayers, 1500);
AddTimer(killPlayers, 800);
}
public override void GameClosed()
{
if (!W_isSaved)
return;
PlayerIO.BigDB.Load("Worlds", RoomId, delegate(DatabaseObject o) {
o.Set("name", W_title);
o.Set("plays", W_plays);
string admins_text = "";
string[] admins_array = admins.GetData();
for (int i = 0; i < admins_array.Length; i++) {
if (admins_array[i] == null) continue;
admins_text += admins_array[i] + ',';
}
if (admins_text.Length > 0)
o.Set("admins", admins_text);
else if (o.Contains("admins"))
o.Remove("admins");
o.Save();
});
}
public override void UserJoined(Player pl)
{
string reason = HandleUserJoin(pl);
if (reason == null)
return;
pl.say_counter = 99;
pl.mWarns = 99;
pl.Send("info", "Connecting failed", reason);
pl.Disconnect();
}
string HandleUserJoin(Player pl)
{
long time = getMTime(),
last_online = 0;
for (int i = 0; i < usernames.Length; i++) {
if (usernames[i] == null) continue;
if (usernames[i].Id == pl.ConnectUserId) {
last_online = Math.Max(usernames[i].join_time, last_online);
}
}
if (time - last_online < 5)
return "You create traffic and I am a traffic light.";
if (W_resized)
return "This world got resized. Please wait until it has fully closed.\nThanks.";
if (!pl.PlayerObject.Contains("name"))
return "You need to set an username first.";
if (pl.PlayerObject.Contains("banned")) {
if (!(pl.PlayerObject["banned"] is bool)) {
long time_left = pl.PlayerObject.GetLong("banned") - getMTime();
if (time_left > 20) {
TimeSpan delta_time = new TimeSpan(time_left);
return ("This account has been banned from EE CM.\n" +
"Please wait " +
delta_time.Hours +
" hour(s) and " +
delta_time.Minutes +
" minute(s) until your ban expires.");
}
} else if (pl.PlayerObject.GetBool("banned"))
return "This account has been banned from EE CM.";
}
string name = pl.PlayerObject.GetString("name");
if (banned.Contains(name))
return "You have been banned from this world.";
bool isGuest = (name == "guest");
if (!isGuest) {
// Something against name modification
string allowed_chars = "abcdefghijklmnopqurstuvwxyz1234567890";
for (int i = 0; i < name.Length; i++) {
bool char_found = false;
for (int c = 0; c < allowed_chars.Length; c++) {
if (allowed_chars[c] == name[i]) {
char_found = true;
break;
}
}
if (!char_found) {
name = "";
break;
}
}
if (name.Length < 2)
return "You are using an invalid nickname.";
} else name = "guest-" + (pl.Id + 1);
pl.Name = name;
pl.isGuest = isGuest;
if (pl.PlayerObject.Contains("isModerator"))
pl.isModerator = pl.PlayerObject.GetBool("isModerator");
if (pl.PlayerObject.Contains("isVigilant"))
pl.isVigilant = pl.PlayerObject.GetBool("isVigilant");
// Use isGuest for non-chatters
if (!isGuest && pl.PlayerObject.Contains("chatbanned"))
pl.isGuest = pl.PlayerObject.GetBool("chatbanned");
if (pl.PlayerObject.Contains("face"))
pl.Face = pl.PlayerObject.GetInt("face");
int found = 0;
System.Net.IPAddress ip = pl.IPAddress;
foreach (Player p in Players) {
if (p.Name == name || p.Name == "x." + name) {
found += 3;
} else if (ip.Equals(p.IPAddress)) {
found += 2;
}
}
if (found > 6)
return "You have reached the limits of accounts in this world.";
// Increase plays counter
if (!isGuest) {
bool wasIn = false;
for (int i = 0; i < usernames.Length; i++) {
if (usernames[i] == null) continue;
if (usernames[i].Name == pl.Name) {
wasIn = true;
break;
}
}
if (!wasIn) {
W_plays++;
RoomData["plays"] = W_plays.ToString();
RoomData.Save();
}
}
if (usernames.Length < pl.Id + 1)
Array.Resize(ref usernames, pl.Id + 10);
usernames[pl.Id] = new PlayerHistory();
usernames[pl.Id].Name = pl.Name;
usernames[pl.Id].Id = pl.ConnectUserId;
usernames[pl.Id].join_time = getMTime();
return null;
}
public override void UserLeft(Player pl)
{
if (W_crown == pl.Id) W_crown = -1;
if (!pl.isInited)
return;
pl.isInited = false;
Broadcast("left", pl.Id);
#if !INDEV
pl.GetPlayerObject(delegate (DatabaseObject obj) {
obj.Set("face", pl.Face);
obj.Save();
});
#endif
}
public override void GotMessage(Player pl, Message m)
{
if (m.Type == "init" ||
m.Type == "botinit" ||
m.Type == "access") {
MainGameFunc(pl, m);
return;
}
if (m.Type == W_rot13 ||
m.Type == "cb" ||
m.Type == "cp" ||
m.Type == "th" ||
m.Type == "complete" ||
m.Type == "rcoins" ||
m.Type == "diamondtouch") {
if (!W_isLoading && pl.isInited && !W_resized && !pl.isDead) {
HandleBlock(pl, m);
}
return;
}
if (m.Type == "say" ||
m.Type == "m") {
if (pl.isInited && !W_resized) {
PlayerInteract(pl, m);
}
return;
}
if (m.Type == "key" ||
m.Type == "name" ||
m.Type == "clear" ||
m.Type == "save") {
if (pl.isAdmin && !W_isLoading) {
OwnerInteract(pl, m);
}
return;
}
// Check for W_rot13 combinations
bool isCmd = false;
char[] ext = { 'f', 'k', 'r', 'g', 'b' };
for (int i = 0; i < ext.Length; i++) {
if (m.Type == W_rot13 + ext[i]) {
isCmd = true;
break;
}
}
if (m.Type == "god" ||
m.Type == "mod" ||
m.Type == "c" ||
isCmd) {
if (pl.isInited) {
GamePlayFunc(pl, m);
}
return;
}
}
void MainGameFunc(Player pl, Message m)
{
#region Init
if ((m.Type == "init" || m.Type == "botinit") &&
!pl.isInited &&
!pl.send_init) {
// Allow god mode for Moderators in open worlds
if (W_key == "")
pl.canEdit = !pl.isModerator;
if (m.Type == "botinit") {
pl.isBot = true;
pl.Name = "x." + pl.Name;
if (m.Count == 1 && m[0] is bool)
pl.init_binary = (bool)m[0];
} else {
pl.firstFace = true;
}
if (W_upgrade) {
// Send dummy output for updated worlds
pl.Send("init", "updateOwner", "updateRoom", "0", "key", pl.Id, 16, 16, "", false, false, 2, 2, false);
pl.Send("upgrade");
} else {
pl.send_init = true;
}
return;
}
#endregion
if (m.Type == "access") {
if (!(m[0] is string) || !pl.isInited) {
pl.Disconnect();
return;
}
if (m.GetString(0) == W_key || pl.isModerator) {
pl.code_tries = 0;
pl.canEdit = true;
pl.Send("access");
} else {
pl.code_tries++;
if (pl.code_tries > 50)
pl.Disconnect();
}
return;
}
}
void HandleBlock(Player pl, Message m)
{
#region Block placement
if (m.Type == W_rot13) {
#region Verify block data
if (isEditBlocked || m.Count < 4 || !pl.canEdit)
return;
for (uint i = 0; i < 4; i++) {
if (!(m[i] is int))
return;
}
int l = m.GetInt(0),
x = m.GetInt(1),
y = m.GetInt(2),
b = m.GetInt(3);
if (!isValidCoor(x, y) || (l != 0 && l != 1) || b < 0)
return;
Bindex bl = new Bindex(blocks[x, y]);
#endregion
#region Get block info
if (pl.getBlockInfo) {
string text = "Id: " + (l == 0 ? bl.FG : bl.BG),
blPlacer = "?";
if (l == 0) {
if (bl.FG == 242) {
text += "\nRotation: " + bl.arg3;
text += "\nPortal-Id: " + bl.arg4;
text += "\nTarget portal: " + bl.arg5;
} else if (bl.FG == 43 || bl.FG == 77) {
text += "\nArg3: " + bl.arg3;
} else if (bl.FG == 1000) {
string ktx = "[ERROR]";
if (bl.arg3 >= 0 && bl.arg3 < modText.Length) {
if (modText[bl.arg3] != null)
ktx = modText[bl.arg3];
}
text += "\nText: " + ktx;
}
if (bl.FGp > 0) {
if (usernames[bl.FGp] != null)
blPlacer = usernames[bl.FGp].Name;
}
} else {
if (blocks[x, y].BGp > 0) {
if (usernames[bl.BGp] != null)
blPlacer = usernames[bl.BGp].Name;
}
}
text += "\nPlacer: " + blPlacer.ToUpper();
pl.Send("write", SYS, (l == 0 ? "Block" : "Background") + " [" + x.ToString() + '|' + y.ToString() + "]: \n" + text);
pl.getBlockInfo = false;
return;
}
#endregion
Message block_msg = null;
if (getBlockArgCount(b) == 0) {
if (b == (l == 0 ? bl.FG : bl.BG) || m.Count != 4) return;
#region normalBlock
if (l == 0 && b < (int)C.BLOCK_MAX) {
#if INDEV
removeOldBlock(x, y, bl.FG, bl.arg3);
if (b != 0) {
if (Nblock[0, b] == null)
Nblock[0, b] = new Block();
Nblock[0, b].Set(x, y);
}
bl.FG = b;
bl.FGp = pl.Id;
bl.arg3 = 0;
bl.pId = 0;
bl.pTarget = 0;
#else
#region foreground
bool edit = false;
if (b >= 0 && b <= 36) edit = true; // Default (some by Krock)
if (b >= 37 && b <= 42) edit = true; // Beta (by Krock)
if (b == 44) edit = true; // Black
if (b >= 45 && b <= 49) edit = true; // Factory (by Krock)
if (b == 50 || b == 243) edit = true; // Secrets
if (b >= 51 && b <= 58) edit = true; // Glass (by Krock)
if (b == 59) edit = true; // Summer 2011
if (b >= 60 && b <= 67) edit = true; // Candy (some by Krock)
if (b >= 68 && b <= 69) edit = true; // Halloween 2011
if (b >= 70 && b <= 76) edit = true; // Minerals (by Krock)
if (b >= 78 && b <= 82) edit = true; // Christmas 2011
if (b >= 84 && b <= 89) edit = true; // Tiles (by Minimania)
if (b == 90) edit = true; // White basic
if (b == 91 || b == 92) edit = true; // Swamp - One way (by Toop)
if (b >= 93 && b <= 95) edit = true; // Ice
if (b >= 96 && b <= 98) edit = true; // Gothic (by Toop)
if (b >= 100 && b <= 101) edit = true; // Coins
//if (b >= 110 && b <= 111) edit = true;
if (b >= 400 && b <= 405) edit = true; // Materials (unknown)
if (b >= 406 && b <= 411) edit = true; // Wall (by Stubby)
if (b >= 412 && b <= 414) edit = true; // Winter (by Toop)
if (b >= 415 && b <= 422) edit = true; // Wood (by HG)
if (b >= 423 && b <= 425) edit = true; // Marble (by HG)
if (b == 426 || b == 427) edit = true; // Granite (by HG)
if (b >= 428 && b <= 438) edit = true; // Extra Blocks (some unknown, some by HG)
if (b >= 439 && b <= 446) edit = true; // Carpet (by Toop)
if (b >= 447 && b <= 455) edit = true; // Mario (unknown)
if (b >= 456 && b <= 457) edit = true; // Extra gothic blocks (by Toop)
if (b >= 458 && b <= 465) edit = true; // Evolution (by HG)
if (b >= 466 && b <= 485) edit = true; // Alien (by Anatoly)
if (b >= 486 && b <= 491) edit = true; // Mansion (by Shadowda)
if (b == 492) edit = true; // Extra metal block (by Toop)
if (b >= 493 && b <= 499) edit = true; // Paint (by Toop)
if (b >= 1001 && b <= 1007) edit = true;// Checker (by Cola1)
if (b >= 1008 && b <= 1014) edit = true;// Dice (by Sleepy)
if (b == 1015) edit = true; // Terraquark (by Weirdo)
if (b >= 1016 && b <= 1020) edit = true;// Organic (by Boberov)
if (b >= 1021 && b <= 1030) edit = true;// Mecha (by Boberov and TundrumMax)
// Decoration
if (b == 103 && (pl.isAdmin || pl.isModerator)) {
edit = true; // Codeblock (by HG)
if (Nblock[0, b] != null) {
if (Nblock[0, b].used > 2)
edit = false;
}
}
if (b == 104) {
edit = true; // Checkpoint (by Krock)
if (Nblock[0, b] != null) {
if (Nblock[0, b].used > 600)
edit = false;
}
}
if (b == 105) edit = true; // Hazard (Spikes) (by Krock)
if ((b == 106 || b == 107) && pl.isAdmin) {
edit = true; // Trophy
if (Nblock[0, b] != null) {
if (Nblock[0, b].used >= 1)
edit = false;
}
}
if (b == 108 || b == 109) edit = true; // Water (by Krock)
if (b == 112) edit = true; // Ladder (unknown)
if (b == 113) edit = true; // Sand (slow) (unknown)
if (b == 118) edit = true; // Swamp-water (by Krock)
if (b >= 114 && b <= 117) edit = true; // Boost (by Krock)
//end special
if (b == 121) edit = true; // Invisible
if (b == 223) edit = true; // Halloween 2011 Trophy
if (b == 227) edit = true; // Candy
if (b >= 218 && b <= 222) edit = true; // Christmas 2011
if (b >= 224 && b <= 226) edit = true; // Halloween 2011
if (b >= 228 && b <= 232) edit = true; // Summer 2011
if (b >= 233 && b <= 240) edit = true; // Spring 2011 Grass
if (b == 241 && pl.isAdmin) {
edit = true; // Diamond
if (Nblock[0, b] != null) {
if (Nblock[0, b].used > 10)
edit = false;
}
}
if (b >= 244 && b <= 248) edit = true; // New year 2010
if (b >= 249 && b <= 254) edit = true; // Christmas 2010
if (b == 255 && (pl.isAdmin || pl.isModerator)) {
edit = true; // Spawnpoint
if (Nblock[0, b] != null) {
if (Nblock[0, b].used > 60)
edit = false;
}
}
if (b >= 256 && b <= 264) edit = true; // Swamp plants (by Toop)
if (b >= 265 && b <= 268) edit = true; // Snow and ice (by Toop)
if (b >= 269 && b <= 273) edit = true; // Gothic (by Toop)
if (b >= 274 && b <= 280) edit = true; // Prison (by Toop)
if (b >= 281 && b <= 285) edit = true; // Extra Gothic/Halloween (by HG)
if (b == 286) edit = true; // Snowman (unknown)
if (b == 287) edit = true; // Kock (by HG)
if (b >= 288 && b <= 299) edit = true; // Glass (by HG)
if (b >= 300 && b <= 305) edit = true; // Alien (by Weirdo)
if (b >= 306 && b <= 310) edit = true; // Cave (by Weirdo)
if (!edit)
return;
removeOldBlock(x, y, bl.FG, bl.arg3);
if (b != 0) {
if (Nblock[0, b] == null)
Nblock[0, b] = new Block();
Nblock[0, b].Set(x, y);
}
bl.FG = b;
bl.FGp = pl.Id;
bl.arg3 = 0;
bl.arg4 = 0;
bl.arg5 = 0;
#endregion
#endif
} else if (l == 1 && ((b >= 500 && b - 500 < (int)C.BLOCK_MAX) || b == 0)) {
#if INDEV
if (bl.BG >= 500)
if (Nblock[1, bl.BG - 500] != null)
Nblock[1, bl.BG - 500].Remove(x, y);
if (b >= 500) {
if (Nblock[1, b - 500] == null)
Nblock[1, b - 500] = new Block();
Nblock[1, b - 500].Set(x, y);
}
bl.BG = b;
bl.BGp = pl.Id;
#else
#region background
bool edit = false;
if (b == 0) edit = true;
if (b >= 500 && b <= 512) edit = true; // Basic (by Krock)
if (b >= 513 && b <= 519) edit = true; // Checker
if (b >= 520 && b <= 526) edit = true; // Dark
if (b >= 527 && b <= 532) edit = true; // Pastel
if (b >= 533 && b <= 538) edit = true; // Canvas
if (b >= 539 && b <= 540) edit = true; // Candy
if (b >= 541 && b <= 544) edit = true; // Halloween 2011
if (b >= 545 && b <= 549) edit = true; // Wallpaper (by Toop)
if (b >= 550 && b <= 555) edit = true; // Tile (by Minimania)
if (b >= 556 && b <= 558) edit = true; // Ice (by Toop)
if (b == 559) edit = true; // Gothic (by Toop)
if (b >= 560 && b <= 564) edit = true; // Fancy (by HG and Krock)
if (b >= 565 && b <= 568) edit = true; // Green (by HG and Krock)
if (b >= 569 && b <= 574) edit = true; // Stone (by HG)
if (b >= 575 && b <= 583) edit = true; // Hexagonal (by Stubby)
if (b == 584) edit = true; // Extra backgrounds (unknown)
if (b >= 585 && b <= 592) edit = true; // Evolution (by HG)
if (b >= 593 && b <= 597) edit = true; // Alien (by Anatoly)
if (b >= 598 && b <= 599) edit = true; // Mansion (by Shadowda)
if (b == 600) edit = true; // Black (by HG)
if (b >= 601 && b <= 608) edit = true; // Stripped (by Ravatroll)
if (!edit) return;
if (bl.BG != 0) {
if (Nblock[1, bl.BG - 500] != null)
Nblock[1, bl.BG - 500].Remove(x, y);
}
if (b != 0) {
if (Nblock[1, b - 500] == null)
Nblock[1, b - 500] = new Block();
Nblock[1, b - 500].Set(x, y);
}
bl.BG = b;
bl.BGp = pl.Id;
#endregion
#endif
} else return;
block_msg = Message.Create("b", l, x, y, b);
#endregion
} else if (b == 1000) {
#region Text
if (b == bl.FG || m.Count != 5 || l != 0)
return;
if (!pl.isModerator && !pl.isAdmin && !W_allowText)
return;
string text = m.GetString(4);
if (text.Length == 0 || string.IsNullOrWhiteSpace(text))
return;
if (text.Length > 150)
text = text.Remove(150);
#region Set modText string
int arg3 = -2,
free = -2;
// Fit empty slot
for (int i = 0; i < modText.Length; i++) {
if (!string.IsNullOrEmpty(modText[i])) {
if (modText[i] == text) {
// Found same text
arg3 = i;
break;
}
} else if (free < 0) {
free = i;
}
}
bool isLimit = false;
if (arg3 < 0) {
if (free < 0) {
if (modText.Length < 200) {
arg3 = modText.Length;
Array.Resize(ref modText, Math.Min(modText.Length + 50, 200));
modText[arg3] = text;
} else isLimit = true;
} else {
modText[free] = text;
arg3 = free;
}
}
#endregion
if (isLimit) {
if (pl.system_messages < sys_msg_max) {
pl.Send("write", SYS, "Fatal error: Reached text limit");
pl.system_messages++;
}
return;
}
removeOldBlock(x, y, bl.FG, bl.arg3);
int gid = BlockToSPId(b);
if (Nblock[gid, arg3] == null)
Nblock[gid, arg3] = new Block();
Nblock[gid, arg3].Set(x, y);
bl.FG = b;
bl.FGp = pl.Id;
bl.arg3 = (byte)arg3;
bl.arg4 = 0;
bl.arg5 = 0;
block_msg = Message.Create("lb", x, y, b, text);
#endregion
} else if (b == 43 || b == 77 /*|| b == 83*/) {
#region Coin doors, Music blocks
if (m.Count != 5 || l != 0)
return;
int arg3 = m.GetInt(4);
if (b == bl.FG && arg3 == bl.arg3)
return;
bool valid = (b == 43) ? pl.isAdmin : true;
if (arg3 < 0 || arg3 >= 100 || !valid)
return;
int bid = BlockToSPId(b);
removeOldBlock(x, y, bl.FG, bl.arg3);
if (Nblock[bid, arg3] == null)
Nblock[bid, arg3] = new Block();
Nblock[bid, arg3].Set(x, y);
bl.FG = b;
bl.FGp = pl.Id;
bl.arg3 = (byte)arg3;
block_msg = Message.Create((b == 43) ? "bc" : "bs", x, y, b, arg3);
#endregion
} else if (b == 242 && (pl.isAdmin || pl.isModerator)) {
#region Portals
if (m.Count != 7 || l != 0)
return;
int rotation = m.GetInt(4),
pId = m.GetInt(5),
pTarget = m.GetInt(6);
if (pId < 0 || pId >= 100 || pTarget < 0 || pTarget >= 100) return;
if (rotation >= 4)
rotation = 0;
if (countBlock(b) > 200) {
if (pl.system_messages < sys_msg_max) {
pl.Send("write", SYS, "Fatal error: Reached portal limit");
pl.system_messages++;
}
return;
}
removeOldBlock(x, y, bl.FG, bl.arg3);
if (PBlock[rotation, pId, pTarget] == null)
PBlock[rotation, pId, pTarget] = new Block();
PBlock[rotation, pId, pTarget].Set(x, y);
bl.FG = b;
bl.FGp = pl.Id;
bl.arg3 = (byte)rotation;
bl.arg4 = (byte)pId;
bl.arg5 = (byte)pTarget;
block_msg = Message.Create("pt", x, y, b, rotation, pId, pTarget);
#endregion
}
if (block_msg == null)
return;
blocks[x, y] = bl;
W_gotEdited = true;
W_Bcount++;
Message bot_msg = block_msg;
bot_msg.Add(pl.Id);
foreach (Player p in Players) {
if (p.isInited)
p.Send(p.isBot ? bot_msg : block_msg);
}
return;
}
#endregion
#region cb - Codeblock
if (m.Type == "cb" && !pl.isBot) {
if (!pl.canEdit && pl.moved > 0 && !pl.god_mode && !pl.mod_mode) {
if (getBlock(0, m.GetInt(0), m.GetInt(1)) == 103) {
pl.canEdit = true;
pl.Send("access");
}
}
return;
}
#endregion
#region cp - Checkpoint
if (m.Type == "cp" && !pl.isBot) {
int x = m.GetInt(0),
y = m.GetInt(1);
if ((pl.cPointX != x || pl.cPointY != y) && !pl.god_mode && !pl.mod_mode) {
if (getBlock(0, x, y) == 104) {
pl.cPointX = x;
pl.cPointY = y;
}
}
return;
}
#endregion
if (m.Type == "th" && !pl.isBot) {
if (!pl.god_mode && !pl.mod_mode && !pl.isDead && !kill_active) {
pl.isDead = true;
}
return;
}
#region complete - Trophy
if (m.Type == "complete") {
if (!pl.god_mode && !pl.mod_mode && !pl.levelComplete) {
if (getBlock(0, m.GetInt(0), m.GetInt(1)) == 106) {
pl.levelComplete = true;
Broadcast("write", SYS, pl.Name.ToUpper() + " completed this world!");
pl.Send("info", "Congratulations!", "You completed the world:\n" + W_title);
}
}
return;
}
#endregion
#region rcoins - Reset player's coins
if (m.Type == "rcoins") {
pl.coins = 0;
pl.cPointX = -1;
pl.cPointY = -1;
parseSpawns();
COOR c = get_next_spawn();
pl.posX = c.x * 16;
pl.posY = c.y * 16;
Broadcast("tele", true, pl.Id, pl.posX, pl.posY);
return;
}
#endregion
if (m.Type == "diamondtouch") {
if (m.Count >= 2 && !pl.god_mode && !pl.mod_mode && pl.Face != 31) {
if (getBlock(0, m.GetInt(0), m.GetInt(1)) == 241) {
if(!pl.isAway)
Broadcast("face", pl.Id, 31);
pl.isCrystalized = true;
}
}
return;
}
}
void GamePlayFunc(Player pl, Message m)
{
if (m.Type == "god" && pl.canEdit && m.Count == 1) {
if (!W_isOpen || pl.isAdmin || pl.isModerator) {
Broadcast("god", pl.Id, m.GetBoolean(0));
pl.god_mode = m.GetBoolean(0);
}
return;
}
if (m.Type == "mod") {
if (!hasAccess(pl, Rights.Moderator)) return;
pl.mod_mode = m.GetBoolean(0);
if (!pl.canEdit) {
pl.Send("access");
pl.canEdit = true;
}
Broadcast("mod", pl.Id);
return;
}
#region Change face
if (m.Type == (W_rot13 + "f")) {
if (pl.firstFace) {
pl.firstFace = false;
Broadcast("face", pl.Id, pl.Face);
return;
}
int f = m.GetInt(0);
if (f != pl.Face) {
#if INDEV
if(f >= 0){
#else
// Disallow unknown smilies
if (f >= 0 && f <= (int)C.SMILIES && f != (int)C.DIAMOND_SMILEY && f != (int)C.AWAY_SMILEY) {
#endif
Broadcast("face", pl.Id, f);
pl.Face = f;
}
}
return;
}
#endregion
if (m.Type == (W_rot13 + "k")) {
if (!pl.god_mode && !pl.mod_mode && !pl.isDead) {
W_crownC = true;
W_crown = pl.Id;
}
return;
}
#region c - Coin
if (m.Type == "c") {
if (W_isLoading || m.Count != 3) return;
if (getBlock(0, m.GetInt(1), m.GetInt(2)) != 100) {
pl.mWarns += 2;
return;
}
pl.coins = m.GetInt(0);
if (pl.coins < 0)
pl.coins = 0;
pl.gotCoin = true;
return;
}
#endregion
#region Keys
for (byte i = 0; i < key_colors.Length; i++) {
if (m.Type == W_rot13 + key_colors[i][0]) {
if (keys[i] == 0) {
keys[i] = 1;
Broadcast("hide", key_colors[i]);