/MJS/Interpreter.cs
C# | 2141 lines | 2044 code | 32 blank | 65 comment | 971 complexity | f7e3658119489266f7486ea9b28e6730 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /* This source file is originally written by Jesbus
- * and may be used in other software and edited
- * freely as long as you put Jesbus's name in the
- * credits of the compilation and as long as this
- * comment remains fully intact.
- *
- * The MJS interpreter is currently used for
- * command and event scripting in MCRevive
- * (Minecraft Classic server software).
- */
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading;
- namespace MJS
- {
- public static class XMath
- {
- public static double Parse(string input)
- {
- ExpressionParser MathParser = new ExpressionParser();
- Hashtable MathParseHashes = new Hashtable();
- return MathParser.Parse(input, MathParseHashes);
- }
- public static double Pythagoras(double a, double b)
- {
- a = Math.Abs(a);
- b = Math.Abs(b);
- return Math.Sqrt(a * a + b * b);
- }
- public static double Pythagoras(double a, double b, double c)
- {
- return Pythagoras(a, Pythagoras(b, c));
- }
- public static double Max(double a, double b, double c)
- {
- return Math.Max(a, Math.Max(b, c));
- }
- public static double Max(double a, double b, double c, double d)
- {
- return Math.Max(Math.Max(a, b), Math.Max(c, d));
- }
- }
- public static class Script
- {
- public static List<Thread> ScriptThreads = new List<Thread>();
- public static void Execute(string file, string arguments, bool deleteWhenFinished = false)
- {
- if (!File.Exists(file)) { Events.Log("Script file " + file + " does not exist."); return; }
- Thread scriptThread = new Thread(new ThreadStart(delegate
- {
- string[] lines = File.ReadAllLines(file);
- string[] blocks = new string[255];
- string[] numberVarNames = new string[255];
- double[] numberVars = new double[255];
- int numberVarCount = 0;
- string[] stringVarNames = new string[255];
- string[] stringVars = new string[255];
- int stringVarCount = 0;
- string[] mapVarNames = new string[255];
- Map[] mapVars = new Map[255];
- int mapVarCount = 0;
- string[] playerVarNames = new string[255];
- Player[] playerVars = new Player[255];
- int playerVarCount = 0;
- int i = 0;
- int j = 0;
- double parseTryer;
- #region CREATE ARGUMENT VARIABLES
- string varType = "";
- string varName = "";
- string varValue = "";
- foreach (string argPart in arguments.Split(' '))
- {
- if (i % 3 == 0) varType = argPart;
- else if (i % 3 == 1) varName = argPart.Remove(0, 1);
- else
- {
- varValue = argPart.Replace("[space]", " ");
- if (varType == "number")
- {
- if (!System.Double.TryParse(varValue, out parseTryer))
- {
- Events.Log("Could not execute script " + file + ": argument \"" + varType + " $" + varName + " " + varValue + "\" contains an error.");
- goto stopScript;
- }
- numberVars[numberVarCount] = parseTryer;
- numberVarNames[numberVarCount] = varName;
- numberVarCount++;
- }
- else if (varType == "string")
- {
- stringVarNames[stringVarCount] = varName;
- stringVars[stringVarCount] = varValue;
- stringVarCount++;
- }
- else if (varType == "map")
- {
- mapVars[mapVarCount] = Map.Find(varValue);
- if (mapVars[mapVarCount] == null)
- {
- Events.Log("Could not execute script " + file + ": no map called " + varValue + " is loaded.");
- goto stopScript;
- }
- mapVarNames[mapVarCount] = varName;
- mapVarCount++;
- }
- else if (varType == "player")
- {
- //Server.s.Log(varName + "=" + varValue);
- playerVars[playerVarCount] = Player.Find(varValue);
- if (playerVars[playerVarCount] == null)
- {
- Events.Log("Could not execute script " + file + ": no player called " + varValue + " is connected.");
- goto stopScript;
- }
- //Events.Log("player:" + playerVars[playerVarCount].name);
- mapVars[mapVarCount] = playerVars[playerVarCount].map;
- mapVarNames[mapVarCount] = varName + ".$map";
- mapVarCount++;
- playerVarNames[playerVarCount] = varName;
- playerVarCount++;
- }
- else
- {
- Events.Log("Could not execute script " + file + ": Variable type " + varType + " does not exist in MCfresh.");
- goto stopScript;
- }
- }
- i++;
- }
- #endregion
- int curBlock = 0;
- string[] block_type = new string[255];
- bool[] block_skipping = new bool[255];
- bool[] block_executeElse = new bool[255];
- int[] block_inBlockCount = new int[255];
- int[] block_repeatCurBlock = new int[255];
- int[] block_repeatStartLine = new int[255];
- block_type[0] = "main";
- block_skipping[0] = false;
- block_executeElse[0] = false;
- bool writingTempThreadFile = false;
- int blocksInThreadCount = 0;
- StreamWriter tempThreadFileWriter = null;
- string tempThreadFileName = "";
- bool ifNot = false;
- bool inTryBlock = false;
- bool skipToCatch = false;
- bool executeCatch = false;
- int catch_inBlockCount = 0;
- int tryCurBlock = 0;
- int lineNum = 0;
- string lineError;
- bool fatalError;
- while (lineNum < lines.Length)
- {
- try
- {
- lineError = "";
- fatalError = false;
- ifNot = false;
- string line = lines[lineNum].Trim();
- if (line.StartsWith("//") || line.StartsWith("#") || line.StartsWith("'")) goto nextLine; // So peoplezz can adzz commentzz
- #region BLOCK HANDLING
- if (writingTempThreadFile)
- {
- if (line == "{") { blocksInThreadCount++; tempThreadFileWriter.WriteLine(line); }
- else if (line == "}" && blocksInThreadCount != 0) { blocksInThreadCount--; tempThreadFileWriter.WriteLine(line); }
- else if (line == "}")
- {
- tempThreadFileWriter.Flush();
- tempThreadFileWriter.Close();
- writingTempThreadFile = false;
- curBlock--;
- Execute(tempThreadFileName, "", true);
- }
- else { tempThreadFileWriter.WriteLine(line); }
- goto nextLine;
- }
- if (skipToCatch)
- {
- if (line.ToLower() == "catch") { skipToCatch = false; executeCatch = true; }
- goto nextLine;
- }
- if (block_type[curBlock] == "catch" && !executeCatch)
- {
- if (line == "{") catch_inBlockCount++;
- else if (line == "}" && catch_inBlockCount != 0) catch_inBlockCount--;
- else if (line == "}")
- {
- executeCatch = false;
- block_type[curBlock] = null;
- curBlock--;
- }
- goto nextLine;
- }
- if (curBlock != 0)
- {
- if (block_skipping[curBlock - 1])
- {
- if (line == "{") block_inBlockCount[curBlock]++;
- else if (line == "}" && block_inBlockCount[curBlock] != 0)
- {
- block_inBlockCount[curBlock]--;
- }
- else if (line == "}")
- {
- block_skipping[curBlock - 1] = false;
- curBlock--;
- }
- goto nextLine;
- }
- }
- if (line.ToLower() == "else")
- {
- block_type[curBlock + 1] = "else";
- goto nextLine;
- }
- if (line == "{")
- {
- curBlock++;
- if (block_type[curBlock] == "if")
- {
- if (block_executeElse[curBlock - 1])
- {
- block_skipping[curBlock - 1] = true;
- block_inBlockCount[curBlock] = 0;
- }
- else
- {
- block_skipping[curBlock - 1] = false;
- }
- }
- else if (block_type[curBlock] == "else")
- {
- if (!block_executeElse[curBlock - 1])
- {
- block_skipping[curBlock - 1] = true;
- block_inBlockCount[curBlock] = 0;
- }
- else
- {
- block_skipping[curBlock - 1] = false;
- }
- }
- else if (block_type[curBlock] == "repeat")
- {
- block_repeatCurBlock[curBlock - 1] = curBlock - 1;
- block_repeatStartLine[curBlock - 1] = lineNum - 1;
- block_skipping[curBlock - 1] = false;
- block_inBlockCount[curBlock - 1] = 0;
- }
- else if (block_type[curBlock] == "thread")
- {
- i = 0;
- while (File.Exists("mjs/threads/temp" + i + ".mjs"))
- {
- i++;
- }
- tempThreadFileWriter = new StreamWriter(File.Create("mjs/threads/temp" + i + ".mjs"));
- tempThreadFileName = "mjs/threads/temp" + i + ".mjs";
- writingTempThreadFile = true;
- }
- goto nextLine;
- }
- if (line == "}")
- {
- if (block_type[curBlock] == "repeat")
- {
- lineNum = block_repeatStartLine[curBlock];
- curBlock--;
- goto nextLine;
- }
- else
- {
- if (block_type[curBlock] == "try") inTryBlock = false;
- block_inBlockCount[curBlock] = 0;
- block_type[curBlock] = null;
- block_executeElse[curBlock] = false;
- block_skipping[curBlock] = false;
- }
- curBlock--;
- goto nextLine;
- }
- if (line.ToLower() == "exit")
- {
- lineNum = lines.Length;
- goto stopScript;
- }
- string[] lineParts = line.Split(' ');
- if (lineParts.Length != 1)
- {
- if (lineParts[1] == "not")
- {
- ifNot = true;
- i = 1;
- while (i < lineParts.Length)
- {
- i++;
- if (i < lineParts.Length) lineParts[i - 1] = lineParts[i];
- }
- }
- }
- #endregion
- #region GROUP THE REMAINS OF STRINGS THAT WERE SPLIT APART INTO ONE ELEMENT OF lineParts
- i = 0;
- bool inString = false;
- int linePartStringStart = 0;
- int nulls = 0;
- while (i < lineParts.Length)
- {
- if (!inString && lineParts[i].StartsWith("\"") && !lineParts[i].EndsWith("\""))
- {
- lineParts[i] += " ";
- inString = true;
- linePartStringStart = i;
- }
- else if (inString)
- {
- if (lineParts[i].EndsWith("\""))
- {
- lineParts[linePartStringStart] += lineParts[i];
- inString = false;
- }
- else lineParts[linePartStringStart] += lineParts[i] + " ";
- lineParts[i] = null;
- nulls++;
- }
- i++;
- }
- /// REMOVE ALL NULL VALUES FROM lineParts:
- string[] newLineParts = new string[lineParts.Length - nulls];
- i = 0;
- j = 0;
- while (i < lineParts.Length)
- {
- if (lineParts[i] != null)
- {
- newLineParts[j] = lineParts[i];
- j++;
- }
- i++;
- }
- lineParts = newLineParts;
- #endregion
- #region GROUP THE REMAINS OF MATH EXPRESSIONS THAT WERE SPLIT APART INTO ONE ELEMENT OF lineParts
- i = 0;
- bool inExpression = false;
- int linePartExpressionStart = 0;
- nulls = 0;
- while (i < lineParts.Length)
- {
- if (!inExpression && lineParts[i].StartsWith("(") && !lineParts[i].EndsWith(")"))
- {
- inExpression = true;
- linePartExpressionStart = i;
- }
- else if (inExpression)
- {
- if (lineParts[i].EndsWith(")"))
- {
- lineParts[linePartExpressionStart] += lineParts[i];
- inString = false;
- }
- else lineParts[linePartExpressionStart] += lineParts[i];
- lineParts[i] = null;
- nulls++;
- }
- i++;
- }
- string[] newLineParts2 = new string[lineParts.Length - nulls];
- i = 0;
- j = 0;
- while (i < lineParts.Length)
- {
- if (lineParts[i] != null)
- {
- newLineParts2[j] = lineParts[i];
- j++;
- }
- i++;
- }
- lineParts = newLineParts2;
- #endregion
- // Update this for every new command:
- #region CONVERSIONS AND VARIABLE TO VALUE REPLACEMENTS
- if (lineParts[0] == "if") lineParts[0] = "If";
- i = 0;
- while (i < lineParts.Length && lineParts[i] != null)
- {
- string shouldBe = "";
- string whatItIs = "";
- if (lineParts[0] == "GlobalMessage" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "PlayerMessage" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "GenerateMap" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "GenerateMap" && (i == 3 || i == 4 || i == 5)) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "LoadMap" && lineParts[1].StartsWith("\"") && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "LoadMap" && i == 1) { shouldBe = "map"; goto done1; }
- if (lineParts[0] == "UnloadMap" && i == 1) { shouldBe = "map"; goto done1; }
- //if (lineParts[0] == "SaveMap" && i == 1) { shouldBe = "map"; goto done1; }
- if (lineParts[0] == "ConsoleMessage" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "KickPlayer" && i == 1) { shouldBe = "player"; goto done1; }
- if (lineParts[0] == "KickPlayer" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "MovePlayer" && i == 1) { shouldBe = "player"; goto done1; }
- if (lineParts[0] == "MovePlayer" && i == 2) { shouldBe = "map"; goto done1; }
- if (lineParts[0] == "CreateFile" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "CreateDirectory" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "DeleteFile" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "DeleteDirectory" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "TruncateFile" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "TruncateDirectory" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "FileWriteLine" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "FileWriteLine" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "ExecuteScript" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "TriggerEvent" && i == 1) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "SetBlock" && i == 2) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "SetBlock" && i == 3) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "SetBlock" && i == 4) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "SetBlock" && i == 5) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "GetBlock" && i == 2) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "GetBlock" && i == 3) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "GetBlock" && i == 4) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "GetBlock" && i == 5) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "SendBlock" && i == 2) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "SendBlock" && i == 3) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "SendBlock" && i == 4) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "SendBlock" && i == 5) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "Replace" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "Replace" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "Sleep" && i == 1) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "Wait" && i == 1) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileExists" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "DirectoryExists" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContainsLine" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContainsLine" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContainsString" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContainsString" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContainsText" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContainsText" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContains" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileContains" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileRemoveLine" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "FileRemoveLine" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringContains" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringContains" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringContainsString" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringContainsString" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringStartsWith" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringStartsWith" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringStartsWithString" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringStartsWithString" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringEndsWith" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringEndsWith" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringEndsWithString" && i == 2) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && lineParts[1] == "StringEndsWithString" && i == 3) { shouldBe = "string"; goto done1; }
- if (lineParts[0] == "If" && (lineParts[2] == "<" || lineParts[2] == ">" || lineParts[2] == "<=" || lineParts[2] == ">=") && i == 1) { shouldBe = "number"; goto done1; }
- if (lineParts[0] == "If" && (lineParts[2] == "<" || lineParts[2] == ">" || lineParts[2] == "<=" || lineParts[2] == ">=") && i == 3) { shouldBe = "number"; goto done1; }
-
- if (lineParts[0] == "If" && (lineParts[2] == "==" || lineParts[2] == "!=") && (i == 1 || i == 3))
- {
- if (System.Double.TryParse(lineParts[1], out parseTryer) || System.Double.TryParse(lineParts[3], out parseTryer)) { shouldBe = "number"; goto done1; }
- if (lineParts[1].StartsWith("\"") || lineParts[3].StartsWith("\"")) { shouldBe = "string"; goto done1; }
- if (lineParts[1].StartsWith("$") && lineParts[3].StartsWith("$"))
- {
- lineParts[1] = lineParts[1].Remove(0, 1);
- i = 0;
- while (i < 255)
- {
- if (mapVarNames[i] != null) { shouldBe = "map"; goto done1; }
- if (playerVarNames[i] != null) { shouldBe = "player"; goto done1; }
- if (stringVarNames[i] != null) { shouldBe = "string"; goto done1; }
- if (numberVarNames[i] != null) { shouldBe = "number"; goto done1; }
- i++;
- }
- lineError = "Variable $" + lineParts[1] + " does not exist.";
- fatalError = true;
- goto nextLine;
- }
- lineError = "Could not compare " + lineParts[1] + " with " + lineParts[3];
- fatalError = true;
- goto nextLine;
- }
- if (lineParts.Length > 2)
- {
- if (lineParts[0] == "If" && (lineParts[2] == "<" || lineParts[2] == ">" || lineParts[2] == "<=" || lineParts[2] == ">=") && (i == 1 || i == 3)) { shouldBe = "number"; goto done1; }
- if ((lineParts[1] == "+=" || lineParts[1] == "-=" || lineParts[1] == "*=" || lineParts[1] == "/=" || lineParts[1] == "^=") && i == 2) { shouldBe = "number"; goto done1; }
- }
- if ((lineParts[0].ToLower() == "sleep" || lineParts[0].ToLower() == "wait") && i == 1) { shouldBe = "number"; goto done1; }
- if (lineParts.Length >= 3)
- {
- if (lineParts[1] == "=" && i == 2) // Assigning value to variable
- {
- lineParts[0] = lineParts[0].Remove(0, 1);
- j = 0;
- while (j < 255)
- {
- if (numberVarNames[j] == lineParts[0]) { shouldBe = "number"; }
- if (stringVarNames[j] == lineParts[0]) { shouldBe = "string"; }
- if (playerVarNames[j] == lineParts[0]) { if (lineParts[2].StartsWith("\"")) { shouldBe = "string"; } else if (lineParts[2].StartsWith("$")) { goto done3; } else { lineError = "Syntax error! After = a player variable or a string is expected."; } }
- if (mapVarNames[j] == lineParts[0]) { if (lineParts[2].StartsWith("\"")) { shouldBe = "string"; } else if (lineParts[2].StartsWith("$")) { goto done3; } else { lineError = "Syntax error! After = a map variable or a string is expected."; } }
- if (shouldBe != "")
- {
- lineParts[0] = "$" + lineParts[0];
- goto done1;
- }
- j++;
- }
- lineError = "Could not assign value to variable. Variable $" + lineParts[1] + " does not exist.";
- goto nextLine;
- }
- }
- if (lineParts.Length >= 4)
- {
- if (lineParts[2] == "=" & i == 3) // Assigning value to variable after creating the variable
- {
- //shouldBe = lineParts[0]; // as the type is already given in the first line part, easy-peasy <-- does not apply anymore :p
- switch (lineParts[0])
- {
- case "string":
- shouldBe = "string";
- break;
- case "number":
- shouldBe = "number";
- break;
- default:
- goto done3; // if a map or player variable is being declared, skip the conversions and replacements as they need to be done else in the kajlkfafadlkfkl
- }
- goto done1;
- }
- }
- goto done3;
- done1:
- if (lineParts[i].StartsWith("\"")) { whatItIs = "string"; goto done2; }
- else if (System.Double.TryParse(lineParts[i], out parseTryer)) { whatItIs = "number"; goto done2; }
- else if (lineParts[i].StartsWith("(") && lineParts[i].EndsWith(")")) { whatItIs = "math"; goto done2; }
- else if (!lineParts[i].StartsWith("$")) { whatItIs = "map/player"; goto done2; } // old >.>
- else
- {
- //Server.s.Log(lineParts[i]);
- lineParts[i] = lineParts[i].Remove(0, 1);
- if (lineParts[i] == "$server.$defaultcolor") { lineParts[1] = "\"" + Vars.Color + "\""; goto done2; }
- //Server.s.Log(lineParts[i]);
- j = 0;
- while (j < 255)
- {
- if (lineParts[i] == playerVarNames[j] + ".$rank.$name.$length") { lineParts[i] = playerVars[j].rank.name.Length.ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$map.$name.$length") { lineParts[i] = playerVars[j].map.name.Length.ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$map.$owner.$length") { lineParts[i] = playerVars[j].map.owner.Length.ToString(); whatItIs = "number"; goto done2; }
-
- if (lineParts[i] == mapVarNames[j] + ".$name.$length") { lineParts[i] = mapVars[j].name.Length.ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == mapVarNames[j] + ".$players.$count") { lineParts[i] = mapVars[j].players.Count.ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == mapVarNames[j] + ".$owner.$length") { lineParts[i] = mapVars[j].owner.Length.ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$rank.$color") { lineParts[i] = "\"" + playerVars[j].rank.color + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$rank.$name") { lineParts[i] = "\"" + playerVars[j].rank.name + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$name.$length") { lineParts[i] = playerVars[j].name.Length.ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$map.$name") { lineParts[i] = "\"" + playerVars[j].map.name + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$map.$creator") { lineParts[i] = "\"" + playerVars[j].map.owner + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == mapVarNames[j] + ".$name") { lineParts[i] = "\"" + mapVars[j].name + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == mapVarNames[j] + ".$creator") { lineParts[i] = "\"" + mapVars[j].name + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$name") { lineParts[i] = "\"" + playerVars[j].name + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$titlecolor") { lineParts[i] = "\"" + playerVars[j].titleColor + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$title") { lineParts[i] = "\"" + playerVars[j].title + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$map") { lineParts[i] = playerVars[j].map.name; whatItIs = "map"; goto done2; }
- if (lineParts[i] == playerVarNames[j] + ".$rank") { lineParts[i] = playerVars[j].rank.permission.ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == stringVarNames[j] + ".$length") { lineParts[i] = stringVars[j].Length.ToString(); whatItIs = "number"; goto done2; }
-
- if (lineParts[i] == numberVarNames[j]) { lineParts[i] = numberVars[j].ToString(); whatItIs = "number"; goto done2; }
- if (lineParts[i] == stringVarNames[j]) { lineParts[i] = "\"" + stringVars[j].ToString() + "\""; whatItIs = "string"; goto done2; }
- if (lineParts[i] == playerVarNames[j]) { whatItIs = "player"; goto done2; } // lineParts[i] = playerVars[j].name; }
- if (lineParts[i] == mapVarNames[j]) { whatItIs = "map"; goto done2; } // lineParts[i] = mapVars[j].name; }
- j++;
- }
- if (whatItIs == "")
- {
- lineError = "Could not find variable $" + lineParts[i];
- goto nextLine;
- }
- }
- lineError = "Unknown syntax error.";
- goto nextLine;
- done2:
- //if (whatItIs == "map/player" && (shouldBe == "map" || shouldBe == "player")) goto done3; <-- nope, removed that outta here
- if (whatItIs == "string")
- {
- lineParts[i] = lineParts[i].Replace("$server.$defaultcolor", Vars.Color);
- j = 0;
- while (j < 255)
- {
- //try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$rank.$name.$length", playerVars[j].group.name.Length); } catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$map.$name.$length", playerVars[j].map.name.ToString()); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$map.$owner.$length", playerVars[j].map.name.ToString()); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$rank.$name.$length", playerVars[j].rank.name.ToString()); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$rank.$color.$length", playerVars[j].rank.color.Length.ToString()); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + mapVarNames[j] + ".$map.$name", playerVars[j].map.name); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$map.$owner", playerVars[j].map.owner); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$rank.$name", playerVars[j].rank.name); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$rank.$color", playerVars[j].rank.color); }
- catch { }
- try { if (mapVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + mapVarNames[j] + ".$players.$count", mapVars[j].players.Count.ToString()); }
- catch { }
- try { if (mapVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + mapVarNames[j] + ".$name.$length", mapVars[j].name.Length.ToString()); }
- catch { }
- try { if (mapVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + mapVarNames[j] + ".$creator.$length", mapVars[j].owner.Length.ToString()); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$name", playerVars[j].name); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$rank", playerVars[j].rank.color + playerVars[j].rank.name); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$titlecolor", playerVars[j].titleColor); }
- catch { }
- try { if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$title", playerVars[j].title); }
- catch { }
- try { if (mapVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + mapVarNames[j] + ".$name", mapVars[j].name); }
- catch { }
- try { if (mapVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + mapVarNames[j] + ".$creator", mapVars[j].owner); }
- catch { }
- try { if (stringVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + stringVarNames[j] + ".$length", stringVars[j].Length.ToString()); }
- catch { }
-
- try { if (stringVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + stringVarNames[j], stringVars[j]); }
- catch { }
- try { if (numberVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + numberVarNames[j], numberVars[j].ToString()); } catch { }
- j++;
- }
- }
- if (whatItIs == "math") ///// FIRST CONVERT ALL MATH TO NUMBER. THEN LATER CONVERT THE NUMBERS TO OTHER STUFF, IF NECESSARY :)
- {
- j = 0;
- while (j < 255)
- {
- if (numberVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + numberVarNames[j], numberVars[j].ToString());
- if (playerVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + playerVarNames[j] + ".$map.$players.$count", playerVars[j].map.players.Count.ToString());
- if (mapVarNames[j] != null) lineParts[i] = lineParts[i].Replace("$" + mapVarNames[j] + ".$players.$count", mapVars[j].players.Count.ToString());
- j++;
- }
- try
- {
- lineParts[i] = XMath.Parse(lineParts[i]).ToString();
- whatItIs = "number";
- }
- catch (Exception e) // ehhh, does this work?
- {
- lineError = "Could not parse math " + lineParts[i] + ": " + e.Message;
- goto nextLine;
- }
- }
- if (whatItIs == shouldBe) goto done3;
- if (whatItIs == "string" && shouldBe == "number")////// STRING --> NUMBER
- {
- if (!System.Double.TryParse(ParseString(lineParts[i]), out parseTryer))
- {
- if (Block.Number(ParseString(lineParts[i])) == 50)
- {
- lineError = "Could not convert string " + lineParts[i] + " to number.";
- goto nextLine;
- }
- else
- {
- lineParts[i] = Convert.ToInt16(Block.Number(ParseString(lineParts[i]))).ToString();
- }
- }
- else
- {
- lineParts[i] = ParseString(lineParts[i]);
- }
- goto done3;
- }
- else if (whatItIs == "number" && shouldBe == "string")
- {
- lineParts[i] = "\"" + lineParts[i] + "\"";
- }
- else
- {
- lineError = "Failed to convert " + whatItIs + " to " + shouldBe + ".";
- goto nextLine;
- }
- #region removed conversions
- /* //// MADE IMPOSSIBLE SINCE MAPS AND PLAYERS ARE ONLY VARIABLES
- else if (whatItIs == "string" && shouldBe == "map") STRING --> MAP
- {
- if (Map.Find(lineParts[i]) == null)
- {
- lineError = "Could not convert string \"" + lineParts[i] + "\" to map, no such map is loaded.";
- goto nextLine;
- }
- else
- {
- lineParts[i] = ParseString(lineParts[i]);
- }
- }
- */
- /*
- else if (whatItIs == "string" && shouldBe == "player") ////// STRING --> PLAYER
- {
- if (Player.Find(lineParts[i]) == null)
- {
- lineError = "Could not convert string \"" + lineParts[i] + "\" to player, no such player is connected.";
- goto nextLine;
- }
- else
- {
- lineParts[i] = ParseString(lineParts[i]);
- }
- }
- */
- #endregion
- done3:
- i++;
- }
- #endregion
- #region Try Catch
- if (lineParts[0].ToLower() == "try")
- {
- if (inTryBlock)
- {
- lineError = "You can't have a try block inside another try block, sorry.";
- block_type[curBlock + 1] = "nothing";
- goto nextLine;
- }
- block_type[curBlock + 1] = "try";
- inTryBlock = true;
- executeCatch = false;
- tryCurBlock = curBlock;
- goto nextLine;
- }
- if (lineParts[0].ToLower() == "catch")
- {
- block_type[curBlock + 1] = "catch";
- goto nextLine;
- }
- #endregion
- #region Repeat StopRepeat
- if (line.ToLower() == "repeat")
- {
- block_type[curBlock + 1] = "repeat";
- goto nextLine;
- }
- if (line.ToLower() == "stop repeat" || line.ToLower() == "stop repeating" || line.ToLower() == "stoprepeat" || line.ToLower() == "stoprepeating")
- {
- i = lineNum;
- double blocksLess = 0;
- while (i >= 0)
- {
- if (lines[i].Trim() == "{") blocksLess++;
- else if (lines[i].Trim() == "}") blocksLess--;
- else …
Large files files are truncated, but you can click here to view the full file