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
#!/usr/bin/python
# -*- coding: GBK -*-
#
##@package E:/GameSVN/U3DGame/ProjectSServer/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFriend.py
# @todo: 
#
# @author: Alee
# @date 2017-8-28 ÏÂÎç10:28:54
# @version 1.0
#
# @note:
#
#---------------------------------------------------------------------
#"""Version =  2017-8-28 21:00"""
#---------------------------------------------------------------------
import IPY_GameServer
import GameWorld
import ChConfig
import PlayerRequest
import PlayerControl
import ChPyNetSendPack
import NetPackCommon
import ShareDefine
import PyDataManager
import IpyGameDataPY
import random
import PlayerSocial
import copy
import PlayerViewCache
import PlayerTeam
 
#---------------------------------------------------------------------
 
 
############################################################
#·â°ü
 
#===============================================================================
# //B3 01 Ìí¼ÓºÃÓÑ#tagCGAddFriend
# struct    tagCGAddFriend
# {
#    tagHead        Head;
#    char        TagName[33];        //Íæ¼ÒÃû³Æ
#    DWORD        TagID;        //Íæ¼ÒID
# };
#===============================================================================
## Ìí¼ÓºÃÓÑ
def AddFriend(index, clientData, tick):
    #»ñÈ¡Íæ¼Ò
    playerManager = GameWorld.GetPlayerManager()
    curPlayer = playerManager.GetPlayerByIndex(index)
    curTagPlayerID = clientData.TagID
 
    limitLV = GetFuncLimitLV(ShareDefine.GameFuncID_Friend)
    if curPlayer.GetLV() < limitLV:
        PlayerControl.NotifyCode(curPlayer, 'LvErr')
        return
    
    if not CheckFriendCount(curPlayer, True, curPlayer.GetID()):
        #ºÃÓÑÒѾ­ÂúÁË
        GameWorld.DebugLog("ºÃÓÑÒѾ­ÂúÁË")
        return
    
    #»ñÈ¡Ä¿±êÍæ¼Ò
    tagPlayer = None
    tagLV = 0
    if clientData.TagID != 0:
        tagPlayer = playerManager.FindPlayerByID(curTagPlayerID)
    else:
        tagPlayer = playerManager.FindPlayerByName(clientData.TagName)
        #Ãû³Æ¼ÓºÃÓѲ»Ö§³ÖÀëÏß
        if tagPlayer == None:
            #XW_SJ_AimOffline Íæ¼ÒÒÑÏÂÏß
            PlayerControl.NotifyCode(curPlayer, 'Friend_OffLine')
            return
    
    if not tagPlayer:
        curCache = PlayerViewCache.FindViewCache(curTagPlayerID)
        if not curCache:
            #Íæ¼ÒµÄÊý¾ÝûÓлº´æ¹ý
            PlayerControl.NotifyCode(curPlayer, 'Friend_OffLine')
            return
        tagLV = curCache.LV
    else:
        tagLV = tagPlayer.GetLV()
    
    if tagLV < limitLV:
        PlayerControl.NotifyCode(curPlayer, 'Friend_OtherLessLv')
        return
    
    curPlayerID = curPlayer.GetID()
    
    if curPlayerID == curTagPlayerID:
        #²»ÔÊÐíÌí¼Ó×Ô¼º
        GameWorld.DebugLog("²»ÔÊÐíÌí¼Ó×Ô¼º")
        return
    
    # ºÚÃûµ¥¼ì²é
    if PyDataManager.GetBlacklistManager().CheckBlacklistBoth(curPlayerID, curTagPlayerID, curPlayer):
        GameWorld.DebugLog("ºÚÃûµ¥¼ì²é")
        return
    
    curPlayerFriendStruct = GetFriendStruct(curPlayerID)
    
    tagFriend = curPlayerFriendStruct.Find(curTagPlayerID)
    
    if tagFriend != None:
        #XW_SJ_Repeat:¶Ô²»Æð,xxxÒÑÊÇÄúµÄºÃÓÑ,Ìí¼ÓºÃÓÑʧ°Ü!</n> 
        PlayerControl.NotifyCode(curPlayer, "Friend_YetFriend")
        return
    
    # Òì³£¼ì²é
    __CheckAddFriend(curPlayer, curTagPlayerID)
    
    #µ±Ç°Íæ¼ÒÌí¼ÓÇëÇó
    #curPlayer.AddRequest(curTagPlayerID, IPY_GameServer.reqFriend, tick, ChConfig.Def_EventClearTime)
    PlayerRequest.PYAddRequest(curPlayer, curTagPlayerID, IPY_GameServer.reqFriend)
 
    #Óë¿Í»§¶ËÔ¼¶¨Ãû×Öºó¼ÓÍæ¼ÒÖ°ÒµºÍµÈ¼¶£¬¿Í»§¶Ë×ÔÐвð¿ª
    #tagPlayer.Frm_AddFriendAsk(curPlayerID, '|'.join([curPlayer.GetName(), str(curPlayer.GetJob()), str(curPlayer.GetLV())]))
 
    if tagPlayer:
        askFriendPack = ChPyNetSendPack.tagGCFriendAskIfJoin()
        askFriendPack.AskID = curPlayerID
        askFriendPack.Name = curPlayer.GetName()
        askFriendPack.LV = curPlayer.GetLV()
        askFriendPack.RealmLV = curPlayer.GetOfficialRank()
        askFriendPack.Face = curPlayer.GetFace()
        askFriendPack.FacePic = curPlayer.GetFacePic()
        
        NetPackCommon.SendFakePack(tagPlayer, askFriendPack) 
 
    #XW_SJ_ApplyFriend ºÃÓÑÇëÇó·¢Ëͳɹ¦
    PlayerControl.NotifyCode(curPlayer, 'Friend_ApplyFriend')
    return
 
 
