Пример #1
0
        /// <summary>
        ///     host request port from client
        /// </summary>
        private void ProcessMessage(ulong remoteUser, SteamP2PRequestPrepareProxy cmd)
        {
            DisposeExistingProxies();

            p2pProxies[remoteUser] = new SteamP2PPortProxy(cmd.Channel, new CSteamID(remoteUser), SteamP2PPortProxy.GetFreeUdpPort());

            SendSteamMessage(remoteUser, new SteamP2PConfirmCreateProxy()
            {
                Channel = cmd.Channel
            });
        }
Пример #2
0
 /// <summary>
 ///     client sends port to host
 /// </summary>
 private void ProcessMessage(ulong remoteUser, SteamP2PConfirmCreateProxy cmd)
 {
     p2pProxies[remoteUser] = new SteamP2PPortProxy(cmd.Channel, new CSteamID(remoteUser), gameHostUdpPort);
 }
Пример #3
0
        /// <summary>
        ///     chobby request p2p game to be created
        /// </summary>
        public void PrepareToHostP2PGame(SteamHostGameRequest request)
        {
            // clear old listeners
            DisposeExistingProxies();

            gameHostUdpPort = SteamP2PPortProxy.GetFreeUdpPort();

            // send channel numbers to players
            foreach (var player in request.Players)
            {
                ulong playerSteamID;
                ulong.TryParse(player.SteamID, out playerSteamID);

                p2pProxies[playerSteamID] = null;
                SendSteamMessage(playerSteamID, new SteamP2PRequestPrepareProxy()
                {
                    Channel = steamChannelCounter++
                });
            }

            // wait for response
            var startWait = DateTime.UtcNow;

            Task.Factory.StartNew(() =>
            {
                // wait 30s for all clients to respond
                while (p2pProxies.Any(x => x.Value == null))
                {
                    if (DateTime.UtcNow.Subtract(startWait).TotalSeconds > 30)
                    {
                        Listener.SendCommand(new SteamHostGameFailed()
                        {
                            CausedBySteamID = p2pProxies.Where(x => x.Value == null).Select(x => x.Key).FirstOrDefault().ToString(),
                            Reason          = "Client didn't send his confirmation"
                        });
                    }

                    Task.Delay(100);
                }

                // send command to start spring to all clients
                foreach (var cli in p2pProxies)
                {
                    var player = request.Players.First(x => x.SteamID == cli.Key.ToString());

                    // tell clients to connect to server's external port/IP
                    SendSteamMessage(cli.Key,
                                     new SteamP2PDirectConnectRequest()
                    {
                        Name           = player.Name,
                        Engine         = request.Engine,
                        Game           = request.Game,
                        Map            = request.Map,
                        ScriptPassword = player.ScriptPassword
                    });
                }

                // send command to start spring to self
                Listener.SendCommand(new SteamHostGameSuccess()
                {
                    HostPort = gameHostUdpPort
                });
            });
        }