Raised This Month: $ Target: $400
 0% 

[L4D2] Server Auto-Restart


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 02-17-2010 , 17:11   [L4D2] Server Auto-Restart
Reply With Quote #1

Purpose: Restart the server after all players disconnect

This plugin for L4D1 does not work for L4D2.. Any ideas?

It seems that L4D2 restarts the map before it goes into hibernation mode.. Maybe that is screwing up the boolean value with the OnMapStart() and OnMapEnd()?

I requested this plugin a while ago, but I need it again for L4D2. (http://forums.alliedmods.net/showthread.php?t=90791)

PHP Code:
#include <sourcemod>

public Plugin:myinfo 
{
    
name "Empty Server Restarter",
    
author "exvel",
    
description "Restarts servers when last player disconnected",
    
version "1.0.0",
    
url "www.sourcemod.net"
}

new 
bool:g_isMapChange false;

public 
OnClientDisconnect(client)
{
    
// if map is changing do not do anything
    
if (client == || g_isMapChange || IsFakeClient(client))
        return;
    
    
CreateTimer(1.0Check);
}

public 
OnMapEnd()
{
    
g_isMapChange true;
}

public 
OnMapStart()
{
    
g_isMapChange false;
}

public 
Action:Check(Handle:timer)
{
    if (
g_isMapChange)
        return;
    
    
// count for players
    
new counter 0;
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientConnected(i) && !IsFakeClient(i))
        {
            
counter++;
        }
    }
        
    
// send "quit" command if there are no players
    
if (counter == 0)
        
ServerCommand("quit");

bman87 is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 02-18-2010 , 12:38   Re: [L4D2] Server Auto-Restart
Reply With Quote #2

Anyone have ideas on how to accomplish a server restart when all clients disconnect?
bman87 is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 02-19-2010 , 09:08   Re: [L4D2] Server Auto-Restart
Reply With Quote #3

Quote:
Originally Posted by Visual77 View Post
This simple script woulden't work? Or are you looking for something else?
Didn't Work. In my logs I see that clients were disconnected Reason: "Server is shutting down".

The original plugin used the g_isMapChange Bool handle and OnMapStart OnMapEnd to determine if the map was changing.

I am testing this version:

PHP Code:
#include <sourcemod>

new bool:g_isMapChange false;

public 
Plugin:myinfo 
{
    
name "Empty Server Restarter",
    
author "Visual77 / B-Man",
    
description "Restarts servers when last player disconnected",
    
version "1.0.0",
    
url "www.sourcemod.net"
}


public 
OnClientDisconnect(client)
{
    if (
IsFakeClient(client) || g_isMapChange)
        return;
    
    
// If no real players are left in game
    
if (!RealPlayersInGame(client))
    {            
        
GameEnded();
    }
}

public 
OnMapStart()
{
    
g_isMapChange false;
}

public 
OnMapEnd()
{
    
g_isMapChange true;
}

GameEnded()
{        
    
CreateTimer(1.5RestartServerDelay);
}

public 
Action:RestartServerDelay(Handle:timer)
{
    
RestartServer();
}

RestartServer()
{
    
ServerCommand("quit");
}

