/// <summary> /// Sends a message to the BoxServer /// </summary> /// <param name="message">The message that must be sent</param> /// <returns>The message outcome</returns> public BoxMessage SendToServer(BoxMessage message) { if (!Connected) { // Not connected, request connection if (MessageBox.Show( null, Pandora.Localization.TextProvider["Misc.RequestConnection"], "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var form = new BoxServerForm(false); form.ShowDialog(); } if (!Connected) { return(null); } } Pandora.Profile.Server.FillBoxMessage(message); var msgForm = new BoxServerForm(message); msgForm.ShowDialog(); Utility.BringClientToFront(); return(msgForm.Response); }
private void tBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if (e.Button == bExit) { Close(); return; } if (e.Button == bRefresh) { TheBox.BoxServer.BoxMessage msg = Pandora.BoxConnection.SendToServer(new TheBox.BoxServer.ClientListRequest()); TheBox.BoxServer.ClientListMessage list = msg as ClientListMessage; if (msg != null) { m_Clients.Clear(); m_Clients.AddRange(list.Clients); } Refresh(); return; } foreach (ToolBarButton b in tBar.Buttons) { b.Pushed = false; } e.Button.Pushed = true; Map = int.Parse(e.Button.Tag as string); }
public override BoxMessage Perform() { BoxMessage msg = null; if (RemoteExplorerConfig.AllowAccess(Username, m_Folder)) { try { string path = System.IO.Path.Combine(BoxUtil.RunUOFolder, m_Folder); System.IO.Directory.CreateDirectory(path); msg = new GenericOK(); } catch (Exception err) { msg = new ErrorMessage("An error occurred when creating the folder:\n\n{0}", err.ToString()); } } else { msg = new ErrorMessage("You can't create folders there"); } return(msg); }
public override BoxMessage Perform() { BoxMessage msg = null; if (RemoteExplorerConfig.AllowAccess(Username, Path.GetDirectoryName(m_Filename))) { if (RemoteExplorerConfig.VeirfyExtension(m_Filename)) { try { StreamWriter writer = new StreamWriter(FullPath, false); writer.Write(m_Text); writer.Close(); msg = new GenericOK(); } catch (Exception err) { msg = new ErrorMessage("An I/O error occurred when writing the file.\n\n{0}", err.ToString()); } } else { // Extension not supported msg = new ErrorMessage("File type not allowed."); } } else { // Trying to upload to a folder that isn't registered for the user msg = new ErrorMessage("You aren't allowed to manipulate that folder."); } return(msg); }
public BoxServerForm( BoxMessage message ) { InitializeComponent(); Pandora.Localization.LocalizeControl( this ); m_Message = message; m_Login = false; }
/// <summary> /// Tries to connect to the BoxServer /// </summary> /// <param name="ProcessErrors">Specifies whether to process errors and display them to the user</param> /// <returns>True if succesful</returns> public bool Connect(bool ProcessErrors) { try { var ConnectionString = string.Format( "tcp://{0}:{1}/BoxRemote", Pandora.Profile.Server.Address, Pandora.Profile.Server.Port); m_Remote = Activator.GetObject(typeof(BoxRemote), ConnectionString) as BoxRemote; // Perform Login BoxMessage msg = new LoginMessage(); msg.Username = Pandora.Profile.Server.Username; msg.Password = Pandora.Profile.Server.Password; var data = msg.Compress(); string outType = null; var result = m_Remote.PerformRemoteRequest(msg.GetType().FullName, data, out outType); if (result == null) { MessageBox.Show(Pandora.Localization.TextProvider["Errors.ServerError"]); Connected = false; return(false); } var t = Type.GetType(outType); var outcome = BoxMessage.Decompress(result, t); if (ProcessErrors) { if (!CheckErrors(outcome)) { Connected = false; return(false); } } if (outcome is LoginSuccess) { Connected = true; return(true); } Connected = false; return(false); } catch (Exception err) { Pandora.Log.WriteError(err, "Connection failed to box server"); Connected = false; } return(false); }
/// <summary> /// Checks a BoxMessage and processes any errors occurred /// </summary> /// <param name="msg">The BoxMessage returned by the server</param> /// <returns>True if the message is OK, false if errors have been found</returns> public bool CheckErrors(BoxMessage msg) { if (msg == null) { return(true); // null message means no error } if (msg is ErrorMessage) { // Generic error message MessageBox.Show( string.Format(Pandora.Localization.TextProvider["Errors.GenServErr"], (msg as ErrorMessage).Message)); return(false); } if (msg is LoginError) { var logErr = msg as LoginError; string err = null; switch (logErr.Error) { case AuthenticationResult.AccessLevelError: err = Pandora.Localization.TextProvider["Errors.LoginAccess"]; break; case AuthenticationResult.OnlineMobileRequired: err = Pandora.Localization.TextProvider["Errors.NotOnline"]; break; case AuthenticationResult.UnregisteredUser: err = Pandora.Localization.TextProvider["Errors.LogUnregistered"]; break; case AuthenticationResult.WrongCredentials: err = Pandora.Localization.TextProvider["Errors.WrongCredentials"]; break; case AuthenticationResult.Success: return(true); } MessageBox.Show(err); return(false); } if (msg is FeatureNotSupported) { MessageBox.Show(Pandora.Localization.TextProvider["Errors.NotSupported"]); return(false); } return(true); }
/// <summary> /// Sends a message to the server /// </summary> /// <param name="msg">The message being sent to the server</param> /// <param name="window">Specifies whether to use the connection form</param> /// <returns>The outcome of the transaction</returns> public BoxMessage ProcessMessage(BoxMessage msg, bool window) { if (window) { var form = new BoxServerForm(msg); form.ShowDialog(); return(form.Response); } return(ProcessMessage(msg)); }
/// <summary> /// Checks a BoxMessage and processes any errors occurred /// </summary> /// <param name="msg">The BoxMessage returned by the server</param> /// <returns>True if the message is OK, false if errors have been found</returns> public bool CheckErrors(BoxMessage msg) { if (msg == null) return true; // null message means no error if (msg is ErrorMessage) { // Generic error message MessageBox.Show(string.Format(Pandora.Localization.TextProvider["Errors.GenServErr"], (msg as ErrorMessage).Message)); return false; } else if (msg is LoginError) { LoginError logErr = msg as LoginError; string err = null; switch (logErr.Error) { case AuthenticationResult.AccessLevelError: err = Pandora.Localization.TextProvider["Errors.LoginAccess"]; break; case AuthenticationResult.OnlineMobileRequired: err = Pandora.Localization.TextProvider["Errors.NotOnline"]; break; case AuthenticationResult.UnregisteredUser: err = Pandora.Localization.TextProvider["Errors.LogUnregistered"]; break; case AuthenticationResult.WrongCredentials: err = Pandora.Localization.TextProvider["Errors.WrongCredentials"]; break; case AuthenticationResult.Success: return true; } MessageBox.Show(err); return false; } else if (msg is FeatureNotSupported) { MessageBox.Show(Pandora.Localization.TextProvider["Errors.NotSupported"]); return false; } return true; }
/// <summary> /// Sends a message to the server /// </summary> /// <param name="msg">The message being sent to the server</param> /// <param name="window">Specifies whether to use the connection form</param> /// <returns>The outcome of the transaction</returns> public BoxMessage ProcessMessage(BoxMessage msg, bool window) { if (window) { TheBox.Forms.BoxServerForm form = new TheBox.Forms.BoxServerForm(msg); form.ShowDialog(); return(form.Response); } else { return(ProcessMessage(msg)); } }
private void bAreaRun_Click(object sender, System.EventArgs e) { if (!EnsureConditions()) { return; } if (cmbMap.SelectedIndex == -1) { MessageBox.Show(Pandora.Localization.TextProvider["Random.NoMap"]); return; } RandomTilesList tileset = cmbTileSet.SelectedItem as RandomTilesList; HuesCollection hues = cmbHues.SelectedItem as HuesCollection; int x1 = Math.Min((int)n1X.Value, (int)n2X.Value); int x2 = Math.Max((int)n1X.Value, (int)n2X.Value); int y1 = Math.Min((int)n1Y.Value, (int)n2Y.Value); int y2 = Math.Max((int)n1Y.Value, (int)n2Y.Value); Rectangle rect = new Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1); double fill = slideFill.Value / 100d; int map = Pandora.Profile.Travel.GetRealMapIndex(cmbMap.SelectedIndex); RandomRectangle rnd = new RandomRectangle(tileset, rect, fill, map); if (rNoHue.Checked) { rnd.Hue = 0; } else if (rSelectedHue.Checked) { rnd.Hue = Pandora.Profile.Hues.SelectedIndex; } else { rnd.RandomHues = hues; } if (chkZ.Checked) { rnd.Z = (int)numZ.Value; } TheBox.BoxServer.BoxMessage msg = rnd.CreateMessage(); Pandora.BoxConnection.SendToServer(msg); }
/// <summary> /// Handles incoming messages /// </summary> /// <param name="typeName">The name of the type of the message</param> /// <param name="data">The byte array representing the message</param> /// <param name="answerType">Will hold the name of the type of the answer message</param> /// <returns>A stream of bytes</returns> private byte[] BoxRemote_OnMessage(string typeName, byte[] data, out string answerType) { answerType = null; BoxMessage inMsg = null; BoxMessage outMsg = null; Type type = Type.GetType(typeName); if (type != null) { inMsg = BoxMessage.Decompress(data, type); if (inMsg != null) { // Authenticate AuthenticationResult auth = Authentication.Authenticate(inMsg); if (auth == AuthenticationResult.Success) { // Perform message outMsg = inMsg.Perform(); } else { // Return authentication error outMsg = new LoginError(auth); } } else { // Send generic server error outMsg = new ErrorMessage("An error occurred when decompressing the incoming message."); } } else { outMsg = new FeatureNotSupported(); } if (outMsg != null) { answerType = outMsg.GetType().FullName; return(outMsg.Compress()); } else { // Actions that don't require an answer answerType = null; return(null); } }
public override BoxMessage Perform() { string folder = Path.GetDirectoryName(m_Filename); BoxMessage msg = null; if (RemoteExplorerConfig.AllowAccess(Username, folder)) { if (File.Exists(FullPath)) { FileInfo info = new FileInfo(FullPath); if (info.Length <= RemoteExplorerConfig.MaxFileSize) { try { msg = new FileTransport(); StreamReader reader = new StreamReader(info.FullName); (msg as FileTransport).Text = reader.ReadToEnd(); reader.Close(); } catch (Exception err) { msg = new ErrorMessage("An I/O error occurred when reading the file:\n\n", err.ToString()); } } else { // File is too big msg = new ErrorMessage("The requested file is too big."); } } else { // File not found msg = new ErrorMessage("The requested file could not be found"); } } else { // Trying to request a file from a folder that isn't registered msg = new ErrorMessage("The requested resource isn't available to you."); } return(msg); }
public override BoxMessage Perform() { BoxMessage msg = null; if (RemoteExplorerConfig.AllowAccess(Username, System.IO.Path.GetDirectoryName(m_Path))) { if (Directory.Exists(FullPath)) { try { Directory.Delete(FullPath, true); msg = new GenericOK(); } catch (Exception err) { msg = new ErrorMessage("Couldn't delete the directory {0}. The following error occurred:\n\n{1}", m_Path, err.ToString()); } } else if (File.Exists(FullPath)) { try { File.Delete(FullPath); msg = null; } catch (Exception err) { msg = new ErrorMessage("Couldn't delete the file {0}. The following error occurred:\n\n{1}", m_Path, err.ToString()); } } else { // Not found msg = new ErrorMessage("The requested resource could not be found on the server, please refresh your view."); } } else { // Can't manipulate that folder msg = new ErrorMessage("You aren't allowed to manipulate the folder : {0}", m_Path); } return(msg); }
/// <summary> /// Sends a message to the server. Processes errors too. /// </summary> /// <param name="msg">The message to send to the server</param> /// <returns>A BoxMessage if there is one</returns> public BoxMessage ProcessMessage(BoxMessage msg) { BoxMessage outcome = null; if (!Connected) { Connect(); } if (!Connected) { return(null); } var data = msg.Compress(); string outType = null; try { var result = m_Remote.PerformRemoteRequest(msg.GetType().FullName, data, out outType); if (result == null) { return(null); } var t = Type.GetType(outType); outcome = BoxMessage.Decompress(result, t); if (!CheckErrors(outcome)) { outcome = null; } } catch (Exception err) { Pandora.Log.WriteError(err, "Error when processing a BoxMessage of type: {0}", msg.GetType().FullName); MessageBox.Show(Pandora.Localization.TextProvider["Errors.ConnectionLost"]); Connected = false; outcome = null; } return(outcome); }
private void VisualClientList_Load(object sender, System.EventArgs e) { ToolBarButton[] buttons = new ToolBarButton[] { map0, map1, map2, map3 }; for (int i = 0; i < 4; i++) { buttons[i].Visible = Pandora.Profile.Travel.EnabledMaps[i]; if (Pandora.Profile.Travel.EnabledMaps[i]) { buttons[i].Text = Pandora.Profile.Travel.MapNames[i]; } } TheBox.BoxServer.BoxMessage msg = Pandora.BoxConnection.SendToServer(new TheBox.BoxServer.ClientListRequest()); TheBox.BoxServer.ClientListMessage list = msg as ClientListMessage; if (list != null) { m_Clients = list.Clients; } else { // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert m_Clients = new List <ClientEntry>(); // Issue 10 - End } for (int i = 0; i < 4; i++) { if (Pandora.Profile.Travel.EnabledMaps[i]) { tBar.Buttons[i].Pushed = true; Map = i; return; } } Close(); }
public override BoxMessage Perform() { BoxMessage msg = null; string folderOld = Path.GetDirectoryName(m_OldPath); string folderNew = Path.GetDirectoryName(m_NewPath); string from = Path.Combine(BoxUtil.RunUOFolder, m_OldPath); string to = Path.Combine(BoxUtil.RunUOFolder, m_NewPath); if (RemoteExplorerConfig.AllowAccess(Username, folderOld) && RemoteExplorerConfig.AllowAccess(Username, folderNew)) { try { if (File.Exists(from)) { File.Move(from, to); msg = null; } else if (Directory.Exists(from)) { Directory.Move(from, to); msg = new GenericOK(); } else { msg = new ErrorMessage("The requested object could not be found ({0})", m_OldPath); } } catch (Exception err) { msg = new ErrorMessage("An error occurred while processing the move request :\n\n{0}", err.ToString()); } } else { msg = new ErrorMessage("You aren't allowed to access that."); } return(msg); }
/// <summary> /// Performs authentication for a BoxMessage /// </summary> /// <param name="msg">The message to authenticate</param> /// <returns>The AuthenticationResult defininf the authentication process</returns> public static AuthenticationResult Authenticate(BoxMessage msg) { Account account = GetAccount(msg.Username); if (account == null) { // Account doesn't exist return(AuthenticationResult.WrongCredentials); } AuthenticationResult auth = AuthenticationResult.WrongCredentials; if (AccountHandler.ProtectPasswords != PasswordProtection.None) { auth = msg.Authenticate(account.CryptPassword, true); if (auth == AuthenticationResult.WrongCredentials) { auth = msg.Authenticate(account.NewCryptPassword, true); } } else { auth = msg.Authenticate(account.PlainPassword, false); } if (auth == AuthenticationResult.Success) { IAuthenticable iAuth = msg as IAuthenticable; if (iAuth != null) { // This message has further authentication properties if (iAuth.RequireOnlineMobile) { // Check for online mobile if (Authentication.VerifyMobileAccessLevel(account, iAuth.MinAccessLevel)) { return(AuthenticationResult.Success); } else { return(AuthenticationResult.OnlineMobileRequired); } } else { if (Authentication.VerifyAccountAccessLevel(account, iAuth.MinAccessLevel)) { return(AuthenticationResult.Success); } else { return(AuthenticationResult.AccessLevelError); } } } else { // No need for advanced authentication, check only access level if (Authentication.VerifyAccountAccessLevel(account, BoxConfig.MinAccessLevel)) { return(AuthenticationResult.Success); } else { return(AuthenticationResult.AccessLevelError); } } } else { return(auth); } }
/// <summary> /// Sends a message to the server /// </summary> /// <param name="msg">The message being sent to the server</param> /// <param name="window">Specifies whether to use the connection form</param> /// <returns>The outcome of the transaction</returns> public BoxMessage ProcessMessage(BoxMessage msg, bool window) { if (window) { TheBox.Forms.BoxServerForm form = new TheBox.Forms.BoxServerForm(msg); form.ShowDialog(); return form.Response; } else { return ProcessMessage(msg); } }
/// <summary> /// Sends a message to the server. Processes errors too. /// </summary> /// <param name="msg">The message to send to the server</param> /// <returns>A BoxMessage if there is one</returns> public BoxMessage ProcessMessage(BoxMessage msg) { BoxMessage outcome = null; if (!Connected) Connect(); if (!Connected) return null; byte[] data = msg.Compress(); string outType = null; try { byte[] result = m_Remote.PerformRemoteRequest(msg.GetType().FullName, data, out outType); if (result == null) { return null; } Type t = Type.GetType(outType); outcome = BoxMessage.Decompress(result, t); if (!CheckErrors(outcome)) { outcome = null; } } catch (Exception err) { Pandora.Log.WriteError(err, "Error when processing a BoxMessage of type: {0}", msg.GetType().FullName); MessageBox.Show(Pandora.Localization.TextProvider["Errors.ConnectionLost"]); Connected = false; outcome = null; } return outcome; }
/// <summary> /// Sends a message to the BoxServer /// </summary> /// <param name="message">The message that must be sent</param> /// <returns>The message outcome</returns> public BoxMessage SendToServer(BoxMessage message) { if (!Connected) { // Not connected, request connection if (MessageBox.Show(null, Pandora.Localization.TextProvider["Misc.RequestConnection"], "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { BoxServerForm form = new BoxServerForm(false); form.ShowDialog(); } if (!Connected) { return null; } } Pandora.Profile.Server.FillBoxMessage(message); BoxServerForm msgForm = new BoxServerForm(message); msgForm.ShowDialog(); TheBox.Common.Utility.BringClientToFront(); return msgForm.Response; }
/// <summary> /// Performs authentication for a BoxMessage /// </summary> /// <param name="msg">The message to authenticate</param> /// <returns>The AuthenticationResult defininf the authentication process</returns> public static AuthenticationResult Authenticate( BoxMessage msg ) { Account account = GetAccount( msg.Username ); if ( account == null ) { // Account doesn't exist return AuthenticationResult.WrongCredentials; } AuthenticationResult auth = AuthenticationResult.WrongCredentials; if ( AccountHandler.ProtectPasswords ) { auth = msg.Authenticate( account.CryptPassword, true ); } else { auth = msg.Authenticate( account.PlainPassword, false ); } if ( auth == AuthenticationResult.Success ) { IAuthenticable iAuth = msg as IAuthenticable; if ( iAuth != null ) { // This message has further authentication properties if ( iAuth.RequireOnlineMobile ) { // Check for online mobile if ( Authentication.VerifyMobileAccessLevel( account, iAuth.MinAccessLevel ) ) { return AuthenticationResult.Success; } else { return AuthenticationResult.OnlineMobileRequired; } } else { if ( Authentication.VerifyAccountAccessLevel( account, iAuth.MinAccessLevel ) ) { return AuthenticationResult.Success; } else { return AuthenticationResult.AccessLevelError; } } } else { // No need for advanced authentication, check only access level if ( Authentication.VerifyAccountAccessLevel( account, BoxConfig.MinAccessLevel ) ) return AuthenticationResult.Success; else return AuthenticationResult.AccessLevelError; } } else { return auth; } }
private void SendMessage( object o ) { BoxMessage result = Pandora.BoxConnection.ProcessMessage( m_Message ); if ( result != null ) { if ( Pandora.BoxConnection.CheckErrors( result ) ) { DialogResult = DialogResult.OK; m_Response = result; } else { DialogResult = DialogResult.Cancel; } } if (!Pandora.BoxConnection.Connected) DialogResult = DialogResult.Cancel; // Account for communication error Close(); }