Example #1
0
 public Server(ServerAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, AutoCSer.Net.TcpServer.IServerCallQueueSet serverCallQueue, byte extendCommandBits, Action <SubArray <byte> > onCustomData, ILog log, int callQueueCount, bool isCallQueueLink, bool isSynchronousVerifyMethod)
     : base(attribute, verify, serverCallQueue, extendCommandBits, onCustomData, log, AutoCSer.Threading.ThreadTaskType.TcpInternalServerGetSocket, callQueueCount, isCallQueueLink, isSynchronousVerifyMethod)
 {
     if (!attribute.IsServer)
     {
         Log.Warn("配置未指明的 TCP 服务端 " + ServerAttribute.ServerName, LogLevel.Warn | LogLevel.AutoCSer);
     }
 }
Example #2
0
 public Server(ServerAttribute attribute, Func <System.Net.Sockets.Socket, bool> verify, AutoCSer.Net.TcpServer.IServerCallQueueSet serverCallQueue, Action <SubArray <byte> > onCustomData, ILog log, int callQueueCount, bool isCallQueueLink, bool isSynchronousVerifyMethod)
     : base(attribute, verify, serverCallQueue, onCustomData, log, AutoCSer.Threading.Thread.CallType.TcpInternalServerGetSocket, callQueueCount, isCallQueueLink, isSynchronousVerifyMethod)
 {
     if (!attribute.IsServer)
     {
         Log.Add(AutoCSer.Log.LogType.Warn, "配置未指明的 TCP 服务端 " + ServerAttribute.ServerName);
     }
 }
Example #3
0
 /// <summary>
 /// TCP 内部服务客户端
 /// </summary>
 /// <param name="attribute">TCP服务调用配置</param>
 /// <param name="maxTimeoutSeconds">最大超时秒数</param>
 /// <param name="onCustomData">自定义数据包处理</param>
 /// <param name="log">日志接口</param>
 /// <param name="clientRoute">TCP 客户端路由</param>
 internal Client(ServerAttribute attribute, ushort maxTimeoutSeconds, Action <SubArray <byte> > onCustomData, ILog log, AutoCSer.Net.TcpServer.ClientLoadRoute <ClientSocketSender> clientRoute)
     : base(attribute, maxTimeoutSeconds, onCustomData, log)
 {
     this.clientRoute = clientRoute;
     if (attribute.TcpRegisterName != null)
     {
         tcpRegisterClient = AutoCSer.Net.TcpRegister.Client.Get(attribute.TcpRegisterName, Log);
         tcpRegisterClient.Register(this);
     }
 }
Example #4
0
 /// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 /// <param name="verifyMethod">TCP 验证方法</param>
 /// <param name="clientRoute">TCP 客户端路由</param>
 /// <param name="onCustomData">自定义数据包处理</param>
 /// <param name="log">日志接口</param>
 public TcpInternalClient(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Func <TcpInternalClient, AutoCSer.Net.TcpInternalServer.ClientSocketSender, bool> verifyMethod = null, AutoCSer.Net.TcpServer.ClientLoadRoute <AutoCSer.Net.TcpInternalServer.ClientSocketSender> clientRoute = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("TcpRegister", typeof(AutoCSer.Net.TcpRegister.Server));
     }
     _TcpClient_ = new AutoCSer.Net.TcpInternalServer.Client <TcpInternalClient>(this, attribute, 0, onCustomData, log, clientRoute, verifyMethod ?? (Func <TcpInternalClient, AutoCSer.Net.TcpInternalServer.ClientSocketSender, bool>)_timerVerify_);
     if (attribute.IsAuto)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Example #5
0
 public KFClient(AutoCSer.Net.TcpStaticServer.Client client, AutoCSer.Net.TcpInternalServer.ServerAttribute attribute, KuaFuClientContext clientInfo, Action <KFCallManager.KFClient> onSetSocket)
 {
     this._Attribute  = attribute;
     this.OnSetSocket = onSetSocket;
     this.tcpClient   = client;
     this.tcpClient.OnSetSocket(delegate(ClientSocketBase socket)
     {
         if (socket.IsSocketVersion(ref this._Socket))
         {
             this.OnSetSocket(this);
         }
     });
 }
