Beispiel #1
0
        public virtual async Task SpawnMeAsync(bool notifyOthers = true)
        {
            Region = L2World.GetRegion(new Location(X, Y, Z));

            L2World.AddObject(this);
            await OnSpawnAsync(notifyOthers);
        }
Beispiel #2
0
        public override async Task RunImpl()
        {
            L2Player      player  = _client.CurrentPlayer;
            L2WorldRegion prevReg = player.Region;

            int realX = player.X;
            int realY = player.Y;
            int realZ = player.Z;

            int dx = _x - realX;
            int dy = _y - realY;
            int dz = _z - realZ;

            double diffSq = Math.Sqrt(dx * dx + dy * dy);

            player.SendMessageAsync($"diff: {(int) diffSq}");

            player.Movement.UpdatePosition(_x, _y, _z);

            if (diffSq > 600)
            {
                Log.Error($"User {player.ObjectId}:{player.Account.Login}:{player.Name} coord is unsync with server");
                // TODO: Add teleport back
            }

            L2World.UpdateRegion(player);

            //Log.Info($"Current client position: X:{_x}, Y:{_y}, Z:{_z}"); //debug
            player.BroadcastUserInfoAsync();
        }
Beispiel #3
0
 public override async Task SendPacketAsync(GameserverPacket pk)
 {
     foreach (L2Player pl in L2World.GetPlayers())
     {
         // TODO: Sends to all players on the server. It is not right
         await pl.Gameclient.SendPacketAsync(pk);
     }
 }
Beispiel #4
0
        private async void RemoveCorpse(object sender, ElapsedEventArgs e)
        {
            CorpseTimer.Stop();
            CorpseTimer.Enabled = false;
            await BroadcastPacketAsync(new DeleteObject(ObjectId));

            L2World.RemoveObject(this);
        }
Beispiel #5
0
 public override async Task BroadcastUserInfoAsync()
 {
     // TODO: Sends to all players on the server. It is not right
     foreach (L2Player pl in L2World.GetPlayers())
     {
         await pl.SendPacketAsync(new NpcInfo(this));
     }
 }
Beispiel #6
0
        public async void Start()
        {
            Config.Config config = ServiceProvider.GetService <Config.Config>();
            await config.Initialise();

            await ServiceProvider.GetService <PreReqValidation>().Initialise();

            CharTemplateTable.Initialize();

            // TODO: refactor NetworkBlock
            NetworkBlock.Instance.Initialize();
            GameTime.Initialize();

            await ServiceProvider.GetService <IdFactory>().Initialise();

            L2World.Initialize();

            MapRegionTable.Initialize();
            ZoneTable.Initialize();

            await ServiceProvider.GetService <ItemTable>().Initialise();

            ItemHandler.Initialize();

            NpcTable.Initialize();
            Capsule.Initialize();
            AttackStanceManager.Initialize();
            BlowFishKeygen.GenerateKeys();

            await ServiceProvider.GetService <IAdminCommandHandler>().Initialise();

            await ServiceProvider.GetService <AnnouncementManager>().Initialise();

            StaticObjTable.Initialize();
            await ServiceProvider.GetService <SpawnTable>().Initialise();

            await ServiceProvider.GetService <HtmCache>().Initialise();

            // TODO: review plugin system
            //PluginManager.Instance.Initialize(this);

            ServiceProvider.GetService <AuthThread>().Initialise();

            _listener = new TcpListener(IPAddress.Any, config.ServerConfig.Port);

            try
            {
                _listener.Start();
            }
            catch (SocketException ex)
            {
                Log.Halt($"Socket Error: '{ex.SocketErrorCode}'. Message: '{ex.Message}' (Error Code: '{ex.NativeErrorCode}')");
            }

            Log.Info($"Listening Gameservers on port {config.ServerConfig.Port}");

            Task.Factory.StartNew(WaitForClients);
        }
