Example #1
0
 public function Sherlock($Buffer, $Length)
 {
     $Data = FRead($this->Socket, $Length);
     if (StrLen($Data) < 4) {
         return false;
     }
     $Buffer->Set($Data);
     return $Buffer->GetLong() === -2;
 }
Example #2
0
 private function ReadData()
 {
     $Packet = array();
     $Size = FRead($this->Socket, 4);
     $Size = UnPack('V1Size', $Size);
     $Size = $Size['Size'];
     $Packet = FRead($this->Socket, $Size);
     $Packet = UnPack('V1RequestId/V1Response/a*String/a*String2', $Packet);
     return $Packet;
 }
Example #3
0
 public function Read($Length = 1400)
 {
     $this->Buffer->Set(FRead($this->RconSocket, $Length));
     if ($this->Buffer->Remaining() < 4) {
         throw new InvalidPacketException('Rcon read: Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY);
     }
     $PacketSize = $this->Buffer->GetLong();
     $Buffer = $this->Buffer->Get();
     $Remaining = $PacketSize - StrLen($Buffer);
     while ($Remaining > 0) {
         $Buffer2 = FRead($this->RconSocket, $Length);
         $Buffer .= $Buffer2;
         $Remaining -= StrLen($Buffer2);
     }
     $this->Buffer->Set($Buffer);
 }
 public function Read()
 {
     $this->Buffer->Set(FRead($this->RconSocket, 4));
     if ($this->Buffer->Remaining() < 4) {
         throw new InvalidPacketException('Rcon read: Failed to read any data from socket', InvalidPacketException::BUFFER_EMPTY);
     }
     $PacketSize = $this->Buffer->GetLong();
     $this->Buffer->Set(FRead($this->RconSocket, $PacketSize));
     $Buffer = $this->Buffer->Get();
     $Remaining = $PacketSize - StrLen($Buffer);
     while ($Remaining > 0) {
         $Buffer2 = FRead($this->RconSocket, $Remaining);
         $PacketSize = StrLen($Buffer2);
         if ($PacketSize === 0) {
             throw new InvalidPacketException('Read ' . strlen($Buffer) . ' bytes from socket, ' . $Remaining . ' remaining', InvalidPacketException::BUFFER_EMPTY);
             break;
         }
         $Buffer .= $Buffer2;
         $Remaining -= $PacketSize;
     }
     $this->Buffer->Set($Buffer);
 }
Example #5
0
<?php

$fp = FOpen("pocitadlo.txt", "r");
$pocet = FRead($fp, 90);
FClose($fp);
$pocet = $pocet + 1;
$fp = FOpen("pocitadlo.txt", "w");
FWrite($fp, $pocet);
FClose($fp);
echo "Navstev: " . $pocet;
Example #6
0
 function Receive()
 {
     $this->readBuffer .= FRead($this->sock, 8192);
     $this->WriteToLog("C<- (" . $this->id . ")\t" . $this->readBuffer, 10);
     $res = $this->__ParseBuffer();
     $this->lastRecieve = time();
     if ($this->sock && feof($this->sock)) {
         $this->Disconnect();
     }
     return $res;
 }
 private function WriteData($Command, $Append = "")
 {
     $Command = Pack('c*', 0xfe, 0xfd, $Command, 0x1, 0x2, 0x3, 0x4) . $Append;
     $Length = StrLen($Command);
     if ($Length !== FWrite($this->Socket, $Command, $Length)) {
         throw new MinecraftQueryException("Failed to write on socket.");
     }
     $Data = FRead($this->Socket, 2048);
     if ($Data === false) {
         throw new MinecraftQueryException("Failed to read from socket.");
     }
     if (StrLen($Data) < 5 || $Data[0] != $Command[2]) {
         return false;
     }
     return SubStr($Data, 5);
 }
Example #8
0
function HTMLDoc_CreatePDF($ModeID, $HTML, $Prefix = '/')
{
    /****************************************************************************/
    $__args_types = array('string', 'string,object', 'string');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    if (Is_Object($HTML)) {
        #---------------------------------------------------------------------------
        $Tables = $HTML->GetByTagName('TABLE');
        #---------------------------------------------------------------------------
        for ($i = 0; $i < Count($Tables); $i++) {
            #-------------------------------------------------------------------------
            $Table =& $Tables[$i];
            #-------------------------------------------------------------------------
            switch (@$Table->Attribs['class']) {
                case 'Standard':
                    $Table->AddAttribs(array('border' => 2, 'cellspacing' => 0, 'cellpadding' => 5), TRUE);
                    break;
                default:
                    # No more...
            }
        }
        #---------------------------------------------------------------------------
        $Tds = $HTML->GetByTagName('TD');
        #---------------------------------------------------------------------------
        for ($i = 0; $i < Count($Tds); $i++) {
            #-------------------------------------------------------------------------
            $Td =& $Tds[$i];
            #-------------------------------------------------------------------------
            switch (@$Td->Attribs['class']) {
                case 'Head':
                    $Td->AddAttribs(array('bgcolor' => '#ADC1F0'), TRUE);
                    break;
                case 'Separator':
                    $Td->AddAttribs(array('bgcolor' => '#EAEAEA'), TRUE);
                    break;
                default:
                    # No more...
            }
        }
        #---------------------------------------------------------------------------
        $Imgs = $HTML->GetByTagName('IMG');
        #---------------------------------------------------------------------------
        for ($i = 0; $i < Count($Imgs); $i++) {
            #-------------------------------------------------------------------------
            $Img =& $Imgs[$i];
            #-------------------------------------------------------------------------
            $Img->AddAttribs(array('src' => SPrintF('%s/%s', $Prefix, $Img->Attribs['src'])), TRUE);
        }
        #---------------------------------------------------------------------------
        $HTML = $HTML->Build();
    }
    #-----------------------------------------------------------------------------
    $Config = Config();
    #-----------------------------------------------------------------------------
    $Settings = $Config['HTMLDOC'];
    #-----------------------------------------------------------------------------
    $Modes = $Settings['Modes'];
    #-----------------------------------------------------------------------------
    $Mode = isset($Modes[$ModeID]) ? $Modes[$ModeID] : $ModeID;
    #-----------------------------------------------------------------------------
    $Tmp = System_Element('tmp');
    if (Is_Error($Tmp)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: временная папка не найдена');
    }
    #-----------------------------------------------------------------------------
    $Logs = SPrintF('%s/logs', $Tmp);
    #-----------------------------------------------------------------------------
    if (!File_Exists($Logs)) {
        #---------------------------------------------------------------------------
        if (!@MkDir($Logs, 0777, TRUE)) {
            return ERROR | @Trigger_Error(500);
        }
    }
    #-----------------------------------------------------------------------------
    $HTML = @Mb_Convert_Encoding($HTML, $Settings['ConvertToCharset']);
    if (!$HTML) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось преобразовать кодировку');
    }
    #-----------------------------------------------------------------------------
    $UniqID = UniqID('HTMLDOC');
    #-----------------------------------------------------------------------------
    $File = IO_Write($Path = SPrintF('%s/%s', $Tmp, $UniqID), $HTML);
    Debug($File);
    if (Is_Error($File)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось создать временный файл');
    }
    #-----------------------------------------------------------------------------
    $Command = SPrintF('htmldoc %s %s', $Mode, $Path);
    #-----------------------------------------------------------------------------
    Debug($Command);
    #-----------------------------------------------------------------------------
    if (!PutENV('HTMLDOC_NOCGI=1')) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось установить переменную окружения HTMLDOC_NOCGI');
    }
    #-----------------------------------------------------------------------------
    $HTMLDOC = @Proc_Open($Command, array(array('pipe', 'r'), array('pipe', 'w'), array('file', $Log = SPrintF('%s/HTMLDOC.log', $Logs), 'a')), $Pipes);
    if (!Is_Resource($HTMLDOC)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось открыть процесс');
    }
    #-----------------------------------------------------------------------------
    $StdOut =& $Pipes[1];
    #-----------------------------------------------------------------------------
    $Result = '';
    #-----------------------------------------------------------------------------
    while (!Feof($StdOut)) {
        $Result .= FRead($StdOut, 1024);
    }
    #-----------------------------------------------------------------------------
    Proc_Close($HTMLDOC);
    #-----------------------------------------------------------------------------
    if (!UnLink($Path)) {
        return ERROR | @Trigger_Error('[HTMLDoc_CreatePDF]: не удалось удалить временный файл');
    }
    #-----------------------------------------------------------------------------
    if (!$Result) {
        return ERROR | @Trigger_Error(SPrintF('[HTMLDoc_CreatePDF]: ошибка формирования PDF, смотрите (%s)', $Log));
    }
    #-----------------------------------------------------------------------------
    return $Result;
}
Example #9
0
 public function Read($Length = 1400)
 {
     switch ($this->Socket->Engine) {
         case CI_SourceQuery::GOLDSOURCE:
             // GoldSource RCON has same structure as Query
             $this->Socket->Read();
             if ($this->Buffer->GetByte() != SourceQuery::S2A_RCON) {
                 return false;
             }
             $Buffer = $this->Buffer->Get();
             $Trimmed = Trim($Buffer);
             if ($Trimmed == 'Bad rcon_password.' || $Trimmed == 'You have been banned from this server.') {
                 throw new SourceQueryException($Trimmed);
             }
             $ReadMore = false;
             // There is no indentifier of the end, so we just need to continue reading
             // TODO: Needs to be looked again, it causes timeouts
             do {
                 $this->Socket->Read();
                 $ReadMore = $this->Buffer->Remaining() > 0 && $this->Buffer->GetByte() == SourceQuery::S2A_RCON;
                 if ($ReadMore) {
                     $Packet = $this->Buffer->Get();
                     $Buffer .= SubStr($Packet, 0, -2);
                     // Let's assume if this packet is not long enough, there are no more after this one
                     $ReadMore = StrLen($Packet) > 1000;
                     // use 1300?
                 }
             } while ($ReadMore);
             $this->Buffer->Set(Trim($Buffer));
             break;
         case CI_SourceQuery::SOURCE:
             $this->Buffer->Set(FRead($this->RconSocket, $Length));
             $Buffer = "";
             $PacketSize = $this->Buffer->GetLong();
             $Buffer .= $this->Buffer->Get();
             // TODO: multi packet reading
             $this->Buffer->Set($Buffer);
             break;
     }
 }
 private function WriteData($Command, $Append = "")
 {
     $Command = Pack('c*', 0xfe, 0xfd, $Command, 0x1, 0x2, 0x3, 0x4) . $Append;
     $Length = StrLen($Command);
     if ($Length !== FWrite($this->Socket, $Command, $Length)) {
         return false;
     }
     $Data = FRead($this->Socket, 1440);
     if (StrLen($Data) < 5 || $Data[0] != $Command[2]) {
         return false;
     }
     return SubStr($Data, 5);
 }
Example #11
0
FUNCTION RunSQL($link, $file) {
	IF(File_Exists($file)) {
		$fd = FOpen($file, "r");
		$sql = FRead($fd, FileSize($file));
		FClose($fd);

		$query = Split(";( )?(\r)?\n(\r)?", $sql);

		FOR($i = 0; $i < Count($query); $i++) {
			IF($query[$i] != "") {
				$link->Query($query[$i]);
				}
			}
		RETURN TRUE;
		}
	ELSE
		{RETURN FALSE;}
	}
 public function Read($Length = 1400)
 {
     $this->Buffer->Set(FRead($this->RconSocket, $Length));
     $PacketSize = $this->Buffer->GetLong();
     $Buffer = $this->Buffer->Get();
     $Remaining = $PacketSize - StrLen($Buffer);
     while ($Remaining > 0) {
         $Buffer2 = FRead($this->RconSocket, $Length);
         $Buffer .= $Buffer2;
         $Remaining -= StrLen($Buffer2);
     }
     $this->Buffer->Set($Buffer);
 }