(svn r23623) -Add: allow bi-directional communication with the AdminPort and GameScript
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "../core/pool_func.hpp"
|
||||
#include "../map_func.h"
|
||||
#include "../rev.h"
|
||||
#include "../game/game.hpp"
|
||||
|
||||
|
||||
/* This file handles all the admin network commands. */
|
||||
@@ -52,6 +53,7 @@ static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
|
||||
ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CONSOLE
|
||||
ADMIN_FREQUENCY_POLL, ///< ADMIN_UPDATE_CMD_NAMES
|
||||
ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_CMD_LOGGING
|
||||
ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_GAMESCRIPT
|
||||
};
|
||||
/** Sanity check. */
|
||||
assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
|
||||
@@ -510,6 +512,20 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p)
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_GAMESCRIPT(Packet *p)
|
||||
{
|
||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
|
||||
char json[NETWORK_GAMESCRIPT_JSON_LENGTH];
|
||||
|
||||
p->Recv_string(json, sizeof(json));
|
||||
|
||||
DEBUG(net, 2, "[admin] GameScript JSON from '%s' (%s): '%s'", this->admin_name, this->admin_version, json);
|
||||
|
||||
Game::NewEvent(new ScriptEventAdminPort(json));
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send console output of other clients.
|
||||
* @param origin The origin of the string.
|
||||
@@ -532,6 +548,25 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const char *origi
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send GameScript JSON output.
|
||||
* @param json The JSON string.
|
||||
*/
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const char *json)
|
||||
{
|
||||
/* At the moment we cannot transmit anything larger than MTU. So the string
|
||||
* has to be no longer than the length of the json + '\0' + 3 bytes of the
|
||||
* packet header. */
|
||||
if (strlen(json) + 1 + 3 >= SEND_MTU) return NETWORK_RECV_STATUS_OKAY;
|
||||
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_GAMESCRIPT);
|
||||
|
||||
p->Send_string(json);
|
||||
this->SendPacket(p);
|
||||
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
/** Send the names of the commands. */
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
|
||||
{
|
||||
@@ -895,6 +930,20 @@ void NetworkAdminConsole(const char *origin, const char *string)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send GameScript JSON to the admin network (if they did opt in for the respective update).
|
||||
* @param json The JSON data as received from the GameScript.
|
||||
*/
|
||||
void NetworkAdminGameScript(const char *json)
|
||||
{
|
||||
ServerNetworkAdminSocketHandler *as;
|
||||
FOR_ALL_ACTIVE_ADMIN_SOCKETS(as) {
|
||||
if (as->update_frequency[ADMIN_UPDATE_GAMESCRIPT] & ADMIN_FREQUENCY_AUTOMATIC) {
|
||||
as->SendGameScript(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Distribute CommandPacket details over the admin network for logging purposes.
|
||||
* @param owner The owner of the CommandPacket (who sent us the CommandPacket).
|
||||
|
Reference in New Issue
Block a user