Veteran Member
Join Date: Aug 2008
Location: GameFolder
|
10-06-2012
, 09:45
[EXTENSION][Any]Server Query 0.0.1.0[windows only]
|
#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[], ServerPort, QueryType:type, DataSize),
}
/**
* 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[], _port, QueryType:type = QT_Start, QueryInfo: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:DataTrie, DataType:data_type = DT_String_Start, String: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:DataTrie, DataType: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:DataTrie, index, String: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:DataTrie, index, String:name[], nameLen, String: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.
__________________
QQ:116268742
Last edited by K.K.Lv; 10-14-2012 at 12:00.
|
|