Raised This Month: $ Target: $400
 0% 

Simple sockets to get server status


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
faki
Senior Member
Join Date: Jul 2013
Old 12-30-2013 , 14:24   Simple sockets to get server status
Reply With Quote #1

Hello i have this:
Code:
stock get_data(host[])
{
new ip[32], port[10], err;
copy(ip,charsmax(ip),host);
copy(port,charsmax(port),"27015");
if(containi(host,":")!=-1)
strtok(host, ip, charsmax(ip), port, charsmax(port), ':');

new sock = socket_open(ip,str_to_num(port),SOCKET_UDP,err);
if(sock<0 || err)
{
server_print("Socket error");
socket_close(sock);
return;
}

new buffer[1500];
copy(buffer,charsmax(buffer),"^xFF^xFF^xFF^xFF^x54Source Engine Query");
socket_send2(sock,buffer,strlen(buffer)+1);

new r = socket_recv(sock,buffer,sizeof(buffer));
socket_close(sock);
if(r<2)
{
server_print("No data");
return;
}

}
but when i use i get:
Code:
test.sma(238) : warning 209: function "get_data" should return a value
test.sma(250) : warning 209: function "get_data" should return a value
test.sma(253) : warning 209: function "get_data" should return a value
I need small code to get server status if is on = 1 if is off = 0.
Thanks.
faki is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 12-31-2013 , 04:43   Re: Simple sockets to get server status
Reply With Quote #2

If you're using the function like this:
new variable = get_data("host");
you can't return nothing. You need to return a value.
For example:
Code:
stock get_data(host[]) {     new ip[32], port[10], err;     copy(ip,charsmax(ip),host);     copy(port,charsmax(port),"27015");     if(containi(host,":")!=-1)     strtok(host, ip, charsmax(ip), port, charsmax(port), ':');     new sock = socket_open(ip,str_to_num(port),SOCKET_UDP,err);     if(sock<0 || err)     {         server_print("Socket error");         socket_close(sock);         return 0;     }     new buffer[1500];     copy(buffer,charsmax(buffer),"^xFF^xFF^xFF^xFF^x54Source Engine Query");     socket_send2(sock,buffer,strlen(buffer)+1);     new r = socket_recv(sock,buffer,sizeof(buffer));     socket_close(sock);     if(r<2)     {         server_print("No data");         return 0;     }     return 1 }
Please indent code.
__________________
Black Rose is offline
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 10:14.


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