Example #6
0
        public static AutoCSer.Net.TcpStaticServer.Client NewTcpClient(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute, Action <SubArray <byte> > onCustomData, ILog log, Func <AutoCSer.Net.TcpInternalServer.ClientSocketSender, bool> verifyMethod)
        {
            KfCall.TcpClient = new AutoCSer.Net.TcpStaticServer.Client(attribute, onCustomData, log, verifyMethod);
            CommandBase tcpClient = KfCall.TcpClient;

            Type[] array = new Type[7];
            array[0] = typeof(KfCall._p12);
            array[1] = typeof(KfCall._p15);
            array[2] = typeof(KfCall._p18);
            array[3] = typeof(KfCall._p27);
            array[4] = typeof(KfCall._p29);
            array[5] = typeof(KfCall._p30);
            Type[] simpleSerializeTypes = array;
            array    = new Type[4];
            array[0] = typeof(KfCall._p6);
            array[1] = typeof(KfCall._p10);
            array[2] = typeof(KfCall._p31);
            Type[] simpleDeSerializeTypes = array;
            array     = new Type[12];
            array[0]  = typeof(KfCall._p1);
            array[1]  = typeof(KfCall._p3);
            array[2]  = typeof(KfCall._p5);
            array[3]  = typeof(KfCall._p7);
            array[4]  = typeof(KfCall._p9);
            array[5]  = typeof(KfCall._p11);
            array[6]  = typeof(KfCall._p19);
            array[7]  = typeof(KfCall._p20);
            array[8]  = typeof(KfCall._p22);
            array[9]  = typeof(KfCall._p23);
            array[10] = typeof(KfCall._p25);
            Type[] serializeTypes = array;
            array     = new Type[12];
            array[0]  = typeof(KfCall._p2);
            array[1]  = typeof(KfCall._p4);
            array[2]  = typeof(KfCall._p8);
            array[3]  = typeof(KfCall._p13);
            array[4]  = typeof(KfCall._p14);
            array[5]  = typeof(KfCall._p16);
            array[6]  = typeof(KfCall._p17);
            array[7]  = typeof(KfCall._p21);
            array[8]  = typeof(KfCall._p24);
            array[9]  = typeof(KfCall._p26);
            array[10] = typeof(KfCall._p28);
            Type[] deSerializeTypes = array;
            array = new Type[1];
            Type[] jsonSerializeTypes = array;
            array = new Type[1];
            tcpClient.ClientCompileSerialize(simpleSerializeTypes, simpleDeSerializeTypes, serializeTypes, deSerializeTypes, jsonSerializeTypes, array);
            return(KfCall.TcpClient);
        }
Example #7
0
 public static void StartServices()
 {
     AsyncDataItem.InitKnownTypes();
     ConfigData.InitConfig();
     RemotingConfiguration.Configure(Process.GetCurrentProcess().MainModule.FileName + ".config", false);
     AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = AutoCSer.Net.TcpStaticServer.ServerAttribute.GetConfig("K", typeof(ZhanDuiZhengBa_K), true);
     attribute.IsAutoServer            = true;
     attribute.Port                    = ConfigData.ServicePort;
     attribute.Host                    = ConfigData.ServiceHost;
     attribute.SendBufferSize          = Size.Kilobyte64;
     attribute.ReceiveBufferSize       = Size.Kilobyte64;
     attribute.ServerSendBufferMaxSize = 33554432;
     attribute.ClientSendBufferMaxSize = 4194304;
     Program.AutoCserServices.Add(new KfCall(attribute, null, null, null));
 }
Example #8
0
        /// <summary>
        /// 时间验证客户端验证
        /// </summary>
        /// <param name="verify">时间验证服务客户端委托</param>
        /// <param name="sender"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        public unsafe static bool Verify(Verifier verify, ClientSocketSender sender, AutoCSer.Net.TcpInternalServer.Client client)
        {
            long            ticks;
            ServerAttribute attribute    = client.Attribute;
            string          verifyString = attribute.VerifyString;

            if (verifyString == null)
            {
                ticks = 0;
                return(verify(sender, 0, null, ref ticks).Value);
            }
            ulong markData = 0;

            if (attribute.IsMarkData)
            {
                markData = attribute.VerifyHashCode;
            }
            ticks = Date.NowTime.SetUtc().Ticks;
            TcpServer.ClientSocketBase socket = sender.ClientSocket;
            do
            {
                ulong randomPrefix = Random.Default.SecureNextULongNotZero();
                while (randomPrefix == markData)
                {
                    randomPrefix = Random.Default.SecureNextULongNotZero();
                }
                socket.ReceiveMarkData = attribute.IsMarkData ? markData ^ randomPrefix : 0UL;
                sender.SendMarkData    = 0;
                long lastTicks = ticks;
                TcpServer.ReturnValue <bool> isVerify = verify(sender, randomPrefix, TcpServer.TimeVerifyServer.Md5(verifyString, randomPrefix, ticks), ref ticks);
                if (isVerify.Value)
                {
                    sender.SendMarkData = socket.ReceiveMarkData;
                    return(true);
                }
                if (isVerify.Type != TcpServer.ReturnType.Success || ticks <= lastTicks)
                {
                    socket.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证失败 [" + isVerify.Type.ToString() + "] " + ticks.toString() + " <= " + lastTicks.toString());
                    return(false);
                }
                socket.Log.Add(AutoCSer.Log.LogType.Error, "TCP客户端验证时间失败重试 " + ticks.toString() + " - " + lastTicks.toString());
            }while (true);
        }
Example #9
0
        private static void NewKFClient(string host, int port)
        {
            AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = new AutoCSer.Net.TcpInternalServer.ServerAttribute();
            attribute.IsAutoClient            = true;
            attribute.Host                    = host;
            attribute.Port                    = port;
            attribute.ServerSendBufferMaxSize = 33554432;
            attribute.ClientSendBufferMaxSize = 4194304;
            KuaFuClientContext clientInfo = new KuaFuClientContext();

            clientInfo.ServerId      = GameManager.ServerId;
            clientInfo.Token         = GameCoreInterface.getinstance().GetLocalAddressIPs();
            KFCallManager.Host       = host;
            KFCallManager.Port       = port;
            KFCallManager.ClientInfo = clientInfo;
            AutoCSer.Net.TcpStaticServer.Client tcpClient = KfCall.NewTcpClient(attribute, null, MyLogAdapter.GetILog(), new Func <AutoCSer.Net.TcpInternalServer.ClientSocketSender, bool>(KFCallManager.verifyMethod));
            KFCallManager.Current = new KFCallManager.KFClient(tcpClient, attribute, clientInfo, new Action <KFCallManager.KFClient>(KFCallManager.OnSetSocket));
            tcpClient.TryCreateSocket();
        }