Raised This Month: $51 Target: $400
 12% 

[EXTENSION][Any]Server Query 0.0.1.0[windows only]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 10-06-2012 , 09:45   [EXTENSION][Any]Server Query 0.0.1.0[windows only]
Reply With Quote #1

This extension allow you to get the server information with the given ip and port.
I'm new on SourceMod, so this is a Beta version.
Feedback are welcome.
about the server query click here.
sorry for my bad english.so not let's start with the pawn

ChangeLog:
Code:
0.0.0.1        Release version
0.0.0.2        Fixed wrong index at the recv pack data,add a timeout param into create_sq_info
0.0.1.0        Rewrite the code, and add player data and server rule type
                 change the recv data type, Like socket extension
new header file for SourceMod:
PHP Code:
#if defined _server_query_ext_included
 #endinput
#endif
#define _server_query_ext_included

enum DataType
{
    
DT_String_Start 0,
    
DT_HostName,
    
DT_MapName,
    
DT_Directory,
    
DT_Description,
    
DT_Version,
    
DT_String_End,
    
DT_Cell_Start,
    
DT_Protocol,
    
DT_AppID,
    
DT_Num,
    
DT_Max,
    
DT_Bots,
    
DT_Dedicated,
    
DT_OS,
    
DT_PassWord,
    
DT_Secure,
    
DT_Cell_End,
};

enum QueryType
{
    
QT_Start 0,
    
QT_Info,
    
QT_Players,
    
QT_Rules,
    
QT_End,
};

funcenum QueryInfo
{
  
/**
     * Call when the query server information success.
     * 
     * @param  DataTrie    Handle to the Data Trie, have not need to free.
     * @param  DataSize    The size of the recv data.
     * @noreturn
     */
  
public(Handle:DataTrie, const String:ServerIP[], ServerPortQueryType:typeDataSize),
}

/**
 * Create a hook to get server's info with given ip and port.
 * 
 * @param    _hostname    server ip or domain.
 * @param    _port        server port.
 * @param    _callback    a query callback.
 * @param    _timeout    where timeout is a value in microseconds
 * 
 * @return              1 on success, or 0 on failed.
 */
native CreateServerQuery(const String:_hostname[], _portQueryType:type QT_StartQueryInfo:callback);

/**
 * Get server string information with the data_type on the QueryInfo callback only.
 * 
 * @param  DataTrie      Handle to the data.
 * @param  data_type     Which string data will be output
 * @param  value         Buffer to store the output data.
 * @param  maxlen        Maximum length of string buffer.
 * 
 * @return               1 on success, or 0 on failed.
 */
native GetServerString(Handle:DataTrieDataType:data_type DT_String_StartString:value[], maxlen);

/**
 * Get server cell information with the data_type on the QueryInfo callback only.
 * 
 * @param  DataTrie      Handle to the data.
 * @param  data_type     Which string data will be output
 * @param  value         Data value.
 * 
 * @return               1 on success, or 0 on failed.
 */
native GetServerCell(Handle:DataTrieDataType:data_type DT_Cell_Start, &value);

/**
 * Get server player count.
 * 
 * @param    DataTrie    Handle to the data.
 * 
 * @return                server player count.
 */
native GetPlayerCount(Handle:DataTrie);

/**
 * Get server player data with the given index.
 * 
 * @param    DataTrie    Handle to the data.
 * @param    index        Data index.(start on 1, end on player count);
 * @param    name        user name.
 * @param    nameLen        max size of name.
 * @param    kills        player frag(s).
 * @param    pltime        play time of user.
 * 
 * @return                1 on success, or 0 on failed.
 */
native GetPlayerData(Handle:DataTrieindexString:name[], nameLen, &kills, &Float:play_time);

/**
 * Get server rules count.
 * 
 * @param    DataTrie    Handle to the data.
 * 
 * @return                server rules count.
 */
native GetRulesCount(Handle:DataTrie);

/**
 * Get server rules data with the given index.
 * 
 * @param    DataTrie    Handle to the data.
 * @param    index        Data index.(start on 1, end on rules count);
 * @param    name        rules name.
 * @param    nameLen        max size of name.
 * @param    value        rules value.
 * @param    valueLen    max size of value.
 * 
 * @return                1 on success, or 0 on failed.
 */
native GetRulesData(Handle:DataTrieindexString:name[], nameLenString:value[], valueLen);

/**
 * Get rule's value with the given name.
 * 
 * @param    DataTrie    Handle to the data.
 * @param    name        Name will be searched.
 * @param    value        rule's value.
 * @param    valueLen    max size of value.
 * 
 * @return                1 on success, or 0 on failed.
 */
