Exemple #1
0
        public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            var    oldName = info.Name;
            string newName = Helper.GetUserName(JoinArg(), info.GetRoom());

            if (!Helper.VerifyName(newName))
            {
                info.SendChatMessage("Invalid name.", Helper.ServerErrorColor);
                return;
            }

            if (oldName == newName)
            {
                info.SendChatMessage("You already have that name.", Helper.ServerErrorColor);
                return;
            }

            info.Name = newName;

            info.SendSetName(newName, room == null, newName == JoinArg());             // permanent = if true, the client will know this name is permanent, and not a rename. different from what's expected. (example: rename to Name, becomes Name(1))

            if (room != null)
            {
                room.SendChatMessageToAll(oldName + " changed name to " + newName + ".");
            }
            else
            {
                info.SendChatMessage("Name set to " + newName + ".");
            }
        }
Exemple #2
0
        public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            var roomName = JoinArg(0);

            if (!Helper.VerifyName(roomName))
            {
                info.SendChatMessage("Invalid room name.", Helper.ServerErrorColor);
                return;
            }

            if (!RoomManager.Exists(roomName))
            {
                RoomManager.CreateRoom(roomName, socket);
            }
            else
            {
                if (room != RoomManager.Rooms[roomName])
                {
                    RoomManager.AddUserToRoom(socket, roomName);
                }
                else
                {
                    info.SendChatMessage("You're already in this room.", Helper.ServerErrorColor);
                }
            }

            Console.WriteLine(info.Name + "(" + Helper.IPString(socket) + ") changed room to " + roomName + ".");
        }
Exemple #3
0
        public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            if (room.IsOwner(socket))
            {
                var targetUser = room.GetUser(JoinArg());

                if (targetUser != null)
                {
                    if (targetUser != socket)
                    {
                        room.KickUser(targetUser);
                    }
                    else
                    {
                        info.SendChatMessage("You can't kick yourself.", Helper.ServerErrorColor);
                    }
                }
                else
                {
                    info.SendChatMessage("There's no user with that name in the room.", Helper.ServerErrorColor);
                }
            }
            else
            {
                info.SendChatMessage("You need to be the owner to use this command.", Helper.ServerErrorColor);
            }
        }
