softwareboss / websender

WebSender. You can send send messages with PHP to your Bungeecord and Spigot based servers. More information: https://bit.ly/3a6VR96
7 stars 5 forks source link

Unrecognized character: 0x20 #4

Open Ale1x opened 2 years ago

Ale1x commented 2 years ago

When sending a command, i receive this error -Exception in thread "Thread-8" java.lang.IllegalArgumentException: com.google.common.io.BaseEncoding$DecodingException: Unrecognized character: 0x20 [14:18:10] [Thread-8/WARN]: at com.google.common.io.BaseEncoding.decode(BaseEncoding.java:219) [14:18:10] [Thread-8/WARN]: at tc.yigit.shared.UtilSocket.DecodeBASE64(UtilSocket.java:62) [14:18:10] [Thread-8/WARN]: at tc.yigit.shared.UtilSocket.readString(UtilSocket.java:58) [14:18:10] [Thread-8/WARN]: at tc.yigit.shared.SocketServer.run(SocketServer.java:60) [14:18:10] [Thread-8/WARN]: Caused by: com.google.common.io.BaseEncoding$DecodingException: Unrecognized character: 0x20 [14:18:10] [Thread-8/WARN]: at com.google.common.io.BaseEncoding$Alphabet.decode(BaseEncoding.java:491) [14:18:10] [Thread-8/WARN]: at com.google.common.io.BaseEncoding$Base64Encoding.decodeTo(BaseEncoding.java:974) [14:18:10] [Thread-8/WARN]: at com.google.common.io.BaseEncoding.decodeChecked(BaseEncoding.java:234) [14:18:10] [Thread-8/WARN]: at com.google.common.io.BaseEncoding.decode(BaseEncoding.java:217) [14:18:10] [Thread-8/WARN]: ... 3 more

Including Web Sender PHP file

`<?php

class WebsenderAPI{

public $timeout = 30;

var $host;
var $password;
var $port;
var $socket;

public function __construct($host, $password, $port){
    $this->host = gethostbyname($host);
    $this->password = $password;
    $this->port = $port;
}

public function __destruct(){
    if($this->socket)
        $this->disconnect();
}

public function connect(){
    @$this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
    if(!$this->socket) return false;
    @$this->writeRawByte(1);
    @$this->writeString(hash("SHA512", $this->readRawInt().$this->password));
    return $this->readRawInt() == 1 ? true: false;
}

public function sendCommand($command){
    $this->writeRawByte(2);
    $this->writeString($command);
    return $this->readRawInt() == 1 ? true: false;
}

public function disconnect(){
    if(!$this->socket) return false;
    return $this->writeRawByte(3) ? true: false;
}

private function writeRawInt($i){
    @fwrite($this->socket, pack("N", $i), 4);
}

private function writeRawByte($b){
    @fwrite($this->socket, strrev(pack("C", $b)));
}

private function writeString($string){
    $array = str_split($string);
    $this->writeRawInt(count($array));
    foreach($array as &$cur){
        $v = ord($cur);
        $this->writeRawByte((0xff & ($v >> 8)));
        $this->writeRawByte((0xff & $v));
    }
}

private function readRawInt(){
    $a = $this->readRawByte();
    $b = $this->readRawByte();
    $c = $this->readRawByte();
    $d = $this->readRawByte();
    $i = ((($a & 0xff) << 24) | (($b & 0xff) << 16) | (($c & 0xff) << 8) | ($d & 0xff));
    if($i > 2147483648)
        $i -= 4294967296;
    return $i;
}

private function readRawByte(){
    $up = unpack("Ci", fread( $this->socket, 1));
    $b = $up["i"];
    if($b > 127)
        $b -= 256;
    return $b;
}

}

?>`

softwareboss commented 2 years ago

Hi,

It can depends your Java version, can you use it with Java 8 and tell me after trying. If you get same error with Java 8 let me know it.

Thanks.

Ale1x commented 2 years ago

It is working with Java 8. but newest minecraft versions requires Java 16+, can you maybe update websender? Thank you

softwareboss commented 2 years ago

I sent new release, please check it.

Ale1x commented 2 years ago

Hi, still the same error.

Exception in thread "Thread-5" java.lang.IllegalArgumentException: Illegal base64 character 20 [22:41:43 ERROR]: at java.base/java.util.Base64$Decoder.decode0(Base64.java:847) [22:41:43 ERROR]: at java.base/java.util.Base64$Decoder.decode(Base64.java:566) [22:41:43 ERROR]: at java.base/java.util.Base64$Decoder.decode(Base64.java:589) [22:41:43 ERROR]: at tc.yigit.shared.UtilSocket.DecodeBASE64(UtilSocket.java:60) [22:41:43 ERROR]: at tc.yigit.shared.UtilSocket.readString(UtilSocket.java:56) [22:41:43 ERROR]: at tc.yigit.shared.SocketServer.run(SocketServer.java:60

softwareboss commented 2 years ago

Hi,

Can you update your WebSenderAPI.php file with new release. Did you do any change at php file?