Skip to content

Commit

Permalink
Add getConnectionInfo() (Mudlet#3105)
Browse files Browse the repository at this point in the history
* Add getConnectionInfo()

* Add link to wiki
  • Loading branch information
vadi2 authored Sep 20, 2019
1 parent 38cf328 commit 1bf0a95
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/TLuaInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14968,6 +14968,18 @@ int TLuaInterpreter::deleteHTTP(lua_State *L)
return 2;
}


// Documentation: https://wiki.mudlet.org/w/Manual:Lua_Functions#getConnectionInfo
int TLuaInterpreter::getConnectionInfo(lua_State *L)
{
Host& host = getHostFromLua(L);

auto [hostName, hostPort] = host.mTelnet.getConnectionInfo();
lua_pushstring(L, hostName.toUtf8().constData());
lua_pushnumber(L, hostPort);
return 2;
}

// No documentation available in wiki - internal function
void TLuaInterpreter::set_lua_table(const QString& tableName, QStringList& variableList)
{
Expand Down Expand Up @@ -15494,6 +15506,7 @@ void TLuaInterpreter::initLuaGlobals()
lua_register(pGlobalLua, "putHTTP", TLuaInterpreter::putHTTP);
lua_register(pGlobalLua, "postHTTP", TLuaInterpreter::postHTTP);
lua_register(pGlobalLua, "deleteHTTP", TLuaInterpreter::deleteHTTP);
lua_register(pGlobalLua, "getConnectionInfo", TLuaInterpreter::getConnectionInfo);
// PLACEMARKER: End of main Lua interpreter functions registration

// prepend profile path to package.path and package.cpath
Expand Down
1 change: 1 addition & 0 deletions src/TLuaInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ class TLuaInterpreter : public QThread
static int putHTTP(lua_State* L);
static int postHTTP(lua_State* L);
static int deleteHTTP(lua_State* L);
static int getConnectionInfo(lua_State* L);
// PLACEMARKER: End of Lua functions declarations


Expand Down
9 changes: 9 additions & 0 deletions src/ctelnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,15 @@ QString cTelnet::decodeOption(const unsigned char ch) const
}
}

std::pair<QString, int> cTelnet::getConnectionInfo() const
{
if (hostName.isEmpty() && hostPort == 0) {
return {mpHost->getUrl(), mpHost->getPort()};
} else {
return {hostName, hostPort};
}
}

void cTelnet::processTelnetCommand(const std::string& command)
{
char ch = command[1];
Expand Down
1 change: 1 addition & 0 deletions src/ctelnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class cTelnet : public QObject
void requestDiscordInfo();
QString decodeOption(const unsigned char) const;
QAbstractSocket::SocketState getConnectionState() const { return socket.state(); }
std::pair<QString, int> getConnectionInfo() const;


QMap<int, bool> supportedTelnetOptions;
Expand Down

0 comments on commit 1bf0a95

Please sign in to comment.