native GetRule(Handle:DataTrie, const String:name[], String:value[], valueLen); 
a sample demo:
Code:
/* Plugin Template generated by Pawn Studio */ #include <sourcemod> #include <server_query_ext> public Plugin:myinfo = {     name = "query test",     author = "L.K",     description = "<- Description ->",     version = "1.0",     url = "<- URL ->" } public OnPluginStart() {     RegServerCmd("sq_test", SQ_Test);         PrintToServer("return %d", CreateServerQuery("www.test.com", 28010, QT_Info, TestCallBackOne)); } public Action:SQ_Test(args) {     CreateServerQuery("www.test.com", 28010, QT_Players, TestCallBackOne);     CreateServerQuery("www.test.com", 28010, QT_Rules, TestCallBackOne);     return Plugin_Handled; } public TestCallBackOne(Handle:DataTrie, const String:ServerIP[], ServerPort, QueryType:type, DataSize) {     switch (type)     {         case QT_Info:         {             decl String:hostname[256], String:version[32];             new app, num;             GetServerString(DataTrie, DT_HostName, hostname, sizeof(hostname));             GetServerString(DataTrie, DT_Version, version, sizeof(version));             GetServerCell(DataTrie, DT_Max, app);             GetServerCell(DataTrie, DT_Num, num);                         PrintToServer("\n\n\"hostname\" is \"%s\"\n\"version\" is \"%s\"\n\"protocol\" is \"%d\"\n\"DataSize\" is \"%d\"\n\"num\" is \"%d\"\n\n", hostname, version, app, DataSize, num);             LogMessage("\n\n\"hostname\" is \"%s\"\n\"version\" is \"%s\"\n\"protocol\" is \"%d\"\n\"DataSize\" is \"%d\"\n\n", hostname, version, app, DataSize);         }         case QT_Players:         {             new count = GetPlayerCount(DataTrie), kills, Float:pltime;             decl String:name[32];             if (GetPlayerData(DataTrie, 1, name, sizeof(name), kills, pltime))             {                 LogMessage("\n\n\"name\" is \"%s\"\n\"kills\" is \"%d\"\n\"play time\" is \"%f\"\n\"count\" is \"%d\"\n\n", name, kills, pltime, count);                 PrintToServer("\n\n\"name\" is \"%s\"\n\"kills\" is \"%d\"\n\"play time\" is \"%f\"\n\"count\" is \"%d\"\n\n", name, kills, pltime, count);             }         }         case QT_Rules:         {             new count = GetRulesCount(DataTrie);             decl String:name[256], String:value[256];             if (GetRulesData(DataTrie, 80, name, sizeof(name), value, sizeof(value)))             {                 LogMessage("\n\n\"name\" is \"%s\"\n\"value\" is \"%s\"\n\"count\" is \"%d\"\n\n", name, value, count);                 PrintToServer("\n\n\"name\" is \"%s\"\n\"value\" is \"%s\"\n\"count\" is \"%d\"\n\n", name, value, count);             }         }     } }

Tested On CS:GO and word fine !
Source
Download the last version.
Attached Files
File Type: zip Server_Query_Bin(Ver 0.0.1.0).zip (49.0 KB, 161 views)
__________________
QQ:116268742

Last edited by K.K.Lv; 10-14-2012 at 12:00.
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 10-06-2012 , 09:57   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #2

pointless, could be done with sockets extension and it has been already done before

https://forums.alliedmods.net/showthread.php?p=1036475
__________________
Taking private C++/PHP/SourcePawn requests, PM me.
Zephyrus is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 10-06-2012 , 10:03   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #3

Thx your link Zephyrus.I haven't search before I post this thread.
and I will add more feature something like query player or rules or ping.
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 10-06-2012 , 18:18   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #4

It could still be done in sourcepawn ;) You should consider writing some sourcepawn library instead of an extension.
__________________
Peace-Maker is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 10-07-2012 , 00:01   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #5

I think extension will more efficient than a sourcepawn library
of course I will gald to make a library with sourcepawn.
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 10-07-2012 , 02:08   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #6

a small update !
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
VoiDeD
AlliedModders Donor
Join Date: Mar 2009
Location: Illinois, USA
Old 10-07-2012 , 17:02   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #7

Quote:
Originally Posted by K.K.Lv View Post
I think extension will more efficient than a sourcepawn library
Far from it. Your extension is using blocking sockets and absolutely no threading.

There's no reason to use this over the socket extension.

On top of this, your get_string_info contains a memory leak. Given that, I imagine more of the code causes leaks, but I only gave it a cursory look.
__________________

Last edited by VoiDeD; 10-07-2012 at 17:07.
VoiDeD is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 10-08-2012 , 01:33   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #8

Quote:
Your extension is using blocking sockets and absolutely no threading.
you are right,i have found this point,and i was trying to use another way like socket extension

about the memory, I use the class, so I think the memory will be free when the class end(am I correct ?).
any problem please point it out .

at the end thx your post
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
FaTony
Veteran Member
Join Date: Aug 2008
Old 10-08-2012 , 05:08   Re: [EXTENSION][Any]Server Query[Beta Version windows only]
Reply With Quote #9

Quote:
Originally Posted by K.K.Lv View Post
about the memory, I use the class, so I think the memory will be free when the class end(am I correct ?).
Nope, for any new there must be a corresponding delete. And if third party library requires manual deallocation, you must do it.
__________________
FaTony is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 10-14-2012 , 12:01   Re: [EXTENSION][Any]Server Query 0.0.1.0[windows only]
Reply With Quote #10

update a new version !
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Reply



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 03:09.


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