コード例 #1
0
        private static void initThrift(IGateway gw)
        {
            G.DefaultGateway = gw;
            var cp          = new ClientProcessor(gw);
            var t_processor = new Client.GW.Processor(cp);
            var transport   = new Thrift.Transport.TServerSocket(6325, 100000, true);

            System.Threading.ThreadPool.SetMinThreads(1, 0);
            var tps = new Thrift.Server.TThreadPoolServer(t_processor, transport);

            Task.Run(() =>
            {
                Console.WriteLine($"{gw.GetPrimaryKeyString()}:Task: thrift started");
                System.Threading.ThreadPool.GetMaxThreads(out var wt, out var cpt);
                Console.WriteLine($"ThreadPool maxwt:{wt} maxcpt:{cpt}");
                tps.Serve();
            });
            Task.Run(() =>
            {//心跳检测,如果客户端长时间没有发起thrift请求,那么回收token,类似udp判断玩家是否断线
                while (true)
                {
                    cp.CheckHeartbeat(); Thread.Sleep(1000);
                }
            });
        }
コード例 #2
0
    public string auth(string name)
    {
        Console.WriteLine($"{ gGateway.GetPrimaryKeyString()}:player auth:{name}");
        //todo 这里直接用name 作为sid
        var sid = "sid_" + name;
        var bp  = GrainClient.GrainFactory.GetGrain <IPlayer>(name);

        Debug.Assert(bp != null);
        allPlayersBySid[sid]      = bp;
        allPlayerAccidBySid[sid]  = name;
        allPlayerEventBuffer[sid] = new EventBuffer(sid);
        AllTokens[sid]            = new TokenInfo()
        {
            LastHeartBeat = DateTime.Now, AccountName = name, SessionId = sid, PlayerName = string.Empty
        };

        return(sid);
    }