Skip to content

Commit 1a876ae

Browse files
committed
gameserver: add gameserver.CalculateCPUUsage()
requested from #25
1 parent b458cdc commit 1a876ae

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,6 +3239,9 @@ bf:WriteString("1") -- ConVar value
32393239
gameserver.BroadcastMessage(5, "NET_SetConVar", bf) -- 5 = net_SetConVar / net message type.
32403240
```
32413241

3242+
#### number gameserver.CalculateCPUUsage()
3243+
Calculates and returns the CPU Usage.
3244+
32423245
### CBaseClient
32433246
This class represents a client.
32443247

source/modules/gameserver.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,17 @@ LUA_FUNCTION_STATIC(gameserver_BroadcastMessage)
12461246
return 0;
12471247
}
12481248

1249+
LUA_FUNCTION_STATIC(gameserver_CalculateCPUUsage)
1250+
{
1251+
if (!Util::server || !Util::server->IsActive())
1252+
return 0;
1253+
1254+
CBaseServer* pServer = (CBaseServer*)Util::server;
1255+
pServer->CalculateCPUUsage();
1256+
LUA->PushNumber(pServer->m_fCPUPercent);
1257+
return 1;
1258+
}
1259+
12491260
extern CGlobalVars* gpGlobals;
12501261
static ConVar* sv_stressbots;
12511262
void CGameServerModule::LuaInit(bool bServerInit)
@@ -1292,6 +1303,7 @@ void CGameServerModule::LuaInit(bool bServerInit)
12921303
Util::AddFunc(gameserver_SetPaused, "SetPaused");
12931304
Util::AddFunc(gameserver_SetPassword, "SetPassword");
12941305
Util::AddFunc(gameserver_BroadcastMessage, "BroadcastMessage");
1306+
Util::AddFunc(gameserver_CalculateCPUUsage, "CalculateCPUUsage");
12951307
Util::FinishTable("gameserver");
12961308
}
12971309

source/sourcesdk/baseserver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class CBaseServer : public IServer
153153

154154
CBaseClient* Client(int index) { return static_cast<CBaseClient*>(m_Clients[index]); };
155155

156-
protected:
156+
public: // protected - private, doesn't matter, I want access :3
157157

158158
virtual IClient *ConnectClient ( netadr_t &adr, int protocol, int challenge, int clientChallenge, int authProtocol,
159159
const char *name, const char *password, const char *hashedCDkey, int cdKeyLen );

0 commit comments

Comments
 (0)