Beispiel #7
0
        public override async Task RunImpl()
        {
            L2Player player = _client.CurrentPlayer;

            player.SetCharLastAccess();
            CharacterService.UpdatePlayer(player);

            player.TotalRestore();

            player.SendPacketAsync(new SystemMessage(SystemMessageId.WelcomeToLineage));

            _announcementManager.OnEnter(player);

            foreach (L2Item item in player.Inventory.Items.Where(item => item.IsEquipped != 0))
            {
                item.NotifyStats(player);
            }

            // player.sendItemList(false);
            player.SendPacketAsync(new FriendList());
            player.SendQuestList();
            player.UpdateReuse();

            player.SendPacketAsync(new ExStorageMaxCount(player));
            // player.sendPacket(new ExBasicActionList());
            //  NpcTable.getInstance().spawnNpc("grandmaster_ramos", player.X, player.Y, player.Z, player.Heading);
            player.SendActionFailedAsync();

            GameTime.UpdateTimeForPlayer(player);

            player.Timer();

            player.SpawnMeAsync();
            //L2WorldRegion worldRegion = L2World.GetRegion(player.X, player.Y);
            //player.SetRegion(worldRegion);
            //player.getKnowns(500, 500, false);


            player.SetupKnowsAsync();
            player.SendPacketAsync(new UserInfo(player));

            foreach (Plugin plugin in PluginManager.Instance.Plugins)
            {
                plugin.OnLogin(player);
            }

            //player.sendPacket(new ShortCutInit(player));
            player.StartAi();
            player.CharStatus.StartHpMpRegeneration();
            player.ShowHtm("servnews.htm", player);
            player.BroadcastUserInfoAsync();
            L2World.AddPlayer(player);
        }
Beispiel #8
0
        public override async Task RunImpl()
        {
            L2Player player = L2World.GetPlayers().FirstOrDefault(x => x.Account.AccountId == _accountId);

            if (player == null)
            {
                GameServer.ServiceProvider.GetService <ClientManager>().Disconnect(_accountId);
                return;
            }

            await L2World.KickPlayer(player);
        }
Beispiel #9
0
        public override async Task Restore(L2Character owner)
        {
            IEnumerable <ItemContract> models = await _itemService.RestoreInventory(owner.ObjectId);

            List <L2Item> items = RestoreFromDb(models.ToList());

            foreach (L2Item item in items)
            {
                L2World.AddObject(item);
                Owner = owner;
                AddItem(item, (L2Player)Owner);
            }
        }
Beispiel #10
0
        public L2Item CreateItem(int itemId, int count, L2Player actor)
        {
            L2Item item = new L2Item(_itemCrudService, _idFactory, GetItem(itemId), _idFactory.NextId());

            L2World.AddObject(item);

            if (item.Template.Stackable && count > 1)
            {
                item.Count = count;
            }

            return(item);
        }
Beispiel #11
0
        public override async Task RunImpl()
        {
            await Task.Run(() =>
            {
                L2Player player = _client.CurrentPlayer;

                switch (_command)
                {
                case 0:            // [loc]
                    int regId = 0; //MapRegionTable.getInstance().getRegionSysId(player.X, player.Y);
                    if (regId > 0)
                    {
                        player.SendPacketAsync(new SystemMessage((SystemMessageId)regId).AddNumber(player.X).AddNumber(player.Y).AddNumber(player.Z));
                    }
                    else
                    {
                        player.SendPacketAsync(new SystemMessage(SystemMessageId.NotImplementedYet2361).AddString("Nowhere"));
                    }

                    int x = (player.X >> 15) + 9 + 8;
                    int y = (player.Y >> 15) + 10 + 11;
                    player.SendMessageAsync($"Current loc is X:{player.X} Y:{player.Y} Z:{player.Z}");
                    player.BroadcastUserInfoAsync();     //for debug reasons
                    break;

                case 52:     // /unstuck

                    L2WorldRegion worldRegion = L2World.GetRegion(player.X, player.Y);
                    player.SetRegion(worldRegion);
                    List <L2Player> knowns = player.GetKnownPlayers();
                    //player.SpawnMeAsync();
                    player.SendMessageAsync("Unstuck not implemented yet.");
                    //player.knownObjects;
                    break;

                case 62:     // /dismount
                    player.SendMessageAsync("Dismount not implemented yet.");
                    break;

                case 77:     // [time]
                    GameTime.ShowInfoAsync(player);
                    break;

                default:
                    player.SendMessageAsync($"cmd alias {_command}");
                    break;
                }
            });
        }
