AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [DEV] WebSocket Server - Direct connection between webbrowser and gameserver (https://forums.alliedmods.net/showthread.php?t=182615)

imdawe 09-05-2013 23:23

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Please update this plugin, it does not worked for me on css.

I have modified these lines, i just specified a protocol. so it works now in motd
Quote:

iSubStrings = MatchRegex(g_hRegExProtocol, receiveData, iRegexError);
new String:sProtocol[256];
if(iSubStrings != -1)
{
if(!GetRegexSubString(g_hRegExProtocol, 1, sProtocol, sizeof(sProtocol)))
{
Format(sProtocol, sizeof(sProtocol), "sm");
// It's not required to specify a subprotocol!
/*LogError("Failed to extract sub protocols.");
CloseChildSocket(iIndex);
return;*/
}
}

Peace-Maker 09-06-2013 20:04

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
I haven't tried to use the motd browser to connect to a websocket server created with this plugin.
What's the error? Does the client reject the connection when lacking a sub protocol?

imdawe 09-07-2013 09:58

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Uhm, i don't remember, but adding protocol will solve the problem.

Dr. McKay 09-13-2013 17:11

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Not sure if it's supposed to support SSL, but when connecting via wss:// I get this:

Code:

[websocket.smx] Failed to extract security key.

n___ 11-10-2013 01:02

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
I get the same error as above when attempting to connect with NodeJS and socket.io
Not familiar with sp, any pointers on where I might be going wrong?

The client.html.txt code works to send messages to the server, but not the following node code

Code:

var io = require('socket.io-client'),
        socket = io.connect('myhost.com', {
            port: 12345
        });


socket.on('connect', function() {
    socket.send("Hello Websockets from Node!");
});


Dr. McKay 11-10-2013 01:40

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by n___ (Post 2059006)
I get the same error as above when attempting to connect with NodeJS and socket.io
Not familiar with sp, any pointers on where I might be going wrong?

The client.html.txt code works to send messages to the server, but not the following node code

Code:

var io = require('socket.io-client'),
        socket = io.connect('myhost.com', {
            port: 12345
        });


socket.on('connect', function() {
    socket.send("Hello Websockets from Node!");
});


If you're trying to communicate with the server using anything besides a web browser (in this case, it looks like you're trying to facilitate communication between a game server and a Node.js program?), you should really use plain sockets.

n___ 11-10-2013 09:03

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
I understand that, it was mainly for experimental purposes. There is a node module called node-ssq, which I guess uses datagram to connect to a source server.

Code:

var ssq = require('node-ssq');

ssq.info('myhost.com', 27015, function (err, data) {
    if (err)
        console.log("Error", err);
    else
        console.log(data);
});

Gives me
Error [Error: SSQ Request timed out.]

I guess I could start playing with it and try to find out why it's not working.

n___ 11-10-2013 09:16

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
--- IGNORE--- Had to remove the portion that sets the timeout and clears it in node-ssq/ssq.js, after doing so, it queries the server fine.


I'm ashamed to admit this lol, but my source server wasn't running. :(

Internet Bully 05-12-2014 20:08

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
I got it up and running on CSGO to the point where I can draw players on a radar image. How does one get the information from the .txt file (offsets, zoom, etc)? csgo\resource\overviews has txt files with similar-ish information, but fails to work.

Right now I'm just guessing and it's working well enough, but it'd be nice to automate it.

Crytiqal 05-13-2014 05:40

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Is it possible to implement a tv_delay on the websocket?

I can ghost all I want. I was trying to get it to connect to a delayed relay server but it seems I cannot open a socket connection to it so that wont work...

Also, connecting it to the tv_port from a gameserver with a tv_delay set doesn't matter as the socket sends the data instantly to the browser regardless.

Peace-Maker 01-12-2017 21:59

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Updated to version 1.2

This includes support for incoming fragmented frames and fixes compilation on SM 1.7.
Download in the first post.

Arkarr 01-13-2017 01:04

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Yay ! Thanks !

Kinsi 02-21-2017 13:17

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Is it somehow possible to get connection parameters (ws://host:port/path/?parameters...), and reject / "force-disconnect" clients to kinda implement authorization?

Edit: looks like, force-closing is possible but theres no built-in way to get the request path. Ill add that in and propose a PR :P

Edit2: took me way too long to find out it's easy to add but the PR's there now :) https://github.com/peace-maker/sm-websocket/pull/4

ESK0 09-05-2017 15:30

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Something is wrong with Websocket_Open?


Code:

SourcePawn Compiler 1.8.0.6025
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2015 AlliedModders LLC
 
D:\Sourcemod\WebSocket - Test\websocket_sourcetv2d (1).sp(111) : error 100: function prototypes do not match
 
1 Error.

Line 111
Quote:

g_hListenSocket = Websocket_Open(sServerIP, 12346, OnWebsocketIncoming, OnWebsocketMasterError, OnWebsocketMasterClose);

Peace-Maker 09-06-2017 11:24

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
I'm guessing you're using the include file from the repository?
The WebsocketIncomingCB signature changed without backwards compatibility - redownload the include file from the repo.
https://github.com/peace-maker/sm-we...d7c154fe46ddd4

Papero 05-28-2018 08:36

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by Dr. McKay (Post 2034004)
Not sure if it's supposed to support SSL, but when connecting via wss:// I get this:

Code:

[websocket.smx] Failed to extract security key.

Is there any way to support the wss:// now?
(Am getting that error too)

asherkin 05-28-2018 09:08

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by Papero (Post 2594224)
Is there any way to support the wss:// now?
(Am getting that error too)

No.

Papero 06-22-2018 13:18

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by asherkin (Post 2594233)
No.

To make it work with wss:// (https) would I have to edit the plugin or the Socket extension?

Peace-Maker 06-22-2018 13:45

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
You'd need an extension that provides you with a raw socket interface that's tunneled through a TLS encrypted connection. The protocol itself doesn't change.

Papero 06-22-2018 14:17

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by Peace-Maker (Post 2598715)
You'd need an extension that provides you with a raw socket interface that's tunneled through a TLS encrypted connection. The protocol itself doesn't change.

Atm that's out of my knowledge, if someone could write it for free or not(if so it'd be a public release) would be nice

morpig 09-27-2018 18:30

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Hi, I used this plugin couple months ago for RCON on SM 1.8. Does this still work in 1.9?

8guawong 09-28-2018 02:17

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by morpig (Post 2617049)
Hi, I used this plugin couple months ago for RCON on SM 1.8. Does this still work in 1.9?

try it?

i don't see why not

Papero 10-06-2018 12:50

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
On sourcemod 1.9 whenever the browser tries to connect to the websocket server I get this error:

Code:

L 10/06/2018 - 12:45:53: [SM] Exception reported: Invalid match index passed.

L 10/06/2018 - 12:45:53: [SM] Blaming: websocket.smx
L 10/06/2018 - 12:45:53: [SM] Call stack trace:
L 10/06/2018 - 12:45:53: [SM]  [0] GetRegexSubString
L 10/06/2018 - 12:45:53: [SM]  [1] Line 753, C:\Users\Jannik\Documents\GitHub\sm-websocket\scripting\websocket.sp::OnChildSocketReceive

Has anyone ever noticed this or knows a fix?

mkvegas 06-09-2019 19:02

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by Papero (Post 2618536)
On sourcemod 1.9 whenever the browser tries to connect to the websocket server I get this error:

Code:

L 10/06/2018 - 12:45:53: [SM] Exception reported: Invalid match index passed.

L 10/06/2018 - 12:45:53: [SM] Blaming: websocket.smx
L 10/06/2018 - 12:45:53: [SM] Call stack trace:
L 10/06/2018 - 12:45:53: [SM]  [0] GetRegexSubString
L 10/06/2018 - 12:45:53: [SM]  [1] Line 753, C:\Users\Jannik\Documents\GitHub\sm-websocket\scripting\websocket.sp::OnChildSocketReceive

Has anyone ever noticed this or knows a fix?

I have the same problem SM 1.9.0anyone knows any fixes?? :cry:

Peace-Maker 06-20-2019 17:41

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
That error should be fixed in the latest version in the repository on GitHub.

hASVAN 11-22-2019 22:06

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Hey Bro. I have a problem with your plugin every time the Websocket tries to connect I get this (Disconnected - status 3 Code: 1006. Reason: - wasClean: false) im using the WebSocket chat Example

hASVAN 11-22-2019 22:33

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
and now I have this error

HTML Code:

L 11/23/2019 - 03:32:31: [SM] Blaming: websocket.smx
L 11/23/2019 - 03:32:31: [SM] Call stack trace:
L 11/23/2019 - 03:32:31: [SM]  [0] GetRegexSubString
L 11/23/2019 - 03:32:31: [SM]  [1] Line 753, C:\Users\Jannik\Documents\GitHub\sm-websocket\scripting\websocket.sp::OnChildSocketReceive
L 11/23/2019 - 03:32:38: [SM] Exception reported: Invalid data pack handle 2 (error 7).


Peace-Maker 11-23-2019 05:58

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Try the latest version from GitHub. You'll have to compile it yourself though.

hASVAN 11-24-2019 16:06

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
when I try to compile it. I get this error

HTML Code:

//// websocket.sp
//
// G:\scripting\include\socket.inc(203) : fatal error 196: deprecated syntax; see https://wiki.alliedmods.net/SourcePawn_Transitional_Syntax#Typedefs
//
// Compilation aborted.
// 1 Error.
//
// Compilation Time: 0,98 sec
// ----------------------------------------


AK978 03-31-2020 11:41

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
2 Attachment(s)
socket.inc and websocket.inc file.

CaptainZidgel 09-18-2022 00:46

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Update: As I suspected, I am an idiot. The issue causing the Invalid Handle error was that my code was in OnPluginStart as opposed to OnAllPluginsLoaded. I plan to get around the lack of ability to select a path endpoint (site.com:port/endpoint) by just using an additional port. However I am now experiencing "Unable to listen on ip: port". Investigating whether this is an issue with my webserver though (most likely).
Original post:
Can someone tell me if I have this right:
I can only create listening servers using
Code:

Websocket_Open(host, port, callbacks...)
where host is the game server's IP.
I assume this is the case because both the author's example programs listen on the same server.
This is actually fine while I'm in dev but in production I'll want to have my game servers on a different server than my webserver. However I still must be doing something wrong, because when I try to use Websocket_Open I get this exception: Invalid Handle 0 (error: 4)
Code:

#include <sourcemod>
#include <tf2_stocks>
#include <entity_prop_stocks>
#include <sdkhooks>
#include <morecolors>
#include <websocket>
WebsocketHandle wsHandle = INVALID_WEBSOCKET_HANDLE;
//----------------------------------------excerpt from OnPluginStart:
{
char txtfile[256];
BuildPath(Path_SM, txtfile, sizeof(txtfile), "configs/mything.cfg");
       
KeyValues kv = new KeyValues("mything");
kv.ImportFromFile(txtfile);

kv.Rewind();
       
char wsHost[64], wsPortStr[12];
kv.GetString("host", wsHost, 64); //this properly reads as my ip string (x.x.x.x)
kv.GetString("port", wsPortStr, 12);
int wsPort = StringToInt(wsPortStr);
delete kv;
PrintToServer("*+*+*+*+*+*+*+*+*+*+*+*+*+ connecting to server @ %s@%i", wsHost, wsPort); //all good here, both server and port are correct. my ws host and game server are on the same ip. my webserver port is 8080. actually my webserver endpoint is :8080/somePath. Is that an issue?
       
wsHandle = Websocket_Open(wsHost, wsPort, wsIncomingCallback, wsErrCallback, wsCloseCallback); //<--- erroring line: full traceback in next block
bool ok = Websocket_Send(wsHandle, SendType_Text, "Hello world!");
}
//-------------------------------------------My Callbacks:
public Action wsIncomingCallback(WebsocketHandle parent, WebsocketHandle child, const char[] host, int port, char protocols[256], char GETPath[2000])
{
        return Plugin_Continue;
}

public void wsCloseCallback(WebsocketHandle socket)
{
        socket = INVALID_WEBSOCKET_HANDLE;
}

public void wsErrCallback(WebsocketHandle socket, const int errType, const int errNum)
{

}

Code:

L 09/17/2022 - 23:24:40: [SM] Exception reported: Invalid Handle 0 (error: 4)
L 09/17/2022 - 23:24:40: [SM] Blaming: websocket.smx
L 09/17/2022 - 23:24:40: [SM] Call stack trace:
L 09/17/2022 - 23:24:40: [SM]  [0] GetArraySize
L 09/17/2022 - 23:24:40: [SM]  [1] Line 171, C:\Users\Jannik\Documents\GitHub\sm-websocket\scripting\websocket.sp::Native_Websocket_Open
L 09/17/2022 - 23:24:40: [SM]  [3] Websocket_Open
L 09/17/2022 - 23:24:40: [SM]  [4] Line 458, /home/steam/steamcmd/tf2/tf/addons/sourcemod/scripting/mything.sp::OnPluginStart

If I want to send out a message, I have to hook incoming messages, store that handle somewhere, then use websocket_send to send something out.
What if I want to create an outgoing message to a foreign server at will? My main desire for websockets is for my game servers to be clients, chiefly.

Peace-Maker 11-14-2022 10:20

Re: [DEV] WebSocket Server - Direct connection between webbrowser and gameserver
 
Quote:

Originally Posted by CaptainZidgel (Post 2789058)
Update: As I suspected, I am an idiot. The issue causing the Invalid Handle error was that my code was in OnPluginStart as opposed to OnAllPluginsLoaded. I plan to get around the lack of ability to select a path endpoint (site.com:port/endpoint) by just using an additional port. However I am now experiencing "Unable to listen on ip: port". Investigating whether this is an issue with my webserver though (most likely).

The latest development version received another parameter on the incoming connection callback with the `GET /path` used in the connection. It's not included in any released binaries
https://github.com/peace-maker/sm-websocket/pull/4

Quote:

Originally Posted by CaptainZidgel (Post 2789058)
If I want to send out a message, I have to hook incoming messages, store that handle somewhere, then use websocket_send to send something out.
What if I want to create an outgoing message to a foreign server at will? My main desire for websockets is for my game servers to be clients, chiefly.

This plugin doesn't implement the client side of websockets.


All times are GMT -4. The time now is 13:48.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.