예제 #1
0
 // Helpful function for client speach. Checks for connection before writing.
 private void ClientBroadcast(string Message)
 {
     try
     {
         byte[] Chat = Encoding.UTF8.GetBytes(Message);
         SelfStream.Write(Chat, 0, Chat.Length);
         SelfStream.Flush();
     }
     catch { }
 }
예제 #2
0
        // Client function. Activates whenever clients are connected. Gets messages from host
        public void GetMessage(object sender, DoWorkEventArgs e)
        {
            while (SelfSocket != null && SelfSocket.Connected)
            {
                SelfStream = SelfSocket.GetStream();
                byte[] InStream = new byte[65536];
                try
                {
                    if (SelfSocket.Connected)
                    {
                        SelfStream.Read(InStream, 0, SelfSocket.ReceiveBufferSize);
                    }
                }
                catch { break; }
                string   Mess    = Decrypt(Encoding.UTF8.GetString(InStream));
                string[] Message = Mess.Split(' ');

                // How to deal with message, first word delim by spaces determines message use
                switch (Message[0])
                {
                // Incoming new list of chatting members
                case "NEWCLIENTSLIST":
                    ClientListUpdate(Message);
                    break;

                // Incoming new playlist information
                case "NEWPLAYLIST":
                    PlaylistUpdate(Message);
                    break;

                // Incoming Currently Playing
                case "CURRENTLYPLAYING":
                    int Play = Convert.ToInt32(Message[1]);
                    if (Play >= 0 && !Hosting && Play < Playlist.Items.Count)
                    {
                        Internal_Command = true;
                        PlayVideo(Play, true);
                        if (Message.Length == 3)
                        {
                            ClientBroadcast("REFRESH$");
                        }
                        Internal_Command = false;
                    }
                    break;

                // Video pause flag sent
                case "PAUSE":
                    if (YoutubeVideo_CallFlash("getPlayerState()") == "<number>1</number>" && !Seek_Immunity)
                    {
                        Internal_Command = true;
                        YoutubeVideo_CallFlash("pauseVideo()");
                        Internal_Command = false;
                    }
                    break;

                case "PLAY":
                    if (YoutubeVideo_CallFlash("getCurrentTime()") == "" || Message.Length == 1)
                    {
                        break;
                    }
                    Seek_Immunity    = true;
                    Internal_Command = true;
                    string sCurrentTime = YoutubeVideo_CallFlash("getCurrentTime()");
                    sCurrentTime = sCurrentTime.Remove(sCurrentTime.Length - 9).Remove(0, 8);
                    double CurrentTime = Convert.ToDouble(sCurrentTime);
                    double SynchTime   = Convert.ToDouble(Message[1]);
                    if (Math.Abs(CurrentTime - SynchTime) >= 0.5f)
                    {
                        SynchTime += 0.3f;
                        YoutubeVideo_CallFlash("seekTo(" + SynchTime.ToString() + ", true)");
                    }
                    YoutubeVideo_CallFlash("playVideo()");
                    Seek_Immunity    = false;
                    Internal_Command = false;
                    break;

                case "VOTETOSKIP":
                    CallTimer();
                    break;

                // The usual chat message
                default:
                    string TotalMessage = "";
                    foreach (string s in Message)
                    {
                        TotalMessage += s;
                        TotalMessage += " ";
                    }
                    TotalMessage = TotalMessage.Substring(0, TotalMessage.Length - 1);
                    ClientChat(TotalMessage);
                    break;
                }
                Thread.Sleep(200);
            }
            Chat("Lost connection from server...", "CONSOLE");

            Connected = false;
        }