Exemple #4
0
        public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            if (Args.Length > 0)
            {
                var command = CommandManager.GetCommand(Args[0].ToLower());

                if (command != null)
                {
                    var capitalized = command.Command.Capitalize();
                    socket.GetInfo().SendChatMessage(capitalized + ": " + command.HelpString);
                    socket.GetInfo().SendChatMessage("Minimum required arguments: " + command.MinimumArgCount);
                }
                else
                {
                    socket.GetInfo().SendChatMessage("There is no command with this name.", Helper.ServerErrorColor);
                }
            }
            else
            {
                string result = "-- Commands --\n";

                foreach (var command in CommandManager.GetCommands())
                {
                    result += "• " + command.Command.Capitalize() + ": " + command.HelpString + "\n";
                }

                result += "-- End of commands --";

                info.SendChatMessage(result);
            }
        }
        private void RegisterConnection(string dest, long term, string caller)
        {
            var number = Interlocked.Increment(ref _connectionNumber);

            _info = new RemoteConnectionInfo
            {
                Caller      = caller,
                Destination = dest,
                StartAt     = DateTime.UtcNow,
                Number      = number,
                Term        = term
            };
            RemoteConnectionsList.Add(_info);
        }
        public ProxyPSCommand(RemoteConnectionInfo connectionInfo, PSCommand cmd, bool asyncInvoke, Task.TaskWarningLoggingDelegate writeWarning)
        {
            if (connectionInfo == null)
            {
                throw new ArgumentNullException("connectionInfo");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            RemoteRunspaceFactory remoteRunspaceFactory = new RemoteRunspaceFactory(new RunspaceConfigurationFactory(), null, connectionInfo);

            this.runspaceMediator = new RunspaceMediator(remoteRunspaceFactory, new BasicRunspaceCache(1));
            this.cmd          = cmd;
            this.asyncInvoke  = asyncInvoke;
            this.writeWarning = writeWarning;
        }
        public override void HandleCommand(Fleck.IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            if (room != null)
            {
                var videoInfos = room.Playlist.ToArray();

                string message = "-- Start of playlist --\n";
                for (int i = 0; i < videoInfos.Length; i++)
                {
                    var videoId = videoInfos[i];
                    message += "[" + i + "]: " + videoId.VideoID + "\n";
                }
                message += "-- End of playlist --";

                info.SendChatMessage(message);
            }
        }
Exemple #8
0
        public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            var username = JoinArg();

            if (room != null)
            {
                if (room.IsOwner(socket))
                {
                    var targetUser = room.GetUser(username);

                    if (targetUser != null)
                    {
                        if (targetUser != socket)
                        {
                            if (!room.IsPrivileged(targetUser))
                            {
                                targetUser.GetInfo().SendAndSetPrivileged(true);
                                info.SendChatMessage(targetUser.GetInfo().Name + " is now a privileged user.");
                            }
                            else
                            {
                                targetUser.GetInfo().SendAndSetPrivileged(false);
                                info.SendChatMessage(targetUser.GetInfo().Name + " is no longer a privileged user.");
                            }
                        }
                        else
                        {
                            info.SendChatMessage("You are already privileged by being the owner.", Helper.ServerErrorColor);
                        }
                    }
                    else
                    {
                        info.SendChatMessage("There's no user with that name in this room.", Helper.ServerErrorColor);
                    }
                }
                else
                {
                    info.SendChatMessage("You need to be the owner of the room to use this command.", Helper.ServerErrorColor);
                }
            }
            else
            {
                info.SendChatMessage("You need to join a room before using this command.", Helper.ServerErrorColor);
            }
        }
Exemple #9
0
        internal static IEnumerable <PSObject> RPSProxyExecution(Guid cmdletUniqueId, PSCommand command, string serverFqn, ExchangeRunspaceConfiguration runspaceConfig, int serverVersion, bool asyncProxying, Task.TaskWarningLoggingDelegate writeWarning)
        {
            Uri uri = ProxyHelper.BuildCmdletProxyUri(serverFqn, runspaceConfig, serverVersion);
            IEnumerable <PSObject> result;

            try
            {
                RemoteConnectionInfo connectionInfo = ProxyHelper.BuildProxyWSManConnectionInfo(uri);
                ProxyPSCommand       proxyPSCommand = new ProxyPSCommand(connectionInfo, command, asyncProxying, writeWarning);
                result = proxyPSCommand.Invoke();
            }
            catch (Exception)
            {
                CmdletLogger.SafeAppendGenericInfo(cmdletUniqueId, "TargetUri", uri.ToString());
                throw;
            }
            return(result);
        }
Exemple #10
0
        public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            if (room != null)
            {
                var result = "Users in this room: ";

                foreach (var user in room.Sockets.OrderBy(socket2 => socket2.GetInfo().Name))
                {
                    result += user.GetInfo().Name + ", ";
                }

                result = result.Remove(result.LastIndexOf(", "));

                info.SendChatMessage(result);
            }
            else
            {
                info.SendChatMessage("You need to join a room to use this command.", Helper.ServerErrorColor);
            }
        }
        protected override Matroska.VideoSink CreateVideoSink()
        {
            var fileIndex                = 0;
            var fileExtension            = "mkv";
            var filePathWithoutExtension = ProcessFilePath(Path.Combine(Options.OutputPath, Options.OutputFileName), RemoteConnectionInfo);
            var filePath = $"{filePathWithoutExtension}-{fileIndex}.{fileExtension}";

            while (File.Exists(filePath))
            {
                filePath = $"{filePathWithoutExtension}-{++fileIndex}.{fileExtension}";
            }

            //TODO: should the JSON here follow the media server conventions?
            var jsonPath = filePath + ".json";

            File.WriteAllText(jsonPath, RemoteConnectionInfo.ToJson());
            Console.WriteLine(jsonPath);

            var format = VideoFormat.Clone();

            format.IsPacketized = false;
            return(new Matroska.VideoSink(filePath, format));
        }
