コード例 #1
0
ファイル: KChannel.cs プロジェクト: qn9663/ET
        // connect
        public KChannel(uint localConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Connect)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.LocalConn      = localConn;
            this.socket         = socket;
            this.remoteEndPoint = remoteEndPoint;
            this.lastRecvTime   = kService.TimeNow;
            this.CreateTime     = kService.TimeNow;
            this.Connect();
        }
コード例 #2
0
ファイル: WChannel.cs プロジェクト: vanex7/ET
        public WChannel(WebSocket webSocket, AService service) : base(service, ChannelType.Connect)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.webSocket = webSocket;

            this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);
            this.recvStream   = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);

            isConnected = false;
        }
コード例 #3
0
        public Task WaitTillAsync(long tillTime)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            return(tcs.Task);
        }
コード例 #4
0
 void GetEnemys(int count)
 {
     for (int i = 0; i < count; i++)
     {
         ///20190702
         Monster enemy = ComponentFactory.CreateWithId <Monster>(IdGenerater.GenerateId());
         enemy.AddComponent <NumericComponent>();
         enemys.Add(enemy.Id, enemy);
     }
     SetPosition(enemys);
 }
コード例 #5
0
ファイル: ObjectPool.cs プロジェクト: isoundy000/ETGame
        public ComponentQueue(string typeName)
        {
            this.Id       = IdGenerater.GenerateId();
            this.TypeName = typeName;
#if !SERVER
            this.ViewGO       = new GameObject();
            this.ViewGO.name  = this.GetType().Name;
            this.ViewGO.layer = LayerNames.GetLayerInt(LayerNames.HIDDEN);
            this.ViewGO.transform.SetParent(Global.transform, false);
            this.ViewGO.AddComponent <ComponentView>().Component = this;
#endif
        }
コード例 #6
0
ファイル: WChannel.cs プロジェクト: dongliang/ET
        public WChannel(HttpListenerWebSocketContext webSocketContext, AService service) : base(service, ChannelType.Accept)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.webSocketContext = webSocketContext;

            this.webSocket = webSocketContext.WebSocket;

            this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);

            isConnected = true;
        }
コード例 #7
0
ファイル: KChannel.cs プロジェクト: Greatdust/ET4.0
        // connect
        public KChannel(uint localConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Connect)
        {
            this.InstanceId   = IdGenerater.GenerateId();
            this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);

            this.LocalConn      = localConn;
            this.socket         = socket;
            this.remoteEndPoint = remoteEndPoint;
            this.lastRecvTime   = kService.TimeNow;
            this.createTime     = kService.TimeNow;
            this.Connect();
        }
コード例 #8
0
        public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            cancellationToken.Register(() => { this.Remove(timer.Id); });
            return(tcs.Task);
        }
コード例 #9
0
        protected Component()
        {
            this.InstanceId = IdGenerater.GenerateId();
#if !SERVER
            if (!this.GetType().IsDefined(typeof(HideInHierarchy), true))
            {
                this.GameObject       = new GameObject();
                this.GameObject.name  = this.GetType().Name;
                this.GameObject.layer = LayerNames.GetLayerInt(LayerNames.HIDDEN);
                this.GameObject.AddComponent <ComponentView>().Component = this;
            }
#endif
        }
コード例 #10
0
ファイル: TService.cs プロジェクト: Xumudada/ET-Modules
        /// <summary>
        /// 即可做client也可做server
        /// </summary>
        public TService(IPEndPoint ipEndPoint, Action <AChannel> acceptCallback)
        {
            this.InstanceId      = IdGenerater.GenerateId();
            this.AcceptCallback += acceptCallback;

            this.acceptor = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this.acceptor.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            this.innArgs.Completed += this.OnComplete;

            this.acceptor.Bind(ipEndPoint);
            this.acceptor.Listen(1000);

            this.AcceptAsync();
        }
