This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
client_server_detection [2019/08/26 03:58] – created korshun | client_server_detection [2019/08/26 21:36] – korshun | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Clientside/Serverside | + | ====== Clientside/serverside |
+ | |||
+ | ===== Introduction | ||
You can check if a script is running serverside, clientside or in singleplayer using functions provided by ACSUtils. | You can check if a script is running serverside, clientside or in singleplayer using functions provided by ACSUtils. | ||
+ | |||
===== Terminology ===== | ===== Terminology ===== | ||
* **Server** -- an engine instance that runs the gameplay code. | * **Server** -- an engine instance that runs the gameplay code. | ||
- | * **Client** -- an engine instance that runs the rendering code and provides input to the server. | + | * **Client** -- an engine instance that runs the rendering code and controls a player on the server. |
In singleplayer, | In singleplayer, | ||
+ | In ZDoom and GZDoom multiplayer (but not Zandronum' | ||
+ | |||
+ | Zandronum multiplayer emulation is singleplayer. Just like in singleplayer, | ||
+ | |||
+ | In real Zandronum multiplayer, | ||
+ | |||
+ | Yet, if Zandronum were to allow hosting non-dedicated servers, where a player allows others to connect to their singleplayer game without launching a separate engine instance, the hosting player would be both a server and a client, while other players in the game would be only clients. | ||
+ | |||
+ | |||
+ | ===== Functions ===== | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | |||
+ | ===== Writing robust multiplayer code ===== | ||
+ | |||
+ | The definitions above enable writing ACS code that functions correctly in both singleplayer and multiplayer without singleplayer being a special case. Using '' | ||
+ | |||
+ | <code acs> | ||
+ | if (IsServer()) | ||
+ | { | ||
+ | // Run serverside gameplay code. | ||
+ | } | ||
+ | if (IsClient()) | ||
+ | { | ||
+ | // Draw hud, spawn effects. | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== How it works ===== | ||
+ | |||
+ | All detection of clients and servers is founded on two functions: [[zdoom> | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | It checks if the multiplayer is real using [[zan> | ||
+ | |||
+ | If the engine is not Zandronum, the function returns true, because in ZDoom/ | ||
+ | |||
+ | If the engine is Zandronum, the functions returns false if it's real multiplayer, | ||
+ | |||
+ | '' | ||