Exemplo n.º 1
0
        public void GetIP(ulong steamId = 0)
        {
            var state = new P2PSessionState();

            if (steamId == 0)
            {
                steamId = Context.Player.SteamUserId;
            }
            Peer2Peer.GetSessionState(steamId, ref state);
            var ip = new IPAddress(BitConverter.GetBytes(state.RemoteIP).Reverse().ToArray());

            Context.Respond($"Your IP is {ip}");
        }
Exemplo n.º 2
0
        //Largely copied from SE
        private void ValidateAuthTicketResponse(ulong steamId, JoinResult response, ulong steamOwner)
        {
            var state = new P2PSessionState();

            Peer2Peer.GetSessionState(steamId, ref state);
            var ip = state.GetRemoteIP();

            _log.Debug($"ValidateAuthTicketResponse(user={steamId}, response={response}, owner={steamOwner})");

            _log.Info($"Connection attempt by {steamId} from {ip}");
            // TODO implement IP bans
            var config = (TorchConfig)Torch.Config;

            if (config.EnableWhitelist && !config.Whitelist.Contains(steamId))
            {
                _log.Warn($"Rejecting user {steamId} because they are not whitelisted in Torch.cfg.");
                UserRejected(steamId, JoinResult.NotInGroup);
            }
            else if (Torch.CurrentSession.KeenSession.OnlineMode == MyOnlineModeEnum.OFFLINE &&
                     !Torch.CurrentSession.KeenSession.IsUserAdmin(steamId))
            {
                _log.Warn($"Rejecting user {steamId}, world is set to offline and user is not admin.");
                UserRejected(steamId, JoinResult.TicketCanceled);
            }
            else if (MySandboxGame.ConfigDedicated.GroupID == 0uL)
            {
                RunEvent(new ValidateAuthTicketEvent(steamId, steamOwner, response, 0, true, false));
            }
            else if (_getServerAccountType(MySandboxGame.ConfigDedicated.GroupID) != MyGameServiceAccountType.Clan)
            {
                UserRejected(steamId, JoinResult.GroupIdInvalid);
            }
            else if (MyGameService.GameServer.RequestGroupStatus(steamId, MySandboxGame.ConfigDedicated.GroupID))
            {
                lock (_waitingForGroupLocal)
                {
                    if (_waitingForGroupLocal.Count >= _waitListSize)
                    {
                        _waitingForGroupLocal.RemoveAt(0);
                    }
                    _waitingForGroupLocal.Add(new WaitingForGroup(steamId, response, steamOwner));
                }
            }
            else
            {
                UserRejected(steamId, JoinResult.SteamServersOffline);
            }
        }
Exemplo n.º 3
0
        private static void DownloadWorld(MyGuiScreenProgress progress, MyMultiplayerBase multiplayer)
        {
            if (progress.Text != null)
            {
                progress.Text.Clear();
                progress.Text.Append(MyTexts.Get(MySpaceTexts.MultiplayerStateConnectingToServer));
            }

            MyLog.Default.WriteLine("World requested");

            const float worldRequestTimeout = 40; // in seconds
            Stopwatch   worldRequestTime    = Stopwatch.StartNew();

            ulong serverId  = multiplayer.GetOwner();
            bool  connected = false;

            progress.Tick += () =>
            {
                P2PSessionState state = default(P2PSessionState);
                Peer2Peer.GetSessionState(multiplayer.ServerId, ref state);

                if (!connected && state.ConnectionActive)
                {
                    MyLog.Default.WriteLine("World requested - connection alive");
                    connected = true;
                    if (progress.Text != null)
                    {
                        progress.Text.Clear();
                        progress.Text.Append(MyTexts.Get(MySpaceTexts.MultiplayerStateWaitingForServer));
                    }
                }

                //progress.Text.Clear();
                //progress.Text.AppendLine("Connecting: " + state.Connecting);
                //progress.Text.AppendLine("ConnectionActive: " + state.ConnectionActive);
                //progress.Text.AppendLine("Relayed: " + state.UsingRelay);
                //progress.Text.AppendLine("Bytes queued: " + state.BytesQueuedForSend);
                //progress.Text.AppendLine("Packets queued: " + state.PacketsQueuedForSend);
                //progress.Text.AppendLine("Last session error: " + state.LastSessionError);
                //progress.Text.AppendLine("Original server: " + serverId);
                //progress.Text.AppendLine("Current server: " + multiplayer.Lobby.GetOwner());
                //progress.Text.AppendLine("Game version: " + multiplayer.AppVersion);

                if (serverId != multiplayer.GetOwner())
                {
                    MyLog.Default.WriteLine("World requested - failed, server changed");
                    progress.Cancel();
                    MyGuiSandbox.Show(MySpaceTexts.MultiplayerErrorServerHasLeft);
                    multiplayer.Dispose();
                }

                if (worldRequestTime.IsRunning && worldRequestTime.Elapsed.TotalSeconds > worldRequestTimeout)
                {
                    MyLog.Default.WriteLine("World requested - failed, server changed");
                    progress.Cancel();
                    MyGuiSandbox.Show(MySpaceTexts.MultiplaterJoin_ServerIsNotResponding);
                    multiplayer.Dispose();
                }
            };

            var downloadResult = multiplayer.DownloadWorld();

            downloadResult.ProgressChanged += (result) =>
            {
                worldRequestTime.Stop();
                OnDownloadProgressChanged(progress, result, multiplayer);
            };

            progress.ProgressCancelled += () =>
            {
                downloadResult.Cancel();
                multiplayer.Dispose();
                //var joinScreen = MyScreenManager.GetScreenWithFocus() as MyGuiScreenJoinGame;
                //if (joinScreen != null)
                //  joinScreen.ReloadList();
            };
        }