Ejemplo n.º 1
0
        public List<AllyData> AllyAcceptList(int unionID)
        {
            lock (_Mutex)
            {
                List<KFAllyData> acceptList = InitAllyAcceptList(unionID);

                List<AllyData> list = new List<AllyData>();
                foreach (KFAllyData rData in acceptList)
                {
                    AllyData d = new AllyData();
                    d.Copy(rData);
                    list.Add(d);
                }

                return list;
            }
        }
Ejemplo n.º 2
0
        //Agree
        public int OperateAgree(int serverID, int unionID, int targetID)
        {
            lock (_Mutex)
            {
                KFAllyData targetData = GetUnionData(targetID);
                if (targetData == null) return (int)EAlly.ENoTargetUnion;

                if (!UnionIsAccept(unionID, targetID)) return (int)EAlly.EFail;
                if (!UnionIsRequest(targetID, unionID)) return (int)EAlly.EFail;

                //num
                int sum = _allyDic[unionID].Count + _requestDic[unionID].Count;
                if (sum >= Consts.AllyNumMax) return (int)EAlly.EAllyMax;

                DateTime logTime = DateTime.Now;
                int logState = (int)EAlly.AllyAgree;

                bool isDB = AllyPersistence.Instance.DBAllyRequestDel(targetID, unionID);
                if (!isDB) return (int)EAlly.EFail;

                isDB = AllyPersistence.Instance.DBAllyAdd(unionID, targetID, logTime);
                if (!isDB) return (int)EAlly.EFail;

                //my
                KFAllyData aData = GetAcceptData(unionID, targetID);
                _acceptDic[unionID].Remove(aData);
                ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyAcceptRemove, unionID, targetID));

                _allyDic[unionID].Add(targetID);
                aData.LogTime = logTime;
                aData.LogState = logState;

                AllyData clientMy = new AllyData();
                clientMy.Copy(aData);
                ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.Ally, unionID, clientMy, false));

                //target
                if (_requestDic.ContainsKey(targetID))
                {
                    KFAllyData rData = GetRequestData(targetID, unionID);
                    _requestDic[targetID].Remove(rData);
                }

                if (_allyDic.ContainsKey(targetID)) _allyDic[targetID].Add(unionID);

                KFAllyData myData = GetUnionData(unionID);
                myData.LogTime = logTime;
                myData.LogState = logState;

                AllyLogData logData = new AllyLogData();
                logData.UnionID = myData.UnionID;
                logData.UnionZoneID = myData.UnionZoneID;
                logData.UnionName = myData.UnionName;
                logData.MyUnionID = targetID;
                logData.LogTime = logTime;
                logData.LogState = (int)EAlly.AllyAgreeOther;

                AllyData clientTarget = new AllyData();
                clientTarget.Copy(myData);

                if (IsAgent(targetData.ServerID))
                {                             
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.Ally, targetID, clientTarget, true));
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyRequestRemove, targetID, unionID));
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyLog, targetID, new List<AllyLogData>() { logData }));
                }
                else
                {
                    AllyPersistence.Instance.DBAllyLogAdd(logData);
                }

                ClientAgentManager.Instance().KFBroadCastAsyncEvent(_gameType, new AsyncDataItem(KuaFuEventTypes.KFAlly, clientMy, clientTarget));
                return (int)EAlly.AllyAgree;
            }
        }