#---------------------------------------------------------------------
##»ñÈ¡Íæ¼Ò½á¹¹Ìå
# @param curPlayer Íæ¼ÒʵÀý
# @return IPY_Friend ÊµÀý
# @remarks 
def GetFriendStruct(playerID):
    curFriends = PyDataManager.GetFriendManager().GetFriends(playerID)
    
    if curFriends != None:
        return curFriends
    
    return PyDataManager.GetFriendManager().AddFriends(playerID)
 
def IsFriend(playerID, tagPlayerID):
    ## ÅжÏË«·½ÊÇ·ñºÃÓÑ
    curFriends = PyDataManager.GetFriendManager().GetFriends(playerID)
    if not curFriends:
        return False
    return curFriends.Find(tagPlayerID) != None
 
#---------------------------------------------------------------------
##ºÃÓѼì²é
# @param curPlayer ÉêÇëºÃÓѵÄÍæ¼Ò
# @param tagPlayer ½ÓÊÜÉêÇëºÃÓѵÄÍæ¼Ò
# @return None
# @remarks 
def __CheckAddFriend(curPlayer, curTagPlayerID):
    curPlayerID = curPlayer.GetID()
    #»ñÈ¡ÉêÇëºÃÓÑÍæ¼ÒÐÅÏ¢ 
    curPlayerFriendStruct = GetFriendStruct(curPlayerID)
    curPlayerHasThisFriend = curPlayerFriendStruct.Find(curTagPlayerID)
    #»ñÈ¡½ÓÊÜÉêÇëºÃÓѵÄÍæ¼ÒÐÅÏ¢
    tagPlayerFriendStruct = GetFriendStruct(curTagPlayerID)
    tagPlayerHasThisFriend = tagPlayerFriendStruct.Find(curPlayerID)
    
    if curPlayerHasThisFriend != None and tagPlayerHasThisFriend != None:
        # Í¬Ê±ÊǶԷ½ºÃÓÑ
        return
 
    if curPlayerHasThisFriend == None and tagPlayerHasThisFriend == None:
        # Í¬Ê±¶¼²»ÊǶԷ½ºÃÓÑ
        return
 
    #״̬Ò쳣ɾ³ýË«·½µÄ¹Øϵ
    GameWorld.ErrLog('AddFriend, (%s, %s)ºÃÓÑÒì³£, É¾³ýË«·½ºÃÓѹØϵ' % (curPlayerID, curTagPlayerID))
 
    # Ö»ÓÐijһ·½ÊÇÁíÒ»·½ºÃÓÑ
    if curPlayerHasThisFriend != None:
        curPlayerFriendStruct.DelFriend(curTagPlayerID)
 
    if tagPlayerHasThisFriend != None:
        tagPlayerFriendStruct.DelFriend(curPlayerID)
    
    return
 
