diff options
-rw-r--r-- | Sluift/SluiftClient.cpp | 3 | ||||
-rw-r--r-- | Sluift/SluiftClient.h | 2 | ||||
-rw-r--r-- | Sluift/client.cpp | 16 |
3 files changed, 17 insertions, 4 deletions
diff --git a/Sluift/SluiftClient.cpp b/Sluift/SluiftClient.cpp index 8a8d772..bfae621 100644 --- a/Sluift/SluiftClient.cpp +++ b/Sluift/SluiftClient.cpp @@ -53,7 +53,8 @@ void SluiftClient::connect() { } -void SluiftClient::connect(const std::string& host) { +void SluiftClient::connect(const std::string& host, int port) { rosterReceived = false; options.manualHostname = host; + options.manualPort = port; client->connect(options); } diff --git a/Sluift/SluiftClient.h b/Sluift/SluiftClient.h index bedd6ba..60eae16 100644 --- a/Sluift/SluiftClient.h +++ b/Sluift/SluiftClient.h @@ -76,5 +76,5 @@ namespace Swift { void connect(); - void connect(const std::string& host); + void connect(const std::string& host, int port); void waitConnected(); bool isConnected() const; diff --git a/Sluift/client.cpp b/Sluift/client.cpp index df43075..04ce8f4 100644 --- a/Sluift/client.cpp +++ b/Sluift/client.cpp @@ -49,14 +49,18 @@ SLUIFT_LUA_FUNCTION(Client, async_connect) { std::string host; + int port = -1; if (lua_istable(L, 2)) { if (boost::optional<std::string> hostString = Lua::getStringField(L, 2, "host")) { host = *hostString; } + if (boost::optional<int> portInt = Lua::getIntField(L, 2, "port")) { + port = *portInt; } - if (host.empty()) { + } + if (host.empty() && port == -1) { client->connect(); } else { - client->connect(host); + client->connect(host, port); } return 0; @@ -316,4 +320,12 @@ SLUIFT_LUA_FUNCTION(Client, set_options) { SluiftClient* client = getClient(L); Lua::checkType(L, 2, LUA_TTABLE); + lua_getfield(L, 2, "host"); + if (!lua_isnil(L, -1)) { + client->getOptions().manualHostname = lua_tostring(L, -1); + } + lua_getfield(L, 2, "port"); + if (!lua_isnil(L, -1)) { + client->getOptions().manualPort = lua_tointeger(L, -1); + } lua_getfield(L, 2, "ack"); if (!lua_isnil(L, -1)) { |