Vice City: Multiplayer

VC:MP Discussion => Support => Topic started by: Chicken on Feb 20, 2022, 08:07 AM

Title: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 20, 2022, 08:07 AM
How can I get the  of servers name, online players name and IP addresses in the VCMP masterlist from other clients
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: habi on Feb 20, 2022, 12:54 PM
Not understood. You are running a server and want to obtain list of other servers ??
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 21, 2022, 01:39 AM
Quote from: habi on Feb 20, 2022, 12:54 PMNot understood. You are running a server and want to obtain list of other servers ??
I want to make a website, how to get the server status on the website
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: habi on Feb 21, 2022, 04:50 AM
If you are building a website and you want the list of players name in the website there is a way. You will get the name of your server, gamemode, version and list of players playing in the server.
You have to create a udp socket in your website code. Are you scripting in php?
From this udp socket you have to send exactly two packets to the VCMP server you are running.
You must have port forwarding done already.
If so, VCMP Server will reply to this query with information mentioned on top.
Consider How can I send data with PHP to an IP address via UDP? (https://stackoverflow.com/questions/687765/how-can-i-send-data-with-php-to-an-ip-address-via-udp)
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 21, 2022, 09:57 AM
Quote from: habi on Feb 21, 2022, 04:50 AMIf you are building a website and you want the list of players name in the website there is a way. You will get the name of your server, gamemode, version and list of players playing in the server.
You have to create a udp socket in your website code. Are you scripting in php?
From this udp socket you have to send exactly two packets to the VCMP server you are running.
You must have port forwarding done already.
If so, VCMP Server will reply to this query with information mentioned on top.
Consider How can I send data with PHP to an IP address via UDP? (https://stackoverflow.com/questions/687765/how-can-i-send-data-with-php-to-an-ip-address-via-udp)

So what should I do is use socket to send data to the server and then let the server return data to the website?
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 21, 2022, 10:04 AM
Quote from: habi on Feb 21, 2022, 04:50 AMIf you are building a website and you want the list of players name in the website there is a way. You will get the name of your server, gamemode, version and list of players playing in the server.
You have to create a udp socket in your website code. Are you scripting in php?
From this udp socket you have to send exactly two packets to the VCMP server you are running.
You must have port forwarding done already.
If so, VCMP Server will reply to this query with information mentioned on top.
Consider How can I send data with PHP to an IP address via UDP? (https://stackoverflow.com/questions/687765/how-can-i-send-data-with-php-to-an-ip-address-via-udp)

There are few ways to use socket plugins in VCMP. Can you tell me which events and functions should I use?
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: habi on Feb 21, 2022, 11:36 AM
Sure. add socket04rel64 to server.cfg
Then, in your main.nut after the bottom line or in onScriptLoad add
s<-NewSocket(dataReceived);Before this, somewhere you must define dataReceived function.
function dataReceived( data )
{
print("Received data: "+data+"\n");
if(data=="players")
s.Send(GetPlayerCount()+"");
}
Try and tell what Happened

Ref:Ref: wiki NewSocket (http://wiki.thijn.ovh/index.php?title=Scripting/Squirrel/Functions/NewSocket)
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Xmair on Feb 21, 2022, 12:04 PM
I don't really understand what you really mean but if you want to make something such as a server browser, here's what you need to do:

Firstly, you make a GET request to a master list URL (I usually use https://master.thijn.ovh/). This returns a JSON array of servers. You are provided with each announced server's IP, port and official status.

Afterwards, you loop through the server list received from the master list and you send a UDP packet to each of them. There's more information about this in the following wiki page:
http://wiki.thijn.ovh/index.php?title=Query_Mechanism

The page is pretty self explanatory but if you still face issues, you can always use a reference such as:
https://github.com/BigETI/SAMPLauncherNET/blob/master/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 21, 2022, 12:05 PM
Quote from: habi on Feb 21, 2022, 11:36 AMSure. add socket04rel64 to server.cfg
Then, in your main.nut after the bottom line or in onScriptLoad add
s<-NewSocket(dataReceived);Before this, somewhere you must define dataReceived function.
function dataReceived( data )
{
print("Received data: "+data+"\n");
if(data=="players")
s.Send(GetPlayerCount()+"");
}
Try and tell what Happened

Ref:Ref: wiki NewSocket (http://wiki.thijn.ovh/index.php?title=Scripting/Squirrel/Functions/NewSocket)
Do I want to use Socket.Start(port,maxConn)??
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 21, 2022, 12:06 PM
Quote from: habi on Feb 21, 2022, 11:36 AMSure. add socket04rel64 to server.cfg
Then, in your main.nut after the bottom line or in onScriptLoad add
s<-NewSocket(dataReceived);Before this, somewhere you must define dataReceived function.
function dataReceived( data )
{
print("Received data: "+data+"\n");
if(data=="players")
s.Send(GetPlayerCount()+"");
}
Try and tell what Happened

Ref:Ref: wiki NewSocket (http://wiki.thijn.ovh/index.php?title=Scripting/Squirrel/Functions/NewSocket)
used your method and didn't return a value
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 21, 2022, 12:10 PM
Quote from: Xmair on Feb 21, 2022, 12:04 PMI don't really understand what you really mean but if you want to make something such as a server browser, here's what you need to do:

Firstly, you make a GET request to a master list URL (I usually use https://master.thijn.ovh/). This returns a JSON array of servers. You are provided with each announced server's IP, port and official status.

Afterwards, you loop through the server list received from the master list and you send a UDP packet to each of them. There's more information about this in the following wiki page:
http://wiki.thijn.ovh/index.php?title=Query_Mechanism

The page is pretty self explanatory but if you still face issues, you can always use a reference such as:
https://github.com/BigETI/SAMPLauncherNET/blob/master/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs
It's the same as you said, but I took out the IP and port and there is no way to convert it to the server name and the names of all online players
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 21, 2022, 12:17 PM
Quote from: Chicken on Feb 21, 2022, 12:10 PM
Quote from: Xmair on Feb 21, 2022, 12:04 PMI don't really understand what you really mean but if you want to make something such as a server browser, here's what you need to do:

Firstly, you make a GET request to a master list URL (I usually use https://master.thijn.ovh/). This returns a JSON array of servers. You are provided with each announced server's IP, port and official status.

Afterwards, you loop through the server list received from the master list and you send a UDP packet to each of them. There's more information about this in the following wiki page:
http://wiki.thijn.ovh/index.php?title=Query_Mechanism

The page is pretty self explanatory but if you still face issues, you can always use a reference such as:
https://github.com/BigETI/SAMPLauncherNET/blob/master/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs
It's the same as you said, but I took out the IP and port and there is no way to convert it to the server name and the names of all online players
Quote from: Xmair on Feb 21, 2022, 12:04 PMI don't really understand what you really mean but if you want to make something such as a server browser, here's what you need to do:

Firstly, you make a GET request to a master list URL (I usually use https://master.thijn.ovh/). This returns a JSON array of servers. You are provided with each announced server's IP, port and official status.

Afterwards, you loop through the server list received from the master list and you send a UDP packet to each of them. There's more information about this in the following wiki page:
http://wiki.thijn.ovh/index.php?title=Query_Mechanism

The page is pretty self explanatory but if you still face issues, you can always use a reference such as:
https://github.com/BigETI/SAMPLauncherNET/blob/master/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs
Quote from: Xmair on Feb 21, 2022, 12:04 PMI don't really understand what you really mean but if you want to make something such as a server browser, here's what you need to do:

Firstly, you make a GET request to a master list URL (I usually use https://master.thijn.ovh/). This returns a JSON array of servers. You are provided with each announced server's IP, port and official status.

Afterwards, you loop through the server list received from the master list and you send a UDP packet to each of them. There's more information about this in the following wiki page:
http://wiki.thijn.ovh/index.php?title=Query_Mechanism

The page is pretty self explanatory but if you still face issues, you can always use a reference such as:
https://github.com/BigETI/SAMPLauncherNET/blob/master/SAMPLauncherNET/Source/SAMPLauncherNET/Core/Server.cs
I probably understand, is it possible to get the server name by sending a data packet whose protocol is UDP and whose format is byte set 32+strlen to the server IP and port?
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: habi on Feb 21, 2022, 12:21 PM
Quote from: Chicken on Feb 21, 2022, 12:05 PMDo I want to use Socket.Start(port,maxConn)??
Yes.
s<-NewSocket(dataReceived)
s.Start( 5192, 12 );
Then from website create socket and  connect to your server using port 5192.
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Xmair on Feb 22, 2022, 11:12 AM
Quote from: Chicken on Feb 21, 2022, 12:17 PMI probably understand, is it possible to get the server name by sending a data packet whose protocol is UDP and whose format is byte set 32+strlen to the server IP and port?
Yes it is possible to get the server name by sending a UDP dgram packet. However I don't think you understand how to parse the result properly so I would suggest you to just use premade code. Fleka did something a few years ago: https://forum.vc-mp.org/?topic=5530.msg39171#msg39171

One small thing to note is you should try changing the magic to 'VCMP' instead of 'MP04' since back when I was coding a browser, some servers wouldn't work if you used 'MP04' as magic.
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 22, 2022, 03:33 PM
Quote from: Xmair on Feb 22, 2022, 11:12 AM
Quote from: Chicken on Feb 21, 2022, 12:17 PMI probably understand, is it possible to get the server name by sending a data packet whose protocol is UDP and whose format is byte set 32+strlen to the server IP and port?
Yes it is possible to get the server name by sending a UDP dgram packet. However I don't think you understand how to parse the result properly so I would suggest you to just use premade code. Fleka did something a few years ago: https://forum.vc-mp.org/?topic=5530.msg39171#msg39171

One small thing to note is you should try changing the magic to 'VCMP' instead of 'MP04' since back when I was coding a browser, some servers wouldn't work if you used 'MP04' as magic.
I understand what you mean, but now there is a question, how should I convert hex and bytes to each other
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: habi on Feb 24, 2022, 01:40 AM
When sending request to server, there is no need to convert hex or byte. It is the same packet every time. I remember last byte of packet is i or c. if it is i, you want information no.1
If it is c, you want information no.2 from server.
And information no.1 is servers name, gamemode, no.of players.
Information 2 contains names of all the players.
wiki (http://wiki.thijn.ovh/index.php?title=Query_Mechanism)
Could you be more specific in asking about convert hex to bytes?
like I have this byte, how i convert this bytes to ascii, etc.
Iterate through the buffer received from server. Or Post the buffer received here. We can help you
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 24, 2022, 05:08 AM
Quote from: habi on Feb 24, 2022, 01:40 AMWhen sending request to server, there is no need to convert hex or byte. It is the same packet every time. I remember last byte of packet is i or c. if it is i, you want information no.1
If it is c, you want information no.2 from server.
And information no.1 is servers name, gamemode, no.of players.
Information 2 contains names of all the players.
wiki (http://wiki.thijn.ovh/index.php?title=Query_Mechanism)
Could you be more specific in asking about convert hex to bytes?
like I have this byte, how i convert this bytes to ascii, etc.
Iterate through the buffer received from server. Or Post the buffer received here. We can help you
http://wiki.thijn.ovh/index.php?title=Query_Mechanism said that Byte4-10 is composed of IP address and port. If I enter a specified IP address to request a query, what should I do?
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: habi on Feb 24, 2022, 07:40 AM
I will show you a live demonstration. This will be helpful for others too in learning wireshark.
See i opened VCMPBrowser and
(https://i.imgur.com/coUYNkL.png)
I clicked on a server shown in the image. At that moment Browser sends packets to that server.

I had already opened wireshark( packet capturing tool) and see what it captured
(https://i.imgur.com/mmtbVZV.png)
The data section of packet which is highlighted in blue. Its ASCII equivalent is shown on right.

56 43 4d 50 41 02 41 d3 00 20 69

Lets investigate what this is.
56 means 5*16+6=80+6=86 and 86 means 'V' in ascii table. ascii table (https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html)
So first 4 bytes( each of these two digits is called byte) 56 43 4d 50 means VCMP

Now, what is 41=16*4+1=65
02=2
41=again, 65
d3=d*16+3=13*16+3=211
So the 4 bytes 41 02 41 d3 gives 65 2 65 211
Now what is the server ip from VCMP Browser?
(https://i.imgur.com/uVTfCBq.png)
Ha. it is exactly the same.

The next 2 bytes viz 00 20 and port 8192 on investigation showed me. port= 00 +( 20 *256 )= 00 + (32*256)=00+8192. This is becauses 20 means 2*16+0=32

The last byte is 69. This is the ASCII equivalent of 'i'. You can see it on the right panel of wireshark window.
i means we want information about server name, gamemode etc.

Having learnt this. you could do the reverse. Will you?
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: Chicken on Feb 24, 2022, 11:34 AM
Quote from: habi on Feb 24, 2022, 07:40 AMI will show you a live demonstration. This will be helpful for others too in learning wireshark.
See i opened VCMPBrowser and
(https://i.imgur.com/coUYNkL.png)
I clicked on a server shown in the image. At that moment Browser sends packets to that server.

I had already opened wireshark( packet capturing tool) and see what it captured
(https://i.imgur.com/mmtbVZV.png)
The data section of packet which is highlighted in blue. Its ASCII equivalent is shown on right.

56 43 4d 50 41 02 41 d3 00 20 69

Lets investigate what this is.
56 means 5*16+6=80+6=86 and 86 means 'V' in ascii table. ascii table (https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html)
So first 4 bytes( each of these two digits is called byte) 56 43 4d 50 means VCMP

Now, what is 41=16*4+1=65
02=2
41=again, 65
d3=d*16+3=13*16+3=211
So the 4 bytes 41 02 41 d3 gives 65 2 65 211
Now what is the server ip from VCMP Browser?
(https://i.imgur.com/uVTfCBq.png)
Ha. it is exactly the same.

The next 2 bytes viz 00 20 and port 8192 on investigation showed me. port= 00 +( 20 *256 )= 00 + (32*256)=00+8192. This is becauses 20 means 2*16+0=32

The last byte is 69. This is the ASCII equivalent of 'i'. You can see it on the right panel of wireshark window.
i means we want information about server name, gamemode etc.

Having learnt this. you could do the reverse. Will you?

In fact, I have already captured the package and extracted the data a few days ago, but I don't know how to specify an IP address and port, maybe your explanation will help me, thank you Habi :D
Title: Re: How can I obtain VCMP master list information from other clients??
Post by: 2b2ttianxiu on Jan 15, 2023, 11:39 AM
Quote from: Chicken on Feb 24, 2022, 11:34 AM
Quote from: habi on Feb 24, 2022, 07:40 AMI will show you a live demonstration. This will be helpful for others too in learning wireshark.
See i opened VCMPBrowser and
(https://i.imgur.com/coUYNkL.png)
I clicked on a server shown in the image. At that moment Browser sends packets to that server.

I had already opened wireshark( packet capturing tool) and see what it captured
(https://i.imgur.com/mmtbVZV.png)
The data section of packet which is highlighted in blue. Its ASCII equivalent is shown on right.

56 43 4d 50 41 02 41 d3 00 20 69

Lets investigate what this is.
56 means 5*16+6=80+6=86 and 86 means 'V' in ascii table. ascii table (https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html)
So first 4 bytes( each of these two digits is called byte) 56 43 4d 50 means VCMP

Now, what is 41=16*4+1=65
02=2
41=again, 65
d3=d*16+3=13*16+3=211
So the 4 bytes 41 02 41 d3 gives 65 2 65 211
Now what is the server ip from VCMP Browser?
(https://i.imgur.com/uVTfCBq.png)
Ha. it is exactly the same.

The next 2 bytes viz 00 20 and port 8192 on investigation showed me. port= 00 +( 20 *256 )= 00 + (32*256)=00+8192. This is becauses 20 means 2*16+0=32

The last byte is 69. This is the ASCII equivalent of 'i'. You can see it on the right panel of wireshark window.
i means we want information about server name, gamemode etc.

Having learnt this. you could do the reverse. Will you?

In fact, I have already captured the package and extracted the data a few days ago, but I don't know how to specify an IP address and port, maybe your explanation will help me, thank you Habi :D

use Python, u can do this data: b'VCMP\x7f\x00\x00\x01H\x14' and can get many servers.