bool:RealPlayersInGame (client)
{    
    new 
i;
    for (
i=1;i<=GetMaxClients();i++)
    {
        if (
!= client)
        {
            if (
IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
                return 
true;
        }
    }
    
    return 
false;


Last edited by bman87; 02-19-2010 at 09:16.
bman87 is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 02-19-2010 , 10:39   Re: [L4D2] Server Auto-Restart
Reply With Quote #4

i dont think you want the isfakeclient check in onclientdisconnect

when a server hibernates - it disconnects all bots.

i dont think you need isclientingame in the check in realplayersingame - if someone is connected, but not in game yet, your going to shutdown the server on them while they are loading.

Last edited by dirka_dirka; 02-19-2010 at 10:41.
dirka_dirka is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 02-19-2010 , 10:52   Re: [L4D2] Server Auto-Restart
Reply With Quote #5

Quote:
Originally Posted by bman87 View Post
Didn't Work. In my logs I see that clients were disconnected Reason: "Server is shutting down".

The original plugin used the g_isMapChange Bool handle and OnMapStart OnMapEnd to determine if the map was changing.
Ok, I know what you mean. I'll try work it out.

Last edited by Visual77; 02-19-2010 at 11:14.
Visual77 is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 02-19-2010 , 11:39   Re: [L4D2] Server Auto-Restart
Reply With Quote #6

I believe I did something wrong when checking the clients, which would result in being kicked at mapchange. Try this one:
Code:
#include <sourcemod>

public OnClientDisconnect(client)
{
    CreateTimer(1.5, GameEnded);
}

public Action:GameEnded(Handle:timer)
{
    if (!RealPlayersInGame())
    { 
        ServerCommand("quit");
    }
}

stock bool:RealPlayersInGame()
{
    for (new i = 1; i <= MaxClients; i++)
    {
        if (IsClientConnected(i) && !IsFakeClient(i))
        {
            return true;
        }
    }
    return false;
}
Visual77 is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 02-20-2010 , 19:21   Re: [L4D2] Server Auto-Restart
Reply With Quote #7

so is the new bit o code working? i might end up using it myself if it does... broken heartbeat makes it real tough to get back into the server quickly after a scavenge map.
dirka_dirka is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 02-21-2010 , 01:01   Re: [L4D2] Server Auto-Restart
Reply With Quote #8

Quote:
Originally Posted by dirka_dirka View Post
so is the new bit o code working? i might end up using it myself if it does... broken heartbeat makes it real tough to get back into the server quickly after a scavenge map.
I havn't had much time to test it. From what I have seen so far its hit and miss. I kicked out everyone from my server and it restarted. But when a group of people quit or return to lobby I don't think it restarts.
bman87 is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 02-21-2010 , 02:35   Re: [L4D2] Server Auto-Restart
Reply With Quote #9

Just a tip; OnClientDisconnect_Post should fire after the has left. So it would be a cleaner way to do what you're trying to do.

Code:
#include <sourcemod>

public OnClientDisconnect_Post
{
    for (new client = 1; client <= MaxClients; client++)
    {
        if (IsClientConnected(client) && !IsFakeClient(client))
            return;
    }

    ServerCommand("quit");
}

I don't see why that wouldn't work or how it would be shutting down with players in the server.
__________________
Greyscale is offline
bman87
Senior Member
Join Date: Dec 2008
Location: Michigan
Old 02-22-2010 , 00:22   Re: [L4D2] Server Auto-Restart
Reply With Quote #10

Quote:
Originally Posted by Visual77 View Post
I believe I did something wrong when checking the clients, which would result in being kicked at mapchange. Try this one:
Code:
#include <sourcemod>

public OnClientDisconnect(client)
{
    CreateTimer(1.5, GameEnded);
}

public Action:GameEnded(Handle:timer)
{
    if (!RealPlayersInGame())
    { 
        ServerCommand("quit");
    }
}

stock bool:RealPlayersInGame()
{
    for (new i = 1; i <= MaxClients; i++)
    {
        if (IsClientConnected(i) && !IsFakeClient(i))
        {
            return true;
        }
    }
    return false;
}
Its not working for some reason..
I do not see any quit messages in the log

Code:
00:11:42 L 02/21/2010 - 23:11:33: "sneakysneaky ninja<25><STEAM_1:1:XXXXXXXX><Infected>" disconnected (reason "Disconnect by user.")
00:11:42 L 02/21/2010 - 23:11:33: "Nick<62><BOT><Survivor>" disconnected (reason "Punting bot, server is hibernating")
00:11:42 L 02/21/2010 - 23:11:33: "Coach<64><BOT><Survivor>" disconnected (reason "Punting bot, server is hibernating")
00:11:42 L 02/21/2010 - 23:11:33: "Tank<63><BOT><Infected>" disconnected (reason "Punting bot, server is hibernating")
00:11:42 L 02/21/2010 - 23:11:33: "Ellis<61><BOT><Survivor>" disconnected (reason "Punting bot, server is hibernating")
00:11:42 L 02/21/2010 - 23:11:33: "Rochelle<60><BOT><Survivor>" disconnected (reason "Punting bot, server is hibernating")
00:11:42 L 02/21/2010 - 23:11:33: RestartScenarioFromVote - changing to map c1m1_hotel
00:11:42 L 02/21/2010 - 23:11:33: Preparing player entities for changelevel
00:11:42 L 02/21/2010 - 23:11:33: Staying on original map c1m1_hotel
00:11:42 L 02/21/2010 - 23:11:33: Preventing spawning
00:11:42 L 02/21/2010 - 23:11:33: CDirector::RunScript, director_base, level: 0
00:11:42 L 02/21/2010 - 23:11:33: World triggered "Round_Start"
bman87 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode