Browse Source

Added RenX::DisconnectReason enum

Added RenX_OnServerDisconnect event to RenX::Plugin
Added DisconnectReason as a parameter for Server::disconnect() and Server::reconnect() -- adjusted all calls to these commands accordingly
pull/3/head
JustinAJ 10 years ago
parent
commit
3fb51512e9
  1. BIN
      Release/Plugins/RenX.Core.lib
  2. 2
      RenX.Commands/RenX_Commands.cpp
  3. 16
      RenX.Core/RenX.h
  4. 5
      RenX.Core/RenX_Plugin.cpp
  5. 1
      RenX.Core/RenX_Plugin.h
  6. 18
      RenX.Core/RenX_Server.cpp
  7. 7
      RenX.Core/RenX_Server.h

BIN
Release/Plugins/RenX.Core.lib

Binary file not shown.

2
RenX.Commands/RenX_Commands.cpp

@ -1193,7 +1193,7 @@ void ReconnectIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString
RenX::Server *server = RenX::getCore()->getServer(i);
if (server->isLogChanType(type))
{
if (server->reconnect()) msg.set("Connection established");
if (server->reconnect(RenX::DisconnectReason::Triggered)) msg.set("Connection established");
else msg.format("[RenX] ERROR: Failed to connect to %.*s on port %u." ENDL, server->getHostname().size(), server->getHostname().ptr(), server->getPort());
source->sendMessage(channel, msg);
}

16
RenX.Core/RenX.h

@ -65,6 +65,22 @@ namespace RenX
Defence,
None
};
enum class DisconnectReason : unsigned int
{
SocketError,
SocketErrorReconnect,
PingTimeout,
PingTimeoutReconnect,
IncompatibleVersion,
IncompatibleVersionReconnect,
Triggered,
TriggeredReconnect,
Rehash,
RehashReconnect,
Other,
OtherReconnect
};
}
#endif // __cplusplus

5
RenX.Core/RenX_Plugin.cpp

@ -65,6 +65,11 @@ void RenX::Plugin::RenX_OnServerCreate(Server *)
return;
}
void RenX::Plugin::RenX_OnServerDisconnect(Server *, RenX::DisconnectReason)
{
return;
}
bool RenX::Plugin::RenX_OnBan(Server *, const RenX::PlayerInfo *, Jupiter::StringType &)
{
return false;

1
RenX.Core/RenX_Plugin.h

@ -48,6 +48,7 @@ namespace RenX
virtual void RenX_OnPlayerDelete(Server *server, const PlayerInfo *player);
virtual void RenX_OnPlayerUUIDChange(Server *server, const PlayerInfo *player, const Jupiter::ReadableString &newUUID);
virtual void RenX_OnServerCreate(Server *server);
virtual void RenX_OnServerDisconnect(Server *server, RenX::DisconnectReason reason);
virtual bool RenX_OnBan(Server *server, const PlayerInfo *player, Jupiter::StringType &data);
/** Player type logs */

18
RenX.Core/RenX_Server.cpp

@ -50,7 +50,7 @@ int RenX::Server::think()
else if (RenX::Server::awaitingPong && std::chrono::steady_clock::now() - RenX::Server::lastActivity >= RenX::Server::pingTimeoutThreshold) // ping timeout
{
RenX::Server::sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (ping timeout)."));
RenX::Server::disconnect();
RenX::Server::disconnect(RenX::DisconnectReason::PingTimeout);
}
else
{
@ -88,7 +88,7 @@ int RenX::Server::think()
if (RenX::Server::maxAttempts != 0)
{
RenX::Server::sendLogChan(IRCCOLOR "07[Warning]" IRCCOLOR " Connection to Renegade-X server lost. Reconnection attempt in progress.");
if (RenX::Server::reconnect())
if (RenX::Server::reconnect(RenX::DisconnectReason::SocketError))
RenX::Server::sendLogChan(IRCCOLOR "06[Progress]" IRCCOLOR " Connection to Renegade-X server reestablished. Initializing Renegade-X RCON protocol...");
else
RenX::Server::sendLogChan(IRCCOLOR "04[Error]" IRCCOLOR " Connection to Renegade-X server lost. Reconnection attempt failed.");
@ -123,7 +123,7 @@ int RenX::Server::OnRehash()
RenX::Server::commands.emptyAndDelete();
RenX::Server::init();
if (oldHostname.equalsi(RenX::Server::hostname) == false || oldPort != RenX::Server::port || oldClientHostname.equalsi(RenX::Server::clientHostname) == false || oldPass.equalsi(RenX::Server::pass) == false)
RenX::Server::reconnect();
RenX::Server::reconnect(RenX::DisconnectReason::Rehash);
return 0;
}
@ -2419,7 +2419,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
else
{
RenX::Server::sendLogChan(STRING_LITERAL_AS_REFERENCE(IRCCOLOR "04[Error]" IRCCOLOR " Disconnected from Renegade-X server (incompatible RCON version)."));
this->disconnect();
this->disconnect(RenX::DisconnectReason::IncompatibleVersion);
}
break;
@ -2443,8 +2443,12 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line)
}
}
void RenX::Server::disconnect()
void RenX::Server::disconnect(RenX::DisconnectReason reason)
{
Jupiter::ArrayList<RenX::Plugin> xPlugins;
for (size_t i = 0; i < xPlugins.size(); i++)
xPlugins.get(i)->RenX_OnServerDisconnect(this, reason);
RenX::Server::sock.closeSocket();
RenX::Server::wipeData();
RenX::Server::connected = false;
@ -2467,9 +2471,9 @@ bool RenX::Server::connect()
return false;
}
bool RenX::Server::reconnect()
bool RenX::Server::reconnect(RenX::DisconnectReason reason)
{
RenX::Server::disconnect();
RenX::Server::disconnect(static_cast<RenX::DisconnectReason>(static_cast<unsigned int>(reason) | 0x01));
return RenX::Server::connect();
}

7
RenX.Core/RenX_Server.h

@ -742,8 +742,10 @@ namespace RenX
/**
* @brief Disconnects from a server's RCON interface.
*
* @param reason Reason for reconnecting.
*/
void disconnect();
void disconnect(RenX::DisconnectReason reason);
/**
* @brief Connects to the server's RCON interface.
@ -755,9 +757,10 @@ namespace RenX
/**
* @brief Reconnects to the server's RCON interface.
*
* @param reason Reason for reconnecting.
* @return True if the socket successfully connected, false otherwise.
*/
bool reconnect();
bool reconnect(RenX::DisconnectReason reason);
/**
* @brief Deletes all of the data about a server (such as players).

Loading…
Cancel
Save