This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
client_server_detection [2019/08/26 01:13] – [Terminology] korshun | client_server_detection [2019/09/05 20:54] (current) – [Writing robust multiplayer code] 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 ===== | ||
Line 12: | Line 15: | ||
In ZDoom and GZDoom multiplayer (but not Zandronum' | In ZDoom and GZDoom multiplayer (but not Zandronum' | ||
- | In regular | + | 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. | 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. | ||
Line 28: | Line 33: | ||
===== Writing robust multiplayer code ===== | ===== 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. Just make sure | + | 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. | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can also make sure that a serverside-only function is not called on the client, and a clientside-only function is not called on the server. | ||
+ | |||
+ | < | ||
+ | function ServersideOnlyFunction(void) | ||
+ | { | ||
+ | // writing if (IsClient()) would incorrectly display the warning in singleplayer. | ||
+ | if (!IsServer()) | ||
+ | printbold(s:" | ||
+ | |||
+ | ... | ||
+ | } | ||
+ | |||
+ | function ClientsideOnlyFunction(void) | ||
+ | { | ||
+ | // writing if (IsServer()) would incorrectly display the warning in singleplayer. | ||
+ | if (!IsClient()) | ||
+ | printbold(s:" | ||
+ | |||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== How it works ===== | ||
+ | |||
+ | All detection of clients and servers is founded on two functions: [[zdoom> | ||
- | ===== How the functions work ===== | + | '' |
- | All detection of clients and servers | + | '' |
- | '' | + | If the engine |
+ | If the engine is Zandronum, the function returns false if it's real multiplayer, | ||
+ | '' | ||