Guest User

Untitled

a guest
Dec 1st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using Nakama;
  6. using System.Threading;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using SimpleJSON;
  10. using Nakama.TinyJson;
  11. //using WindowsInput;
  12. //using WindowsInput.Native;
  13.  
  14. namespace kalameston_robot
  15. {
  16. class Class1
  17. {
  18. //----------
  19. int index;
  20. string[] robots = { "robot1@me.com", "robot2@me.com", "robot3@me.com", "robot4@me.com", "robot5@me.com", };
  21. //-----------------
  22. Client client1;
  23. Dictionary<string, int> letter_score = new Dictionary<string, int>();
  24. ISocket ic2;
  25. ISession session1;
  26. string match_ID = "";
  27. string userstatus;
  28. Timer timer;
  29. List<string> list_answer_words;
  30. DateTime t1;
  31. DateTime t2;
  32. string start_game;
  33. public class LevelInfo
  34. {
  35. public string Letters { get; set; }
  36. public string[] AnswerArray { get; set; }
  37. public int Duration { get; set; }
  38. }
  39.  
  40. LevelInfo levelInfo = new LevelInfo();
  41. Random rnd = new Random();
  42. int timer_counter = 0;
  43.  
  44. public void start()
  45. {
  46. index = 0;
  47. try
  48. {
  49.  
  50.  
  51. t1 = DateTime.MinValue;//قرار دادن مقدار پیشفرض در t1
  52.  
  53. set_letter_score();
  54. Login1();
  55.  
  56. Console.WriteLine("((((((((((((((((((())))))))))))))))))))))))))");
  57. Console.ReadKey();
  58. }
  59. catch (Exception err)
  60. {
  61. Console.WriteLine(err.Message);
  62. }
  63. }
  64.  
  65. private void set_letter_score()
  66. {
  67. if (letter_score.Count == 0)
  68. {
  69. letter_score.Add("ا", 1);
  70. letter_score.Add("ی", 1);
  71. letter_score.Add("ن", 1);
  72. letter_score.Add("م", 1);
  73. letter_score.Add("ت", 1);
  74. letter_score.Add("ر", 1);
  75. letter_score.Add("ه", 1);
  76. letter_score.Add("ش", 1);
  77. letter_score.Add("و", 1);
  78. letter_score.Add("د", 1);
  79. letter_score.Add("ب", 2);
  80. letter_score.Add("ل", 2);
  81. letter_score.Add("س", 2);
  82. letter_score.Add("ک", 2);
  83. letter_score.Add("ف", 2);
  84. letter_score.Add("ز", 2);
  85. letter_score.Add("ع", 2);
  86. letter_score.Add("ق", 2);
  87. letter_score.Add("گ", 2);
  88. letter_score.Add("خ", 2);
  89. letter_score.Add("ج", 3);
  90. letter_score.Add("پ", 3);
  91. letter_score.Add("ح", 3);
  92. letter_score.Add("ص", 3);
  93. letter_score.Add("آ", 3);
  94. letter_score.Add("ط", 3);
  95. letter_score.Add("غ", 4);
  96. letter_score.Add("چ", 4);
  97. letter_score.Add("ض", 4);
  98. letter_score.Add("ذ", 4);
  99. letter_score.Add("ژ", 5);
  100. letter_score.Add("ث", 5);
  101. letter_score.Add("ظ", 5);
  102. }
  103. }
  104.  
  105. void Login1()
  106. {
  107. try
  108. {
  109. Console.WriteLine("----------------login1 with +++++++++++ "+robots[index]);
  110. client1 = new Client("ttyhgbnghju", "127.0.0.1", 7350, false);
  111. // client1 = new Client("ttyhgbnghju", "192.168.1.20", 7350, false);
  112. // client1 = new Client("ttyhgbnghju", "157.119.190.92", 7350, false);
  113. Login_user(robots[index], "robot100");
  114.  
  115. if (index < 4)
  116. index++;
  117. else index = 0;
  118. }
  119. catch (Exception err)
  120. {
  121. Debug.Write(err.Message);
  122.  
  123. Console.Write("errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrorr");
  124. }
  125. }
  126. async void Login_user(string email, string password)
  127. {
  128. //**********login*****************
  129. if (session1 == null)
  130. {
  131. Console.WriteLine(" try login ............");
  132. session1 = await client1.AuthenticateEmailAsync(email, password);
  133. Console.WriteLine(" *******login success********* ");
  134. }
  135. Match_users();
  136.  
  137. //var score = password;// "sala555";
  138. //var rpcid = "f_get_level";
  139. //var pokemonInfo = await client1.RpcAsync(session1, rpcid, score);
  140. }
  141.  
  142. private async void Match_users()
  143. {
  144.  
  145.  
  146. ////توقف تصادفی ربات برای جلوگیری از وصل شدن سریع کاربر
  147. //int i = rnd.Next(15, 40);
  148. //Console.WriteLine("%%%%%%%%%%%%%%%% sleep for {0} second",i);
  149. //Thread.Sleep(i*1000);
  150. ////-------------------------
  151.  
  152.  
  153.  
  154.  
  155. //try
  156. //{
  157.  
  158. //********************get score***********
  159. /*
  160. var rpcid = "f_get_score";
  161. var score = "salam "; // + em.Substring(0, 2);
  162. var userInfo = await Client.RpcAsync(session, rpcid, score);
  163. Debug.LogFormat("GetUserInfoAsync: {0}", userInfo.Payload);
  164. JSONNode node = JSON.Parse(userInfo.Payload);
  165. print("==> " + node.AsObject["coins"].ToString());
  166. print("==> " + node.AsObject["diamonds"].ToString());
  167. print("==> " + node.AsObject["scores"].ToString());
  168. PlayerPrefs.SetInt("SCORES", node.AsObject["scores"]);*/
  169.  
  170.  
  171. //score = "salam";
  172. //rpcid = "f_get_score";
  173. //var userInfo = await client1.RpcAsync(session1, rpcid, score);
  174. //Debug.WriteLine(userInfo);
  175.  
  176.  
  177. //********************match make*******************
  178. Console.WriteLine("initialize match create......");
  179. var query2 = "*";
  180. var minCount2 = 2;
  181. var maxCount2 = 2;
  182.  
  183. // var query2 = "+properties.region:iran";
  184.  
  185. var stringProperties2 = new Dictionary<string, string>() {
  186. {"region", "robot"},
  187. {"type","robot" }
  188.  
  189. };
  190. var numericProperties2 = new Dictionary<string, double>() {
  191. { "rank", 1},
  192. { "score_ratio", 1}
  193.  
  194. };
  195.  
  196.  
  197. Console.WriteLine(":::::::::::::::::::::::::::::::::::::::::::::::::::1:");
  198. // var stringProperties2 = new Dictionary<string, string>() { { "region", "europe" }, { "levelwords", "12" },{ "scor_ratio","1"} };
  199. // var numericProperties2 = new Dictionary<string, double>() { { "rank", 8 } };
  200. //tttt = DateTime.Now;
  201. ic2 = client1.CreateWebSocket();
  202. Console.WriteLine(":::::::::::::::::::::::::::::::::::::::::::::::::::2:");
  203. //ic2.TimeoutMs = 20000;
  204. await ic2.ConnectAsync(session1);
  205. Console.WriteLine(":::::::::::::::::::::::::::::::::::::::::::::::::::3:");
  206.  
  207. Console.WriteLine("--------------try match make in loop by 6 second");
  208. bool repeat = true;
  209.  
  210. while (repeat)
  211. {
  212. try
  213. {
  214.  
  215. Console.Write("*");
  216. Thread.Sleep(10000);
  217.  
  218. Console.Write("+");
  219. var matchmakerTicket2 = await ic2.AddMatchmakerAsync(
  220. query2, minCount2, maxCount2, stringProperties2, numericProperties2);
  221. repeat = false;
  222.  
  223. Console.Write("------------match make is successfull");
  224.  
  225. }
  226. catch (Exception err)
  227. {
  228. Debug.Write(err.Message);
  229. Console.Write(err.Message.ToString());
  230. query2 = null;
  231. numericProperties2 = null;
  232. stringProperties2 = null;
  233.  
  234.  
  235. ic2 = null;
  236. client1 = null;
  237. session1 = null;
  238. end_game("while error");
  239.  
  240. return;
  241. }
  242. }
  243. var so = ic2;
  244.  
  245. Console.WriteLine("\n :::::::::::::::::::::::::::::::::::::::::::::::::::4:");
  246.  
  247. so.OnMatchmakerMatched += async (_, matched) =>
  248. {
  249. start_game = "no";//بعد از اتصال کاربر بازی نباید شروع شود تا زمانی که کد 200 از سمت سرور جهت شروع بازی ارسال گردد
  250. userstatus = "resume";
  251. Console.WriteLine(":::::::::::::::::::::::::::::::::::::::::::::::::::5:");
  252. var t = DateTime.Now;
  253.  
  254. var opponents = matched.Users.ToArray()[0].Presence.UserId.ToString() + matched.Users.ToArray()[1].Presence.UserId.ToString(); // printable list.
  255. Console.WriteLine(":::::::::::::::::::::::::::::::::::::::::::::::::::6:");
  256. Console.WriteLine(matched.Users.ToArray()[0].Presence.UserId.ToString() + " =======VS======= " + matched.Users.ToArray()[1].Presence.UserId.ToString());
  257.  
  258. //بررسی وجود ربات در بین بازیکن ها
  259. bool robot1 = false;
  260. bool robot2 = false;
  261. string[] robot_list = new string[5];
  262.  
  263. robot_list[0] = "3ad707d7-4f05-4fc8-93c5-cf64ca576d4a";
  264. robot_list[1] = "d7aedbda-a706-414e-9083-4e6d8a1e2c07";
  265. robot_list[2] = "ab2da0a3-009f-42df-a53c-e7122b89c838";
  266. robot_list[3] = "cbf3c9ff-f086-4b2a-8482-b5911de40215";
  267. robot_list[4] = "d694b240-5144-4ba9-a9b1-5dc73832ab1c";
  268. for (int i = 0; i < robot_list.Length; i++)
  269. {
  270. if (matched.Users.ToArray()[0].Presence.UserId.ToString() == robot_list[i])
  271. { robot1 = true; Console.WriteLine("+++++++++++player1 is robot"); }
  272. if (matched.Users.ToArray()[1].Presence.UserId.ToString() == robot_list[i])
  273. { robot2 = true; Console.WriteLine("+++++++++++player2 is robot"); }
  274. }
  275. //اگر ربات به خودش یا ربات دیگر متصل شود بازی باید تمام شود در غیر این صورت ادامه یابد
  276. if (robot1 == true && robot2 == true)
  277. {
  278. Console.WriteLine("!!!!!!!!!!!!!!!!!!!! robot match with self !!!!!!! end_game");
  279. end_game("--------robot vs robot-------");
  280. }
  281. else
  282. {
  283. Console.WriteLine("~~~~~~~~~~~~~~~~ play with opponents");
  284. //*****************************
  285. await so.JoinMatchAsync(matched);
  286. Console.WriteLine("************match created ********");
  287. timer = new Timer(TimerCallback, null, 0, 1000);
  288. }
  289.  
  290. };
  291.  
  292.  
  293. //************دریافت اطلاعات مرحله
  294. so.OnMatchState += (_, state) =>
  295. {
  296. Console.WriteLine("OnMatchState");
  297. Console.WriteLine("opcode=" + state.OpCode.ToString());
  298. Console.WriteLine("********OnMatchState*******");
  299. var content = System.Text.Encoding.UTF8.GetString(state.State);
  300. //Debug.Log("OnMatchState" + state.OpCode.ToString() + " | " + content);
  301. Console.WriteLine("state= ", content);
  302. MJSONNode node;
  303. switch (state.OpCode)
  304. {
  305. case 999:
  306. Console.WriteLine("InitGame");
  307.  
  308. node = JSON.Parse(content);
  309.  
  310. Console.WriteLine("Level " + node.AsObject["lvl"].Value);
  311. Console.WriteLine("Duration " + node.AsObject["duration"].ToString());
  312. Console.WriteLine("Counter " + node.AsObject["counter"].ToString());
  313.  
  314. levelInfo.Duration = node.AsObject["duration"].AsInt;
  315. levelInfo.Letters = node.AsObject["lvl"].Value.Split('-')[0];
  316. levelInfo.AnswerArray = node.AsObject["lvl"].Value.Split('-')[1].Split(' ');
  317. //مرتب کردن کلمات صحیح بر از کلمات کوچک به کلمات بزرگ
  318. //string[] temp = new string[levelInfo.AnswerArray.Length];
  319. //int temp_index = 0;
  320. //for (int i=3;i<10;i++)
  321. //{
  322. // for(int j=0;j< levelInfo.AnswerArray.Length;j++)
  323. // {
  324. // if(levelInfo.AnswerArray[j].Length==i)
  325. // {
  326. // temp[temp_index] = levelInfo.AnswerArray[j];
  327. // temp_index++;
  328. // }
  329. // }
  330. //}
  331. //levelInfo.AnswerArray = temp;
  332.  
  333. list_answer_words = new List<string>(levelInfo.AnswerArray);
  334.  
  335. Console.WriteLine("InitGameCounter= " + node.AsObject["counter"].AsInt.ToString());
  336. Console.WriteLine("duration= " + node.AsObject["duration"].AsInt.ToString());
  337. Console.WriteLine("lvl= " + node.AsObject["lvl"].Value.ToString());
  338.  
  339.  
  340.  
  341.  
  342.  
  343. break;
  344. case 101:
  345. //Console.WriteLine( "AddScore");
  346.  
  347. //node = JSON.Parse(content);
  348.  
  349. //Console.WriteLine( "AddScore", node.AsObject["add_score"].ToString());
  350. //Console.WriteLine( "Counter", node.AsObject["counter"].ToString());
  351.  
  352. //if (messageLastCounter < node.AsObject["counter"].AsInt)
  353. //{
  354. // messageLastCounter = node.AsObject["counter"].AsInt;
  355. // UnityMainThreadDispatcher.Instance().Enqueue(() => ScreenManager.Instance.gamePanel.OnScoreGameEvent(state.UserPresence, node.AsObject["add_score"].AsInt,
  356. // node.AsObject["add_score_word"].AsInt, node.AsObject["add_score_length"].AsInt));
  357.  
  358. // // opCode = 101;
  359.  
  360. // // Console.WriteLine("NakamaManager", "Update", "AddScore", "true");
  361. // // Console.WriteLine("NakamaManager", "Update", "AddScoreCounter", messageCounter.ToString());
  362. // // Console.WriteLine("NakamaManager", "Update", "AddScoreLastCounter", messageLastCounter.ToString());
  363. //}
  364. //else
  365. //{
  366. // // Console.WriteLine("NakamaManager", "Update", "AddScore", "false");
  367. // // Console.WriteLine("NakamaManager", "Update", "AddScoreCounter", messageCounter.ToString());
  368. // // Console.WriteLine("NakamaManager", "Update", "AddScoreLastCounter", messageLastCounter.ToString());
  369. //}
  370. break;
  371. case 110:
  372. //Console.WriteLine( "UserStatus");
  373.  
  374. //// TODO sync func ??? -- automatic send score for test
  375.  
  376. node = JSON.Parse(content);
  377. userstatus = node.AsObject["userStatus"].ToString();
  378. userstatus = userstatus.Replace("\"", "");
  379. Console.WriteLine("&&&&&&&&&&&&&& UserStatus= " + userstatus);
  380. //Console.WriteLine( "Counter", node.AsObject["counter"].ToString());
  381.  
  382. //if (messageLastCounter < node.AsObject["counter"].AsInt)
  383. //{
  384. // messageLastCounter = node.AsObject["counter"].AsInt;
  385.  
  386. // UnityMainThreadDispatcher.Instance().Enqueue(() => ScreenManager.Instance.gamePanel.OnStatusGameEvent(state.UserPresence, node.AsObject["userStatus"]));
  387.  
  388. // Console.WriteLine("NakamaManager", "Update", "AddScore", "true");
  389. // Console.WriteLine("NakamaManager", "Update", "AddScoreCounter", messageCounter.ToString());
  390. // Console.WriteLine("NakamaManager", "Update", "AddScoreLastCounter", messageLastCounter.ToString());
  391. //}
  392. //else
  393. //{
  394. // Console.WriteLine("NakamaManager", "Update", "AddScore", "false");
  395. // Console.WriteLine("NakamaManager", "Update", "AddScoreCounter", messageCounter.ToString());
  396. // Console.WriteLine("NakamaManager", "Update", "AddScoreLastCounter", messageLastCounter.ToString());
  397. //}
  398.  
  399.  
  400. break;
  401. case 200:
  402. start_game = "ok";
  403. break;
  404.  
  405. default:
  406. try
  407. {
  408. string uname = "";
  409. if (state.UserPresence.Username != null)
  410. { uname = state.UserPresence.Username.ToString(); }
  411.  
  412. Console.WriteLine("User {0} sent {1}", uname, content);
  413. }
  414. catch (Exception err)
  415. { Debug.Write(err.Message); }
  416. break;
  417. }
  418. };
  419.  
  420.  
  421. //*** user 2
  422.  
  423. // چاپ لیست رقبا
  424.  
  425.  
  426. var connectedOpponents = new List<IUserPresence>(0);
  427. ic2.OnMatchPresence += (_, presence) =>
  428. {
  429. connectedOpponents.AddRange(presence.Joins);
  430. Debug.WriteLine("///////////////" + presence);
  431. Console.WriteLine("///////////////" + presence);
  432. match_ID = presence.MatchId.ToString();
  433. Debug.WriteLine("///////////------------////" + match_ID);
  434. Console.WriteLine("///////////------------////" + match_ID);
  435.  
  436.  
  437. //var opCode = 1;
  438. //var newState = new Dictionary<string, string> { { "add_score", "25" } }.ToJson();
  439. //ic2.SendMatchState(match_ID, opCode, newState);
  440. foreach (var leave in presence.Leaves)
  441. {
  442. connectedOpponents.RemoveAll(item => item.SessionId.Equals(leave.SessionId));
  443. }
  444. Debug.WriteLine("ttttttttttt" + connectedOpponents.Count.ToString());
  445. };
  446.  
  447.  
  448. //*****************************
  449.  
  450. //if (i % 20 == 0)
  451. //{
  452. // for (int k = 1; k < 4000; k++)
  453. // {
  454. // TimeSpan span = tttt[k].Subtract(DateTime.Now);
  455. // if (span.Seconds > 250)
  456. // {
  457. // ic2[k].DisconnectAsync().Dispose();
  458. // }
  459. // }
  460. // Thread.Sleep(5000);
  461. //}
  462.  
  463.  
  464.  
  465. //textBox1.Text = "match make";
  466.  
  467. //}
  468.  
  469. //catch (Exception err)
  470. //{
  471. // Console.WriteLine( err.Message.ToString() + Environment.NewLine + "-----------------------" );
  472. //}
  473.  
  474.  
  475.  
  476. }
  477.  
  478.  
  479. public void SendDataMessage(int opCode, Dictionary<string, string> newState)
  480. {
  481. Console.WriteLine("*********************SendDataMessage************");
  482.  
  483.  
  484. //var newStatse = new Dictionary<string, string> { { "hello", "world" } }.ToJson();
  485. // Socket.SendMatchState(matchId, opCode, newState.ToJson());
  486. ic2.SendMatchState(match_ID, opCode, newState.ToJson());
  487. }
  488.  
  489. //public void AddScore(int wordScore, int wordLength)
  490. //{
  491. // DebugManager.Log("GamePanel", "AddScore");
  492. // DebugManager.LogKeyValue("GamePanel", "AddScore", "AddScore", wordScore.ToString());
  493. // if (gameFinished)
  494. // return;
  495.  
  496. // int k = 0;
  497. // if (wordLength > 3)
  498. // k = wordLength;
  499.  
  500.  
  501. // NakamaManager.Instance.SendDataMessage(101, new Dictionary<string, string>()
  502. //{
  503. // {KEY_ADD_SCORE, (wordScore+k).ToString() },
  504. // {KEY_ADD_SCORE_WORD, (wordScore).ToString() },
  505. // {KEY_ADD_SCORE_LENGTH, (k).ToString() }
  506. //});
  507. //}
  508.  
  509.  
  510.  
  511.  
  512.  
  513. private void TimerCallback(Object o)
  514. {
  515. if (start_game == "ok")
  516. {
  517.  
  518. if (userstatus == "resume")
  519. {
  520. t1 = DateTime.MinValue;//مقدار پیشفرض در t1
  521. if (levelInfo != null)
  522. {
  523. timer_counter++;
  524. Console.WriteLine(" duration=" + levelInfo.Duration);
  525. levelInfo.Duration = levelInfo.Duration - 1;
  526. //ارسال تصادفی امتیاز
  527.  
  528. int r = rnd.Next(1, rnd.Next(8, 15));//اگر عدد تصادفی 5 باشد امتیاز یک کلمه ارسال خواهد شد
  529. if (r == 5 && timer_counter > 3)//در صورتی که عدد تصادفی 5 باشد و 3 ثانیه از شروع بازی گذشته باشد و کلمه ارسال نشده ای نیز وجود داشته باشد
  530. {
  531. int opcode = 101;
  532. int wordScore = 0;
  533. int k = 0;
  534. //انتخاب تصادفی کلمه پاسخ
  535. int rnd_index = rnd.Next(0, list_answer_words.Count - 1);
  536. string correct_word = list_answer_words[rnd_index].ToString();
  537. list_answer_words.RemoveAt(rnd_index);
  538. Console.WriteLine("+++++++++++++++++ list words length= " + list_answer_words.Count.ToString() + " +++++++++++++ correct word length= " + correct_word.Length.ToString() + " ====================== k= " + k.ToString());
  539.  
  540. //
  541. for (int i = 0; i < correct_word.Length; i++)
  542. {
  543. int score = 0;
  544. if (letter_score.TryGetValue(correct_word[i].ToString(), out score))
  545. {
  546. wordScore = wordScore + score;
  547. }
  548. }
  549.  
  550.  
  551.  
  552.  
  553. if (correct_word.Length > 3)
  554. { k = correct_word.Length; }
  555.  
  556. Console.WriteLine("=================== word score= " + wordScore.ToString() + " ====================== k= " + k.ToString());
  557. Dictionary<string, string> newState = new Dictionary<string, string>()
  558. {
  559. {"add_score", (wordScore+k).ToString() },
  560. {"add_score_word", (wordScore).ToString() },
  561. {"add_score_length", (k).ToString() }
  562. };
  563. SendDataMessage(opcode, newState);
  564. }
  565. //حذف تایمر هنگام پایان زمان باری
  566. if (levelInfo.Duration == 0 || levelInfo.Duration < -2)
  567. {
  568. start_game = "no";
  569. GetMatchResultAsync("finished");
  570. end_game("1");
  571.  
  572.  
  573. }
  574. }
  575. }
  576. else
  577. {
  578. Console.WriteLine("---------------------- user is pause " + userstatus);
  579. //اگر کاربر متوقف شود
  580. if (t1 == DateTime.MinValue)
  581. {
  582. t1 = DateTime.Now;
  583. }
  584. t2 = DateTime.Now;
  585. TimeSpan diff = t2 - t1;
  586. if (diff.TotalSeconds >= 10)
  587. {
  588. start_game = "no";
  589. t1 = DateTime.MinValue;
  590. GetMatchResultAsync("unfinished");
  591. end_game("2");
  592. }
  593. }
  594.  
  595.  
  596. // Display the date/time when this method got called.
  597. Console.WriteLine("In TimerCallback: " + DateTime.Now);
  598. // Force a garbage collection to occur for this demo.
  599. //GC.Collect();
  600.  
  601. }
  602. }
  603.  
  604. private void end_game(string code)
  605. {
  606. Console.WriteLine("&&&&&&&&&&&&&&&& end_game(" + code + ") &&&&&&&&&&&&&&&&");
  607. leave();
  608. //--------------------
  609. //ic2.Dispose();
  610. session1 = null;
  611. //client1 = null;
  612. //-----------یکبار اجرا--------
  613. //Thread.Sleep(2000);
  614. //InputSimulator a = new InputSimulator();
  615. //a.Keyboard.KeyPress(VirtualKeyCode.SPACE);
  616.  
  617. //Environment.Exit(0);
  618. //-------------------
  619.  
  620. if (timer != null) { timer.Dispose(); }
  621. timer_counter = 0;
  622.  
  623. set_letter_score();
  624. Console.WriteLine("'''''''''''''sleep for 10 second");
  625. Thread.Sleep(10000);
  626. Login1();
  627. // Match_users();
  628.  
  629.  
  630.  
  631. }
  632.  
  633. public async void GetMatchResultAsync(string end_game_state)
  634. {
  635. Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^ call Match Result ^^^^^^^^^^^^^^^^^^^6");
  636.  
  637.  
  638.  
  639. var rpcid = "f_match_result";
  640.  
  641. MJSONObject jsonObject = new MJSONObject();
  642. jsonObject.Add("match_id", match_ID);
  643. jsonObject.Add("match_end_status", end_game_state);
  644. //if (end_game_state)
  645. // jsonObject.Add("match_end_status", "finished");
  646. //else
  647. // jsonObject.Add("match_end_status", "unfinished"); // when opponent player disconnect for ten seconds
  648.  
  649.  
  650. // var score = "[{\"match_id\":::::::::::::::::::::::::::::::::::::::::::::::::::\"b1284e80-0e53-42e7-9d45-8abe9101bfc9.nakama\",\"match_end_status\":::::::::::::::::::::::::::::::::::::::::::::::::::\"finished\"}]";
  651.  
  652. // print("=====> " + jsonObject.ToString());
  653. var result = await client1.RpcAsync(session1, rpcid, jsonObject.ToString());
  654.  
  655. //Debug.LogFormat("Retrieved pokemon info: {0}", result);
  656. // Debug.LogFormat("Retrieved pokemon info: {0}", result.Payload);
  657.  
  658. Console.WriteLine(result.Payload);
  659. //return result.Payload.Substring(1, result.Payload.Length - 2);
  660. }
  661.  
  662. public async Task leave()
  663. {
  664. Console.WriteLine("***************leave match*****************");
  665. await ic2.LeaveMatchAsync(match_ID);
  666. }
  667. }
  668. }
Add Comment
Please, Sign In to add comment