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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#
#---------------------------------------------------------------------
##@package ChPlayer
# @todo: Íæ¼Ò·â°üÂß¼­´¦Àí
#
# @author: eggxp
# @date 2010-3-31
# @version 4.2
#
# @note: 
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
#"""Version = 2017-06-22 15:00""" 
#---------------------------------------------------------------------
import GameWorld
import IPY_GameServer
import PlayerTeam
import ChConfig
import PlayerControl
import PlayerFamily
import PlayerEventCounter
import PlayerFriend
import GMCommon
import ShareDefine
#import PlayerFamilyTech
import time
import ChPyNetSendPack
import NetPackCommon
import GameDataRecord
import UpdatePlayerName
import GameWorldBoss
import PlayerFamilyBoss
import PlayerBourse
import PlayerZhuXianBoss
import PlayerXMZZ
import PlayerTruck
import PlayerHorsePetBoss
import PlayerCompensation
import PlayerFamilyRedPacket
#import PlayerFamilyStore
import PlayerSocial
import PlayerFamilyParty
#import PlayerSealDemon
import PlayerBillboard
import PlayerLVAward
import PlayerDuJie
import PlayerFamilySWRH
import IpyGameDataPY
import PlayerTalk
import PlayerGeTui
import PlayerStore
import GameWorldActionControl
import GameWorldFamilyWar
import PlayerFBHelpBattle
import GameWorldSkyTower
import GMT_CTG
import PyGameData
import GMShell
import IPY_PlayerDefine
import GameWorldArena
import CrossLuckyCloudBuy
import CrossRealmPK
import AuctionHouse
import PlayerAssist
import PlayerFB
import PlayerLove
import PlayerCharm
import CrossRealmPlayer
import CrossBattlefield
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
 
def DoRefreshMainServerRole(curPlayer):
    ## Ë¢Ð±¾·þ½ÇÉ«ÐÅÏ¢
    
    curTeam = curPlayer.GetTeam()
    if curTeam:
        PlayerTeam.Sync_TeamMemberInfo(curTeam)
    return
 
