1

SteamBot コードに問題があります。そのため、誰かが「Bot」を友達として追加すると、誰が追加したかがログに表示されます。その後、さらにコードを追加しましたが、その部分は機能しません。誰かが追加したことを記録するだけで、すぐに true を返すようです。質問は、なぜコードの他の部分を実行しないのですか?

public override bool OnFriendAdd()
        {
            Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " (" + OtherSID.ToString() + ") added me!");
            HttpWebRequest check =
            check.Method = "GET";
            HttpWebResponse checkResp;
            try
            {
                checkResp = check.GetResponse() as HttpWebResponse;
                StreamReader createRead = new StreamReader(checkResp.GetResponseStream());
                string resultCA = createRead.ReadToEnd();
                if (resultCA.Contains("success"))
                {
                    Regex SomeNameHere3 = new Regex("\"\" : \"([A-Za-z0-9]+)");
                    string swag3 = SomeNameHere3.Match(resultCA).Value;
                    swag3 = swag3.Replace("\"\" : \"", "");
                    currentSID = currentSID.ConvertToUInt64();
                    Log.Success("User: " + Bot.SteamFriends.GetFriendPersonaName(currentSID) + "  : " + swag3);
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                    Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                }
            }
            catch (WebException ex)
            {
                checkResp = ex.Response as HttpWebResponse;
                StreamReader createRead = new StreamReader(checkResp.GetResponseStream());
                string resultCA = createRead.ReadToEnd();
                if (resultCA.Contains("fail") && resultCA.Contains("Label does not exist"))
                {
                    HttpWebRequest create =
                    create.Method = "GET";
                    HttpWebResponse createResp = (HttpWebResponse)create.GetResponse();
                    StreamReader createSR = new StreamReader(createResp.GetResponseStream());
                    string createSRRTE = createSR.ReadToEnd();
                    if (createSRRTE.Contains("success"))
                    {
                        Regex SomeNameHere3 = new Regex("\"\" : \"([A-Za-z0-9]+)");
                        string get = SomeNameHere3.Match(createSRRTE).Value;
                        get = get.Replace("\"\" : \"", "");
                        Log.Success("User: " + Bot.SteamFriends.GetFriendPersonaName(currentSID) + "  : " + get);
                        Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                        Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                        Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                        Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                        Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                        Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                        Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                        Bot.SteamFriends.SendChatMessage(currentSID, type, ");
                       Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                       Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                       Bot.SteamFriends.SendChatMessage(currentSID, type, "");
                   }
               }
           }
           return true;
       }
4

2 に答える 2

1

が読み取りまたは書き込みを行うためにはStream、読み取りまたは書き込みを行っている管理されていないデータが終了したこと、または読み取りまたは書き込みを続ける必要がないことを通知する必要があります。

ストリームを閉じる/破棄する必要がある理由を読んでください。

ストリームを閉じるだけでなく、破棄する必要もあります。Stream を破棄すると自動的に閉じられるため、破棄だけで十分です。

var stream = new FileStream();
// stuff;
stream.Dispose();

他の回答が示唆するように、オブジェクト ( a など)using() {}でブロックを使用することも選択できます。これにより、ブロックの最後で「使用中」のオブジェクトが確実に破棄されます。IDisposableStreamusing

using(var stream = new FileStream()){
    //stuff;
}
于 2016-03-16T13:22:40.327 に答える
0

usingステートメントを使用することをお勧めします。それはあなたのために処分を処理します

using (StreamReader createRead = new StreamReader(createResp.GetResponseStream()))
{
   ///
}
于 2016-03-16T11:37:23.237 に答える