예제 #1
0
        public void Test()
        {
            var logger = new TestLogger();
            var config = new DefaultServerConfig();

            var playerConnections = new PlayerConnectionManager(logger, config.PlayerConnection);
            var udpTransport      = new ServerUdpPacketTransport(
                logger,
                config.NetworkTransport.PacketEncryptor,
                config.NetworkTransport,
                config.UdpServer);
            IPacketEncryptor packetEncryption = new XorPacketEncryptor();
            var channelManager = new OutgoingServerChannel(
                config.NetworkTransport,
                udpTransport,
                packetEncryption,
                logger);
            IGameWorldLoader gameWorldLoader = new GameWorldLoader();

            var gameWorld = new GameWorld(
                worldType: WorldType.New(),
                id: WorldInstanceId.New(),
                logger: logger,
                config: config,
                channelManager: channelManager,
                gameWorldLoader: gameWorldLoader);
        }
예제 #2
0
        public void Test()
        {
            var logger      = new TestLogger();
            var connections = new PlayerConnectionManager(
                logger,
                new PlayerConnectionConfig
            {
                Capacity = new PlayerConnectionConfig.CapacityConfig
                {
                    InitialConnectionsCapacity = 1
                }
            });

            Assert.Equal(0, connections.Count);

            var worldId       = new WorldInstanceId(0);
            var encryptionKey = new byte[] { 0x1 };

            connections.Add(worldId, new PlayerId(0), encryptionKey);
            connections.Add(worldId, new PlayerId(1), encryptionKey);
            connections.Add(worldId, new PlayerId(2), encryptionKey);

            Assert.Equal(3, connections.Count);

            ref readonly var connection1 = ref connections.Get(new PlayerId(0));
예제 #3
0
 public ConnectPlayerServerCommand(
     WorldInstanceId instanceId,
     PlayerId playerId,
     byte[] encryptionKey)
 {
     _instanceId    = instanceId;
     _playerId      = playerId;
     _encryptionKey = encryptionKey;
 }
예제 #4
0
        public bool Kill(WorldInstanceId id)
        {
            foreach (var instance in this._worldInstances)
            {
                instance.World.Stop();
                this._worldInstances.Remove(instance);

                return(true);
            }

            return(false);
        }
예제 #5
0
        public GameWorld Get(WorldInstanceId id)
        {
            foreach (var instance in this._worldInstances)
            {
                if (instance.World.InstanceId == id)
                {
                    return(instance.World);
                }
            }

            return(null);
        }
예제 #6
0
        public GameWorld CreateInstance(WorldInstanceId instanceId)
        {
            var gameWorld = new GameWorld(
                this._worldType,
                instanceId,
                this._logger,
                this._serverConfig,
                this._channelManager,
                this._worldLoader);

            return(gameWorld);
        }
예제 #7
0
파일: GameWorld.cs 프로젝트: danchart/Ecs
        public GameWorld(
            WorldType worldType,
            WorldInstanceId id,
            ILogger logger,
            IServerConfig config,
            OutgoingServerChannel channelManager,
            IGameWorldLoader gameWorldLoader)
        {
            this.WorldType  = worldType;
            this.InstanceId = id;
            this._logger    = logger ?? throw new ArgumentNullException(nameof(logger));
            this._isStopped = false;
            this._world     = new World(config.Ecs);

            this._fixedTick = config.Simulation.FixedTick;

            this._channelManager = channelManager ?? throw new ArgumentNullException(nameof(channelManager));

            this._simulationSynchronizer = new SimulationSynchronizer(this._world);
            this._entityGridMap          = new EntityGridMap(config.Replication.GridSize);

            this._players = new WorldPlayers(
                config.Replication,
                config.PlayerInput,
                config.PlayerConnection.Capacity.InitialConnectionsCapacity);

            this._replicationManager = new WorldReplicationManager(config.Replication, this._players, this._entityGridMap);

            this._physicsWorld = new VolatilePhysicsWorld(config.Replication.PhysicsHistoryCount);

            this._systems =
                new Systems(this._world)
                .Add(new PhysicsSystem())
                .Add(new ServerEntityReplicationSystem())
                .Add(new JiggleSystem())
                .Inject(this._physicsWorld)
                .Inject(new ReplicationDataBroker(config.Replication.Capacity, this._replicationManager))
                .Inject(this._entityGridMap);

            this._simulation = new ServerSimulation <InputComponent>(
                config.Simulation,
                this._world,
                this._systems);

            this._simulation.Create();

            gameWorldLoader.LoadWorld(this.WorldType, this._world, this._physicsWorld);
        }
예제 #8
0
파일: GameSever.cs 프로젝트: danchart/Ecs
        public bool DisconnectPlayer(
            WorldInstanceId instanceId,
            PlayerId playerId)
        {
            // TODO: Error handling.

            var gameWorld = this._gameWorlds.Get(instanceId);

            var playerConnectionRef = this._playerConnectionManager.GetRef(playerId);

            gameWorld.Disconnect(playerConnectionRef);

            // Remove player connection,
            this._playerConnectionManager.Remove(playerId);

            return(true);
        }
예제 #9
0
파일: GameSever.cs 프로젝트: danchart/Ecs
        public PlayerConnectionRef ConnectPlayer(
            WorldInstanceId instanceId,
            PlayerId playerId,
            byte[] encryptionKey)
        {
            // TODO: Error handling.
            var gameWorld = this._gameWorlds.Get(instanceId);

            // Create player connection.
            this._playerConnectionManager.Add(instanceId, playerId, encryptionKey);

            var playerConnectionRef = this._playerConnectionManager.GetRef(playerId);

            // Connect player to the world.
            gameWorld.Connect(playerConnectionRef);

            return(playerConnectionRef);
        }
예제 #10
0
        public GameWorld Spawn(IGameWorldFactory factory)
        {
            var worldInstanceId = new WorldInstanceId(this._nextInstanceId++);
            var world           = factory.CreateInstance(worldInstanceId);
            var thread          = new Thread(world.Run);

            this._worldInstances.Add(
                new GameWorldThread
            {
                World  = world,
                Thread = thread,
            });

            thread.Start();

            this._logger.Info($"Spawned world instance: id={world.InstanceId}, threadId={thread.ManagedThreadId}");

            return(world);
        }
예제 #11
0
파일: GameSever.cs 프로젝트: danchart/Ecs
 public bool KillWorld(WorldInstanceId id)
 {
     return(this._gameWorlds.Kill(id));
 }