Esempio n. 1
0
        private static void ProcessIncomingPacket(object sender, PacketReceivedEventArgs e)
        {
            NetworkPacket packet = e.Packet;

            packet.SourceIP = e.SourceIP;

            switch (packet.Type)
            {
            case PacketType.Ping:
                ProcessPing(packet);
                break;

            case PacketType.Salutation:
                ProcessSalutation(packet);
                break;

            case PacketType.Acknowledge:
                ProcessAcknowledge(packet);
                break;

            case PacketType.PlayerData:
                ProcessPlayerData(packet);
                break;

            default:
                // ignore other packet types -- they may be for someone else
                break;
            }
        }
Esempio n. 2
0
        private async void OnRequestReceived(object sender, PacketReceivedEventArgs e)
        {
            StreamSocket  source = e.Source;
            NetworkPacket packet = e.Packet;

            if (packet.Type == PacketType.LobbyCommand)
            {
                LobbyCommandPacket command  = packet as LobbyCommandPacket;
                string             playerID = command.PlayerID;

                if (Server)
                {
                    switch ((int)command.Command)
                    {
                    case (int)LobbyCommands.EnterLobby:
                        await ProcessEnterLobbyCommand(playerID, source.Information.RemoteAddress.DisplayName);

                        break;

                    case (int)LobbyCommands.LeaveLobby:
                        ProcessLeaveLobbyCommand(playerID);
                        break;

                    case (int)LobbyCommands.HostGame:
                        string hostIPAddress = command.Data;
                        ProcessHostGameCommand(playerID, hostIPAddress);
                        break;

                    case (int)LobbyCommands.JoinGame:
                        string hostID = command.Data;
                        ProcessJoinGameCommand(playerID, hostID);
                        break;

                    case (int)LobbyCommands.LeaveGame:
                        ProcessLeaveGameCommand(playerID);
                        break;

                    case (int)LobbyCommands.SetupGame:
                        await ProcessSetupGameCommand(playerID);

                        break;
                    }

                    await _lobbyCommandConnection.SendPacketTo(source, new AcknowledgePacket());
                    await UpdateAllClients();

                    MenuManager.PlayerListChanged();
                }
                else
                {
                    switch ((int)command.Command)
                    {
                    case (int)LobbyCommands.EjectThisUser:
                        ProcessEjectThisUserCommand();
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        private void ProcessIncomingPacket(object sender, PacketReceivedEventArgs e)
        {
            NetworkPacket packet = e.Packet;

            if (packet.Type == PacketType.Entity)
            {
                EntityPacket entityPacket = packet as EntityPacket;
                _updateQueue.Add(entityPacket);
            }
        }
Esempio n. 4
0
        internal async void OnPacketReceived(object network, PacketReceivedEventArgs args)

        {
            StreamSocket  source = args.Source;
            NetworkPacket packet = args.Packet;

            switch (packet.Type)
            {
            case PacketType.PlayerData:
                PlayerData data = packet as PlayerData;
                data.Location = source;
                if (_playerList.ContainsKey(data.PlayerID))
                {
                    _playerList[data.PlayerID] = data;
                }
                else
                {
                    _playerList.Add(data.PlayerID, data);
                }
                await SendPacketToAllClients(packet);

                if (Hosting)
                {
                    // check if we're ready to start game
                    // by seeing if all packets have a sourcesocket
                    bool ReadyToStart = true;
                    foreach (PlayerData player in _playerList.Values)
                    {
                        if (player.Location == null)
                        {
                            ReadyToStart = false;
                        }
                    }
                    if (ReadyToStart)
                    {
                        _gameData.Status = GameData.GameStatus.ReadyToStart;
                        await SendPacketToAllClients(_gameData);

                        OnGameChanged(_gameData);
                    }
                }
                break;

            case PacketType.GameData:
                _gameData = packet as GameData;
                // raise game changed event;
                OnGameChanged(_gameData);
                break;

            default:
                break;
            }
        }
Esempio n. 5
0
        internal async void OnPacketReceived(object network, PacketReceivedEventArgs args)
        {
            StreamSocket  source = args.Source;
            NetworkPacket packet = args.Packet;

            if (packet.Type == PacketType.LobbyCommand)
            {
                LobbyCommandPacket command  = packet as LobbyCommandPacket;
                string             playerID = command.PlayerID;

                if (Server)
                {
                    switch ((int)command.Command)
                    {
                    case (int)LobbyCommands.EnterLobby:
                        await ProcessEnterLobbyCommand(playerID, source.Information.RemoteAddress.DisplayName);

                        break;

                    case (int)LobbyCommands.LeaveLobby:
                        ProcessLeaveLobbyCommand(playerID);
                        break;

                    case (int)LobbyCommands.HostGame:
                        string hostIPAddress = command.Data;
                        ProcessHostGameCommand(playerID, hostIPAddress);
                        break;

                    case (int)LobbyCommands.JoinGame:
                        string hostID = command.Data;
                        ProcessJoinGameCommand(playerID, hostID);
                        break;

                    case (int)LobbyCommands.LeaveGame:
                        ProcessLeaveGameCommand(playerID);
                        break;

                    case (int)LobbyCommands.SetupGame:
                        await ProcessSetupGameCommand(playerID);

                        break;
                    }
                    await UpdateAllClients();

                    MenuManager.PlayerListChanged();
                }
                else
                {
                    switch ((int)command.Command)
                    {
                    case (int)LobbyCommands.EjectThisUser:
                        ProcessEjectThisUserCommand();
                        break;
                    }
                }
            }
            else if (packet.Type == PacketType.LobbyData && !Server)
            {
                LobbyData data = packet as LobbyData;
                _playerList = data._playerList;
                _gameList   = data._gameList;
                MenuManager.PlayerListChanged();
            }
        }