示例#1
0
        public void Disconnect(User user)
        {
            Connection.CurrentGroup.RemoveUser(user);
            OnUserDisconnect(user);
            PresentationController.UserDisconneced(user);

            if (Connection.CurrentPresentation != null && Connection.CurrentPresentation.Author.CompareTo(user.Username) == 0)
            {
                ClPresentationEnd();
            }

            foreach (User u in users.Keys)
            {
                if (u.Username == user.Username)
                {
                    lock (syncObj)
                    {
                        this.users.Remove(u);
                        foreach (User key in users.Keys)
                        {
                            ISharePCallback callback = users[key];
                            try {
                                callback.RefreshUsers(Connection.CurrentGroup.userList);
                                callback.UserLeave(user);
                            } catch
                            {
                                usersToRemove.Add(key);
                            }
                        }
                        RemoveUsers();
                    }
                    return;
                }
            }
        }
示例#2
0
        /// IShareP

        public ConnectionResult Connect(User user, byte[] password)
        {
            if (!users.ContainsValue(CurrentCallback))
            {
                lock (syncObj)
                {
                    if (SearchUsersByName(user.Username))
                    {
                        Log.LogInfo("Username already exists: " + user.Username);
                        return(ConnectionResult.UsernameExists);
                    }

                    if (Connection.CurrentGroup.passwordProtected && !Helper.CompareByteArrays(password, Connection.CurrentGroup.password))
                    {
                        Log.LogInfo("Wrong password. User: "******"Refused connection from banned user. User: "******"Callback faulted during Connect: " + key.Username);
                        }
                    }
                    RemoveUsers();
                    users.Add(user, CurrentCallback);
                    ICommunicationObject commObj = CurrentCallback as ICommunicationObject;
                    if (commObj != null)
                    {
                        commObj.Closed  += new EventHandler(CallBackFaulted);
                        commObj.Faulted += new EventHandler(CallBackFaulted);
                    }
                }

                Log.LogInfo("User connected: " + user.Username);
                return(ConnectionResult.Success);
            }
            Log.LogInfo("Refused connection of: " + user.Username);
            return(ConnectionResult.Error);
        }
示例#3
0
        public ConnectionResult Reconnect(User user)
        {
            if (!users.ContainsValue(CurrentCallback))
            {
                lock (syncObj)
                {
                    bool exists = false;
                    foreach (var item in usersToReconnect)
                    {
                        if (item.Id.CompareTo(user.Id) == 0 &&
                            item.IP == user.IP)
                        {
                            exists = true;
                        }
                    }
                    if (!exists)
                    {
                        return(ConnectionResult.Error);
                    }
                    Connection.CurrentGroup.AddUser(user);
                    PresentationController.UserConnected(user);

                    foreach (User key in users.Keys)
                    {
                        ISharePCallback callback = users[key];
                        try
                        {
                            callback.RefreshUsers(Connection.CurrentGroup.userList);
                        }
                        catch
                        {
                            usersToRemove.Add(key);
                            Log.LogInfo("Callback faulted during Reconnect: " + key.Username);
                        }
                    }
                    RemoveUsers();
                    users.Add(user, CurrentCallback);
                    ICommunicationObject commObj = CurrentCallback as ICommunicationObject;
                    if (commObj != null)
                    {
                        commObj.Closed  += new EventHandler(CallBackFaulted);
                        commObj.Faulted += new EventHandler(CallBackFaulted);
                    }
                }

                Log.LogInfo("User reconnected: " + user.Username);
                return(ConnectionResult.Success);
            }
            Log.LogInfo("Refused reconnection from: " + user.Username);
            return(ConnectionResult.Error);
        }
示例#4
0
        public void BanUser(string username)
        {
            lock (syncObj)
            {
                foreach (User key in users.Keys)
                {
                    if (key.Username.CompareTo(username) == 0)
                    {
                        Log.LogInfo("Banning user: " + username);
                        ISharePCallback callback = users[key];
                        try
                        {
                            callback.BanUser();
                        }
                        catch
                        {
                            usersToRemove.Add(key);
                        }

                        usersInBan.Add(key);
                        Connection.CurrentGroup.RemoveUser(key);
                        PresentationController.UserDisconneced(key);

                        foreach (User u in users.Keys)
                        {
                            ISharePCallback cb = users[u];
                            try
                            {
                                cb.RefreshUsers(Connection.CurrentGroup.userList);
                                cb.UserLeave(u);
                            }
                            catch
                            {
                                usersToRemove.Add(u);
                            }
                        }

                        if (Connection.CurrentPresentation != null && Connection.CurrentPresentation.Author.CompareTo(key.Username) == 0)
                        {
                            ClPresentationEnd();
                        }

                        break;
                    }
                }
                RemoveUsers();
            }
        }
示例#5
0
 public void OnGroupClose()
 {
     lock (syncObj)
     {
         foreach (User key in users.Keys)
         {
             ISharePCallback callback = users[key];
             try
             {
                 callback.GroupClose();
             }
             catch (Exception ex)
             {
                 Log.LogException(ex, "OnGroupClose Service");
             }
         }
     }
 }
示例#6
0
 public void IsWriting(User user)
 {
     lock (syncObj)
     {
         foreach (User key in users.Keys)
         {
             ISharePCallback callback = users[key];
             try
             {
                 callback.IsWritingCallback(user);
             }
             catch
             {
                 usersToRemove.Add(key);
             }
         }
         RemoveUsers();
     }
 }
