Merge pull request #14 from Tiiffi/refactoring/networking

Refactoring/networking
This commit is contained in:
Tiiffi
2016-11-15 22:21:13 +02:00
committed by GitHub
8 changed files with 783 additions and 507 deletions

2
.gitignore vendored
View File

@ -2,6 +2,8 @@
*.o *.o
*.dev *.dev
*.win *.win
*.txt
*.layout *.layout
*.project *.project
mcrcon mcrcon
todo

64
CHANGELOG.md Normal file
View File

@ -0,0 +1,64 @@
####Version history:
######0.0.5
- IPv6 support!
* Thanks to 'Tanja84dk' for addressing the real need of IPv6.
- Fixed bug causing crash / segmentation fault (invalid write) when receiving malformed rcon packet.
- Program makes use of C99 feature (variable-length arrays) so "-std=gnu99" flag on
GCC-compiler must be used to avoid unecessary warnings.
- Rcon receive buffer is now bigger (2024 bytes -> 10240 bytes).
* Thanks to 'gman_ftw' @ Bukkit forums.
- Fixed invalid error message when receiving empty rcon packet (10 bytes).
* Thanks to 'pkmnfrk' @ bukkit forums.
- Terminal mode now closes automatically when rcon socket is closed by server
or if packet size cannot be retrieved correctly.
- Client now tries to clean the incoming socket data if last package was out of spec.
######0.0.4
- Reverted back to default getopts options error handler (opterr = 1).
Custom error handler requires rewriting.
- Some cosmetic changes in program output strings.
- Program usage(); function now waits for enter before exiting on Windows.
######0.0.3
- Colors are now supported on Windows too!
- Terminal mode is now triggered with "-t" flag. "-i" flag still works for
backwards compatibility.
- Bug fixes (Packet size check always evaluating false and color validity
check always evaluating true).
######0.0.2
- License changed from 'ISC License' to 'zlib/libpng License'.
- Bug fixes & code cleanups
- Interactive mode (-i flag). Client acts as interactive terminal.
- Program return value is now the number of rcon commmands sent successfully.
If connecting or authentication fails, the return value is -1.
- Colors are now enabled by default. Now '-c' flag disables the color support.
######0.0.1
- Added experimental support for bukkit colors.
Should work with any sh compatible shell.
- Packet string data limited to max 2048 (DATA_BUFFSIZE) bytes.
No idea how Minecraft handles multiple rcon packets.
If someone knows, please mail me so I can implement it.
####TODO:
- Make the receive buffer dynamic??
- Change some of the packet size issues to fatal errors.
- Code cleanups.
- Check global variables (remove if possible).
- Add some protocol checks (proper packet id check etc..).
- Preprocessor (#ifdef / #ifndef) cleanups.
- Follow valve rcon protocol standard strictly?
- Multiple packet support if minecraft supports it?!
- Investigate if player chat messages gets sent through rcon.
If they are, the messaging system requires rewriting.
- Name resolving should be integrated to connection creation function.
- Dont try to cleanup the socket if not authenticated
- Better sockets error reporting
- Better error function (VA_ARGS support)

21
INSTALL Normal file
View File

@ -0,0 +1,21 @@
Compiling and installing
------------------------
Only dependency is C library with POSIX getopt support.
Compiling with GCC or CLANG:
cc -std=gnu99 -Wpedantic -Wall -Wextra -Os -s -o mcrcon mcrcon.c
Or you can just run "make":
make - compiles mcrcon
make install - installs compiled binaries and manpage to the system
make uninstall - removes binaries and manpage from the system
file install locations:
/usr/share/bin/mcrcon
/usr/share/man/man1/mcrcon.1
On Window remember to link with winsockets by adding "-lws2_32" to your compiler command line.
Makefile should take care of this automatically but "install" and "uninstall" rules are disabled on windows.

View File

@ -1,4 +1,4 @@
Copyright (c) 2012-2015, Tiiffi <tiiffi --> gmail_dot_com> Copyright (c) 2012-2016, Tiiffi <tiiffi_at_gmail_dot_com>
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages

View File

@ -1,8 +1,36 @@
# Cross comple, eg. # if you want to cross compile
# export PATH=$PATH:/path/to/compiler/bin # export PATH=$PATH:/path/to/compiler/bin
# export CROSS_COMPILE=arm-none-linux-gnueabi- # export CROSS_COMPILE=arm-none-linux-gnueabi-
# make # make
all: ifeq ($(OS), Windows_NT)
$(CROSS_COMPILE)gcc -std=gnu99 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c LINKER = -lws2_32
EXENAME = mcrcon.exe
RM = cmd /C del /F
else
LINKER =
EXENAME = mcrcon
RM = rm -f
endif
CC = gcc
CFLAGS = -std=gnu99 -Wall -Wextra -Wpedantic -Os -s
all:
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o $(EXENAME) mcrcon.c $(LINKER)
ifneq ($(OS), Windows_NT)
install:
cp $(EXENAME) /usr/local/bin/$(EXENAME)
chmod 0755 /usr/local/bin/$(EXENAME)
cp mcrcon.1 /usr/local/share/man/man1/mcrcon.1
chmod 0644 /usr/local/share/man/man1/mcrcon.1
@echo "\nmcrcon installed. Run 'make uninstall' if you want to uninstall.\n"
uninstall:
rm -f /usr/local/bin/$(EXENAME)
rm -f /usr/local/share/man/man1/mcrcon.1
@echo "\nmcrcon uninstalled.\n"
endif
clean:
$(RM) $(EXENAME)

123
README.md
View File

@ -1,116 +1,59 @@
####Compiling: ###Installing:
Raw command: from sources:
```gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c``` ```
git clone https://github.com/Tiiffi/mcrcon.git
cd mcrcon/
make
sudo make install
```
Check **INSTALL** for more details.
or just run **make**. You can also download precompiled binaries: https://github.com/Tiiffi/mcrcon/releases/latest
On windows, remember to link with winsockets. Binaries are provided for Linux and Windows.
Add ```-lws2_32``` to compiler command line on Mingw GCC.
--- ---
####Usage: ###Usage:
Usage: mcrcon [OPTIONS]... [COMMANDS]... mcrcon [OPTIONS]... [COMMANDS]...
Sends rcon commands to minecraft server.
Sends rcon commands to Minecraft server.
``` ```
Option: Option:
-h Prints usage. -h Print usage
-s Silent mode. Do not print data received from rcon. -H Server address
-t Terminal mode. Acts as interactive terminal. -P Port (default is 25575)
-p Rcon password. Default: "". -p Rcon password
-H Host address or ip. -t Interactive terminal mode
-P Port. Default: 25575. -s Silent mode (do not print received packets)
-c Do not print colors. Disables bukkit color printing. -c Disable colors
-r Print everything in raw mode. -r Output raw packets (debugging and custom handling)
Good for debugging and custom handling of the output. -v Output version information
``` ```
Invidual commands must be separated with spaces.
Commands with arguments must be enclosed in quotes.
Example: Example:
```mcrcon -c -H 192.168.1.42 -P 9999 -p password cmd1 "cmd2 with spaces"``` ```mcrcon -H my.minecraft.server -p password "say Server is restarting!" save-all stop```
#####Enable rcon ---
Remember to enable rcon by changing/adding these lines to ```server.properties``` file.
###Enable rcon on server
Remember to enable rcon by adding following lines to ```server.properties``` file.
``` ```
enable-rcon=true enable-rcon=true
rcon.port=25575
rcon.password=your_rcon_pasword rcon.password=your_rcon_pasword
rcon.port=9999
``` ```
--- ---
####Contact: ####Contact:
* WWW: http://sourceforge.net/projects/mcrcon/ * WWW: https://github.com/Tiiffi/mcrcon/
* MAIL: tiiffi_at_gmail_dot_com * MAIL: tiiffi_at_gmail_dot_com
* IRC: tiiffi @ quakenet * IRC: tiiffi @ quakenet
* BUG REPORTS: https://github.com/Tiiffi/mcrcon/issues/ * BUG REPORTS: https://github.com/Tiiffi/mcrcon/issues/
---
####Version history:
######0.0.5
- IPv6 support!
* Thanks to 'Tanja84dk' for addressing the real need of IPv6.
- Fixed bug causing crash / segmentation fault (invalid write) when receiving malformed rcon packet.
- Program makes use of C99 feature (variable-length arrays) so "-std=gnu99" flag on
GCC-compiler must be used to avoid unecessary warnings.
- Rcon receive buffer is now bigger (2024 bytes -> 10240 bytes).
* Thanks to 'gman_ftw' @ Bukkit forums.
- Fixed invalid error message when receiving empty rcon packet (10 bytes).
* Thanks to 'pkmnfrk' @ bukkit forums.
- Terminal mode now closes automatically when rcon socket is closed by server
or if packet size cannot be retrieved correctly.
- Client now tries to clean the incoming socket data if last package was out of spec.
######0.0.4
- Reverted back to default getopts options error handler (opterr = 1).
Custom error handler requires rewriting.
- Some cosmetic changes in program output strings.
- Program usage(); function now waits for enter before exiting on Windows.
######0.0.3
- Colors are now supported on Windows too!
- Terminal mode is now triggered with "-t" flag. "-i" flag still works for
backwards compatibility.
- Bug fixes (Packet size check always evaluating false and color validity
check always evaluating true).
######0.0.2
- License changed from 'ISC License' to 'zlib/libpng License'.
- Bug fixes & code cleanups
- Interactive mode (-i flag). Client acts as interactive terminal.
- Program return value is now the number of rcon commmands sent successfully.
If connecting or authentication fails, the return value is -1.
- Colors are now enabled by default. Now '-c' flag disables the color support.
######0.0.1
- Added experimental support for bukkit colors.
Should work with any sh compatible shell.
- Packet string data limited to max 2048 (DATA_BUFFSIZE) bytes.
No idea how Minecraft handles multiple rcon packets.
If someone knows, please mail me so I can implement it.
####TODO:
- Make the receive buffer dynamic??
- Change some of the packet size issues to fatal errors.
- Code cleanups.
- Check global variables (remove if possible).
- Add some protocol checks (proper packet id check etc..).
- Preprocessor (#ifdef / #ifndef) cleanups.
- Follow valve rcon protocol standard strictly?
- Multiple packet support if minecraft supports it?!
- Investigate if player chat messages gets sent through rcon.
If they are, the messaging system requires rewriting.
- Name resolving should be integrated to connection creation function.
- Dont try to cleanup the socket if not authenticated
- Better sockets error reporting
- Better error function (VA_ARGS support)

53
mcrcon.1 Normal file
View File

@ -0,0 +1,53 @@
.\" Process this file with
.\" groff -man -Tascii mcrcon.1
.\"
.TH MCRCON 1 "November 2016" "Version 0.0.6"
.SH NAME
mcrcon \- sends rcon commands to a Minecraft server
.SH SYNOPSIS
.B mcrcon [
options
.B ] [
commands
.B ]
.SH DESCRIPTION
mcrcon is Minecraft rcon client / terminal with bukkit coloring support.\n\n\n
It is well suited for remote administration and server maintenance scripts.
.SH OPTIONS
.IP -h
Print usage
.IP -H
Server address
.IP -P
Port (default is 25575)
.IP -p
Rcon password
.IP -t
Interactive terminal mode
.IP -s
Silent mode (do not print received packets)
.IP -c
Disable colors
.IP -r
Output raw packets (for debugging and custom handling)
.IP -v
Output version information
.PP
Commands with arguments must be enclosed in quotes.
.SH EXAMPLES
Make rcon connection in terminal mode using default port
.RS
\fBmcrcon\fR -H my.minecraft.server -p password
.RE
.PP
Send "weather clear" command to server using custom port 1337
.RS
\fBmcrcon\fR -H my.minecraft.server -P 1337 -p password "weather clear"
.RE
.PP
Send three commands to server (say, save-all and stop)
.RS
\fBmcrcon\fR -H my.minecraft.server -p password "say Server is restarting!" save-all stop
.RE
.SH BUGS
Bugs can be reported to \fBtiiffi_at_gmail_dot_com\fR or \fBhttps://github.com/Tiiffi/mcrcon/issues/\fR

991
mcrcon.c

File diff suppressed because it is too large Load Diff