Beispiel #1
0
            public void Return(Session session)
            {
                if (pool.Count >= size)
                    throw new InvalidOperationException();

                pool.Push(session);
            }
Beispiel #2
0
        public void NonFixedPathLeave()
        {
            var pool = new Channel.Pool();
            var session = new Session();

            pool.Join(new Channel.Path("world.map"), session);
            pool.Leave(new Channel.Path("world.*"), session);
        }
Beispiel #3
0
        /// <summary>
        /// 현재 패킷과, 지정된 세션에 대해서 아웃바인딩을 수행한다.
        /// (세션 프로퍼티의 값을 패킷의 필드에 바인딩한다)
        /// </summary>
        /// <param name="session">세션</param>
        private void OutBind(Session session)
        {
            var bindFields = GetBindFields(GetType());

            foreach (var field in bindFields)
            {
                DataBinder.OutBind(field.Item1, session, field.Item2, this);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 현재 패킷과, 지정된 세션에 대해서 인바인딩을 수행한다.
        /// (패킷 필드의 값을 세션의 프로퍼티에 바인딩)
        /// </summary>
        /// <param name="session">세션</param>
        private void InBind(Session session)
        {
            var bindFields = GetBindFields(GetType());

            foreach (var field in bindFields)
            {
                var value = field.Item2.GetValue(this);
                DataBinder.InBind(field.Item1, value, session);
            }
        }
Beispiel #5
0
            /// <summary>
            /// IO 쓰레드에 새로운 IO 쓰기 작업이 발생했음을 알린다.
            /// 필요하다면 IO 쓰레드를 즉시 깨워 전송 작업을 시작한다.
            /// [Thread-Safe]
            /// </summary>
            /// <param name="session">IO 쓰기 작업이 발생한 세션</param>
            public void Pulse(Session session)
            {
                if (!pendingSessions.TryAdd(session, 0))
                    return;

                lock (obj)
                {
                    Monitor.Pulse(obj);
                }   
            }
Beispiel #6
0
        public void OnSyncRequest(Session session, SyncProperty.Request packet)
        {
            if (objects.ContainsKey(packet.objectId) == false)
            {
                server.logger.Warn("OnSyncRequest - invalid object id {0}", packet.objectId);
                return;
            }

            var target = objects[packet.objectId];
            target.OnSyncProperty(packet);
        }
Beispiel #7
0
            public void Leave(Channel.Path path, Session session)
            {
                if (!path.isFixed)
                    throw new ArgumentException("path isFixed(false)");

                var targets = pool.Query(path);
                if (targets.Count > 0)
                {
                    foreach (var target in targets)
                        target.Leave(session);
                }
            }
Beispiel #8
0
        private void Forwards(Session session)
        {
            var forwardFields = GetForwardFields(GetType());
            var request = session.pipelineContext.request;

            foreach (var field in forwardFields)
            {
                var value = 
                    request.GetType().GetField(field.Name)
                    .GetValue(request);
                field.SetValue(this, request);
            }
        }
Beispiel #9
0
        public void AutoRemove()
        {
            var sc = new SafeCollection<Session>();

            var session = new Session();

            sc.Add(session);

            session.Disconnect();

            Assert.AreEqual(
                sc.Count,
                0);
        }
Beispiel #10
0
        /// <summary>
        /// 패킷이 클라이언트에게 Send 되기 전 처리해야 할 작업들을 수행한다.
        /// 이 작업은 S2C 패킷에만 수행되어야 한다.
        /// </summary>
        /// <param name="session">세션</param>
        internal void PostProcess(Session session)
        {
            OutBind(session);
            Forwards(session);

            foreach (var pp in Packet.GetCustomFields(GetType()))
            {
                var value = pp.Item2.GetValue(this);
                pp.Item1.OnPostProcess(ref value);
                pp.Item2.SetValue(this, value);
            }

            foreach (var pp in Server.current.preProcessors)
                pp.Item2.Invoke(session, this);
        }
Beispiel #11
0
        /// <summary>
        /// 패킷이 각 서비스들에게 라우팅 되기 전 처리해야 할 작업들을 수행한다.
        /// 이 작업은 C2S 패킷에만 수행되어야 한다.
        /// </summary>
        /// <param name="session">세션</param>
        internal void PreProcess(Session session)
        {
            var join = Packet.GetJoinPath(GetType());
            if (join != null)
                Server.current.channelPool.Join(join, session);

            var leave = Packet.GetLeavePath(GetType());
            if (leave != null)
                Server.current.channelPool.Leave(leave, session);

            InBind(session);

            foreach (var pp in Packet.GetCustomFields(GetType()))
            {
                var value = pp.Item2.GetValue(this);
                pp.Item1.OnPreProcess(ref value);
                pp.Item2.SetValue(this, value);
            }
                
            foreach (var pp in Server.current.preProcessors)
                pp.Item2.Invoke(session, this);
        }
Beispiel #12
0
 public RecvPacketEvent(Session session, Packet packet)
 {
     this.type = Type.RecvPacket;
     this.session = session;
     this.packet = packet;
 }
Beispiel #13
0
 public DisconnectEvent(Session session)
 {
     this.type = Type.Disconnect;
     this.session = session;
 }
        public void OnTestPacket(Session session, TestPacket packet)
        {
            Console.WriteLine("OnTestPacket");

            session.Send(packet);
        }
Beispiel #15
0
 public void OnFoo(Session session, FooPacket packet)
 {
     Console.WriteLine("ON FOO {0} / {1}", packet.foo, packet.bar);
 }
Beispiel #16
0
 public void OnTestPacket(Session session, TestPacket packet)
 {
 }
Beispiel #17
0
 public void OnABC(Session session, Packet packet)
 {
 }
Beispiel #18
0
        internal void OnDisconnect(Session session)
        {
            var host = ((IPEndPoint)session.client.Client.RemoteEndPoint).Address.ToString();

            Console.WriteLine("OnDisconnect {0}", host);
        }
Beispiel #19
0
 public void OnBeginPipeline(Session session)
 {
     onBeginPipeline?.Invoke(server, session);
 }
Beispiel #20
0
        internal void OnConnect(Session session)
        {
            var endPoint = ((IPEndPoint)session.client.Client.RemoteEndPoint);

            foreach(var peer in peers)
            {
                if(peer.Value.host == endPoint.Address.ToString() &&
                   peer.Value.port == endPoint.Port)
                {
                    peer.Value.Reset(session);
                    break;
                }
            }

            Console.WriteLine("OnConnect {0}", endPoint.Address.ToString());
        }
Beispiel #21
0
 public void OnEndPipeline(Session session)
 {
     onEndPipeline?.Invoke(server, session);
 }
Beispiel #22
0
 public void Reset(Merona.Session session)
 {
     this.session = (Session)session;
     this.isActive = true;
 }