1 /* 2 * This file is part of OpenTTD. 3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. 4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. 6 */ 7 8 /** @file script_admin.hpp Everything to communicate with the AdminPort. */ 9 10 #ifndef SCRIPT_ADMIN_HPP 11 #define SCRIPT_ADMIN_HPP 12 13 #include <string> 14 #include "script_object.hpp" 15 16 /** 17 * Class that handles communication with the AdminPort. 18 * @api game 19 */ 20 class ScriptAdmin : public ScriptObject { 21 public: 22 #ifndef DOXYGEN_API 23 /** 24 * Internal representation of the Send function. 25 */ 26 static SQInteger Send(HSQUIRRELVM vm); 27 #else 28 /** 29 * Send information to the AdminPort. The information can be anything 30 * as long as it isn't a class or instance thereof. 31 * @param table The information to send, in a table. For example: { param = "param" }. 32 * @return True if and only if the data was successfully converted to JSON 33 * and send to the AdminPort. 34 * @note If the resulting JSON of your table is larger than 1450 bytes, 35 * nothing will be sent (and false will be returned). 36 */ 37 static bool Send(void *table); 38 #endif /* DOXYGEN_API */ 39 40 private: 41 /** 42 * Convert a Squirrel structure into a JSON string. 43 * @param vm The VM to operate on. 44 * @param index The index we are currently working for. 45 * @param max_depth The maximal depth to follow the squirrel struct. 46 * @param data The resulting json string. 47 */ 48 static bool MakeJSON(HSQUIRRELVM vm, SQInteger index, int max_depth, std::string &data); 49 }; 50 51 #endif /* SCRIPT_ADMIN_HPP */ 52