コード例 #1
0
        private RunescapeAPI(RunescapeWebClient Client)
        {
            Client.BaseAddress = new Uri($@"http://services.runescape.com/");

            Client.DefaultRequestHeaders.Accept.Clear();
            Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            GrandExchange = new GrandExchange(Client);
            Bestiary      = new Bestiary(Client);
            Hiscores      = new Hiscores(Client);
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            //Lets do the loading here to catch any exceptions.
            Console.WriteLine("For future updates visit http://www.CamSpark.com");
            MapData.load();  //this has to be packed once all mapdata is gotten.
            ObjectData.load();
            ItemData.load(); //this has to be first because npcDrops use itemData.. i think.
            NpcData.load();  //first load the npc data.
            NpcDrop.load();  //second load the npc drops. [order does matter here, as it binds to npcData].
            NpcSpawn.load(); //finally you can spawn the npcs.
            LaddersAndStairs.load();
            objectManager     = new WorldObjectManager();
            groundItemManager = new GroundItemManager();
            shopManager       = new ShopManager();
            minigames         = new MinigamesHandler();
            grandExchange     = new GrandExchange();
            clanManager       = new ClanManager();
            packetHandlers    = new PacketHandlers();
            loginHandler      = new LoginHandler();

            registerEvent(new RunEnergyEvent());
            registerEvent(new LevelChangeEvent());
            registerEvent(new SpecialRestoreEvent());
            registerEvent(new SkullCycleEvent());
            registerEvent(new AreaVariables());
            registerEvent(new AggressiveNpcEvent());
            registerEvent(new LowerPotionCyclesEvent());
            objectManager.getFarmingPatches().processPatches();
            isRunning = true;
            new Thread(new ThreadStart(Server.gameThread)).Start();
            new Thread(new ThreadStart(Server.eventProcessingThread)).Start();

            Console.Title = "Runescape 2 530 C# Server";

            // Startup the Server Listener
            try
            {
                IPEndPoint ipe = new IPEndPoint(0, Constants.SERVER_PORT);
                serverListenerSocket = new System.Net.Sockets.Socket(ipe.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                serverListenerSocket.Bind(ipe);
                serverListenerSocket.Listen(25); //backlog
                serverListenerSocket.BeginAccept(new AsyncCallback(acceptCallback), serverListenerSocket);
                Console.WriteLine("Runescape 2 530 C# server started on port " + Constants.SERVER_PORT);
            }
            catch (SocketException ioe)
            {
                misc.WriteError("Error: Unable to startup listener on " + Constants.SERVER_PORT + " - port already in use?");
                misc.WriteError(ioe.Message.ToString());
                isRunning = false;
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Ciastex/RuneAPI
        static void ScrapeForDb()
        {
            Console.WriteLine("Scraping...");

            var ge   = new GrandExchange();
            var dict = ge.GetAlphabeticalCatalogue();

            using (var sw = new StreamWriter("./items.json"))
            {
                sw.WriteLine("{");
                foreach (var kvp in dict)
                {
                    var pageCount = Math.Ceiling(kvp.Value / 12d);

                    for (var i = 1; i <= pageCount; i++)
                    {
                        var itemList = ge.GetCataloguePage(kvp.Key, i);

                        while (itemList == null)
                        {
                            itemList = ge.GetCataloguePage(kvp.Key, i);
                            Thread.Sleep(500);
                        }

                        foreach (var item in itemList.Items)
                        {
                            Console.WriteLine($"{item.Name}: {item.Id}");
                            sw.WriteLine($"    \"{item.Name}\": {item.Id},");
                        }
                        Thread.Sleep(500);
                    }
                }
                sw.WriteLine("}");
            }
            Console.WriteLine("Done.");
            Console.ReadLine();
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: Rut0/RSPS-CSharp
        public static void Main(string[] args)
        {
            //MapData.MapList(); //this has to be packed once all mapdata is gotten.
            ObjectData.load();
            ItemData.load(); //this has to be first because npcDrops use itemData.. i think.
            NpcData.load();  //first load the npc data.
            NpcDrop.load();  //second load the npc drops. [order does matter here, as it binds to npcData].
            NpcSpawn.load(); //finally you can spawn the npcs.
            LaddersAndStairs.load();
            objectManager     = new WorldObjectManager();
            groundItemManager = new GroundItemManager();
            shopManager       = new ShopManager();
            minigames         = new MinigamesHandler();
            grandExchange     = new GrandExchange();
            clanManager       = new ClanManager();
            packetHandlers    = new PacketHandlers();
            loginHandler      = new LoginHandler();

            registerEvent(new RunEnergyEvent());
            registerEvent(new LevelChangeEvent());
            registerEvent(new SpecialRestoreEvent());
            registerEvent(new SkullCycleEvent());
            registerEvent(new AreaVariables());
            registerEvent(new AggressiveNpcEvent());
            registerEvent(new LowerPotionCyclesEvent());
            objectManager.getFarmingPatches().processPatches();
            isRunning = true;
            new Thread(new ThreadStart(Server.eventProcessingThread)).Start();
            Console.Title = "RS2 530 C# Server";
            // setup the listener
            try
            {
                IPEndPoint ipe = new IPEndPoint(0, Constants.SERVER_PORT);
                serverListenerSocket = new System.Net.Sockets.Socket(ipe.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                serverListenerSocket.Bind(ipe);
                serverListenerSocket.Listen(25); //backlog
                serverListenerSocket.BeginAccept(new AsyncCallback(acceptCallback), serverListenerSocket);
                Console.WriteLine("RS2 530 C# server started on port " + Constants.SERVER_PORT);
            }
            catch (SocketException ioe)
            {
                Misc.WriteError("Error: Unable to startup listener on " + Constants.SERVER_PORT + " - port already in use?");
                Misc.WriteError(ioe.Message.ToString());
                isRunning = false;
            }

            while (isRunning)
            {
                // could do game updating stuff in here...
                // maybe do all the major stuff here in a big loop and just do the packet
                // sending/receiving in the client subthreads. The actual packet forming code
                // will reside within here and all created packets are then relayed by the subthreads.
                // This way we avoid all the sync'in issues
                // The rough outline could look like:
                // doPlayers()		// updates all player related stuff
                // doNpcs()		// all npc related stuff
                // doObjects()
                // doWhatever()
                curTime = Environment.TickCount;

                if (curTime - lastInfoTime >= 2000 && !toggledStats)
                {
                    Console.Title = "RS2 C# Server [Players: " + players.Count + "][Connections: " + connections.Count + "]";
                    lastInfoTime  = curTime;
                    toggledStats  = true;
                }
                else if (curTime - lastInfoTime >= 4000 && toggledStats)
                {
                    Console.Title = "RS2 C# Server [Events Running: " + events.Count + "]";
                    lastInfoTime  = curTime;
                    toggledStats  = false;
                }

                lock (connections)
                {
                    foreach (Connection c in connections.ToArray()) //these are logged in players.
                    //ThreadPool.QueueUserWorkItem(c.processQueuedPackets);
                    {
                        c.processQueuedPackets(null);
                    }

                    foreach (Connection c in connections.ToArray()) //update server.
                    {
                        if (LoginHandler.removableConnection(c))
                        {
                            removeConnection(c);
                        }
                    }
                }

                lock (players)
                {
                    foreach (Player p in players)
                    {
                        p.tick();
                        p.processQueuedHits();
                        //if (p.getWalkingQueue().hasNextStep() || p.getTeleportTo() != null)
                        p.getWalkingQueue().getNextPlayerMovement();
                    }
                }

                lock (npcs)
                {
                    foreach (Npc n in npcs)
                    {
                        n.tick();
                        n.processQueuedHits();
                    }
                }

                lock (players)
                {
                    foreach (Player p in players)
                    {
                        if (p == null)
                        {
                            continue;
                        }
                        if (p.isActive())
                        {
                            PlayerUpdate.update(p);
                            NpcUpdate.update(p);

                            //In case the player turns active in the loop below make sure it doesn't clear flags.
                            if (!p.getUpdateFlags().isClearable())
                            {
                                p.getUpdateFlags().setClearable(true);
                            }
                        }
                    }
                    foreach (Player p in players)
                    {
                        if (p.isActive() && p.getUpdateFlags().isClearable() && p.getUpdateFlags().isUpdateRequired())
                        {
                            p.getUpdateFlags().clear();
                        }
                        p.getHits().clear();
                        if (!p.getConnection().socket.Connected || p.isDisconnected())
                        {
                            unregister(p); //This must be after PlayerUpdate or chance of messing up playerIndexes for PlayerUpdate
                        }
                    }
                }
                lock (npcs)
                {
                    foreach (Npc n in npcs)
                    {
                        if (n.getUpdateFlags().isUpdateRequired())
                        {
                            n.getUpdateFlags().clear();
                        }
                        n.getHits().clear();
                    }
                }

                try { System.Threading.Thread.Sleep(500 - (Environment.TickCount - curTime)); }
                catch { }
            }

            Console.WriteLine("Server has shutdown successfully, press any key to exit console.");
            //Console.ReadKey(true);
            Console.ReadLine();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: Ciastex/RuneAPI
        static void Main(string[] args)
        {
            if (!File.Exists("./items.json"))
            {
                ScrapeForDb();
            }

            var db = File.ReadAllText("./items.json").ToLower();
            var ge = new GrandExchange(db);

            ReadLine.AutoCompletionHandler = new AutoCompletionHandler(ge.ItemDb.Keys.ToArray());

            while (true)
            {
                try
                {
                    var line = ReadLine.Read("#id> ");
                    if (string.IsNullOrEmpty(line) || string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    var cmdline = line.Split(' ');
                    if (int.TryParse(cmdline[0], out int id))
                    {
                        var item = ge.GetItemDetails(id);
                        if (item != null)
                        {
                            Console.WriteLine(item.ToString());
                        }
                    }
                    else if (cmdline[0] == "/graph")
                    {
                        if (cmdline.Length != 2)
                        {
                            continue;
                        }

                        if (!int.TryParse(cmdline[1], out int param))
                        {
                            continue;
                        }

                        var data = ge.GetGraphData(param);

                        if (data == null)
                        {
                            continue;
                        }

                        foreach (var kvp in data)
                        {
                            Console.WriteLine($"{kvp.Key}: {kvp.Value}");
                        }
                    }
                    else if (cmdline[0] == "/latest")
                    {
                        if (cmdline.Length != 2)
                        {
                            continue;
                        }

                        if (!int.TryParse(cmdline[1], out int param))
                        {
                            continue;
                        }

                        var latestPrice = ge.GetLatestPrice(param);
                        if (latestPrice < 0)
                        {
                            continue;
                        }

                        Console.WriteLine($"Current GE price for this item is {latestPrice}gp.");
                    }
                    else
                    {
                        var item = ge.GetItemDetails(line.ToLower());
                        if (item != null)
                        {
                            Console.WriteLine(item.ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }