예제 #1
0
    public SerializableObjectFactory(Assembly[] assemblies, bool forServer)
    {
        var types = ReflectionHelpers.GetTypesThatImplementInterfaces(assemblies, new Type[] { typeof(SerializableObject) });

        foreach (var t in types)
        {
            var ctor = t.GetConstructor(System.Type.EmptyTypes);
            if (ctor != null)
            {
                var obj = ctor.Invoke(null) as SerializableObject;
                if ((forServer && (obj.serverType == t)) || (!forServer && (obj.clientType == t)))
                {
                    if (objTypes.Contains(obj.classID))
                    {
                        throw new System.Exception(t.FullName + " collides with an existing type!");
                    }
                    else
                    {
                        objTypes.Add(obj.classID, ctor);
                    }
                }
            }
            else
            {
                throw new TargetInvocationException(t.FullName + " does not have a constructor!", null);
            }
        }
    }
예제 #2
0
	void AddRPCMethods(Type t, BindingFlags flags) {
		var typeMethods = t.GetMethods(flags);
		foreach (var minfo in typeMethods) {
			var rpcAttrs = minfo.GetCustomAttributes(typeof(RPC), false);

			if (rpcAttrs.Length == 1) {
				var actualMethod = minfo.GetBaseDefinition();
				var sig = GenerateMethodSignature(actualMethod);
				if (!methods.ContainsKey(sig)) {
					int rpcID = methods.Count;
					methods.Add(sig, rpcID);
					var actorRPC = new ObjectRPCSerializer(rpcAttrs[0] as RPC, actualMethod);
					rpcIDToRPC.Add(rpcID, actorRPC);
				}
			}
		}
	}
예제 #3
0
    public NetMsgFactory(Assembly[] assemblies, bool forServer)
    {
        var types = ReflectionHelpers.GetTypesThatImplementInterfaces(assemblies, new[] { typeof(NetMsg) });

        foreach (var t in types)
        {
            var ctor = t.GetConstructor(System.Type.EmptyTypes);
            if (ctor != null)
            {
                var netMsg = ctor.Invoke(null) as NetMsg;
                if ((netMsg.isServerMsg && forServer) || (netMsg.isClientMsg && !forServer))
                {
                    if (netMsg.shareInstance != null)
                    {
                        netMsg = netMsg.shareInstance;
                    }
                    else
                    {
                        netMsg.Init();
                    }
                    if (netMsgs.Contains(netMsg.msgTypeID))
                    {
                        throw new System.Exception(t.FullName + " collides with an existing type!");
                    }
                    else
                    {
                        netMsgs.Add(netMsg.msgTypeID, netMsg);
                    }
                }
                else if (netMsg.shareInstance == null)
                {
                    netMsg.Init();                     // clients need to init server net messages to send.
                }
            }
            else
            {
                throw new TargetInvocationException(t.FullName + " does not have a constructor!", null);
            }
        }
    }
예제 #4
0
 public void Add(int k, V v)
 {
     hashtable.Add(k, v);
     list.Add(v);
 }