Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Xml.Serialization;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.Collections.Specialized;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- public class MyWebClient : WebClient{
- protected override WebRequest GetWebRequest(System.Uri adress){
- HttpWebRequest req = base.GetWebRequest(adress) as HttpWebRequest;
- //req.AutomaticDecompression = DecompressionMethods.GZip;
- req.Proxy = null;
- req.Timeout = 10000;
- req.KeepAlive = true;
- req.ReadWriteTimeout = 10000;
- req.CookieContainer = new CookieContainer();
- return req;
- }
- }
- public static class Encrypting<T>{
- public static string EncryptObject(T o){
- try{
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream s = new MemoryStream();
- bf.Serialize(s, (object)o);
- string r = System.Convert.ToBase64String(s.GetBuffer());
- s.Dispose();
- return r;
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z zapisem danych...: " + ex.Message);
- } }
- return "";
- }
- }
- public static T DecryptObject(string str){
- try{
- str = str.Replace(" ","+");
- int mod4 = str.Length % 4;
- if ( mod4 > 0 )
- {
- str += new string( '=', 4 - mod4 );
- }
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream s = new MemoryStream(System.Convert.FromBase64String (str));
- object o = bf.Deserialize(s);
- s.Dispose();
- return (T)o;
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z odczytem...: " + ex.Message);
- } }
- Debug.Log (ex.Message);
- return default(T);
- }
- }
- public static string EncryptObjectXml(T o){
- XmlSerializer xml = new XmlSerializer(typeof(T));
- MemoryStream s = new MemoryStream();
- xml.Serialize(s, (object)o);
- string r = System.Text.Encoding.UTF8.GetString (s.GetBuffer());
- s.Dispose();
- return r;
- }
- public static string EncryptObjectXml64(T o){
- XmlSerializer xml = new XmlSerializer(typeof(T));
- MemoryStream s = new MemoryStream();
- xml.Serialize(s, (object)o);
- string r = System.Convert.ToBase64String(s.GetBuffer());
- s.Dispose();
- return r;
- }
- public static T DecryptObjectXml(string o){
- XmlSerializer xml = new XmlSerializer(typeof(T));
- MemoryStream s = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(o));
- object r = xml.Deserialize(s);
- s.Dispose();
- return (T)r;
- }
- public static T DecryptObjectXml64(string o){
- XmlSerializer xml = new XmlSerializer(typeof(T));
- MemoryStream s = new MemoryStream(System.Convert.FromBase64String(o));
- object r = xml.Deserialize(s);
- s.Dispose();
- return (T)r;
- }
- }
- public static class Internet{
- static string ftpurl = "ftp://interet.hekko24.pl/"; // e.g. ftp://serverip/foldername/foldername
- static string ftpusername = "user@interet.hekko24.pl"; // e.g. username
- static string ftppassword = "123321"; // e.g. password
- public static MonoBehaviour mono;
- public static string MainURL2 = "http://interet.hekko24.pl/PHP/";
- public static string AllUsers = "GetAllUsersNicks.php";
- public static string MatchDataUpload = "SetGameFromGAMEID.php";
- public static string MatchDataDownload = "GetGameFromGAMEID.php";
- public static string MatchCreate = "CreateNewGame.php";
- public static string SetValue = "SetValue.php";
- public static string GetValue = "GetValue.php";
- public static string QURL = "mail.php";
- public static string GetAllUsers = "DownloadUsers.php";
- public static string GetAllUsersNicknames = "DownloadUsersNicks.php";
- public static string ChatRoomCreate = "CreateChatroom.php";
- private static void UploadFileToFTP(string source)
- {
- try
- {
- string filename = Path.GetFileName(source);
- string ftpfullpath = ftpurl;
- FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath + "/" + UIInstanceHelper.Instance.GetUsername() + ".png");
- Debug.Log ("Created req");
- ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
- ftp.KeepAlive = true;
- ftp.UseBinary = true;
- ftp.Method = WebRequestMethods.Ftp.UploadFile;
- Debug.Log ("Created full");
- FileStream fs = File.OpenRead(source);
- byte[] buffer = new byte[fs.Length];
- fs.Read(buffer, 0, buffer.Length);
- fs.Close();
- Debug.Log ("Read fle");
- Stream ftpstream = ftp.GetRequestStream();
- ftpstream.Write(buffer, 0, buffer.Length);
- ftpstream.Close();
- Debug.Log ("Upload fle");
- SetAvatar (UIInstanceHelper.Instance.GetUsername(), ftpfullpath + "/" + UIInstanceHelper.Instance.GetUsername() + ".png");
- }
- catch (System.Exception ex)
- {
- Debug.Log (ex.Message);
- }
- }
- public static bool SetAvatar(string email, string AvatarLink){
- if(AvatarLink.ToLower().Contains ("http") || AvatarLink.ToLower().Contains ("ftp")){
- Internet.Upload.SetValueString("LoginData", "EMail", email, "Avatar", AvatarLink);
- return true;
- }
- else{
- return false;
- }
- }
- public static bool SetAvatarFromFile(string email, string FileLink){
- UploadFileToFTP (FileLink);
- return true;
- }
- public static byte[] GetAvatar(string email){
- //Debug.Log (email);
- string AvatarLink = Internet.Download.GetValueString ("LoginData", "EMail", email, "Avatar");
- if(AvatarLink == ""){
- return null;
- }
- //Texture2D r = new Texture2D(1,1);
- if(AvatarLink.Contains ("http")){
- byte[] a = Internet.AskWebsiteForBytedata(AvatarLink);
- return a;
- }
- else if(AvatarLink.Contains("img::")){
- string al = AvatarLink.Replace ("img::", "");
- byte[] bs = Encrypting<byte[]>.DecryptObjectXml(al);
- return bs;
- }
- else if(AvatarLink.Contains ("ftp")){
- string ftpfullpath = ftpurl;
- FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(AvatarLink);
- ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
- ftp.KeepAlive = true;
- ftp.UseBinary = true;
- ftp.Method = WebRequestMethods.Ftp.DownloadFile;
- Debug.Log ("DL full");
- FtpWebResponse resp = (FtpWebResponse)ftp.GetResponse ();
- Stream s = resp.GetResponseStream();
- byte[] b = ReadFully(s);
- s.Close();
- Debug.Log ("Read fle");
- return b;
- }
- return null;
- }
- public static byte[] AskWebsiteForBytedata(string url){
- try{
- WebClient wcl = new WebClient();
- wcl.Proxy = null;
- byte[] content = wcl.DownloadData(url);
- wcl.Dispose ();
- return content;
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z internetem... " + ex.Message);
- } }
- Debug.Log (ex.Message);
- return default(byte[]);
- }
- }
- public static byte[] ReadFully(Stream input)
- {
- try{
- byte[] buffer = new byte[16*1024];
- using (MemoryStream ms = new MemoryStream())
- {
- int read;
- while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
- {
- ms.Write(buffer, 0, read);
- }
- return ms.ToArray();
- }
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Błąd odczytu danych... " + ex.Message);
- }
- }
- Debug.Log (ex.Message);
- return default(byte[]);
- }
- }
- public static string AskWebsite(string url){
- try{
- WebClient wc = new WebClient();
- wc.Proxy = null;
- var content = wc.DownloadString(url);
- wc.Dispose ();
- return content;
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z internetem... " + ex.Message);
- } }
- Debug.Log (ex.Message);
- return "";
- }
- }
- public static class Helper{
- public static string CombineURL2(string URL){
- string r = MainURL2 + URL;
- return r;
- }
- public static string EncryptGames(List<string> sync){
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream s = new MemoryStream();
- bf.Serialize(s, sync);
- string r = System.Convert.ToBase64String(s.GetBuffer());
- s.Dispose();
- return r;
- }
- public static List<string> DecryptGames(string games){
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream s = new MemoryStream(System.Convert.FromBase64String (games));
- object o = bf.Deserialize(s);
- s.Dispose();
- return (List<string>)o;
- }
- public static string EncryptObject(object o){
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream s = new MemoryStream();
- bf.Serialize(s, o);
- string r = System.Convert.ToBase64String(s.GetBuffer());
- s.Dispose();
- return r;
- }
- public static object DecryptObject(string str){
- BinaryFormatter bf = new BinaryFormatter();
- MemoryStream s = new MemoryStream(System.Convert.FromBase64String (str));
- object o = bf.Deserialize(s);
- s.Dispose();
- return o;
- }
- }
- ///Classes designed to upload data
- public static class Upload{
- public static void CreateChatRoom(string name, List<ChatMsg> messages, bool NEX = true){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- string msgsE = Encrypting<List<ChatMsg>>.EncryptObject(messages);
- var data = new NameValueCollection();
- data["Name"] = name;
- data["DefaultMsgs"] = msgsE;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(ChatRoomCreate) , "POST", data));
- wb.Dispose ();
- if(content != "Done"){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
- }
- }
- Debug.Log (content);
- }
- }
- catch(System.Exception ex){
- if(NEX){
- CreateChatRoom(name, messages, false);
- }
- else{
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
- }
- }
- }
- }
- }
- public static void SendQuestion(string msg, string sender, bool NEX = true){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["MSG"] = msg;
- data["SENDER"] = sender;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(QURL), "POST", data));
- wb.Dispose ();
- if(content != "Done"){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
- }
- }
- Debug.Log (content);
- }
- }
- catch(System.Exception ex){
- if(NEX){
- SendQuestion(msg, sender, false);
- }
- else{
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
- }
- }
- }
- }
- }
- public static string SetValueString(string TABLE, string IDFIELD, string ID, string VALUEFIELD, string VALUE, bool NEX = true){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["TABLE"] = TABLE;
- data["IDFIELD"] = IDFIELD;
- data["ID"] = ID;
- data["VALUEFIELD"] = VALUEFIELD;
- data["VALUE"] = VALUE;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(SetValue), "POST", data));
- wb.Dispose ();
- if(content != "Done"){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
- }
- }
- Debug.Log ("SET " + VALUEFIELD + " IN " + TABLE + " TO " + VALUE + " WHERE " + IDFIELD + " IS " + ID);
- Debug.Log (content);
- }
- return content;
- }
- catch(System.Exception ex){
- if(NEX){
- return SetValueString (TABLE, IDFIELD, ID, VALUEFIELD, VALUE, false);
- }
- else{
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
- }
- }
- return "ERROR";
- }
- }
- }
- public static string SetValueInt(string TABLE, string IDFIELD, string ID, string VALUEFIELD, int VALUE, bool NEX = true){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- //string url = Helper.CombineURL2(SetValue) + "?TABLE=" + TABLE + "&IDFIELD=" + IDFIELD + "&ID=" + ID + "&VALUEFIELD=" + VALUEFIELD + "&VALUE=" + VALUE;
- //string content = AskWebsite(url);
- var data = new NameValueCollection();
- data["TABLE"] = TABLE;
- data["IDFIELD"] = IDFIELD;
- data["ID"] = ID;
- data["VALUEFIELD"] = VALUEFIELD;
- data["VALUE"] = VALUE.ToString();
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(SetValue), "POST", data));
- wb.Dispose ();
- if(content != "Done"){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
- }
- }
- Debug.Log ("SET " + VALUEFIELD + " IN " + TABLE + " TO " + VALUE + " WHERE " + IDFIELD + " IS " + ID);
- Debug.Log (content);
- }
- return content;
- }
- catch(System.Exception ex){
- if(NEX){
- return SetValueInt (TABLE, IDFIELD, ID, VALUEFIELD, VALUE, false);
- }
- else{
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
- }
- }
- return "ERROR";
- }
- }
- }
- public static string CreateMatch(string ID, string Data, bool NEX = true){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["ID"] = ID;
- data["Value"] = Data;
- data["Value2"] = Encrypting<List<string>>.EncryptObject(new List<string>());
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(MatchCreate), "POST", data));
- wb.Dispose ();
- return content;
- }
- catch(System.Exception ex){
- if(NEX){
- return CreateMatch(ID, Data, false);
- }
- else{
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
- }
- }
- return "ERROR";
- }
- }
- }
- }
- ///Classes designed to download data
- public static class Download{
- public static string[] GetAllUsersN(){
- string url = Helper.CombineURL2(AllUsers);
- string content = AskWebsite(url);
- return content.Split(new string[]{"!"}, System.StringSplitOptions.RemoveEmptyEntries);
- }
- public static string[] GetLoggedUsers(){
- string url = Helper.CombineURL2(GetAllUsers);
- string content = AskWebsite(url);
- return content.Split('!');
- }
- public static string[] GetLoggedUsersNicknames(){
- string url = Helper.CombineURL2(GetAllUsersNicknames);
- string content = AskWebsite(url);
- return (content.Split('!'));
- }
- public static string GetValueStringNonMissing(string TABLE, string IDFIELD, string ID, string VALUEFIELD){
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["TABLE"] = TABLE;
- data["IDFIELD"] = IDFIELD;
- data["ID"] = ID;
- data["VALUEFIELD"] = VALUEFIELD;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(GetValue), "POST", data));
- wb.Dispose ();
- return content;
- }
- public static string GetValueString(string TABLE, string IDFIELD, string ID, string VALUEFIELD){
- var wb = new MyWebClient ();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["TABLE"] = TABLE;
- data["IDFIELD"] = IDFIELD;
- data["ID"] = ID;
- data["VALUEFIELD"] = VALUEFIELD;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(GetValue), "POST", data));
- if(content == "Missing" || content == "404" || content == null || (content == "" && VALUEFIELD != "Avatar")){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
- }
- }
- Debug.Log ("GET " + VALUEFIELD + " FROM " + TABLE + " WHERE " + IDFIELD + " IS " + ID);
- Debug.Log (content);
- }
- wb.Dispose ();
- return content;
- }
- public static int GetValueInt(string TABLE, string IDFIELD, string ID, string VALUEFIELD){
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["TABLE"] = TABLE;
- data["IDFIELD"] = IDFIELD;
- data["ID"] = ID;
- data["VALUEFIELD"] = VALUEFIELD;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(GetValue), "POST", data));
- if(content == "Missing" || content == "404" || content == null || (content == "" && VALUEFIELD != "Avatar")){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
- }
- }
- Debug.Log ("GET " + VALUEFIELD + " FROM " + TABLE + " WHERE " + IDFIELD + " IS " + ID);
- Debug.Log (content);
- }
- wb.Dispose ();
- return (System.Convert.ToInt32 (content));
- }
- public static string DownloadMatch(string ID){
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["ID"] = ID;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(MatchDataDownload), "POST", data));
- wb.Dispose ();
- return content;
- }
- }
- public static class InternalDataExchange{
- public static string LoginURL = "LoginUser.php";
- public static string LogoutURL = "LogoutUser.php";
- public static string RegisterURL = "RegisterUser.php";
- public static string RecoverPassURL = "GeneratePassHashcode.php";
- public static string RecoverFromCODEURL = "GetPasswordFromCode.php";
- public static string ChangePassURL = "ChangePassword.php";
- public static string Login(string Email, string Password){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["Email"] = Email;
- data["Password"] = Password;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(LoginURL), "POST", data));
- wb.Dispose ();
- switch(content){
- case "EmptyMail":
- return ("Email jest pusty");
- case "EmptyPassword":
- return ("Hasło jest puste");
- case "NoAccount":
- return("Brak konta dla tego adresu");
- case "WrongPassword":
- return("Błędne hasło");
- case "Done":
- return("Zalogowano");
- default:
- Debug.LogError(content);
- return "Błąd internetu\n" +content;
- }
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
- }
- return ex.Message;
- }
- }
- public static string ChangePassword(string Email, string Password, string NewPassword){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["Email"] = Email;
- data["Password"] = Password;
- data["NewPassword"] = NewPassword;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(ChangePassURL), "POST", data));
- wb.Dispose ();
- switch(content){
- case "EmptyMail":
- return("Email jest pusty");
- case "EmptyPass":
- return("Hasło jest puste");
- case "NoAccount":
- return("Brak konta dla tego adresu");
- case "WrongPassword":
- return("Błędne hasło");
- case "Done":
- return("Hasło zmienione");
- default:
- Debug.Log (content);
- return(content);
- }
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
- }
- return ex.Message;
- }
- }
- public static string GenerateRecoverCode(string Email){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["Email"] = Email;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(RecoverPassURL), "POST", data));
- wb.Dispose ();
- switch(content){
- case "EmptyMail":
- return("Email jest pusty");
- case "NoAccount":
- return("Brak konta dla tego adresu");
- case "Failed":
- return("Nieznany błąd");
- case "Done":
- return("Wygenerowano kod i wysłano E-mailem");
- default:
- Debug.Log (content);
- return(content);
- }
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
- }
- return ex.Message;
- }
- }
- public static string Logout(string Email){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["Email"] = Email;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(LogoutURL), "POST", data));
- wb.Dispose ();
- switch(content){
- case "EmptyMail":
- return("Email jest pusty");
- case "NoAccount":
- return("Brak konta dla tego adresu");
- case "Done":
- return("Wylogowano");
- default:
- Debug.Log (content);
- return(content);
- }
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
- }
- return ex.Message;
- }
- }
- public static string RecoverPassword(string Email, string Hash, string Password){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["Email"] = Email;
- data["HashCode"] = Hash;
- data["Password"] = Password;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(RecoverFromCODEURL), "POST", data));
- wb.Dispose ();
- switch(content){
- case "EmptyMail":
- return("Email jest pusty");
- case "NoAccount":
- return("Brak konta dla tego adresu");
- case "Failed":
- return("Nieznany błąd");
- case "Done":
- return("Hasło zmienione");
- case "WrongHashcode":
- return("Błędny kod odzyskiwania");
- default:
- Debug.Log (content);
- return(content);
- }
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
- }
- return ex.Message;
- }
- }
- public static string RegisterAccount(string Username, string Email, string Password){
- try{
- WebClient wb = new WebClient();
- wb.Proxy = null;
- var data = new NameValueCollection();
- data["Email"] = Email;
- data["Username"] = Username;
- data["Password"] = Password;
- var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(RegisterURL), "POST", data));
- wb.Dispose ();
- switch(content){
- case "EmptyMail":
- return("Email jest pusty");
- case "EmptyPassword":
- return("Hasło jest puste");
- case "EmptyUsername":
- return("Nazwa użytkownika jest pusta");
- case "UsernameInUse":
- return("Nazwa użytkownika jest w użyciu");
- case "Done":
- return("Zarejestrowano");
- case "Exists":
- return("Email jest w użyciu");
- default:
- Debug.Log (content);
- return(content);
- }
- }
- catch(System.Exception ex){
- if(!System.Threading.Thread.CurrentThread.IsBackground){
- UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
- }
- return ex.Message;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment