AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   The operating system of server (https://forums.alliedmods.net/showthread.php?t=309898)

gubka 08-11-2018 13:23

The operating system of server
 
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);



MasterMind420 08-14-2018 12:48

Re: The operating system of server
 
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.

xerox8521 08-14-2018 13:46

Re: The operating system of server
 
Addendum to what MasterMind said https://wiki.alliedmods.net/Generic_...s#server_spawn.

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

psychonic 08-14-2018 20:46

Re: The operating system of server
 
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?

MasterMind420 08-14-2018 21:53

Re: The operating system of server
 
Quote:

Originally Posted by psychonic (Post 2610238)
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.

Spirit_12 08-14-2018 22:18

Re: The operating system of server
 
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.

Silvers 08-24-2018 07:41

Re: The operating system of server
 
Quote:

Originally Posted by psychonic (Post 2610238)
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. :roll:

Peace-Maker 08-24-2018 10:53

Re: The operating system of server
 
Quote:

Originally Posted by Silvers (Post 2611966)
which is more confusing to end users who don't read or have much computer/sourcemod knowledge. :roll:

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?

Silvers 08-24-2018 11:45

Re: The operating system of server
 
Quote:

Originally Posted by Peace-Maker (Post 2611991)
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.

klippy 08-30-2018 03:15

Re: The operating system of server
 
Quote:

Originally Posted by Silvers (Post 2612006)
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.


All times are GMT -4. The time now is 00:57.

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