public static string UploadFile(TcpClient clientSocket, string data) { int productid; string Token; string productfile = null; string ServerResponse = null; if (Request.Contains("Token", data)) { Token = Request.Get("Token", data); Tokens.Token token = new Tokens.Token(((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString(), Tokens.Tokens.GetTokenByToken(Token).ID, Tokens.Tokens.GetTokenByToken(Token).Username, Token); if (Tokens.Tokens.CheckToken(token)) { if (Request.Contains("ProductID", data)) { productid = Convert.ToInt32(Request.Get("ProductID", data)); if (HandleProducts.HasProduct(productid, token)) { foreach (Product product in Caches.Products) { if (product.id == productid) { productfile = product.file; break; } } if (productfile != null) { if (FileTransfer.UploadFile(clientSocket.GetStream(), productfile)) { ServerResponse = "File Upload Complete"; } else { ServerResponse = "File Upload failed"; } } else { ServerResponse = "ProductID returned an invalid file"; } } else { ServerResponse = "You do not own the Product that was specified"; } } else { ServerResponse = "ProductID was missing from the request"; } } else { ServerResponse = "Authentication Token was not found"; } } return(ServerResponse); }
public static string ParseCommand(TcpClient clientSocket, string data) { string Function; string ServerResponse; //Request Variable if (Request.Contains("Request", data)) { Function = Request.Get("Request", data); Console.WriteLine(Function); #region User API Requests if (Function == "Version") { //If cache is older than 5 minutes, update it if (Server.CacheTime.AddMinutes(30) > DateTime.Now) { ServerResponse = Server.Version; } else { Server.Version = new StreamReader("Version.txt").ReadLine(); ServerResponse = Server.Version; } } else if (Function == "Update") { ServerResponse = HandleFiles.UploadUpdate(clientSocket); } else if (Function == "Login") { ServerResponse = HandleLogin.Login(clientSocket, data); } else if (Function == "Register") { ServerResponse = "Register on the Forum"; //HandleRegister.Register(clientSocket, data); } else if (Function == "Activate") { ServerResponse = "Activations Disabled"; //HandleActivation.Activate(clientSocket, data); } else if (Function == "Products") { ServerResponse = HandleProducts.UserProducts(clientSocket, data); } else if (Function == "Newsfeed") { ServerResponse = HandleNews.ProductNews(clientSocket, data); } else if (Function == "Download") { ServerResponse = HandleFiles.UploadFile(clientSocket, data); } else if (Function == "AccountDetails") { ServerResponse = HandleAccount.AccountDetails(clientSocket, data); } else if (Function == "CheckProduct") { ServerResponse = HandleCheat.Products(clientSocket, data); } else if (Function == "APICheck") { ServerResponse = HandleCheat.Verified(clientSocket, data); } else if (Function == "LoginCount") { ServerResponse = HandleAccountCount.LoginCount(clientSocket, data); } else if (Function == "OnlineCount") { ServerResponse = HandleAccountCount.OnlineCount(clientSocket, data); } #endregion #region Administrator Commands else if (Function == "AdminGetAccountDetails") { ServerResponse = "Deprecated"; //HandleAccount.AdminGetAccountDetails(clientSocket, data); } else if (Function == "GenerateKey") { ServerResponse = "Deprecated"; //HandleGenerating.GenerateKey(clientSocket, data); } else if (Function == "Ban") { ServerResponse = "Deprecated"; //HandleBan.Ban(clientSocket, data); } else if (Function == "FindUser") { ServerResponse = "Deprecated"; //HandleAccount.FindUsernameFromDiscordId(clientSocket, data); } else if (Function == "ResetHWID") { ServerResponse = "Dreprecated"; //HandleAccount.ResetHWID(clientSocket, data); } else if (Function == "ResetPassword") { ServerResponse = "Deprecated"; //HandleAccount.ResetPassword(clientSocket, data); } else { ServerResponse = "Request Undefined"; } #endregion } else { ServerResponse = "Invalid API Request"; } Console.WriteLine("Server Response: " + ServerResponse + " Data: " + data + " IP -> " + ((IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString()); return(ServerResponse); }