Beispiel #1
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);
        }