
10-31-2002, 06:25 AM
Hrm I once found a C-Sourcecode of a small rcon tool. It#s not displaying any output, but enough to display scheduled messages, kick players, ...
[code:079cc]
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int port, sock, i;
struct sockaddr_in addr;
struct hostent *host;
char str[1024];
if(argc < 5)
{
printf("\nprintf(" Usage: rcon <address> <port> <password> <commands>\n");
printf(" e.g. rcon 143.112.89.219 12203 itssecret say hello\n");
printf(" or rcon 16.22.14.93 12203 myfavorite kick profane\n\n");
return 1;
}
sock = socket(AF_INET, SOCK_DGRAM, 0);
if(sock < 0)
{
perror("socket");
return 1;
}
port = atoi(argv[2]);
host = gethostbyname(argv[1]);
if(host == NULL)
{
perror("gethostbyname");
return 1;
}
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr = *((struct in_addr *)host->h_addr);
str[0] = 255;
str[1] = 255;
str[2] = 255;
str[3] = 255;
str[4] = 2;
str[5] = 0;
sprintf(str + 5, "rcon %s ", argv[3]);
for(i = 4; i < argc; i++)
{
strcat(str, "\"");
strcat(str, argv[i]);
strcat(str, "\" ");
}
i = strlen(str) - 1;
str[i] = 0;
str[i+1] = 0x0a;
if(sendto(sock, str, i + 2, 0, &addr,
sizeof(struct sockaddr_in)) == -1)
{
perror("sendto");
return 1;
}
close(sock);
return 0;
}
[/code:079cc]
|