Ejemplo n.º 1
0
        public HostNetworkConnection(SkirmishGame game) : base(game)
        {
            _listener.ConnectionRequestEvent += request =>
            {
                Logger.Trace($"Accepting connection from {request.RemoteEndPoint}");

                var peer = request.Accept();

                Logger.Trace($"Accept result: {peer}");
            };
        }
Ejemplo n.º 2
0
        protected SkirmishManager(Game game, bool isHosting)
        {
            _game = game;

            _listener = new EventBasedNetListener();
            _manager  = new NetManager(_listener);

            _writer = new NetDataWriter();

            _processor = new NetPacketProcessor();
            _processor.RegisterNestedType(SkirmishSlot.Serialize, SkirmishSlot.Deserialize);

            IsHosting = isHosting;

            SkirmishGame = new SkirmishGame(isHost: IsHosting);
        }
Ejemplo n.º 3
0
        public NetworkConnection(SkirmishGame game)
        {
            _numberOfOtherPlayers = game.Slots.Count(s => s.State == SkirmishSlotState.Human) - 1;
            _listener             = new EventBasedNetListener();
            _manager = new NetManager(_listener);

            if (Debugger.IsAttached)
            {
                _manager.DisconnectTimeout = 600000;
            }

            _listener.PeerConnectedEvent    += peer => Logger.Trace($"{peer.EndPoint} connected");
            _listener.PeerDisconnectedEvent += (peer, info) => Logger.Trace($"{peer.EndPoint} disconnected with reason {info.Reason}");
            _listener.NetworkReceiveEvent   += (NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) => _processor.ReadAllPackets(reader, peer);

            _writer    = new NetDataWriter();
            _processor = new NetPacketProcessor();
            _processor.RegisterNestedType <Order>(WriteOrder, ReadOrder);
            _processor.Subscribe <SkirmishOrderPacket, NetPeer>(ReceiveOrderPacket, () => new SkirmishOrderPacket());
        }
Ejemplo n.º 4
0
        protected SkirmishManager(Game game, bool isHosting)
        {
            _game = game;

            _listener = new EventBasedNetListener();
            _manager  = new NetManager(_listener)
            {
                ReuseAddress = true,
                IPv6Enabled  = IPv6Mode.Disabled, // TODO: temporary
            };

            _writer = new NetDataWriter();

            _processor = new NetPacketProcessor();
            _processor.RegisterNestedType(SkirmishSlot.Serialize, SkirmishSlot.Deserialize);

            IsHosting = isHosting;

            SkirmishGame = new SkirmishGame(isHost: IsHosting);
        }
Ejemplo n.º 5
0
            protected override void Loop()
            {
                switch (SkirmishGame.Status)
                {
                case SkirmishGameStatus.Configuring when SkirmishGame.IsDirty:
                    _writer.Put((byte)PacketType.SkirmishSlotStatus);
                    _processor.Write(_writer, new SkirmishGameStatusPacket()
                    {
                        MapName = SkirmishGame.MapName,
                        Slots   = SkirmishGame.Slots
                    });

                    _manager.SendToAll(_writer, DeliveryMethod.ReliableUnordered);

                    SkirmishGame.ResetDirty();
                    break;

                case SkirmishGameStatus.SendingStartSignal:
                    _writer.Put((byte)PacketType.SkirmishStartGame);
                    _processor.Write(_writer, new SkirmishStartGamePacket()
                    {
                        Seed = SkirmishGame.Seed
                    });

                    _manager.SendToAll(_writer, DeliveryMethod.ReliableUnordered);
                    SkirmishGame.Status = SkirmishGameStatus.WaitingForAllPlayers;
                    break;

                case SkirmishGameStatus.WaitingForAllPlayers:
                    if (Connection != null)
                    {
                        SkirmishGame.Status = SkirmishGameStatus.ReadyToStart;
                    }
                    break;

                case SkirmishGameStatus.ReadyToStart:
                case SkirmishGameStatus.Started:
                    Stop();
                    break;
                }
            }
Ejemplo n.º 6
0
 public ClientNetworkConnection(SkirmishGame game) : base(game)
 {
     _hostAddress = game.Slots[0].EndPoint.Address;
 }