Guest User

Untitled

a guest
Apr 5th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. // Network.cs
  2. // Basically this is the only class that is actually "synced" across the network the old-fashioned way
  3. // This class will call own functions across network via registered server connection,
  4. // or client connections.
  5.  
  6. // Warning, heavy pseudocode here!
  7. public static class Network
  8. {
  9.     public static bool AreWeServer;
  10.  
  11.     // At initialization, spawning of entities will always register them with this dictionary
  12.     private static Dictionary<int, Entity> NetworkedEntites;
  13.  
  14.  
  15.     // =============
  16.     //  Client Side code
  17.     // =============
  18.     public static void InvokeCommand(int NID, int commandIndex, object arg)
  19.     {
  20.         -serialize args into packet
  21.         -send packet to server connection
  22.         -this will invoke "AcceptCommand" on server-side Network
  23.     }
  24.  
  25.     public static void AcceptVar(byte[] data)
  26.     {
  27.         -deserialize NID, index and value from data
  28.  
  29.         Entity target;
  30.         if (NetworkedEntites.TryGet(NID, out target))
  31.         {
  32.             target.ReplicateVarFromServer(index, value);
  33.         }
  34.     }
  35.     // -----------------
  36.  
  37.     // =============
  38.     //  Server Side code
  39.     // =============
  40.     public static void ReplicateVar(int NID, int varIndex, object value)
  41.     {
  42.         -serialize args into packet
  43.         -for all opened connections
  44.         -send args
  45.         - this will invoke "AcceptVar" on all cliend-side Network instances
  46.     }
  47.  
  48.     public static void AcceptCommand(byte[] data)
  49.     {
  50.         -deserialize NID, index and value from data
  51.  
  52.         Entity target;
  53.         if (NetworkedEntites.TryGet(NID, out target))
  54.         {
  55.             target.InvokeFunctionWithArg(index, value);
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment