Exemplo n.º 1
0
        internal virtual void HandleActorRemoteMethodCall(INetworkMessageIn msg)
        {
            int  id             = msg.ReadInt();
            int  methodKey      = msg.ReadInt();
            byte parameterCount = msg.ReadByte();

            var parameters = new object[parameterCount];

            for (byte i = 0; i < parameterCount; i++)
            {
                var type = (NetworkRemoteCallParameterType)msg.ReadByte();
                switch (type)
                {
                case NetworkRemoteCallParameterType.Int:
                    parameters[i] = msg.ReadInt();
                    break;

                case NetworkRemoteCallParameterType.Float:
                    parameters[i] = msg.ReadFloat();
                    break;

                case NetworkRemoteCallParameterType.String:
                    parameters[i] = msg.ReadString();
                    break;

                case NetworkRemoteCallParameterType.Boolean:
                    parameters[i] = msg.ReadBool();
                    break;
                }
            }

            try
            {
                if (_remoteMethods.ContainsKey(methodKey))
                {
                    var actor = Actors.FirstOrDefault(a => a.Id == id);
                    actor?.GetType().InvokeMember(_remoteMethods[methodKey], BindingFlags.InvokeMethod, null, actor, parameters);
                }
            }
            catch
            {
                // todo: throw?
            }
        }
        internal override void HandleServerTravel(INetworkMessageIn msg)
        {
            var newGameState      = msg.ReadByte();
            var worldBuilderClass = msg.ReadString();
            var levelName         = msg.ReadString();

            Actors.Clear();

            ChangeGameState(newGameState, levelName);

            var outMessage = CreateMessage(NetworkMessageType.ServerTravel);

            SendMessageToAll(outMessage, MessageDeliveryMethod.ReliableOrdered, 2);
        }