コード例 #11
0
        public static Scene CreateScene(SceneType sceneType, string name, Scene parent = null, long id = 0)
        {
            Scene scene = (Scene)Game.ObjectPool.Fetch(typeof(Scene));

            scene.Id        = id != 0 ? id : IdGenerater.GenerateId();
            scene.Name      = name;
            scene.SceneType = sceneType;
            if (parent != null)
            {
                scene.Parent = parent;
            }
            scene.Domain = scene;
            return(scene);
        }
コード例 #12
0
        protected Entity()
        {
            this.InstanceId = IdGenerater.GenerateId();

#if !SERVER
            if (!this.GetType().IsDefined(typeof(HideInHierarchy), true))
            {
                this.ViewGO       = new GameObject();
                this.ViewGO.name  = this.GetType().Name;
                this.ViewGO.layer = LayerNames.GetLayerInt(LayerNames.HIDDEN);
                this.ViewGO.transform.SetParent(Global.transform, false);
                this.ViewGO.AddComponent <ComponentView>().Component = this;
            }
#endif
        }
コード例 #13
0
        /// <summary>
        /// 等待指定(毫秒)
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public ETTask WaitForMilliSecondAsync(long time)
        {
            ETTaskCompletionSource tcs = new ETTaskCompletionSource();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = TimeHelper.ClientNowMilliSeconds() + time, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            if (timer.Time < this.minTime)
            {
                this.minTime = timer.Time;
            }
            return(tcs.Task);
        }
コード例 #14
0
ファイル: TChannel.cs プロジェクト: NewCai/ET
        public TChannel(IPEndPoint ipEndPoint, TService service) : base(service, ChannelType.Connect)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.socket             = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this.socket.NoDelay     = true;
            this.parser             = new PacketParser(this.recvBuffer);
            this.innArgs.Completed += this.OnComplete;
            this.outArgs.Completed += this.OnComplete;

            this.RemoteAddress = ipEndPoint;

            this.isConnected = false;
            this.isSending   = false;
        }
コード例 #15
0
ファイル: TimerComponent.cs プロジェクト: yangtzehina/ET
        public ETTask WaitAsync(long time)
        {
            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            if (timer.Time < this.minTime)
            {
                this.minTime = timer.Time;
            }
            return(tcs.Task);
        }
コード例 #16
0
        public ETTask WaitTillAsync(long tillTime)
        {
            ETTaskCompletionSource tcs = new ETTaskCompletionSource();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            if (timer.Time < this.minTime)
            {
                this.minTime = timer.Time;
            }
            return(tcs.Task);
        }
コード例 #17
0
ファイル: TChannel.cs プロジェクト: NewCai/ET
        public TChannel(Socket socket, TService service) : base(service, ChannelType.Accept)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.socket             = socket;
            this.socket.NoDelay     = true;
            this.parser             = new PacketParser(this.recvBuffer);
            this.innArgs.Completed += this.OnComplete;
            this.outArgs.Completed += this.OnComplete;

            this.RemoteAddress = (IPEndPoint)socket.RemoteEndPoint;

            this.isConnected = true;
            this.isSending   = false;
        }
コード例 #18
0
ファイル: TimerComponent.cs プロジェクト: yangtzehina/ET
        public ETTask WaitAsync(long time, CancellationToken cancellationToken)
        {
            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            if (timer.Time < this.minTime)
            {
                this.minTime = timer.Time;
            }
            cancellationToken.Register(() => { this.Remove(timer.Id); });
            return(tcs.Task);
        }
コード例 #19
0
ファイル: TChannel.cs プロジェクト: HusKka/Egametang
        public TChannel(Socket socket, TService service) : base(service, ChannelType.Accept)
        {
            this.InstanceId   = IdGenerater.GenerateId();
            this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);

            this.socket             = socket;
            this.socket.NoDelay     = true;
            this.parser             = new PacketParser(this.recvBuffer, this.memoryStream);
            this.innArgs.Completed += this.OnComplete;
            this.outArgs.Completed += this.OnComplete;

            this.RemoteAddress = (IPEndPoint)socket.RemoteEndPoint;

            this.isConnected = true;
            this.isSending   = false;
        }
