Leaderboard
Popular Content
Showing content with the highest reputation on 03/09/19 in all areas
-
Version 0.2.0
730 downloads
RAGE Editor is a resource that allows you to write, test, and save JavaScript code without leaving the game. Features Derived from VS Code. RAGE Editor is built on top of Monaco Editor, which is the same text editor that powers VS Code. This means you can use familiar keybindings and color schemes when editing your code for maximum productivity. Multiple tabs and file management. You can create as many simultaneous tabs as you want in order to switch between testing environments. Tabs can be persisted to your local storage by any name and restored at any time, even through game restarts. Execute code on multiple environments. Run code dynamically on your local client, the server, or all other clients. You can also highlight a specific section of code and right click to run only that selection on any environment. Built-in up-to-date RAGE API typings w/ context switching. Typings for server-side and client-side RAGE APIs are fetched directly from GitHub to ensure you get the most up-to-date auto-complete and IntelliSense features without installing or setting up TypeScript. Local recently updated typing backups are also bundled with RAGE Editor in the event you're trying to work offline. You can switch between server-side and client-side typings with the click of a button. Configurable key binding. You can set the key binds to be any key you want for your server. Customizable user authentication using custom logic or built-in IP whitelisting. Without modification, you can specify a whitelist of IP addresses that will be able to access the editor in order to prevent anyone from running code on your server or other players, or you can omit whitelisting altogether to allow anyone to run code anywhere (not recommended, though). For more control, you can override this method by specifying your own logic to control who can access the editor, and which features they can use. See below. Dynamically move and resize the editor to your liking. In order to accommodate testing different UI components and optimizing for performance, you can drag/resize the editor to be any place and shape on your screen. Access convenient libraries such as rage-rpc. RAGE Editor uses rage-rpc under the hood to route code for remote execution. The editor also exposes a global rpc variable for you to use in your scripts for easy client<->server communication and testing! Installation Extract the provided rage-editor.zip file into your servers root. Installation is the same as any other resource. Don't forget to include the client_package in your client-side index.js: require('./rage-editor/index.js'); 3. When in game, simply press the key binding (default is F8) in order to toggle the editor view. Configuration RAGE Editor gives you some flexibility in order to make it work smoothly in your environment. There is a config.json file located in packages/rage-editor/config.json. The default version of this file should look like something like this once you open it in a text editor: { "key": 119, // F8 "port": 8083, "whitelistIPs": [], "useNgrok": true } Options: key: The key that the player will press in-game to toggle the editor. This defaults to F8. You must use the decimal representation of the key for now. Check this link for keys: https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes port: The port that the built-in web server will serve the editor from. Monaco Editor requires web workers to function, and Chromium won't load web workers unless they are over HTTP/HTTPS. It's recommended that you open this port and disable useNgrok for the best performance and reliability. More on this below. whitelistIPs: This is an array of IPv4 strings that you want to allow to use RAGE Editor. If the list is empty, anyone will be allowed to use it without restrictions. If the list is not empty, only players whose IPs are in the list will be able to open the editor. This means you can use it in a production environment if you really want to. Be careful who you give access as they will have the ability to execute any code they want on the server or other users. useNgrok: ngrok is a utility that can open an HTTP tunnel to your server without you having to open a port (similar to Hamachi), and it comes with RAGE Editor by default. With this option enabled, you do not have to open the port specified above. However, anonymous ngrok tunnels have a maximum life-span of ~8 hours and have a limit on concurrent open connections. It's recommended that you disable this and open the port specified above yourself. This way, traffic can directly talk to your server without going through a middleman. It will increase load-time as well as reliability. Ngrok is a good way to get started and is perfectly acceptable if you have a small number of people using RAGE Editor, or you don't use it often. Connections from the same computer will always be served from localhost, whether this option is enabled or not. Usage The UI for RAGE Editor is pretty straight-forward. The top left toolbar has a few buttons that do different things regarding tab and file management: New: Opens a blank new tab. Open: Opens a previously saved file. You can only open files that aren't already open in any other tab. Save: Saves the current tab. It will prompt you for a file name of your choice if the tab is fresh. It'll overwrite the existing data if it's not a fresh tab. Save As: Saves the current tab as a different file name, but does not change this tab to reference that new file. This is useful for saving different variations of the same file. The top right section of the toolbar has some buttons that relate to executing code and switching typing contexts: L: Run the current tab locally on the current user's client. S: Run the current tab on the server. C :Run the current tab on all clients, including the current user. Server-side/Client-side: This button swaps out the built-in typings for the RAGE API. If it says Server-side, server-side IntelliSense will be available in the editor. If it says Client-side, client-side API typings will be available in the editor. This doesn't alter your code in any way other than swapping out the TypeScript definitions. You can drag the editor around by clicking and holding the top toolbar where the buttons are. You can resize the editor by clicking and holding on the handle on the lower right of the screen. The bottom right of the editor shows the status of the editor. It'll tell you when it's loading type definitions, or when it's in the middle of executing code. Currently there is no way to view execution results or errors. This will change in the future! Customization / Interoperability Access Control RAGE Editor has a built-in IP whitelist solution for controlling who can access the editor when in-game. This is great for most users, however, other users might want more flexibility and control over who can access what, and when. Since the editor uses rage-rpc under the hood to ask the server if a certain user can use the editor, this functionality can easily be overridden by any resource developer by simply re-registering the procedure on the server, making the calculation however you wish, and replying to the client if they can access the editor. You can also configure which features of the editor they are able to use. This is called every time a player presses the key bind to open the editor. Here's an example: const rpc = require('rage-rpc'); // Allow players with the name "micaww" to open the editor and execute code on all contexts rpc.register('reditor:canPlayerUse', (_, { player }) => player.name === 'micaww'); // Allow players whose name starts with "Admin" to open the editor and execute on all contexts, but only allow other players to execute code locally rpc.register('reditor:canPlayerUse', (_, { player }) => { if(player.name.startsWith("Admin")) return true; return { l: true, c: false, s: false }; }); You can either return a boolean or an object with the properties l, c, and s. If you return true, the player will be able to open the editor and execute on all contexts. If you return false, the player won't be able to open the editor at all. The key bind will do nothing. If you return an object, the editor will open, but you will need to specify which contexts they are allowed to execute on. l: Local client c: All clients s: The server This gives you unlimited control over which players can access the editor and what they are able to access. Events There are a few events that RAGE Editor exposes for you to hook into: reditor:shown (Client-side): The editor has been shown. reditor:hidden (Client-side): The editor has been hidden. Here's an example usage to disable some custom chat. // client-side const chat = require('./my-juicy-package/customchat.js'); mp.events.add('reditor:shown', () => { chat.setActive(false); }); mp.events.add('reditor:hidden', () => { chat.setActive(true); }); Examples Server-side Execution: https://streamable.com/c432b Client-side Execution: https://streamable.com/oomuq Add me on Discord micaww#3032, or message me here on the forums for any help. Here is the GitHub if you would like to contribute or have an issue: https://github.com/micaww/rage-editor4 points -
Introduction Hello, So I have decided I should make this tutorial about how to use CEF alongside RAGEMP to make interactable UI because I have spent some time understanding it from examples without a clear tutorial, I am going to explain how to interact between the CEF browsers and RAGEMP client, and how to send/receive information from and to server. This tutorial is targeting new comers in RAGEMP but who have background in scripting and know how to run and connect their server locally. So the main points will be: 1-What is CEF 2-Sending information from CEF to RAGEMP client (and vice versa) 3-Sending information from RAGEMP to The Server (and vice versa) (I will be using C# Bridge API for working with the serverside scripting) Before we start you are going to need the following to better understand the tutorial: Basic knowledge in HTML, CSS and JavaScript (Optional – Nice to have) Bootstrap and JQuery Let’s start! What is CEF CEF is abbreviation to Chromium Embedded Framework an open source framework that allow the ability to embed HTML webpages into applications. RAGEMP already integrates the CEF so you don’t have to download anything externally to begin using it. CEF and RAGEMP Client So now we are going to learn how to create a browser inside the RAGEMP client and interact with it. I am going to teach by giving example, it is going to be a basic login/register system. First download or or create your own webpage design, If you don't know how to create a webpage just use my sample (Attached to this thread) and follow the tutorial. Start by going to RAGEMP/server-files/client_packages folder and create a new folder name it “Login” then inside the Login folder we’ve just created place the HTML,CSS and JS files that is related to the webpage inside and then create the (clientside) script we will call it “Main.js” that will be the main connecting point between the CEF browser, client and the server. NOTE: In the Login folder you are going to place the webpage files and all dependences such as Bootstrap or JQuery libraries. So to this point you should’ve something similar to this Dependences folder contains the minified JQuery and Bootstrap libraries, Links below: https://getbootstrap.com/docs/3.3/getting-started/ https://code.jquery.com/jquery-3.3.1.min.js/ So I have pre-made this simple page for the sake of this tutorial, I will link download to all of the files that I have used at the bottom of this thread. But you can go with any page design you like. Disclaimer: I am new to web development so it may not look that good but it does the job. Now we need to interact with this page, Inside the Login.html (assuming you already have made/imported a page) find the main components that you want to interact with and give them the ‘id’ attribute, in my case I need the buttons and text input elements, image below for more understanding Also notice how we referenced the “Login.js” script. We are going to use these inside our “Login.js” file, so Open the Login.js file and write the following: (Code is written using JQuery) $('#loginButton').click(() => { mp.trigger('loginInformationToServer', $('#loginUsernameText').val(), $('#loginPasswordText').val()); }); $('#registerButton').click(() => { mp.trigger('registerInformationToServer', $('#registerUsernameText').val(), $('#registerPasswordText').val()); }); So what this basically does is once the loginButton/registerButton is clicked is going to trigger (mp.trigger) an event with the given name and pass the values inside the text fields as arguments, that later we are going to catch that in our “Main.js” script. (This point is where we send information from CEF Browser to RAGEMP Client). Now that we have send the information and they are waiting to be caught, But before we do that we are going to show the browser window when a player connect to our server. Open “Main.js” and use mp.browsers.new(‘package://path’); In our case: we have the html page inside our Login folder. var loginBrowser = mp.browsers.new('package://Login/Login.html'); Now at this point when the player connects to our server this will show him our page that we’ve just made, it is still not functional yet until we catch the information that we’ve sent before. Let’s catch them now, inside the “Main.js” add the following: mp.events.add('loginInformationToServer', (username, password) => { mp.events.callRemote('OnPlayerLoginAttempt', username, password); }); mp.events.add('registerInformationToServer', (username, password) => { mp.events.callRemote('OnPlayerRegisterAttempt', username, password); }); I am not going to go into much details here on the syntax but what we are doing is catching the 'loginInformationToServer' and 'registerInformationToServer' events (like you’d do in any other client event in ragemp) and sending them directly to the server to verify the information passed. But before we forget go back to the client_packages folder and create or open the file ‘index.js’ and place require('./Login/Main.js'); to let the server know that this file contains JavaScript codes that related to RAGEMP client (mp.events.add, mp.events.callRemote and mp.browsers.new), a complete list found on ragemp wiki https://wiki.rage.mp/index.php?title=Client-side_functions RAGEMP Client and RAGEMP Server Now that we have sent the information from the CEF client to the RAGEMP client, and then to the RAGEMP server via (mp.events.callRemote) we didn’t catch the event on the server yet, so let’s go ahead and do that. It can be done in same ways but different syntax depending on which programming language you are using, I am going to be using C# because I am more familiar with but it can be easily done with JS serverside once you are familiar with scripting in it. So go ahead and inside any resource file that you are using type the following: [RemoteEvent("OnPlayerLoginAttempt")] public void OnPlayerLoginAttempt(Client player, string username, string password) { NAPI.Util.ConsoleOutput($"[Login Attempt] Username {username} | Password: {password}"); if(username == "Max" && password == "123") { player.TriggerEvent("LoginResult", 1); } else player.TriggerEvent("LoginResult", 0); } So The above code catch the event that is triggered when player sends the information to the server so we validate them then send back a response to the client with either success or fail depending on the player data, in ideal case we should check the information from a database but that’s out of the scope for this tutorial so I am just checking if his username is Max and password is 123 then we send information back to the client with result 1 (success) else we send the result of 0 (incorrect username/password) Same thing apply for the register event handle. Now you can notice a pattern here is that whenever we send an event from one place to another we need to catch it, so back to the “Main.js” and let’s handle the response sent from the server, Add the following: mp.events.add('LoginResult', (result) => { if (result == 1) { //Success we destroy the loginBrowser as we don't need it anymore loginBrowser.destroy(); mp.gui.cursor.show(false, false); mp.gui.chat.push("You have successfully logged in."); } else { //Failed we just send a message to the player saying he provided incorrect info //Here you can be creative and handle it visually in your webpage by using the (browser).execute or loginBrowser.execute in our case to execute a js code in your webpage mp.gui.chat.push('Incorrect password or username.'); } }); Similar to what we did when we caught function from CEF we did for catching from server and we checked if the value passed is 1 then the player succeeds in logging in else he fails. Now you can just run your server and connect with your client and you should see the login page appear, enter anything and hit login - it should message Then try using the combinations of Max and 123 and you should see and the window should disappear. Same practice apply to the register I will leave it for you to practice and try to implement that by yourself! Good luck! Summary Important things to remember: - From CEF browser to RAGEMP client => mp.trigger caught by mp.events.add - From RAGEMP client to RAGEMP server (C#) => mp.events.callRemote caught by [RemoteEvent()] flag and a function Now the other way around: - From RAGEMP server (C#) to RAGEMP client => (Client).TriggerEvent caught by mp.events.add - From RAGEMP client to CEF browser => (Browser).execute For more information about the syntax for these you can check the ragemp wiki NOTE: Sometimes you don’t need to send anything to the server, For example a browser that contains information about your server, you just need to contact between CEF and RAGEMP client. NOTE: Similarly if you want to use JavaScript for serverside scripting you can find the equivalent to my functions used and do the same, however everything done in clientside scripts (Main.js) should remain the same for both languages!! The End And here you’ve just completed the tutorial! Thanks for taking your time to read and if you have faced any problems or any question post a comment below and I will do my best to answer it. Also feel free to correct me if there is any suggestions or any syntax/logical errors. Happy coding! Files used in this tutorial: https://www.solidfiles.com/v/nYR8xn43j57jv1 point
-
CommanderDonkey kann ich nur empfehlen macht super Arbeit1 point