## Íæ¼ÒµÇ¼³õʼ»¯(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks µÇ½˳Ðò, PlayerLogin->PlayerLoadMapState(PlayerLoginLoadMapOK), ´Ë´¦Î´ÉèÖóõʼ»¯×´Ì¬
def PlayerLogin(index, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    try:
        __Func_PlayerLogin(curPlayer, tick)
    except:
        curPlayer.Kick(IPY_PlayerDefine.disWaitForPlayerLoinError)
        import traceback
        GameWorld.RaiseException("Íæ¼ÒÉÏÏßÂß¼­´íÎó\r\n%s" % traceback.format_exc())
    return
 
#---------------------------------------------------------------------
## Íæ¼ÒµÇ¼³õʼ»¯(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks µÇ½˳Ðò, PlayerLogin->PlayerLoadMapState(PlayerLoginLoadMapOK), ´Ë´¦Î´ÉèÖóõʼ»¯×´Ì¬
def __Func_PlayerLogin(curPlayer, tick):
    
    GameWorld.Log("__Func_PlayerLogin mapID=%s" % curPlayer.GetMapID(), curPlayer.GetPlayerID())
    curPlayer.SetDict(ChConfig.Def_PDict_LoginMapID, curPlayer.GetMapID())
    #Íæ¼ÒÔÚÏßʱ¼ä³õʼ»¯
    InitPlayerOnLineTime(curPlayer, tick)
    #Íæ¼ÒÏìÓ¦ÐÅÏ¢³õʼ»¯
    InitPlayerOnLineReply(curPlayer, tick)
    # Í³¼ÆµÇÈëÈËÊý
    GameDataRecord.PlayerLoginRecord(curPlayer, tick)
    __DoPlayerLoginServer(curPlayer, tick)
    
    #֪ͨµØÍ¼·þÎñÆ÷×Ô¼º³õʼ»¯³É¹¦
    curPlayer.MapServer_InitOK()
    return
 
def __DoPlayerLoginServer(curPlayer, tick):
    ''' Íæ¼ÒµÇ¼ÐèÒª´¦ÀíµÄÄÚÈÝ£¬±¾·þ¼°¿ç·þ·þÎñÆ÷·Ö¿ª
    '''
    if GameWorld.IsCrossServer():
        #¿ç·þPK
        CrossRealmPK.OnPlayerLoginCrossServer(curPlayer)
        #ЭÖú
        PlayerAssist.OnPlayerLoginCrossServer(curPlayer)
        return
    
    #Íæ¼Ò¼Ò×åË¢ÐÂ
    #¼Ò×åÈÎÎñÐèҪˢРFamilyLV, µØÍ¼·þÎñÆ÷ÐèÒªÖªµÀFamilyLVÀ´Í¨ÖªÍæ¼Ò¼Ò×åÈÎÎñ´ÎÊý 
    PlayerFamily.PlayerLoginRefreshFamily(curPlayer, tick)
    #Íæ¼Ò¶ÓÎé³õʼ»¯
    PlayerTeam.OnPlayerLoginRefreshTeam(curPlayer, tick)
    PlayerCompensation.NotifyPlayerCompensation(curPlayer)
    __UpdOnedayJobPlayerLoginoffTime(curPlayer)
    CrossRealmPlayer.OnPlayerLogin(curPlayer)
    
    if not PlayerControl.GetIsTJG(curPlayer):
        # Ö»ÓÐ֪ͨÂß¼­µÄÓ¦¸Ã·Å´Ë´¦¼õÉÙIO£¬ÈçÓÐÂß¼­´¦Àí´æ´¢µÈ²»¿É·ÅÔÚ´Ë´¦
        #ºÃÓÑÐÅϢˢÐÂ
        PlayerFriend.OnPlayerLogin(curPlayer, tick)
        
        #Í¨ÖªÍæ¼ÒµÇ½ÐÅÏ¢£¬À´×ÔÔËÓª·½
        #DoLogic_LoginUserData(curPlayer)
    
        #֪ͨ¿ª·þÌìÊý, µÇ¼ʱ¸ÄΪµØÍ¼Í¨Öª£¬ÒòΪGameServerµÄPlayerLoginÔÚµØÍ¼Ö®ºó£¬Ç°¶ËÓÐЩ¹¦ÄÜ´¦ÀíÐèÒªÌáǰµÃµ½¿ª·þÌì
        #PlayerEventCounter.Sync_OpenServerDay(curPlayer)
        # Í¨Öª¹ã²¥ÐÅÏ¢
        GMCommon.SendBroadCastToClient(curPlayer)
    
        PlayerTruck.SyncPlayerTruckStartTime(curPlayer)
        #Í¨ÖªÍæ¼Ò½»Ò×Ëù¹Òµ¥Çé¿ö
        PlayerBourse.OnPlayerLogin(curPlayer)
        #ÅÄÂôÐÐ
        AuctionHouse.OnPlayerLogin(curPlayer)
        
        #ÉÏÏ߹㲥
        __CheckWorldNotifyOnLogin(curPlayer, tick)
        
        #ÏÉÃ˺ì°ü
        PlayerFamilyRedPacket.OnPlayerLogin(curPlayer)
        #ÏÉÃ˲ֿâ
        #PlayerFamilyStore.OnPlayerLogin(curPlayer)
        #ÏÉÃËÑç»á
        PlayerFamilyParty.OnPlayerLogin(curPlayer)
        #·âħ̳
        #PlayerSealDemon.OnPlayerLogin(curPlayer)
        #ÏÉħ֮Õù
        PlayerXMZZ.OnXMZZOnLogin(curPlayer)
        #µÈ¼¶½±Àø
        PlayerLVAward.OnPlayerLogin(curPlayer)
        #É̵깺Âò´ÎÊý
        PlayerStore.OnPlayerLogin(curPlayer)
        #֪ͨÊÀ½çbossÐÅÏ¢
        GameWorldBoss.OnPlayerLogin(curPlayer)
        #¶É½Ù
        PlayerDuJie.OnPlayerLogin(curPlayer)
        #ÊØÎÀÈË»Ê
        PlayerFamilySWRH.OnLogin(curPlayer)
        PlayerTalk.LoginChatMi(curPlayer)
        PlayerTalk.NotifyTalkCache(curPlayer)
        #PlayerGeTui.CleanNewGuyCallBackGeTui(curPlayer.GetID())
        #»î¶¯
        GameWorldActionControl.OnPlayerLogin(curPlayer)
        #Íæ¼ÒµÈ¼¶¼Ç¼
        PyGameData.g_todayPlayerLVDict[curPlayer.GetID()] = curPlayer.GetLV()
        #¾º¼¼³¡
        GameWorldArena.OnPlayerLogin(curPlayer)
        #¿ç·þPK
        CrossRealmPK.OnPlayerLogin(curPlayer)
        #ÐÒÔËÔÆ¹º
        CrossLuckyCloudBuy.OnPlayerLogin(curPlayer)
        #ÖïÏÉBOSS
        PlayerZhuXianBoss.OnPlayerLogin(curPlayer)
        #Æï³èboss״̬֪ͨ
        PlayerHorsePetBoss.OnLogin(curPlayer)
        #ЭÖú
        PlayerAssist.OnPlayerLogin(curPlayer)
        #ÌìÐÇËþ
        GameWorldSkyTower.OnPlayerLogin(curPlayer)
        GMT_CTG.OnPlayerLogin(curPlayer)
        
    else:
        pass
        
    return
 
def DoPlayerRealLoginOK(curPlayer, loginMsg, tick):
    ''' Íæ¼Ò×îÖյǼ³É¹¦´¦Àí£¬ ÓÉ  MapServer  DoPlayerRealLoginOK  Í¨Öª
        ¸Ãº¯ÊýΪµØÍ¼×îÖյǼ³É¹¦²Å»áÖ´Ðе½£¬ÒÔºóһЩ¹¦ÄÜÀàµÄµÇ¼´¦Àí½¨Òé¾ùдµ½ÕâÀï
        ¾ÉµÄ¹¦ÄÜÏȲ»¶¯( __DoPlayerLoginServer º¯ÊýÖеŦÄÜ)£¬Èç¹ûÓеǼÏà¹ØµÄbugÔÙ¿¼ÂÇÊÇ·ñÒÆ¶¯µ½´Ëº¯Êý
    '''
    isMixServerFirstLogin = loginMsg[0]
    GameWorld.Log("GameServer->DoPlayerRealLoginOK, isMixServerFirstLogin=%s" % isMixServerFirstLogin, curPlayer.GetPlayerID())
    
    if GameWorld.IsCrossServer():
        return
    
    PyGameData.g_dbPlayerIDMap[curPlayer.GetPlayerID()] = curPlayer.GetAccID()
    
    if not PlayerControl.GetIsTJG(curPlayer):
        #¼Ò×帱±¾boss״̬֪ͨ
        PlayerFamilyBoss.OnLogin(curPlayer)
        #÷ÈÁ¦
        PlayerCharm.OnPlayerLogin(curPlayer)
        #ÇéÔµ
        PlayerLove.OnPlayerLogin(curPlayer)
        #¿ç·þÕ½³¡
        CrossBattlefield.OnPlayerLogin(curPlayer)
        
    if isMixServerFirstLogin:
        PlayerCharm.OnMixServerFirstLogin(curPlayer)
        
    return
 
def __UpdOnedayJobPlayerLoginoffTime(curPlayer):
    ## ¸üÐÂÒ»ÌìÄÚÖ°Òµ¶ÔÓ¦Íæ¼ÒµÇ¼¡¢ÀëÏßʱ¼ä
    job = curPlayer.GetJob()
    playerID = curPlayer.GetPlayerID()
    if job not in PyGameData.g_onedayJobPlayerLoginoffTimeDict:
        PyGameData.g_onedayJobPlayerLoginoffTimeDict[job] = {}
    playerLoginoffTimeDict = PyGameData.g_onedayJobPlayerLoginoffTimeDict[job]
    playerLoginoffTimeDict[playerID] = int(time.time())
    #GameWorld.DebugLog("¸üÐÂÖ°Òµ¶ÔÓ¦Íæ¼ÒµÇ¼ÀëÏßʱ¼ä: %s" % PyGameData.g_onedayJobPlayerLoginoffTimeDict)
    return
 
def CheckOnedayJobPlayerLoginoffTimeout():
    ## ¼ì²éÒ»ÌìÄÚÖ°Òµ¶ÔÓ¦Íæ¼ÒµÇ¼¡¢ÀëÏßʱ¼ä³¬Ê±Íæ¼Ò£¬Ã¿Ð¡Ê±¼ì²éÒ»´Î
    
    maxTime = 24 * 3600 # Ôݶ¨24Сʱ
    curTime = int(time.time())
    #GameWorld.DebugLog("´¦Àí24СʱÄÚÔÚÏߵĽÇÉ«Ö°ÒµÍæ¼Ò: curTime=%s,maxTime=%s, %s" % (curTime, maxTime, PyGameData.g_onedayJobPlayerLoginoffTimeDict))
    
    playerManager = GameWorld.GetPlayerManager()
    for playerDict in PyGameData.g_onedayJobPlayerLoginoffTimeDict.values():
        for playerID, loginoffTime in playerDict.items():
            if playerManager.FindPlayerByID(playerID):
                #GameWorld.DebugLog("    ÔÚÏß²»´¦Àí, playerID=%s" % playerID)
                continue
            if curTime - loginoffTime > maxTime:
                playerDict.pop(playerID)
                #GameWorld.DebugLog("    ³¬Ê±Íæ¼Ò£¬ÒƳý! playerID=%s,loginoffTime=%s" % (playerID, loginoffTime))
    #GameWorld.DebugLog("    ´¦ÀíÍê±Ï£¬Ê£ÓàÍæ¼Ò! %s" % PyGameData.g_onedayJobPlayerLoginoffTimeDict)
    return
 
## Ôö¼Ó¸ßÊÖÍæ¼ÒÉÏÏ߹㲥
#  @param curPlayer
#  @return None
def __CheckWorldNotifyOnLogin(curPlayer, tick):
    # ¿ç·þ·þÎñÆ÷²»¹ã²¥
    if GameWorld.IsCrossServer():
        return
    
    limitLV = IpyGameDataPY.GetFuncCfg("BillBoardPlayerLoginNotify", 2) # ×îµÍµÈ¼¶ÏÞÖÆ
    
    if curPlayer.GetLV() < limitLV:
        return
    
    notifyCD = IpyGameDataPY.GetFuncCfg("BillBoardPlayerLoginNotify", 3)
    LogoffTime = GetPlayerLeaveServerSecond(curPlayer)
    if LogoffTime and LogoffTime < notifyCD:
        #¾àÀëÉÏ´ÎÀëÏßµÄʱ¼äCD
        return
     
    notifyCheckList = IpyGameDataPY.GetFuncEvalCfg("BillBoardPlayerLoginNotify")
    msgMark = ""
    for checkMark, notifyDict in notifyCheckList:
        
        # ÅÅÐаñÀàÐÍ
        if isinstance(checkMark, int):
            if checkMark not in ShareDefine.BillboardTypeList:
                continue
            
            billboard = GameWorld.GetBillboard().FindBillboard(checkMark)
            if not billboard:
                continue
            
            billboardCnt = billboard.GetCount()
            maxOrder = max(notifyDict)
            for index in range(0, maxOrder):
                if index < 0 or index >= billboardCnt:
                    continue
                
                order = index + 1
                
                if order not in notifyDict:
                    continue
                
                objBillboard = billboard.At(index)
                if curPlayer.GetID() == objBillboard.GetID():
                    msgMark = notifyDict[order]
                    break           
        
        # ÓпÉÒԹ㲥µÄ£¬ÂíÉϹ㲥£¬Í˳ö£¬²»ÔÙ¼ì²é
        if msgMark:
            PlayerControl.WorldNotify(0, msgMark, [curPlayer.GetName()])
            break
    
    return
 
##»ñµÃÍæ¼Òµ±Ç°ÀۼƵÄÀëÏßÃëÊý
# @param curPlayer Íæ¼ÒʵÀý
# @return ÀۼƵÄÃëÊý
# @remarks ¿Í»§¶Ë·â°üÏìÓ¦
def GetPlayerLeaveServerSecond(curPlayer):
    #µ±Ç°ÀëÏßʱ¼ä×Ö·û´«
    logoffTimeStr = curPlayer.GetLogoffTime()
 
    if logoffTimeStr == "" or logoffTimeStr == '0':
        return 0
 
    logoffTime = GameWorld.GetDateTimeByStr(logoffTimeStr)
    loginTime = GameWorld.GetDateTimeByStr(GameWorld.GetCurrentDataTimeStr())
 
    diff_Time = loginTime - logoffTime
    #ÌìÊý * 24Сʱ * 60 ·ÖÖÓ + Ãë
    return diff_Time.days * 24 * 60 * 60 + diff_Time.seconds
 
## ÔËÓªµÇ½ÐÅÏ¢´¦Àí
#  @param curPlayer
#  @return None
def DoLogic_LoginUserData(curPlayer):
    curPlayerUserData = GameWorld.GetUserData(curPlayer)
    if not curPlayerUserData:
        return
    
    #Õ˺ż¤»î½±Àø
    ActivateAccountAward(curPlayer, curPlayerUserData)
    
    SyncOPPlayerLoginInfo(curPlayer, curPlayerUserData)
    #NotifyGameWallowInfo
    return
 
 
## ¸ù¾Ýkey»ñÈ¡Óû§ÐÅÏ¢
#  @param curPlayer
#  @param key
#  @param default
#  @return
def GetUserDataByKey(curPlayer, key, default=None):
    playerUserDataStr = curPlayer.GetUserData()
    
    if not playerUserDataStr:
        return default
    
    try:
        curPlayerUserData = eval(playerUserDataStr)
    except:
        GameWorld.ErrLog("data error UserData = %s"%curPlayerUserData )
        return default
    
    if not isinstance(curPlayerUserData, dict):
        GameWorld.ErrLog("type error UserData = %s"%curPlayerUserData )
        return default
    
    return curPlayerUserData.get(key, default)
 
# Ñ¸À×ÐÅÏ¢
#curPlayerUserData={'username': 'alee', 
#'cm': '1', 'agent': 'xunlei', 'goldlevel': '2', 'viplevel': '3', 
#'serverid': '1', 'isvip': '1', 'clienttype': '1', 'isgoldvip': '1', 'paytype': '1', 
#'token': '6fb3a97df0bb3c142593a11a95a1688b', 'time': '1393575021', 'viptype': '2'}
 
 
## Í¨ÖªMAPƽ̨µÇ½ÐÅÏ¢
#  @param curPlayer
#  @return µÇ½ÐÅÏ¢×Ö·û´®
def SyncOPPlayerLoginInfo(curPlayer, userDict):
    if userDict.get('agent', "") == "xunlei":
        isvip = int(userDict.get('isvip', 0))
        curPlayer.SetDict("XunLeiVIP", isvip)
        #ѸÀ×Óû§£¬Ñ¸À×VIP£¬VIPµÈ¼¶£¬½ð¿¨VIP£¬½ð¿¨µÈ¼¶, µÇ¼¿Í»§¶ËÀàÐÍ
        result = ['xunlei', isvip, int(userDict.get('viplevel', 0)), int(userDict.get('isgoldvip', 0)), 
                  int(userDict.get('goldlevel', 0)), int(userDict.get('clienttype', 0))]
    else:
        result = [int(userDict.get('clienttype', 0)), userDict.get('channel_code', ""),]
        
    pid = GameWorld.ToIntDef(userDict.get('pid', "0"))
    curPlayer.SetDict(ChConfig.Def_PlayerKey_PlayerFromPID, pid)
    
    platform = userDict.get('pf', "")
    if not platform:
        platform = userDict.get('platform', "")
        
    account_type = GameWorld.ToIntDef(userDict.get('qidtype', "0"))
    
    result.extend([pid, platform, account_type])
        
    # µ± pf Îª qzone¡¢pengyou¡¢qplus Ê±£¬·¢ËÍ»Æ×êÐÅÏ¢
    if platform in ["qzone", "pengyou", "qplus"]:
        result.extend([int(userDict.get('is_yellow', 0)), int(userDict.get('is_year_yellow', 0)), 
                       int(userDict.get('is_high_yellow', 0)), int(userDict.get('yellow_level', 0))])
        
    # µ± pf Îª qqgame¡¢3366 Ê±£¬·¢ËÍÀ¶×êÐÅÏ¢
    elif platform in ["qqgame", "3366"]:
        result.extend([int(userDict.get('is_blue', 0)), int(userDict.get('is_year_blue', 0)), 
                       int(userDict.get('is_high_blue', 0)), int(userDict.get('blue_level', 0))])
        
    result = str(result)
    curPlayer.MapServer_QueryPlayerResult(0, 0, "LoginData", result, len(result))
    return
 
    
## Õ˺ż¤»î½±Àø
#  @param Userdict
#  @return None
def ActivateAccountAward(curPlayer, userDict):
    if not userDict.has_key("activateType"):
        return
    
    msg = str(userDict["activateType"])
    
    curPlayer.MapServer_QueryPlayerResult(0, 0, 'ActivateAward', msg, len(msg))
 
    
## Í¨ÖªÍæ¼Ò·À³ÁÃÔÐÅÏ¢
#  @param curPlayer: Íæ¼ÒʵÀý
#  @return: None
def NotifyGameWallowInfo(curPlayer):
    
    return
    playerUserDataStr = curPlayer.GetUserData()
    
    if not playerUserDataStr:
        return
    
    curPlayerUserData = eval(playerUserDataStr)
 
    GameWorld.Log("type=%s, curPlayerUserData=%s"%(type(curPlayerUserData), curPlayerUserData))
    #º«¹ú°æÓÐcurPlayerUserDataÊý¾Ý
    if not curPlayerUserData:
        GameWorld.Log("not curPlayerUserData=%s"%curPlayerUserData )
        return
    
    try:
        curPlayerAge = int(curPlayerUserData["data"]["result"]["age"])  #ÄêÁä
        endTime = curPlayerUserData["data"]["result"]["endtime"]    #½áÊøÊ±¼ä
    except BaseException:
        GameWorld.ErrLog("curPlayerAge or endTime ##Error!" )
        return
 
    #ÏÖÔÚʱ¼ä
    #curPlayerAge = 15 #ÄêÁä
    #endTime = ""    #½áÊøÊ±¼ä
 
    if not curPlayerAge:
        GameWorld.ErrLog("curPlayerAge:%s not ##Error!"%curPlayerAge )
        return
 
    if endTime:
        if not GameWorld.GetDateTimeByStr(endTime):
            GameWorld.ErrLog("endTime:%s Format ##Error!"%endTime )
            return
        endTime = int(time.mktime(time.strptime(endTime,"%Y-%m-%d %H:%M:%S"))) 
    else:
        endTime = 0
    
#    packData = ChPyNetSendPack.tagInfoGameWallow()
#    packData.Clear()
#    packData.Age = curPlayerAge
#    packData.EndTime = endTime
#    GameWorld.Log("Í¨ÖªÍæ¼Ò·À³ÁÃÔÐÅÏ¢,packData.Age=%s ,packData.EndTime=%s"%(packData.Age,packData.EndTime))
#    NetPackCommon.SendFakePack(curPlayer, packData)
    
    return
 
## ·¢ËÍÇëÇóÖÁÄ¿±êµØÍ¼(ÈÎÎñÐèÒªµÇ½¼Ò×峤´¥·¢Ê¼þ)
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __RefreshFamilyToMapServer(curPlayer):
    curFamily = curPlayer.GetFamily()
    
    if not curFamily:
        #Íæ¼ÒÎÞ¼Ò×å
        return
    
    playerID = curPlayer.GetPlayerID()
    curMember = curFamily.FindMember(playerID)
    
    if not curMember:
        GameWorld.ErrLog("ˢмÒ×åÊôÐÔʧ°Ü, ¼Ò×å³ÉÔ±²éÕÒÒì³£ = %s"%(playerID))
        return
    
    tagMapID = GameWorld.GetQueryPlayerMapID(curPlayer)
    
    if not tagMapID:
        GameWorld.ErrLog("ˢмÒ×åÊôÐÔʧ°Ü, ¼Ò×å³ÉÔ±²éÕÒÒì³£ tagMapID = %s"%(tagMapID))
        return
    
    sendCMD = "0"
    
    if curMember.GetFamilyLV() == IPY_GameServer.fmlLeader:
        sendCMD = "1"
    
    queryCallName = "Refresh_Family_Info"
    
    #֪ͨMapServer½á¹û´¦Àí
    GameWorld.GetPlayerManager().MapServer_QueryPlayer(playerID, ChConfig.queryType_sqtRefresh_Family_Info, 
                    playerID, tagMapID, queryCallName, sendCMD, len(sendCMD), curPlayer.GetRouteServerIndex())
    return
    
 
## Íæ¼ÒÔÚÏßʱ¼ä³õʼ»¯ 
#  @param curPlayer  µ±Ç°Íæ¼Ò 
#  @param tick µ±Ç°Ê±¼ä 
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def InitPlayerOnLineTime(curPlayer, tick):
    curPlayer.SetLoginTick(tick)
    return
 
## Íæ¼ÒÏìÓ¦ÐÅÏ¢³õʼ»¯ 
#  @param curPlayer  µ±Ç°Íæ¼Ò 
#  @param tick µ±Ç°Ê±¼ä 
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def InitPlayerOnLineReply(curPlayer, tick):
    curPlayer.SetOnlineReplyErrorCount(0)
    curPlayer.SetOnlineReplyTick(0)
    return
 
## Íæ¼ÒÏÂÏß(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def PlayerDisconnect(index, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    try:
        __Func_PlayerDisconnect(curPlayer, tick)
    except:
        import traceback
        GameWorld.RaiseException("Íæ¼ÒÏÂÏßÂß¼­´íÎó\r\n%s" % traceback.format_exc())
    #µ÷ÓõײãÏÂÏß
    curPlayer.DoDisconnect()
    return
 
## Íæ¼ÒÏÂÏß(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __Func_PlayerDisconnect(curPlayer, tick):
    
    if GameWorld.IsCrossServer():
        PlayerFB.OnPlayerDisconnectCrossServer(curPlayer)
        
    #¿ç·þÆ¥ÅäPK
    CrossRealmPK.OnLeaveServer(curPlayer)
    
    #×é¶ÓÍæ¼ÒÀëÏß
    PlayerTeam.DoPlayerLogOffTeamLogic(curPlayer, tick)
    #¼Ò×åÍæ¼ÒÀëÏß
    PlayerFamily.PlayerLogoffRefreshFamily(curPlayer, tick)
    PlayerFriend.OnPlayerDisconnect(curPlayer, tick)
    
    __UpdOnedayJobPlayerLoginoffTime(curPlayer)
    #PlayerGeTui.NewGuyCallBackGeTui(curPlayer, tick)
    # ÉèÖüÒ×å³ÉÔ±ÀëÏßʱ¼ä
    SetPlayerOfflineTime(curPlayer)
    #ÅÄÂôÐÐ
    AuctionHouse.OnPlayerLeaveServer(curPlayer)
    #ЭÖú
    PlayerAssist.OnLeaveServer(curPlayer)
    #ºì°ü
    PlayerFamilyRedPacket.OnLeaveServer(curPlayer)
    #------------ïÚ³µÂß¼­
    #TruckPlayerDisconnectProcess(curPlayer, tick)
    
    if not PlayerControl.GetIsTJG(curPlayer):
        playerID = curPlayer.GetPlayerID()
        PyGameData.g_unTJLogoffTime[playerID] = int(time.time())
        
    return
 
## ÉèÖÃÍæ¼ÒÀëÏßʱ¼ä
#  @param curPlayer  µ±Ç°Íæ¼Ò 
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def SetPlayerOfflineTime(curPlayer):
    #if PlayerControl.GetIsTJG(curPlayer):
    #    return
    
    curPlayerID = curPlayer.GetPlayerID()
    curFamily = curPlayer.GetFamily()
    if not curFamily:
        return
    curMember = curFamily.FindMember(curPlayerID)
    curTimeStr = GameWorld.GetCurrentDataTimeStr()
    curTimeTuple = time.strptime(curTimeStr, ChConfig.TYPE_Time_Format)
    curTimeNum = int(time.mktime(curTimeTuple))
 
    curMember.SetExattr2(curTimeNum)
 
## ïÚ³µÂß¼­(²ÎÊý -> µ±Ç°Íæ¼Ò,µ±Ç°Ê±¼ä)
#  @param curPlayer  µ±Ç°Íæ¼Ò 
#  @param tick µ±Ç°Ê±¼ä 
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def TruckPlayerDisconnectProcess(curPlayer, tick):
#    #ïÚ³µ¹ÜÀíÆ÷
#    truckMananger = GameWorld.GetTruckMananger()
#    curPlayerTruck = truckMananger.FindTruckByOwner(curPlayer.GetPlayerID())
#    #¸ÃÍæ¼ÒÎÞïÚ³µ
#    if curPlayerTruck == None :
#        return
#    #ÉèÖüÆËãïÚ³µÏûʧʱ¼ä
#    curPlayerTruck.SetLogoffTick(tick)
    return
 
## Ë¢ÐÂÍæ¼ÒÃû×Ö(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def RefreshName(index, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerNamePack = IPY_GameServer.IPY_GRefreshPlayerName()
    curPlayer.SetName(playerNamePack.GetName())
    return
 
## Ë¢ÐÂ״̬(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def RefreshState(index, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    if curPlayer == None:
        GameWorld.Log("RefreshState, index = %d, player = None"%(index))
        return
    
    playerStatePack = IPY_GameServer.IPY_GRefreshPlayerProperty()
    packValue = playerStatePack.GetValue()
    packValueEx = playerStatePack.GetValueEx()
    packType = playerStatePack.GetType()
    
    #---ÌØÊâÂß¼­´¦Àí---
    if packType == ShareDefine.CDBPlayerRefresh_ForbidenTalk:
        PlayerControl.SetGMForbidenTalk(curPlayer, packValue)
        return
    
    if packType == ShareDefine.CDBPlayerRefresh_ExAttr17:
        PlayerControl.SetPlayerAccState(curPlayer, packValue)
        return
 
    if packType == IPY_GameServer.CDBPlayerRefresh_State:
        # ÍÑ»úÔÚÏß
        PlayerControl.SetIsTJG(curPlayer, packValue)
        return
    if packType == IPY_GameServer.CDBPlayerRefresh_HappyPoint:
        # ÍÑ»úʱ¼ä
        PlayerControl.SetTJGTime(curPlayer, packValue)
        return
    
    if packType == IPY_GameServer.CDBPlayerRefresh_FamilyActiveValue:
        #¼Ò×å»îÔ¾¶ÈË¢ÐÂ
        PlayerFamily.ReFreshPlayerFamilyActiveValue(curPlayer, packValue)
        return
    
    if packType == IPY_GameServer.CDBPlayerRefresh_FightPower:
        curPlayer.SetFightPower(packValue, packValueEx)
        return
 
    if packType == IPY_GameServer.CDBPlayerRefresh_ExAttr2:
        #¶ÓÎéÏà¹ØÏà¹ØÉóºË¿ª¹Ø×´Ì¬
        PlayerTeam.SetTeamCheckState(curPlayer, packValue)
        return
    
    #if packType == IPY_GameServer.CDBPlayerRefresh_ExAttr1:
    #    PlayerControl.SetAssistTagPlayerID(curPlayer, packValue)
    #    return
    
    if packType == IPY_GameServer.CDBPlayerRefresh_ExAttr3:
        PlayerControl.SetFBFuncLineID(curPlayer, packValue)
        return
    
    #---³£¹æÂß¼­´¦Àí---
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_LV:
        curPlayer.SetLV(packValue)
        PlayerSocial.UpdateSocialInfo(curPlayer.GetID(), packType, packValue)
        #Íæ¼ÒµÈ¼¶¼Ç¼
        playerID = curPlayer.GetID()
        if playerID in PyGameData.g_todayPlayerLVDict:
            PyGameData.g_todayPlayerLVDict[playerID] = packValue
 
    elif packType == IPY_GameServer.CDBPlayerRefresh_Job:
        curPlayer.SetJob(packValue)
        
#    elif packType == IPY_GameServer.CDBPlayerRefresh_CurrentPlayerType:
#        #ÕâÀïÓ¦¸Ã֪ͨ×é¶ÓÄDZßË¢ÐÂ
#        curPlayer.SetCurrentProperty(packValue)
#        __RefreshTeamState(curPlayer)
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_MapID:
        #Íæ¼ÒÇл»µØÍ¼
        curPlayer.SetMapID(packValue)
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_RealMapID:
        #Íæ¼ÒµÄÕæÊµµØÍ¼ID
        curPlayer.SetRealMapID(packValue)
        OnPlayerChangeRealMap(curPlayer, tick)
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_FBID:
        curPlayer.SetFBID(packValue)
    
    elif packType == IPY_GameServer.CDBPlayerRefresh_VIPLv:
        curPlayer.SetVIPLv(packValue);
#        __RefreshTeamState(curPlayer)
    
    elif packType == IPY_GameServer.CDBPlayerRefresh_ExAttr5:
        PlayerControl.SetCrossMapID(curPlayer, packValue, False)
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_ExAttr9:
        PlayerControl.SetVIPExpireTime(curPlayer, packValue)
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_ExAttr10:
        PlayerControl.SetChatBubbleBox(curPlayer, packValue)
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_ExAttr13:
        PlayerControl.SetPlayerServerGroupID(curPlayer, packValue)
        
    elif packType == IPY_GameServer.CDBPlayerRefresh_OperateInfo:
        curPlayer.SetOperateInfo(packValue);
    
    elif packType == IPY_GameServer.CDBPlayerRefresh_OfficialRank:
        curPlayer.SetOfficialRank(packValue)
        PlayerSocial.UpdateSocialInfo(curPlayer.GetID(), packType, packValue)
        #¸üÐÂÅÅÐаñµÄ¾³½ç
        PlayerBillboard.UpdateBillboardRealm(curPlayer)
        
    #×é¶Ó³ÉԱˢÐÂ
    PlayerTeam.PlayerTeamMemberRefresh(curPlayer, packType, packValue, tick)
    #¼Ò×åË¢ÐÂ
    PlayerFamily.PlayerRefresh(curPlayer, tick)
    #¸±±¾ÖúÕ½
    PlayerFBHelpBattle.UpdateCheckInPlayerInfoByRefresh(curPlayer, packType, packValue)
    return
 
## Íæ¼ÒÇл»µØÍ¼µÄÏìÓ¦(²ÎÊý -> µ±Ç°Íæ¼Ò,µ±Ç°Ê±¼ä)
#  @param curPlayer  µ±Ç°Íæ¼Ò 
#  @param tick µ±Ç°Ê±¼ä 
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def OnPlayerChangeMap(curPlayer, tick):
    #δ³õʼ»¯³É¹¦²»´¦Àí
    if not curPlayer.GetInitOK():
        #GameWorld.ErrLog("Çл»µØÍ¼, Íæ¼Ò³õʼ»¯²»³É¹¦£¬²»Ö´ÐÐÏà¹ØÂß¼­", curPlayer.GetPlayerID())
        return
    
    GameWorld.Log("Íæ¼Ò : %s,%s,FBID=%s Çл»µØÍ¼" % (curPlayer.GetName(), curPlayer.GetRealMapID(), curPlayer.GetFBID()) , curPlayer.GetPlayerID())
    PlayerTeam.OnPlayerChangeMap(curPlayer, tick)
    GameWorldBoss.OnPlayerChangeMap(curPlayer)
    PlayerFamily.OnPlayerChangeMap(curPlayer, tick)
    PlayerFamilyParty.OnPlayerChangeMap(curPlayer, tick)
    GameWorldFamilyWar.OnPlayerChangeMap(curPlayer)
    return 
 
## Íæ¼ÒÇл»ÕæÊµµØÍ¼
#  @param curPlayer  µ±Ç°Íæ¼Ò 
#  @param tick µ±Ç°Ê±¼ä 
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def OnPlayerChangeRealMap(curPlayer , tick):
#===============================================================================
#    Çл»µØÍ¼·â°üʱÐò
#    CDBPlayerRefresh_MapID
#    CDBPlayerRefresh_FBID
#    CDBPlayerRefresh_RealMapID
#===============================================================================
    #¿ªÊ¼µØÍ¼³õʼ»¯¶¯×÷
    OnPlayerChangeMap(curPlayer, tick)
    return
 
## ¼ì²éÍæ¼ÒÏìӦʱ¼ä(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return True
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def PlayerOnlineReply(index, tick):
    #Ŀǰ×öµ½RouteServerÖÐÈ¥ÁË
#    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
#    
#    curPlayer.Sync_OnlineReplyAnswer()
#    if curPlayer.GetOnlineReplyTick() == 0:
#        curPlayer.SetOnlineReplyTick(tick)
#        return
#    
#    #ÏìӦʱ¼ä¼ì²â(5ÃëÕý³£¼Ç¼,10ÃëÌßÏÂÏß,10´Î´íÎóÌßÏÂÏß)
#    playerOnlineReplayTime = abs( tick - curPlayer.GetOnlineReplyTick() - ChConfig.Def_PlayerOnLineReply_ClientReply)
#    #²»ÁôÇé,Ö±½ÓÌß
#    if playerOnlineReplayTime >= ChConfig.Def_PlayerOnLineReply_MaxTick:
#        GameWorld.Log("ÏìÓ¦´íÎó,ʱ¼ä³¬¹ý%s,ÌßÏÂÏß"%(ChConfig.Def_PlayerOnLineReply_MaxTick))
#        curPlayer.Kick(IPY_GameServer.disTimeError)
#        return True
#    #¼Ç¼
#    elif playerOnlineReplayTime >= ChConfig.Def_PlayerOnLineReply_NoteTick:
#        curPlayer.SetOnlineReplyErrorCount( curPlayer.GetOnlineReplyErrorCount() + 1 )
#        GameWorld.Log("ÏìÓ¦´íÎó,Òѱ»¼Ç¼,µ±Ç°´ÎÊý%s"%(curPlayer.GetOnlineReplyErrorCount()))
#    #¼ì²é´íÎó´ÎÊý,Ö±½ÓÌß
#    if curPlayer.GetOnlineReplyErrorCount() >= ChConfig.Def_PlayerOnLineReply_ErrorCount:
#        GameWorld.Log("ÏìÓ¦´íÎó,´íÎó´ÎÊý³¬¹ý%s,ÌßÏÂÏß"%(ChConfig.Def_PlayerOnLineReply_ErrorCount))
#        curPlayer.Kick(IPY_GameServer.disTimeError)
#        return True
#    #ÉèÖõ±Ç°Ê±¼ä
#    curPlayer.SetOnlineReplyTick(tick)
    
    return True
 
#//////////////////////////////////////////////////////////////
#//01 03 Íæ¼ÒµÇ¼µØÍ¼³õʼ»¯#tagGPlayerLoadMap
#tagGPlayerLoadMap       *   GettagGPlayerLoadMap();
#
#class   IPY_GPlayerLoadMap
#{
#public:
#    //0: ¿ªÊ¼¶ÁÈ¡ 1: ¶ÁÈ¡³É¹¦
#    int      GetLoadState();
#};
 
## Íæ¼ÒµÚÒ»´Î½øÈëÓÎÏ·³õʼ»¯(²ÎÊý -> µ±Ç°Íæ¼Ò,µ±Ç°Ê±¼ä)
#  @param curPlayer  µ±Ç°Íæ¼Ò 
#  @param tick µ±Ç°Ê±¼ä 
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def PlayerLoginLoadMapOK(curPlayer, tick):
    #ÔÚÍæ¼Ò·¢À´·â°ü, µØÍ¼¶ÁÈ¡³É¹¦ºó´¥·¢
    GameWorld.Log("%s µÇ¼, accID = %s, IP = %s, MapID = %s"%(curPlayer.GetName(), curPlayer.GetAccID(), curPlayer.GetIP(), curPlayer.GetRealMapID()) , curPlayer.GetPlayerID())
    #·¢Ë͸ø¿Í»§¶Ë·â°üͬ²½Ê±¼ä¸ÄÓÃA0 04
    #curPlayer.Sync_ServerDataTimeToClient()
    #¸Äµ½mapServerµÇ¼³É¹¦Í¨Öª
    #Sync_PyServerDataTimeToClient(curPlayer, tick)
    
    if GameWorld.IsCrossServer():
        PlayerFB.PlayerLoginLoadCrossMapOK(curPlayer)
        
    PlayerTeam.OnPlayerReadMapOK(curPlayer, tick)
    
    #Ë¢ÐÂÈËÎïÈÕÆÚ״̬
    PlayerEventCounter.UpdatePlayerLoginTime(curPlayer)
    
#===============================================================================
#    #¸±±¾»î¶¯½çÃæÐÞ¸ÄΪ, Íæ¼Òµã»÷NPC´¥·¢, 2010-07-02
#    if GameWorld.GetGameWorld().GetGameFbEventList().GetGameFbEventListCount() != 0:
#        #»î¶¯¸±±¾²»Îª0, Í¨Öª¿Í»§¶ËËùÓи±±¾×´Ì¬
#        curPlayer.Sync_GameFbEvent()
#===============================================================================
    #×Ô¼ºÒѾ­³õʼ»¯³É¹¦
    curPlayer.SetInitOK(True)
    GMShell.OnPlayerLogin(curPlayer)
    #·¢ËÍÇëÇóÖÁÄ¿±êµØÍ¼(ÈÎÎñÐèÒªµÇ½¼Ò×峤´¥·¢Ê¼þ)
    __RefreshFamilyToMapServer(curPlayer)
    return
 
## Íæ¼Ò¶ÁÈ¡µØÍ¼×´Ì¬(·â°ü²ÎÊý)
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return True
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def PlayerLoadMapState(index, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    pack = IPY_GameServer.IPY_GPlayerLoadMap()
    if pack.GetLoadState() == 0:
        curPlayer.SetIsLoadMap(True)
        return
    
    #Íæ¼ÒµÚÒ»´Î½øÈëÓÎÏ·³õʼ»¯£¬ÕâÀïÖ»ÔËÐÐÒ»´Î
    if not curPlayer.GetInitOK():
        PlayerLoginLoadMapOK(curPlayer, tick)
        
        #¾ÀÕýÍæ¼ÒÃû×ÖÐÞ¸ÄÊÇ·ñ³É¹¦
        UpdatePlayerName.PlayerLoadMapRedressUpdatePlayerName(curPlayer, tick)
    
    #2008.12.21
    #ÓÉÓÚbug: 2¸öÈËͬʱ½ø¸±±¾, ·Ç¶Ó³¤»á±»Ìß³ö
    #Ô­Òò: ×é¶ÓˢеÄʱ»úÊÇÔÚ¿Í»§¶Ë·¢À´µØÍ¼¶ÁÈ¡³É¹¦µÄʱºò, Õâ¸öʱ»ú¹ýÍí
    #µ±2¸öÈËͬʱ½øÈëµÄʱºò, µØÍ¼·þÎñÆ÷»¹Ã»ÓÐ×é¶ÓÐÅÏ¢, ËùÒԻᱻÌß
    #ËùÒÔ°ÑOnPlayerChangeMapʼþ¸Äµ½SetMapIDÖÐ
#    else:
#        #¿ªÊ¼µØÍ¼³õʼ»¯¶¯×÷
#        OnPlayerChangeMap(curPlayer, tick)
    
    #Íæ¼ÒµØÍ¼¶ÁÈ¡³É¹¦ºó£¬·¢Ë͸øµØÍ¼·þÎñÆ÷³õʼ»¯³É¹¦·â°ü
    if curPlayer.GetIsLoadMap():
        #֪ͨµØÍ¼·þÎñÆ÷Íæ¼Ò³õʼ»¯³É¹¦
        curPlayer.MapServer_GameServerRefreshOK()
    
    curPlayer.SetIsLoadMap(False)
    
    #Ö´ÐнûIP²Ù×÷
    GMCommon.DoLogic_GMForbidIP(curPlayer, tick)
    
    GameWorld.Log("Íæ¼Ò¿ªÊ¼µØÍ¼³õʼ»¯¶¯×÷" , curPlayer.GetPlayerID())
    return
 
#g_worldNotifyTick = 0
## ÊÀ½ç֪ͨ
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return True
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def WorldNotify(index, tick):
    #===============================================================================================
    # global g_worldNotifyTick
    # if g_worldNotifyTick and tick - g_worldNotifyTick < 3000:
    #    return
    # g_worldNotifyTick = tick
    #===============================================================================================
    pack = IPY_GameServer.IPY_GWorldNotifyCode()
    #¹¹½¨ÏµÍ³Ìáʾ²ÎÊýÁбí
    notifyCodeList = PlayerControl.NotifyCodeList
    notifyCodeList.Clear()
    
    for i in range(pack.GetParCount()):
        notifyMsg = pack.GetPars(i)
        
        if notifyMsg.GetLen() == 0:
            #ÊÇÕûÐÍ
            notifyCodeList.AddInt(notifyMsg.GetMsgInt())
            #ÊÇ×Ö·û´®
        else:
            notifyCodeList.AddStr(notifyMsg.GetMsg())
    
    familyID = pack.GetFamilyID()
    
    #¼Ò×å¹ã²¥
    if familyID != 0:
        GameWorld.GetPlayerManager().FamilyNotifyCode(familyID, pack.GetMsg(), notifyCodeList)
        return
    
    #È«·þ¹ã²¥
    if pack.GetLineID() <= 0:
        GameWorld.GetPlayerManager().CountryNotifyCode(pack.GetCountry(), pack.GetMsg(), notifyCodeList)
        return
    
    #·ÖÁ÷¹ã²¥ IPY_PlayerManager::LineNotifyCode(int LineNo, char * code, IPY_NotifyCodeList * nofityCode) // ·ÖÁ÷֪ͨ½Ó¿Ú
    GameWorld.GetPlayerManager().LineNotifyCode(pack.GetRouteIndex(), pack.GetMsg(), notifyCodeList)
    return
 
 
 
 
 
#// A0 04 ²éѯ¸±±¾¹¦ÄÜÏß·ÈËÊý #tagCGGetFBLinePlayerCnt
#
#struct    tagCGGetFBLinePlayerCnt
#{
#    tagHead        Head;
#    DWORD        MapID;
#    BYTE        LineCount;
#    BYTE        LineIDList[LineCount];    //¸öÊýΪ0ʱ´ú±í²éÈ«²¿
#};
def ClinetQueryFBLinePlayerCnt(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    queryMapID = clientData.MapID
    queryFBLineIDList = clientData.LineIDList
    playerManager = GameWorld.GetPlayerManager()
    
    if queryMapID in ChConfig.Def_CrossMapIDList:
        fbLinePlayerInfoDict = PyGameData.g_crossFBFuncLinePlayerCountInfo.get(queryMapID, {})
        if not queryFBLineIDList:
            resultInfo = [queryMapID, fbLinePlayerInfoDict]
        else:
            defaultInfo = [0] # Óë±¾·þ½á¹¹Ïàͬ£¬Ä¬ÈÏ0ÈË
            queryFBLineInfo = {}
            for lineID in queryFBLineIDList:
                queryFBLineInfo[lineID] = fbLinePlayerInfoDict.get(lineID, defaultInfo)
            resultInfo = [queryMapID, queryFBLineInfo]
        QueryFBLinePlayerCntResult(curPlayer, resultInfo)
        return
    
    sendCMD = str([queryMapID, queryFBLineIDList])
    playerManager.MapServer_QueryPlayer(curPlayer.GetPlayerID(), 0, 0, queryMapID,
                'FBLinePlayerCnt', sendCMD, len(sendCMD), curPlayer.GetRouteServerIndex())
    return
 
def QueryFBLinePlayerCntResult(curPlayer, resultInfo):
    if not curPlayer:
        return
    if not resultInfo:
        return
    if len(resultInfo) != 2:
        return
    tagMapID, fbLinePlayerCntDict = resultInfo
    fblinePack = ChPyNetSendPack.tagGCFBLinePlayerCnt()
    fblinePack.MapID = tagMapID
    fblinePack.FBLineInfoList = []
    for lineID, infoList in fbLinePlayerCntDict.items():
        mapLineState = ChPyNetSendPack.tagGCFBLineInfo()
        mapLineState.Clear()
        mapLineState.FBLineID = lineID
        mapLineState.PlayerCnt = infoList[0] if infoList else 0
        mapLineState.ExtraStr = infoList[1] if len(infoList) > 1 else ''
        mapLineState.ExtraStrLen = len(mapLineState.ExtraStr)
        fblinePack.FBLineInfoList.append(mapLineState)
    
    fblinePack.Count = len(fblinePack.FBLineInfoList)
    NetPackCommon.SendFakePack(curPlayer, fblinePack)
    return
 
#// A0 03 ²éѯµØÍ¼Ïß·״̬ #tagPyGetLineState
#
#struct    tagPyGetLineState
#{
#    tagHead        Head;
#    DWORD        MapID;
#};
def ClientQueryLineState(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    queryMapID = clientData.MapID # Òª²éѯµÄµØÍ¼£¬0Ϊ²éÈ«²¿
    
    mapLineDict = IpyGameDataPY.GetFuncEvalCfg("MapLine", 1)
    mapPlayerDict = {}
    mapServerStateManager = GameWorld.GetGameWorld().GetMapServerStateManager()
    GetZoneServerCnt = mapServerStateManager.GetZoneServerCnt()
    for zoneIndex in xrange(GetZoneServerCnt):
        ZoneServerState = mapServerStateManager.GetZoneServerByIndex(zoneIndex)
        mapCnt = ZoneServerState.GetMapCount()
        for i in xrange(mapCnt):
            MapServerState = ZoneServerState.GetMapServerStateByIndex(i)
            mapID = MapServerState.GetMapID()
            if queryMapID > 0 and mapID != queryMapID:
                continue
            lineCnt = MapServerState.GetLineCount()
            if mapID in mapLineDict:
                lineCnt = min(lineCnt, mapLineDict[mapID])
            curPlayerCntList, maxPlayerCntList = mapPlayerDict.get(mapID, [[], []])
            for lineIndex in xrange(lineCnt):
                MapServerLineState = MapServerState.GetLineByIndex(lineIndex)
                #GetMapID = MapServerLineState.GetMapID()
                #lineID = MapServerLineState.GetLineID()
                curPlayerCnt = MapServerLineState.GetCurPlayerCnt()
                maxPlayerCnt = MapServerLineState.GetMaxPlayerCnt()
                
                curPlayerCntList.append(curPlayerCnt)
                maxPlayerCntList.append(maxPlayerCnt)
                
            mapPlayerDict[mapID] = [curPlayerCntList, maxPlayerCntList]
            if queryMapID > 0:
                break
    
    # A0 06 ·þÎñÆ÷µØÍ¼Ïß·ÈËÊý״̬ #tagGCPyServerMapState
    mapStatePack = ChPyNetSendPack.tagGCPyServerMapState()
    mapStatePack.Clear()
    mapStatePack.MapStateList = []
    for mapID, playerCntList in mapPlayerDict.items():
        mapLineState = ChPyNetSendPack.tagGCPyServerMapLineState()
        mapLineState.Clear()
        mapLineState.MapID = mapID
        mapLineState.LineCurPlayerCntList = playerCntList[0]
        mapLineState.LineMaxPlayerCntList = playerCntList[1]
        mapLineState.LineCnt = len(mapLineState.LineCurPlayerCntList)
        mapStatePack.MapStateList.append(mapLineState)
    mapStatePack.MapCount = len(mapStatePack.MapStateList)
    NetPackCommon.SendFakePack(curPlayer, mapStatePack)
    return
 
## µØÍ¼·þÎñÆ÷ÇëÇóÍæ¼ÒÏß·״̬
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return True
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def MapServer_GetLineState(index, tick):
#    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
#    #curPlayer.Sync_LineState()
#    
#    mapPlayerDict = {}
#    mapServerStateManager = GameWorld.GetGameWorld().GetMapServerStateManager()
#    GetZoneServerCnt = mapServerStateManager.GetZoneServerCnt()
#    for zoneIndex in xrange(GetZoneServerCnt):
#        ZoneServerState = mapServerStateManager.GetZoneServerByIndex(zoneIndex)
#        mapCnt = ZoneServerState.GetMapCount()
#        for i in xrange(mapCnt):
#            MapServerState = ZoneServerState.GetMapServerStateByIndex(i)
#            mapID = MapServerState.GetMapID()
#            lineCnt = MapServerState.GetLineCount()
#            curPlayerCntList, maxPlayerCntList = mapPlayerDict.get(mapID, [[], []])
#            for lineIndex in xrange(lineCnt):
#                MapServerLineState = MapServerState.GetLineByIndex(lineIndex)
#                #GetMapID = MapServerLineState.GetMapID()
#                #lineID = MapServerLineState.GetLineID()
#                curPlayerCnt = MapServerLineState.GetCurPlayerCnt()
#                maxPlayerCnt = MapServerLineState.GetMaxPlayerCnt()
#                
#                curPlayerCntList.append(curPlayerCnt)
#                maxPlayerCntList.append(maxPlayerCnt)
#                
#            mapPlayerDict[mapID] = [curPlayerCntList, maxPlayerCntList]
#    
#    # A0 06 ·þÎñÆ÷µØÍ¼Ïß·ÈËÊý״̬ #tagGCPyServerMapState
#    mapStatePack = ChPyNetSendPack.tagGCPyServerMapState()
#    mapStatePack.Clear()
#    mapStatePack.MapStateList = []
#    for mapID, playerCntList in mapPlayerDict.items():
#        mapLineState = ChPyNetSendPack.tagGCPyServerMapLineState()
#        mapLineState.Clear()
#        mapLineState.MapID = mapID
#        mapLineState.LineCurPlayerCntList = playerCntList[0]
#        mapLineState.LineMaxPlayerCntList = playerCntList[1]
#        mapLineState.LineCnt = len(mapLineState.LineCurPlayerCntList)
#        mapStatePack.MapStateList.append(mapLineState)
#    mapStatePack.MapCount = len(mapStatePack.MapStateList)
#    NetPackCommon.SendFakePack(curPlayer, mapStatePack)
    return
 
## ²é¿´FBÏÔʾ½çÃæ
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return True
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def ShowFbEvent(index, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    if tick - curPlayer.GetDictByKey("ShowFbEvent") < ChConfig.Def_Show_Fb_Event_Tick:
        return
    
    curPlayer.Sync_GameFbEvent()
    curPlayer.SetDict("ShowFbEvent", tick)
#---------------------------------------------------------------------
#===============================================================================
# //03 24 ¾Ù±¨#tagCImpeach
# tagCImpeach       *   GettagCImpeach();
# class   IPY_CImpeach
# {
# public:
#    int      GetPlayerID();
#    int      GetMsgLen();
#    //size = MsgLen
#    char *      GetMsg();
#    int      GetTalkLen();
#    //size = TalkLen
#    char *      GetTalk();
# };
#===============================================================================
## ¾Ù±¨Íæ¼Ò
#  @param index Íæ¼ÒË÷Òý 
#  @param tick µ±Ç°Ê±¼ä
#  @return True
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def Impeach(index , tick):
    playerManager = GameWorld.GetPlayerManager()
    curPlayer = playerManager.GetPlayerByIndex(index)
    gameWorld = GameWorld.GetGameWorld()
    
    if tick - gameWorld.GetTickByType(ChConfig.TYPE_ImpeachTick) < ChConfig.TYPE_Tick_Time[ChConfig.TYPE_ImpeachTick]:
        #Speech_Lost_Frequently ¶Ô²»Æð£¬ÄúµÄ¾Ù±¨²Ù×÷¹ýÓÚÆµ·±£¬ÇëÉÔºóÖØÊÔ
        PlayerControl.NotifyCode(curPlayer, "Speech_Lost_Frequently")
        return
    
    gameWorld.SetTickByType(ChConfig.TYPE_ImpeachTick , tick)
    
    pack = IPY_GameServer.IPY_CImpeach()
    tagPlayer = playerManager.FindPlayerByID(pack.GetPlayerID())
    
    if not tagPlayer:
        #Speech_Lost_NoLine ¶Ô²»Æð£¬Äú¾Ù±¨µÄÍæ¼Ò²»ÔÚÏߣ¬ÇëÉÔºóÖØÊÔ
        PlayerControl.NotifyCode(curPlayer, "Speech_Lost_NoLine")
        return
    
    curPlayer.ImpeachPlayer(tagPlayer, str(pack.GetTalk()))
    #Speech_Success ×¢Ò⣺ÄúµÄ¾Ù±¨²Ù×÷ÒѾ­³É¹¦
    PlayerControl.NotifyCode(curPlayer, "Speech_Success")
    return
#---------------------------------------------------------------------
 
## Í¬²½Ê±¼ä
#  @param index Íæ¼ÒʵÀý
#  @param clientData ·â°ü½á¹¹Ìå
#  @param tick Ê±¼ä´Á
#  @return None
def ClientRequestServerTime(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    Sync_PyServerDataTimeToClient(curPlayer, tick)
    return
 
 
## Í¬²½Ê±¼ä
#  @param curPlayer 
#  @param tick Ê±¼ä´Á
#  @return None
def Sync_PyServerDataTimeToClient(curPlayer, tick):
 
    if not GameWorld.RefurbishPlayerTick(curPlayer, ChConfig.TYPE_Player_Tick_SyncClientTick, tick):
        #¼ä¸ôδµ½
        return
    
    # ·þÎñÆ÷ʱ¼ä
    serverTime = GameWorld.GetServerTime()
    if not serverTime:
        return
    
    serverDateTime = ChPyNetSendPack.tagServerDateTime()
    serverDateTime.Clear()
    serverDateTime.Year = serverTime.year
    serverDateTime.Month = serverTime.month
    serverDateTime.Day = serverTime.day
    serverDateTime.Hour = serverTime.hour
    serverDateTime.Minute = serverTime.minute
    serverDateTime.Second = serverTime.second
    serverDateTime.MicSecond = serverTime.microsecond
    serverDateTime.CrossServerTime = GameWorld.GetCrossServerTimeStr()
    
    # Í¨Öª¿Í»§¶Ëͬ²½Ê±¼ä
    NetPackCommon.SendFakePack(curPlayer, serverDateTime)
    return
 
def UpdataPlayerLVInfo():
    #Onday¸üÐÂÍæ¼ÒµÈ¼¶ÐÅÏ¢
    PyGameData.g_yesterdayPlayerLVDict = PyGameData.g_todayPlayerLVDict
    PyGameData.g_todayPlayerLVDict = {}
    playerManager = GameWorld.GetPlayerManager()
    for i in xrange(playerManager.GetActivePlayerCount()):
        curPlayer = playerManager.GetActivePlayerAt(i)
        if curPlayer == None or not curPlayer.GetInitOK():
            continue
        if PlayerControl.GetIsTJG(curPlayer):
            continue
        PyGameData.g_todayPlayerLVDict[curPlayer.GetID()] = curPlayer.GetLV()
    return
 
def LoadPlayerLVData():
    #·þÎñÆ÷¿ªÆôʱ¼ÓÔØ»îÔ¾Íæ¼ÒµÈ¼¶ÐÅÏ¢
    universalRecMgr = GameWorld.GetUniversalRecMgr()
 
    recDataList = universalRecMgr.GetTypeList(ShareDefine.Def_UniversalGameRecType_TodayPlayerLVInfo)
    allCnt = recDataList.Count()
    for index in xrange(allCnt):
        recData = recDataList.At(index)
        PyGameData.g_todayPlayerLVDict[recData.GetValue1()] = recData.GetValue2()
    
    recDataList = universalRecMgr.GetTypeList(ShareDefine.Def_UniversalGameRecType_YesterdayPlayerLVInfo)
    allCnt = recDataList.Count()
    for index in xrange(allCnt):
        recData = recDataList.At(index)
        PyGameData.g_yesterdayPlayerLVDict[recData.GetValue1()] = recData.GetValue2()
    GameWorld.DebugLog('    ·þÎñÆ÷¿ªÆôʱ¼ÓÔØ»îÔ¾Íæ¼ÒµÈ¼¶ÐÅÏ¢g_todayPlayerLVDict=%s, g_yesterdayPlayerLVDict=%s'%(PyGameData.g_todayPlayerLVDict,PyGameData.g_yesterdayPlayerLVDict))
    return
 
def SavePlayerLVData():
    #·þÎñÆ÷¹Ø±Õǰʱ±£´æ»îÔ¾Íæ¼ÒµÈ¼¶ÐÅÏ¢
    GameWorld.GetUniversalRecMgr().Delete(ShareDefine.Def_UniversalGameRecType_TodayPlayerLVInfo)
    GameWorld.GetUniversalRecMgr().Delete(ShareDefine.Def_UniversalGameRecType_YesterdayPlayerLVInfo)
    universalRecMgr = GameWorld.GetUniversalRecMgr()
    recDataList = universalRecMgr.GetTypeList(ShareDefine.Def_UniversalGameRecType_TodayPlayerLVInfo)
    for playerID, lv in PyGameData.g_todayPlayerLVDict.items():
        recData = recDataList.AddRec()
        recData.SetValue1(playerID)
        recData.SetValue2(lv)
    
    recDataList = universalRecMgr.GetTypeList(ShareDefine.Def_UniversalGameRecType_YesterdayPlayerLVInfo)
    for playerID, lv in PyGameData.g_yesterdayPlayerLVDict.items():
        recData = recDataList.AddRec()
        recData.SetValue1(playerID)
        recData.SetValue2(lv)
    return