|
@@ -6,7 +6,6 @@
|
|
|
#include <Schrift.h>
|
|
|
#include <Datei.h>
|
|
|
#include <InitDatei.h>
|
|
|
-#include "Keys.h"
|
|
|
|
|
|
void KSGSRückruf( void *p, RCArray< KSGSVariable > *parameter, KSGSVariable **ret )
|
|
|
{
|
|
@@ -17,8 +16,9 @@ void KSGSR
|
|
|
|
|
|
// Inhalt der News Klasse aus News.h
|
|
|
// Konstruktor
|
|
|
-News::News( Bildschirm *zB, Schrift *zS )
|
|
|
+News::News( Bildschirm *zB, Schrift *zS, KSGClient::NewsServerClient *client )
|
|
|
{
|
|
|
+ this->client = client;
|
|
|
ref = 1;
|
|
|
// Ladeanimation laden
|
|
|
Animation2DData *aData = new Animation2DData();
|
|
@@ -98,6 +98,11 @@ News::News( Bildschirm *zB, Schrift *zS )
|
|
|
News::~News()
|
|
|
{
|
|
|
warteAufThread( INFINITE );
|
|
|
+ if( client )
|
|
|
+ {
|
|
|
+ client->trenne( 1 );
|
|
|
+ client->release();
|
|
|
+ }
|
|
|
if( frame )
|
|
|
{
|
|
|
frame->zurücksetzen();
|
|
@@ -139,30 +144,35 @@ void News::thread()
|
|
|
laden->setSichtbar( 1 );
|
|
|
frame->zurücksetzen();
|
|
|
// KSGScript Seite Herunterladen
|
|
|
- NewsKlient *klient = new NewsKlient();
|
|
|
- if( !klient->verbinde() )
|
|
|
- {
|
|
|
- klient->release();
|
|
|
- fehler->addZeile( "Fehler beim verbinden mit dem News-Server." );
|
|
|
- fehler->addStyle( TextFeld::Style::Sichtbar );
|
|
|
- laden->setSichtbar( 0 );
|
|
|
- screen->setOnTop( 0 );
|
|
|
- run = 0;
|
|
|
- return;
|
|
|
- }
|
|
|
- if( !klient->downloadSeite( scriptName->getText() ) )
|
|
|
- {
|
|
|
- klient->trenne( 1 );
|
|
|
- klient->release();
|
|
|
- fehler->addZeile( "Die Seite konnte nicht herruntergeladen werden." );
|
|
|
- fehler->addStyle( TextFeld::Style::Sichtbar );
|
|
|
- laden->setSichtbar( 0 );
|
|
|
- screen->setOnTop( 0 );
|
|
|
- run = 0;
|
|
|
- return;
|
|
|
- }
|
|
|
- klient->trenne( 1 );
|
|
|
- klient->release();
|
|
|
+ if( client )
|
|
|
+ {
|
|
|
+ if( !client->verbinde() )
|
|
|
+ {
|
|
|
+ fehler->addZeile( "Fehler beim verbinden mit dem News-Server." );
|
|
|
+ fehler->addStyle( TextFeld::Style::Sichtbar );
|
|
|
+ laden->setSichtbar( 0 );
|
|
|
+ screen->setOnTop( 0 );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if( !client->ladeSeite( scriptName->getText() ) )
|
|
|
+ {
|
|
|
+ client->trenne( 0 );
|
|
|
+ fehler->addZeile( "Die Seite konnte nicht herruntergeladen werden." );
|
|
|
+ fehler->addStyle( TextFeld::Style::Sichtbar );
|
|
|
+ laden->setSichtbar( 0 );
|
|
|
+ screen->setOnTop( 0 );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ client->trenne( 0 );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fehler->addZeile( "Es steht kein News Client zur Verfügung." );
|
|
|
+ fehler->addStyle( TextFeld::Style::Sichtbar );
|
|
|
+ laden->setSichtbar( 0 );
|
|
|
+ screen->setOnTop( 0 );
|
|
|
+ return;
|
|
|
+ }
|
|
|
// KSGScript Laden
|
|
|
Text *pfad = new Text( "data/tmp/news/" );
|
|
|
pfad->append( scriptName->getText() );
|
|
@@ -190,347 +200,6 @@ News *News::getThis()
|
|
|
}
|
|
|
|
|
|
News *News::release()
|
|
|
-{
|
|
|
- ref--;
|
|
|
- if( !ref )
|
|
|
- delete this;
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// Inhalt der NewsKlient Klasse aus News.h
|
|
|
-// Konstruktor
|
|
|
-NewsKlient::NewsKlient()
|
|
|
-{
|
|
|
- // lade Client id
|
|
|
- id = 0;
|
|
|
- Datei *dat = new Datei();
|
|
|
- dat->setDatei( new Text( "data/tmp/k.id" ) );
|
|
|
- dat->open( Datei::Style::lesen );
|
|
|
- dat->lese( (char*)&id, 4 );
|
|
|
- dat->close();
|
|
|
- // lade Schlüssel
|
|
|
- dat->setDatei( new Text( "data/tmp/schlüssel.netw" ) );
|
|
|
- dat->open( Datei::Style::lesen );
|
|
|
- schlüsselLän = 0;
|
|
|
- dat->lese( &schlüsselLän, 1 );
|
|
|
- schlüssel = new char[ schlüsselLän ];
|
|
|
- dat->lese( schlüssel, schlüsselLän );
|
|
|
- dat->close();
|
|
|
- dat->release();
|
|
|
- // Initialisierung
|
|
|
- verbunden = 0;
|
|
|
- klient = 0;
|
|
|
- InitializeCriticalSection( &cs );
|
|
|
- ref = 1;
|
|
|
-}
|
|
|
-
|
|
|
-// Destruktor
|
|
|
-NewsKlient::~NewsKlient()
|
|
|
-{
|
|
|
- if( verbunden )
|
|
|
- trenne( 1 );
|
|
|
- delete[] schlüssel;
|
|
|
- if( klient )
|
|
|
- klient->release();
|
|
|
- DeleteCriticalSection( &cs );
|
|
|
-}
|
|
|
-
|
|
|
-// nicht constant
|
|
|
-void NewsKlient::lock()
|
|
|
-{
|
|
|
- EnterCriticalSection( &cs );
|
|
|
-}
|
|
|
-
|
|
|
-void NewsKlient::unlock()
|
|
|
-{
|
|
|
- LeaveCriticalSection( &cs );
|
|
|
-}
|
|
|
-
|
|
|
-bool NewsKlient::verbinde()
|
|
|
-{
|
|
|
- lock();
|
|
|
- if( verbunden )
|
|
|
- {
|
|
|
- unlock();
|
|
|
- return 1;
|
|
|
- }
|
|
|
- if( !klient )
|
|
|
- {
|
|
|
- InitDatei *dat = new InitDatei( "data/optionen.ini" );
|
|
|
- dat->laden();
|
|
|
- Text *ipT = dat->getWert( "ServerIP" );
|
|
|
- Datei d;
|
|
|
- d.setDatei( "data/tmp/m.port" );
|
|
|
- d.open( Datei::Style::lesen );
|
|
|
- int port = 0;
|
|
|
- d.lese( (char*)&port, 4 );
|
|
|
- d.close();
|
|
|
- dat->release();
|
|
|
- int län = ipT->getLength();
|
|
|
- char *msIp = new char[ län + 1 ];
|
|
|
- msIp[ län ] = 0;
|
|
|
- for( int i = 0; i < län; i++ )
|
|
|
- msIp[ i ] = ipT->getText()[ i ];
|
|
|
- ipT->release();
|
|
|
- klient = new Klient();
|
|
|
- int l;
|
|
|
- char *key;
|
|
|
- Keys::getServerKey( &key, l, Keys::MAIN, Keys::SENDEN );
|
|
|
- klient->setSendeKey( key, l );
|
|
|
- delete[] key;
|
|
|
- Keys::getServerKey( &key, l, Keys::MAIN, Keys::SENDEN );
|
|
|
- klient->setEmpfangKey( key, l );
|
|
|
- delete[] key;
|
|
|
- if( !klient->verbinde( port, msIp ) )
|
|
|
- {
|
|
|
- klient = klient->release();
|
|
|
- delete[]msIp;
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- delete[]msIp;
|
|
|
- klient->sende( "\0", 1 ); // verschlüsselung aktivieren
|
|
|
- klient->sendeEncrypted( "\1", 1 );
|
|
|
- klient->sendeEncrypted( (char*)&id, 4 );
|
|
|
- char serverReturn = 0;
|
|
|
- klient->getNachrichtEncrypted( &serverReturn, 1 );
|
|
|
- if( serverReturn == 3 )
|
|
|
- {
|
|
|
- char byte = 0;
|
|
|
- klient->getNachrichtEncrypted( &byte, 1 );
|
|
|
- char *fehler = new char[ byte + 1 ];
|
|
|
- fehler[ byte ] = 0;
|
|
|
- klient->getNachrichtEncrypted( fehler, byte );
|
|
|
- delete[] fehler;
|
|
|
- klient->sendeEncrypted( "\3", 1 );
|
|
|
- klient->getNachrichtEncrypted( &serverReturn, 1 );
|
|
|
- klient->trenne();
|
|
|
- klient = klient->release();
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- klient->setSendeKey( this->schlüssel, schlüsselLän );
|
|
|
- klient->setEmpfangKey( this->schlüssel, schlüsselLän );
|
|
|
- klient->sendeEncrypted( "\6\x9", 2 );
|
|
|
- char byte = 0;
|
|
|
- klient->getNachrichtEncrypted( &byte, 1 );
|
|
|
- if( byte == 2 )
|
|
|
- {
|
|
|
- unsigned char nsIp[ 4 ];
|
|
|
- klient->getNachrichtEncrypted( (char *)nsIp, 4 );
|
|
|
- unsigned short nsPort = 0;
|
|
|
- klient->getNachrichtEncrypted( (char*)&nsPort, 2 );
|
|
|
- klient->sendeEncrypted( "\3", 1 );
|
|
|
- klient->getNachrichtEncrypted( &serverReturn, 1 );
|
|
|
- klient->trenne();
|
|
|
- Text *nsIpT = new Text( "" );
|
|
|
- nsIpT->append( (int)nsIp[ 0 ] );
|
|
|
- nsIpT->append( "." );
|
|
|
- nsIpT->append( (int)nsIp[ 1 ] );
|
|
|
- nsIpT->append( "." );
|
|
|
- nsIpT->append( (int)nsIp[ 2 ] );
|
|
|
- nsIpT->append( "." );
|
|
|
- nsIpT->append( (int)nsIp[ 3 ] );
|
|
|
- int l;
|
|
|
- char *key;
|
|
|
- Keys::getServerKey( &key, l, Keys::NEWS, Keys::SENDEN );
|
|
|
- klient->setSendeKey( key, l );
|
|
|
- delete[] key;
|
|
|
- Keys::getServerKey( &key, l, Keys::NEWS, Keys::SENDEN );
|
|
|
- klient->setEmpfangKey( key, l );
|
|
|
- delete[] key;
|
|
|
- klient->verbinde( nsPort, nsIpT->getText() );
|
|
|
- nsIpT = nsIpT->release();
|
|
|
- klient->sendeEncrypted( "\3", 1 );
|
|
|
- klient->getNachrichtEncrypted( &serverReturn, 1 );
|
|
|
- klient->trenne();
|
|
|
- }
|
|
|
- if( byte == 3 )
|
|
|
- {
|
|
|
- klient->getNachrichtEncrypted( &byte, 1 );
|
|
|
- char *fehler = new char[ byte + 1 ];
|
|
|
- fehler[ byte ] = 0;
|
|
|
- klient->getNachrichtEncrypted( fehler, byte );
|
|
|
- delete[]fehler;
|
|
|
- klient->sendeEncrypted( "\3", 1 );
|
|
|
- klient->getNachrichtEncrypted( &serverReturn, 1 );
|
|
|
- klient->trenne();
|
|
|
- klient = klient->release();
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
- int l;
|
|
|
- char *key;
|
|
|
- Keys::getServerKey( &key, l, Keys::NEWS, Keys::SENDEN );
|
|
|
- klient->setSendeKey( key, l );
|
|
|
- delete[] key;
|
|
|
- Keys::getServerKey( &key, l, Keys::NEWS, Keys::SENDEN );
|
|
|
- klient->setEmpfangKey( key, l );
|
|
|
- delete[] key;
|
|
|
- if( klient->verbinde( klient->getServerPort(), klient->getServerIp() ) )
|
|
|
- {
|
|
|
- if( klient->sendeEncrypted( "\1", 1 ) )
|
|
|
- {
|
|
|
- klient->sendeEncrypted( (char*)&id, 4 );
|
|
|
- char serverReturn = 0;
|
|
|
- klient->getNachrichtEncrypted( &serverReturn, 1 );
|
|
|
- if( serverReturn == 3 )
|
|
|
- {
|
|
|
- char byte = 0;
|
|
|
- klient->getNachrichtEncrypted( &byte, 1 );
|
|
|
- char *fehler = new char[ byte + 1 ];
|
|
|
- fehler[ byte ] = 0;
|
|
|
- klient->getNachrichtEncrypted( fehler, byte );
|
|
|
- delete[]fehler;
|
|
|
- klient->sendeEncrypted( "\3", 1 );
|
|
|
- klient->getNachrichtEncrypted( &serverReturn, 1 );
|
|
|
- klient->trenne();
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- klient->setSendeKey( this->schlüssel, schlüsselLän );
|
|
|
- klient->setEmpfangKey( this->schlüssel, schlüsselLän );
|
|
|
- verbunden = 1;
|
|
|
- unlock();
|
|
|
- return 1;
|
|
|
- }
|
|
|
- else
|
|
|
- klient = klient->release();
|
|
|
- }
|
|
|
- else
|
|
|
- klient = klient->release();
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-bool NewsKlient::downloadSeite( char *name )
|
|
|
-{
|
|
|
- lock();
|
|
|
- if( !verbunden )
|
|
|
- verbinde();
|
|
|
- if( !verbunden )
|
|
|
- {
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- klient->sendeEncrypted( "\5", 1 );
|
|
|
- char ret = 0;
|
|
|
- klient->getNachrichtEncrypted( &ret, 1 );
|
|
|
- if( ret == 1 )
|
|
|
- {
|
|
|
- char län = (char)textLength( name );
|
|
|
- klient->sendeEncrypted( &län, 1 );
|
|
|
- klient->sendeEncrypted( name, län );
|
|
|
- klient->getNachrichtEncrypted( &ret, 1 );
|
|
|
- if( ret == 1 )
|
|
|
- {
|
|
|
- Text *pfad = new Text( "data/tmp/news/" );
|
|
|
- pfad->append( name );
|
|
|
- if( DateiExistiert( pfad->getThis() ) )
|
|
|
- DateiRemove( pfad->getThis() );
|
|
|
- pfad->append( "/" );
|
|
|
- int dAnz = 0;
|
|
|
- klient->getNachrichtEncrypted( (char*)&dAnz, 4 );
|
|
|
- for( int i = 0; i < dAnz; i++ )
|
|
|
- {
|
|
|
- char nLän = 0;
|
|
|
- klient->getNachrichtEncrypted( &nLän, 1 );
|
|
|
- char *dName = new char[ nLän + 1 ];
|
|
|
- dName[ nLän ] = 0;
|
|
|
- klient->getNachrichtEncrypted( dName, nLän );
|
|
|
- Text *pf = new Text( pfad->getText() );
|
|
|
- pf->append( dName );
|
|
|
- delete[] dName;
|
|
|
- Datei *d = new Datei();
|
|
|
- d->setDatei( pf );
|
|
|
- d->erstellen();
|
|
|
- d->open( Datei::Style::schreiben );
|
|
|
- __int64 dGr = 0;
|
|
|
- klient->getNachrichtEncrypted( (char*)&dGr, 8 );
|
|
|
- char buffer[ 2048 ];
|
|
|
- while( dGr > 0 )
|
|
|
- {
|
|
|
- int län = dGr > 2048 ? 2048 : (int)dGr;
|
|
|
- klient->getNachricht( buffer, län );
|
|
|
- d->schreibe( buffer, län );
|
|
|
- dGr -= län;
|
|
|
- }
|
|
|
- d->close();
|
|
|
- d->release();
|
|
|
- }
|
|
|
- pfad->release();
|
|
|
- }
|
|
|
- }
|
|
|
- if( ret == 3 )
|
|
|
- {
|
|
|
- klient->getNachrichtEncrypted( &ret, 1 );
|
|
|
- if( ret )
|
|
|
- {
|
|
|
- char *tmp = new char[ ret ];
|
|
|
- klient->getNachrichtEncrypted( tmp, ret );
|
|
|
- delete[] tmp;
|
|
|
- }
|
|
|
- unlock();
|
|
|
- return 0;
|
|
|
- }
|
|
|
- unlock();
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-bool NewsKlient::trenne( bool abmelden )
|
|
|
-{
|
|
|
- lock();
|
|
|
- if( !verbunden )
|
|
|
- {
|
|
|
- unlock();
|
|
|
- return 1;
|
|
|
- }
|
|
|
- if( abmelden )
|
|
|
- {
|
|
|
- klient->sendeEncrypted( "\4", 1 );
|
|
|
- char ret = 0;
|
|
|
- klient->getNachrichtEncrypted( &ret, 1 );
|
|
|
- if( ret == 3 )
|
|
|
- { // error
|
|
|
- klient->getNachrichtEncrypted( &ret, 1 );
|
|
|
- char *msg = new char[ ret + 1 ];
|
|
|
- msg[ ret ] = 0;
|
|
|
- if( ret )
|
|
|
- klient->getNachrichtEncrypted( msg, ret );
|
|
|
- unlock();
|
|
|
- delete[] msg;
|
|
|
- }
|
|
|
- }
|
|
|
- klient->sendeEncrypted( "\3", 1 );
|
|
|
- char ret = 0;
|
|
|
- klient->getNachrichtEncrypted( &ret, 1 );
|
|
|
- if( ret == 3 )
|
|
|
- { // error
|
|
|
- klient->getNachrichtEncrypted( &ret, 1 );
|
|
|
- char *msg = new char[ ret + 1 ];
|
|
|
- msg[ ret ] = 0;
|
|
|
- if( ret )
|
|
|
- klient->getNachrichtEncrypted( msg, ret );
|
|
|
- unlock();
|
|
|
- delete[] msg;
|
|
|
- }
|
|
|
- klient->trenne();
|
|
|
- klient = klient->release();
|
|
|
- verbunden = 0;
|
|
|
- unlock();
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-// Reference Counting
|
|
|
-NewsKlient *NewsKlient::getThis()
|
|
|
-{
|
|
|
- ref++;
|
|
|
- return this;
|
|
|
-}
|
|
|
-
|
|
|
-NewsKlient *NewsKlient::release()
|
|
|
{
|
|
|
ref--;
|
|
|
if( !ref )
|