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
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#
#---------------------------------------------------------------------
##@package PlayerRequest
# @todo: Íæ¼ÒÇëÇó´¦Àí
#
# @author: panwei
# @date 2010-12-10
# @version 1.1
#
# @note: 
# @change: "2012-12-21 11:00" jiang Íæ¼Òʱ¼ä¼ä¸ôʹÓÃGameWorld.RefurbishPlayerTick()º¯Êý
#---------------------------------------------------------------------
"""Version = 2012-12-21 11:00"""
#---------------------------------------------------------------------
import GameWorld
import ChConfig
import PyGameData
import IPY_GameServer
import NetPackCommon
import ChPyNetSendPack
#---------------------------------------------------------------------
## ÅжÏÍæ¼ÒÊÇ·ñÓÐÏàͬµÄÇëÇó
#  @param curPlayer µ±Ç°Íæ¼Ò 
#  @param curTagPlayer Ä¿±êÍæ¼Ò 
#  @param requestType ¶ÔÏóÀàÐÍ
#  @return True or False
#  @remarks ÅжÏÍæ¼ÒÊÇ·ñÓÐÏàͬµÄÇëÇó
def CheckRequest(curPlayer, curTagPlayer, requestType):
    if curTagPlayer == None:
        return False
    
    #¶ÔÏóID
    curTagID = curTagPlayer.GetPlayerID()
    
    for i in range(0, curPlayer.GetRequestCount()):
        requestID = curPlayer.GetRequestID(i)
        type = curPlayer.GetRequestType(i)
        #---¼ì²éÇëÇóÊÇ·ñÒ»ÖÂ---
        if requestID == curTagID and type == requestType:
            #GameWorld.Log("curTagID = %dÇëÇó¼ì²éͨ¹ý"%(curTagID) , curPlayer.GetPlayerID())
            return True
        
    #GameWorld.Log("Ë«·½ÇëÇóID²»Í¬»ò×é¶ÓÀàÐͲ»ÕýÈ· , ÇëÇóʧ°Ü" , curPlayer.GetPlayerID(), curTagID)
    return False
#---------------------------------------------------------------------
## É¾³ýÖ¸¶¨ÇëÇó
#  @param curPlayer µ±Ç°Íæ¼Ò 
#  @param curTagPlayer Ä¿±êÍæ¼Ò 
#  @param requestType ¶ÔÏóÀàÐÍ
#  @return True or False
#  @remarks É¾³ýÖ¸¶¨ÇëÇó
def DelRequest(curPlayer, curTagPlayer, requestType):
    if curTagPlayer == None:
        return False
    
    #¶ÔÏóID
    curTagID = curTagPlayer.GetPlayerID()
    
    for i in range(0, curPlayer.GetRequestCount()):
        requestID = curPlayer.GetRequestID(i)
        type = curPlayer.GetRequestType(i)
        #---¼ì²éÇëÇóÊÇ·ñÒ»ÖÂ---
        if requestID == curTagID and type == requestType:
            #ɾ³ýÖ¸¶¨ÇëÇó
            curPlayer.DeleteRequest(i)
            return True
 
    #GameWorld.Log("Ë«·½ÇëÇóID²»Í¬»ò×é¶ÓÀàÐͲ»ÕýÈ· , ÇëÇóʧ°Ü" , curPlayer.GetPlayerID(), curTagID)
    return False
#---------------------------------------------------------------------
## Ë¢ÐÂÍæ¼ÒÇëÇó (²ÎÊý -> µ±Ç°Íæ¼Ò,µ±Ç°Ê±¼ä)
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def ProcessPlayerRequest(curPlayer, tick):
    #ÏÂÏß²»±£´æ ¿É²»´¦Àí
    return 
    if not GameWorld.RefurbishPlayerTick(curPlayer, ChConfig.TYPE_Player_Tick_Requestkey, tick):
        return
 
    #Íæ¼ÒÇëÇó´ÎÊý
    requestCount = curPlayer.GetRequestCount()
    curIndex = 0
    
    while curIndex < requestCount:  
        #»ñµÃÇëÇó¿ªÊ¼Ê±¼ä
        requestTick = curPlayer.GetRequestTick(curIndex)
        
        if requestTick == 0:
            curIndex += 1
            continue
        
        #--ÑéÖ¤ÊÇ·ñ³¬¹ý×î´óʱ¼ä--
        requestMaxTick = curPlayer.GetRequestMaxTick(curIndex)
        
        if (tick - requestTick) < requestMaxTick:
            curIndex += 1
            continue
        
        curPlayer.DeleteRequest(curIndex)
        #GameWorld.Log("ÇëÇóÏìÓ¦ = %s³¬Ê±,״̬ÒÑÇå³ý"%(curIndex) , curPlayer.GetPlayerID())
        requestCount = curPlayer.GetRequestCount()
    
    return
#---------------------------------------------------------------------
 
# paramΪÇëÇóÕß ±»ÇëÇóÕß ÇëÇóÀàÐÍ£¬´æ´¢¸ñʽΪ{±»ÇëÇóÕß:[ÇëÇ󷢯ðÕߣ¬·¢ÆðÀàÐÍ]}
def PYAddRequest(curPlayer, curTagPlayerID, requestType):
    if curTagPlayerID not in PyGameData.g_playerRequests:
        PyGameData.g_playerRequests[curTagPlayerID] = {}
        
    PyGameData.g_playerRequests[curTagPlayerID][(curPlayer.GetID(), requestType)] = [curPlayer.GetName(), 
                                                                                     curPlayer.GetLV(),
                                                                                     curPlayer.GetOfficialRank(),
                                                                                     curPlayer.GetFace(),
                                                                                     curPlayer.GetFacePic()]
    return
 
 
# ¼ì²éÇëÇóÐÅÏ¢, curTagPlayerΪ»ØÓ¦ÇëÇóÕß
def PYCheckRequest(requestPlayeID, curTagPlayer, requestType):
    #¶ÔÏóID
    curTagID = curTagPlayer.GetPlayerID()
    if curTagID not in PyGameData.g_playerRequests:
        return False
    
    if (requestPlayeID, requestType) not in PyGameData.g_playerRequests[curTagID]:
        return False
    
    PyGameData.g_playerRequests[curTagID].pop((requestPlayeID, requestType))
    return True
 
 
# ÊÇ·ñÇëÇóÖÐ
def IsRequesting(playerID, tagID, requestType):
    if tagID not in PyGameData.g_playerRequests:
        return False
    
    if (playerID, requestType) not in PyGameData.g_playerRequests[tagID]:
        return False
    return True
 
 
# Í¨Öª±»ÇëÇóÐÅÏ¢,ÔÝÇÒֻ֪ͨºÃÓÑ
def Sync_LoginRequest(curPlayer):
    playerID = curPlayer.GetPlayerID()
    if playerID not in PyGameData.g_playerRequests:
        return
    
    for requestInfo, playerInfo in PyGameData.g_playerRequests[playerID].items():
        if requestInfo[1] != IPY_GameServer.reqFriend:
            continue
        askFriendPack = ChPyNetSendPack.tagGCFriendAskIfJoin()
        askFriendPack.AskID = requestInfo[0]
        askFriendPack.Name = playerInfo[0]
        askFriendPack.LV = playerInfo[1]
        askFriendPack.RealmLV = playerInfo[2]
        askFriendPack.Face = playerInfo[3]
        askFriendPack.FacePic = playerInfo[4]
        NetPackCommon.SendFakePack(curPlayer, askFriendPack) 
    
    return