View Single Post
Author Message
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 08-11-2018 , 13:23   The operating system of server
Reply With Quote #1

PHP Code:
/**
 * List of operation systems.
 **/
enum EngineOS
{
    
OS_Unknown,
    
OS_Windows,
    
OS_Linux,
    
OS_Mac
};

EngineOS Server_PlatForm;

/**
 * Gets the server operating system.
 *
 * @param oS                The platform id.
 *
 * @return                  True or false.
 **/
bool GameEnginePlatform(EngineOS oS)
{
    
// Validate platform
    
if(Server_PlatForm == OS_Unknown)
    {
        
// Initialize char
        
char sBuffer[PLATFORM_MAX_PATH+PLATFORM_MAX_PATH];
        
        
// Extract status string
        
ServerCommandEx(sBuffersizeof(sBuffer), "status");

        
// Precompile a regular expression
        
Regex hRegex CompileRegex("(os\\s+:\\s+\\w+)"); 
        
        
// i = str index
        
int iCount hRegex.Match(sBuffer); 
        for(
int i 0iCounti++) 
        { 
            
// Returns a matched substring from a regex handle
            
hRegex.GetSubString(isBuffersizeof(sBuffer)); 
            
            
// Finds the first occurrence of a character in a string
            
int iSystem FindCharInString(sBuffer' 'true) + 1;

            
// Validate operating system
            
Server_PlatForm = !strncmp(sBuffer[iSystem], "win"3false) ? OS_Windows : !strncmp(sBuffer[iSystem], "lin"3false) ? OS_Linux OS_Mac;
            break;
        }
        
        
// Decompile expression
        
delete hRegex;
    }
    
    
// Return on success
    
return (Server_PlatForm == oS);

__________________
gubka is offline
Send a message via ICQ to gubka