public IdleDisconnectProcessor(TimeSpan idleTimeout, INetChannel channel) { _lastReceivedTime = DateTime.UtcNow; Observable.Interval(TimeSpan.FromSeconds(1)).Subscribe(_ => KillIfIdle()); _idleTimeout = idleTimeout; _channel = channel; }
public MsgEntity(INetChannel channel) : base(NAME, GROUP, ID) { }
public void Thrown(ThrownEventArgs eventArgs) { SendNetworkMessage(new InstrumentStopMidiMessage()); _instrumentPlayer = null; _userInterface.CloseAll(); }
public void DisconnectChannel(INetChannel channel, string reason) { channel.Disconnect(reason); }
/// <inheritdoc /> public void ServerSendMessage(NetMessage message, INetChannel recipient) { var packet = BuildMessage(message); ServerSendMessage(packet, recipient.Connection); }
/// <summary> /// Receives messages to remove entities from storage, verifies the player can do them, /// and puts the removed entity in hand or on the ground /// </summary> /// <param name="message"></param> /// <param name="channel"></param> /// <param name="session"></param> public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null) { base.HandleNetworkMessage(message, channel, session); if (session == null) { throw new ArgumentException(nameof(session)); } switch (message) { case RemoveEntityMessage _: { _ensureInitialCalculated(); var playerentity = session.AttachedEntity; var ourtransform = Owner.GetComponent<ITransformComponent>(); var playertransform = playerentity.GetComponent<ITransformComponent>(); if (playertransform.GridPosition.InRange(_mapManager, ourtransform.GridPosition, 2) && (ourtransform.IsMapTransform || playertransform.ContainsEntity(ourtransform))) { var remove = (RemoveEntityMessage)message; var entity = _entityManager.GetEntity(remove.EntityUid); if (entity != null && storage.Contains(entity)) { Remove(entity); var item = entity.GetComponent<ItemComponent>(); if (item != null && playerentity.TryGetComponent(out HandsComponent hands)) { if (hands.PutInHand(item)) return; } entity.GetComponent<ITransformComponent>().WorldPosition = ourtransform.WorldPosition; } } break; } case InsertEntityMessage _: { _ensureInitialCalculated(); var playerEntity = session.AttachedEntity; var storageTransform = Owner.GetComponent<ITransformComponent>(); var playerTransform = playerEntity.GetComponent<ITransformComponent>(); // TODO: Replace by proper entity range check once it is implemented. if (playerTransform.GridPosition.InRange(_mapManager, storageTransform.GridPosition, InteractionSystem.InteractionRange)) { PlayerInsertEntity(playerEntity); } break; } case CloseStorageUIMessage _: { UnsubscribeSession(session as IPlayerSession); break; } } }
public void NetChannelRequestStarted(INetNode node, INetChannel channel, Message request, Guid requestId) { if (_logger.IsEnabled(LogEventLevel.Debug)) _logger.Debug("NetNode {@node} on NetChannel {@channel} sending request {@message} with id {requestId}", node, channel, request, requestId); }
public NetDisconnectedArgs(INetChannel channel, string reason) : base(channel) { Reason = reason; }
public void NetChannelDisconnected(INetNode node, INetChannel channel) { if (_logger.IsEnabled(LogEventLevel.Debug)) _logger.Debug("NetNode {@node} NetChannel {@channel} has disconnected", node, channel); }
public void ConnectionSucceeded(INetNode node, IPEndPoint address, INetChannel channel, int durationMs) { if (_logger.IsEnabled(LogEventLevel.Information)) _logger.Information("NetNode {@node} has connected to {@address} with {@channel} in {durationMs} ms", node, address, channel, durationMs); }
public void NetChannelSentMessage(INetNode node, INetChannel channel, Message message) { if (_logger.IsEnabled(LogEventLevel.Debug)) _logger.Debug("NetChannel {@channel} has sent message {@message}", channel, message); }
public void NetChannelRequestTimedOut(INetNode node, INetChannel channel, Message message, Guid requestId, int durationMs) { if (_logger.IsEnabled(LogEventLevel.Warning)) _logger.Warning("NetChannel {@channel} has timed out within {durationMs} ms on sending request {@message} {requestId}", channel, durationMs, message, requestId); }
public void OperationProcessed(INetNode node, INetChannel channel, IOperationContext operation) { if (_logger.IsEnabled(LogEventLevel.Information)) _logger.Information("NetNode {@node} on NetChannel {@channel} processed {@operation}", node, channel, operation); }
public NetCommunicationClient(INetChannel channel) { Channel = channel; }
public void NetChannelSentReplyMessage(INetNode node, INetChannel channel, Message reply, IOperationContext operation) { if (_logger.IsEnabled(LogEventLevel.Debug)) _logger.Debug("NetNode {@node} on NetChannel {@channel} sent reply {@message} for operation {@operation}", node, channel, reply, operation); }
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession?session = null) { base.HandleNetworkMessage(message, netChannel, session); if (message is not BasePerformActionMessage performActionMessage) { return; } if (session == null) { throw new ArgumentNullException(nameof(session)); } var player = session.AttachedEntity; if (player != Owner) { return; } var attempt = ActionAttempt(performActionMessage, session); if (attempt == null) { return; } if (!attempt.TryGetActionState(this, out var actionState) || !actionState.Enabled) { Logger.DebugS("action", "user {0} attempted to use" + " action {1} which is not granted to them", player.Name, attempt); return; } if (actionState.IsOnCooldown(GameTiming)) { Logger.DebugS("action", "user {0} attempted to use" + " action {1} which is on cooldown", player.Name, attempt); return; } switch (performActionMessage.BehaviorType) { case BehaviorType.Instant: attempt.DoInstantAction(player); break; case BehaviorType.Toggle: if (performActionMessage is not IToggleActionMessage toggleMsg) { return; } if (toggleMsg.ToggleOn == actionState.ToggledOn) { Logger.DebugS("action", "user {0} attempted to" + " toggle action {1} to {2}, but it is already toggled {2}", player.Name, attempt.Action.Name, toggleMsg.ToggleOn); return; } if (attempt.DoToggleAction(player, toggleMsg.ToggleOn)) { attempt.ToggleAction(this, toggleMsg.ToggleOn); } else { // if client predicted the toggle will work, need to reset // that prediction Dirty(); } break; case BehaviorType.TargetPoint: if (performActionMessage is not ITargetPointActionMessage targetPointMsg) { return; } if (!CheckRangeAndSetFacing(targetPointMsg.Target, player)) { return; } attempt.DoTargetPointAction(player, targetPointMsg.Target); break; case BehaviorType.TargetEntity: if (performActionMessage is not ITargetEntityActionMessage targetEntityMsg) { return; } if (!EntityManager.TryGetEntity(targetEntityMsg.Target, out var entity)) { Logger.DebugS("action", "user {0} attempted to" + " perform target entity action {1} but could not find entity with " + "provided uid {2}", player.Name, attempt.Action.Name, targetEntityMsg.Target); return; } if (!CheckRangeAndSetFacing(entity.Transform.Coordinates, player)) { return; } attempt.DoTargetEntityAction(player, entity); break; case BehaviorType.None: break; default: throw new ArgumentOutOfRangeException(); } }
public void OperationProcessingFailed(INetNode node, INetChannel channel, IOperationContext operation, Exception exception) { if (_logger.IsEnabled(LogEventLevel.Warning)) _logger.Warning("NetNode {@node} on NetChannel {@channel} failed to process operation {@operation} with {@exception}", node, channel, operation, exception); }
/// <inheritdoc /> public void SendDirectedComponentNetworkMessage(INetChannel channel, IEntity entity, IComponent component, ComponentMessage message) { throw new NotImplementedException(); }
static void OnRoomLeave(INetChannel channel) { RoomMember member; if (RoomMembers.TryGetValue(channel, out member)) { List<RoomMember> members; if (Rooms.TryGetValue(member.RoomName, out members)) { members.Remove(member); members.ForEach((m) => m.UserChannel.Send(new RoomEvent() { UserName = member.UserName, Text = "Left" })); } } }
protected virtual void OnDisconnected(INetChannel channel) { Disconnect?.Invoke(this, new NetChannelArgs(channel)); }
async Task OnRoomLeave(INetChannel channel) { RoomMember member; if (RoomMembers.TryGetValue(channel, out member)) { var newEvent = new RoomEvent() { UserName = member.UserName, Text = "Left" }; RoomData room; if (Rooms.TryGetValue(member.RoomName, out room)) { room.Members.Remove(member); room.Members.ForEach(m => m.UserChannel.Send(newEvent)); room.History.Add(newEvent); using (var tx = StateManager.CreateTransaction()) { await _roomsState.SetAsync(tx, room.Name, room); await tx.CommitAsync(); } } } }
public void NetChannelIsDisposing(INetNode node, INetChannel channel) { if (_logger.IsEnabled(LogEventLevel.Debug)) _logger.Debug("NetChannel {@channel} is closing", channel); }
public MsgScriptStop(INetChannel channel) : base(NAME, GROUP) { }
public MsgState(INetChannel channel) : base(NAME, GROUP) { }
public MsgRay(INetChannel channel) : base(NAME, GROUP) { }
public MsgServerInfoReq(INetChannel channel) : base(NAME, GROUP) { }
public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message) { base.HandleNetMessage(channel, message); switch (message) { case RequestVerbsMessage req: { if (!_entityManager.TryGetEntity(req.EntityUid, out var entity)) { return; } var session = _playerManager.GetSessionByChannel(channel); var userEntity = session.AttachedEntity; var data = new List <VerbsResponseMessage.VerbData>(); //Get verbs, component dependent. foreach (var(component, verb) in VerbUtility.GetVerbs(entity)) { if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity)) { continue; } if (VerbUtility.IsVerbInvisible(verb, userEntity, component, out var vis)) { continue; } // TODO: These keys being giant strings is inefficient as hell. data.Add(new VerbsResponseMessage.VerbData(verb.GetText(userEntity, component), $"{component.GetType()}:{verb.GetType()}", vis == VerbVisibility.Visible)); } //Get global verbs. Visible for all entities regardless of their components. foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly())) { if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity)) { continue; } if (VerbUtility.IsVerbInvisible(globalVerb, userEntity, entity, out var vis)) { continue; } data.Add(new VerbsResponseMessage.VerbData(globalVerb.GetText(userEntity, entity), globalVerb.GetType().ToString(), vis == VerbVisibility.Visible)); } var response = new VerbsResponseMessage(data, req.EntityUid); RaiseNetworkEvent(response, channel); break; } case UseVerbMessage use: { if (!_entityManager.TryGetEntity(use.EntityUid, out var entity)) { return; } var session = _playerManager.GetSessionByChannel(channel); var userEntity = session.AttachedEntity; foreach (var(component, verb) in VerbUtility.GetVerbs(entity)) { if ($"{component.GetType()}:{verb.GetType()}" != use.VerbKey) { continue; } if (verb.RequireInteractionRange) { var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition) .LengthSquared; if (distanceSquared > VerbUtility.InteractionRangeSquared) { break; } } verb.Activate(userEntity, component); break; } foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly())) { if (globalVerb.GetType().ToString() != use.VerbKey) { continue; } if (globalVerb.RequireInteractionRange) { var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition) .LengthSquared; if (distanceSquared > VerbUtility.InteractionRangeSquared) { break; } } globalVerb.Activate(userEntity, entity); break; } break; } } }
public MsgStateAck(INetChannel channel) : base(NAME, GROUP, ID) { }
IPlayerSession IPlayerManager.GetSessionByChannel(INetChannel channel) => GetSessionByChannel(channel);
public MsgDeleteCharacter(INetChannel channel) : base(NAME, GROUP) { }
public void SendPrivateMessage(INetChannel client, ChatChannel channel, string text, string name, int?entityId) { MsgChat message = MakeNetChatMessage(channel, text, name, entityId); IoCManager.Resolve <IServerNetManager>().ServerSendMessage(message, client); }
public MsgScriptResponse(INetChannel channel) : base(NAME, GROUP) { }
private void ProcessEmote(string text, string name, ChatChannel channel, int?entityId, INetChannel client) { if (entityId == null) { return; //No emotes from non-entities! } var args = new List <string>(); CommandParsing.ParseArguments(text, args); if (_emotes.ContainsKey(args[0])) { // todo make a user-only channel that only the sender can see i.e. for emotes and game feedback ('you put the coins in the jar' or whatever) var otherText = String.Format(_emotes[args[0]].OtherText, name, "his"); //todo pronouns, gender SendChatMessage(ChatChannel.Emote, otherText, name, entityId); } else { //todo Bitch at the user } }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="channel">The channel causing the event.</param> public NetChannelArgs(INetChannel channel) { Channel = channel; }
/// <summary> /// Processes commands (chat messages starting with /) /// </summary> /// <param name="text">Text content.</param> /// <param name="name">Player name that sent the chat text.</param> /// <param name="channel">Channel message was received on.</param> /// <param name="client">Client that sent the command.</param> private void ProcessCommand(string text, string name, ChatChannel channel, int?entityId, INetChannel client) { List <string> args = new List <string>(); CommandParsing.ParseArguments(text.Substring(1), args); // Parse, but cut out the first character (/). if (args.Count <= 0) { return; } string command = args[0]; if (!_commands.ContainsKey(command)) { string message = string.Format("Command '{0}' not found.", command); SendPrivateMessage(client, ChatChannel.Default, message, "Server", null); return; } _commands[command].Execute(this, client, args.ToArray()); }
public MsgChatMessage(INetChannel channel) : base(NAME, GROUP) { }
public MsgMapReq(INetChannel channel) : base(NAME, GROUP, ID) { }
public MsgViewVariablesDenySession(INetChannel channel) : base(NAME, GROUP) { }
public IPlayerSession GetSessionByChannel(INetChannel client) { // Should only be one session per client. Returns that session, in theory. return(_sessions.FirstOrDefault(s => s?.ConnectedClient == client)); }
protected virtual void OnConnected(INetChannel channel) { Connected?.Invoke(this, new NetChannelArgs(channel)); }
public MsgConCmd(INetChannel channel) : base(NAME, GROUP) { }
public MsgPreferencesAndSettings(INetChannel channel) : base(NAME, GROUP) { }
public MsgConGroupUpdate(INetChannel channel) : base(Name, Group) { }
public static IMessageProcessingPipeBuilder UseIdleDisconnect(this IMessageProcessingPipeBuilder builder, TimeSpan idleDisconnectTimeout, INetChannel channel) { var mp = new IdleDisconnectProcessor(idleDisconnectTimeout, channel); return builder.Use(next => context => mp.Process(next, context)); }
public void NetChannelRequestCompleted(INetNode node, INetChannel channel, Message message, Guid requestId, int durationMs) { if (_logger.IsEnabled(LogEventLevel.Information)) _logger.Information("NetNode {@node} NetChannel {@channel} is received reply {@message} for {requestId} in {durationMs} ms", node, channel, message, requestId, durationMs); }