Raised This Month: $140 Target: $400
 35% 

The operating system of server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gubka
Veteran Member
Join Date: Jan 2012
Location: Dublin
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 Send a message via Skype™ to gubka
MasterMind420
Veteran Member
Join Date: Nov 2010
Old 08-14-2018 , 12:48   Re: The operating system of server
Reply With Quote #2

Just an fyi...There is a generic sourcemod event u can hook that will allow u to get the servers operating system with a lot less code. server_start i believe...but not 100 sure on the event name.

Last edited by MasterMind420; 08-14-2018 at 12:49.
MasterMind420 is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 08-14-2018 , 13:46   Re: The operating system of server
Reply With Quote #3

Addendum to what MasterMind said https://wiki.alliedmods.net/Generic_...s#server_spawn.

Though im not sure if over the years OSX got added.

Last edited by xerox8521; 08-14-2018 at 13:46.
xerox8521 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 08-14-2018 , 20:46   Re: The operating system of server
Reply With Quote #4

Unless there's some major API gap, you shouldn't need to care what OS is from SourceMod. May I ask what the use case is?
psychonic is offline
MasterMind420
Veteran Member
Join Date: Nov 2010
Old 08-14-2018 , 21:53   Re: The operating system of server
Reply With Quote #5

Quote:
Originally Posted by psychonic View Post
Unless there's some major API gap, you shouldn't need to care what OS is from SourceMod. May I ask what the use case is?
I know that if I wanted to I could use OS detection to merge L4D2 Thirpersonshoulder Shotgun Sound Fix. I think using EmitGameSoundToClient on windows caused crashes so I made two versions one for windows which uses EmitSoundToClient and linux which uses EmitGameSoundToClient. On a side not original poster the server_spawn event in the documentation says WIN32 or LINUX nothing about MAC so if this does indeed detect it then it would be better to use your function if someone has need for that.
MasterMind420 is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-14-2018 , 22:18   Re: The operating system of server
Reply With Quote #6

Should it not return the OS as opposed to bool result? If I was to code this, I would rather have a function that can get the os name without providing any parameter.
__________________
Spirit_12 is offline
Reply


Thread Tools
Display Modes

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 18:05.


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