• Websocket RCON - Slight problem
    12 replies, posted
As this started out as a search for documentation we have figured out this: You authenticate/login by connecting to the websocket like this: [CODE] ws://SERVER:PORT/RCONPASSWORD[/CODE] Messages come back as a json string like this: [CODE]{ "Message": "[CHAT] kentbakk: Hello", "Identifier": 0, "Type": 3, "Stacktrace": "" }[/CODE] And you send commands with a json string like this (Works for me on windows based server): [CODE]{ "Message": "say Hello"}[/CODE] While iScripters is running a linux server he is using: [CODE]{ "Message": "say Hello", "Identifier": 0, "Type": 3, "Stacktrace": "" }[/CODE] For some reason the first one works for me while the second does not (Other way around goes for iScripter to i believe) Might be the OS but i can not verify that.
Mine doesn't seem to be giving errors, but how do I authenticate with it? (Disclaimer: very new to websockets) [QUOTE]WebSocket connection to 'ws://SERVER:PORT/' failed: Connection closed before receiving a handshake response[/QUOTE] [QUOTE][RCON][IP.ADD.RR.ESS] Disconnected: invalid packet [RCON][IP.ADD.RR.ESS] Disconnected: invalid packet[/QUOTE] Using the example from [url]http://www.tutorialspoint.com/html5/html5_websocket.htm[/url]
Could you post your startup script, i do have a feeling that it might be related to that, As far as i know you would authenticate as you normally would with the old system (First message you send being the password?) Not sure as of yet i do hope to get it working soon so i can play around with it to learn and to start on a rcon client for it :p
[QUOTE=kentbakk;49812293]Could you post your startup script, i do have a feeling that it might be related to that, As far as i know you would authenticate as you normally would with the old system (First message you send being the password?) Not sure as of yet i do hope to get it working soon so i can play around with it to learn and to start on a rcon client for it :p[/QUOTE] Using Ubuntu so server is loaded in Wine. Startup script: [code] WINEARCH=win64 WINEPREFIX=~/.wine64 /usr/bin/xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' /usr/bin/wine RustDedicated -batchmode -load +rcon.port 28018 +rcon.password ** +server.hostname '*no-advertising*' +server.port 28015 +server.ip ** +server.identity rust_server +server.maxplayers 10 +server.seed 1337 +rcon.web 1 +server.worldsize 2000 -autoupdate -logFile console.out [/code]
Well it seems rust is higly picky relating to the order of the rcon stuff, changed the websocket enabler to be the last argument and presto, Il play with the thing a bit and get back to you on authenticating tough ;) edit: Cancel that, it boots now Now it randomly pooped with the same error and a error when trying to connect "WebSocket service with the specified path isn't found: " So yeah, back to debugging before i can come back to you on that :/ [editline]25th February 2016[/editline] It seems i resolved both our problems, authentication is done by connecting like this 'ws://SERVER:PORT/RCONPASSWORD'
[QUOTE=kentbakk;49812352]It seems i resolved both our problems, authentication is done by connecting like this 'ws://SERVER:PORT/RCONPASSWORD'[/QUOTE] I actually tried that but it didn't work :/ Let's try again! :D
[QUOTE=iScripters;49812909]I actually tried that but it didn't work :/ Let's try again! :D[/QUOTE] I should also mention i could not go trough a dns server so you will have to put in the serverip, not the hostname. I do not know if that was just something on my side but its worth a shot :)
[QUOTE=kentbakk;49812920]I should also mention i could not go trough a dns server so you will have to put in the serverip, not the hostname. I do not know if that was just something on my side but its worth a shot :)[/QUOTE] Still getting the 'invalid packet' :/ What are you using to connect to it? [B]Edit[/B]: Also, I can still connect using rcon, that shouldn't happen.... right? [B][B]Edit 2[/B][/B]: The above edit triggered me into checking 'ps'.. turns out there was still an instance running. No invalid packets anymore :D
Took and edited the example you posted and tested with that now; [QUOTE]<!DOCTYPE HTML> <html> <head> <script type="text/javascript"> function WebSocketTest() { if ("WebSocket" in window) { alert("WebSocket is supported by your Browser!"); // Let us open a web socket var ws = new WebSocket("ws://IP:PORT/PASSWORD"); ws.onmessage = function (evt) { var received_msg = evt.data; alert("Message is received..."); }; ws.onclose = function() { // websocket is closed. alert("Connection is closed..."); }; } else { // The browser doesn't support WebSocket alert("WebSocket NOT supported by your Browser!"); } } </script> </head> <body> <div id="sse"> <a href="javascript:WebSocketTest()">Run WebSocket</a> </div> </body> </html>[/QUOTE] This worked without an problem :) (It is edited a bit as i dont yet know what the correct format for sending things to the server is it would crash if the example sent a message)
Got it working (see my previous edits) but sending 'status' and 'status\n' give nice errors: [QUOTE]2/25/2016 9:52:44 PM|Fatal|WebSocket.processException|Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: s. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonTextReader.ReadInternal () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonTextReader.Read () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, Boolean hasConverter) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0 Rcon Error: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: s. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonTextReader.ReadInternal () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonTextReader.Read () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, Boolean hasConverter) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0 Rcon Error: Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: s. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonTextReader.ReadInternal () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.JsonTextReader.Read () [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, Boolean hasConverter) [0x00000] in <filename unknown>:0 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, Boolean checkAdditionalContent) [0x00000] in <filename unknown>:0 An exception has occurred during an OnMessage event. 2/25/2016 9:52:44 PM|Fatal|WebSocket.processException|System.ObjectDisposedException: The object was used after being disposed. at System.Net.Sockets.NetworkStream.CheckDisposed () [0x00000] in <filename unknown>:0 at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0 at WebSocketSharp.Ext+<>c__DisplayClass9.<ReadBytesAsync>b__8 (IAsyncResult ar) [0x00000] in <filename unknown>:0 Rcon Error: System.ObjectDisposedException: The object was used after being disposed. at System.Net.Sockets.NetworkStream.CheckDisposed () [0x00000] in <filename unknown>:0 at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0 at WebSocketSharp.Ext+<>c__DisplayClass9.<ReadBytesAsync>b__8 (IAsyncResult ar) [0x00000] in <filename unknown>:0 Rcon Error: System.ObjectDisposedException: The object was used after being disposed. at System.Net.Sockets.NetworkStream.CheckDisposed () [0x00000] in <filename unknown>:0 at System.Net.Sockets.NetworkStream.EndRead (IAsyncResult ar) [0x00000] in <filename unknown>:0 at WebSocketSharp.Ext+<>c__DisplayClass9.<ReadBytesAsync>b__8 (IAsyncResult ar) [0x00000] in <filename unknown>:0 An exception has occurred while receiving a message.[/QUOTE]
[QUOTE=iScripters;49813040]Got it working (see my previous edits) but sending 'status' and 'status\n' give nice errors:[/QUOTE] Indeed indeed, As facepunch havent released documentation on this yet we are sorta just doing gues work for the moment, it does look like we need to send back an JSON string tough Im still working on sending things to the server ;) [editline]25th February 2016[/editline] Indeed, sending a json formatted string like this works '{"Message": "say test"}' Il change the first post to reflect on our findings so others can easily get the information to :)
Made a bit of progress [IMG]http://i.imgur.com/ZssjWaT.png[/IMG] [B]In case image doesn't work:[/B] I sent [QUOTE]{"command":"status"}[/QUOTE] and received [QUOTE]{ "Message": "Null", "Identifier": 0, "Type": 3, "Stacktrace": "" } { "Message": "Command not found", "Identifier": 0, "Type": 3, "Stacktrace": "" } [/QUOTE] [editline]25th February 2016[/editline] Oh, your edit beat me to it :p [editline]25th February 2016[/editline] Got it! :D [QUOTE]{ "Message": "status", "Identifier": 0, "Type": 3, "Stacktrace": "" } { "Message": "hostname: ***\nversion : 1355 secure (secure mode enabled, connected to Steam3)\nmap : Procedural Map\nplayers : 0 (10 max) (0 queued) (0 joining)\n\nid name ping connected addr owner violation \r\n", "Identifier": 0, "Type": 3, "Stacktrace": "" }[/QUOTE]
Good work
Sorry, you need to Log In to post a reply to this thread.