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; } }
public override void dropLoot() { Entity killer = this.getKiller(); Player p = killer is Player ? (Player)killer : null; NpcDrop drop = this.npcDef.getDrop(); if (killer == null || p == null) { return; } if (drop != null) { try { List <Item> drops = new List <Item>(); int random = Misc.random(100); int random2 = 100 - random; if (random2 == 0) { random2++; } if (random2 < 25) { // 25% - semi rare if (drop.getUncommonDrops() != null && drop.getUncommonDrops().Count > 0) { drops.Add(drop.getUncommonDrops()[Misc.random(drop.getUncommonDrops().Count - 1)]); } } else if (random2 >= 25 && random2 < 95) { // 65% common if (drop.getCommonDrops() != null && drop.getCommonDrops().Count > 0) { drops.Add(drop.getCommonDrops()[Misc.random(drop.getCommonDrops().Count - 1)]); } } else if (random2 >= 95) { // 5% - rare if (drop.getRareDrops() != null && drop.getRareDrops().Count > 0) { drops.Add(drop.getRareDrops()[Misc.random(drop.getRareDrops().Count - 1)]); } } random = random2; if (drop.getAlwaysDrops().Count != 0) { foreach (Item d in drop.getAlwaysDrops()) { drops.Add(d); } } foreach (Item randomItem in drops) { int amount = randomItem.getItemAmount(); int itemId = randomItem.getItemId(); if (amount < 0) { amount = Misc.random((amount - (amount * 2))); if (amount == 0) { amount = 1; } } if (itemId == 8844) { // defender itemId = WarriorGuildData.DEFENDERS[((Player)killer).getDefenderWave()]; } bool stackable = ItemData.forId(itemId).isNoted() || ItemData.forId(itemId).isStackable(); if (stackable || (!stackable && amount == 1)) { if (Server.getGroundItems().addToStack(itemId, amount, this.getLocation(), p)) { } else { GroundItem item = new GroundItem(itemId, amount, this.getLocation(), p); Server.getGroundItems().newEntityDrop(item); } } else { for (int i = 0; i < amount; i++) { GroundItem item = new GroundItem(itemId, 1, this.getLocation(), p); Server.getGroundItems().newEntityDrop(item); } } } } catch (Exception e) { Misc.WriteError("Error at npc dropLoot, msg=" + e.Message); } } }
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(); }