mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Add function to get server info.
This commit is contained in:
parent
468eeb618e
commit
ae0d8f74d7
7 changed files with 53 additions and 21 deletions
|
@ -58,6 +58,7 @@ Client::Client(
|
|||
IrrlichtDevice *device,
|
||||
const char *playername,
|
||||
const std::string &password,
|
||||
const std::string &address_name,
|
||||
MapDrawControl &control,
|
||||
IWritableTextureSource *tsrc,
|
||||
IWritableShaderSource *shsrc,
|
||||
|
@ -89,6 +90,7 @@ Client::Client(
|
|||
),
|
||||
m_particle_manager(&m_env),
|
||||
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this),
|
||||
m_address_name(address_name),
|
||||
m_device(device),
|
||||
m_camera(NULL),
|
||||
m_minimap_disabled_by_server(false),
|
||||
|
@ -253,13 +255,11 @@ Client::~Client()
|
|||
delete m_minimap;
|
||||
}
|
||||
|
||||
void Client::connect(Address address,
|
||||
const std::string &address_name,
|
||||
bool is_local_server)
|
||||
void Client::connect(Address address, bool is_local_server)
|
||||
{
|
||||
DSTACK(FUNCTION_NAME);
|
||||
|
||||
initLocalMapSaving(address, address_name, is_local_server);
|
||||
initLocalMapSaving(address, m_address_name, is_local_server);
|
||||
|
||||
m_con.SetTimeoutMs(0);
|
||||
m_con.Connect(address);
|
||||
|
|
16
src/client.h
16
src/client.h
|
@ -257,6 +257,7 @@ public:
|
|||
IrrlichtDevice *device,
|
||||
const char *playername,
|
||||
const std::string &password,
|
||||
const std::string &address_name,
|
||||
MapDrawControl &control,
|
||||
IWritableTextureSource *tsrc,
|
||||
IWritableShaderSource *shsrc,
|
||||
|
@ -284,9 +285,7 @@ public:
|
|||
The name of the local player should already be set when
|
||||
calling this, as it is sent in the initialization.
|
||||
*/
|
||||
void connect(Address address,
|
||||
const std::string &address_name,
|
||||
bool is_local_server);
|
||||
void connect(Address address, bool is_local_server);
|
||||
|
||||
/*
|
||||
Stuff that references the environment is valid only as
|
||||
|
@ -525,6 +524,16 @@ public:
|
|||
|
||||
IrrlichtDevice *getDevice() const { return m_device; }
|
||||
|
||||
const Address getServerAddress()
|
||||
{
|
||||
return m_con.GetPeerAddress(PEER_ID_SERVER);
|
||||
}
|
||||
|
||||
const std::string &getAddressName() const
|
||||
{
|
||||
return m_address_name;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// Virtual methods from con::PeerHandler
|
||||
|
@ -576,6 +585,7 @@ private:
|
|||
ClientEnvironment m_env;
|
||||
ParticleManager m_particle_manager;
|
||||
con::Connection m_con;
|
||||
std::string m_address_name;
|
||||
IrrlichtDevice *m_device;
|
||||
Camera *m_camera;
|
||||
Minimap *m_minimap;
|
||||
|
|
|
@ -2044,7 +2044,7 @@ bool Game::connectToServer(const std::string &playername,
|
|||
}
|
||||
|
||||
client = new Client(device,
|
||||
playername.c_str(), password,
|
||||
playername.c_str(), password, *address,
|
||||
*draw_control, texture_src, shader_src,
|
||||
itemdef_manager, nodedef_manager, sound, eventmgr,
|
||||
connect_address.isIPv6(), &flags);
|
||||
|
@ -2056,7 +2056,7 @@ bool Game::connectToServer(const std::string &playername,
|
|||
connect_address.print(&infostream);
|
||||
infostream << std::endl;
|
||||
|
||||
client->connect(connect_address, *address,
|
||||
client->connect(connect_address,
|
||||
simple_singleplayer_mode || local_server_mode);
|
||||
|
||||
/*
|
||||
|
|
|
@ -234,10 +234,20 @@ int ModApiClient::l_sound_stop(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// get_protocol_version()
|
||||
int ModApiClient::l_get_protocol_version(lua_State *L)
|
||||
// get_server_info()
|
||||
int ModApiClient::l_get_server_info(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, getClient(L)->getProtoVersion());
|
||||
Client *client = getClient(L);
|
||||
Address serverAddress = client->getServerAddress();
|
||||
lua_newtable(L);
|
||||
lua_pushstring(L, client->getAddressName().c_str());
|
||||
lua_setfield(L, -2, "address");
|
||||
lua_pushstring(L, serverAddress.serializeString().c_str());
|
||||
lua_setfield(L, -2, "ip");
|
||||
lua_pushinteger(L, serverAddress.getPort());
|
||||
lua_setfield(L, -2, "port");
|
||||
lua_pushinteger(L, client->getProtoVersion());
|
||||
lua_setfield(L, -2, "protocol_version");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -265,6 +275,6 @@ void ModApiClient::Initialize(lua_State *L, int top)
|
|||
API_FCT(get_meta);
|
||||
API_FCT(sound_play);
|
||||
API_FCT(sound_stop);
|
||||
API_FCT(get_protocol_version);
|
||||
API_FCT(get_server_info);
|
||||
API_FCT(take_screenshot);
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ private:
|
|||
|
||||
static int l_sound_stop(lua_State *L);
|
||||
|
||||
// get_protocol_version()
|
||||
static int l_get_protocol_version(lua_State *L);
|
||||
// get_server_info()
|
||||
static int l_get_server_info(lua_State *L);
|
||||
|
||||
static int l_take_screenshot(lua_State *L);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue