Exemple #1
0
        public List <KFRankData> HRankTopList(int rankType)
        {
            List <KFRankData> list = new List <KFRankData>();

            lock (this._lockRank)
            {
                if (this._rankTopDic.TryGetValue(rankType, out list))
                {
                    return(list);
                }
                IAllyService kuaFuService = this.GetKuaFuService(false);
                if (null == kuaFuService)
                {
                    return(list);
                }
                try
                {
                    list = kuaFuService.RankTopList(this._ClientInfo.ServerId, rankType);
                    if (list != null)
                    {
                        this._rankTopDic.Add(rankType, list);
                    }
                }
                catch (Exception ex)
                {
                    this.ResetKuaFuService();
                    LogManager.WriteLog(LogTypes.Error, "HRankList Error{0}", ex, true);
                }
            }
            return(list);
        }
Exemple #2
0
 private void ResetKuaFuService()
 {
     _RemoteServiceUri = _CoreInterface.GetRuntimeVariable(RuntimeVariableNames.AllyUri, null);
     lock (_Mutex)
     {
         _KuaFuService = null;
     }
 }
Exemple #3
0
        private IAllyService GetKuaFuService(bool noWait = false)
        {
            IAllyService kuaFuService = null;
            int          clientId     = -1;

            try
            {
                lock (_Mutex)
                {
                    if (string.IsNullOrEmpty(_RemoteServiceUri))
                    {
                        return(null);
                    }

                    if (null == _KuaFuService && noWait)
                    {
                        return(null);
                    }
                }

                lock (_RemotingMutex)
                {
                    if (_KuaFuService == null)
                    {
                        kuaFuService = (IAllyService)Activator.GetObject(typeof(IAllyService), _RemoteServiceUri);
                        if (null == kuaFuService)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        kuaFuService = _KuaFuService;
                    }

                    clientId = kuaFuService.InitializeClient(this, _ClientInfo);
                    if (null != kuaFuService && (clientId != _ClientInfo.ClientId || _KuaFuService != kuaFuService))
                    {
                        lock (_Mutex)
                        {
                            _KuaFuService        = kuaFuService;
                            _ClientInfo.ClientId = clientId;
                            return(kuaFuService);
                        }
                    }

                    return(_KuaFuService);
                }
            }
            catch (System.Exception ex)
            {
                ResetKuaFuService();
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(null);
        }
Exemple #4
0
        public EAlly HAllyRequest(int unionID, int zoneID, string unionName)
        {
            AllyData result = null;

            try
            {
                lock (_Mutex)
                {
                    if (!VersionIsEqual())
                    {
                        _unionDic.Clear();
                        _allyDic.Clear();
                        _requestDic.Clear();
                        _acceptDic.Clear();

                        _CoreInterface.GetEventSourceInterface().fireEvent(new KFNotifyAllyStartGameEvent(), (int)_sceneType);
                        return(EAlly.EFail);
                    }

                    IAllyService kuaFuService = GetKuaFuService();
                    if (null == kuaFuService)
                    {
                        return(EAlly.EServer);
                    }

                    try
                    {
                        AllyData d = kuaFuService.AllyRequest(_ClientInfo.ServerId, unionID, zoneID, unionName);
                        if (d.LogState == (int)EAlly.AllyRequestSucc)
                        {
                            List <AllyData> list = null;
                            if (!_requestDic.TryGetValue(unionID, out list))
                            {
                                list = new List <AllyData>()
                                {
                                };
                                _requestDic.TryAdd(unionID, list);
                            }

                            list.Add(d);
                            return((EAlly)d.LogState);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ResetKuaFuService();
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(EAlly.EAllyRequest);
        }
Exemple #5
0
        public KFRankData HRankData(int rankType, int roleID)
        {
            KFRankData result;

            lock (this._lockRank)
            {
                if (this._rankTopDic.ContainsKey(rankType))
                {
                    List <KFRankData> list = this._rankTopDic[rankType];
                    KFRankData        data = list.Find((KFRankData _x) => _x != null && _x.RoleID == roleID);
                    if (data != null)
                    {
                        return(data);
                    }
                }
                if (this._rankDic.ContainsKey(rankType))
                {
                    Dictionary <int, KFRankData> dic = this._rankDic[rankType];
                    if (dic.ContainsKey(roleID))
                    {
                        return(dic[roleID]);
                    }
                }
                else
                {
                    this._rankDic.Add(rankType, new Dictionary <int, KFRankData>());
                }
                IAllyService kuaFuService = this.GetKuaFuService(false);
                if (null == kuaFuService)
                {
                    result = null;
                }
                else
                {
                    try
                    {
                        KFRankData data = kuaFuService.RankRole(this._ClientInfo.ServerId, rankType, roleID);
                        if (data != null)
                        {
                            this._rankDic[rankType].Add(roleID, data);
                        }
                        return(data);
                    }
                    catch (Exception ex)
                    {
                        this.ResetKuaFuService();
                    }
                    result = null;
                }
            }
            return(result);
        }
Exemple #6
0
        public EAlly HUnionDataChange(AllyData unionData)
        {
            EAlly result = EAlly.EFail;

            try
            {
                lock (_Mutex)
                {
                    IAllyService kuaFuService = GetKuaFuService();
                    if (null == kuaFuService)
                    {
                        return(result);
                    }

                    try
                    {
                        result = (EAlly)kuaFuService.UnionDataChange(_ClientInfo.ServerId, unionData);
                        if (result == EAlly.Succ)
                        {
                            int unionID = unionData.UnionID;

                            DateTime oldTime;
                            if (_unionDic.TryGetValue(unionID, out oldTime))
                            {
                                _unionDic[unionID] = DateTime.Now;
                                return(EAlly.Succ);
                            }
                            else
                            {
                                _unionDic.TryAdd(unionID, DateTime.Now);

                                HAllyDataList(unionID, EAllyDataType.Ally);
                                HAllyDataList(unionID, EAllyDataType.Request);
                                HAllyDataList(unionID, EAllyDataType.Accept);
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ResetKuaFuService();
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(result);
        }
Exemple #7
0
        public List <AllyData> HAllyDataList(int unionID, EAllyDataType type)
        {
            List <AllyData> list = new List <AllyData>();

            lock (_Mutex)
            {
                ConcurrentDictionary <int, List <AllyData> > dic = null;
                switch (type)
                {
                case EAllyDataType.Ally:
                    dic = _allyDic;
                    break;

                case EAllyDataType.Request:
                    dic = _requestDic;
                    break;

                case EAllyDataType.Accept:
                    dic = _acceptDic;
                    break;
                }

                if (dic.TryGetValue(unionID, out list))
                {
                    return(list);
                }

                IAllyService kuaFuService = GetKuaFuService();
                if (null == kuaFuService)
                {
                    return(list);
                }

                try
                {
                    list = kuaFuService.AllyDataList(_ClientInfo.ServerId, unionID, (int)type);
                    if (list != null)
                    {
                        dic.TryAdd(unionID, list);
                    }
                }
                catch (System.Exception ex)
                {
                    ResetKuaFuService();
                }
            }

            return(list);
        }
Exemple #8
0
        private bool VersionIsEqual()
        {
            lock (_Mutex)
            {
                IAllyService kuaFuService = GetKuaFuService(true);
                if (null == kuaFuService)
                {
                    return(false);
                }

                long oldVersion = _unionAllyVersion;
                _unionAllyVersion = kuaFuService.UnionAllyVersion(_ClientInfo.ServerId);
                return(_unionAllyVersion == oldVersion && _unionAllyVersion > 0);
            }
        }
Exemple #9
0
 public EAlly HAllyRequest(int unionID, int zoneID, string unionName)
 {
     try
     {
         lock (this._Mutex)
         {
             if (!this.VersionIsEqual())
             {
                 this._unionDic.Clear();
                 this._allyDic.Clear();
                 this._requestDic.Clear();
                 this._acceptDic.Clear();
                 this._CoreInterface.GetEventSourceInterface().fireEvent(new KFNotifyAllyStartGameEvent(), 10004);
                 return(EAlly.EFail);
             }
             IAllyService kuaFuService = this.GetKuaFuService(false);
             if (null == kuaFuService)
             {
                 return(EAlly.EServer);
             }
             try
             {
                 AllyData d = kuaFuService.AllyRequest(this._ClientInfo.ServerId, unionID, zoneID, unionName);
                 if (d.LogState == 1)
                 {
                     List <AllyData> list = null;
                     if (!this._requestDic.TryGetValue(unionID, out list))
                     {
                         list = new List <AllyData>();
                         this._requestDic.TryAdd(unionID, list);
                     }
                     list.Add(d);
                     return((EAlly)d.LogState);
                 }
             }
             catch (Exception ex)
             {
                 this.ResetKuaFuService();
             }
         }
     }
     catch (Exception ex)
     {
         LogManager.WriteExceptionUseCache(ex.ToString());
     }
     return(EAlly.EAllyRequest);
 }
Exemple #10
0
        public void TimerProc(object sender, EventArgs e)
        {
            try
            {
                string uri = _CoreInterface.GetRuntimeVariable(RuntimeVariableNames.AllyUri, null);
                if (_RemoteServiceUri != uri)
                {
                    _RemoteServiceUri = uri;
                }

                IAllyService kuaFuService = GetKuaFuService();
                if (null != kuaFuService)
                {
                    if (_ClientInfo.ClientId > 0)
                    {
                        //同步数据
                        AsyncDataItem[] items = kuaFuService.GetClientCacheItems(_ClientInfo.ServerId);
                        if (null != items && items.Length > 0)
                        {
                            ExecuteEventCallBackAsync(items);
                        }
                    }
                }

                DateTime now = DateTime.Now;
                if (now > _versionTime)
                {
                    _versionTime = now.AddSeconds(ALLY_VERSION_SPAN_SECOND);
                    if (!VersionIsEqual())
                    {
                        _unionDic.Clear();
                        _allyDic.Clear();
                        _requestDic.Clear();
                        _acceptDic.Clear();

                        _CoreInterface.GetEventSourceInterface().fireEvent(new KFNotifyAllyStartGameEvent(), (int)_sceneType);
                    }
                }
            }
            catch (System.Exception ex)
            {
                ResetKuaFuService();
            }
        }
Exemple #11
0
        public EAlly HUnionDataChange(AllyData unionData)
        {
            EAlly result = EAlly.EFail;

            try
            {
                lock (this._Mutex)
                {
                    IAllyService kuaFuService = this.GetKuaFuService(false);
                    if (null == kuaFuService)
                    {
                        return(result);
                    }
                    try
                    {
                        result = (EAlly)kuaFuService.UnionDataChange(this._ClientInfo.ServerId, unionData);
                        if (result == EAlly.Succ)
                        {
                            int      unionID = unionData.UnionID;
                            DateTime oldTime;
                            if (this._unionDic.TryGetValue(unionID, out oldTime))
                            {
                                this._unionDic[unionID] = TimeUtil.NowDateTime();
                                return(EAlly.Succ);
                            }
                            this._unionDic.TryAdd(unionID, TimeUtil.NowDateTime());
                            this.HAllyDataList(unionID, EAllyDataType.Ally);
                            this.HAllyDataList(unionID, EAllyDataType.Request);
                            this.HAllyDataList(unionID, EAllyDataType.Accept);
                        }
                    }
                    catch (Exception ex)
                    {
                        this.ResetKuaFuService();
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }
            return(result);
        }
Exemple #12
0
        private bool VersionIsEqual()
        {
            bool result;

            lock (this._Mutex)
            {
                IAllyService kuaFuService = this.GetKuaFuService(true);
                if (null == kuaFuService)
                {
                    result = false;
                }
                else
                {
                    long oldVersion = this._unionAllyVersion;
                    this._unionAllyVersion = kuaFuService.UnionAllyVersion(this._ClientInfo.ServerId);
                    result = (this._unionAllyVersion == oldVersion && this._unionAllyVersion > 0L);
                }
            }
            return(result);
        }
Exemple #13
0
        public EAlly HUnionDel(int unionID)
        {
            EAlly result = EAlly.EFail;

            try
            {
                lock (_Mutex)
                {
                    IAllyService kuaFuService = GetKuaFuService();
                    if (null == kuaFuService)
                    {
                        return(result);
                    }

                    try
                    {
                        result = (EAlly)kuaFuService.UnionDel(_ClientInfo.ServerId, unionID);
                        if (result == EAlly.Succ)
                        {
                            DateTime        oldTime;
                            List <AllyData> list;
                            _unionDic.TryRemove(unionID, out oldTime);
                            _allyDic.TryRemove(unionID, out list);
                            _requestDic.TryRemove(unionID, out list);
                            _acceptDic.TryRemove(unionID, out list);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ResetKuaFuService();
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(result);
        }
Exemple #14
0
 public void TimerProc(object sender, EventArgs e)
 {
     try
     {
         string uri = this._CoreInterface.GetRuntimeVariable("AllyUri", null);
         if (this._RemoteServiceUri != uri)
         {
             this._RemoteServiceUri = uri;
         }
         IAllyService kuaFuService = this.GetKuaFuService(false);
         if (null != kuaFuService)
         {
             if (this._ClientInfo.ClientId > 0)
             {
                 AsyncDataItem[] items = kuaFuService.GetClientCacheItems(this._ClientInfo.ServerId);
                 if (items != null && items.Length > 0)
                 {
                     this.ExecuteEventCallBackAsync(items);
                 }
             }
         }
         DateTime now = TimeUtil.NowDateTime();
         if (now > this._versionTime)
         {
             this._versionTime = now.AddSeconds(30.0);
             if (!this.VersionIsEqual())
             {
                 this._unionDic.Clear();
                 this._allyDic.Clear();
                 this._requestDic.Clear();
                 this._acceptDic.Clear();
                 this._CoreInterface.GetEventSourceInterface().fireEvent(new KFNotifyAllyStartGameEvent(), 10004);
             }
         }
     }
     catch (Exception ex)
     {
         this.ResetKuaFuService();
     }
 }
Exemple #15
0
        public KFRankData HRankUpdate(int rankType, int grade, int roleID, int zoneID, string roleName, byte[] roleData)
        {
            KFRankData result;

            lock (this._lockRank)
            {
                KFRankData myData = new KFRankData();
                myData.RankType = rankType;
                myData.Rank     = -1;
                myData.ZoneID   = zoneID;
                myData.RoleID   = roleID;
                myData.RoleName = roleName;
                myData.Grade    = grade;
                myData.RoleData = roleData;
                myData.RankTime = TimeUtil.NowDateTime();
                myData.ServerID = this._ClientInfo.ServerId;
                IAllyService kuaFuService = this.GetKuaFuService(false);
                if (null == kuaFuService)
                {
                    result = null;
                }
                else
                {
                    try
                    {
                        kuaFuService.RankGradeUpdate(this._ClientInfo.ServerId, myData);
                    }
                    catch (Exception ex)
                    {
                        this.ResetKuaFuService();
                    }
                    result = null;
                }
            }
            return(result);
        }
Exemple #16
0
        public EAlly HAllyOperate(int unionID, int targetID, EAllyOperate operateType)
        {
            EAlly result = EAlly.EFail;

            try
            {
                lock (_Mutex)
                {
                    if (!VersionIsEqual())
                    {
                        _unionDic.Clear();
                        _allyDic.Clear();
                        _requestDic.Clear();
                        _acceptDic.Clear();

                        _CoreInterface.GetEventSourceInterface().fireEvent(new KFNotifyAllyStartGameEvent(), (int)_sceneType);
                        return(result);
                    }

                    ConcurrentDictionary <int, List <AllyData> > dic = null;
                    switch (operateType)
                    {
                    case EAllyOperate.Agree:
                    case EAllyOperate.Refuse:
                        dic = _acceptDic;
                        break;

                    case EAllyOperate.Cancel:
                        dic = _requestDic;
                        break;

                    case EAllyOperate.Remove:
                        dic = _allyDic;
                        break;
                    }

                    List <AllyData> list = null;
                    if (!dic.TryGetValue(unionID, out list))
                    {
                        return(EAlly.ENoTargetUnion);
                    }

                    AllyData targetData = dic[unionID].Find(
                        delegate(AllyData data) { return(data.UnionID == targetID); });
                    if (targetData == null)
                    {
                        return(EAlly.ENoTargetUnion);
                    }

                    IAllyService kuaFuService = GetKuaFuService();
                    if (null == kuaFuService)
                    {
                        return(EAlly.EServer);
                    }

                    try
                    {
                        result = (EAlly)kuaFuService.AllyOperate(_ClientInfo.ServerId, unionID, targetID, (int)operateType);
                        if (result == EAlly.AllyAgree || result == EAlly.AllyRefuse ||
                            result == EAlly.AllyCancelSucc || result == EAlly.AllyRemoveSucc)
                        {
                            dic[unionID].Remove(targetData);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ResetKuaFuService();
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(result);
        }