示例#1
0
        public void TimedSpawn()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Players in Realm: " + world.Players.Count); //checks players in realm
            }
            if (world.Players.Count > 0)                                       //Makes sure player is in the realm
            {
                var evt = events[rand.Next(0, events.Count)];
                SpawnEvent(evt.Item1, evt.Item2);

                TauntData?dat = null;
                dat = null;
                foreach (var i in criticalEnemies)
                {
                    if (evt.Item1 == i.Item1)
                    {
                        dat = i.Item2;
                        break;
                    }
                }
                if (dat == null)
                {
                    return;
                }

                if (dat.Value.spawn != null)
                {
                    var arr = dat.Value.spawn;
                    var msg = arr[rand.Next(0, arr.Length)];
                    BroadcastMsg(msg); //Taunt that bish
                }
            }
            world.Timers.Add(new WorldTimer(300000, (ww, tt) => { TimedSpawn(); })); //New Event every 5 minutes
        }
        public void TickLoop()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Procces: Starting network loop.");
            }
            Work work;

            while (true)
            {
                if (Manager.Terminating)
                {
                    break;
                }
                loopLock.Reset();
                while (pendings.TryDequeue(out work))
                {
                    if (Manager.Terminating)
                    {
                        return;
                    }
                    try
                    {
                        if (work.Item1.Stage == ProtocalStage.Disconnected)
                        {
                            Client client;
                            var    accId = work.Item1?.Account?.AccountId;
                            if (accId != null)
                            {
                                Manager.Clients.TryRemove(accId, out client);
                            }
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                    try
                    {
                        Packet packet = Packet.Packets[work.Item2].CreateInstance();
                        packet.Read(work.Item1, work.Item3, 0, work.Item3.Length);
                        work.Item1.ProcessPacket(packet);
                    }
                    catch { }
                }
                while (pendings.Count == 0 && !Manager.Terminating)
                {
                    loopLock.SpinOnce();
                }
            }
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Procces: Stopping network loop.");
            }
        }
示例#3
0
 public void Start()
 {
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Starting server...");
     }
     Socket.Bind(new IPEndPoint(IPAddress.Any, Program.Settings.GetValue <int>("port")));
     Socket.Listen(0xff);
     Socket.BeginAccept(Listen, null);
 }
示例#4
0
        public void Init()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Oryx is controlling world {0}({1})...", world.Id, world.Name);
            }
            var w     = world.Map.Width;
            var h     = world.Map.Height;
            var stats = new int[12];

            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    var tile = world.Map[x, y];
                    if (tile.Terrain != WmapTerrain.None)
                    {
                        stats[(int)tile.Terrain - 1]++;
                    }
                }
            }
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Spawning minions...");
            }
            foreach (var i in spawn)
            {
                var terrain    = i.Key;
                var idx        = (int)terrain - 1;
                var enemyCount = stats[idx] / i.Value.Item1;
                enemyMaxCounts[idx] = enemyCount;
                enemyCounts[idx]    = 0;
                for (var j = 0; j < enemyCount; j++)
                {
                    var objType = GetRandomObjType(i.Value.Item2);
                    if (objType == 0)
                    {
                        continue;
                    }

                    enemyCounts[idx] += Spawn(world.Manager.GameData.ObjectDescs[objType], terrain, w, h);
                    if (enemyCounts[idx] >= enemyCount)
                    {
                        break;
                    }
                }
            }
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Oryx is done.");
            }
        }
示例#5
0
 public void Stop()
 {
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Stoping server...");
     }
     foreach (Client i in Manager.Clients.Values.ToArray())
     {
         i.Save();
         i.Disconnect(Client.DisconnectReason.STOPPING_SERVER);
     }
     Socket.Close();
 }
示例#6
0
 public void Oryx(World world, string text)
 {
     world.BroadcastPacket(new TextPacket
     {
         BubbleTime = 0,
         Stars      = -1,
         Name       = "#Oryx the Mad God",
         Text       = text.ToSafeText()
     }, null);
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("[{0}({1})] <Oryx the Mad God> {2}", world.Name, world.Id, text);
     }
 }
