Raised This Month: $32 Target: $400
 8% 

[NATIVE] Server Queries


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-11-2010 , 02:42   [NATIVE] Server Queries
Reply With Quote #1

Introduction:
This set of functions is to be able to query a server by IP:port for it's information or players list.
This is how xRedirect or other plugins show information about a server, but makes it easier for other coders who want to do it.
It is equipped with various functions and functionality for error reporting and statistics about the query.


Constants:
These constants are used inside the core plugin as well as the plugins that use this include:
Spoiler



Primary Native:
Spoiler



Error Checking:
There are 2 ways that a query can result in no results:
  • Problem with sq_query() call
  • Could not read results in time, so callback function has failed set to true

Error Check #1:
To check the first error, you need to check for a valid SQuery ID.
Spoiler

When this happens, you can get a descriptive string from the error code for reporting:
Spoiler

Here is an example of using this:
Spoiler


Error Check #2:
The second error checking takes place inside the callback function:
Spoiler



Buffer Reading:
When the query is successful and the callback function has a buffer that contains data, the buffer needs to be read into variables.

Depending on the query type and response type, the buffer Trie is filled data according to the query.

Server Response (Source)
Source servers and updated CS 1.6 Steam servers use this response.
Should also work for SourceTVs.
Spoiler

If the server is a The Ship server, then additional data is added to the buffer:
Spoiler

Server Response (GoldSource)
Original HL Games which are not updated to the latest 48 protocol.
This should only work for HLTVs, HL1-based games (not CS), and Non-Steam CS servers.
If a Steam server is running dproto, this will be the response that is given back.
Spoiler

If the game is a mod for HL, the following will be added to the response buffer:
Spoiler

Players Response
Spoiler

Example:
Spoiler

Challenge Response
Spoiler

To get the 4 bytes of the challenge:
Spoiler

Ping Response
Spoiler

Rules Response
Spoiler

Example:
Spoiler

You can use this function to get a description of the server type:
Spoiler

Here is how it is used:
Spoiler


A function exists to convert the time played into 2 formats:
Spoiler

Here is an example usage:
Spoiler


Use this function for getting a description for The Ship's game mode:
Spoiler

Here is an example usage:
Spoiler



Notes About Callback Function:
When using callback functions, it is necessary to do consider each of the following:
  • If using the same callback function for different query types, the query type should be check inside the function before reading a buffer:
    Spoiler
  • If using the same callback for queries that are executed at the same time, you should check the squery_id to know which results are found.
    This is because there is no guarantee that the queries are going to give results in the order that you called sq_query().
    Spoiler


Requirements:
  • AMX Mod X 1.8.1 or higher
  • Regex Module
  • Sockets Module


Installation:


Ending Notes:
There are more functions inside the include file that are used behind-the-scenes in the other functions or in the core plugin.

server_query_interface.sma is the test plugin I used if you would like to see what I did.
Here are the results from testing (server is the first server I found that had players in my "Internet" servers list).

Servers Info:
Spoiler


Players Info:
Spoiler


Challenge Info:
Spoiler


Ping Info:
Spoiler


Rules Info:
Spoiler



All suggestions and reported bugs are welcome.
Credits
xPaw helped me with few problems. Also, his PHP Source Query Class helped guide me along some questions I had.
Attached Files
File Type: inc server_query.inc (11.5 KB, 1265 views)
File Type: sma Get Plugin or Get Source (server_query_api.sma - 2126 views - 26.7 KB)
File Type: sma Get Plugin or Get Source (server_query_interface.sma - 1994 views - 4.8 KB)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 06-12-2012 at 09:34. Reason: Added credits to xPaw.
Exolent[jNr] is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 11-11-2010 , 03:44   Re: [NATIVE] Server Queries
Reply With Quote #2

Great plugin

You know, I see people doing this a lot, and there's absolutely no need for this:
Code:
register_native( "sq_query", "_sq_query" );

Unless for some obscure reason you include the .inc in your own plugin, you can use a callback with the same name of the command.

EDIT: you use amxx studio D:
Seta00 is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 11-11-2010 , 04:18   Re: [NATIVE] Server Queries
Reply With Quote #3

Yeah !second post !
good job man !
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-11-2010 , 12:17   Re: [NATIVE] Server Queries
Reply With Quote #4

Quote:
Originally Posted by Seta00 View Post
Great plugin

You know, I see people doing this a lot, and there's absolutely no need for this:
Code:
register_native( "sq_query", "_sq_query" );

Unless for some obscure reason you include the .inc in your own plugin, you can use a callback with the same name of the command.

EDIT: you use amxx studio D:
Thanks

I do include the .inc file.

Nothing wrong with AMXX Studio. I use it for the syntax highlighting, the tooltip when writing a function or constant, and the function parameter list box on the right when you are calling a function.

Quote:
Originally Posted by K.K.Lv View Post
Yeah !second post !
good job man !
Thanks!
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-11-2010 , 12:48   Re: [NATIVE] Server Queries
Reply With Quote #5

Nice work Exolent

What's wrong with using AMX-X studio? Just wondering.
__________________
Bugsy is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 11-11-2010 , 17:06   Re: [NATIVE] Server Queries
Reply With Quote #6

Wow, all the new modules and includes are actually useful

THANKS
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-11-2010 , 19:03   Re: [NATIVE] Server Queries
Reply With Quote #7

Ideas for an update:
  • IP and port as parameters in callback function
  • ability to set timeout values rather than use the API's default
  • change to unlimited number of connections
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 11-11-2010 , 19:48   Re: [NATIVE] Server Queries
Reply With Quote #8

Quote:
Originally Posted by Exolent[jNr] View Post
I do include the .inc file.
lol I didn't open the include file, they are normally just the native/forward declarations.

Quote:
Nothing wrong with AMXX Studio. I use it for the syntax highlighting, the tooltip when writing a function or constant, and the function parameter list box on the right when you are calling a function.
Quote:
Originally Posted by Bugsy View Post
What's wrong with using AMX-X studio? Just wondering.
I just find it freaking ugly. I was using Pawn Studio on Windows until I discovered there's gedit for Windows! And gedit > all:

http://dl.dropbox.com/u/10968786/gedit.png

You may think "teck no! dark themes suck!", but this one specifically besides being sexy doesn't hurt your eyes if you code in the dark (like I do most of the time)

Last edited by Seta00; 11-11-2010 at 19:48. Reason: okay that image was a little too big :P
Seta00 is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 11-11-2010 , 20:05   Re: [NATIVE] Server Queries
Reply With Quote #9

Quote:
Originally Posted by Seta00 View Post
lol I didn't open the include file, they are normally just the native/forward declarations.





I just find it freaking ugly. I was using Pawn Studio on Windows until I discovered there's gedit for Windows! And gedit > all:

http://dl.dropbox.com/u/10968786/gedit.png

You may think "teck no! dark themes suck!", but this one specifically besides being sexy doesn't hurt your eyes if you code in the dark (like I do most of the time)
Link, please.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 11-12-2010 , 04:46   Re: [NATIVE] Server Queries
Reply With Quote #10

Quote:
Originally Posted by wrecked_ View Post
Link, please.
sudo apt-get install gmate

or if you're on Windows:

http://projects.gnome.org/gedit/
https://github.com/gmate/gmate

The name of the theme I use is Darkmacs. You will have to manually install the themes/plugins/etc on Windows, just check the install.sh file.

Also with the External Tools plugin you can have one button compile as well ;)
(Not sure if it works on Windows though)
Seta00 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:55.


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