Ejemplo n.º 3
0
        public AllyData AllyRequest(int serverID, int unionID, int zoneID, string unionName)
        {
            lock (_Mutex)
            {
                AllyData clientRequest = new AllyData();
                if (!IsAgent(serverID))
                {
                    clientRequest.LogState = (int)EAlly.EServer;
                    return clientRequest;
                }

                KFAllyData targetData = GetUnionData(zoneID, unionName);
                if (targetData == null)
                {
                    clientRequest.LogState = (int)EAlly.EName;
                    return clientRequest;
                }

                InitAllyIDList(targetData.UnionID);
                InitAllyRequestList(targetData.UnionID);
                InitAllyAcceptList(targetData.UnionID);

                if (UnionIsAlly(unionID, targetData.UnionID))
                {
                    clientRequest.LogState = (int)EAlly.EIsAlly;
                    return clientRequest;
                }

                if (UnionIsRequest(unionID, targetData.UnionID) || UnionIsAccept(targetData.UnionID, unionID))
                {
                    clientRequest.LogState = (int)EAlly.EMore;
                    return clientRequest;
                }

                int sum = _allyDic[unionID].Count + _requestDic[unionID].Count;
                if (sum >= Consts.AllyNumMax)
                {
                    clientRequest.LogState = (int)EAlly.EAllyMax;
                    return clientRequest;
                }

                DateTime logTime = DateTime.Now;
                int logState = (int)EAlly.AllyRequestSucc;
                bool isAdd = AllyPersistence.Instance.DBAllyRequestAdd(unionID, targetData.UnionID, logTime, logState);
                if (!isAdd)
                {
                    clientRequest.LogState = (int)EAlly.EAllyRequest;
                    return clientRequest;
                }
                //my
                KFAllyData myData = GetUnionData(unionID);

                AllyLogData logData = new AllyLogData();
                logData.UnionID = targetData.UnionID;
                logData.UnionZoneID = targetData.UnionZoneID;
                logData.UnionName = targetData.UnionName;
                logData.MyUnionID = unionID;
                logData.LogTime = logTime;
                logData.LogState = logState;
                ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyLog, unionID, new List<AllyLogData>() { logData }));


                KFAllyData requestData = new KFAllyData();
                requestData.Copy(targetData);
                requestData.LogState = logState;
                requestData.LogTime = logTime;
                requestData.UpdateLogtime();

                AllyRequestAdd(unionID, requestData);

                clientRequest.Copy(requestData);
                // ClientAgentManager.Instance().PostAsyncEvent(serverID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyRequest, unionID, clientRequest));

                //target
                KFAllyData acceptData = new KFAllyData();
                acceptData.Copy(myData);
                acceptData.LogState = logState;
                acceptData.LogTime = logTime;
                AllyAcceptAdd(targetData.UnionID, acceptData);

                if (IsAgent(targetData.ServerID))
                {
                    AllyData clientAccept = new AllyData();
                    clientAccept.Copy(acceptData);
                    ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyAccept, targetData.UnionID, clientAccept));
                }

                return clientRequest;
            }
        }
Ejemplo n.º 4
0
        public int UnionDataChange(int serverID, AllyData newData)
        {
            if (!IsAgent(serverID)) return (int)EAlly.EServer;

            lock (_Mutex)
            {
                //获取老的数据,更新状态,logtime
                KFAllyData kfData = new KFAllyData();
                kfData.Copy(newData);
                kfData.LogTime = DateTime.Now;
                kfData.ServerID = serverID;
                kfData.UpdateLogtime();

                bool result = AllyPersistence.Instance.DBUnionDataUpdate(kfData);
                if (!result) return (int)EAlly.EFail;

                KFAllyData oldData;
                if (_unionDic.TryGetValue(kfData.UnionID, out oldData))
                    _unionDic[kfData.UnionID] = kfData;
                else
                    _unionDic.TryAdd(kfData.UnionID, kfData);             

                //结盟数据
                List<int> oldAllyIDList;
                if (_allyDic.TryGetValue(kfData.UnionID, out oldAllyIDList))
                {
                    AllyData myData = new AllyData();
                    myData.Copy(kfData);
                    myData.LogState = (int)EAlly.AllyAgree;

                    foreach (int id in oldAllyIDList)
                    {
                        KFAllyData targetData = GetUnionData(id);
                        if (IsAgent(targetData.ServerID))
                            ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyUnionUpdate, targetData.UnionID, myData));
                    }
                }

                AllyData myData2 = new AllyData();
                myData2.Copy(kfData);
                myData2.LogState = (int)EAlly.AllyRequestSucc;
                //结盟请求
                List<KFAllyData> rList = null;
                if (_requestDic.TryGetValue(kfData.UnionID, out rList))
                {     
                    foreach (KFAllyData targetData in rList)
                    {
                        List<KFAllyData> raList = null;
                        if (IsAgent(targetData.ServerID) && _acceptDic.TryGetValue(targetData.UnionID, out raList))
                        {
                            KFAllyData oldAData = GetAcceptData(targetData.UnionID, kfData.UnionID);
                            if (oldAData != null)
                            {
                                raList.Remove(oldAData);
                                raList.Add(kfData);
                                ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyUnionUpdate, targetData.UnionID, myData2));
                            }
                        } 
                    }
                }

                //接受请求
                List<KFAllyData> aList = null;
                if (_acceptDic.TryGetValue(kfData.UnionID, out aList))
                {
                    foreach (KFAllyData targetData in aList)
                    {
                        List<KFAllyData> arList = null;
                        if (IsAgent(targetData.ServerID) && _requestDic.TryGetValue(targetData.UnionID, out arList))
                        {
                            KFAllyData oldRData = GetRequestData(targetData.UnionID, kfData.UnionID);
                            if (oldRData != null)
                            {
                                arList.Remove(oldRData);
                                arList.Add(kfData);
                                ClientAgentManager.Instance().PostAsyncEvent(targetData.ServerID, _gameType, new AsyncDataItem(KuaFuEventTypes.AllyUnionUpdate, targetData.UnionID, myData2));
                            }
                        }
                    }
                }

                return (int)EAlly.Succ;
            }
        }