forked from tinyspeck/glitch-GameServerJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
7738 lines (6176 loc) · 208 KB
/
main.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
log.info("Starting main...");
//
// the main dispatch handler
//
function processMessage(pc, msg){
//log.info("TYPE="+msg.type);
processMessageInner(pc, msg);
pc.performPostProcessing(msg);
}
function processMessageInner(pc, msg){
switch (msg.type){
case 'move_vec': return doVecMove(pc, msg);
case 'move_xy': return doXYMove(pc, msg);
case 'login_start': return doLoginStart(pc, msg, false);
case 'login_end': return doLoginEnd(pc, msg, false);
case 'relogin_start': return doLoginStart(pc, msg, true);
case 'relogin_end': return doLoginEnd(pc, msg, true);
case 'location_passthrough': return doLocationPassthrough(pc, msg);
case 'signpost_move_start': return doStartSignpostMove(pc, msg);
case 'signpost_move_end': return doEndSignpostMove(pc, msg);
case 'follow_move_end': return doEndMove(pc, msg, 'pc_follow_move');
case 'door_move_start': return doStartDoorMove(pc, msg);
case 'door_move_end': return doEndDoorMove(pc, msg);
case 'afk': return doAFK(pc, msg);
case 'local_chat': return doLocalChat(pc, msg);
case 'local_chat_start': return doLocalChatStart(pc, msg);
case 'itemstack_verb': return doVerb(pc, msg);
case 'itemstack_verb_menu': return doItemstackVerbMenu(pc, msg);
case 'itemstack_menu_up': return doMenuUp(pc, msg);
case 'itemstack_mouse_over': return doMouseOver(pc, msg);
case 'itemstack_verb_cancel': return doVerbCancel(pc, msg);
case 'itemstack_inspect': return doInspectItem(pc, msg);
case 'itemstack_modify': return doModifyItem(pc, msg);
case 'itemstack_create': if (pc.is_god) return doCreateItem(pc, msg);
case 'itemstack_status': return doStatusItem(pc, msg);
case 'itemstack_invoke': return doItemstackInvoke(pc, msg);
case 'itemstack_sync': return doSync(pc, msg);
case 'get_item_defs': return doGetItemDefs(pc, msg);
case 'get_item_asset': return doGetItemAsset(pc, msg);
case 'get_item_placement': return doGetItemPlacement(pc, msg);
case 'edit_location': if (pc.is_god) return doReplaceGeometry(pc, msg);
case 'im_send': return doSendIM(pc, msg);
case 'location_lock_request': return doLocationLock(pc, msg);
case 'location_lock_release': return doLocationUnlock(pc, msg);
case 'conversation_choice': return doConversationChoice(pc, msg);
case 'conversation_cancel': return doConversationCancel(pc, msg);
case 'teleport_move_end': return doEndTeleportMove(pc, msg);
case 'note_close': return doNoteClose(pc, msg);
case 'buddy_add': return doBuddyAdd(pc, msg);
case 'buddy_remove': return doBuddyRemove(pc, msg);
case 'ping': return doPing(pc, msg);
case 'follow_start': return doStartFollow(pc, msg);
case 'follow_end': return doStopFollow(pc, msg);
case 'make_known': return doMakeKnown(pc, msg);
case 'make_unknown': return doMakeUnknown(pc, msg);
case 'recipe_request': return doRecipeRequest(pc, msg);
case 'store_buy': return doStoreBuy(pc, msg);
case 'store_sell': return doStoreSell(pc, msg);
case 'store_sell_check': return doStoreSellCheck(pc, msg);
case 'overlay_dismissed': return doOverlayDismissed(pc, msg);
case 'overlay_done': return doOverlayDone(pc, msg);
case 'overlay_click': return doOverlayClick(pc, msg);
case 'screen_view_close': return doScreenViewClose(pc, msg);
case 'close_img_menu': return doScreenViewClose(pc, msg);
case 'inventory_move': return doInventoryMove(pc, msg);
case 'location_move': return doLocationMove(pc, msg);
case 'location_drag_targets': return doLocationDragTargets(pc, msg);
case 'inventory_drag_targets': return doInventoryDragTargets(pc, msg);
case 'echo_annc': return doEchoAnnc(pc, msg);
case 'play_music': return doPlayMusic(pc, msg);
case 'groups_chat_join': return doGroupsChatJoin(pc, msg);
case 'groups_chat_leave': return doGroupsChatLeave(pc, msg);
case 'groups_chat': return doGroupsChat(pc, msg);
case 'prompt_choice': return doPromptChoice(pc, msg);
case 'trade_start': return doStartTrade(pc, msg);
case 'trade_cancel': return doCancelTrade(pc, msg);
case 'trade_add_item': return doTradeAddItem(pc, msg);
case 'trade_remove_item': return doTradeRemoveItem(pc, msg);
case 'trade_change_item': return doTradeChangeItem(pc, msg);
case 'trade_currants': return doTradeCurrants(pc, msg);
case 'trade_accept': return doTradeAccept(pc, msg);
case 'trade_unlock': return doTradeUnlock(pc, msg);
case 'skills_can_learn': return doSkillsCanLearn(pc, msg);
case 'skill_unlearn_cancel': return doUnlearnCancel(pc, msg);
case 'action_request_reply': return doActionRequestReply(pc, msg);
case 'action_request_cancel': return doActionRequestCancel(pc, msg);
case 'action_request_broadcast': return doActionRequestBroadcast(pc, msg);
case 'teleportation_set': return doTeleportationSet(pc, msg);
case 'teleportation_go': return doTeleportationGo(pc, msg);
case 'teleportation_map': return doTeleportationMap(pc, msg);
case 'pc_verb_menu': return doPcVerbMenu(pc, msg);
case 'pc_menu': return doPCMenu(pc, msg);
case 'emote': return doEmote(pc, msg);
case 'quest_begin': return doQuestBegin(pc, msg);
case 'quest_conversation_choice': return doQuestConversationChoice(pc, msg);
case 'quest_dialog_closed': return doQuestDialogEnd(pc, msg);
case 'shrine_spend': return doShrineSpend(pc, msg);
case 'emblem_spend': return doEmblemSpend(pc, msg);
case 'shrine_favor_request': return doShrineFavorRequest(pc, msg);
case 'favor_request': return doFavorRequest(pc, msg);
case 'job_apply_work': if (pc.is_god) return doJobApplyWork(pc, msg);
case 'job_contribute_item': return doJobContributeItem(pc, msg);
case 'job_contribute_currants': return doJobContributeCurrants(pc, msg);
case 'job_contribute_work': return doJobContributeWork(pc, msg);
case 'job_stop_work': return doJobStopWork(pc, msg);
case 'job_leaderboard': return doJobLeaderboard(pc, msg);
case 'job_status': return doJobStatus(pc, msg);
case 'job_claim': return doJobClaim(pc, msg);
case 'input_response': return doInputResponse(pc, msg);
case 'note_save': return doInputResponse(pc, msg);
case 'teleportation_script_create': return doInputResponse(pc, msg);
case 'teleportation_script_use': return doTPScriptUse(pc, msg);
case 'teleportation_script_imbue': return doTPScriptImbue(pc, msg);
case 'map_get': return doMapGet(pc, msg);
case 'get_path_to_location': return doMapGetPath(pc, msg);
case 'clear_location_path': return doMapClearPath(pc, msg);
case 'set_prefs': return doSetPrefs(pc, msg);
case 'garden_action': return doGardenAction(pc, msg);
// Notice board feature
case 'notice_board_action': return doNoticeBoardAction(pc, msg);
// Mail messages
case 'mail_send': return doMailSend(pc, msg);
case 'mail_receive': return doMailReceive(pc, msg);
case 'mail_read': return doMailRead(pc, msg);
case 'mail_delete': return doMailDelete(pc, msg);
case 'mail_archive': return doMailArchive(pc, msg);
case 'mail_cancel': return doMailCancel(pc, msg);
case 'mail_cost': return doMailCost(pc, msg);
case 'mail_check': return doMailCheck(pc, msg);
// camera mode notices form client
case 'camera_mode_started': return doCameraModeStarted(pc, msg);
case 'camera_mode_ended': return doCameraModeEnded(pc, msg);
// Parties
case 'party_invite': return doPartyInvite(pc, msg);
case 'party_chat': return doPartyChat(pc, msg);
case 'party_leave': return doPartyLeave(pc, msg);
case 'party_space_response': return doPartySpaceInviteResponse(pc, msg);
case 'party_space_join': return doPartySpaceJoin(pc, msg);
//
// House ACLs
//
case 'acl_key_info': return doAclKeyInfo(pc, msg);
case 'acl_key_change': return doAclKeyChange(pc, msg);
//
// god-only messages
//
case 'admin_loc_request': if (pc.is_god || pc.is_help) return doAdminLocRequest(pc, msg);
case 'admin_teleport': if (pc.is_god || pc.is_help) return doAdminTeleport(pc, msg);
case 'perf_teleport': return doPerfTeleport(pc, msg);
case 'guide_status_change': return doGuideStatusChange(pc, msg);
// games
case 'splash_screen_button_payload': return doSplashScreenButtonPayload(pc, msg);
case 'new_item_window_closed': return doNewItemWindowClosed(pc, msg);
// houses
case 'houses_add_neighbor': return doAddNeighbor(pc, msg);
case 'houses_remove_neighbor': return doRemoveNeighbor(pc, msg);
case 'houses_expand_costs': return doHousesExpandCosts(pc, msg);
case 'houses_expand_wall': return doHousesExpandWall(pc, msg);
case 'houses_expand_yard': return doHousesExpandYard(pc, msg);
case 'houses_expand_tower': return doHousesExpandTower(pc, msg);
case 'houses_unexpand_wall': return doHousesUnexpandWall(pc, msg);
case 'houses_style_choices': return doHousesStyleChoices(pc, msg);
case 'houses_style_switch': return doHousesStyleSwitch(pc, msg);
case 'houses_wall_choices': return doHousesWallChoices(pc, msg);
case 'houses_wall_set': return doHousesWallSet(pc, msg);
case 'houses_wall_buy': return doHousesWallBuy(pc, msg);
case 'houses_wall_preview': return doHousesWallPreview(pc, msg);
case 'houses_floor_choices': return doHousesFloorChoices(pc, msg);
case 'houses_floor_set': return doHousesFloorSet(pc, msg);
case 'houses_floor_buy': return doHousesFloorBuy(pc, msg);
case 'houses_floor_preview': return doHousesFloorPreview(pc, msg);
case 'houses_ceiling_choices': return doHousesCeilingChoices(pc, msg);
case 'houses_ceiling_set': return doHousesCeilingSet(pc, msg);
case 'houses_ceiling_buy': return doHousesCeilingBuy(pc, msg);
case 'houses_ceiling_preview': return doHousesCeilingPreview(pc, msg);
/* deprecated */ case 'houses_deco_mode': return doNoEnergyMode(pc, msg);
case 'no_energy_mode': return doNoEnergyMode(pc, msg);
case 'tower_set_name': return doTowerSetName(pc, msg);
case 'tower_set_floor_name': return doTowerSetFloorName(pc, msg);
case 'houses_set_name': return doHousesSetName(pc, msg);
case 'houses_visit': return doHousesVisit(pc, msg);
case 'houses_signpost': return doHousesSignpost(pc, msg);
case 'furniture_drop': return doFurnitureDrop(pc, msg);
case 'furniture_move': return doFurnitureMove(pc, msg);
case 'furniture_pickup': return doFurniturePickup(pc, msg);
case 'furniture_upgrade_purchase': return doFurnitureUpgradePurchase(pc, msg);
case 'furniture_set_zeds': return doFurnitureSetZeds(pc, msg);
case 'furniture_set_user_config': return doFurnitureSetUserConfig(pc, msg);
case 'itemstack_set_user_config': return doItemstackSetUserConfig(pc, msg);
case 'resnap_minimap': return doResnapMiniMap(pc, msg);
case 'cultivation_start': return doCultivationStart(pc, msg);
case 'cultivation_purchase': return doCultivationPurchase(pc, msg);
// imagination
case 'imagination_purchase': return doImaginationPurchase(pc, msg);
case 'imagination_purchase_confirmed': return doImaginationPurchaseConfirmed(pc, msg);
case 'imagination_shuffle': return doImaginationShuffle(pc, msg);
case 'nudgery_start': return doNudgeryStart(pc, msg);
case 'itemstack_nudge': return doItemstackNudge(pc, msg);
case 'contact_list_opened': return doContactListOpened(pc, msg);
case 'cultivation_mode_ended': return doCultivationModeEnded(pc, msg);
case 'item_discovery_dialog_closed': return itemDiscoveryDialogClosed(pc, msg);
case 'snap_travel': return doSnapTravel(pc, msg);
case 'snap_travel_forget': return doSnapTravelForget(pc, msg);
case 'avatar_get_choices': return doAvatarGetChoices(pc, msg);
case 'share_track': return doShareButton(pc, msg);
case 'craftybot_add': return doCraftybotMessage(pc, msg);
case 'craftybot_remove': return doCraftybotMessage(pc, msg);
case 'craftybot_cost': return doCraftybotMessage(pc, msg);
case 'craftybot_pause': return doCraftybotMessage(pc, msg);
case 'craftybot_lock': return doCraftybotMessage(pc, msg);
case 'craftybot_refuel': return doCraftybotMessage(pc, msg);
case 'hi_emote_missile_hit': return doHiEmoteMissileHit(pc, msg);
case 'get_hi_emote_leaderboard': return doGetHiEmoteLeaderboard(pc, msg);
}
log.info(pc.tsid+' '+msg);
var rsp = make_rsp(msg);
rsp.success = false;
if (msg.type){
rsp.msg = 'unrecognized msg type: '+msg.type;
}else{
rsp.msg = 'unspecified msg type';
}
pc.apiSendMsg(rsp);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function stat_format(s){
return {
value: s.value,
max: s.top
};
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doLoginStart(pc, msg, isRelogin){
//log.info('***LOGIN-START-'+pc.tsid+'-1');
pc.didStartStreetMove();
var rsp = make_rsp(msg);
rsp.success = true;
apiLogAction('LOGIN_START', 'pc='+pc.tsid, 'loc='+pc.location.tsid, 'played='+pc.getTimePlayed());
if (isRelogin){
rsp.relogin_type = msg.relogin_type;
// simulate moving into location
pc.location.apiMoveIn(pc, pc.x, pc.y);
// Call the player's java code to make end of the move arrangements
pc.apiEndLocationMove(pc.location);
}else{
//
// Let's make sure the player is in a good place
//
var below = pc.location.apiGetPointOnTheClosestPlatformLineBelow(pc.x, pc.y-1);
if (!below){
var above = pc.location.apiGetPointOnTheClosestPlatformLineAbove(pc.x, pc.y);
if (above){
pc.apiSetXY(above.x, above.y);
}
else{
log.error(pc+" is in a bad place, but can't be fixed");
}
}
//
// sounds file, if defined
//
if (config.sounds_url){
rsp.sounds_file = config.sounds_url;
rsp.ambient_library = {
'default': [
config.music_map['FOREST_AMBIENT1'],
config.music_map['FOREST_AMBIENT2'],
config.music_map['FOREST_AMBIENT3'],
config.music_map['FOREST_AMBIENT4']
],
'caverns': [
config.music_map['AMBIENT_CAVERNS1'],
config.music_map['AMBIENT_CAVERNS2'],
config.music_map['AMBIENT_CAVERNS3'],
config.music_map['AMBIENT_CAVERNS4']
],
'uralia': [
config.music_map['AMBIENT_URALIA1'],
config.music_map['AMBIENT_URALIA2'],
config.music_map['AMBIENT_URALIA3'],
config.music_map['AMBIENT_URALIA4']
],
'firebog': [
config.music_map['AMBIENT_FIREBOGS1'],
config.music_map['AMBIENT_FIREBOGS2'],
config.music_map['AMBIENT_FIREBOGS3'],
config.music_map['AMBIENT_FIREBOGS4'],
config.music_map['AMBIENT_FIREBOGS5'],
config.music_map['AMBIENT_FIREBOGS6'],
config.music_map['AMBIENT_FIREBOGS7']
],
'savanna': [
config.music_map['AMBIENT_SAVANNA1'],
config.music_map['AMBIENT_SAVANNA2'],
config.music_map['AMBIENT_SAVANNA3'],
config.music_map['AMBIENT_SAVANNA4'],
config.music_map['AMBIENT_SAVANNA5'],
config.music_map['AMBIENT_SAVANNA6']
],
'highlands': [
config.music_map['AMBIENT_HIGHLANDS1'],
config.music_map['AMBIENT_HIGHLANDS2'],
config.music_map['AMBIENT_HIGHLANDS3'],
config.music_map['AMBIENT_HIGHLANDS4'],
config.music_map['AMBIENT_HIGHLANDS5'],
config.music_map['AMBIENT_HIGHLANDS6'],
config.music_map['AMBIENT_HIGHLANDS7']
],
'cave': [
config.music_map['CAVE_MUSIC1'],
config.music_map['CAVE_MUSIC2'],
config.music_map['CAVE_MUSIC3'],
config.music_map['CAVE_MUSIC4'],
config.music_map['CAVE_MUSIC5']
],
'ix': [
config.music_map['AMBIENT_IX_1'],
config.music_map['AMBIENT_IX_2'],
config.music_map['AMBIENT_IX_3'],
config.music_map['AMBIENT_IX_4'],
config.music_map['AMBIENT_IX_5'],
config.music_map['AMBIENT_IX_6'],
config.music_map['AMBIENT_IX_7'],
config.music_map['AMBIENT_IX_8'],
config.music_map['AMBIENT_IX_9'],
config.music_map['AMBIENT_IX_10'],
config.music_map['AMBIENT_IX_11'],
config.music_map['AMBIENT_IX_12'],
config.music_map['AMBIENT_IX_13'],
config.music_map['AMBIENT_IX_14'],
config.music_map['AMBIENT_IX_15'],
config.music_map['AMBIENT_IX_16'],
config.music_map['AMBIENT_IX_17'],
config.music_map['AMBIENT_IX_18']
],
'andra_kajuu': [
config.music_map['ANDRA_KAJUU_1'],
config.music_map['ANDRA_KAJUU_2'],
config.music_map['ANDRA_KAJUU_3'],
config.music_map['ANDRA_KAJUU_4'],
config.music_map['ANDRA_KAJUU_5'],
config.music_map['ANDRA_KAJUU_6'],
config.music_map['ANDRA_KAJUU_7'],
config.music_map['ANDRA_KAJUU_8'],
config.music_map['ANDRA_KAJUU_9'],
config.music_map['ANDRA_KAJUU_10'],
config.music_map['ANDRA_KAJUU_11'],
config.music_map['ANDRA_KAJUU_12'],
config.music_map['ANDRA_KAJUU_13'],
config.music_map['ANDRA_KAJUU_14'],
config.music_map['ANDRA_KAJUU_15']
],
'kloro_haoma': [
config.music_map['AMBIENT_KLORO_HAOMA1']
],
'urwok': [
config.music_map['AMBIENT_URWOK1'],
config.music_map['AMBIENT_URWOK2'],
config.music_map['AMBIENT_URWOK3'],
config.music_map['AMBIENT_URWOK4'],
config.music_map['AMBIENT_URWOK5'],
config.music_map['AMBIENT_URWOK6'],
config.music_map['AMBIENT_URWOK7'],
config.music_map['AMBIENT_URWOK8']
],
'jal': [
config.music_map['JAL1'],
config.music_map['JAL2']
],
'nottis': [
config.music_map['WINTER_HUB1'],
config.music_map['WINTER_HUB2'],
config.music_map['WINTER_HUB3'],
config.music_map['WINTER_HUB4'],
config.music_map['WINTER_HUB5']
],
'bortola_muufo': [
config.music_map['AMBIENT_FOREST_SLOW1'],
config.music_map['AMBIENT_FOREST_SLOW2'],
config.music_map['AMBIENT_FOREST_SLOW3'],
config.music_map['AMBIENT_FOREST_SLOW4']
],
'hell': [
config.music_map['HELL']
]
};
// these map hub ids to records in the ambient_library above
rsp.ambient_hub_map = {
'78': 'caverns', // Ilmenskie Deeps
'50': 'caverns', // Ilmenskie Caverns
'18': 'caverns', // obaix on dev, for testing
'51': 'uralia', // Uralia
'40': 'hell',
'63': 'firebog',
'71': 'firebog',
'72': 'firebog',
'77': 'firebog',
'99': 'firebog',
'86': 'savanna',
'95': 'savanna',
'90': 'savanna',
'91': 'savanna',
'76': 'highlands',
'93': 'highlands',
'109': 'highlands',
'114': 'highlands',
'107': 'cave',
'106': 'cave',
'85': 'andra_kajuu',
'89': 'andra_kajuu',
'113': 'andra_kajuu',
'119': 'andra_kajuu',
'102': 'andra_kajuu', // actually Ormonos, yay!
'105': 'andra_kajuu', // actually Lida, yay!
'27': 'ix',
'133': 'kloro_haoma', // actually Kloro, yay!
'131': 'kloro_haoma', // actually Haoma, yay!
'126': 'urwok', // actually Roobrik, yay!
'128': 'urwok', // actually Balzare, yay!
'136': 'jal',
'140': 'jal', // actually Samudra, yay!
'137': 'nottis',
'141': 'nottis', // actually Drifa, yay!
'75': 'bortola_muufo', // actually bortola, yay!
'97': 'bortola_muufo', // actually yay!
'112': 'bortola_muufo', // actually brillah yay!
'116': 'bortola_muufo', // actually haraiva yay!
'88': 'bortola_muufo', // karnata
'110': 'cave' // massadoe
};
}
//
// map data
//
rsp.world_map_url = overlay_key_to_url('world_map');
//
// basic info about the player
//
rsp.pc = pc.make_hash_with_location();
//
// misc stuff
//
rsp.pc.role = 'peon';
if (pc.is_help) rsp.pc.role = 'help';
if (pc.is_god) rsp.pc.role = 'god';
if (pc.is_guide){
rsp.pc.role = 'guide';
rsp.pc.guide_on_duty = pc.guide_on_duty ? true : false;
}
rsp.prefs = pc.getPrefs();
//
// stats & metabolics
//
rsp.pc.stats = {};
pc.stats_get_login(rsp.pc.stats);
pc.metabolics_get_login(rsp.pc.stats);
//
// contents of the pc's bags
//
rsp.pc.itemstacks = make_bag(pc);
var furniture_bag = pc.furniture_get_bag();
if (furniture_bag){
var contents = furniture_bag.getContents();
for (var n in contents){
var it = contents[n];
if (it){
rsp.pc.itemstacks[it.tsid] = make_item(it);
}
}
}
//
// quests, buffs & familiar
//
rsp.quests = pc.quests_get_status();
rsp.buffs = pc.buffs_get_active();
rsp.familiar = pc.familiar_get_login();
rsp.groups = pc.groups_get_login();
if (!pc.live_help_group || (!in_array_real(pc.live_help_group, config.live_help_groups) && !in_array_real(pc.live_help_group, config.newbie_live_help_groups)) || time() - pc.date_last_loggedin >= 3600){
if (pc.stats_get_level() < 11){
pc.live_help_group = choose_one(config.newbie_live_help_groups);
}
else{
pc.live_help_group = choose_one(config.live_help_groups);
}
}
rsp.live_help_group = pc.live_help_group;
if (!pc.global_chat_group || !in_array_real(pc.global_chat_group, config.global_chat_groups) || time() - pc.date_last_loggedin >= 3600) pc.global_chat_group = choose_one(config.global_chat_groups);
rsp.global_chat_group = pc.global_chat_group;
if (pc.canJoinTradeChat()){
if (!pc.trade_chat_group || !in_array_real(pc.trade_chat_group, config.trade_chat_groups) || time() - pc.date_last_loggedin >= 3600) pc.trade_chat_group = choose_one(config.trade_chat_groups);
rsp.trade_chat_group = pc.trade_chat_group;
}
rsp.prompts = pc.prompts_get_login();
rsp.pc.hi_emote_variant = pc.hi_emote_variant;
rsp.pc.escrow_tsid = pc.trading.storage_tsid;
rsp.pc.rewards_bag_tsid = pc.rewards.storage_tsid;
rsp.pc.mail_bag_tsid = pc.mail.storage_tsid;
rsp.pc.trophy_storage_tsid = pc.trophies_find_container().tsid;
rsp.pc.auction_storage_tsid = pc.auctions_find_container().tsid;
rsp.pc.furniture_bag_tsid = pc.furniture.storage_tsid;
rsp.pc.needs_account = (pc.quickstart_needs_account && pc.location.class_tsid != 'newxp_intro' && pc.location.class_tsid != 'newxp_training1') ? true : false;
rsp.acl_key_count = pc.acl_keys_count_received();
rsp.pol_info = pc.houses_get_login();
rsp.home_info = pc.houses_get_login_new();
rsp.overlay_urls = config.overlays_map;
rsp.newxp_locations = config.newxp_locations;
var hi_variants_tracker = apiFindObject(config.hi_variants_tracker);
var hi_variants_login_data = {};
if (hi_variants_tracker) hi_variants_login_data = hi_variants_tracker.get_login_data();
var infector_pc = (hi_variants_login_data.yesterdays_top_infector_tsid) ? apiFindObject(hi_variants_login_data.yesterdays_top_infector_tsid) : null;
rsp.hi_emote_data = {
hi_emote_variants: config.hi_emote_variants,
hi_emote_variants_color_map: config.hi_emote_variants_color_map,
hi_emote_variants_name_map: config.hi_emote_variants_name_map,
hi_emote_leaderboard: hi_variants_login_data.leaderboard,
yesterdays_variant_winner: hi_variants_login_data.yesterdays_winner,
yesterdays_variant_winner_count: hi_variants_login_data.yesterdays_winner_count,
yesterdays_top_infector_tsid: hi_variants_login_data.yesterdays_top_infector_tsid,
yesterdays_top_infector_count: hi_variants_login_data.yesterdays_top_infector_count,
yesterdays_top_infector_variant: hi_variants_login_data.yesterdays_top_infector_variant,
yesterdays_top_infector_pc: (infector_pc && infector_pc.is_player) ? infector_pc.make_hash() : null,
};
/* we used to send only a subset, but it is not too much data to just send it all, and we can use it in client
var client_overlay_keys = ['tower_sign_scaffolding_overlay', 'fox_brush', 'proto_puff', 'smoke_puff', 'world_map', 'neuron_burst', 'rook_attack_test', 'rook_attack_fx_test', 'rook_fly_side', 'rook_fly_up', 'rook_fly_up_flv', 'rook_flock', 'rook_fly_forward', 'rook_familiar', 'sonic_boom', 'rook_fly_up_fractal_flv'];
for (var i=0;i<client_overlay_keys.length;i++) {
var o = client_overlay_keys[i];
rsp.overlay_urls[o] = overlay_key_to_url(o);
}
*/
var path_data = pc.getPathRsp();
if (path_data){
rsp.path_info = path_data;
}
rsp.camera_abilities = pc.getCameraAbilities();
}
//log.info('***LOGIN-START-'+pc.tsid+'-2');
rsp.location = pc.location.prep_geometry(pc);
// Rewrite the world map url
if (rsp.overlay_urls && rsp.location.mapData && rsp.location.mapData.world_map) rsp.overlay_urls['world_map'] = rsp.location.mapData.world_map;
//log.info('***LOGIN-START-'+pc.tsid+'-3');
//
// send item definitions for all items
//
// this is a horrible hack and is temporary!
// a special 'item' called 'catalog' contains an array of class_tsids
//
var catalog = apiFindItemPrototype('catalog');
var tsids = catalog.class_tsids;
// do not send these in rsp
var skip_props = config.itemDef_skip_props;
// send these props only if their value is not the default value specified
var default_values = config.itemDef_default_values;
// send this to client so it can apply the default values
rsp.default_item_values = default_values;
rsp.items = {};
for (var n in tsids){
var tsid = tsids[n];
try {
var itemProto = apiFindItemPrototype(tsid);
rsp.items[tsid] = utils.copy_hash(itemProto.itemDef);
rsp.items[tsid].has_infopage = itemProto.has_infopage;
if (itemProto.proxy_item) rsp.items[tsid].proxy_item = itemProto.proxy_item;
for (var i in default_values){
if (rsp.items[tsid][i] == default_values[i]) {
delete rsp.items[tsid][i];
}
}
for (var i in skip_props){
delete rsp.items[tsid][i];
}
if (itemProto.getSubClasses) rsp.items[tsid].subclasses = itemProto.getSubClasses();
if (itemProto.is_routable) rsp.items[tsid].is_routable = true;
} catch (e){
//rsp.items[tsid] = {};
log.error("can't find prototype for "+tsid+" from catalog during login_start");
}
}
// Invoking sets catalog
catalog = apiFindItemPrototype('catalog_invoking_sets');
rsp.invoking = {
sets: catalog.sets,
blockers: {
items: {
'furniture_chassis': {
width: 740
},
'home_sign': {
width: 116
},
'magic_rock': {
width: 116
},
'patch_seedling': {
width: 286
},
'wood_tree': {
width: 286
},
'trant_bean': {
width: 286
},
'trant_spice': {
width: 286
},
'trant_bubble': {
width: 286
},
'trant_egg': {
width: 286
},
'trant_fruit': {
width: 286
},
'trant_gas': {
width: 286
},
'trant_bean_dead': {
width: 286
},
'trant_spice_dead': {
width: 286
},
'trant_bubble_dead': {
width: 286
},
'trant_egg_dead': {
width: 286
},
'trant_fruit_dead': {
width: 286
},
'trant_gas_dead': {
width: 286
}
},
signpost: {
width: 260
}
}
};
// Deco sets catalog
catalog = apiFindItemPrototype('catalog_userdeco_sets');
rsp.userdeco = {
sets: catalog.sets
};
// Recipe catalog
catalog = apiFindItemPrototype('catalog_recipes');
rsp.recipes = {};
for (var rid in catalog.recipes){
if (catalog.recipes[rid].learnt == 3) continue;
var r = get_recipe(rid); // get_recipe sets some other stuff up for us, so let's call it
// Copy the recipe so we don't modify the catalog
r = utils.copy_hash(r);
r.id = rid; // We need recipe id too
// Discoverable?
if (r.learnt == 0) r.discoverable = 1;
// Get the tool that makes this recipe
var tool = apiFindItemPrototype(r.tool);
// Change task_limit based on potential upgrades
var task_limit_multiplier = pc.get_task_limit_multiplier(tool);
if (task_limit_multiplier != 1.0){
r.task_limit = Math.round(r.task_limit * task_limit_multiplier);
}
// Do we know this recipe?
if (!pc.recipes.recipes[rid]){
// We implicitly know all transmogrification recipes
if (!tool || tool.getClassProp('making_type') != 'transmogrification'){
r.learnt = 0;
}
else if (rid == 288 && isPiDay()) {
// we implicitly know the pi recipe
r.learnt = 0;
}
}
else if (r.discoverable){
r.learnt = 1;
}
// Explain if we can make this thing, and why we can't if we can't
if (r.learnt){
r.disabled = false;
if (r.skills){
for (var s in r.skills){
if (!pc.skills_has(r.skills[s])){
r.disabled = true;
r.disabled_reason = "You need to learn the "+pc.skills_linkify(r.skills[s])+" skill.";
break;
}
}
}
if (r.achievements){
for (var a in r.achievements){
if (!pc.achievements_has(r.achievements[a])){
r.disabled = true;
r.disabled_reason = "You need to get the "+pc.achievements_linkify(r.achievements[a])+" achievement.";
break;
}
}
}
}
rsp.recipes[rid] = r;
}
//log.info('***LOGIN-START-'+pc.tsid+'-4');
//
// the player's buddylists
//
rsp.buddies = pc.buddies_get_login();
rsp.ignoring = pc.buddies_get_ignoring_login();
//log.info('***LOGIN-START-'+pc.tsid+'-5');
//
// in a party?
//
var m = pc.party_members();
if (m){
rsp.party = {
members: m,
};
}
//log.info('***LOGIN-START-'+pc.tsid+'-6');
//
// Loading info
//
rsp.loading_info = pc.location.getLoadingInfo(pc);
//
// Skill urls
//
rsp.skill_urls = pc.skills_get_urls();
//log.info('***LOGIN-START-'+pc.tsid+'-7');
//
// send it
//
pc.apiSendMsgAsIs(rsp);
//
// Perf testing
//
if (msg.perf_testing && msg.perf_testing == true){
if (!pc.after_perf_test_location){
pc.after_perf_test_location = {
tsid: pc.location.tsid,
x: pc.x,
y: pc.y
};
}
delete pc.halt_perf_test;
}
else if (pc.after_perf_test_location){
pc.halt_perf_test = true;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doLoginEnd(pc, msg, isRelogin){
pc.didEndStreetMove();
var rsp = make_rsp(msg);
rsp.success = true;
apiLogAction('LOGIN_END', 'pc='+pc.tsid);
//
// location info
//
rsp.location = {};
rsp.location.tsid = pc.location.tsid;
rsp.location.pcs = {};
rsp.location.itemstacks = {};
//
// active players in location
//
for (var i in pc.location.activePlayers){
var p = pc.location.activePlayers[i];
if (p.tsid != pc.tsid || isRelogin){// we want to send all pcs data on relogin_end
rsp.location.pcs[p.tsid] = p.make_hash_with_location();
}
}
//
// itemstacks in location
//
for (var i in pc.location.items){
var item = pc.location.items[i];
if (item && item.isVisibleTo(pc)) {
rsp.location.itemstacks[item.tsid] = make_item(item, pc);
}
}
if (isRelogin){
rsp.relogin_type = msg.relogin_type;
}
//
// teleportation
//
rsp.teleportation = pc.teleportation_get_status();
rsp.previous_location = pc.houses_get_previous_location_client();
rsp.is_dead = pc.is_dead;
delete pc['!teleporting'];
//
// send it
//
pc.apiSendMsgAsIs(rsp);
//
// Are we allowed to login?
//
if (pc.isInTimeout()){
rsp = {
type:"booted",
msg: "Your account has been suspended.",
url: "/"
};
return pc.apiSendMsg(rsp);
}
//
// send message to other people in location
//
var notification = {