Raised This Month: $71 Target: $400
 17% 

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 , 14: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 , 13: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 13:49.
MasterMind420 is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 08-14-2018 , 14: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 14:46.
xerox8521 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 08-14-2018 , 21: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 , 22: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 , 23: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
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 08-24-2018 , 08:41   Re: The operating system of server
Reply With Quote #7

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?
As example: I created a plugin to fix Windows server crash and used the gamedata "offsets" section with a value of 1 for Windows. Linux returns -1 (doesn't exist) but this method is also frowned upon. So instead of an error saying "Fix not required for linux" it throws an incorrect offset error which is more confusing to end users who don't read or have much computer/sourcemod knowledge.
__________________
Silvers is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 08-24-2018 , 11:53   Re: The operating system of server
Reply With Quote #8

Quote:
Originally Posted by Silvers View Post
which is more confusing to end users who don't read or have much computer/sourcemod knowledge.
So the purpose of a way to get the server's operating system is to make it OK to not care and encourage users to not read documentation?
__________________
Peace-Maker is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 08-24-2018 , 12:45   Re: The operating system of server
Reply With Quote #9

Quote:
Originally Posted by Peace-Maker View Post
So the purpose of a way to get the server's operating system is to make it OK to not care and encourage users to not read documentation?
Some people tend to not read, even after being repeatedly told to.
__________________
Silvers is offline
KliPPy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-30-2018 , 04:15   Re: The operating system of server
Reply With Quote #10

Quote:
Originally Posted by Silvers View Post
Some people tend to not read, even after being repeatedly told to.
Let their servers crash, it's okay if they don't read the documentation.
__________________
KliPPy 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 08:38.


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