Пример #1
0
    private void DisconnetPlayer(NetIncomingMessage incmsg)
    {
        string   playerName = incmsg.ReadString();
        World    w          = serverCore.GetWorld();
        DataBase db         = serverCore.GetDataBase();

        for (int i = 0; i < w.ships.Count; i++)
        {
            if (w.ships[i].shipName.Equals(playerName))
            {
                incmsg.SenderConnection.Disconnect("bye");
                //System.Threading.Thread.Sleep(100);
                ServerCore.LogAdd(playerName + " disconnected.");

                if (ServerCore.GetServerCore().GetServer().ConnectionsCount != 0)
                {
                    NetOutgoingMessage outmsg = serverCore.CreateMessage();
                    outmsg.Write((byte)PacketType.Disconnect);
                    outmsg.Write(playerName);
                    ServerPacketSender.SendMessageToAll(outmsg);
                }
                db.SaveUser(playerName, w.ships[i]);
                w.ships.RemoveAt(i);
                i--;
                break;
            }
        }
    }
Пример #2
0
 public override bool LeftClick()
 {
     if (buttons[0].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y)))
     {
         core.SetWorld(new World(true));
         core.currentGui = null;
         Thread t = new Thread(StartLocalServer);
         t.Start();
         Core.console.AddDebugString("Starting client world...");
         ClientNetwork.GetClientNetwork().Start();
         return(true);
     }
     else if (buttons[1].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y)))
     {
         core.currentGui = new GuiConnect(false);
         return(true);
     }
     else if (buttons[2].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y)))
     {
         core.currentGui = new GuiConnect(true);
         return(true);
     }
     else if (buttons[3].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y)))
     {
         core.currentGui = new GuiSettings(this);
         return(true);
     }
     else if (buttons[4].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y)))
     {
         core.isExit = true;
         if (ServerCore.GetServerCore() != null && ServerCore.GetServerCore().GetServer().Status == NetPeerStatus.Running)
         {
             Core.console.AddDebugString("Closing server...");
             Thread t = new Thread(() => ServerCore.GetServerCore().Stop());
             t.Start();
             //ServerCore.instance.Stop();
         }
         return(true);
     }
     else if (Settings.isDebug && buttons[5].Rect.Contains(new Point((int)core.inputManager.cursor.Position.X, (int)core.inputManager.cursor.Position.Y)))
     {
         core.SetWorld(new World(true));
         int[] components = { 1, 1, 1, 1, 1, 1, 1 };
         Ship  s          = new Ship(Vector2.Zero, Vector2.Zero, Faction.Human, ShipType.HumanSmall1, components, world, 0, 0);
         s.shipName = "Debug";
         GunSlot[] gs = { new GunSlot(GunType.PlasmSmall, s), null };
         s.AddGuns(gs);
         world.ships.Add(s);
         core.currentGui = new GuiSelectFaction();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        private void SpawnShips()
        {
            World w = ServerCore.GetServerCore().GetWorld();

            if (faction == Faction.Enemy)
            {
                if (spawnerType == SpawnerType.Easy)
                {
                    for (int i = 0; i < maxShips; i++)
                    {
                        Vector2 rndVector = new Vector2(core.random.Next(-500, 500), core.random.Next(-500, 500)) + Position;
                        int[]   comp      = { 1, 1, 0, 0, 0, 0, 0 };
                        //r e s a a a a;
                        ShipNPC   s  = new ShipNPC(rndVector, rndVector, faction, ShipType.EnemySmall1, comp, w, AiSearchType.Around, AiAgressiveType.Attack);
                        GunSlot[] gs = { new GunSlot(GunType.LaserSmall, s), new GunSlot(GunType.LaserSmall, s) };
                        s.AddGuns(gs);
                        s.cargoSize = s.maxCargoSize;
                        s.crewSize  = s.maxCrewSize;
                        s.shipName  = "<BOT> Saimon";
                        s.id        = w.GetNpcId();
                        ships.Add(s);
                        w.shipsNpc.Add(s);
                        ServerPacketSender.SendCreateNpcShip(s);
                    }
                }
            }
            else if (faction == Faction.Human)
            {
                if (spawnerType == SpawnerType.Easy)
                {
                    for (int i = 0; i < maxShips; i++)
                    {
                        Vector2 rndVector = new Vector2(core.random.Next(-500, 500), core.random.Next(-500, 500)) + Position;
                        int[]   comp      = { 1, 1, 0, 0, 0, 0, 0 };
                        //r e s a a a a;
                        ShipNPC   s  = new ShipNPC(rndVector, rndVector, faction, ShipType.HumanSmall1, comp, w, AiSearchType.Around, AiAgressiveType.Attack);
                        GunSlot[] gs = { new GunSlot(GunType.PlasmSmall, s), new GunSlot(GunType.PlasmSmall, s) };
                        s.AddGuns(gs);
                        s.cargoSize = s.maxCargoSize;
                        s.crewSize  = s.maxCrewSize;
                        s.shipName  = "<BOT> Human";
                        s.id        = w.GetNpcId();
                        ships.Add(s);
                        w.shipsNpc.Add(s);
                        ServerPacketSender.SendCreateNpcShip(s);
                    }
                }
            }
            else if (faction == Faction.Civilian)
            {
                if (spawnerType == SpawnerType.Easy)
                {
                    for (int i = 0; i < maxShips; i++)
                    {
                        Vector2 rndVector = new Vector2(core.random.Next(-500, 500), core.random.Next(-500, 500)) + Position;
                        int[]   comp      = { 1, 1, 0, 0, 0, 0, 0 };
                        //r e s a a a a;
                        ShipNPC   s  = new ShipNPC(rndVector, rndVector, faction, ShipType.CivSmall1, comp, w, AiSearchType.Around, AiAgressiveType.Attack);
                        GunSlot[] gs = { new GunSlot(GunType.GausSmall, s), new GunSlot(GunType.GausSmall, s) };
                        s.AddGuns(gs);
                        s.cargoSize = s.maxCargoSize;
                        s.crewSize  = s.maxCrewSize;
                        s.shipName  = "<BOT> Engi";
                        s.id        = w.GetNpcId();
                        ships.Add(s);
                        w.shipsNpc.Add(s);
                        ServerPacketSender.SendCreateNpcShip(s);
                    }
                }
            }
        }