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
*.dev
*.win
*.txt
*.layout
*.project
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
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 CROSS_COMPILE=arm-none-linux-gnueabi-
# make
all:
$(CROSS_COMPILE)gcc -std=gnu99 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
ifeq ($(OS), Windows_NT)
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:
```gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c```
from sources:
```
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.
Add ```-lws2_32``` to compiler command line on Mingw GCC.
Binaries are provided for Linux and Windows.
---
####Usage:
Usage: mcrcon [OPTIONS]... [COMMANDS]...
Sends rcon commands to minecraft server.
###Usage:
mcrcon [OPTIONS]... [COMMANDS]...
Sends rcon commands to Minecraft server.
```
Option:
-h Prints usage.
-s Silent mode. Do not print data received from rcon.
-t Terminal mode. Acts as interactive terminal.
-p Rcon password. Default: "".
-H Host address or ip.
-P Port. Default: 25575.
-c Do not print colors. Disables bukkit color printing.
-r Print everything in raw mode.
Good for debugging and custom handling of the output.
-h Print usage
-H Server address
-P Port (default is 25575)
-p Rcon password
-t Interactive terminal mode
-s Silent mode (do not print received packets)
-c Disable colors
-r Output raw packets (debugging and custom handling)
-v Output version information
```
Invidual commands must be separated with spaces.
Commands with arguments must be enclosed in quotes.
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
rcon.port=25575
rcon.password=your_rcon_pasword
rcon.port=9999
```
---
####Contact:
* WWW: http://sourceforge.net/projects/mcrcon/
* WWW: https://github.com/Tiiffi/mcrcon/
* MAIL: tiiffi_at_gmail_dot_com
* IRC: tiiffi @ quakenet
* 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