Exemplo n.º 1
0
 // Token: 0x06000986 RID: 2438 RVA: 0x00045F84 File Offset: 0x00044184
 public void Close()
 {
     if (this.m_con != HSteamNetConnection.Invalid)
     {
         ZLog.Log("Closing socket " + this.GetEndPointString());
         this.Flush();
         ZLog.Log("  send queue size:" + this.m_sendQueue.Count);
         Thread.Sleep(100);
         CSteamID steamID = this.m_peerID.GetSteamID();
         SteamNetworkingSockets.CloseConnection(this.m_con, 0, "", false);
         SteamUser.EndAuthSession(steamID);
         this.m_con = HSteamNetConnection.Invalid;
     }
     if (this.m_listenSocket != HSteamListenSocket.Invalid)
     {
         ZLog.Log("Stopping listening socket");
         SteamNetworkingSockets.CloseListenSocket(this.m_listenSocket);
         this.m_listenSocket = HSteamListenSocket.Invalid;
     }
     if (ZSteamSocket.m_hostSocket == this)
     {
         ZSteamSocket.m_hostSocket = null;
     }
     this.m_peerID.Clear();
 }
        public void ShutdownServer()
        {
            //foreach(Connection conn in steamworksServerManager.Connected)
            //{
            //    conn.Close();
            //}
            //steamworksServerManager.Close();
            //steamworksServerManager = null;
            //steamSocket = null;
            doCallbacks = false;

            foreach (ulong steamID in connectedSteamIDs)
            {
                SteamUser.EndAuthSession(steamID);
                SteamServer.EndSession(steamID);
            }
            connectedSteamIDs = new List <ulong>();

            SteamServer.Shutdown();

            if (NetTools.ENSManagingSteam())
            {
                //SteamServer.LogOff();

                if ((NetTools.isServer && NetServer.serverInstance.steamAppID != -1) || (NetTools.isClient && NetClient.instanceClient.steamAppID != -1))
                {
                    //SteamServer.Shutdown();
                    //SteamClient.Shutdown();
                }
            }
            serverRunning = false;
        }
Exemplo n.º 3
0
 private void Close(CSteamID user)
 {
     if (!this._connectionStateMap.ContainsKey(user))
     {
         return;
     }
     SteamUser.EndAuthSession(user);
     SteamNetworking.CloseP2PSessionWithUser(user);
     this._connectionStateMap[user] = NetSocialModule.ConnectionState.Inactive;
 }
 private void Close(CSteamID user)
 {
     if (_connectionStateMap.ContainsKey(user))
     {
         SteamUser.EndAuthSession(user);
         SteamNetworking.CloseP2PSessionWithUser(user);
         _connectionStateMap[user] = ConnectionState.Inactive;
         _reader.ClearUser(user);
         _writer.ClearUser(user);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Ends the authentication session.
 /// </summary>
 public void End()
 {
     if (isClientSession)
     {
         SteamUser.EndAuthSession(User);
     }
     else
     {
         SteamGameServer.EndAuthSession(User);
     }
 }
Exemplo n.º 6
0
 private void Close(CSteamID user)
 {
     //IL_0006: Unknown result type (might be due to invalid IL or missing references)
     //IL_000f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0015: Unknown result type (might be due to invalid IL or missing references)
     //IL_0022: Unknown result type (might be due to invalid IL or missing references)
     //IL_002f: Unknown result type (might be due to invalid IL or missing references)
     //IL_003b: Unknown result type (might be due to invalid IL or missing references)
     if (_connectionStateMap.ContainsKey(user))
     {
         SteamUser.EndAuthSession(user);
         SteamNetworking.CloseP2PSessionWithUser(user);
         _connectionStateMap[user] = ConnectionState.Inactive;
         _reader.ClearUser(user);
         _writer.ClearUser(user);
     }
 }
Exemplo n.º 7
0
 // Token: 0x060009A6 RID: 2470 RVA: 0x000467D8 File Offset: 0x000449D8
 public void Close()
 {
     ZLog.Log("Closing socket " + this.GetEndPointString());
     if (this.m_peerID != CSteamID.Nil)
     {
         this.Flush();
         ZLog.Log("  send queue size:" + this.m_sendQueue.Count);
         Thread.Sleep(100);
         P2PSessionState_t p2PSessionState_t;
         SteamNetworking.GetP2PSessionState(this.m_peerID, out p2PSessionState_t);
         ZLog.Log("  P2P state, bytes in send queue:" + p2PSessionState_t.m_nBytesQueuedForSend);
         SteamNetworking.CloseP2PSessionWithUser(this.m_peerID);
         SteamUser.EndAuthSession(this.m_peerID);
         this.m_peerID = CSteamID.Nil;
     }
     this.m_listner = false;
 }
        private void DirectKick(NetworkPlayer player, string reason, float delay = 0f)
        {
            Thread.Sleep((int)(delay * 1000)); //Convert to milliseconds.
            ConnectionPacket cP = new ConnectionPacket(true, reason);

            Packet p = new Packet(Packet.pType.connectionPacket, Packet.sendType.nonbuffered, ENSSerialization.SerializeConnectionPacket(cP));

            p.packetOwnerID   = -1;
            p.sendToAll       = false;
            p.serverAuthority = true;
            SendPacket(player, p);
            player.netStream.Close();
            player.playerConnected = false;
            SteamServer.EndSession(player.steamID);
            SteamUser.EndAuthSession(player.steamID);
            if (connections.Contains(player))
            {
                connections.Remove(player);
            }
            Debug.Log("Client<" + player.steamID + "> has been kicked for: " + reason);
        }
Exemplo n.º 9
0
        private IEnumerator VoteWithSteamID(bool upvote)
        {
            if (!SteamManager.Initialized)
            {
                Plugin.log.Error($"SteamManager is not initialized!");
            }

            _upvoteButton.interactable   = false;
            _downvoteButton.interactable = false;

            Plugin.log.Info($"Getting a ticket...");

            var    steamId             = SteamUser.GetSteamID();
            string authTicketHexString = "";

            byte[] authTicket       = new byte[1024];
            var    authTicketResult = SteamUser.GetAuthSessionTicket(authTicket, 1024, out var length);

            if (authTicketResult != HAuthTicket.Invalid)
            {
                var beginAuthSessionResult = SteamUser.BeginAuthSession(authTicket, (int)length, steamId);
                switch (beginAuthSessionResult)
                {
                case EBeginAuthSessionResult.k_EBeginAuthSessionResultOK:
                    var result = SteamUser.UserHasLicenseForApp(steamId, new AppId_t(620980));

                    SteamUser.EndAuthSession(steamId);

                    switch (result)
                    {
                    case EUserHasLicenseForAppResult.k_EUserHasLicenseResultDoesNotHaveLicense:
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "User does not\nhave license";
                        yield break;

                    case EUserHasLicenseForAppResult.k_EUserHasLicenseResultHasLicense:
                        if (SteamHelper.m_GetAuthSessionTicketResponse == null)
                        {
                            SteamHelper.m_GetAuthSessionTicketResponse = Callback <GetAuthSessionTicketResponse_t> .Create(OnAuthTicketResponse);
                        }

                        SteamHelper.lastTicket = SteamUser.GetAuthSessionTicket(authTicket, 1024, out length);
                        if (SteamHelper.lastTicket != HAuthTicket.Invalid)
                        {
                            Array.Resize(ref authTicket, (int)length);
                            authTicketHexString = BitConverter.ToString(authTicket).Replace("-", "");
                        }

                        break;

                    case EUserHasLicenseForAppResult.k_EUserHasLicenseResultNoAuth:
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "User is not\nauthenticated";
                        yield break;
                    }
                    break;

                default:
                    _upvoteButton.interactable   = false;
                    _downvoteButton.interactable = false;
                    _ratingText.text             = "Auth\nfailed";
                    yield break;
                }
            }

            Plugin.log.Info("Waiting for Steam callback...");

            float startTime = Time.time;

            yield return(new WaitWhile(() => { return SteamHelper.lastTicketResult != EResult.k_EResultOK && (Time.time - startTime) < 20f; }));

            if (SteamHelper.lastTicketResult != EResult.k_EResultOK)
            {
                Plugin.log.Error($"Auth ticket callback timeout");
                _upvoteButton.interactable   = true;
                _downvoteButton.interactable = true;
                _ratingText.text             = "Callback\ntimeout";
                yield break;
            }

            SteamHelper.lastTicketResult = EResult.k_EResultRevoked;

            Plugin.log.Info($"Voting...");

            Payload payload = new Payload()
            {
                steamID = steamId.m_SteamID.ToString(), ticket = authTicketHexString, direction = (upvote ? 1 : -1)
            };
            string json = JsonUtility.ToJson(payload);

            Plugin.log.Info(json);
            UnityWebRequest voteWWW = UnityWebRequest.Post($"{PluginConfig.beatsaverURL}/api/vote/steam/{_lastBeatSaverSong.key}", json);

            byte[] jsonBytes = new System.Text.UTF8Encoding().GetBytes(json);
            voteWWW.uploadHandler = new UploadHandlerRaw(jsonBytes);
            voteWWW.SetRequestHeader("Content-Type", "application/json");
            voteWWW.timeout = 30;
            yield return(voteWWW.SendWebRequest());

            if (voteWWW.isNetworkError)
            {
                Plugin.log.Error(voteWWW.error);
                _ratingText.text = voteWWW.error;
            }
            else
            {
                if (!_firstVote)
                {
                    yield return(new WaitForSecondsRealtime(2f));
                }

                _firstVote = false;

                if (voteWWW.responseCode >= 200 && voteWWW.responseCode <= 299)
                {
                    //              Plugin.log.Info(voteWWW.downloadHandler.text);
                    JObject node = JObject.Parse(voteWWW.downloadHandler.text);
                    //         Plugin.log.Info(((int)node["stats"]["upVotes"]).ToString() + " -- " + ((int)(node["stats"]["downVotes"])).ToString());
                    _ratingText.text = (((int)node["stats"]["upVotes"]) - ((int)node["stats"]["downVotes"])).ToString();

                    if (upvote)
                    {
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = true;
                    }
                    else
                    {
                        _downvoteButton.interactable = false;
                        _upvoteButton.interactable   = true;
                    }
                    string lastlevelHash = SongCore.Utilities.Hashing.GetCustomLevelHash(_lastLevel as CustomPreviewBeatmapLevel).ToLower();
                    if (!PluginConfig.votedSongs.ContainsKey(lastlevelHash))
                    {
                        PluginConfig.votedSongs.Add(lastlevelHash, new SongVote(_lastBeatSaverSong.key, upvote ? VoteType.Upvote : VoteType.Downvote));
                        PluginConfig.SaveConfig();
                    }
                    else if (PluginConfig.votedSongs[lastlevelHash].voteType != (upvote ? VoteType.Upvote : VoteType.Downvote))
                    {
                        PluginConfig.votedSongs[lastlevelHash] = new SongVote(_lastBeatSaverSong.key, upvote ? VoteType.Upvote : VoteType.Downvote);
                        PluginConfig.SaveConfig();
                    }
                }
                else
                {
                    switch (voteWWW.responseCode)
                    {
                    case 500:
                    {
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "Server \nerror";
                        Plugin.log.Error("Error: " + voteWWW.downloadHandler.text);
                    }; break;

                    case 401:
                    {
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "Invalid\nauth ticket";
                        Plugin.log.Error("Error: " + voteWWW.downloadHandler.text);
                    }; break;

                    case 404:
                    {
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "Beatmap not\found";
                        Plugin.log.Error("Error: " + voteWWW.downloadHandler.text);
                    }; break;

                    case 400:
                    {
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "Bad\nrequest";
                        Plugin.log.Error("Error: " + voteWWW.downloadHandler.text);
                    }; break;

                    default:
                    {
                        _upvoteButton.interactable   = true;
                        _downvoteButton.interactable = true;
                        _ratingText.text             = "Error\n" + voteWWW.responseCode;
                        Plugin.log.Error("Error: " + voteWWW.downloadHandler.text);
                    }; break;
                    }
                }
            }
        }
Exemplo n.º 10
0
        private IEnumerator VoteWithSteamID(bool upvote)
        {
            if (!SteamManager.Initialized)
            {
                Logger.Error($"SteamManager is not initialized!");
            }

            _upvoteButton.interactable   = false;
            _downvoteButton.interactable = false;

            Logger.Log($"Getting a ticket...");

            var    steamId             = SteamUser.GetSteamID();
            string authTicketHexString = "";

            byte[] authTicket       = new byte[1024];
            var    authTicketResult = SteamUser.GetAuthSessionTicket(authTicket, 1024, out var length);

            if (authTicketResult != HAuthTicket.Invalid)
            {
                var beginAuthSessionResult = SteamUser.BeginAuthSession(authTicket, (int)length, steamId);
                switch (beginAuthSessionResult)
                {
                case EBeginAuthSessionResult.k_EBeginAuthSessionResultOK:
                    var result = SteamUser.UserHasLicenseForApp(steamId, new AppId_t(620980));

                    SteamUser.EndAuthSession(steamId);

                    switch (result)
                    {
                    case EUserHasLicenseForAppResult.k_EUserHasLicenseResultDoesNotHaveLicense:
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "User does not\nhave license";
                        yield break;

                    case EUserHasLicenseForAppResult.k_EUserHasLicenseResultHasLicense:
                        if (SteamHelper.m_GetAuthSessionTicketResponse == null)
                        {
                            SteamHelper.m_GetAuthSessionTicketResponse = Callback <GetAuthSessionTicketResponse_t> .Create(OnAuthTicketResponse);
                        }

                        SteamHelper.lastTicket = SteamUser.GetAuthSessionTicket(authTicket, 1024, out length);
                        if (SteamHelper.lastTicket != HAuthTicket.Invalid)
                        {
                            Array.Resize(ref authTicket, (int)length);
                            authTicketHexString = BitConverter.ToString(authTicket).Replace("-", "");
                        }

                        break;

                    case EUserHasLicenseForAppResult.k_EUserHasLicenseResultNoAuth:
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = false;
                        _ratingText.text             = "User is not\nauthenticated";
                        yield break;
                    }
                    break;

                default:
                    _upvoteButton.interactable   = false;
                    _downvoteButton.interactable = false;
                    _ratingText.text             = "Auth\nfailed";
                    yield break;
                }
            }

            Logger.Log("Waiting for Steam callback...");

            float startTime = Time.time;

            yield return(new WaitWhile(() => { return SteamHelper.lastTicketResult != EResult.k_EResultOK && (Time.time - startTime) < 20f; }));

            if (SteamHelper.lastTicketResult != EResult.k_EResultOK)
            {
                Logger.Error($"Auth ticket callback timeout");
                _upvoteButton.interactable   = true;
                _downvoteButton.interactable = true;
                _ratingText.text             = "Callback\ntimeout";
                yield break;
            }

            SteamHelper.lastTicketResult = EResult.k_EResultRevoked;

            Logger.Log($"Voting...");

            Dictionary <string, string> formData = new Dictionary <string, string> ();

            formData.Add("id", steamId.m_SteamID.ToString());
            formData.Add("ticket", authTicketHexString);

            UnityWebRequest voteWWW = UnityWebRequest.Post($"{PluginConfig.beatsaverURL}/api/songs/voteById/{_lastBeatSaverSong.id}/{(upvote ? 1 : 0)}", formData);

            voteWWW.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            voteWWW.timeout = 30;
            yield return(voteWWW.SendWebRequest());

            if (voteWWW.isNetworkError)
            {
                Logger.Error(voteWWW.error);
                _ratingText.text = voteWWW.error;
            }
            else
            {
                if (!_firstVote)
                {
                    yield return(new WaitForSecondsRealtime(2f));
                }

                _firstVote = false;

                switch (voteWWW.responseCode)
                {
                case 200:
                {
                    JSONNode node = JSON.Parse(voteWWW.downloadHandler.text);
                    _ratingText.text = (int.Parse(node["upVotes"]) - int.Parse(node["downVotes"])).ToString();

                    if (upvote)
                    {
                        _upvoteButton.interactable   = false;
                        _downvoteButton.interactable = true;
                    }
                    else
                    {
                        _downvoteButton.interactable = false;
                        _upvoteButton.interactable   = true;
                    }

                    if (!PluginConfig.votedSongs.ContainsKey(_lastLevel.levelID.Substring(0, 32)))
                    {
                        PluginConfig.votedSongs.Add(_lastLevel.levelID.Substring(0, 32), new SongVote(_lastBeatSaverSong.id, upvote ? VoteType.Upvote : VoteType.Downvote));
                        PluginConfig.SaveConfig();
                    }
                    else if (PluginConfig.votedSongs[_lastLevel.levelID.Substring(0, 32)].voteType != (upvote ? VoteType.Upvote : VoteType.Downvote))
                    {
                        PluginConfig.votedSongs[_lastLevel.levelID.Substring(0, 32)] = new SongVote(_lastBeatSaverSong.id, upvote ? VoteType.Upvote : VoteType.Downvote);
                        PluginConfig.SaveConfig();
                    }
                }; break;

                case 500:
                {
                    _upvoteButton.interactable   = false;
                    _downvoteButton.interactable = false;
                    _ratingText.text             = "Steam API\nerror";
                    Logger.Error("Error: " + voteWWW.downloadHandler.text);
                }; break;

                case 401:
                {
                    _upvoteButton.interactable   = false;
                    _downvoteButton.interactable = false;
                    _ratingText.text             = "Invalid\nauth ticket";
                    Logger.Error("Error: " + voteWWW.downloadHandler.text);
                }; break;

                case 403:
                {
                    _upvoteButton.interactable   = false;
                    _downvoteButton.interactable = false;
                    _ratingText.text             = "Steam ID\nmismatch";
                    Logger.Error("Error: " + voteWWW.downloadHandler.text);
                }; break;

                case 400:
                {
                    _upvoteButton.interactable   = false;
                    _downvoteButton.interactable = false;
                    _ratingText.text             = "Bad\nrequest";
                    Logger.Error("Error: " + voteWWW.downloadHandler.text);
                }; break;

                default:
                {
                    _upvoteButton.interactable   = true;
                    _downvoteButton.interactable = true;
                    _ratingText.text             = "Error\n" + voteWWW.responseCode;
                    Logger.Error("Error: " + voteWWW.downloadHandler.text);
                }; break;
                }
            }
        }
Exemplo n.º 11
0
        static bool Prefix(ref PhotonMessageInfo pmi)
        {
            //Utilities.Logger.Info("About to check if containskey. isMasterClient: " + PhotonNetwork.isMasterClient.ToString());
            bool foundplayer = false;

            if (ModMessageHelper.Instance.GetPlayerMods(pmi.sender) != "NoPlayer")
            { //checks if server has received mod list from client. request for mod list is sent in the class 'PrefixServerOnClientJoin'
                foundplayer = true;
            }
            Utilities.Logger.Info("tried finding player, returned " + foundplayer.ToString());
            //Checks mod list
            if (foundplayer) //If server received mod list from client
            {
                List <string> missingmods = new List <string>();
                string        LocalMods   = MPModChecks.GetMPModList();
                string        clientmods  = ModMessageHelper.Instance.GetPlayerMods(pmi.sender);
                Logger.Info($"Starting Serverside Mod check");
                if (clientmods != LocalMods) //if the client's modlist isn't equal to the local mod list
                {
                    Logger.Info($"Checking if client is missing required mods");
                    string[] localmodlist = LocalMods.Split('\n');
                    foreach (string mod in localmodlist) //check local multiplayer mods to see if the client has required mods
                    {
                        if (!string.IsNullOrWhiteSpace(mod) && !clientmods.Contains(mod) && mod.Contains("MPF3"))
                        {
                            missingmods.Add(mod);
                        }
                    }
                    if (missingmods.Count == 0) //if nothing was added to the missing mod list check if the client needs something the server doesn't.
                    {
                        Logger.Info($"Client isn't missing mods, checking if client has mods that require server installation");
                        string[] clientmodlist = clientmods.Split('\n');
                        foreach (string mod in clientmodlist)
                        {
                            if (!string.IsNullOrWhiteSpace(mod) && !LocalMods.Contains(mod) && (mod.Contains("MPF2") || mod.Contains("MPF3")))
                            {
                                missingmods.Add(mod);
                            }
                        }
                        if (missingmods.Count > 0) //Client has non-server mods
                        {
                            Logger.Info("Client has non-server multiplayer mods");
                            string message = $"You have been disconnected for having the following mods (try removing them):\n{MPModChecks.ConvertModlist(missingmods)}";
                            ModMessageHelper.Instance.photonView.RPC("RecieveErrorMessage", pmi.sender, new object[] { message });
                            if (SteamManager.Initialized && pmi.sender.SteamID != CSteamID.Nil)
                            {
                                SteamUser.EndAuthSession(pmi.sender.SteamID);
                            }
                            PhotonNetwork.CloseConnection(pmi.sender);
                            return(false);
                        }
                    }
                    else //client is missing server mods
                    {
                        Logger.Info("client is missing server mods");
                        string message = $"You have been disconnected for not having the following mods (try installing them):\n{MPModChecks.ConvertModlist(missingmods)}";
                        ModMessageHelper.Instance.photonView.RPC("RecieveErrorMessage", pmi.sender, new object[] { message });
                        if (SteamManager.Initialized && pmi.sender.SteamID != CSteamID.Nil)
                        {
                            SteamUser.EndAuthSession(pmi.sender.SteamID);
                        }
                        PhotonNetwork.CloseConnection(pmi.sender);
                        return(false);
                    }
                }
                Logger.Info("Modcheck passed, proceding ondwards");
            }
            else //client wasn't found in mod list
            {
                if (ModMessageHelper.ServerHasMPMods) //small vulnerability: if a client with mods disables the pong message, they can still connect with their multiplayer mods
                {
                    Utilities.Logger.Info("Didn't receive message or proper modlist. proceeding to kick PhotonPlayer");
                    string message = $"You have been disconnected for not having the mod loader installed";
                    ModMessageHelper.Instance.photonView.RPC("RecieveErrorMessage", pmi.sender, new object[] { message });
                    if (SteamManager.Initialized && pmi.sender.SteamID != CSteamID.Nil)
                    {
                        SteamUser.EndAuthSession(pmi.sender.SteamID);
                    }
                    PhotonNetwork.CloseConnection(pmi.sender);
                    return(false);
                }
                Utilities.Logger.Info("Didn't receive message or proper modlist, but the server doesn't have multiplayer explicit mods. Proceeding onwards");
            }
            return(true);
        }
    //public void playVoiceIfAvailable()
    //{
    //    uint Compressed;
    //    uint Uncompressed;
    //    ret = SteamUser.GetAvailableVoice(out Compressed, out Uncompressed, 11025);


    //    if (ret == EVoiceResult.k_EVoiceResultOK && Compressed > 0)
    //    {
    //        //Console.WriteLine("GetAvailableVoice(out Compressed, out Uncompressed, 11025) : " + ret + " -- " + Compressed + " -- " + Uncompressed);
    //        uint BytesWritten;
    //        uint UncompressedBytesWritten;
    //        ret = SteamUser.GetVoice(true, DestBuffer, 1024, out BytesWritten, true, UncompressedDestBuffer, (uint)DestBuffer.Length, out UncompressedBytesWritten, 11025);
    //        //Console.WriteLine("SteamUser.GetVoice(true, DestBuffer, 1024, out BytesWritten, true, UncompressedDestBuffer, (uint)DestBuffer.Length, out UncompressedBytesWritten, 11025) : " + ret + " -- " + BytesWritten + " -- " + UncompressedBytesWritten);

    //        if (ret == EVoiceResult.k_EVoiceResultOK && BytesWritten > 0)
    //        {

    //            uint BytesWritten2;
    //            ret = SteamUser.DecompressVoice(DestBuffer, BytesWritten, DestBuffer2, (uint)DestBuffer2.Length, out BytesWritten2, 11025);
    //            //Console.WriteLine("SteamUser.DecompressVoice(DestBuffer, BytesWritten, DestBuffer2, (uint)DestBuffer2.Length, out BytesWritten2, 11025) - " + ret + " -- " + BytesWritten2);

    //            if (ret == EVoiceResult.k_EVoiceResultOK && BytesWritten2 > 0)
    //            {

    //                //converts to doubles?
    //                //for (int i = 0; i < test.Length; ++i)
    //                //{
    //                //    test[i] = (short)(DestBuffer2[i * 2] | DestBuffer2[i * 2 + 1] << 8) / 32768.0f;
    //                //}
    //                //source.clip.SetData(test, 0);

    //                MemoryStream stream = new MemoryStream(DestBuffer2);

    //                SoundEffect sound = new SoundEffect(stream.ToArray(), 11025, AudioChannels.Mono);
    //                sound.Play();

    //                stream.Dispose();
    //                //sound.Dispose();

    //                ////AudioSource source;
    //                //if (!m_VoiceLoopback)
    //                //{
    //                //    m_VoiceLoopback = new GameObject("Voice Loopback");
    //                //    source = m_VoiceLoopback.AddComponent<AudioSource>();
    //                //    source.clip = AudioClip.Create("Testing!", 11025, 1, 11025, false, false);
    //                //}
    //                //else
    //                //{
    //                //    source = m_VoiceLoopback.GetComponent<AudioSource>();
    //                //}


    //                //source.Play();
    //            }
    //        }
    //    }
    //}



    //Client A must retrieve a session ticket by calling SteamUser()->GetAuthSessionTicket().
    //Client A must send its session ticket to client B.
    //Client B must pass client A's ticket to SteamUser()->BeginAuthSession(), which will perform a quick validity check. If the ticket is valid, BeginAuthSession() will forward the ticket to then the Steam backend to verify that the ticket has not been reused and was issued by the account owner of client A. The result of this verification will be returned in a ValidateAuthTicketResponse_t callback.
    //When the multiplayer session terminates:
    //    Client A must pass the handle initially returned from GetAuthSessionTicket() to SteamUser()->CancelAuthTicket().
    //    Client B must pass the SteamID of client A to SteamUser()->EndAuthSession().


    public void RenderOnGUI()
    {
        //GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
        //GUILayout.Label("m_HAuthTicket: " + m_HAuthTicket);
        //GUILayout.Label("m_pcbTicket: " + m_pcbTicket);
        //GUILayout.EndArea();

        //GUILayout.Label("GetHSteamUser() : " + SteamUser.GetHSteamUser());
        //GUILayout.Label("BLoggedOn() : " + SteamUser.BLoggedOn());
        //GUILayout.Label("GetSteamID() : " + SteamUser.GetSteamID());

        //GUILayout.Label("InitiateGameConnection() : " + SteamUser.InitiateGameConnection()); // N/A - Too Hard to test like this.
        //GUILayout.Label("TerminateGameConnection() : " + SteamUser.TerminateGameConnection()); // ^
        //GUILayout.Label("TrackAppUsageEvent() : " + SteamUser.TrackAppUsageEvent()); // Legacy function with no documentation

        {
            string Buffer;
            bool   ret = SteamUser.GetUserDataFolder(out Buffer, 260);
            Console.WriteLine("GetUserDataFolder(out Buffer, 260) : " + ret + " -- " + Buffer);
        }

        //if (GUILayout.Button("StartVoiceRecording()"))
        {
            SteamUser.StartVoiceRecording();
            Console.WriteLine("SteamUser.StartVoiceRecording()");
        }

        //if (GUILayout.Button("StopVoiceRecording()"))
        {
            SteamUser.StopVoiceRecording();
            Console.WriteLine("SteamUser.StopVoiceRecording()");
        }

        {
            //GUILayout.Label("GetVoiceOptimalSampleRate() : " + SteamUser.GetVoiceOptimalSampleRate());

            {
                //if (GUILayout.Button("GetAuthSessionTicket(Ticket, 1024, out pcbTicket)"))
                {
                    m_Ticket      = new byte[1024];
                    m_HAuthTicket = SteamUser.GetAuthSessionTicket(m_Ticket, 1024, out m_pcbTicket);
                    Console.WriteLine("SteamUser.GetAuthSessionTicket(Ticket, 1024, out pcbTicket) - " + m_HAuthTicket + " -- " + m_pcbTicket);
                }

                //if (GUILayout.Button("BeginAuthSession(m_Ticket, (int)m_pcbTicket, SteamUser.GetSteamID())"))
                {
                    if (m_HAuthTicket != HAuthTicket.Invalid && m_pcbTicket != 0)
                    {
                        EBeginAuthSessionResult ret = SteamUser.BeginAuthSession(m_Ticket, (int)m_pcbTicket, SteamUser.GetSteamID());
                        Console.WriteLine("SteamUser.BeginAuthSession(m_Ticket, " + (int)m_pcbTicket + ", " + SteamUser.GetSteamID() + ") - " + ret);
                    }
                    else
                    {
                        Console.WriteLine("Call GetAuthSessionTicket first!");
                    }
                }
            }

            //if (GUILayout.Button("EndAuthSession(SteamUser.GetSteamID())"))
            {
                SteamUser.EndAuthSession(SteamUser.GetSteamID());
                Console.WriteLine("SteamUser.EndAuthSession(" + SteamUser.GetSteamID() + ")");
            }

            //if (GUILayout.Button("CancelAuthTicket(m_HAuthTicket)"))
            {
                SteamUser.CancelAuthTicket(m_HAuthTicket);
                Console.WriteLine("SteamUser.CancelAuthTicket(" + m_HAuthTicket + ")");
            }

            Console.WriteLine("UserHasLicenseForApp(SteamUser.GetSteamID(), SteamUtils.GetAppID()) : " + SteamUser.UserHasLicenseForApp(SteamUser.GetSteamID(), SteamUtils.GetAppID()));
            Console.WriteLine("BIsBehindNAT() : " + SteamUser.BIsBehindNAT());

            //if (GUILayout.Button("AdvertiseGame(2, 127.0.0.1, 27015)"))
            {
                SteamUser.AdvertiseGame(CSteamID.NonSteamGS, 2130706433, 27015);
                Console.WriteLine("SteamUser.AdvertiseGame(2, 2130706433, 27015)");
            }

            //if (GUILayout.Button("RequestEncryptedAppTicket()"))
            {
                byte[]         k_unSecretData = System.BitConverter.GetBytes(0x5444);
                SteamAPICall_t handle         = SteamUser.RequestEncryptedAppTicket(k_unSecretData, sizeof(uint));
                OnEncryptedAppTicketResponseCallResult.Set(handle);
                Console.WriteLine("SteamUser.RequestEncryptedAppTicket(k_unSecretData, " + sizeof(uint) + ") - " + handle);
            }

            //if (GUILayout.Button("GetEncryptedAppTicket()"))
            {
                byte[] rgubTicket = new byte[1024];
                uint   cubTicket;
                bool   ret = SteamUser.GetEncryptedAppTicket(rgubTicket, 1024, out cubTicket);
                Console.WriteLine("SteamUser.GetEncryptedAppTicket() - " + ret + " -- " + cubTicket);
            }

            //GUILayout.Label("GetGameBadgeLevel(1, false) : " + SteamUser.GetGameBadgeLevel(1, false)); // SpaceWar does not have trading cards, so this function will only ever return 0 and produce an annoying warning.
            Console.WriteLine("GetPlayerSteamLevel() : " + SteamUser.GetPlayerSteamLevel());

            //if (GUILayout.Button("RequestStoreAuthURL(\"https://steampowered.com\")"))
            {
                SteamAPICall_t handle = SteamUser.RequestStoreAuthURL("https://steampowered.com");
                OnStoreAuthURLResponseCallResult.Set(handle);
                Console.WriteLine("SteamUser.RequestStoreAuthURL(\"https://steampowered.com\") - " + handle);
            }

#if _PS3
            //GUILayout.Label("LogOn() : " + SteamUser.LogOn());
            //GUILayout.Label("LogOnAndLinkSteamAccountToPSN : " + SteamUser.LogOnAndLinkSteamAccountToPSN());
            //GUILayout.Label("LogOnAndCreateNewSteamAccountIfNeeded : " + SteamUser.LogOnAndCreateNewSteamAccountIfNeeded());
            //GUILayout.Label("GetConsoleSteamID : " + SteamUser.GetConsoleSteamID());
#endif
        }
    }
 /// <summary>
 /// When the multiplayer session terminates: The server communicates that the session is over. Client B (the server) must pass the SteamID of client A  to SteamUser()->EndAuthSession().
 /// </summary>
 public void EndAuthSession(CSteamID CSteamID)
 {
     SteamUser.EndAuthSession(CSteamID);
 }
Exemplo n.º 14
0
    public void RenderOnGUI()
    {
        GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
        GUILayout.Label("m_HAuthTicket: " + m_HAuthTicket);
        GUILayout.Label("m_pcbTicket: " + m_pcbTicket);
        GUILayout.EndArea();

        GUILayout.Label("GetHSteamUser() : " + SteamUser.GetHSteamUser());
        GUILayout.Label("BLoggedOn() : " + SteamUser.BLoggedOn());
        GUILayout.Label("GetSteamID() : " + SteamUser.GetSteamID());

        //GUILayout.Label("InitiateGameConnection() : " + SteamUser.InitiateGameConnection()); // N/A - Too Hard to test like this.
        //GUILayout.Label("TerminateGameConnection() : " + SteamUser.TerminateGameConnection()); // ^
        //GUILayout.Label("TrackAppUsageEvent() : " + SteamUser.TrackAppUsageEvent()); // Legacy function with no documentation

        {
            string Buffer;
            bool   ret = SteamUser.GetUserDataFolder(out Buffer, 260);
            GUILayout.Label("GetUserDataFolder(out Buffer, 260) : " + ret + " -- " + Buffer);
        }

        if (GUILayout.Button("StartVoiceRecording()"))
        {
            SteamUser.StartVoiceRecording();
            print("SteamUser.StartVoiceRecording()");
        }

        if (GUILayout.Button("StopVoiceRecording()"))
        {
            SteamUser.StopVoiceRecording();
            print("SteamUser.StopVoiceRecording()");
        }

        {
            uint         Compressed;
            uint         Uncompressed;
            EVoiceResult ret = SteamUser.GetAvailableVoice(out Compressed, out Uncompressed, 11025);
            GUILayout.Label("GetAvailableVoice(out Compressed, out Uncompressed, 11025) : " + ret + " -- " + Compressed + " -- " + Uncompressed);

            if (ret == EVoiceResult.k_EVoiceResultOK && Compressed > 0)
            {
                byte[] DestBuffer             = new byte[1024];
                byte[] UncompressedDestBuffer = new byte[1024];
                uint   BytesWritten;
                uint   UncompressedBytesWritten;
                ret = SteamUser.GetVoice(true, DestBuffer, 1024, out BytesWritten, true, UncompressedDestBuffer, (uint)DestBuffer.Length, out UncompressedBytesWritten, 11025);
                //print("SteamUser.GetVoice(true, DestBuffer, 1024, out BytesWritten, true, UncompressedDestBuffer, (uint)DestBuffer.Length, out UncompressedBytesWritten, 11025) : " + ret + " -- " + BytesWritten + " -- " + UncompressedBytesWritten);

                if (ret == EVoiceResult.k_EVoiceResultOK && BytesWritten > 0)
                {
                    byte[] DestBuffer2 = new byte[11025 * 2];
                    uint   BytesWritten2;
                    ret = SteamUser.DecompressVoice(DestBuffer, BytesWritten, DestBuffer2, (uint)DestBuffer2.Length, out BytesWritten2, 11025);
                    //print("SteamUser.DecompressVoice(DestBuffer, BytesWritten, DestBuffer2, (uint)DestBuffer2.Length, out BytesWritten2, 11025) - " + ret + " -- " + BytesWritten2);

                    if (ret == EVoiceResult.k_EVoiceResultOK && BytesWritten2 > 0)
                    {
                        AudioSource source;
                        if (!m_VoiceLoopback)
                        {
                            m_VoiceLoopback = new GameObject("Voice Loopback");
                            source          = m_VoiceLoopback.AddComponent <AudioSource>();
                            source.clip     = AudioClip.Create("Testing!", 11025, 1, 11025, false, false);
                        }
                        else
                        {
                            source = m_VoiceLoopback.GetComponent <AudioSource>();
                        }

                        float[] test = new float[11025];
                        for (int i = 0; i < test.Length; ++i)
                        {
                            test[i] = (short)(DestBuffer2[i * 2] | DestBuffer2[i * 2 + 1] << 8) / 32768.0f;
                        }
                        source.clip.SetData(test, 0);
                        source.Play();
                    }
                }
            }
        }

        GUILayout.Label("GetVoiceOptimalSampleRate() : " + SteamUser.GetVoiceOptimalSampleRate());

        {
            if (GUILayout.Button("GetAuthSessionTicket(Ticket, 1024, out pcbTicket)"))
            {
                m_Ticket      = new byte[1024];
                m_HAuthTicket = SteamUser.GetAuthSessionTicket(m_Ticket, 1024, out m_pcbTicket);
                print("SteamUser.GetAuthSessionTicket(Ticket, 1024, out pcbTicket) - " + m_HAuthTicket + " -- " + m_pcbTicket);
            }

            if (GUILayout.Button("BeginAuthSession(m_Ticket, (int)m_pcbTicket, SteamUser.GetSteamID())"))
            {
                if (m_HAuthTicket != HAuthTicket.Invalid && m_pcbTicket != 0)
                {
                    EBeginAuthSessionResult ret = SteamUser.BeginAuthSession(m_Ticket, (int)m_pcbTicket, SteamUser.GetSteamID());
                    print("SteamUser.BeginAuthSession(m_Ticket, " + (int)m_pcbTicket + ", " + SteamUser.GetSteamID() + ") - " + ret);
                }
                else
                {
                    print("Call GetAuthSessionTicket first!");
                }
            }
        }

        if (GUILayout.Button("EndAuthSession(SteamUser.GetSteamID())"))
        {
            SteamUser.EndAuthSession(SteamUser.GetSteamID());
            print("SteamUser.EndAuthSession(" + SteamUser.GetSteamID() + ")");
        }

        if (GUILayout.Button("CancelAuthTicket(m_HAuthTicket)"))
        {
            SteamUser.CancelAuthTicket(m_HAuthTicket);
            print("SteamUser.CancelAuthTicket(" + m_HAuthTicket + ")");
        }

        GUILayout.Label("UserHasLicenseForApp(SteamUser.GetSteamID(), SteamUtils.GetAppID()) : " + SteamUser.UserHasLicenseForApp(SteamUser.GetSteamID(), SteamUtils.GetAppID()));
        GUILayout.Label("BIsBehindNAT() : " + SteamUser.BIsBehindNAT());

        if (GUILayout.Button("AdvertiseGame(2, 127.0.0.1, 27015)"))
        {
            SteamUser.AdvertiseGame(CSteamID.NonSteamGS, 2130706433, 27015);
            print("SteamUser.AdvertiseGame(2, 2130706433, 27015)");
        }

        if (GUILayout.Button("RequestEncryptedAppTicket()"))
        {
            byte[]         k_unSecretData = System.BitConverter.GetBytes(0x5444);
            SteamAPICall_t handle         = SteamUser.RequestEncryptedAppTicket(k_unSecretData, sizeof(uint));
            OnEncryptedAppTicketResponseCallResult.Set(handle);
            print("SteamUser.RequestEncryptedAppTicket(k_unSecretData, " + sizeof(uint) + ") - " + handle);
        }

        if (GUILayout.Button("GetEncryptedAppTicket()"))
        {
            byte[] rgubTicket = new byte[1024];
            uint   cubTicket;
            bool   ret = SteamUser.GetEncryptedAppTicket(rgubTicket, 1024, out cubTicket);
            print("SteamUser.GetEncryptedAppTicket() - " + ret + " -- " + cubTicket);
        }

        //GUILayout.Label("GetGameBadgeLevel(1, false) : " + SteamUser.GetGameBadgeLevel(1, false)); // SpaceWar does not have trading cards, so this function will only ever return 0 and produce an annoying warning.
        GUILayout.Label("GetPlayerSteamLevel() : " + SteamUser.GetPlayerSteamLevel());

        if (GUILayout.Button("RequestStoreAuthURL(\"https://steampowered.com\")"))
        {
            SteamAPICall_t handle = SteamUser.RequestStoreAuthURL("https://steampowered.com");
            OnStoreAuthURLResponseCallResult.Set(handle);
            print("SteamUser.RequestStoreAuthURL(\"https://steampowered.com\") - " + handle);
        }

#if _PS3
        //GUILayout.Label("LogOn() : " + SteamUser.LogOn());
        //GUILayout.Label("LogOnAndLinkSteamAccountToPSN : " + SteamUser.LogOnAndLinkSteamAccountToPSN());
        //GUILayout.Label("LogOnAndCreateNewSteamAccountIfNeeded : " + SteamUser.LogOnAndCreateNewSteamAccountIfNeeded());
        //GUILayout.Label("GetConsoleSteamID : " + SteamUser.GetConsoleSteamID());
#endif
    }
Exemplo n.º 15
0
 /// <summary>
 /// <para>Ends an auth session that was started with BeginAuthSession. This should be called when no longer playing with the specified entity.</para>
 /// <a href="https://partner.steamgames.com/doc/api/ISteamUser#EndAuthSession">https://partner.steamgames.com/doc/api/ISteamUser#EndAuthSession</a>
 /// </summary>
 /// <param name="user"></param>
 public static void ClientEndAuthSession(CSteamID user)
 {
     SteamUser.EndAuthSession(user);
 }