Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void OnSubmit ()
- {
- string text = UIInput.current.value;
- text = NGUIText.StripSymbols(text);
- if (!string.IsNullOrEmpty(text))
- {
- mHistory.Remove(text);
- mHistory.Insert(0, text);
- if (mHistory.size > 10) mHistory.RemoveAt(10);
- mLast = -1;
- if (text[0] == '/')
- {
- text = text.Substring(1);
- string[] split = text.Split(new char[] { ' ' }, 2, System.StringSplitOptions.RemoveEmptyEntries);
- if (split.Length == 2 && TwoPartCommand(split))
- {
- // Done, it's handled
- }
- else if (text == "who")
- {
- UIWindow.Show(GameWindows.instance.playerList);
- }
- else if (text == "note" || text == "setNote")
- {
- TNManager.SetPlayerData("note", null);
- AddCurrent(Localization.Get("Player note cleared"), Color.yellow);
- }
- else if (text == "ver" || text == "version")
- {
- AddCurrent(Game.FormatVersion(Game.version), Color.yellow);
- }
- else if (text == "played")
- {
- var span = new System.TimeSpan(0, 0, (int)TNManager.playedTime);
- AddCurrent(span.ToString(), Color.yellow);
- }
- else if (text == "stuck")
- {
- var vehicle = ControllableEntity.controlled as Vehicle;
- if (vehicle != null) vehicle.GetUnstuck();
- }
- else if (text == "admin")
- {
- TNManager.SetAdmin(Game.adminKey);
- }
- else if (text == "resetChat")
- {
- Resize(500, 212);
- }
- else if (text == "quit" || text == "exit")
- {
- Application.Quit();
- }
- else if (text == "fps")
- {
- UIFPSCounter.Toggle();
- }
- else if (text == "ping")
- {
- AddCurrent(TNManager.ping + " ms", Color.yellow);
- }
- else if (text == "leaveFaction")
- {
- GameFaction.Leave();
- }
- else if (text == "scenic")
- {
- Game.scenicMode = !Game.scenicMode;
- }
- else if (TNManager.isAdmin && text == "reloadServerData")
- {
- TNManager.BeginSend(Packet.RequestReloadServerConfig);
- TNManager.EndSend();
- }
- else if (text == "relocalize" || text == "reloc")
- {
- Localization.Reload();
- }
- else if (text == "startCoup")
- {
- var fac = GameFaction.mine;
- if (fac != null && !fac.isOwner) fac.StartCoup();
- }
- else if (text == "res" && GameOptions.creativeMode)
- {
- if (ControllableEntity.mine != null)
- {
- var resources = new List<ExtractableResource>();
- var pos = FloatingOrigin.positionOffset + ControllableEntity.mine.trans.position;
- if (ResourceNode.Collect(pos.x, pos.z, resources) > 0)
- {
- text = Localization.Get(resources[0].name);
- for (int i = 1; i < resources.size; ++i)
- text += ", " + Localization.Get(resources[i].name);
- UIGameChat.AddCurrent("Resources nearby: " + text);
- }
- else UIGameChat.AddCurrent("No resources nearby");
- }
- }
- else if (text == "biomes" && GameOptions.creativeMode && ProceduralTerrain.sampleFunc != null)
- {
- var worldPos = FloatingOrigin.truePosition;
- float height, shoreFactor, temperature, precipitation;
- BiomeContributions contributions;
- ProceduralTerrain.sampleFunc(worldPos.x, worldPos.z, out height, out shoreFactor, out temperature, out precipitation, out contributions);
- AddCurrent("Position: " + worldPos, Color.yellow);
- if (contributions.biome0.contribution > 0f) AddCurrent("1. " + contributions.biome0.biome.name + " = " + contributions.biome0.contribution, Color.yellow);
- if (contributions.biome1.contribution > 0f) AddCurrent("2. " + contributions.biome1.biome.name + " = " + contributions.biome1.contribution, Color.yellow);
- if (contributions.biome2.contribution > 0f) AddCurrent("3. " + contributions.biome2.biome.name + " = " + contributions.biome2.contribution, Color.yellow);
- if (contributions.biome3.contribution > 0f) AddCurrent("4. " + contributions.biome3.biome.name + " = " + contributions.biome3.contribution, Color.yellow);
- if (contributions.biome4.contribution > 0f) AddCurrent("5. " + contributions.biome4.biome.name + " = " + contributions.biome4.contribution, Color.yellow);
- if (contributions.biome5.contribution > 0f) AddCurrent("6. " + contributions.biome5.biome.name + " = " + contributions.biome5.contribution, Color.yellow);
- if (contributions.biome6.contribution > 0f) AddCurrent("7. " + contributions.biome6.biome.name + " = " + contributions.biome6.contribution, Color.yellow);
- if (contributions.biome7.contribution > 0f) AddCurrent("8. " + contributions.biome7.biome.name + " = " + contributions.biome7.contribution, Color.yellow);
- else
- {
- bool handled = false;
- if (onCommand != null) onCommand(text, ref handled);
- if (!handled) Error("Invalid command");
- }
- }
- else
- {
- mLastPrefix = "";
- GameChat.Send(text, MessageType.Local);
- }
- UIInput.current.value = "";
- }
- UIInput.current.isSelected = false;
- }
- /// <summary>
- /// Chat command made up of two components.
- /// </summary>
- protected bool TwoPartCommand (string[] split)
- {
- string left = split[0].Trim();
- string right = split[1].Trim();
- if (left == "w" || left == "a" || left == "all" || left == "world" || left == "global")
- {
- mLastPrefix = "/world ";
- GameChat.Send(split[1], MessageType.World);
- }
- else if (left == "f" || left == "faction" || left == "t" || left == "team")
- {
- mLastPrefix = "/faction ";
- GameChat.Send(split[1], MessageType.Faction);
- }
- else if (left == "g" || left == "group")
- {
- mLastPrefix = "/group ";
- GameChat.Send(split[1], MessageType.Group);
- }
- else if (left == "mark" || left == "marker")
- {
- var fac = GameFaction.mine;
- if (fac != null)
- {
- var pos = FloatingOrigin.truePosition;
- if (!fac.AddMarker(new Vector2D(pos.x, pos.z), right))
- {
- var text = Localization.Get("markerErr");
- UIStatusBar.ShowError(text);
- AddCurrent(text, Color.yellow);
- }
- }
- else AddCurrent(Localization.Get("factionReq"), Color.yellow);
- }
- else if (left == "motd" && TNManager.isAdmin)
- {
- TNManager.SetServerData("motd", right);
- }
- else if (left == "spin" && GameCamera.instance != null)
- {
- float amount = 0f;
- float.TryParse(right, out amount);
- GameCamera.instance.passiveSpin = amount;
- }
- else if (left == "note" || left == "setNote")
- {
- if (right == "null")
- {
- TNManager.SetPlayerData("note", null);
- AddCurrent(Localization.Get("Player note cleared"), Color.yellow);
- }
- else
- {
- if (right.Length > 40) right = right.Substring(0, 40);
- TNManager.SetPlayerData("note", right);
- AddCurrent(Localization.Format("Player note set", right), Color.yellow);
- }
- }
- else if (left == "rename" && TNManager.isAdmin)
- {
- var parts = right.Split(':');
- if (parts.Length == 2)
- {
- var player = TNManager.FindPlayer(parts[0].Trim());
- if (player != null) GameChat.ChangePlayerName(player, parts[1].Trim());
- else AddCurrent(Localization.Get("Player not found"), Color.yellow);
- }
- else AddCurrent("/rename Current Name: NewName", Color.yellow);
- }
- else if (left == "goto" && GameOptions.creativeMode)
- {
- split = right.Split(' ');
- if (split.Length == 2)
- {
- var v = new Vector3D(0.0, 20.0, 0.0);
- if (double.TryParse(split[0], out v.x) && double.TryParse(split[1], out v.z))
- {
- v.x = Game.MetersToUnits(v.x);
- v.z = Game.MetersToUnits(v.z);
- ControllableEntity.TeleportTo(v);
- }
- }
- else if (split.Length == 1)
- {
- var player = TNManager.FindPlayer(right);
- if (player != null) ControllableEntity.TeleportTo(player.Get<Vector3D>("pos"));
- }
- }
- else if (left == "time" && GameOptions.creativeMode)
- {
- float f;
- var sky = TOD_Sky.instance;
- if (float.TryParse(right, out f))
- {
- sky.GetComponent<TOD_Time>().ProgressTime = false;
- sky.Cycle.Hour = f;
- }
- else sky.GetComponent<TOD_Time>().ProgressTime = true;
- }
- else if (left == "rain" && GameOptions.creativeMode)
- {
- var weather = FindObjectOfType<Weather>();
- weather.allowRain = (right == "on");
- }
- else if (TNManager.isAdmin && left == "addFlag")
- {
- var bytes = ResourceLoader.Upload("Flags/" + right + ".png");
- if (bytes != null)
- {
- UIGameChat.AddCurrent("Uploaded " + right + " (" + bytes.Length.ToString("N0") + " bytes)", Color.yellow);
- }
- else UIGameChat.AddCurrent("Unable to find " + right, Color.yellow);
- }
- else if (TNManager.isAdmin && left == "upload")
- {
- var bytes = ResourceLoader.Upload(right);
- if (bytes != null)
- {
- UIGameChat.AddCurrent("Uploaded " + right + " (" + bytes.Length.ToString("N0") + " bytes)", Color.yellow);
- }
- else UIGameChat.AddCurrent("Unable to find " + right, Color.yellow);
- }
- else if (TNManager.isAdmin && left == "setServer")
- {
- TNManager.SetServerData(right);
- }
- else if (TNManager.isAdmin && (left == "addFilter" || left == "filter"))
- {
- TNManager.SetServerData("Filter/" + right);
- }
- else if (TNManager.isAdmin && left == "removeFilter")
- {
- TNManager.SetServerData("Filter/" + right + " = null");
- }
- else if (TNManager.isAdmin && left == "removeServer")
- {
- TNManager.SetServerData(right, null);
- UIGameChat.AddCurrent("Removed " + right, Color.yellow);
- }
- else if (TNManager.isAdmin && left == "allowMod")
- {
- if (ModManager.AllowMod(right))
- {
- UIGameChat.AddCurrent("The mod [ " + right + " ] is now allowed on the server.", Color.yellow);
- }
- else UIGameChat.AddCurrent("The mod [ " + right + " ] must be active in order to allow it.", Color.yellow);
- }
- else if (TNManager.isAdmin && left == "disallowMod")
- {
- if (ModManager.DisallowMod(right))
- {
- UIGameChat.AddCurrent("The mod [ " + right + " ] is no longer allowed on the server.", Color.yellow);
- }
- else UIGameChat.AddCurrent("The mod [ " + right + " ] is not in the allowed list.", Color.yellow);
- }
- else if (left == "addAdmin" && TNManager.isAdmin)
- {
- TNManager.AddAdmin(right);
- }
- else if (left == "removeAdmin" && TNManager.isAdmin)
- {
- TNManager.RemoveAdmin(right);
- }
- else if (GameOptions.creativeMode && left == "add")
- {
- var twoParts = right.Split(' ');
- if (twoParts.Length == 2)
- {
- double amount;
- if (double.TryParse(twoParts[1], out amount) && amount > 0.0 && Compound.Get(twoParts[0]) != null)
- {
- var v = ControllableEntity.mine;
- if (v != null && v.inventory != null)
- {
- v.inventory.AddItem(new InventoryItem(twoParts[0], amount));
- }
- }
- }
- }
- else if (left == "exe" && GameServerConfig.runTimeCode && GameOptions.creativeMode)
- {
- right = right.Replace("Debug.Log(", "UIGameChat.AddCurrent(");
- right = right.Replace("print(", "UIGameChat.AddCurrent(");
- AddCurrent("[i]Result:[/i] " + RuntimeCode.Execute(right));
- }
- else if (left == "exeFile" && GameServerConfig.runTimeCode && GameOptions.creativeMode)
- {
- AddCurrent("[i]Result:[/i] " + RuntimeCode.ExecuteFile(right));
- }
- else if (left == "ignore")
- {
- if (mIgnore.Contains(right)) Unignore(right);
- else Ignore(right);
- }
- else if (left == "r" || left == "reply")
- {
- if (!string.IsNullOrEmpty(GameChat.lastPlayerPM))
- {
- GameChat.Send(right, GameChat.lastPlayerPM);
- GameTools.ReplaceLinks(ref right);
- var text = Localization.Format("Chat To", GameChat.lastPlayerPM, right);
- for (int i = 0; i < UIChatFilterTab.list.Count; ++i)
- {
- UIChatFilterTab tab = UIChatFilterTab.list[i];
- if (tab.privateChat || tab.isActive) tab.Add(text, pmColor);
- }
- }
- //else NGUITools.PlaySound(GameAudio.instance.error);
- }
- else if (left == "pm" || left == "w" || left == "whisper")
- {
- split = right.Split(new char[] { ':' }, 2, System.StringSplitOptions.RemoveEmptyEntries);
- if (split.Length == 2)
- {
- GameChat.Send(split[1], split[0]);
- GameTools.ReplaceLinks(ref split[1]);
- var text = Localization.Format("Chat To", split[0], split[1]);
- for (int i = 0; i < UIChatFilterTab.list.Count; ++i)
- {
- UIChatFilterTab tab = UIChatFilterTab.list[i];
- if (tab.privateChat || tab.isActive) tab.Add(text, pmColor);
- }
- }
- else Error("Invalid command");
- }
- else if (left == "world" || left == "w" || left == "f" || left == "faction") { }
- else if (left == "get")
- {
- right = right.Replace("\\", "/");
- DataNode node = TNManager.GetServerData(right);
- if (node == null)
- {
- UIGameChat.AddCurrent("No such option", Color.yellow);
- }
- else
- {
- string[] lines = node.ToString().Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
- foreach (string s in lines)
- {
- if (s.StartsWith("\t\t")) continue;
- UIGameChat.AddCurrent(s.Replace("\t", " "), Color.yellow);
- }
- }
- }
- else if (left == "setName")
- {
- var vehicle = ControllableEntity.mine;
- if (vehicle != null && vehicle.isControlledByMe) vehicle.Set("name", right);
- }
- else if (left == "createFaction")
- {
- if (GameFaction.mine != null)
- {
- AddCurrent(Localization.Get("FacInvite6"), Color.yellow);
- }
- else
- {
- var fac = GameFaction.Find(right);
- if (fac != null) AddCurrent(Localization.Get("FacInvite5"), Color.yellow);
- else GameFaction.Create(right);
- }
- }
- else if (left == "inviteFaction")
- {
- var myFac = GameFaction.mine;
- if (myFac == null || !myFac.isOfficer)
- {
- AddCurrent(Localization.Get("FacInvite3"), Color.yellow);
- }
- else
- {
- var target = TNManager.FindPlayer(right);
- if (target == null)
- {
- AddCurrent(Localization.Get("FacInvite8"), Color.yellow);
- }
- else
- {
- var existing = GameFaction.Find(target);
- if (existing == null)
- {
- myFac.Invite(target.name);
- AddCurrent(Localization.Format("FacInvite2", target.name, myFac.name), Color.yellow);
- }
- else AddCurrent(Localization.Format("FacInvite16", target.name, existing.name, myFac.name), Color.yellow);
- }
- }
- }
- else if (left == "kickFaction" || (!TNManager.isAdmin && left == "kick"))
- {
- var myFac = GameFaction.mine;
- if (myFac == null || !myFac.Kick(right)) AddCurrent(Localization.Get("GenericErr"), Color.yellow);
- }
- else if (left == "renameFaction")
- {
- if (right.Contains("="))
- {
- if (TNManager.isAdmin)
- {
- var parts = right.Split('=');
- if (parts.Length == 2)
- {
- var fac = GameFaction.Find(parts[0], true);
- if (fac != null) fac.Rename(parts[1]);
- }
- }
- }
- else
- {
- var myFac = GameFaction.mine;
- var s = right.Trim();
- if (myFac == null || !myFac.isOwner)
- {
- AddCurrent(Localization.Get("FacInvite3"), Color.yellow);
- }
- else if (string.IsNullOrEmpty(s) || GameFaction.Find(s) != null)
- {
- AddCurrent(Localization.Get("FacInvite5"), Color.yellow);
- }
- else myFac.Rename(s);
- }
- }
- else if (left == "promote")
- {
- var myFac = GameFaction.mine;
- if (myFac == null || !myFac.Promote(right)) AddCurrent(Localization.Get("GenericErr"), Color.yellow);
- }
- else if (left == "demote")
- {
- var myFac = GameFaction.mine;
- if (myFac == null || !myFac.Demote(right)) AddCurrent(Localization.Get("GenericErr"), Color.yellow);
- }
- else if (left == "war")
- {
- if (MyPlayer.faction != null)
- {
- var other = GameFaction.Find(right);
- if (other == null)
- {
- other = GameFaction.Find(right, true);
- if (other != null) AddCurrent(Localization.Format("War5", other.name), Color.yellow);
- else AddCurrent(Localization.Get("War4"), Color.yellow);
- }
- else if (MyPlayer.faction.HasDeclaredWarOn(other.uid))
- {
- other.MakePeace();
- }
- else other.DeclareWar();
- }
- else UIGameChat.AddCurrent(Localization.Get("War3"), Color.yellow);
- }
- else if (left == "war2")
- {
- if (MyPlayer.faction != null)
- {
- var other = GameFaction.Find(right, true);
- if (other == null)
- {
- AddCurrent(Localization.Get("War4"), Color.yellow);
- }
- else if (MyPlayer.faction.HasDeclaredWarOn(other.uid))
- {
- other.MakePeace();
- }
- else other.DeclareWar();
- }
- else UIGameChat.AddCurrent(Localization.Get("War3"), Color.yellow);
- }
- else if (left == "ally" || left == "alliance")
- {
- var myFac = GameFaction.mine;
- if (myFac != null && myFac.isOwner)
- {
- var other = GameFaction.Find(right);
- if (other == null)
- {
- other = GameFaction.Find(right, true);
- if (other != null) UIGameChat.AddCurrent(Localization.Format("Ally5", other.name), Color.yellow);
- else UIGameChat.AddCurrent(Localization.Get("War4"), Color.yellow);
- }
- else myFac.SetAlly(other, !MyPlayer.faction.IsAlliedWith(other.uid));
- }
- else UIGameChat.AddCurrent(Localization.Get("War3"), Color.yellow);
- }
- else if (left == "ally2")
- {
- var myFac = GameFaction.mine;
- if (myFac != null && myFac.isOwner)
- {
- var other = GameFaction.Find(right, true);
- if (other == null) UIGameChat.AddCurrent(Localization.Get("War4"), Color.yellow);
- else MyPlayer.faction.SetAlly(other, !MyPlayer.faction.IsAlliedWith(other.uid));
- }
- else UIGameChat.AddCurrent(Localization.Get("War3"), Color.yellow);
- }
- else if (TNManager.isAdmin && left == "kick")
- {
- var player = TNManager.FindPlayer(right);
- var writer = TNManager.BeginSend(Packet.RequestKick);
- writer.Write(-1);
- if (player != null)
- {
- writer.Write(player.id);
- TNManager.EndSend();
- AddCurrent("Kicking [" + player.name + "]", Color.yellow);
- }
- else
- {
- writer.Write(0);
- writer.Write(right);
- TNManager.EndSend();
- AddCurrent("Kicking " + right, Color.yellow);
- }
- }
- else if (TNManager.isAdmin && left == "ban")
- {
- var player = TNManager.FindPlayer(right);
- var writer = TNManager.BeginSend(Packet.RequestBan);
- if (player != null)
- {
- writer.Write(0);
- writer.Write(player.name);
- TNManager.EndSend();
- writer = TNManager.BeginSend(Packet.RequestBan);
- writer.Write(player.id);
- TNManager.EndSend();
- AddCurrent("Banning [" + player.name + "]", Color.yellow);
- }
- else
- {
- writer.Write(0);
- writer.Write(right);
- TNManager.EndSend();
- AddCurrent("Banning " + right, Color.yellow);
- }
- }
- else if (TNManager.isAdmin && left == "unban")
- {
- TNManager.BeginSend(Packet.RequestUnban).Write(right);
- TNManager.EndSend();
- AddCurrent("Unbanning " + right, Color.yellow);
- }
- else return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment