Пример #1
0
        public bool InitGameDbConnection(int serverId, string ip, int port, string logIp, int logPort)
        {
            bool init = false;
            KuaFuDbConnection pool;

            lock (this.DbMutex)
            {
                if (!this.GameDbConnectPoolDict.TryGetValue(serverId, out pool))
                {
                    pool = new KuaFuDbConnection(serverId);
                    pool.LastHeartTicks = TimeUtil.NOW();
                    this.GameDbConnectPoolDict[serverId] = pool;
                    init = true;
                }
                else
                {
                    pool.Pool[0].ChangeIpPort(ip, port);
                    pool.Pool[1].ChangeIpPort(logIp, logPort);
                }
            }
            bool result;

            if (init)
            {
                result = (pool.Pool[0].Init(3, ip, port, string.Format("server_db_{0}", serverId)) && pool.Pool[1].Init(3, logIp, logPort, string.Format("server_log_{0}", serverId)));
            }
            else
            {
                result = (pool.Pool[0].Supply() && pool.Pool[1].Supply());
            }
            return(result);
        }
Пример #2
0
        public bool InitGameDbConnection(int serverId, string ip, int port, string logIp, int logPort)
        {
            KuaFuDbConnection pool;
            bool init = false;

            lock (DbMutex)
            {
                if (!GameDbConnectPoolDict.TryGetValue(serverId, out pool))
                {
                    pool = new KuaFuDbConnection(serverId);

                    GameDbConnectPoolDict[serverId] = pool;
                    init = true;
                }
                else
                {
                    pool.Pool[0].ChangeIpPort(ip, port);
                    pool.Pool[1].ChangeIpPort(logIp, logPort);
                }
            }

            if (init)
            {
                if (!pool.Pool[0].Init(3, ip, port, string.Format("server_db_{0}", serverId)) || !pool.Pool[1].Init(3, logIp, logPort, string.Format("server_log_{0}", serverId)))
                {
                    return(false);
                }
            }
            else
            {
                return(pool.Pool[0].Supply() && pool.Pool[1].Supply());
            }

            return(true);
        }