Exemple #12
0
        public override void HandleCommand(IWebSocketConnection socket, RemoteConnectionInfo info, Room room)
        {
            if (room != null)
            {
                if (room.Owner == socket)
                {
                    var nextOwner = room.GetUser(JoinArg());

                    if (nextOwner != null)
                    {
                        if (nextOwner != socket)
                        {
                            room.NextOwner = nextOwner;
                            info.SendChatMessage("Next owner is now " + nextOwner.GetInfo().Name + ".");
                            nextOwner.GetInfo().SendChatMessage("You are now the next owner of this room.", Helper.ServerRoomColor);
                        }
                        else
                        {
                            info.SendChatMessage("You are already the owner of this room.", Helper.ServerErrorColor);
                        }
                    }
                    else
                    {
                        info.SendChatMessage("There's no user in this room with that name.", Helper.ServerErrorColor);
                    }
                }
                else
                {
                    info.SendChatMessage("You need to be the owner of the room to use this command.", Helper.ServerErrorColor);
                }
            }
            else
            {
                info.SendChatMessage("You need to join a room to use this command.", Helper.ServerErrorColor);
            }
        }
Exemple #13
0
        public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets)
        {
            string id           = data["id"] as string;
            int    startSeconds = 0;

            if (data.ContainsKey("t"))
            {
                startSeconds = (int)(long)data["t"];
            }

            if (room != null)
            {
                var videoInfo = room.AddVideo(id, startSeconds);

                if (YoutubeHelper.VideoExists(id))
                {
                    if (YoutubeHelper.CanEmbed(id))
                    {
                        var title        = YoutubeHelper.GetTitle(id);
                        var author       = YoutubeHelper.GetAuthor(id);
                        var channelImage = YoutubeHelper.GetChannelImage(id);
                        var totalSeconds = YoutubeHelper.GetTotalTime(id);

                        var totalTimeSpan = TimeSpan.FromSeconds(totalSeconds);
                        var totalTime     = string.Format("({0})", totalTimeSpan.ToString());

                        room.SendAddVideoToAll(videoInfo, title, totalTime, author, channelImage);

                        room.SendChatMessageToAll(info.Name + " added " + title + " to the playlist.");

                        if (room.CurrentPlayingVideo == null)
                        {
                            room.GotoNextVideo();
                            room.PlayVideo();
                            room.SendSetVideoToAll(room.CurrentPlayingVideo.VideoID, room.CurrentPlayingVideo.PlayState, (float)room.CurrentPlayingVideo.ElapsedSeconds);
                        }
                    }
                    else
                    {
                        info.SendVideoMessage("Author of video doesn't allow embedding this video.");
                    }
                }
                else
                {
                    info.SendVideoMessage("Video does not exist on youtube.");
                }
            }
            else
            {
                info.SendVideoMessage("You need to join a room first.");
            }
        }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SharpViewCore.EventArgs.IncomingConnectionEventArgs"/> class.
 /// </summary>
 /// <param name="info">Info.</param>
 public RemoteServerIncomingConnectionEventArgs(RemoteConnectionInfo info)
 {
     this.Info = info;
 }
 public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets)
 {
     info.SendPublicRooms();
 }
Exemple #16
0
        public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets)
        {
            var color = (string)data["color"];

            if (Helper.VerifyNameColor(color))
            {
                info.NameColor = color;
            }
            else
            {
                info.SendChatMessage("\"" + color + "\" is not an accepted color.", Helper.ServerErrorColor);
            }
        }
