public virtual void OnNeutronStart() { if (_hasOnAutoSynchronization) { NeutronStream packetStream = GetPacketStream(); if (packetStream == null && _onAutoSynchronizationOptions.FixedSize) { throw new Exception("AutoSync: Packet stream not implemented!"); } if (packetStream != null && !packetStream.IsFixedSize && _onAutoSynchronizationOptions.FixedSize) { LogHelper.Warn("AutoSync: The stream has no fixed size! performance is lower if you send with very frequency."); } } foreach (iRpcOptions option in _iRpcOptions) { //* Add the iRPC options to the runtime dictionary. if (option.Instance.Id == Id) { RuntimeIRpcOptions.Add(option.RpcId, option); //* If the instance id is the same as the object id, add the option to the runtime dictionary. } else { NeutronView.NeutronBehaviours[option.Instance.Id].RuntimeIRpcOptions.Add(option.RpcId, option); //* If the instance id is different, add the option to the runtime dictionary of the instance. } } IsRegistered = true; //* Set the object as registered. }
protected virtual void OnNeutronUpdate() { if (_hasOnAutoSynchronization) { _autoSyncTimeDelay += Time.deltaTime; //* Decrease the auto-sync delay. if (_autoSyncTimeDelay >= _onAutoSynchronizationOptions.SendRate) { NeutronStream packetStream = GetPacketStream(); if (AutoSyncAuthority) { if (!_onAutoSynchronizationOptions.FixedSize) { using (NeutronStream stream = Neutron.PooledNetworkStreams.Pull()) { stream.Writer.SetPosition(PacketSize.AutoSync); //* Set the position of the stream to the auto-sync packet size. if (OnAutoSynchronization(stream, true)) { This.OnAutoSynchronization(stream, NeutronView, Id, _onAutoSynchronizationOptions.Protocol, IsServer); //* Send the auto-sync packet. } } } else { //* If the stream has a fixed size, send the auto-sync packet with the fixed size. packetStream.Writer.SetPosition(PacketSize.AutoSync); //* Set the position of the stream to the auto-sync packet size. if (OnAutoSynchronization(packetStream, true)) { This.OnAutoSynchronization(packetStream, NeutronView, Id, _onAutoSynchronizationOptions.Protocol, IsServer); //* Send the auto-sync packet. } } } _autoSyncTimeDelay = 0; //* Set the auto-sync delay per second. } } }
/// <summary> ///* Envia o estado da autenticação ao seu usuário. /// </summary> /// <param name="user">* O usuário a ser autenticado.</param> /// <param name="authStatus">* O estado da autenticação</param> /// <returns></returns> protected bool OnAuth(NeutronPlayer user, bool authStatus) { user.Properties = string.IsNullOrEmpty(user.Properties) ? "{\"Neutron\":\"Neutron\"}" : user.Properties; using (NeutronStream stream = Neutron.PooledNetworkStreams.Pull()) { NeutronStream.IWriter writer = stream.Writer; writer.WritePacket((byte)Packet.AuthStatus); writer.Write(user.Properties); writer.Write(authStatus); user.Write(writer); } return(authStatus); }
/// <summary> ///* Ends a gRPC(Global Remote Procedure Call) service call.<br/> ///* (from server-side) use this overload to send from server to client. /// </summary> /// <param name="id">The id of the gRPC service.</param> /// <param name="parameters">The parameters that will be sent with the service.</param> /// <param name="protocol">The protocol used to send the service.</param> /// <param name="player">The player that will send the service.</param> public void End_gRPC(byte id, NeutronStream parameters, Protocol protocol, NeutronPlayer player) { Server.End_gRPC(id, parameters, protocol, player); }
/// <summary> ///* Ends a gRPC(Global Remote Procedure Call) service call.<br/> ///* (from client-side) use this overload to send from client to server. /// </summary> /// <param name="id">The id of the gRPC service.</param> /// <param name="parameters">The parameters that will be sent with the service.</param> /// <param name="protocol">The protocol used to send the service.</param> /// <param name="neutron">The neutron instance that will be responsible for ending the service.</param> public void End_gRPC(byte id, NeutronStream parameters, Protocol protocol, Neutron neutron) { neutron.End_gRPC(id, parameters, protocol); }
/// <summary> ///* Initiates a gRPC(Global Remote Procedure Call) service call.<br/> ///* (from server-side) use this overload to send from server to client. /// </summary> /// <param name="parameters">The parameters that will be sent with the service.</param> /// <returns></returns> public NeutronStream.IWriter Begin_gRPC(NeutronStream parameters) => Server.Begin_gRPC(parameters);
/// <summary> ///* Initiates a gRPC(Global Remote Procedure Call) service call.<br/> ///* (from client-side) use this overload to send from client to server. /// </summary> /// <param name="parameters">The parameters that will be sent with the service.</param> /// <param name="neutron">The neutron instance that will be responsible for starting the service.</param> /// <returns></returns> public NeutronStream.IWriter Begin_gRPC(NeutronStream parameters, Neutron neutron) => neutron.Begin_gRPC(parameters);