summaryrefslogtreecommitdiff
path: root/src/script/api/script_client.hpp
diff options
context:
space:
mode:
authorPavel Stupnikov <dp@dpointer.org>2018-04-22 16:42:29 +0300
committerPatric Stout <truebrain@openttd.org>2018-04-22 15:42:29 +0200
commit6ff81b908e8773c5ab94bc8a16c7d564270b0e75 (patch)
treece2fb92a9a8044d6cdb543a998e95932e436f4e1 /src/script/api/script_client.hpp
parente0ae67cefabb1116067c0220eb9ea831a512fa06 (diff)
downloadopenttd-6ff81b908e8773c5ab94bc8a16c7d564270b0e75.tar.xz
Feature #6459: API for querying network clients from GS (#6736)
Diffstat (limited to 'src/script/api/script_client.hpp')
-rw-r--r--src/script/api/script_client.hpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/script/api/script_client.hpp b/src/script/api/script_client.hpp
new file mode 100644
index 000000000..423f134c0
--- /dev/null
+++ b/src/script/api/script_client.hpp
@@ -0,0 +1,70 @@
+/* $Id$ */
+
+/*
+ * This file is part of OpenTTD.
+ * 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.
+ * 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.
+ * 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/>.
+ */
+
+/** @file script_client.hpp Everything to query a network client's information */
+
+#ifndef SCRIPT_CLIENT_HPP
+#define SCRIPT_CLIENT_HPP
+
+#include "script_text.hpp"
+#include "script_date.hpp"
+#include "script_company.hpp"
+#include "../../network/network_type.h"
+
+/**
+ * Class that handles all client related functions.
+ *
+ * @api game
+ */
+class ScriptClient : public ScriptObject {
+public:
+
+ /** Different constants related to ClientID. */
+ enum ClientID {
+ CLIENT_INVALID = 0, ///< Client is not part of anything
+ CLIENT_SERVER = 1, ///< Servers always have this ID
+ CLIENT_FIRST = 2, ///< The first client ID
+ };
+
+ /**
+ * Resolves the given client id to the correct index for the client.
+ * If the client with the given id does not exist it will
+ * return CLIENT_INVALID.
+ * @param client The client id to resolve.
+ * @return The resolved client id.
+ */
+ static ClientID ResolveClientID(ClientID client);
+
+ /**
+ * Get the name of the given client.
+ * @param client The client to get the name for.
+ * @pre ResolveClientID(client) != CLIENT_INVALID.
+ * @return The name of the given client.
+ */
+ static char *GetName(ClientID client);
+
+ /**
+ * Get the company in which the given client is playing.
+ * @param client The client to get company for.
+ * @pre ResolveClientID(client) != CLIENT_INVALID.
+ * @return The company in which client is playing or COMPANY_SPECTATOR.
+ */
+ static ScriptCompany::CompanyID GetCompany(ClientID client);
+
+ /**
+ * Get the game date when the given client has joined.
+ * @param client The client to get joining date for.
+ * @pre ResolveClientID(client) != CLIENT_INVALID.
+ * @return The date when client has joined.
+ */
+ static ScriptDate::Date GetJoinDate(ClientID client);
+};
+
+
+#endif /* SCRIPT_CLIENT_HPP */