Linux下一个rcon通讯的小工具

首先放上c代码

/*
# This is a simple linux command line utility to execute rcon commands
# Just change the YOUR_PASSWORD_HERE to your rcon password (unless
# you want to enter it every time) and possibly change the default
# IP address from 127.0.0.1 (localhost)
#
# once downloaded on your linux system, compile it with:
#
#   gcc -o rcon rcon.c
#
# note, it should work on non-linux too, but may require changing the 
# socket stuff (i.e. windows will definitely need to add the winsock
# initialization line)
#
# written by [ASY]Zyrain
#
*/
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#define DEBUG 0
 
#define SERVERDATA_EXECCOMMAND 2
#define SERVERDATA_AUTH 3
#define SERVERDATA_RESPONSE_VALUE 0
#define SERVERDATA_AUTH_RESPONSE 2
 
int send_rcon(int sock, int id, int command, char *string1, char *string2) {
   
  int size, ret;
  size = 10+strlen(string1)+strlen(string2);
 
  ret = send(sock,&size,sizeof(int),0);
  if(ret == -1) {
   
    perror("send() failed:");
    return -1;
  }
  ret = send(sock,&id,sizeof(int),0);
  if(ret == -1) {
   
    perror("send() failed:");
    return -1;
  }
  ret = send(sock,&command,sizeof(int),0);
  if(ret == -1) {
   
    perror("send() failed:");
    return -1;
  }
  ret = send(sock,string1,strlen(string1)+1,0);
  if(ret == -1) {
   
    perror("send() failed:");
    return -1;
  }
  ret = send(sock,string2,strlen(string2)+1,0);
  if(ret == -1) {
   
    perror("send() failed:"

你可能感兴趣的:(RCON,Linux,linux)