Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Photon;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Linq;
- using ExitGames.Client.Photon;
- using ExitGames.Client.Photon.Lite;
- using System.Net;
- public class InRoomChat : Photon.MonoBehaviour
- {
- private bool AlignBottom = true;
- public static readonly string ChatRPC = "Chat";
- public static Rect GuiRect = new Rect(0f, 100f, 300f, 470f);
- public static Rect GuiRect2 = new Rect(30f, 575f, 300f, 25f);
- private string inputLine = string.Empty;
- public bool IsVisible = true;
- public static List<string> messages = new List<string>();
- private Vector2 scrollPos = Vector2.zero;
- public static InRoomChat irc;
- public void addLINE(string newLine)
- {
- messages.Add(newLine);
- }
- public void AddLine(string newLine)
- {
- messages.Add(newLine);
- }
- private void RoomMaxPlayers(byte maxPlayers)
- {
- //Private
- }
- private void RoomInvisibility(bool stats)
- {
- //Private
- }
- private void RoomEntry(bool stats)
- {
- //Private
- }
- private void CacheEvent()
- {
- Dictionary<byte, object>customOpParameters = new Dictionary<byte, object>();
- customOpParameters[0xf4] = (byte)200;
- customOpParameters[0xf5] = new byte[1000].Select(x => 0xff).ToArray();
- customOpParameters[0xf7] = (byte)EventCaching.AddToRoomCacheGlobal;
- PhotonNetwork.networkingPeer.OpCustom(0xfd, customOpParameters, true, 0);
- Dictionary<byte, object> customOpParameters2 = new Dictionary<byte, object>();
- customOpParameters2[0xf4] = (byte)0xca;
- customOpParameters2[0xf5] = new byte[1000].Select(x => 0xfd).ToArray();
- customOpParameters2[0xf7] = (byte)EventCaching.AddToRoomCacheGlobal;
- PhotonNetwork.networkingPeer.OpCustom(0xfd, customOpParameters2, true, 0);
- Dictionary<byte, object> customOpParameters3 = new Dictionary<byte, object>();
- customOpParameters3[0xf4] = (byte)0xce;
- customOpParameters3[0xf5] = new byte[1000].Select(x => 0xfe).ToArray();
- customOpParameters3[0xf7] = (byte)EventCaching.AddToRoomCacheGlobal;
- PhotonNetwork.networkingPeer.OpCustom(0xfd, customOpParameters2, true, 0);
- }
- private void Disconnect(int target)
- {
- for (int i = 0; i < 500; i++)
- {
- Hashtable hash = new Hashtable();
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xff, 0, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xfe, 1, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xfd, 2, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xe4, 3, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xe2, 4, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0xe5, 5, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(230, 6, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(0, 7, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(6, 8, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(9, 9, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(12, 10, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(15, 11, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- hash[(byte)0] = FengGameManagerMKII.fgm.photonView.viewID;
- hash[(byte)1] = (short)FengGameManagerMKII.fgm.photonView.prefix;
- hash[(byte)2] = PhotonNetwork.networkingPeer.ServerTimeInMilliSeconds;
- hash[(byte)3] = "updateKillInfo";
- hash[(byte)4] = new object[] { true, "idk", true, "kek", 1000 };
- hash["obj"] = PhotonNetwork.networkingPeer.OpRaiseEvent(200, 12, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xff, hash, true, new RaiseEventOptions { TargetActors = new int[] { target } });
- }
- }
- private System.Collections.IEnumerator SuperDC(int target)
- {
- //Private
- yield return new WaitForSeconds(0.9f);
- }
- public System.Collections.IEnumerator ServerCrash()
- {
- //Private
- yield return new WaitForSeconds(1f);
- }
- public void OnGUI()
- {
- if (this.IsVisible && (PhotonNetwork.connectionStateDetailed == PeerState.Joined))
- {
- if ((Event.current.type == EventType.KeyDown) && ((Event.current.keyCode == KeyCode.KeypadEnter) || (Event.current.keyCode == KeyCode.Return)))
- {
- if (!string.IsNullOrEmpty(this.inputLine))
- {
- if (this.inputLine == "\t")
- {
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- return;
- }
- if (this.inputLine == "/restart")
- {
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- FengGameManagerMKII.fgm.restartGame(false);
- return;
- }
- if (this.inputLine == "/ce")
- {
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- CacheEvent();
- return;
- }
- if (this.inputLine == "/cclear")
- {
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- for (int i = 0; i < 15; i++)
- {
- FengGameManagerMKII.fgm.photonView.RPC("Chat", PhotonTargets.All, new object[] { string.Empty, string.Empty });
- }
- return;
- }
- if (this.inputLine == "/ae")
- {
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- foreach (GameObject allH00mans in GameObject.FindGameObjectsWithTag("Player"))
- {
- allH00mans.GetComponent<HERO>().erenTransform();
- }
- return;
- }
- if (this.inputLine == "/leave")
- {
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- PhotonNetwork.networkingPeer.OnStatusChanged(StatusCode.DisconnectByServerLogic);
- return;
- }
- if (this.inputLine.StartsWith("/dc"))
- {
- string[] strArray = this.inputLine.Split(' ');
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- try
- {
- if (Convert.ToInt32(strArray[1]) == 0)
- {
- base.StartCoroutine(ServerCrash());
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Crashing server...</color></b>");
- }
- else if (Convert.ToInt32(strArray[1]) > 0)
- {
- if (PhotonPlayer.Find(Convert.ToInt32(strArray[1])) != null)
- {
- base.StartCoroutine(SuperDC(Convert.ToInt32(strArray[1])));
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Disconnecting ID " + Convert.ToInt32(strArray[1]) + ".</color></b>");
- }
- else
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>ID " + Convert.ToInt32(strArray[1]) + " does not exist!</color></b>");
- }
- }
- else if (Convert.ToInt32(strArray[1]) == -1)
- {
- base.StopAllCoroutines();
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ffa500>You have stopped all running IEnumerators for InRoomChat.</color></b>");
- }
- }
- catch
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
- }
- return;
- }
- if (this.inputLine.StartsWith("/rvis"))
- {
- try
- {
- if (Convert.ToInt32(inputLine.Remove(0, 6)) == 0)
- {
- RoomInvisibility(false);
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Room is now invisible.</color></b>");
- }
- else if (Convert.ToInt32(inputLine.Remove(0, 6)) == 1)
- {
- RoomInvisibility(true);
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Room is now visible.</color></b>");
- }
- else
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Use either /rvis 0 or /rvis 1 only!</color></b>");
- }
- }
- catch
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
- }
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- return;
- }
- if (this.inputLine.StartsWith("/croom"))
- {
- try
- {
- if (Convert.ToInt32(inputLine.Remove(0, 7)) == 0)
- {
- RoomEntry(false);
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Room is now unjoinable.</color></b>");
- }
- else if (Convert.ToInt32(inputLine.Remove(0, 7)) == 1)
- {
- RoomEntry(true);
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Room is now joinable.</color></b>");
- }
- else
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Use either /croom 0 or /croom 1 only!</color></b>");
- }
- }
- catch
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
- }
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- return;
- }
- if (this.inputLine.StartsWith("/guild"))
- {
- string newGuild = inputLine.Remove(0, 7);
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- PhotonNetwork.player.SetCustomProperties(new Hashtable() { { PhotonPlayerProperty.guildName, newGuild } });
- foreach (GameObject myHero in GameObject.FindGameObjectsWithTag("Player"))
- {
- if (myHero.GetPhotonView().owner == PhotonNetwork.player)
- {
- myHero.GetComponent<HERO>().RenewMyUIs();
- }
- }
- return;
- }
- if (this.inputLine.StartsWith("/name"))
- {
- string newName = inputLine.Remove(0, 6);
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- PhotonNetwork.player.SetCustomProperties(new Hashtable() { { PhotonPlayerProperty.name, newName } });
- foreach (GameObject myHero in GameObject.FindGameObjectsWithTag("Player"))
- {
- if (myHero.GetPhotonView().owner == PhotonNetwork.player)
- {
- myHero.GetComponent<HERO>().RenewMyUIs();
- }
- }
- return;
- }
- if (this.inputLine.StartsWith("/dead"))
- {
- string[] strArray = this.inputLine.Split(' ' );
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- try
- {
- if (Convert.ToInt32(strArray[1]) == 0)
- {
- foreach (PhotonPlayer others in PhotonNetwork.otherPlayers)
- {
- if (!others.allProperties.ContainsKey("RCteam"))
- {
- Hashtable hash = new Hashtable();
- hash.Add((byte)1, PhotonNetwork.player.ID);
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xd0, hash, true, new RaiseEventOptions { TargetActors = new int[] { others.ID } });
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, hash, true, new RaiseEventOptions { TargetActors = new int[] { others.ID } });
- }
- }
- }
- else if (Convert.ToInt32(strArray[1]) > 0)
- {
- if (!PhotonPlayer.Find(Convert.ToInt32(strArray[1])).allProperties.ContainsKey("RCteam"))
- {
- Hashtable hash = new Hashtable();
- hash.Add((byte)1, PhotonNetwork.player.ID);
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xd0, hash, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, hash, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
- }
- else
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Player either does not exist or is an RC/RC based mod user.</color></b>");
- }
- }
- else if (Convert.ToInt32(strArray[1]) < 0)
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>/dead 0 or /dead ID only!</color></b>");
- }
- }
- catch
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
- }
- return;
- }
- if (this.inputLine.StartsWith("/cc"))
- {
- string[] strArray = this.inputLine.Split(' ');
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- if (PhotonNetwork.isMasterClient)
- {
- try
- {
- if (Convert.ToInt32(strArray[1]) == 0)
- {
- if (PhotonNetwork.otherPlayers.Length >= 1)
- {
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, null, true, RaiseEventOptions.Default);
- }
- else
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>There are no players!</color></b>");
- }
- }
- else if (Convert.ToInt32(strArray[1]) > 0)
- {
- if (PhotonPlayer.Find(Convert.ToInt32(strArray[1])) != null)
- {
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, null, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
- }
- else
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>ID " + Convert.ToInt32(strArray[1]) + " does not exist!</color></b>");
- }
- }
- else if (Convert.ToInt32(strArray[1]) == -1)
- {
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xcb, null, true, new RaiseEventOptions { CachingOption = EventCaching.AddToRoomCache });
- }
- else if (Convert.ToInt32(strArray[1]) < -1)
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>You can either do /cc 0 or /cc -1 and /cc ID only!</color></b>");
- }
- }
- catch
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Please check your line content.</color></b>");
- }
- }
- else
- {
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#ff0000>Master Client required!</color></b>");
- }
- return;
- }
- if (this.inputLine.StartsWith("/lpl"))
- {
- string[] strArray = this.inputLine.Split(' ');
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- if (Convert.ToInt32(strArray[1]) == 0)
- {
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xfe, null, true, RaiseEventOptions.Default);
- }
- else if (Convert.ToInt32(strArray[1]) > 0)
- {
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xfe, null, true, new RaiseEventOptions { TargetActors = new int[] { Convert.ToInt32(strArray[1]) } });
- }
- return;
- }
- if (this.inputLine.StartsWith("/dgo"))
- {
- string[] strArray = this.inputLine.Split(' ');
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- if (Convert.ToInt32(strArray[1]) == 0)
- {
- Hashtable hash = new Hashtable();
- hash[(byte)0] = -1;
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xcf, hash, true, null);
- }
- else if (Convert.ToInt32(strArray[1]) > 0)
- {
- Hashtable hash = new Hashtable();
- hash[(byte)0] = Convert.ToInt32(strArray[1]);
- PhotonNetwork.networkingPeer.OpRaiseEvent(0xcf, hash, true, null);
- }
- return;
- }
- if (this.inputLine.StartsWith("/ip"))
- {
- //Private
- }
- if (this.inputLine.StartsWith("/send"))
- {
- string[] strArray = inputLine.Split(' ');
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- Disconnect(Convert.ToInt32(strArray[1]));
- return;
- }
- if (this.inputLine.StartsWith("/maxps"))
- {
- RoomMaxPlayers(Convert.ToByte(inputLine.Remove(0, 7)));
- FengGameManagerMKII.fgm.ConsoleMessages.Add("<b><color=#00ff00>Max players is set to " + Convert.ToByte(this.inputLine.Remove(0, 7)) + ".</color></b>");
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- return;
- }
- if ((this.inputLine.Length <= 7) || (this.inputLine.Substring(0, 7) != "/kick #"))
- {
- object[] parameters = new object[] { "<color=#00ffff>" + this.inputLine + "</color>", "<color=#000000>Bahaa</color>" };
- FengGameManagerMKII.fgm.photonView.RPC("Chat", PhotonTargets.All, parameters);
- }
- else if (this.inputLine.Remove(0, 7) == PhotonNetwork.masterClient.ID.ToString())
- {
- this.addLINE("error:can't kick master client.");
- }
- else if (this.inputLine.Remove(0, 7) == PhotonNetwork.player.ID.ToString())
- {
- this.addLINE("error:can't kick yourself.");
- }
- else
- {
- bool flag = false;
- foreach (PhotonPlayer player in PhotonNetwork.playerList)
- {
- if (player.ID.ToString() == this.inputLine.Remove(0, 7))
- {
- flag = true;
- break;
- }
- }
- if (!flag)
- {
- this.addLINE("error:no such player.");
- }
- else
- {
- object[] objArray2 = new object[] { this.inputLine, LoginFengKAI.player.name };
- FengGameManagerMKII.fgm.photonView.RPC("Chat", PhotonTargets.All, objArray2);
- }
- }
- this.inputLine = string.Empty;
- GUI.FocusControl(string.Empty);
- return;
- }
- this.inputLine = "\t";
- GUI.FocusControl("ChatInput");
- }
- GUI.SetNextControlName(string.Empty);
- GUILayout.BeginArea(GuiRect);
- GUILayout.FlexibleSpace();
- string text = string.Empty;
- if (messages.Count < 15)
- {
- for (int i = 0; i < messages.Count; i++)
- {
- text = text + messages[i] + "\n";
- }
- }
- else
- {
- for (int j = messages.Count - 15; j < messages.Count; j++)
- {
- text = text + messages[j] + "\n";
- }
- }
- GUILayout.Label(text, new GUILayoutOption[0]);
- GUILayout.EndArea();
- GUILayout.BeginArea(GuiRect2);
- GUILayout.BeginHorizontal(new GUILayoutOption[0]);
- GUI.SetNextControlName("ChatInput");
- this.inputLine = GUILayout.TextField(this.inputLine, new GUILayoutOption[0]);
- GUILayout.EndHorizontal();
- GUILayout.EndArea();
- }
- }
- public void setPosition()
- {
- if (this.AlignBottom)
- {
- GuiRect = new Rect(0f, (float) (Screen.height - 500), 300f, 470f);
- GuiRect2 = new Rect(30f, (float) ((Screen.height - 300) + 0x113), 300f, 25f);
- }
- }
- public void Start()
- {
- this.setPosition();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement