Ejemplo n.º 1
0
        internal void ProcessPing(MessageSession session, AlivePingMsg msg)
        {
            if (session != _session)
                return;

            // ping을 받았으니 pong을 보낸다.
            session.Send(new AlivePongMsg());
        }
Ejemplo n.º 2
0
        private void ConnectionLoop()
        {
            while (true)
            {
                try
                {
                    _event.Reset();

                    Logger.Write("Try to connect Pylon({0}:{1})", Configuration.PylonHost, Configuration.PylonPort);
                    _session = MessageSessionManager.Instance.CreateSession();
                    _session.Connect(Configuration.PylonHost, Configuration.PylonPort);

                    Task.Factory.StartNew(_session.StartReceive);
                    _session.Send(new ServerMsg
                        {
                            Host = Configuration.HostAddress,
                            Port = Configuration.Port,
                            Name = Configuration.ServerName
                        });

                    Logger.Write("Pylon Connected.");

                    _event.WaitOne();
                }
            #if DEBUG
                catch (Exception e)
                {
                    Logger.Write("Cannot connect to Pylon");
                    Logger.Write(e);

                    Thread.Sleep(RetryInterval);
                }
            #else
                catch
                {
                    Logger.Write("Cannot connect to Pylon");
                    Thread.Sleep(RetryInterval);
                }
            #endif
            }
            // ReSharper disable FunctionNeverReturns
        }
Ejemplo n.º 3
0
        private void Reconnect()
        {
            try
            {
                _session = MessageSessionManager.Instance.CreateSession();
            #if DEBUG
                _session.Connect("127.0.0.1", Configuration.PylonPort);
            #else
                _session.Connect(Configuration.PylonHost, Configuration.PylonPort);
            #endif
                _session.StartReceive();

                _session.Send(new InterChatLoginMsg { Name = _userName });
                return;
            }
            catch
            {
                Task.Delay(5000).ContinueWith(_ => Reconnect());
            }
        }
Ejemplo n.º 4
0
        internal void OnEnterWorld(MessageSession session, EnterWorldMsg msg)
        {
            // get or create entity
            Entity entity;
            lock (_accountLock)
            {
                if (NameCache.Instance.Contains(msg.Name))
                    entity = EntityManager.Instance[NameCache.Instance[msg.Name]];
                else
                {
                    entity = EntityManager.Instance.Create(EntityTemplate.Ids.User);
                    entity.Get<Nameplate>().Name = msg.Name;

                    if (!EntityBinder.Instance.Add(entity))
                    {
                        Logger.Write("Cannot insert entity[{0}]", msg.Name);
                        return;
                    }

                    NameCache.Instance.Add(msg.Name, entity.Id);
                }

                // ignore duplicately send enter-world msg
                if (entity.Id == session.SessionId)
                    return;

                // prevent repeatly login
                if (entity.Get<Player>().Logged)
                {
                    Logger.Write("{0} is already logged.", msg.Name);
                    session.Shutdown(SocketShutdown.Both);
                    return;
                }

                entity.Get<Player>().Logged = true;
            }

            entity.Ensure<Tickable>();
            entity.Get<Tickable>().Interval = DataCenter.Instance.GetAttributeValue<int>(typeof(Tickable), "interval");

            session.SessionId = entity.Id;
            session.Send(new WorldInfoMsg { Id = entity.Id, WorldId = 1 });
            session.Send(entity.ToMessage<SpawnMsg>());

            PositionSystem.Global.Appear(entity);

            Logger.Write("{0} is logged.", msg.Name);
        }