Exemple #17
0
        public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets)
        {
            var message = (string)data["message"];

            if (message.StartsWith("/"))
            {
                if (!CommandManager.HandleCommand(message, socket))
                {
                    info.SendChatMessage("Unknown command.", Helper.ServerErrorColor);
                }
            }
            else
            {
                if (room != null)
                {
                    room.SendChatMessageToAll(message, info.Name, "#FFF", info.NameColor);
                }
                else
                {
                    info.SendChatMessage("You need to join a room to use the chat. Type /room [room name] to join the room called [room name].", Helper.ServerErrorColor);
                }
            }
        }
 public ProxyPSCommand(RemoteConnectionInfo connectionInfo, PSCommand cmd, Task.TaskWarningLoggingDelegate writeWarning) : this(connectionInfo, cmd, false, writeWarning)
 {
 }
        public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets)
        {
            if (room == null)
            {
                return;
            }

            if (!room.IsPrivileged(socket))
            {
                return;
            }

            var state = (long)data["state"];

            if (room.CurrentPlayingVideo == null)
            {
                info.SendVideoMessage("Could not edit state of video to " + state + " because the video doesn't exist.");
                return;
            }

            if ((int)room.CurrentPlayingVideo.PlayState != state)
            {
                string action = null;

                Console.WriteLine("[{0}] Elapsed Time Set: {1}", room.RoomName, data["elapsed"]);

                switch (state)
                {
                case 0:
                {
                    action = "finished";
                    room.GotoNextVideo();
                    if (room.PlayVideo())
                    {
                        room.SendSetVideoToAll();
                    }
                    break;
                }

                case 1:
                {
                    action = "started";
                    room.PlayVideo();
                    break;
                }

                case 2:
                {
                    action = "paused";
                    room.PauseVideo();
                    break;
                }

                case 3:
                {
                    action = "is buffering";
                    room.PauseVideo();
                    break;
                }

                case 5:
                {
                    action = "stopped";
                    room.GotoNextVideo();
                    if (room.PlayVideo())
                    {
                        room.SendSetVideoToAll();
                    }
                    break;
                }
                }

                if (room.CurrentPlayingVideo != null)                 // CurrentPlayingVideo is null if playlist is empty.
                {
                    // In the case that the elapsed seconds is an integer, the value will be parsed as a long.
                    if (data["elapsed"] is long)
                    {
                        room.CurrentPlayingVideo.ElapsedSeconds = (long)data["elapsed"];
                    }
                    else
                    {
                        room.CurrentPlayingVideo.ElapsedSeconds = (double)data["elapsed"];
                    }

                    room.SendToAllExcept(socket, new Dictionary <string, object>
                    {
                        { "intent", "setVideoState" },
                        { "state", data["state"] },
                        { "elapsed", room.CurrentPlayingVideo.ElapsedSeconds },
                    });

                    //room.SendVideoMessageToAll(info.Name + " " + action + " the video.");
                }
            }
        }
Exemple #20
0
        public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets)
        {
            var name = data["name"] as string;

            if (name == "")
            {
                name = socket.ConnectionInfo.ClientIpAddress;
            }

            socket.SetInfo(new RemoteConnectionInfo(name, socket, Helper.GetMD5(name + DateTime.Now.ToLongTimeString())));

            Helper.SendQuick(socket, new Dictionary <string, object>
            {
                { "intent", "connectResult" },
                { "success", true },
                { "myName", name },
                { "id", socket.GetInfo().ID },
            });

            if (data.ContainsKey("room"))
            {
                var roomName = data["room"] as string;

                if (roomName != null)
                {
                    if (Helper.VerifyName(roomName))
                    {
                        if (RoomManager.Exists(roomName))
                        {
                            Helper.VerifyFixUsername(RoomManager.Rooms[roomName], socket.GetInfo());
                            RoomManager.AddUserToRoom(socket, roomName);
                        }
                        else
                        {
                            RoomManager.CreateRoom(roomName, socket);
                        }
                    }
                }
            }

            Console.WriteLine(name + "(" + Helper.IPString(socket) + ") connected");
        }