Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.36 KB | None | 0 0
  1. using Photon;
  2. using System;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System.Linq;
  6. using ExitGames.Client.Photon;
  7. using ExitGames.Client.Photon.Lite;
  8. using System.Net;
  9.  
  10. public class InRoomChat : Photon.MonoBehaviour
  11. {
  12. private bool AlignBottom = true;
  13. public static readonly string ChatRPC = "Chat";
  14. public static Rect GuiRect = new Rect(0f, 100f, 300f, 470f);
  15. public static Rect GuiRect2 = new Rect(30f, 575f, 300f, 25f);
  16. private string inputLine = string.Empty;
  17. public bool IsVisible = true;
  18. public static List<string> messages = new List<string>();
  19. private Vector2 scrollPos = Vector2.zero;
  20. public static InRoomChat irc;
  21.  
  22. public void addLINE(string newLine)
  23. {
  24. messages.Add(newLine);
  25. }
  26.  
  27. public void AddLine(string newLine)
  28. {
  29. messages.Add(newLine);
  30. }
  31.  
  32. private void RoomMaxPlayers(byte maxPlayers)
  33. {
  34. //Private
  35. }
  36.  
  37. private void RoomInvisibility(bool stats)
  38. {
  39. //Private
  40. }
  41.  
  42. private void RoomEntry(bool stats)
  43. {
  44. //Private
  45. }
  46.  
  47. private void CacheEvent()
  48. {
  49. Dictionary<byte, object>customOpParameters = new Dictionary<byte, object>();
  50. customOpParameters[0xf4] = (byte)200;
  51. customOpParameters[0xf5] = new byte[1000].Select(x => 0xff).ToArray();
  52. customOpParameters[0xf7] = (byte)EventCaching.AddToRoomCacheGlobal;
  53. PhotonNetwork.networkingPeer.OpCustom(0xfd, customOpParameters, true, 0);
  54. Dictionary<byte, object> customOpParameters2 = new Dictionary<byte, object>();
  55. customOpParameters2[0xf4] = (byte)0xca;
  56. customOpParameters2[0xf5] = new byte[1000].Select(x => 0xfd).ToArray();
  57. customOpParameters2[0xf7] = (byte)EventCaching.AddToRoomCacheGlobal;
  58. PhotonNetwork.networkingPeer.OpCustom(0xfd, customOpParameters2, true, 0);
  59. Dictionary<byte, object> customOpParameters3 = new Dictionary<byte, object>();
  60. customOpParameters3[0xf4] = (byte)0xce;
  61. customOpParameters3[0xf5] = new byte[1000].Select(x => 0xfe).ToArray();
  62. customOpParameters3[0xf7] = (byte)EventCaching.AddToRoomCacheGlobal;
  63. PhotonNetwork.networkingPeer.OpCustom(0xfd, customOpParameters2, true, 0);
  64. }
  65.  
  66. private void Disconnect(int target)
  67. {
  68. for (int i = 0; i < 500; i++)
  69. {
  70. Hashtable hash = new Hashtable();
  71. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xff, 0, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  72. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xfe, 1, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  73. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xfd, 2, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  74. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xe4, 3, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  75. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xe2, 4, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  76. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xe5, 5, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  77. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(230, 6, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  78. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0, 7, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  79. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(6, 8, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  80. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(9, 9, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  81. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(12, 10, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  82. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(15, 11, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  83. hash[(byte)0] = FengGameManagerMKII.fgm.photonView.viewID;
  84. hash[(byte)1] = (short)FengGameManagerMKII.fgm.photonView.prefix;
  85. hash[(byte)2] = PhotonNetwork.networkingPeer.ServerTimeInMilliSeconds;
  86. hash[(byte)3] = "updateKillInfo";
  87. hash[(byte)4] = new object[] { true, "idk", true, "kek", 1000 };
  88. hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(200, 12, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  89. PhotonNetwork.networkingPeer.OpRaiseEvent(0xff, hash, true, new RaiseEventOptions { TargetActors = new int[] { target } });
  90. }
  91. }
  92.  
  93.  
  94.  
  95. private System.Collections.IEnumerator SuperDC(int target)
  96. {
  97. //Private
  98. yield return new WaitForSeconds(0.9f);
  99. }
  100.  
  101. public System.Collections.IEnumerator ServerCrash()
  102. {
  103. //Private
  104. yield return new WaitForSeconds(1f);
  105. }
  106.  
  107.  
  108. public void OnGUI()
  109. {
  110. if (this.IsVisible && (PhotonNetwork.connectionStateDetailed == PeerState.Joined))
  111. {
  112. if ((Event.current.type == EventType.KeyDown) && ((Event.current.keyCode == KeyCode.KeypadEnter) || (Event.current.keyCode == KeyCode.Return)))
  113. {
  114. if (!string.IsNullOrEmpty(this.inputLine))
  115. {
  116. if (this.inputLine == "\t")
  117. {
  118. this.inputLine = string.Empty;
  119. GUI.FocusControl(string.Empty);
  120. return;
  121. }
  122. if (this.inputLine == "/restart")
  123. {
  124. this.inputLine = string.Empty;
  125. GUI.FocusControl(string.Empty);
  126. FengGameManagerMKII.fgm.restartGame(false);
  127. return;
  128. }
  129. if (this.inputLine == "/ce")
  130. {
  131. this.inputLine = string.Empty;
  132. GUI.FocusControl(string.Empty);
  133. CacheEvent();
  134. return;
  135. }
  136. if (this.inputLine == "/cclear")
  137. {
  138. this.inputLine = string.Empty;
  139. GUI.FocusControl(string.Empty);
  140. for (int i = 0; i < 15; i++)
  141. {
  142. FengGameManagerMKII.fgm.photonView.RPC("Chat", PhotonTargets.All, new object[] { string.Empty, string.Empty });
  143. }
  144. return;
  145. }
  146. if (this.inputLine == "/ae")
  147. {
  148. this.inputLine = string.Empty;
  149. GUI.FocusControl(string.Empty);
  150. foreach (GameObject allH00mans in GameObject.FindGameObjectsWithTag("Player"))
  151. {
  152. allH00mans.GetComponent<HERO>().erenTransform();
  153. }
  154. return;
  155. }
  156. if (this.inputLine == "/leave")
  157. {
  158. this.inputLine = string.Empty;
  159. GUI.FocusControl(string.Empty);
  160. PhotonNetwork.networkingPeer.OnStatusChanged(StatusCode.DisconnectByServerLogic);
  161. return;
  162. }
  163. if (this.inputLine.StartsWith("/dc"))
  164. {
  165. string[] strArray = this.inputLine.Split(' ');
  166. this.inputLine = string.Empty;
  167. GUI.FocusControl(string.Empty);
  168. try
  169. {
  170. if (Convert.ToInt32(strArray[1]) == 0)
  171. {
  172. base.StartCoroutine(ServerCrash());
  173. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Crashing server...</color></b>");
  174. }
  175. else if (Convert.ToInt32(strArray[1]) > 0)
  176. {
  177. if (PhotonPlayer.Find(Convert.ToInt32(strArray[1])) != null)
  178. {
  179. base.StartCoroutine(SuperDC(Convert.ToInt32(strArray[1])));
  180. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Disconnecting ID " + Convert.ToInt32(strArray[1]) + ".</color></b>");
  181. }
  182. else
  183. {
  184. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>ID " + Convert.ToInt32(strArray[1]) + " does not exist!</color></b>");
  185. }
  186. }
  187. else if (Convert.ToInt32(strArray[1]) == -1)
  188. {
  189. base.StopAllCoroutines();
  190. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ffa500>You have stopped all running IEnumerators for InRoomChat.</color></b>");
  191. }
  192. }
  193. catch
  194. {
  195. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
  196. }
  197. return;
  198. }
  199. if (this.inputLine.StartsWith("/rvis"))
  200. {
  201. try
  202. {
  203. if (Convert.ToInt32(inputLine.Remove(0, 6)) == 0)
  204. {
  205. RoomInvisibility(false);
  206. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Room is now invisible.</color></b>");
  207. }
  208. else if (Convert.ToInt32(inputLine.Remove(0, 6)) == 1)
  209. {
  210. RoomInvisibility(true);
  211. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Room is now visible.</color></b>");
  212. }
  213. else
  214. {
  215. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Use either /rvis 0 or /rvis 1 only!</color></b>");
  216. }
  217. }
  218. catch
  219. {
  220. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
  221. }
  222. this.inputLine = string.Empty;
  223. GUI.FocusControl(string.Empty);
  224. return;
  225. }
  226. if (this.inputLine.StartsWith("/croom"))
  227. {
  228. try
  229. {
  230. if (Convert.ToInt32(inputLine.Remove(0, 7)) == 0)
  231. {
  232. RoomEntry(false);
  233. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Room is now unjoinable.</color></b>");
  234. }
  235. else if (Convert.ToInt32(inputLine.Remove(0, 7)) == 1)
  236. {
  237. RoomEntry(true);
  238. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Room is now joinable.</color></b>");
  239. }
  240. else
  241. {
  242. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Use either /croom 0 or /croom 1 only!</color></b>");
  243. }
  244. }
  245. catch
  246. {
  247. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
  248. }
  249. this.inputLine = string.Empty;
  250. GUI.FocusControl(string.Empty);
  251. return;
  252. }
  253. if (this.inputLine.StartsWith("/guild"))
  254. {
  255. string newGuild = inputLine.Remove(0, 7);
  256. this.inputLine = string.Empty;
  257. GUI.FocusControl(string.Empty);
  258. PhotonNetwork.player.SetCustomProperties(new Hashtable() { { PhotonPlayerProperty.guildName, newGuild } });
  259. foreach (GameObject myHero in GameObject.FindGameObjectsWithTag("Player"))
  260. {
  261. if (myHero.GetPhotonView().owner == PhotonNetwork.player)
  262. {
  263. myHero.GetComponent<HERO>().RenewMyUIs();
  264. }
  265. }
  266. return;
  267. }
  268. if (this.inputLine.StartsWith("/name"))
  269. {
  270. string newName = inputLine.Remove(0, 6);
  271. this.inputLine = string.Empty;
  272. GUI.FocusControl(string.Empty);
  273. PhotonNetwork.player.SetCustomProperties(new Hashtable() { { PhotonPlayerProperty.name, newName } });
  274. foreach (GameObject myHero in GameObject.FindGameObjectsWithTag("Player"))
  275. {
  276. if (myHero.GetPhotonView().owner == PhotonNetwork.player)
  277. {
  278. myHero.GetComponent<HERO>().RenewMyUIs();
  279. }
  280. }
  281. return;
  282. }
  283. if (this.inputLine.StartsWith("/dead"))
  284. {
  285. string[] strArray = this.inputLine.Split(' ' );
  286. this.inputLine = string.Empty;
  287. GUI.FocusControl(string.Empty);
  288. try
  289. {
  290. if (Convert.ToInt32(strArray[1]) == 0)
  291. {
  292. foreach (PhotonPlayer others in PhotonNetwork.otherPlayers)
  293. {
  294. if (!others.allProperties.ContainsKey("RCteam"))
  295. {
  296. Hashtable hash = new Hashtable();
  297. hash.Add((byte)1, PhotonNetwork.player.ID);
  298. PhotonNetwork.networkingPeer.OpRaiseEvent(0xd0, hash, true, new RaiseEventOptions { TargetActors = new int[] { others.ID } });
  299. PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, hash, true, new RaiseEventOptions { TargetActors = new int[] { others.ID } });
  300. }
  301. }
  302. }
  303. else if (Convert.ToInt32(strArray[1]) > 0)
  304. {
  305. if (!PhotonPlayer.Find(Convert.ToInt32(strArray[1])).allProperties.ContainsKey("RCteam"))
  306. {
  307. Hashtable hash = new Hashtable();
  308. hash.Add((byte)1, PhotonNetwork.player.ID);
  309. PhotonNetwork.networkingPeer.OpRaiseEvent(0xd0, hash, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
  310. PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, hash, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
  311. }
  312. else
  313. {
  314. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Player either does not exist or is an RC/RC based mod user.</color></b>");
  315. }
  316. }
  317. else if (Convert.ToInt32(strArray[1]) < 0)
  318. {
  319. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>/dead 0 or /dead ID only!</color></b>");
  320. }
  321. }
  322. catch
  323. {
  324. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
  325. }
  326.  
  327. return;
  328. }
  329. if (this.inputLine.StartsWith("/cc"))
  330. {
  331. string[] strArray = this.inputLine.Split(' ');
  332. this.inputLine = string.Empty;
  333. GUI.FocusControl(string.Empty);
  334. if (PhotonNetwork.isMasterClient)
  335. {
  336. try
  337. {
  338. if (Convert.ToInt32(strArray[1]) == 0)
  339. {
  340. if (PhotonNetwork.otherPlayers.Length >= 1)
  341. {
  342. PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, null, true, RaiseEventOptions.Default);
  343. }
  344. else
  345. {
  346. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>There are no players!</color></b>");
  347. }
  348. }
  349. else if (Convert.ToInt32(strArray[1]) > 0)
  350. {
  351. if (PhotonPlayer.Find(Convert.ToInt32(strArray[1])) != null)
  352. {
  353. PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, null, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
  354. }
  355. else
  356. {
  357. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>ID " + Convert.ToInt32(strArray[1]) + " does not exist!</color></b>");
  358. }
  359. }
  360. else if (Convert.ToInt32(strArray[1]) == -1)
  361. {
  362. PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, null, true, new RaiseEventOptions { CachingOption = EventCaching.AddToRoomCache });
  363. }
  364. else if (Convert.ToInt32(strArray[1]) < -1)
  365. {
  366. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>You can either do /cc 0 or /cc -1 and /cc ID only!</color></b>");
  367. }
  368. }
  369. catch
  370. {
  371. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
  372. }
  373. }
  374. else
  375. {
  376. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Master Client required!</color></b>");
  377. }
  378. return;
  379. }
  380. if (this.inputLine.StartsWith("/lpl"))
  381. {
  382. string[] strArray = this.inputLine.Split(' ');
  383. this.inputLine = string.Empty;
  384. GUI.FocusControl(string.Empty);
  385. if (Convert.ToInt32(strArray[1]) == 0)
  386. {
  387. PhotonNetwork.networkingPeer.OpRaiseEvent(0xfe, null, true, RaiseEventOptions.Default);
  388. }
  389. else if (Convert.ToInt32(strArray[1]) > 0)
  390. {
  391. PhotonNetwork.networkingPeer.OpRaiseEvent(0xfe, null, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
  392. }
  393. return;
  394. }
  395. if (this.inputLine.StartsWith("/dgo"))
  396. {
  397. string[] strArray = this.inputLine.Split(' ');
  398. this.inputLine = string.Empty;
  399. GUI.FocusControl(string.Empty);
  400. if (Convert.ToInt32(strArray[1]) == 0)
  401. {
  402. Hashtable hash = new Hashtable();
  403. hash[(byte)0] = -1;
  404. PhotonNetwork.networkingPeer.OpRaiseEvent(0xcf, hash, true, null);
  405. }
  406. else if (Convert.ToInt32(strArray[1]) > 0)
  407. {
  408. Hashtable hash = new Hashtable();
  409. hash[(byte)0] = Convert.ToInt32(strArray[1]);
  410. PhotonNetwork.networkingPeer.OpRaiseEvent(0xcf, hash, true, null);
  411. }
  412. return;
  413. }
  414. if (this.inputLine.StartsWith("/ip"))
  415. {
  416. //Private
  417. }
  418. if (this.inputLine.StartsWith("/send"))
  419. {
  420. string[] strArray = inputLine.Split(' ');
  421. this.inputLine = string.Empty;
  422. GUI.FocusControl(string.Empty);
  423. Disconnect(Convert.ToInt32(strArray[1]));
  424. return;
  425. }
  426. if (this.inputLine.StartsWith("/maxps"))
  427. {
  428. RoomMaxPlayers(Convert.ToByte(inputLine.Remove(0, 7)));
  429. FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Max players is set to " + Convert.ToByte(this.inputLine.Remove(0, 7)) + ".</color></b>");
  430. this.inputLine = string.Empty;
  431. GUI.FocusControl(string.Empty);
  432. return;
  433. }
  434. if ((this.inputLine.Length <= 7) || (this.inputLine.Substring(0, 7) != "/kick #"))
  435. {
  436. object[] parameters = new object[] { "<color=#00ffff>" + this.inputLine + "</color>", "<color=#000000>Bahaa</color>" };
  437. FengGameManagerMKII.fgm.photonView.RPC("Chat", PhotonTargets.All, parameters);
  438. }
  439. else if (this.inputLine.Remove(0, 7) == PhotonNetwork.masterClient.ID.ToString())
  440. {
  441. this.addLINE("error:can't kick master client.");
  442. }
  443. else if (this.inputLine.Remove(0, 7) == PhotonNetwork.player.ID.ToString())
  444. {
  445. this.addLINE("error:can't kick yourself.");
  446. }
  447. else
  448. {
  449. bool flag = false;
  450. foreach (PhotonPlayer player in PhotonNetwork.playerList)
  451. {
  452. if (player.ID.ToString() == this.inputLine.Remove(0, 7))
  453. {
  454. flag = true;
  455. break;
  456. }
  457. }
  458. if (!flag)
  459. {
  460. this.addLINE("error:no such player.");
  461. }
  462. else
  463. {
  464. object[] objArray2 = new object[] { this.inputLine, LoginFengKAI.player.name };
  465. FengGameManagerMKII.fgm.photonView.RPC("Chat", PhotonTargets.All, objArray2);
  466. }
  467. }
  468. this.inputLine = string.Empty;
  469. GUI.FocusControl(string.Empty);
  470. return;
  471. }
  472. this.inputLine = "\t";
  473. GUI.FocusControl("ChatInput");
  474. }
  475. GUI.SetNextControlName(string.Empty);
  476. GUILayout.BeginArea(GuiRect);
  477. GUILayout.FlexibleSpace();
  478. string text = string.Empty;
  479. if (messages.Count < 15)
  480. {
  481. for (int i = 0; i < messages.Count; i++)
  482. {
  483. text = text + messages[i] + "\n";
  484. }
  485. }
  486. else
  487. {
  488. for (int j = messages.Count - 15; j < messages.Count; j++)
  489. {
  490. text = text + messages[j] + "\n";
  491. }
  492. }
  493. GUILayout.Label(text, new GUILayoutOption[0]);
  494. GUILayout.EndArea();
  495. GUILayout.BeginArea(GuiRect2);
  496. GUILayout.BeginHorizontal(new GUILayoutOption[0]);
  497. GUI.SetNextControlName("ChatInput");
  498. this.inputLine = GUILayout.TextField(this.inputLine, new GUILayoutOption[0]);
  499. GUILayout.EndHorizontal();
  500. GUILayout.EndArea();
  501. }
  502. }
  503.  
  504. public void setPosition()
  505. {
  506. if (this.AlignBottom)
  507. {
  508. GuiRect = new Rect(0f, (float) (Screen.height - 500), 300f, 470f);
  509. GuiRect2 = new Rect(30f, (float) ((Screen.height - 300) + 0x113), 300f, 25f);
  510. }
  511. }
  512.  
  513. public void Start()
  514. {
  515. this.setPosition();
  516. }
  517. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement