Exemplo n.º 1
0
        private void ChannelContinue(PacketHandlerContext ctx, IChannel channel, string text)
        {
            if (channel == null
                //  || !ChannelUsers.HasUser(channel, ctx.User) look below
                //  || (ctx.User.IsSilenced && !ctx.User.Can(UserPermissions.SilenceUser)) TODO: readd silencing
                )
            {
                return;
            }

            ChannelUsers.HasSession(channel, ctx.Session, hasSession => {
                if (!hasSession)
                {
                    return;
                }

                if (ctx.User.Status != UserStatus.Online)
                {
                    Users.Update(ctx.User, status: UserStatus.Online);
                    // ChannelUsers?
                    //channel.SendPacket(new UserUpdatePacket(ctx.User));
                }

                // there's a very miniscule chance that this will return a different value on second read
                int maxLength = Messages.TextMaxLength;
                if (text.Length > maxLength)
                {
                    text = text.Substring(0, maxLength);
                }

                text = text.Trim();

#if DEBUG
                Logger.Write($@"<{ctx.Session.SessionId} {ctx.User.UserName}> {text}");
#endif

                bool handled = false;

                if (text[0] == '/')
                {
                    try {
                        handled = HandleCommand(text, ctx.User, channel, ctx.Session, ctx.Connection);
                    } catch (CommandException ex) {
                        ctx.Connection.SendPacket(ex.ToPacket(Bot));
                        handled = true;
                    }
                }

                if (!handled)
                {
                    Messages.Create(ctx.Session, channel, text);
                }
            });
        }