コード例 #20
0
ファイル: TChannel.cs プロジェクト: Greatdust/ET4.0
        /// <summary>
        /// 初始化远程端Socket  (这里只是给了远程端的IP,所以并没有和远程端建立连接)
        /// </summary>
        /// <param name="ipEndPoint"></param>
        /// <param name="service"></param>
        public TChannel(IPEndPoint ipEndPoint, TService service) : base(service, ChannelType.Connect)
        {
            this.InstanceId   = IdGenerater.GenerateId();
            this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);

            this.socket             = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this.socket.NoDelay     = true;            // Socket 使用 Nagle 算法
            this.parser             = new PacketParser(this.recvBuffer, this.memoryStream);
            this.innArgs.Completed += this.OnComplete; //接收到数据的回调
            this.outArgs.Completed += this.OnComplete; //接收到数据的回调

            this.RemoteAddress = ipEndPoint;           //得到远程端IP

            this.isConnected = false;
            this.isSending   = false;
        }
コード例 #21
0
        /// <summary>
        /// 设置一个定时器 (定时事件是直接给的时间,而不是多少秒后)
        /// </summary>
        /// <returns>The till async.</returns>
        /// <param name="tillTime">Till time.</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            if (timer.Time < this.minTime)
            {
                this.minTime = timer.Time;
            }
            //监视取消请求。
            cancellationToken.Register(() => { this.Remove(timer.Id); });
            return(tcs.Task);             //如果要返回tcs.Task 那么就需要tcs.SetResult(true) 设置了结果
        }
コード例 #22
0
        // accept
        public KChannel(uint conn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.Id             = conn;
            this.Conn           = conn;
            this.RemoteConn     = remoteConn;
            this.remoteEndPoint = remoteEndPoint;
            this.socket         = socket;
            kcp = new KCP(this.RemoteConn, this);
            kcp.SetOutput(this.Output);
            kcp.NoDelay(1, 10, 2, 1);              //fast
            kcp.SetMTU(470);
            kcp.WndSize(256, 256);
            this.isConnected = true;

            this.lastRecvTime = kService.TimeNow;
        }
コード例 #23
0
        //等待到设定的时间 tillTime
        public ETTask WaitTillAsync(long tillTime, CancellationToken cancellationToken)
        {
            ETTaskCompletionSource tcs = new ETTaskCompletionSource();
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs
            };

            this.timers[timer.Id] = timer;
            this.timeId.Add(timer.Time, timer.Id);
            //缓存最近时间点的Task
            if (timer.Time < this.minTime)
            {
                this.minTime = timer.Time;
            }
            //取消的事件 就是将存储的字典的相同key移除掉
            cancellationToken.Register(() => { this.Remove(timer.Id); });
            return(tcs.Task);
        }
コード例 #24
0
ファイル: TService.cs プロジェクト: Greatdust/ET4.0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="ipEndPoint">本地IP</param>
        /// <param name="acceptCallback">用于处理接收到消息数据的方法</param>
        public TService(IPEndPoint ipEndPoint, Action <AChannel> acceptCallback)
        {
            this.InstanceId      = IdGenerater.GenerateId();
            this.AcceptCallback += acceptCallback;             //处理接收到消息的函数

            this.acceptor = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            // 端口复用。ReuseAddress选项设置为True将允许将套接字绑定到已在使用中的地址。

            /*端口复用真正的用处主要在于服务器编程:当服务器需要重启时,经常会碰到端口尚未完全关闭的情况,这时如果不设置端口复用,则无法完成绑定,因为端口还处于被别的套接口绑定的状态之中。
             * socket1.Bind(localEP);   socket2.Bind(localEP);
             * 这样Socket1和Socket2便绑定在同一个端口上了。
             * */
            this.acceptor.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            this.innArgs.Completed += this.OnComplete;

            this.acceptor.Bind(ipEndPoint); //绑定本地IP
            this.acceptor.Listen(1000);     //监听远程端数量

            this.AcceptAsync();             //开始监听
        }
