Skip to content

Commit 2a46ed2

Browse files
committed
Make /showip available in the server
It was only provided in the client before. But in fact it is only relevant for server-side networking. Also migrate it to new-style command.
1 parent 0e1ffd5 commit 2a46ed2

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

src/engine/client/cl_main.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ CGameVM cgvm;
151151
refexport_t re;
152152

153153
void CL_CheckForResend();
154-
void CL_ShowIP_f();
155154

156155
#if defined(USE_MUMBLE)
157156
static void CL_UpdateMumble()
@@ -2400,7 +2399,6 @@ void CL_Init()
24002399

24012400
Cmd_AddCommand( "ping", CL_Ping_f );
24022401
Cmd_AddCommand( "serverstatus", CL_ServerStatus_f );
2403-
Cmd_AddCommand( "showip", CL_ShowIP_f );
24042402

24052403
Cmd_AddCommand( "updatescreen", SCR_UpdateScreen );
24062404
// done.
@@ -2476,7 +2474,6 @@ void CL_Shutdown()
24762474
Cmd_RemoveCommand( "globalservers" );
24772475
Cmd_RemoveCommand( "ping" );
24782476
Cmd_RemoveCommand( "serverstatus" );
2479-
Cmd_RemoveCommand( "showip" );
24802477

24812478
CL_ClearKeyBinding();
24822479
CL_ClearInput();
@@ -2496,16 +2493,6 @@ void CL_Shutdown()
24962493

24972494
}
24982495

2499-
/*
2500-
==================
2501-
CL_ShowIP_f
2502-
==================
2503-
*/
2504-
void CL_ShowIP_f()
2505-
{
2506-
Sys_ShowIP();
2507-
}
2508-
25092496
/*
25102497
====================
25112498
CL_GetClipboardData

src/engine/qcommon/net_ip.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ struct nip_localaddr_t
170170
struct sockaddr_storage netmask;
171171
};
172172

173+
// Used for Sys_IsLANAddress
173174
static nip_localaddr_t localIP[ MAX_IPS ];
174175
static int numIP;
175176

@@ -887,30 +888,32 @@ bool Sys_IsLANAddress( const netadr_t& adr )
887888
return false;
888889
}
889890

890-
/*
891-
==================
892-
Sys_ShowIP
893-
==================
894-
*/
895-
void Sys_ShowIP()
891+
class ShowIPCommand : public Cmd::StaticCmd
896892
{
897-
int i;
898-
char addrbuf[ NET_ADDR_STR_MAX_LEN ];
893+
public:
894+
ShowIPCommand() : StaticCmd("showip", Cmd::SERVER, "show addresses of network interfaces") {}
899895

900-
for ( i = 0; i < numIP; i++ )
896+
void Run( const Cmd::Args & ) const override
901897
{
902-
Sys_SockaddrToString( addrbuf, sizeof( addrbuf ), ( struct sockaddr * ) &localIP[ i ].addr );
898+
int i;
899+
char addrbuf[ NET_ADDR_STR_MAX_LEN ];
903900

904-
if ( localIP[ i ].type == netadrtype_t::NA_IP )
901+
for ( i = 0; i < numIP; i++ )
905902
{
906-
Log::Notice( "IP: %s", addrbuf );
907-
}
908-
else if ( localIP[ i ].type == netadrtype_t::NA_IP6 )
909-
{
910-
Log::Notice( "IP6: %s", addrbuf );
903+
Sys_SockaddrToString( addrbuf, sizeof( addrbuf ), ( struct sockaddr * ) &localIP[ i ].addr );
904+
905+
if ( localIP[ i ].type == netadrtype_t::NA_IP )
906+
{
907+
Print( "IP: %s", addrbuf );
908+
}
909+
else if ( localIP[ i ].type == netadrtype_t::NA_IP6 )
910+
{
911+
Print( "IP6: %s", addrbuf );
912+
}
911913
}
912914
}
913-
}
915+
};
916+
static ShowIPCommand showipRegistration;
914917

915918
//=============================================================================
916919

src/engine/qcommon/sys.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ bool Sys_GetPacket(netadr_t *net_from, msg_t *net_message);
4343
bool Sys_StringToAdr(const char *s, netadr_t *a, netadrtype_t family);
4444

4545
bool Sys_IsLANAddress(const netadr_t& adr);
46-
void Sys_ShowIP();
4746

4847
#endif // ENGINE_QCOMMON_SYS_H_

0 commit comments

Comments
 (0)