Differences

This shows you the differences between two versions of the page.

Link to this comparison view

client-server_architecture [2014/10/20 00:56] (current)
chris created
Line 1: Line 1:
 +====== Client-Server Architecture ======
 +One of the key things you'll notice with the client-server architecture in Empeld is that we both try to reuse the same code wherever possible, while maintaining good separation where needed. ​ One key example of this is using the same Entity classes for both client and server, but completely separating subsystems (that are only applicable to one or the other).
  
 +===== Communicating Between Client and Server =====
 +
 +There are two ways to communicate between client and server. ​ Both methods account for indianship of the operating system, and are very low-bandwidth in their operation.
 +
 +==== Entity Syncables ====
 +Entity syncables are a special type of class that implements INetSyncable and that the server will automatically synchronize between client and server. ​ There are several things to consider here, including security (We don't want cheaters), and frequency of the sync.  These types of variables only work for Entities, and is the best way to communicate. ​ Read more about them here: [[Syncables]]
 +
 +==== Remote Procedure Call (RPC) ====
 +RPC is a simple method in which one class, can call a method on an instance of the same class on the server, or by getting a reference to another class that is registered on the server. See [[RPC]] for details on how to use this.
 +
 +===== Good Practices =====
 +
 +==== Partial Breakup of Large Classes ====
 +One thing that we've found useful is to break up large classes, such as entities, by the type of service they provide. ​ We can do this using [[http://​msdn.microsoft.com/​en-us/​library/​wa80x488.aspx|partial classes]]. ​ In the case of entities, we usually have 3 parts: Common, Client, and Server; so we can break up into 3 files, like this:
 +
 +<file csharp MyEntity.cs>​
 +public partial class MyEntity : NewtonianBase
 +{
 +    //Common logic and syncables go here that both client and server access
 +
 +</​file>​
 +
 +<file csharp MyEntity.Client.cs>​
 +public partial class MyEntity
 +{
 +  //Client specific logic goes here, such as client RPC calls and 
 +  //Assume all logic here is subject to hacking and cheats
 +}
 +</​file>​
 +
 +<file csharp MyEntity.Server.cs>​
 +public partial class MyEntity
 +{
 +    //​Server-specific logic goes here, such as RPC calls, simulation, and any specific validation
 +    //This logic should verify all actions
 +}
 +</​file>​