Facepunch/garrysmod-requests

Add Player:Reconnect / Expose IClient::Reconnect

RaphaelIT7 opened this issue · 0 comments

Details

Expose the IClient::Reconnect function as Player:Reconnect.
Please also add an internal check to IClient::Reconnect so that Bots cannot be reconnected, because currently, if you try to reconnect a bot, it will crash the Game/Server.
Possible code (Didn't test it):

IServer* server; // Somehow get the IServer.
CBasePlayer* player = Get_Player(1, false); // Idk what the second argument does. Also make sure that the player is valid.
IClient* client = server->GetClient(player->GetClientIndex());
if (!client->IsFakeClient()) { // This check is needed, because Reconnect crashes if it's a fake client.
	client->Reconnect();
	LUA->PushBool(true); // We return a bool as a way to verify that the client got reconnected.
} else {
	LUA->PushBool(false);
}

This function could be useful because when you have a full server, and you want a client to reconnect, he could do so without the fear of losing his slot. Currently, you'll need to use the retry command to reconnect the client, which could result in the client losing his slot.