我是C#的新手,并使用连接到网站和交易项目的开源代码。
我之前的问题非常愚蠢,我很抱歉!
我找到了代码停止的位置,并需要有关如何修复错误的建议。 - http://i.imgur.com/qqeMOUn.png
我还标记了我认为错误的位置//代码在此行停止!
namespace BOT
{
internal static class Program
{
private const string serverName = "http://MYVPSIP/ezyskins.php";
private const string serverDemon = "ws://MYVPSIP:5555";
public static List<IWebSocketConnection> allsockets = new List<IWebSocketConnection>();
public static WebSocketServer server = new WebSocketServer(serverDemon);
public static WebClient wc = new WebClient();
public static GameJson GJ = new GameJson();
public static List<DepositItem> DI = new List<DepositItem>();
public static List<DepositUser> DU = new List<DepositUser>();
public static Thread ResolveSocketsThread;
public static Thread GameThread;
public static Thread TradeBotThread;
public static Thread SendBotThread;
public static Thread SteamAuth;
public static Thread ClearInfo;
public static int globalGameID = 0;
public static string winnersecretkey;
public static List<string> FoundPrices = new List<string>();
public static List<string> resTrades = new List<string>();
public static List<string> waitTrades = new List<string>();
public static List<string> BannedSteamID = new List<string>();
public static object steamRequest = new object();
public static object lockSocket = new object();
public static string username = ""; //Bot Login
public static string password = ""; //Bot Pass
public static string steamID = ""; //Steam64 ID
public static string sessionID = ""; //Cookies
public static string steamLogin = ""; //Cookies
public static string steamLoginSecure = ""; //Cookies
public static string machineAuth = ""; //Cookies
public static string steamApiKey = ""; //Bots Api
public static string webServerSecretKey = ""; Secret Key
public static int gameID = 0;
public static double gameKey = 0.0;
public static int totalItems = 0;
public static double totalPrice = 0.0;
public static double totalPrice2 = 0.0;
public static long closeAt = 0L;
public static long openAt = 0L;
public static double last_ticket = 0.0;
public static string hash = string.Empty;
public static DepositUser winner;
public static string totalwinner;
public static bool deposits = false;
public static bool timerStarted = false;
public static bool gameStarted = false;
public static NumberFormatInfo nfi = NumberFormatInfo.CurrentInfo;
[STAThread]
private static void Main()
{
try
{
string source = string.Empty;
using (HttpRequest httpRequest = new HttpRequest())
{
RequestParams requestParams = new RequestParams();
httpRequest.Cookies = new CookieDictionary(false) {
{
"key", webServerSecretKey
}
};
requestParams["method"] = "getinfo";
source = httpRequest.Post(serverName, requestParams, false).ToString();
}
string[] array = Program.explode("(|)", source);
Program.globalGameID = int.Parse(array[0]); //Code stops on this line!
Program.winnersecretkey = array[1];
Program.server.SupportedSubProtocols = new string[] {
"ezyskins"
};
Program.ResolveSocketsThread = new Thread(new ThreadStart(Program.ResolveSockets));
Program.GameThread = new Thread(new ThreadStart(Program.Game));
Program.TradeBotThread = new Thread(new ThreadStart(Program.TradeBot));
Program.SendBotThread = new Thread(new ThreadStart(Program.SendBotT));
Program.SteamAuth = new Thread(new ThreadStart(Program.SteamAuthT));
Program.ClearInfo = new Thread(new ThreadStart(Program.ClearInfoT));
Program.GameThread.IsBackground = true;
Program.TradeBotThread.IsBackground = true;
Program.ResolveSocketsThread.IsBackground = true;
Program.SendBotThread.IsBackground = true;
Program.SteamAuth.IsBackground = true;
Program.ClearInfo.IsBackground = true;
Program.ResolveSocketsThread.Start();
Program.GameThread.Start();
Program.TradeBotThread.Start();
Program.SendBotThread.Start();
Program.SteamAuth.Start();
Program.ClearInfo.Start();
while (true)
{
string a = Console.ReadLine();
if (a == "clear")
{
Console.Clear();
}
if (a == "save-online")
{
Console.WriteLine("Sockets: " + Program.allsockets.Count<IWebSocketConnection>());
foreach (IWebSocketConnection current in Program.allsockets)
{
string text = "";
if (File.Exists("online.txt"))
{
text = File.ReadAllText("online.txt");
}
foreach (KeyValuePair<string, string> current2 in current.ConnectionInfo.Headers)
{
File.WriteAllText("online.txt", string.Concat(new object[] {
text, "\r\n", current.ConnectionInfo.ClientIpAddress, ":", current.ConnectionInfo.ClientPort, " (", current2.Key, ": ", current2.Value, ")"
}));
}
}
}
if (a == "restart")
{
Program.ResolveSocketsThread.Abort();
Program.ResolveSocketsThread.Start();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message); // ----> This gets printed out! <----
Console.Read();
}
}
答案 0 :(得分:2)
您应该调查数组内部的内容。如果value无法解析为number,则抛出异常。
如果您正在使用visual studio,请将数组打印到调试控制台或将断点设置为解析行并将数组添加到监视器中。
答案 1 :(得分:1)
您没有向int.Parse
提供有效的整数值,因为您收到此异常。在这种情况下,您无法使用int.TryParse
因为您需要游戏ID。我建议你的是调试你的代码,看看数组的价值是什么。
如果要在控制台中查看,请添加此行。
foreach(string sArr in array)
{
Console.WriteLine(sArr);
}
之后,看看您的游戏ID位于哪个位置并将其放入int.Parse。