示例#1
0
        private void SetupNetwork()
        {
            netDefs = new NetDefinitions();
            server  = new AsteroidServer(netDefs, Resolution.ToVector2(), 11002);

            client = new NetworkClient(new UDPConnection(
                                           System.Net.IPAddress.Parse((server != null) ? "127.0.0.1" : "122.58.99.13"),
                                           11002, // Change this destination to 12002 to connect to a running NetProxy.
                                           (server != null) ? 11003 : 11002
                                           ));
            client.Connection.Compression = AsteroidServer.NetworkCompression;
            client.Connection.Stats.ByteAggregationPeriodMilliseconds = 100;

            // Note, when using NetProxy with this setup, the Open command should be:
            // open 12002 11003 12003 11002

            incomingPool = new IncomingSyncPool(netDefs, 0);
            outgoingPool = new OutgoingSyncPool(netDefs, 0);
            client.Attach(incomingPool);
            client.Attach(outgoingPool);
            controlVector = new PlayerControl()
            {
                Ready      = true,
                PlayerName = System.Environment.MachineName
            };
            outgoingPool.AddEntity(controlVector);

            client.SetState(NetworkClient.ConnectionState.Open);
        }
示例#2
0
 public AirlockHostedClient(NetDefinitions netDefs, NetworkClient client, OutgoingSyncPool worldContent)
 {
     Network       = client;
     ReturnContent = new IncomingSyncPool(netDefs, (ushort)AirlockServer.SyncPoolID.ReturnContent);
     ClientContent = new OutgoingSyncPool(netDefs, (ushort)AirlockServer.SyncPoolID.ClientContent);
     ClientContent.LinkedPools.Add(worldContent);
     Network.Attach(ReturnContent);
     Network.Attach(ClientContent);
     Network.SetState(NetworkClient.ConnectionState.Open);
     ClientInfo = new ClientInfo();
     ClientContent.AddEntity(ClientInfo);
 }
示例#3
0
        public AirlockServer(int port)
        {
            Server = new UDPServer(port);
            Server.IncomingConnectionLimit = MaxPlayers;
            Clients = new List <AirlockHostedClient>();

            NetDefs = new NetDefinitions();
            NetDefs.LoadEntityTypes();
            WorldContent = new OutgoingSyncPool(NetDefs, (ushort)SyncPoolID.WorldContent);

            Entities = new List <Entity>();
            Grid     = MapGrid.StartingMap();

            AddEntity(new DroppedItem(new Vector2(200, -200)));

            foreach (MapRoom room in Grid.Rooms)
            {
                WorldContent.AddEntity(room);
            }
        }
示例#4
0
        public AsteroidServer(NetDefinitions netdefs, Vector2 boundary, int port)
        {
            NetDefs = netdefs;

            Boundary           = boundary;
            Server             = new UDPServer(port);
            Server.Compression = NetworkCompression;
            MaxPlayers         = 8;

            OutgoingPool   = new OutgoingSyncPool(netdefs, 0);
            Physicals      = new List <Physical>();
            Projectiles    = new List <Projectile>();
            CollisionWorld = new VoltWorld(0, 1.0f);

            Clients = new List <RemoteClient>();

            Context = new ContextToken(this);

            int k = 4;

            for (int i = 0; i < 30 * k; i++)
            {
                AddEntity(NewAsteroid(32));
            }
            for (int i = 0; i < 40 * k; i++)
            {
                AddEntity(NewAsteroid(48));
            }
            for (int i = 0; i < 10 * k; i++)
            {
                AddEntity(NewAsteroid(56));
            }

            OutgoingPool.AddEntity(serverReport);

            LastTimestamp = 0;
            Random        = new Random((int)System.DateTime.UtcNow.ToBinary());
        }
示例#5
0
        private void AddEntity(Entity entity)
        {
            //ListStreaming
            //serverReport.Entities.Add(entity);
            entity.SetContext(Context);

            if (entity is Physical phys)
            {
                phys.GenerateBody(CollisionWorld);
                Physicals.Add(phys);
            }
            else if (entity is Projectile proj)
            {
                Projectiles.Add(proj);
            }
            else
            {
                throw new ArgumentException();
            }

            entity.UpdateMotion(NetTime.Now());
            OutgoingPool.AddEntity(entity);
        }
示例#6
0
        public AirlockClient(IPAddress address, int destport, int srcport)
        {
            Network = new NetworkClient(new UDPConnection(address, destport, srcport));

            NetDefinitions netDefs = new NetDefinitions();

            netDefs.LoadEntityTypes();

            WorldContent  = new IncomingSyncPool(netDefs, (ushort)AirlockServer.SyncPoolID.WorldContent);
            ReturnContent = new OutgoingSyncPool(netDefs, (ushort)AirlockServer.SyncPoolID.ReturnContent);
            ClientContent = new IncomingSyncPool(netDefs, (ushort)AirlockServer.SyncPoolID.ClientContent);
            ClientContent.LinkedPools.Add(WorldContent);
            Network.Attach(WorldContent);
            Network.Attach(ReturnContent);
            Network.Attach(ClientContent);

            Network.SetState(NetworkClient.ConnectionState.Open);
            LocalPlayer = new LocalPlayer();
            ReturnContent.AddEntity(LocalPlayer);

            Inputs = new ClientInputs();

            Grid = new MapGrid();
        }
示例#7
0
 public void AddEntity(Entity entity)
 {
     Entities.Add(entity);
     WorldContent.AddEntity(entity);
 }