示例#7
0
        void CallBackFaulted(object sender, EventArgs e)
        {
            Log.LogInfo("Callback faulted");
            ISharePCallback callback = sender as ISharePCallback;

            if (callback != null)
            {
                if (users.ContainsValue(callback))
                {
                    ICommunicationObject commObj = callback as ICommunicationObject;
                    if (commObj != null)
                    {
                        //remove the reference to the event handle to help memory cleanup
                        commObj.Closed -= new EventHandler(CallBackFaulted);
                    }
                    usersToReconnect.Add(users.FirstOrDefault(x => x.Value == callback).Key);
                    Disconnect(users.FirstOrDefault(x => x.Value == callback).Key);
                }
            }
        }
示例#8
0
 public void Say(Message msg)
 {
     ChatController.RecieveMessage(msg);
     Log.LogInfo("Message sent: " + msg.Time.ToLongTimeString());
     lock (syncObj)
     {
         foreach (User key in users.Keys)
         {
             ISharePCallback callback = users[key];
             try
             {
                 callback.Receive(msg);
                 Log.LogInfo("Finished: " + DateTime.Now.ToLongTimeString());
             }
             catch
             {
                 usersToRemove.Add(key);
                 Log.LogInfo("Users kicked: " + DateTime.Now.ToLongTimeString());
             }
         }
         RemoveUsers();
     }
 }
示例#9
0
        public void OnGroupSettingsChanged()
        {
            lock (syncObj)
            {
                foreach (User key in users.Keys)
                {
                    ISharePCallback callback = users[key];
                    try
                    {
                        var result = new Dictionary <string, string>();
                        result.Add("Download", Connection.CurrentGroup.settings.Download.ToString());
                        result.Add("ViewersPresent", Connection.CurrentGroup.settings.Viewerspresent.ToString());
                        if (Connection.CurrentGroup.navigation == GroupNavigation.Backwards)
                        {
                            result.Add("GroupNavigation", "Backwards");
                        }
                        else if (Connection.CurrentGroup.navigation == GroupNavigation.BothDirections)
                        {
                            result.Add("GroupNavigation", "Both");
                        }
                        else if (Connection.CurrentGroup.navigation == GroupNavigation.FollowOnly)
                        {
                            result.Add("GroupNavigation", "Follow");
                        }

                        callback.GroupSettingsChanged(result);
                    }
                    catch (Exception ex)
                    {
                        Log.LogException(ex, "OnGroupSettingsChanged Service");
                        usersToRemove.Add(key);
                    }
                }
                RemoveUsers();
            }
        }
示例#10
0
 public void OnPresentationEnd()
 {
     lock (syncObj)
     {
         foreach (User key in users.Keys)
         {
             ISharePCallback callback = users[key];
             if (key.Username.CompareTo(Connection.CurrentPresentation.Author) == 0)
             {
                 continue;
             }
             try
             {
                 callback.PresentationEnd();
             }
             catch (Exception ex)
             {
                 Log.LogException(ex, "OnPresentationEnd Service");
                 usersToRemove.Add(key);
             }
         }
         RemoveUsers();
     }
 }
示例#11
0
        public void LoadSlides()
        {
            lock (syncObj)
            {
                ISharePCallback presentationHost = null;
                if (SearchUsersByName(Connection.CurrentPresentation.Author))
                {
                    foreach (User key in users.Keys)
                    {
                        if (key.Username.CompareTo(Connection.CurrentPresentation.Author) == 0)
                        {
                            presentationHost = users[key];
                        }
                    }
                }
                if (presentationHost == null)
                {
                    Log.LogInfo("Can't load presentation. Host not found");
                    return;
                }

                DirectoryInfo din;
                DirectoryInfo dout;
                string        path      = Helper.GetCurrentFolder() + "tout/";
                string        innerPath = Helper.GetCurrentFolder() + "tin/";
                if (!Directory.Exists(path))
                {
                    din = Directory.CreateDirectory(path);
                }
                else
                {
                    din = new DirectoryInfo(path);
                    foreach (FileInfo file in din.GetFiles())
                    {
                        file.Delete();
                    }
                    foreach (DirectoryInfo dir in din.GetDirectories())
                    {
                        dir.Delete(true);
                    }
                }
                din.Attributes = FileAttributes.Directory | FileAttributes.Hidden;

                if (!Directory.Exists(innerPath))
                {
                    dout = Directory.CreateDirectory(innerPath);
                }
                else
                {
                    dout = new DirectoryInfo(innerPath);
                    foreach (FileInfo file in dout.GetFiles())
                    {
                        file.Delete();
                    }
                    foreach (DirectoryInfo dir in dout.GetDirectories())
                    {
                        dir.Delete(true);
                    }
                }
                dout.Attributes = FileAttributes.Directory | FileAttributes.Hidden;

                try
                {
                    Log.LogInfo("[Server]Start loading slides (" + Connection.CurrentPresentation.SlidesTotal + ")");
                    for (int i = 1; i <= Connection.CurrentPresentation.SlidesTotal; i++)
                    {
                        byte[]     file       = presentationHost.ClRequestSlide(i);
                        FileStream fileStream = new FileStream(path + (i.ToString() + ".dat"), FileMode.Create, FileAccess.ReadWrite);
                        fileStream.Write(file, 0, file.Length);
                        FileStream fileStreamInner = new FileStream(innerPath + (i.ToString() + ".dat"), FileMode.Create, FileAccess.ReadWrite);
                        fileStreamInner.Write(file, 0, file.Length);
                    }
                }
                catch (Exception ex)
                {
                    Log.LogException(ex, "[Server]Error loading slide");
                }
            }
        }