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; } }
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; } }