コード例 #25
0
ファイル: TaskerInfo.cs プロジェクト: xfs81150082/TumoET
        void GetSkillItems()
        {
            TaskerItem item11101 = ComponentFactory.CreateWithId <TaskerItem>(IdGenerater.GenerateId());
            TaskerItem item21101 = ComponentFactory.CreateWithId <TaskerItem>(IdGenerater.GenerateId());
            TaskerItem item31101 = ComponentFactory.CreateWithId <TaskerItem>(IdGenerater.GenerateId());
            TaskerItem item41101 = ComponentFactory.CreateWithId <TaskerItem>(IdGenerater.GenerateId());

            //item11101.AddComponent<NumericComponent>().Set(NumericType.ManageAdd, 10);
            item11101.AddComponent <NumericComponent>().Set(NumericType.ValuationAdd, 10);
            item21101.AddComponent <NumericComponent>().Set(NumericType.ValuationAdd, 12);
            item21101.AddComponent <NumericComponent>().Set(NumericType.ValuationAdd, 12);
            //item31101.AddComponent<NumericComponent>().Set(NumericType.MeasureAdd, 10);
            item31101.AddComponent <NumericComponent>().Set(NumericType.ValuationAdd, 10);
            item41101.AddComponent <NumericComponent>().Set(NumericType.CaseAdd, 14);
            item41101.AddComponent <NumericComponent>().Set(NumericType.ValuationAdd, 14);

            idTaskerItems.Add(item11101.Id, item11101);
            idTaskerItems.Add(item21101.Id, item21101);
            idTaskerItems.Add(item31101.Id, item31101);
            idTaskerItems.Add(item41101.Id, item41101);
        }
コード例 #26
0
        public override void EndInit()
        {
            try
            {
                this.InstanceId = IdGenerater.GenerateId();

                this.componentDict.Clear();

                if (this.components != null)
                {
                    foreach (Component component in this.components)
                    {
                        component.Parent = this;
                        this.componentDict.Add(component.GetType(), component);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #27
0
        //从现在起 等待N毫秒后
        public ETTask WaitAsync(long time)
        {
            ETTaskCompletionSource tcs = new ETTaskCompletionSource();
            //创建Timer 并且生成ID 设定触发时间=当前时间+等待的时间 缓存ETTaskCompletionSource对象tcs
            Timer timer = new Timer {
                Id = IdGenerater.GenerateId(), Time = TimeHelper.Now() + time, tcs = tcs
            };

            //管理所有timer对象的字典
            this.timers[timer.Id] = timer;
            //管理所有时间相关的事件 key:时间 value:timerid 通过timerid可以找到以上的Timer对象
            //然后获取它的tcs ...
            this.timeId.Add(timer.Time, timer.Id);
            //这个事件的时间跟当前最近要触发的时间进行比较 如果小于 那么最近要触发的事件是这个 timer.Time
            if (timer.Time < this.minTime)
            {
                //则进行更新最近要触发的time
                this.minTime = timer.Time;
            }
            //返回tcs.Task 而非tcs,所以等待的是其内部的Task对象
            return(tcs.Task);
        }
コード例 #28
0
        // accept
        public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.LocalConn      = localConn;
            this.RemoteConn     = remoteConn;
            this.remoteEndPoint = remoteEndPoint;
            this.socket         = socket;
            this.kcp            = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn));
            Kcp.KcpSetoutput(
                this.kcp,
                (bytes, len, k, user) =>
            {
                KService.Output(bytes, len, user);
                return(len);
            }
                );
            Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1);
            Kcp.KcpWndsize(this.kcp, 256, 256);
            Kcp.KcpSetmtu(this.kcp, 470);
            this.isConnected           = true;
            this.isRecvFirstKcpMessage = false;
            this.lastRecvTime          = kService.TimeNow;
        }
コード例 #29
0
ファイル: AChannel.cs プロジェクト: Xumudada/ET-Modules
 protected AChannel(AService service, ChannelType channelType)
 {
     this.Id          = IdGenerater.GenerateId();
     this.ChannelType = channelType;
     this.service     = service;
 }
コード例 #30
0
ファイル: Component.cs プロジェクト: tuita520/ETServer
 protected Component()
 {
     this.InstanceId = IdGenerater.GenerateId();
     Game.EventSystem.Add(this);
 }