Guest User

tetaeaettea

a guest
May 29th, 2017
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.96 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Xml.Serialization;
  5. using System.Net;
  6. using System.Net.NetworkInformation;
  7. using System.Collections.Specialized;
  8. using System.IO;
  9. using System.Runtime.Serialization.Formatters.Binary;
  10.  
  11. public class MyWebClient : WebClient{
  12. protected override WebRequest GetWebRequest(System.Uri adress){
  13. HttpWebRequest req = base.GetWebRequest(adress) as HttpWebRequest;
  14. //req.AutomaticDecompression = DecompressionMethods.GZip;
  15. req.Proxy = null;
  16. req.Timeout = 10000;
  17. req.KeepAlive = true;
  18. req.ReadWriteTimeout = 10000;
  19. req.CookieContainer = new CookieContainer();
  20. return req;
  21. }
  22. }
  23.  
  24.  
  25.  
  26. public static class Encrypting<T>{
  27.  
  28.  
  29.  
  30.  
  31. public static string EncryptObject(T o){
  32. try{
  33. BinaryFormatter bf = new BinaryFormatter();
  34. MemoryStream s = new MemoryStream();
  35. bf.Serialize(s, (object)o);
  36. string r = System.Convert.ToBase64String(s.GetBuffer());
  37. s.Dispose();
  38. return r;
  39. }
  40. catch(System.Exception ex){
  41. if(!System.Threading.Thread.CurrentThread.IsBackground){
  42. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  43. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z zapisem danych...: " + ex.Message);
  44. } }
  45. return "";
  46.  
  47. }
  48. }
  49.  
  50. public static T DecryptObject(string str){
  51. try{
  52. str = str.Replace(" ","+");
  53. int mod4 = str.Length % 4;
  54. if ( mod4 > 0 )
  55. {
  56. str += new string( '=', 4 - mod4 );
  57. }
  58.  
  59. BinaryFormatter bf = new BinaryFormatter();
  60. MemoryStream s = new MemoryStream(System.Convert.FromBase64String (str));
  61. object o = bf.Deserialize(s);
  62. s.Dispose();
  63.  
  64.  
  65. return (T)o;
  66. }
  67. catch(System.Exception ex){
  68. if(!System.Threading.Thread.CurrentThread.IsBackground){
  69. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  70. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z odczytem...: " + ex.Message);
  71. } }
  72. Debug.Log (ex.Message);
  73. return default(T);
  74. }
  75. }
  76.  
  77. public static string EncryptObjectXml(T o){
  78. XmlSerializer xml = new XmlSerializer(typeof(T));
  79. MemoryStream s = new MemoryStream();
  80. xml.Serialize(s, (object)o);
  81. string r = System.Text.Encoding.UTF8.GetString (s.GetBuffer());
  82. s.Dispose();
  83. return r;
  84. }
  85.  
  86. public static string EncryptObjectXml64(T o){
  87. XmlSerializer xml = new XmlSerializer(typeof(T));
  88. MemoryStream s = new MemoryStream();
  89. xml.Serialize(s, (object)o);
  90. string r = System.Convert.ToBase64String(s.GetBuffer());
  91. s.Dispose();
  92. return r;
  93. }
  94.  
  95. public static T DecryptObjectXml(string o){
  96. XmlSerializer xml = new XmlSerializer(typeof(T));
  97. MemoryStream s = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(o));
  98. object r = xml.Deserialize(s);
  99. s.Dispose();
  100. return (T)r;
  101. }
  102.  
  103. public static T DecryptObjectXml64(string o){
  104. XmlSerializer xml = new XmlSerializer(typeof(T));
  105. MemoryStream s = new MemoryStream(System.Convert.FromBase64String(o));
  106. object r = xml.Deserialize(s);
  107. s.Dispose();
  108. return (T)r;
  109. }
  110.  
  111.  
  112.  
  113. }
  114.  
  115.  
  116. public static class Internet{
  117.  
  118. static string ftpurl = "ftp://interet.hekko24.pl/"; // e.g. ftp://serverip/foldername/foldername
  119. static string ftpusername = "user@interet.hekko24.pl"; // e.g. username
  120. static string ftppassword = "123321"; // e.g. password
  121.  
  122. public static MonoBehaviour mono;
  123.  
  124. public static string MainURL2 = "http://interet.hekko24.pl/PHP/";
  125.  
  126. public static string AllUsers = "GetAllUsersNicks.php";
  127. public static string MatchDataUpload = "SetGameFromGAMEID.php";
  128. public static string MatchDataDownload = "GetGameFromGAMEID.php";
  129.  
  130. public static string MatchCreate = "CreateNewGame.php";
  131.  
  132. public static string SetValue = "SetValue.php";
  133. public static string GetValue = "GetValue.php";
  134.  
  135. public static string QURL = "mail.php";
  136.  
  137. public static string GetAllUsers = "DownloadUsers.php";
  138. public static string GetAllUsersNicknames = "DownloadUsersNicks.php";
  139.  
  140. public static string ChatRoomCreate = "CreateChatroom.php";
  141.  
  142. private static void UploadFileToFTP(string source)
  143. {
  144. try
  145. {
  146. string filename = Path.GetFileName(source);
  147. string ftpfullpath = ftpurl;
  148. FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath + "/" + UIInstanceHelper.Instance.GetUsername() + ".png");
  149. Debug.Log ("Created req");
  150. ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
  151.  
  152. ftp.KeepAlive = true;
  153. ftp.UseBinary = true;
  154. ftp.Method = WebRequestMethods.Ftp.UploadFile;
  155. Debug.Log ("Created full");
  156.  
  157. FileStream fs = File.OpenRead(source);
  158. byte[] buffer = new byte[fs.Length];
  159. fs.Read(buffer, 0, buffer.Length);
  160. fs.Close();
  161. Debug.Log ("Read fle");
  162.  
  163.  
  164.  
  165. Stream ftpstream = ftp.GetRequestStream();
  166. ftpstream.Write(buffer, 0, buffer.Length);
  167. ftpstream.Close();
  168. Debug.Log ("Upload fle");
  169. SetAvatar (UIInstanceHelper.Instance.GetUsername(), ftpfullpath + "/" + UIInstanceHelper.Instance.GetUsername() + ".png");
  170.  
  171. }
  172. catch (System.Exception ex)
  173. {
  174. Debug.Log (ex.Message);
  175.  
  176. }
  177. }
  178.  
  179. public static bool SetAvatar(string email, string AvatarLink){
  180. if(AvatarLink.ToLower().Contains ("http") || AvatarLink.ToLower().Contains ("ftp")){
  181. Internet.Upload.SetValueString("LoginData", "EMail", email, "Avatar", AvatarLink);
  182. return true;
  183. }
  184. else{
  185. return false;
  186. }
  187.  
  188. }
  189.  
  190. public static bool SetAvatarFromFile(string email, string FileLink){
  191.  
  192. UploadFileToFTP (FileLink);
  193. return true;
  194. }
  195.  
  196. public static byte[] GetAvatar(string email){
  197. //Debug.Log (email);
  198.  
  199. string AvatarLink = Internet.Download.GetValueString ("LoginData", "EMail", email, "Avatar");
  200. if(AvatarLink == ""){
  201. return null;
  202. }
  203. //Texture2D r = new Texture2D(1,1);
  204. if(AvatarLink.Contains ("http")){
  205. byte[] a = Internet.AskWebsiteForBytedata(AvatarLink);
  206. return a;
  207. }
  208. else if(AvatarLink.Contains("img::")){
  209. string al = AvatarLink.Replace ("img::", "");
  210.  
  211. byte[] bs = Encrypting<byte[]>.DecryptObjectXml(al);
  212.  
  213. return bs;
  214. }
  215. else if(AvatarLink.Contains ("ftp")){
  216. string ftpfullpath = ftpurl;
  217. FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(AvatarLink);
  218. ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
  219.  
  220. ftp.KeepAlive = true;
  221. ftp.UseBinary = true;
  222. ftp.Method = WebRequestMethods.Ftp.DownloadFile;
  223. Debug.Log ("DL full");
  224.  
  225. FtpWebResponse resp = (FtpWebResponse)ftp.GetResponse ();
  226.  
  227. Stream s = resp.GetResponseStream();
  228.  
  229. byte[] b = ReadFully(s);
  230.  
  231.  
  232. s.Close();
  233. Debug.Log ("Read fle");
  234.  
  235. return b;
  236.  
  237. }
  238. return null;
  239.  
  240.  
  241. }
  242.  
  243. public static byte[] AskWebsiteForBytedata(string url){
  244. try{
  245.  
  246.  
  247. WebClient wcl = new WebClient();
  248. wcl.Proxy = null;
  249. byte[] content = wcl.DownloadData(url);
  250. wcl.Dispose ();
  251.  
  252.  
  253.  
  254. return content;
  255. }
  256. catch(System.Exception ex){
  257. if(!System.Threading.Thread.CurrentThread.IsBackground){
  258. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  259. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z internetem... " + ex.Message);
  260. } }
  261. Debug.Log (ex.Message);
  262.  
  263. return default(byte[]);
  264. }
  265.  
  266. }
  267.  
  268. public static byte[] ReadFully(Stream input)
  269. {
  270. try{
  271. byte[] buffer = new byte[16*1024];
  272. using (MemoryStream ms = new MemoryStream())
  273. {
  274. int read;
  275. while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
  276. {
  277. ms.Write(buffer, 0, read);
  278. }
  279.  
  280. return ms.ToArray();
  281. }
  282. }
  283. catch(System.Exception ex){
  284. if(!System.Threading.Thread.CurrentThread.IsBackground){
  285. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  286. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Błąd odczytu danych... " + ex.Message);
  287. }
  288. }
  289. Debug.Log (ex.Message);
  290.  
  291. return default(byte[]);
  292. }
  293. }
  294.  
  295. public static string AskWebsite(string url){
  296. try{
  297.  
  298. WebClient wc = new WebClient();
  299.  
  300. wc.Proxy = null;
  301. var content = wc.DownloadString(url);
  302. wc.Dispose ();
  303.  
  304. return content;
  305. }
  306. catch(System.Exception ex){
  307. if(!System.Threading.Thread.CurrentThread.IsBackground){
  308. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  309. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś nie tak z internetem... " + ex.Message);
  310. } }
  311. Debug.Log (ex.Message);
  312.  
  313. return "";
  314. }
  315.  
  316. }
  317.  
  318. public static class Helper{
  319.  
  320.  
  321. public static string CombineURL2(string URL){
  322. string r = MainURL2 + URL;
  323. return r;
  324. }
  325.  
  326. public static string EncryptGames(List<string> sync){
  327. BinaryFormatter bf = new BinaryFormatter();
  328. MemoryStream s = new MemoryStream();
  329. bf.Serialize(s, sync);
  330.  
  331. string r = System.Convert.ToBase64String(s.GetBuffer());
  332. s.Dispose();
  333. return r;
  334. }
  335.  
  336. public static List<string> DecryptGames(string games){
  337. BinaryFormatter bf = new BinaryFormatter();
  338. MemoryStream s = new MemoryStream(System.Convert.FromBase64String (games));
  339. object o = bf.Deserialize(s);
  340. s.Dispose();
  341. return (List<string>)o;
  342. }
  343.  
  344.  
  345. public static string EncryptObject(object o){
  346. BinaryFormatter bf = new BinaryFormatter();
  347. MemoryStream s = new MemoryStream();
  348. bf.Serialize(s, o);
  349. string r = System.Convert.ToBase64String(s.GetBuffer());
  350. s.Dispose();
  351. return r;
  352. }
  353.  
  354. public static object DecryptObject(string str){
  355. BinaryFormatter bf = new BinaryFormatter();
  356. MemoryStream s = new MemoryStream(System.Convert.FromBase64String (str));
  357. object o = bf.Deserialize(s);
  358. s.Dispose();
  359. return o;
  360. }
  361.  
  362. }
  363.  
  364. ///Classes designed to upload data
  365. public static class Upload{
  366.  
  367.  
  368. public static void CreateChatRoom(string name, List<ChatMsg> messages, bool NEX = true){
  369. try{
  370. WebClient wb = new WebClient();
  371. wb.Proxy = null;
  372.  
  373. string msgsE = Encrypting<List<ChatMsg>>.EncryptObject(messages);
  374. var data = new NameValueCollection();
  375. data["Name"] = name;
  376. data["DefaultMsgs"] = msgsE;
  377. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(ChatRoomCreate) , "POST", data));
  378.  
  379. wb.Dispose ();
  380. if(content != "Done"){
  381. if(!System.Threading.Thread.CurrentThread.IsBackground){
  382. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  383. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
  384. }
  385. }
  386.  
  387. Debug.Log (content);
  388. }
  389. }
  390. catch(System.Exception ex){
  391. if(NEX){
  392. CreateChatRoom(name, messages, false);
  393. }
  394. else{
  395. if(!System.Threading.Thread.CurrentThread.IsBackground){
  396. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  397. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
  398. }
  399. }
  400.  
  401. }
  402. }
  403. }
  404.  
  405. public static void SendQuestion(string msg, string sender, bool NEX = true){
  406. try{
  407. WebClient wb = new WebClient();
  408. wb.Proxy = null;
  409. var data = new NameValueCollection();
  410. data["MSG"] = msg;
  411. data["SENDER"] = sender;
  412.  
  413. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(QURL), "POST", data));
  414.  
  415. wb.Dispose ();
  416. if(content != "Done"){
  417. if(!System.Threading.Thread.CurrentThread.IsBackground){
  418. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  419. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
  420. }
  421. }
  422.  
  423. Debug.Log (content);
  424. }
  425. }
  426. catch(System.Exception ex){
  427. if(NEX){
  428. SendQuestion(msg, sender, false);
  429. }
  430. else{
  431. if(!System.Threading.Thread.CurrentThread.IsBackground){
  432. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  433. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
  434. }
  435. }
  436.  
  437. }
  438. }
  439.  
  440. }
  441.  
  442. public static string SetValueString(string TABLE, string IDFIELD, string ID, string VALUEFIELD, string VALUE, bool NEX = true){
  443. try{
  444. WebClient wb = new WebClient();
  445. wb.Proxy = null;
  446.  
  447.  
  448. var data = new NameValueCollection();
  449. data["TABLE"] = TABLE;
  450. data["IDFIELD"] = IDFIELD;
  451. data["ID"] = ID;
  452. data["VALUEFIELD"] = VALUEFIELD;
  453. data["VALUE"] = VALUE;
  454.  
  455. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(SetValue), "POST", data));
  456.  
  457. wb.Dispose ();
  458. if(content != "Done"){
  459. if(!System.Threading.Thread.CurrentThread.IsBackground){
  460. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  461. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
  462. }
  463. }
  464.  
  465. Debug.Log ("SET " + VALUEFIELD + " IN " + TABLE + " TO " + VALUE + " WHERE " + IDFIELD + " IS " + ID);
  466. Debug.Log (content);
  467.  
  468. }
  469.  
  470. return content;
  471. }
  472. catch(System.Exception ex){
  473. if(NEX){
  474. return SetValueString (TABLE, IDFIELD, ID, VALUEFIELD, VALUE, false);
  475. }
  476. else{
  477. if(!System.Threading.Thread.CurrentThread.IsBackground){
  478. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  479. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
  480. }
  481. }
  482. return "ERROR";
  483. }
  484. }
  485. }
  486.  
  487.  
  488.  
  489.  
  490. public static string SetValueInt(string TABLE, string IDFIELD, string ID, string VALUEFIELD, int VALUE, bool NEX = true){
  491. try{
  492. WebClient wb = new WebClient();
  493. wb.Proxy = null;
  494. //string url = Helper.CombineURL2(SetValue) + "?TABLE=" + TABLE + "&IDFIELD=" + IDFIELD + "&ID=" + ID + "&VALUEFIELD=" + VALUEFIELD + "&VALUE=" + VALUE;
  495. //string content = AskWebsite(url);
  496.  
  497. var data = new NameValueCollection();
  498. data["TABLE"] = TABLE;
  499. data["IDFIELD"] = IDFIELD;
  500. data["ID"] = ID;
  501. data["VALUEFIELD"] = VALUEFIELD;
  502. data["VALUE"] = VALUE.ToString();
  503.  
  504. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(SetValue), "POST", data));
  505. wb.Dispose ();
  506.  
  507. if(content != "Done"){
  508. if(!System.Threading.Thread.CurrentThread.IsBackground){
  509. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  510. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
  511. }
  512. }
  513. Debug.Log ("SET " + VALUEFIELD + " IN " + TABLE + " TO " + VALUE + " WHERE " + IDFIELD + " IS " + ID);
  514. Debug.Log (content);
  515.  
  516. }
  517.  
  518. return content;
  519. }
  520. catch(System.Exception ex){
  521. if(NEX){
  522. return SetValueInt (TABLE, IDFIELD, ID, VALUEFIELD, VALUE, false);
  523. }
  524. else{
  525. if(!System.Threading.Thread.CurrentThread.IsBackground){
  526. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  527. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
  528. }
  529. }
  530. return "ERROR";
  531. }
  532. }
  533. }
  534.  
  535. public static string CreateMatch(string ID, string Data, bool NEX = true){
  536.  
  537. try{
  538. WebClient wb = new WebClient();
  539. wb.Proxy = null;
  540.  
  541. var data = new NameValueCollection();
  542. data["ID"] = ID;
  543. data["Value"] = Data;
  544. data["Value2"] = Encrypting<List<string>>.EncryptObject(new List<string>());
  545.  
  546. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(MatchCreate), "POST", data));
  547. wb.Dispose ();
  548.  
  549. return content;
  550. }
  551. catch(System.Exception ex){
  552. if(NEX){
  553. return CreateMatch(ID, Data, false);
  554. }
  555. else{
  556. if(!System.Threading.Thread.CurrentThread.IsBackground){
  557. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  558. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...: " + ex.Message);
  559. }
  560. }
  561. return "ERROR";
  562. }
  563. }
  564. }
  565.  
  566.  
  567. }
  568.  
  569.  
  570. ///Classes designed to download data
  571. public static class Download{
  572.  
  573. public static string[] GetAllUsersN(){
  574.  
  575. string url = Helper.CombineURL2(AllUsers);
  576.  
  577. string content = AskWebsite(url);
  578.  
  579.  
  580. return content.Split(new string[]{"!"}, System.StringSplitOptions.RemoveEmptyEntries);
  581.  
  582. }
  583.  
  584. public static string[] GetLoggedUsers(){
  585.  
  586. string url = Helper.CombineURL2(GetAllUsers);
  587.  
  588. string content = AskWebsite(url);
  589.  
  590.  
  591. return content.Split('!');
  592.  
  593. }
  594.  
  595. public static string[] GetLoggedUsersNicknames(){
  596.  
  597.  
  598.  
  599. string url = Helper.CombineURL2(GetAllUsersNicknames);
  600.  
  601. string content = AskWebsite(url);
  602.  
  603.  
  604. return (content.Split('!'));
  605.  
  606. }
  607.  
  608. public static string GetValueStringNonMissing(string TABLE, string IDFIELD, string ID, string VALUEFIELD){
  609.  
  610.  
  611. WebClient wb = new WebClient();
  612. wb.Proxy = null;
  613.  
  614. var data = new NameValueCollection();
  615. data["TABLE"] = TABLE;
  616. data["IDFIELD"] = IDFIELD;
  617. data["ID"] = ID;
  618. data["VALUEFIELD"] = VALUEFIELD;
  619.  
  620. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(GetValue), "POST", data));
  621. wb.Dispose ();
  622.  
  623.  
  624. return content;
  625.  
  626.  
  627.  
  628. }
  629.  
  630. public static string GetValueString(string TABLE, string IDFIELD, string ID, string VALUEFIELD){
  631.  
  632. var wb = new MyWebClient ();
  633. wb.Proxy = null;
  634.  
  635. var data = new NameValueCollection();
  636. data["TABLE"] = TABLE;
  637. data["IDFIELD"] = IDFIELD;
  638. data["ID"] = ID;
  639. data["VALUEFIELD"] = VALUEFIELD;
  640.  
  641. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(GetValue), "POST", data));
  642.  
  643. if(content == "Missing" || content == "404" || content == null || (content == "" && VALUEFIELD != "Avatar")){
  644. if(!System.Threading.Thread.CurrentThread.IsBackground){
  645. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  646. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
  647. }
  648. }
  649. Debug.Log ("GET " + VALUEFIELD + " FROM " + TABLE + " WHERE " + IDFIELD + " IS " + ID);
  650. Debug.Log (content);
  651. }
  652. wb.Dispose ();
  653.  
  654. return content;
  655.  
  656.  
  657.  
  658.  
  659. }
  660.  
  661.  
  662. public static int GetValueInt(string TABLE, string IDFIELD, string ID, string VALUEFIELD){
  663.  
  664. WebClient wb = new WebClient();
  665. wb.Proxy = null;
  666.  
  667. var data = new NameValueCollection();
  668. data["TABLE"] = TABLE;
  669. data["IDFIELD"] = IDFIELD;
  670. data["ID"] = ID;
  671. data["VALUEFIELD"] = VALUEFIELD;
  672.  
  673. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(GetValue), "POST", data));
  674.  
  675. if(content == "Missing" || content == "404" || content == null || (content == "" && VALUEFIELD != "Avatar")){
  676. if(!System.Threading.Thread.CurrentThread.IsBackground){
  677. if(UIInstanceHelper.Instance.game.isMainThread(System.Threading.Thread.CurrentThread)){
  678. UIInstanceHelper.Instance.errorForm.Show ("Błąd", "Coś poszło nie tak po stronie serwera...");
  679. }
  680. }
  681. Debug.Log ("GET " + VALUEFIELD + " FROM " + TABLE + " WHERE " + IDFIELD + " IS " + ID);
  682. Debug.Log (content);
  683.  
  684. }
  685. wb.Dispose ();
  686.  
  687. return (System.Convert.ToInt32 (content));
  688.  
  689.  
  690.  
  691.  
  692. }
  693.  
  694.  
  695. public static string DownloadMatch(string ID){
  696.  
  697. WebClient wb = new WebClient();
  698. wb.Proxy = null;
  699.  
  700. var data = new NameValueCollection();
  701. data["ID"] = ID;
  702.  
  703. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(MatchDataDownload), "POST", data));
  704.  
  705. wb.Dispose ();
  706.  
  707. return content;
  708. }
  709.  
  710.  
  711. }
  712.  
  713. public static class InternalDataExchange{
  714.  
  715.  
  716. public static string LoginURL = "LoginUser.php";
  717. public static string LogoutURL = "LogoutUser.php";
  718. public static string RegisterURL = "RegisterUser.php";
  719.  
  720. public static string RecoverPassURL = "GeneratePassHashcode.php";
  721. public static string RecoverFromCODEURL = "GetPasswordFromCode.php";
  722. public static string ChangePassURL = "ChangePassword.php";
  723.  
  724.  
  725. public static string Login(string Email, string Password){
  726. try{
  727.  
  728. WebClient wb = new WebClient();
  729. wb.Proxy = null;
  730.  
  731. var data = new NameValueCollection();
  732. data["Email"] = Email;
  733. data["Password"] = Password;
  734.  
  735. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(LoginURL), "POST", data));
  736.  
  737. wb.Dispose ();
  738.  
  739. switch(content){
  740. case "EmptyMail":
  741. return ("Email jest pusty");
  742.  
  743. case "EmptyPassword":
  744. return ("Hasło jest puste");
  745. case "NoAccount":
  746. return("Brak konta dla tego adresu");
  747. case "WrongPassword":
  748. return("Błędne hasło");
  749. case "Done":
  750. return("Zalogowano");
  751. default:
  752. Debug.LogError(content);
  753. return "Błąd internetu\n" +content;
  754. }
  755. }
  756. catch(System.Exception ex){
  757. if(!System.Threading.Thread.CurrentThread.IsBackground){
  758. UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
  759. }
  760. return ex.Message;
  761. }
  762. }
  763.  
  764.  
  765. public static string ChangePassword(string Email, string Password, string NewPassword){
  766. try{
  767.  
  768. WebClient wb = new WebClient();
  769. wb.Proxy = null;
  770.  
  771. var data = new NameValueCollection();
  772. data["Email"] = Email;
  773. data["Password"] = Password;
  774. data["NewPassword"] = NewPassword;
  775.  
  776. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(ChangePassURL), "POST", data));
  777.  
  778.  
  779.  
  780. wb.Dispose ();
  781. switch(content){
  782. case "EmptyMail":
  783. return("Email jest pusty");
  784. case "EmptyPass":
  785. return("Hasło jest puste");
  786. case "NoAccount":
  787. return("Brak konta dla tego adresu");
  788. case "WrongPassword":
  789. return("Błędne hasło");
  790. case "Done":
  791. return("Hasło zmienione");
  792. default:
  793. Debug.Log (content);
  794.  
  795. return(content);
  796. }
  797. }
  798. catch(System.Exception ex){
  799. if(!System.Threading.Thread.CurrentThread.IsBackground){
  800. UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
  801. }
  802. return ex.Message;
  803. }
  804. }
  805.  
  806. public static string GenerateRecoverCode(string Email){
  807.  
  808. try{
  809.  
  810.  
  811. WebClient wb = new WebClient();
  812. wb.Proxy = null;
  813. var data = new NameValueCollection();
  814. data["Email"] = Email;
  815.  
  816.  
  817. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(RecoverPassURL), "POST", data));
  818.  
  819.  
  820.  
  821. wb.Dispose ();
  822. switch(content){
  823. case "EmptyMail":
  824. return("Email jest pusty");
  825. case "NoAccount":
  826. return("Brak konta dla tego adresu");
  827. case "Failed":
  828. return("Nieznany błąd");
  829. case "Done":
  830. return("Wygenerowano kod i wysłano E-mailem");
  831. default:
  832. Debug.Log (content);
  833.  
  834. return(content);
  835. }
  836. }
  837. catch(System.Exception ex){
  838. if(!System.Threading.Thread.CurrentThread.IsBackground){
  839. UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
  840. }
  841. return ex.Message;
  842. }
  843. }
  844.  
  845. public static string Logout(string Email){
  846.  
  847.  
  848. try{
  849.  
  850.  
  851. WebClient wb = new WebClient();
  852. wb.Proxy = null;
  853. var data = new NameValueCollection();
  854. data["Email"] = Email;
  855.  
  856.  
  857. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(LogoutURL), "POST", data));
  858.  
  859.  
  860.  
  861. wb.Dispose ();
  862. switch(content){
  863. case "EmptyMail":
  864. return("Email jest pusty");
  865. case "NoAccount":
  866. return("Brak konta dla tego adresu");
  867. case "Done":
  868. return("Wylogowano");
  869. default:
  870. Debug.Log (content);
  871.  
  872. return(content);
  873. }
  874. }
  875. catch(System.Exception ex){
  876. if(!System.Threading.Thread.CurrentThread.IsBackground){
  877. UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
  878. }
  879. return ex.Message;
  880. }
  881. }
  882.  
  883.  
  884. public static string RecoverPassword(string Email, string Hash, string Password){
  885. try{
  886.  
  887. WebClient wb = new WebClient();
  888. wb.Proxy = null;
  889. var data = new NameValueCollection();
  890. data["Email"] = Email;
  891. data["HashCode"] = Hash;
  892. data["Password"] = Password;
  893.  
  894.  
  895. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(RecoverFromCODEURL), "POST", data));
  896.  
  897. wb.Dispose ();
  898. switch(content){
  899. case "EmptyMail":
  900. return("Email jest pusty");
  901. case "NoAccount":
  902. return("Brak konta dla tego adresu");
  903. case "Failed":
  904. return("Nieznany błąd");
  905. case "Done":
  906. return("Hasło zmienione");
  907. case "WrongHashcode":
  908. return("Błędny kod odzyskiwania");
  909. default:
  910. Debug.Log (content);
  911.  
  912. return(content);
  913. }
  914. }
  915. catch(System.Exception ex){
  916. if(!System.Threading.Thread.CurrentThread.IsBackground){
  917. UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
  918. }
  919. return ex.Message;
  920. }
  921.  
  922. }
  923.  
  924.  
  925. public static string RegisterAccount(string Username, string Email, string Password){
  926. try{
  927.  
  928. WebClient wb = new WebClient();
  929. wb.Proxy = null;
  930. var data = new NameValueCollection();
  931. data["Email"] = Email;
  932. data["Username"] = Username;
  933. data["Password"] = Password;
  934.  
  935.  
  936. var content = System.Text.Encoding.Default.GetString(wb.UploadValues(Helper.CombineURL2(RegisterURL), "POST", data));
  937.  
  938. wb.Dispose ();
  939. switch(content){
  940. case "EmptyMail":
  941. return("Email jest pusty");
  942. case "EmptyPassword":
  943. return("Hasło jest puste");
  944. case "EmptyUsername":
  945. return("Nazwa użytkownika jest pusta");
  946. case "UsernameInUse":
  947. return("Nazwa użytkownika jest w użyciu");
  948. case "Done":
  949. return("Zarejestrowano");
  950. case "Exists":
  951. return("Email jest w użyciu");
  952. default:
  953. Debug.Log (content);
  954.  
  955. return(content);
  956. }
  957. }
  958. catch(System.Exception ex){
  959. if(!System.Threading.Thread.CurrentThread.IsBackground){
  960. UIInstanceHelper.Instance.errorForm.Show ("Błąd", ex.Message);
  961. }
  962. return ex.Message;
  963. }
  964.  
  965. }
  966.  
  967.  
  968.  
  969. }
  970.  
  971.  
  972. }
Add Comment
Please, Sign In to add comment