Beispiel #12
0
        public void DropMe(int x, int y, int z, L2Character dropper, L2Character killer, int seconds)
        {
            X = x;
            Y = y;
            Z = z;
            DropItem pk = new DropItem(this);

            if (dropper != null)
            {
                Dropper = dropper.ObjectId;
            }

            Location = ItemLocation.Void;

            killer?.AddKnownObject(this, pk, true);

            L2World.AddObject(this);
        }
Beispiel #13
0
        public void Initialize()
        {
            L2WorldRegion[,] worldRegions = L2World.GetWorldRegions();

            try
            {
                //XmlDocument doc = new XmlDocument();
                //int fileCounter = 0;
                //string[] xmlFilesArray = Directory.GetFiles(@"data\xml\zones\");
                //for (int i = 0; i < xmlFilesArray.Length; i++) { }
            }
            catch (Exception e)
            {
                Log.Error($"ZoneManager: {e.Message}");
            }

            //int size = 0;
        }
Beispiel #14
0
        public override async Task RunImpl()
        {
            await Task.Run(() =>
            {
                L2Player player = _client.CurrentPlayer;
                L2Object obj    = null;

                if (player.PBlockAct == 1)
                {
                    player.SendActionFailedAsync();
                    return;
                }

                if (_objectId == player.ObjectId)
                {
                    obj = player;
                }
                else
                {
                    if (L2World.GetObject(_objectId) != null)
                    {
                        obj = L2World.GetObject(_objectId);
                    }
                }

                if (obj == null)
                {
                    player.SendActionFailedAsync();
                    return;
                }

                //if (obj is L2Npc)
                //{
                //    if (((L2Npc)obj).Template._can_be_attacked == 0)
                //    {
                //        player.sendSystemMessage(144);//That is the incorrect target.
                //        player.sendActionFailed();
                //        return;
                //    }
                //}

                obj.OnForcedAttackAsync(player);
            });
        }
Beispiel #15
0
        public override async Task RunImpl()
        {
            await Task.Run(() =>
            {
                L2Player player = _client.CurrentPlayer;
                L2Object obj    = null;

                if (_objectId == player.ObjectId)
                {
                    obj = player;
                }
                else
                {
                    if (L2World.GetObject(_objectId) != null)
                    {
                        obj = L2World.GetObject(_objectId);
                    }
                }
                //fixed nullreference exception when obj is null
                Log.Debug($"Action Requested with { Utilz.GetTypeLower(obj).ToString() }  of ID : { _objectId.ToString()}");

                if (obj == null)
                {
                    Log.Debug("Action Requested Failed");
                    player.SendActionFailedAsync();
                    return;
                }

                switch (_actionId)
                {
                case 0:
                    obj.OnActionAsync(player);
                    break;

                case 1:
                    obj.OnActionShiftAsync(player);
                    break;

                default:
                    player.SendActionFailedAsync();
                    break;
                }
            });
        }
Beispiel #16
0
        internal static void Start()
        {
            // Set up logging
            Logging.LoggerFactory.AddConsole(LogLevel.Debug, true);

            // Services
            PlayerService = CharacterService.Instance;
            World         = L2World.Instance;

            // Connect to loginserver
            Task login = LoginService.Instance.ConnectAsync(LoginIp, 2110);

            // start network server
            Logger.LogInformation("Starting network");
            GameServer = new Network.GameServer();
            Task listen = GameServer.ListenAsync("*", 7777);

            // Wait till all tasks finished
            Task.WaitAll(login, listen);
        }
Beispiel #17
0
        private void DesctructTime(object sender, ElapsedEventArgs e)
        {
            _selfDestruct.Enabled = false;

            NpcCenter.DecayMe();

            foreach (L2Object o in ObjectsInside.Values)
            {
                OnExit(o, false);
            }

            ObjectsInside.Clear();

            L2WorldRegion region = L2World.GetRegion(CylinderCenter[0], CylinderCenter[1]);

            if (region != null)
            {
                // region._zoneManager.remZone(this);
            }
        }
Beispiel #18
0
        public virtual List <L2Player> GetKnownPlayers(bool excludeSelf = true)
        {
            L2WorldRegion region = Region;

            if (region == null)
            {
                return(new List <L2Player>());
            }

            List <L2Player> result = new List <L2Player>();

            if (excludeSelf)
            {
                region.GetSurroundingRegions().ForEach(reg => result.AddRange(L2World.GetPlayers().Where(obj => obj != this)));
            }
            else
            {
                region.GetSurroundingRegions().ForEach(reg => result.AddRange(L2World.GetPlayers()));
            }
            return(result);
        }
Beispiel #19
0
        public override async Task RunImpl()
        {
            L2Player      player  = _client.CurrentPlayer;
            L2WorldRegion prevReg = player.Region;

            int realX = player.X;
            int realY = player.Y;
            int realZ = player.Z;

            int dx = _x - realX;
            int dy = _y - realY;
            int dz = _z - realZ;

            double diffSq = Math.Sqrt(dx * dx + dy * dy);

            player.SendMessageAsync($"diff: {(int) diffSq}");

            player.CharMovement.UpdatePosition(_x, _y, _z);

            if (diffSq > 600)
            {
                Log.Error($"User {player.ObjectId}:{player.Account.Login}:{player.Name} coord is unsync with server");
            }

            L2WorldRegion NewRegion = L2World.GetRegion(new Location(player.X, player.Y, player.Z));

            if (prevReg != NewRegion)
            {
                player.SetRegion(NewRegion);
                player.SetupKnowsAsync();

                //Add objects from surrounding regions into knows, this is a hack to prevent
                //objects from popping into view as soon as you enter a new region
                //TODO: Proper region transition
                player.SetupKnowsAsync(NewRegion);
            }
            //Log.Info($"Current client position: X:{_x}, Y:{_y}, Z:{_z}"); //debug
            player.BroadcastUserInfoAsync();
            player.ValidateVisibleObjects(realX, realY, true);
        }
Beispiel #20
0
        public override async Task OnActionAsync(L2Player player)
        {
            double dis = Calcs.CalculateDistance(this, player, true);
            await player.SendMessageAsync($"{AsString()} dis {(int)dis}");

            if (dis < 80)
            {
                foreach (L2Player p in Region.GetAllNeighbourPlayers())
                {
                    p.SendPacketAsync(new GetItem(p.ObjectId, ObjectId, X, Y, Z));
                    p.SendPacketAsync(new DeleteObject(ObjectId));
                }

                player.OnPickUp(this);

                L2World.RemoveObject(this);
            }
            else // TODO: Rework this
            {
                await player.Movement.MoveTo(X, Y, Z);
            }
        }
Beispiel #21
0
        public override async Task OnActionAsync(L2Player player)
        {
            double dis = Calcs.CalculateDistance(this, player, true);
            await player.SendMessageAsync($"{AsString()} dis {(int)dis}");

            if (dis < 80)
            {
                foreach (L2Player o in KnownObjects.Values.OfType <L2Player>())
                {
                    await o.SendPacketAsync(new GetItem(player.ObjectId, ObjectId, X, Y, Z));

                    await o.SendPacketAsync(new DeleteObject(ObjectId));
                }

                player.OnPickUp(this);

                L2World.RemoveObject(this);
            }
            else
            {
                await player.CharMovement.MoveTo(X, Y, Z);
            }
        }
Beispiel #22
0
        public void ScreenAnnounce(string text)
        {
            CreatureSay cs = new CreatureSay(SayIDList.CHAT_SCREEN_ANNOUNCE, text);

            L2World.GetPlayers().ForEach(p => p.SendPacketAsync(cs));
        }
Beispiel #23
0
        //public virtual void ReduceHp(L2Character attacker, double damage) { }

        public virtual void DecayMe()
        {
            Region = null;

            L2World.RemoveObject(this);
        }
Beispiel #24
0
 public virtual async Task SpawnMeAsync(bool notifyOthers = true)
 {
     L2World.AddObject(this);
     await OnSpawnAsync();
 }
Beispiel #25
0
 public virtual void DecayMe()
 {
     L2World.RemoveObject(this);
 }
Beispiel #26
0
 public void GetKnowns(int range, int height, bool zones)
 {
     L2World.GetObjects(); // GetKnowns(this, range, height, zones);
 }
Beispiel #27
0
        public static void Initialize()
        {
            Objects = new Dictionary <int, L2StaticObject>();
            using (StreamReader reader = new StreamReader(new FileInfo(@"scripts\staticobjects.txt").FullName))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine() ?? string.Empty;
                    if ((line.Length == 0) || line.StartsWithIgnoreCase("#"))
                    {
                        continue;
                    }

                    string[] pt = line.Split('\t');

                    L2StaticObject obj = null;
                    //TODO: Implement this
                    switch (pt[1])
                    {
                    case "map":
                        // obj = new L2TownMap(IdFactory.Instance.NextId(),null);
                        break;

                    case "chair":
                        // obj = new L2Chair(IdFactory.Instance.NextId(), null);
                        break;

                    case "pvp":
                        //obj = new L2PvPSign(IdFactory.Instance.NextId(), null);
                        break;

                    case "door":
                        //obj = new L2Door(IdFactory.Instance.NextId(), null);
                        break;
                    }

                    if (obj == null)
                    {
                        continue;
                    }

                    obj.StaticId = Convert.ToInt32(pt[0]);

                    for (byte ord = 2; ord < pt.Length; ord++)
                    {
                        string parameter = pt[ord];
                        string value     = parameter.Substring(parameter.IndexOf('{') + 1);
                        value = value.Remove(value.Length - 1);

                        switch (parameter.Split('{')[0].ToLower())
                        {
                        case "spawn":
                            obj.SetLoc(value.Split(' '));
                            break;

                        case "tex":
                            obj.SetTex(value.Split(' '));
                            break;

                        case "htm":
                            obj.Htm = value;
                            break;

                        case "hp":
                            obj.CharacterStat = new CharacterStat(obj);
                            break;

                        case "defence":
                            obj.Pdef = Convert.ToInt32(value.Split(' ')[0]);
                            obj.Mdef = Convert.ToInt32(value.Split(' ')[1]);
                            break;

                        case "unlock":
                        {
                            foreach (string str in value.Split(' '))
                            {
                                switch (str)
                                {
                                case "trigger":
                                    obj.UnlockTrigger = true;
                                    break;

                                case "skill":
                                    obj.UnlockSkill = true;
                                    break;

                                case "drop":
                                    obj.UnlockNpc = true;
                                    break;
                                }
                            }
                        }

                        break;
                        }
                    }

                    Objects.Add(obj.StaticId, obj);
                }
            }

            foreach (L2StaticObject o in Objects.Values)
            {
                L2World.AddObject(o);
                o.OnSpawnAsync();
            }

            Log.Info($"Spawned {Objects.Count} objects.");
        }
Beispiel #28
0
        public void UpdatePlayersOnline()
        {
            short cnt = (short)L2World.GetPlayers().Count;

            SendPacket(new PlayerCount(cnt));
        }
Beispiel #29
0
 public override void Execute(string param)
 {
     Console.WriteLine("Count - " + L2World.GetPlayers().Count);
 }
Beispiel #30
0
 private static void UpdateTimeForAll()
 {
     L2World.GetPlayers().ForEach(UpdateTimeForPlayer);
 }