#===============================================================================
# //B3 02 É¾³ýºÃÓÑ#tagCGDeleteFriend
# struct    tagCGDeleteFriend
# {
#    tagHead        Head;
#    DWORD        FriendID;
# };
#===============================================================================
## É¾³ýºÃÓÑ
def DeleteFriend(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    playerID = curPlayer.GetPlayerID()
    curFriends = PyDataManager.GetFriendManager().GetFriends(playerID)
    if curFriends == None:
        GameWorld.Log('DeleteFriend -> ·â°üÒì³£ ->ûÓкÃÓÑ',playerID)
        return
    
    friendID = clientData.FriendID
    curFriend = curFriends.Find(friendID)
    if curFriend == None:
        GameWorld.Log('DeleteFriend -> ·â°üÒì³£ ->ûÓÐÕâ¸öÍæ¼Ò', playerID)
        return
    
    couple = PyDataManager.GetDBPyCoupleManager().GetCouple(playerID)
    if couple and couple.GetCoupleID(playerID) == friendID:
        #GameWorld.Log('DeleteFriend -> ·â°üÒì³£ ->°é²»ÄÜɾ³ýºÃÓÑ.friendID=%s' % friendID, playerID)
        PlayerControl.NotifyCode(curPlayer, "DelFriendCoupleLimit")
        return
    
    #ÀëÏߺÃÓÑͬʱɾ³ý¼Ç¼
    PyDataManager.GetFriendManager().DelFriendBoth(playerID, friendID)
    
    #XW_SJ_DeleteFriend ½â³ýºÃÓѳɹ¦
    PlayerControl.NotifyCode(curPlayer, 'Friend_DeleteFriend')
    
    tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(friendID)
    if tagPlayer != None:
        PlayerControl.NotifyCode(tagPlayer, 'Friend_DeleteFriend2', [curPlayer.GetName()])
    PlayerTeam.OnTeamMemFriendChange(curPlayer, friendID, False)
    
    # Ç×ÃܶȼõÉÙ
    decIntimacyPer = IpyGameDataPY.GetFuncCfg("IntimacyReduce", 1)
    if decIntimacyPer:
        PyDataManager.GetIntimacyManager().DelIntimacyBothPer(playerID, friendID, decIntimacyPer)
        
    return
 
 
## ¼ì²âºÃÓÑÊýÊÇ·ñ´ïµ½ÉÏÏÞ
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @return ²¼¶ûÖµ
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def CheckFriendCount(curPlayer, isNotify, playerID):
    
    curFriends = PyDataManager.GetFriendManager().GetFriends(playerID)
    if curFriends == None:
        return True
        
    if curFriends.GetCount() >= IpyGameDataPY.GetFuncCfg("FriendMaxCnt"):
        # ºÃÓÑÒÑÂú
        if isNotify:
            PlayerControl.NotifyCode(curPlayer, "Friend_FullList")
        return False
    
    return True
 
#===============================================================================
# //B3 03 ÊÇ·ñÔÊÐí¼ÓÈëºÃÓѵĻØÓ¦#tagCGJoinFriendAnswer
# struct    tagCGJoinFriendAnswer
# {
#    tagHead        Head;
#    DWORD        TagID;
#    BYTE        Answer;        //0: ¾Ü¾ø 1: ½ÓÊÜ
# };
#===============================================================================
## ÊÇ·ñÔÊÐí¼ÓÈëºÃÓѵĻØÓ¦
def JoinFriendAnswer(index, clientData, tick):
    playerManager = GameWorld.GetPlayerManager()
    curPlayer = playerManager.GetPlayerByIndex(index)
    
    srcPlayerID = clientData.TagID  # ÇëÇóÕßµÄID
    srcPlayer = playerManager.FindPlayerByID(srcPlayerID)
    if srcPlayer == None:
        # Íæ¼ÒÒÑÏÂÏß
        curCache = PlayerViewCache.FindViewCache(srcPlayerID)
        if not curCache:
            #Íæ¼ÒµÄÊý¾ÝûÓлº´æ¹ý
            #PlayerControl.NotifyCode(curPlayer, 'Friend_OffLine')
            return
    
    playerID = curPlayer.GetPlayerID()
    
    if playerID == srcPlayerID:
        GameWorld.Log('JoinFriendAnswer -> ·â°üÒì³£ ->²»ÄܼÓÈë×Ô¼ºÎªºÃÓÑ', playerID)
        return
    
    if not PlayerRequest.PYCheckRequest(srcPlayerID, curPlayer, IPY_GameServer.reqFriend):
        GameWorld.Log("JoinFriendAnswer -> ·â°üÒì³£ ->Íæ¼ÒûÓÐÕâ¸öÇëÇó", playerID)
        return
    
    if not clientData.Answer: 
        if srcPlayer:
            #XW_SJ_RefuseApply  XXX¾Ü¾ø°ÑÄã¼ÓΪºÃÓÑ
            PlayerControl.NotifyCode(srcPlayer, 'Friend_RejectFriend', [curPlayer.GetName()])
        return
    
    # ºÚÃûµ¥¼ì²é
    if PyDataManager.GetBlacklistManager().CheckBlacklistBoth(playerID, srcPlayerID, curPlayer):
        return
    
    #×Ô¼ºµÄºÃÓÑÂúÔ±
    if not CheckFriendCount(curPlayer, True, curPlayer.GetID()):
        
        GameWorld.DebugLog("#×Ô¼ºµÄºÃÓÑÂúÔ±")
        return
    
    #¶Ô·½µÄºÃÓÑÂúÔ±
    if not CheckFriendCount(None, False, srcPlayerID):
        PlayerControl.NotifyCode(curPlayer, "Friend_OtherFullList")
        return
    
    curFriends = PyDataManager.GetFriendManager().GetFriends(playerID)
    if curFriends == None:
        curFriends = PyDataManager.GetFriendManager().AddFriends(playerID)
        
    tagFriend = curFriends.Find(playerID)
    if tagFriend != None:
        #Õâ¸öºÃÓÑÒѾ­ÔÚ×Ô¼ºµÄºÃÓÑÁбíÖÐ
        GameWorld.Log('JoinFriendAnswer -> ·â°üÒì³£ ->Õâ¸öºÃÓÑÒѾ­ÔÚ×Ô¼ºµÄºÃÓÑÁбíÖÐ', playerID)
        return
        
    PyDataManager.GetFriendManager().AddFriendBoth(playerID, srcPlayerID)
    
    #XW_SJ_AppendFriend xxx³ÉΪÁËÄúµÄºÃÓÑ
    ##·¢ËÍÌí¼ÓºÃÓѳɹ¦µ½µØͼ·þÎñÆ÷ 
    # ´Ë´¦Í¨ÖªÖ»ÊÇ´¥·¢Í¬Ò»¸öºÃÓÑÌí¼Óɾ³ý¿É´¥·¢¶à´Î£¬ MapServer_SyncFriendInfoΪ¾ßÌåµÄºÃÓÑÊýÁ¿£¬¸ù¾Ý²ß»®ÐèÇóÖÆ×÷
    #curPlayer.MapServer_QueryPlayerResult(0, 0, 'AddFriendSucceed', "", 0)
    if srcPlayer:   
        PlayerControl.NotifyCode(curPlayer, 'Friend_MakeFriend', [srcPlayer.GetName()])  
        PlayerControl.NotifyCode(srcPlayer, 'Friend_MakeFriend', [curPlayer.GetName()])
        #srcPlayer.MapServer_QueryPlayerResult(0, 0, 'AddFriendSucceed', "", 0)
    else:
        cacheDict = PlayerViewCache.GetCachePropDataDict(curCache)
        PlayerControl.NotifyCode(curPlayer, 'Friend_MakeFriend', [cacheDict['Name']])  
        # ¼Ç¼µÈ¶Ô·½ÉÏÏß֪ͨµØͼ£¬ÈÎÎñµÈ»áÓõ½´¥·¢Âß¼­£¬Í¨ÓüǼ´ÎÊý¼´¿É£¬ MapServer_SyncFriendInfoΪ¾ßÌåµÄºÃÓÑÊýÁ¿£¬¸ù¾Ý²ß»®ÐèÇóÖÆ×÷
        pass
    PlayerTeam.OnTeamMemFriendChange(curPlayer, srcPlayerID, True)
    return
 
 
 
#//06 02 Ìí¼ÓµÐÈË#tagGAddEnemy
#tagGAddEnemy       *   GettagGAddEnemy();
#
#class   IPY_GAddEnemy
#{
#public:
#
#    int      GetEnemyID();
#
#    char *      GetEnemyName();
#};
## Ìí¼ÓµÐÈË 
#  @param index Íæ¼ÒË÷Òý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def MapServer_AddEnemy(index, tick):
 
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    pack = IPY_GameServer.IPY_GAddEnemy()
    tagID = pack.GetEnemyID()
    playerID = curPlayer.GetPlayerID()
    
    friends = PyDataManager.GetFriendManager().GetFriends(playerID)
    if friends and friends.Find(tagID):
        #ºÃÓѲ»¼ÓÈë³ðÈË
        return
 
    enemies = PyDataManager.GetEnemyManager().GetEnemies(playerID)
    if enemies and enemies.GetCount() > IpyGameDataPY.GetFuncCfg("EnemiesMaxCnt"):
        return
 
    # ÐèÒª¸üÐÂ×îÐÂÊý¾ÝÕâÀï²»¹ýÂËÊÇ·ñÒѾ­ÊdzðÈË
    PyDataManager.GetEnemyManager().AddEnemy(playerID, tagID)
    
    return
 
#===============================================================================
# //B3 04 ¼ÓÈëºÚÃûµ¥ #tagCGAddBlackList
# struct    tagCGAddBlackList
# {
#    tagHead        Head;
#    DWORD        TagID;        //Íæ¼ÒID
# };
#===============================================================================
def AddBlackList(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    tagID = clientData.TagID
    
    # ·ÇÉ罻ȦÄÚÍæ¼Ò²»ÄܼÓÈëºÚÃûµ¥
    #===========================================================================
    # if not PyDataManager.GetPersonalSocialManager().GetSocialPlayer(tagID):
    #    #¼Ù·â°ü»òÕßÒì³£
    #    GameWorld.DebugLog("#¼Ù·â°ü»òÕßÒì³£")
    #    return
    #===========================================================================
    
    couple = PyDataManager.GetDBPyCoupleManager().GetCouple(curPlayer.GetID())
    if couple and couple.GetCoupleID(curPlayer.GetID()) == tagID:
        #GameWorld.DebugLog("°é²»ÄܼÓÈëºÚÃûµ¥! tagID=%s" % tagID, curPlayer.GetID())
        PlayerControl.NotifyCode(curPlayer, "AddBlackCoupleLimit")
        return
    
    tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(tagID)
    if not tagPlayer:
        curCache = PlayerViewCache.FindViewCache(tagID)
        if not curCache:
            return
        cacheDict = PlayerViewCache.GetCachePropDataDict(curCache)
        playerName = cacheDict['Name']
    else:
        playerName = tagPlayer.GetName()
        
    players = PyDataManager.GetBlacklistManager().GetBlacklist(curPlayer.GetID())
    if players != None:
 
        if players.GetCount() >= IpyGameDataPY.GetFuncCfg("BlacklistMaxCnt"):
            PlayerControl.NotifyCode(curPlayer, 'BlacklistFull')
            return False
    
    PyDataManager.GetBlacklistManager().JoinBlacklist(curPlayer.GetPlayerID(), tagID)
    
    PlayerControl.NotifyCode(curPlayer, 'AddBlackList', [playerName])
    
    # Ç×ÃܶȼõÉÙ
    decIntimacyPer = IpyGameDataPY.GetFuncCfg("IntimacyReduce", 2)
    if decIntimacyPer:
        PyDataManager.GetIntimacyManager().DelIntimacyBothPer(curPlayer.GetPlayerID(), tagID, decIntimacyPer)
        
    return
 
 
#===============================================================================
# //B3 05 ÒƳýºÚÃûµ¥ #tagCGDelBlackList
# struct    tagCGDelBlackList
# {
#    tagHead        Head;
#    DWORD        TagID;
# };
#===============================================================================
def DelBlackList(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    PyDataManager.GetBlacklistManager().DelBlacklist(curPlayer.GetPlayerID(), clientData.TagID)
    PlayerControl.NotifyCode(curPlayer, 'DelBlackSuccess')
    #GameWorld.DebugLog("pack DelBlackList  %s "%clientData.TagID)
    return
 
############################################################
## µÇ½ºó֪ͨºÃÓÑ
def __OnPlayerLoginFriend(curPlayer, tick):
    #Íæ¼ÒµÇ¼
    curFriends = PyDataManager.GetFriendManager().GetFriends(curPlayer.GetID())
    if curFriends == None:
        return
    
    curFriends.Sync_SocialsInfo(curPlayer)
    #Ìí¼ÓÀëÏß¼ÓºÃÓÑ£¬ÉÏÏß֪ͨmapserver
    curFriends.MapServer_SyncFriendInfo(curPlayer)
    
    #֪ͨºÃÓÑÇëÇóÐÅÏ¢
    PlayerRequest.Sync_LoginRequest(curPlayer)
    return
 
## µÇ½ºó֪ͨ³ðÈË
def __OnPlayerLoginEnemy(curPlayer, tick):
    #֪ͨ³ðÈËÐÅÏ¢
    players = PyDataManager.GetEnemyManager().GetEnemies(curPlayer.GetID())
    if players == None:
        return
    
    players.Sync_SocialsInfo(curPlayer)
    return
 
# ×î½üÁªÏµÈË
def __OnPlayerLoginContacts(curPlayer, tick):
    players = PyDataManager.GetContactsManager().GetContacts(curPlayer.GetID())
    if players == None:
        return
    
    players.Sync_SocialsInfo(curPlayer)
    return
 
#ºÚÃûµ¥
def __OnPlayerLoginBlacklist(curPlayer, tick):
    players = PyDataManager.GetBlacklistManager().GetBlacklist(curPlayer.GetID())
    if players == None:
        return
    
    players.Sync_SocialsInfo(curPlayer)
    return
 
#Ç×ÃÜ
def __OnPlayerLoginIntimacylist(curPlayer, tick):
    intimacys = PyDataManager.GetIntimacyManager().GetIntimacys(curPlayer.GetID())
    if intimacys == None:
        return
    
    intimacys.Sync_SocialsInfo(curPlayer)
    return
 
## Íæ¼ÒµÇ½
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def OnPlayerLogin(curPlayer, tick):
    socialPlayer = PyDataManager.GetPersonalSocialManager().GetSocialPlayer(curPlayer.GetID())
    if socialPlayer:
        socialPlayer.playerInfo.OnlineType = ChConfig.Def_Online
    __OnPlayerLoginFriend(curPlayer, tick)
    __OnPlayerLoginEnemy(curPlayer, tick)
    __OnPlayerLoginContacts(curPlayer, tick)
    __OnPlayerLoginBlacklist(curPlayer, tick)
    __OnPlayerLoginIntimacylist(curPlayer, tick)
    
    # Ïòµ±Ç°Íæ¼Ò֪ͨÏà¹ØÁªµÄËùÓÐÍæ¼ÒÐÅÏ¢
    PlayerSocial.Sync_AllSocialsInfo(curPlayer)
    
    # ÏòÏà¹ØÁªµÄËùÓÐÍæ¼Ò֪ͨµ±Ç°Íæ¼ÒÐÅÏ¢
    PlayerSocial.Notify_All(curPlayer.GetID(), ChConfig.Def_CDBPlayerRefresh_Online, ChConfig.Def_Online)
    return
 
 
 
## Íæ¼ÒÏÂÏß
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def OnPlayerDisconnect(curPlayer, tick):
    if PlayerControl.GetIsTJG(curPlayer):
        return
    
    socialPlayer = PyDataManager.GetPersonalSocialManager().GetSocialPlayer(curPlayer.GetID())
    if socialPlayer == None:
        return
    socialPlayer.playerInfo.OnlineType = ChConfig.Def_Offline
 
    PlayerSocial.Notify_All(curPlayer.GetID(), ChConfig.Def_CDBPlayerRefresh_Online, ChConfig.Def_Offline)
    return
 
 
 
#// A9 A3 ²é¿´ÍƼöºÃÓÑ #tagCGQueryRecommendFriends
#
#struct    tagCGQueryRecommendFriends
#{
#    tagHead        Head;
#};
## ÍƼöºÃÓÑ
def Client_RecommendFriends(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    #recommendDict = [(5000, [0, 30]), (8000,[31, 50]), (9500,[51, 70]), (10000,[71, 800])]
    recommendFriend = copy.deepcopy(IpyGameDataPY.GetFuncEvalCfg("recommendFriend"))
    needCnt = IpyGameDataPY.GetFuncCfg("SerchFriendCnt")
    
    playerLV = curPlayer.GetLV()
    curPlayerID = curPlayer.GetPlayerID()
    curPlayerFriendStruct = GetFriendStruct(curPlayerID)
    
    limitLV = GetFuncLimitLV(ShareDefine.GameFuncID_Friend)
    if playerLV < limitLV:
        return
    #¹¹½¨²éѯÁбí
    allPlayerID = set()
    playerManager = GameWorld.GetPlayerManager()
    for i in range(0, playerManager.GetActivePlayerCount()):
        findPlayer = playerManager.GetActivePlayerAt(i)
        if findPlayer == None or not findPlayer.GetInitOK():
            continue
        curTagPlayerID = findPlayer.GetPlayerID()
        if curPlayerID == curTagPlayerID:
            #²»ÔÊÐíÌí¼Ó×Ô¼º
            continue
        
        # ÍƼöºÃÓÑÈ¥³ýÍÑ»ú¹ÒÍæ¼Ò
        if PlayerControl.GetIsTJG(findPlayer):
            continue
        
        #ÒÑÊǺÃÓÑ
        tagFriend = curPlayerFriendStruct.Find(curTagPlayerID)
        if tagFriend != None:
            continue
        
        #ÔÚºÚÃûµ¥ÖÐ
        if PyDataManager.GetBlacklistManager().CheckBlacklistBoth(curPlayerID, curTagPlayerID):
            GameWorld.DebugLog("ºÚÃûµ¥¼ì²é")
            continue
        
        # ÒÑÔÚÇëÇóÁбíÖÐ
        if PlayerRequest.IsRequesting(curPlayerID, curTagPlayerID, IPY_GameServer.reqFriend):
            continue
        
        #°´µÈ¼¶Çø¼ä·Ö×é
        findLV = findPlayer.GetLV()
        if findLV < limitLV:
            # ÏÞÖƵȼ¶
            continue
        
        for recommend in recommendFriend:
            minLV = recommend[1][0]
            maxLV = recommend[1][1]
            # ²»ÔÚÖ¸¶¨Çø¼äÄÚ
            if not ((playerLV - maxLV) <= findLV <= (playerLV - minLV) and \
            (playerLV + minLV) <= findLV <= (playerLV + maxLV)):
                continue
            
            if len(recommend) == 2:
                recommend[1].append([])
            recommend[1][2].append(curTagPlayerID)
        
        # ×îÖÕɸѡÓÃ
        allPlayerID.add(curTagPlayerID)
        
    GameWorld.DebugLog("recommendFriend %s"%(recommendFriend,))    
    
 
    
    # °´È¨ÖزéÕÒÍæ¼Ò
    playeIDs = []
    for i in xrange(needCnt*2):
        lvlimit = GameWorld.GetResultByRandomList(recommendFriend)
        if len(lvlimit) == 2:
            # Ã»ÓÐÍæ¼Ò
            continue
        
        playerID = random.choice(lvlimit[2])
        if playerID in playeIDs:
            continue
        
        if len(playeIDs) == needCnt:
            break
    
    #ÐÞÕý²»×ã
    fixCnt = needCnt - len(playeIDs)
    if fixCnt > 0:
        fixList = list(allPlayerID - set(playeIDs))
        playeIDs.extend(random.sample(fixList, min(fixCnt, len(fixList))))
    
    sendPack = ChPyNetSendPack.tagGCRecommendFriendsInfo()
    sendPack.Cnt = len(playeIDs)
    sendPack.FriendsList = []
    for playerID in playeIDs:
        tagPlayer = playerManager.FindPlayerByID(playerID)
        if not tagPlayer:
            continue
        rceFriendsData = ChPyNetSendPack.tagRecommendFriendsData()
        rceFriendsData.ID = playerID
        rceFriendsData.Name = tagPlayer.GetName()
        rceFriendsData.LV = tagPlayer.GetLV()
        rceFriendsData.Job = tagPlayer.GetJob()
        rceFriendsData.RealmLV = tagPlayer.GetOfficialRank()
        rceFriendsData.Face = tagPlayer.GetFace()
        rceFriendsData.FacePic = tagPlayer.GetFacePic()
        sendPack.FriendsList.append(rceFriendsData)
        
    #GameWorld.DebugLog("Client_RecommendFriends:%s"%sendPack.FriendsList)
    NetPackCommon.SendFakePack(curPlayer, sendPack) 
    return
 
 
#===============================================================================
# // A9 A4 ²éÕÒÍæ¼Ò #tagCGFuzzySearchPlayer
# struct    tagCGFuzzySearchPlayer
# {
#    tagHead        Head;
#    char        Name[33];
# };
#===============================================================================
 
def FuzzySearchPlayer(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    findName = clientData.Name
    limitLV = GetFuncLimitLV(ShareDefine.GameFuncID_Friend)
    if curPlayer.GetLV() < limitLV:
        return
    
    players = []
    curPlayerFriendStruct = GetFriendStruct(curPlayer.GetPlayerID())
    playerManager = GameWorld.GetPlayerManager()
    for i in range(0, playerManager.GetActivePlayerCount()):
        findPlayer = playerManager.GetActivePlayerAt(i)
        if findPlayer == None or not findPlayer.GetInitOK():
            continue
        
        curTagPlayerID = findPlayer.GetPlayerID()
        if curPlayer.GetPlayerID() == curTagPlayerID:
            #²»ÔÊÐíÌí¼Ó×Ô¼º
            continue
        
        #ÒÑÊǺÃÓÑ
        tagFriend = curPlayerFriendStruct.Find(curTagPlayerID)
        if tagFriend != None:
            continue
        
        if findPlayer.GetLV() < limitLV:
            # ÏÞÖƵȼ¶
            continue
        
        if findName in findPlayer.GetName():
            players.append(findPlayer)
    
    
    sendPack = ChPyNetSendPack.tagGCRecommendFriendsInfo()
    sendPack.Cnt = len(players)
    sendPack.FriendsList = []
    for tagPlayer in players:
        rceFriendsData = ChPyNetSendPack.tagRecommendFriendsData()
        rceFriendsData.ID = tagPlayer.GetID()
        rceFriendsData.Name = tagPlayer.GetName()
        rceFriendsData.LV = tagPlayer.GetLV()
        rceFriendsData.Job = tagPlayer.GetJob()
        rceFriendsData.RealmLV = tagPlayer.GetOfficialRank()
        rceFriendsData.Face = tagPlayer.GetFace()
        rceFriendsData.FacePic = tagPlayer.GetFacePic()
        sendPack.FriendsList.append(rceFriendsData)
        
    
    NetPackCommon.SendFakePack(curPlayer, sendPack) 
    return
 
 
 
## »ñÈ¡¹¦ÄÜÏÞÖƵȼ¶(µÈ¼¶Ìõ¼þΪȫ¾Ö)
def GetFuncLimitLV(funcID):
    ipyData = IpyGameDataPY.GetIpyGameData("FuncOpenLV", funcID)
    if not ipyData:
        return 0
    
    return ipyData.GetLimitLV()