示例#7
0
        public async void Stop()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Stoping server...");
            }
            foreach (Client i in Manager.Clients.Values.ToArray())
            {
                await i.Save();

                i.Disconnect();
            }
            Socket.Close();
        }
示例#8
0
 public void News(string text)
 {
     foreach (var i in manager.Clients.Values)
     {
         i.SendPacket(new TextPacket
         {
             BubbleTime = 0,
             Stars      = -1,
             Name       = "#Zylixel News",
             Text       = text.ToSafeText()
         });
     }
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("<Zylixel News> {0}", text);
     }
 }
示例#9
0
 protected override void Init()
 {
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Initializing Game World {0}({1}) from map {2}...", Id, Name, _mapId);
     }
     LoadMap("wServer.realm.worlds.maps.world" + _mapId + ".wmap", MapType.Wmap);
     SetPieces.ApplySetPieces(this);
     if (_oryxPresent)
     {
         Overseer = new Oryx(this);
     }
     else
     {
         Overseer = null;
     }
     if (CheckConfig.IsDebugOn())
     {
         Console.WriteLine("Game World initalized.");
     }
 }
示例#10
0
        public void TickLoop()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Logic loop started.");
            }
            Stopwatch watch = new Stopwatch();
            long      dt    = 0;
            long      count = 0;
            long      good  = 0;

            watch.Start();
            RealmTime t = new RealmTime();

            do
            {
                if (Manager.Terminating)
                {
                    break;
                }

                long times = dt / MsPT;
                dt -= times * MsPT;
                times++;

                long b = watch.ElapsedMilliseconds;

                count += times;
                if (times > 3)
                {
                    Program.writeNotable("LAGGED!| time:" + times + " dt:" + dt + " count:" + count + " time:" + b + " tps:" +
                                         count / (b / 1000.0));
                    if (dt > 2000)
                    {
                        foreach (Client i in Manager.Clients.Values)
                        {
                            i.Player.ApplyConditionEffect(new ConditionEffect
                            {
                                Effect     = ConditionEffectIndex.Invulnerable,
                                DurationMS = 5 * 1000
                            });
                            i.Player.SendInfo("Lag Detected, giving Invulnerability to prevent death");
                        }
                    }
                    foreach (Client i in Manager.Clients.Values)
                    {
                        if (i.Player != null)
                        {
                            i.Player.dexShotViolation = 0;
                        }
                    }
                    Program.isLagging = true;
                    good = 0;
                }
                if (good > 100)
                {
                    Program.isLagging = false;
                }
                good++;

                t.tickTimes      = b;
                t.tickCount      = count;
                t.thisTickCounts = (int)times;
                t.thisTickTimes  = (int)(times * MsPT);

                foreach (ConcurrentQueue <Action <RealmTime> > i in pendings)
                {
                    Action <RealmTime> callback;
                    while (i.TryDequeue(out callback))
                    {
                        try
                        {
                            callback(t);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                }
                TickWorlds1(t);

                Player[] tradingPlayers = TradeManager.TradingPlayers.Where(_ => _.Owner == null).ToArray();
                foreach (var player in tradingPlayers)
                {
                    TradeManager.TradingPlayers.Remove(player);
                }

                KeyValuePair <Player, Player>[] requestPlayers = TradeManager.CurrentRequests.Where(_ => _.Key.Owner == null || _.Value.Owner == null).ToArray();
                foreach (var players in requestPlayers)
                {
                    TradeManager.CurrentRequests.Remove(players);
                }

                try
                {
                    GuildManager.Tick(CurrentTime);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                Thread.Sleep(MsPT);
                dt += Math.Max(0, watch.ElapsedMilliseconds - b - MsPT);
            } while (true);
            Console.WriteLine("Logic loop stopped.");
        }