Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Network.cs
- // Basically this is the only class that is actually "synced" across the network the old-fashioned way
- // This class will call own functions across network via registered server connection,
- // or client connections.
- // Warning, heavy pseudocode here!
- public static class Network
- {
- public static bool AreWeServer;
- // At initialization, spawning of entities will always register them with this dictionary
- private static Dictionary<int, Entity> NetworkedEntites;
- // =============
- // Client Side code
- // =============
- public static void InvokeCommand(int NID, int commandIndex, object arg)
- {
- -serialize args into packet
- -send packet to server connection
- -this will invoke "AcceptCommand" on server-side Network
- }
- public static void AcceptVar(byte[] data)
- {
- -deserialize NID, index and value from data
- Entity target;
- if (NetworkedEntites.TryGet(NID, out target))
- {
- target.ReplicateVarFromServer(index, value);
- }
- }
- // -----------------
- // =============
- // Server Side code
- // =============
- public static void ReplicateVar(int NID, int varIndex, object value)
- {
- -serialize args into packet
- -for all opened connections
- -send args
- - this will invoke "AcceptVar" on all cliend-side Network instances
- }
- public static void AcceptCommand(byte[] data)
- {
- -deserialize NID, index and value from data
- Entity target;
- if (NetworkedEntites.TryGet(NID, out target))
- {
- target.InvokeFunctionWithArg(index, value);
- }
- }
- }
Add Comment
Please, Sign In to add comment