Login.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. #include "Login.h"
  2. #include <Text.h>
  3. #include <Schrift.h>
  4. #include <TextFeld.h>
  5. #include "..\Server\Patch\PatchServer.h"
  6. #include "..\Version\Version.h"
  7. // Inhalt der AktionThread Klasse aus Login.h
  8. // Konstruktor
  9. AktionThread::AktionThread( int ak, Bildschirm *zScreen, Programm *zProg )
  10. : Thread()
  11. {
  12. this->ak = ak;
  13. zB = zScreen;
  14. zP = zProg;
  15. start();
  16. }
  17. // Destruktor
  18. AktionThread::~AktionThread()
  19. {
  20. }
  21. // nicht constant
  22. void AktionThread::thread()
  23. {
  24. zB->lock();
  25. switch( ak )
  26. {
  27. case 0:
  28. zP->removeAbschnitt( "Patch Server" );
  29. zP->removeAbschnitt( "Version" );
  30. break;
  31. }
  32. zB->unlock();
  33. release();
  34. }
  35. // Inhalt der AdminAccount Klasse aus Login.h
  36. // Konstruktor
  37. AdminAccount::AdminAccount( const char *name, const char *passwort )
  38. {
  39. this->name = new Text( name );
  40. this->passwort = new Text( passwort );
  41. ref = 1;
  42. }
  43. // Destruktor
  44. AdminAccount::~AdminAccount()
  45. {
  46. name->release();
  47. passwort->release();
  48. }
  49. // nicht constant
  50. void AdminAccount::login( const char *name, const char *passwort )
  51. {
  52. this->name = new Text( name );
  53. this->passwort = new Text( passwort );
  54. }
  55. // constant
  56. Text *AdminAccount::getName() const
  57. {
  58. return name->getThis();
  59. }
  60. Text *AdminAccount::zName() const
  61. {
  62. return name;
  63. }
  64. Text *AdminAccount::getPasswort() const
  65. {
  66. return passwort->getThis();
  67. }
  68. Text *AdminAccount::zPasswort() const
  69. {
  70. return passwort;
  71. }
  72. // Reference Counting
  73. AdminAccount *AdminAccount::getThis()
  74. {
  75. ref++;
  76. return this;
  77. }
  78. AdminAccount *AdminAccount::release()
  79. {
  80. ref--;
  81. if( !ref )
  82. delete this;
  83. return 0;
  84. }
  85. // Inhalt der Login Klasse aus Login.h
  86. // Konstruktor
  87. Login::Login( Schrift *s, Programm *zP, InitDatei *iDat, RessourceBild *resB, Bildschirm *b )
  88. : Abschnitt( b )
  89. {
  90. account = 0;
  91. fenster = 0;
  92. zProg = zP;
  93. iD = iDat;
  94. rB = resB;
  95. schrift = s;
  96. f = new Fenster();
  97. f->setStyle( Fenster::Style::Sichtbar | Fenster::Style::Erlaubt | Fenster::Style::Rahmen | Fenster::Style::Titel | Fenster::Style::TitelBuffered );
  98. f->setRFarbe( 0xFFFFFFFF );
  99. f->setRBreite( 1 );
  100. f->setTitel( "Login" );
  101. f->setTSchriftZ( s->getThis() );
  102. f->setTSFarbe( 0xFFFFFFFF );
  103. f->setTSSize( 12 );
  104. f->setTAfFarbe( 0x1000FF00 );
  105. f->setTAfStrength( -15 );
  106. f->setTRFarbe( 0xFFFFFFFF );
  107. f->setTRBreite( 1 );
  108. f->zTTextFeld()->addStyle( TextFeld::Style::Sichtbar | TextFeld::Style::Center | TextFeld::Style::Rahmen );
  109. f->zTTextFeld()->setSize( 0, 20 );
  110. f->setSize( 300, 120 );
  111. logout = new TextFeld();
  112. logout->setStyle( TextFeld::Style::HCenter );
  113. logout->setSchriftZ( s->getThis() );
  114. logout->setSchriftFarbe( 0xFFFFFFFF );
  115. logout->setSchriftSize( 12 );
  116. logout->setText( "Möchtest du dich wirklich ausloggen?" );
  117. logout->setSize( 300, 20 );
  118. logout->setPosition( 0, 20 );
  119. f->addMember( logout->getThis() );
  120. name = new TextFeld();
  121. name->setStyle( TextFeld::Style::TextFeld );
  122. name->setSchriftZ( s->getThis() );
  123. name->setSchriftFarbe( 0xFFFFFFFF );
  124. name->setSchriftSize( 12 );
  125. name->setAlphaFeldFarbe( 0x1000FF00 );
  126. name->setAlphaFeldStrength( -5 );
  127. name->setTastaturEreignisParameter( this );
  128. name->setTastaturEreignis( loginNameTastaturEreignis );
  129. name->setSize( 200, 20 );
  130. name->setPosition( 50, 10 );
  131. name->setText( "Name" );
  132. name->setRahmenFarbe( 0xFFFFFFFF );
  133. name->setRahmenBreite( 1 );
  134. f->addMember( name->getThis() );
  135. passwort = new TextFeld();
  136. passwort->setStyle( TextFeld::Style::TextFeld );
  137. passwort->setSchriftZ( s->getThis() );
  138. passwort->setSchriftFarbe( 0xFFFFFFFF );
  139. passwort->setSchriftSize( 12 );
  140. passwort->setAlphaFeldFarbe( 0x1000FF00 );
  141. passwort->setAlphaFeldStrength( -5 );
  142. passwort->setTastaturEreignisParameter( this );
  143. passwort->setTastaturEreignis( loginPasswortTastaturEreignis );
  144. passwort->setSize( 200, 20 );
  145. passwort->setPosition( 50, 40 );
  146. passwort->setText( "Passwort" );
  147. passwort->setRahmenFarbe( 0xFFFFFFFF );
  148. passwort->setRahmenBreite( 1 );
  149. f->addMember( passwort->getThis() );
  150. login = new Knopf();
  151. login->setStyle( Knopf::Style::Normal );
  152. login->setText( "Login" );
  153. login->setSchriftZ( s->getThis() );
  154. login->setMausEreignisParameter( this );
  155. login->setMausEreignis( loginLoginMausEreignis );
  156. login->setSize( 150, 20 );
  157. login->setPosition( 75, 70 );
  158. f->addMember( login->getThis() );
  159. ref = 1;
  160. }
  161. // Destruktor
  162. Login::~Login()
  163. {
  164. if( fenster )
  165. fenster->release();
  166. f->release();
  167. name->release();
  168. passwort->release();
  169. login->release();
  170. if( account )
  171. account->release();
  172. logout->release();
  173. iD->release();
  174. rB->release();
  175. schrift->release();
  176. }
  177. // nicht constant
  178. void Login::setFenster( Fenster *f )
  179. {
  180. if( fenster )
  181. fenster->release();
  182. this->f->setPosition( f->getBreite() / 2 - 150, f->getHeight() / 2 - 60 );
  183. fenster = f;
  184. }
  185. void Login::setSichtbar( bool s )
  186. {
  187. sichtbar = s;
  188. if( s )
  189. {
  190. name->addStyle( TextFeld::Style::Fokus );
  191. name->setAuswahl( name->zText()->getLength(), 0 );
  192. fenster->addMember( f->getThis() );
  193. }
  194. else
  195. {
  196. fenster->removeMember( f );
  197. }
  198. }
  199. bool Login::nameTastaturEreignis( void *obj, TastaturEreignis te )
  200. {
  201. if( te.id == TE_Release )
  202. {
  203. if( te.taste == T_Enter || te.taste == T_Unten || te.taste == T_Tab )
  204. {
  205. name->removeStyle( TextFeld::Style::Fokus );
  206. passwort->addStyle( TextFeld::Style::Fokus );
  207. passwort->setAuswahl( passwort->zText()->getLength(), 0 );
  208. }
  209. }
  210. return 1;
  211. }
  212. bool Login::passwortTastaturEreignis( void *obj, TastaturEreignis te )
  213. {
  214. passwort->setSchowChar( '*' );
  215. if( te.id == TE_Release )
  216. {
  217. if( te.taste == T_Enter )
  218. {
  219. passwort->removeStyle( TextFeld::Style::Fokus );
  220. MausEreignis me;
  221. me.id = ME_RLinks;
  222. me.mx = login->getX() + 1;
  223. me.my = login->getY() + 1;
  224. me.verarbeitet = 0;
  225. b->lock();
  226. login->doMausEreignis( me );
  227. b->unlock();
  228. }
  229. }
  230. return 1;
  231. }
  232. bool Login::loginMausEreignis( void *obj, MausEreignis me )
  233. {
  234. if( me.id == ME_RLinks )
  235. {
  236. if( f->zTitel()->istGleich( "Login" ) )
  237. {
  238. MSKlient *msk = new MSKlient( iD->zWert( "MainServerIP" )->getText(), TextZuInt( iD->zWert( "MainServerPort" )->getText(), 10 ) );
  239. if( msk->login( name->zText()->getText(), passwort->zText()->getText() ) )
  240. {
  241. if( !account )
  242. account = new AdminAccount( name->zText()->getText(), passwort->zText()->getText() );
  243. else
  244. account->login( name->zText()->getText(), passwort->zText()->getText() );
  245. f->setTitel( "Logout" );
  246. name->removeStyle( TextFeld::Style::Sichtbar );
  247. passwort->removeStyle( TextFeld::Style::Sichtbar );
  248. logout->addStyle( TextFeld::Style::Sichtbar );
  249. login->setText( "Logout" );
  250. zProg->renameAbschnitt( "Login", "Logout" );
  251. // Abshnitte erstellen
  252. PatchServer *psA = new PatchServer( schrift->getThis(), iD->getThis(), msk->getThis(), rB->getThis(), account->getThis(), b->getThis() );
  253. zProg->addAbschnitt( "Patch Server", psA );
  254. Version *vA = new Version( schrift->getThis(), msk->getThis(), rB->getThis(), account->getThis(), b->getThis() );
  255. zProg->addAbschnitt( "Version", vA );
  256. zProg->abschnittAuswählen( "Patch Server" );
  257. }
  258. else
  259. WMessageBox( 0, new Text( "Fehler" ), new Text( msk->getLetzterFehler() ), MB_ICONERROR );
  260. msk->release();
  261. }
  262. else
  263. {
  264. new AktionThread( 0, b, zProg );
  265. f->setTitel( "Login" );
  266. name->addStyle( TextFeld::Style::Sichtbar );
  267. passwort->addStyle( TextFeld::Style::Sichtbar );
  268. logout->removeStyle( TextFeld::Style::Sichtbar );
  269. login->setText( "Login" );
  270. account = account->release();
  271. zProg->renameAbschnitt( "Logout", "Login" );
  272. name->setText( "Name" );
  273. passwort->setText( "Passwort" );
  274. passwort->setSchowChar( 0 );
  275. }
  276. }
  277. return 1;
  278. }
  279. // constant
  280. AdminAccount *Login::getAccount() const
  281. {
  282. return account ? account->getThis() : 0;
  283. }
  284. AdminAccount *Login::zAccount() const
  285. {
  286. return account;
  287. }
  288. // Reference Counting
  289. Abschnitt *Login::getThis()
  290. {
  291. ref++;
  292. return this;
  293. }
  294. Abschnitt *Login::release()
  295. {
  296. ref--;
  297. if( !ref )
  298. delete this;
  299. return 0;
  300. }
  301. // Ereignisse
  302. bool loginNameTastaturEreignis( void *p, void *obj, TastaturEreignis te )
  303. {
  304. if( !p )
  305. return 0;
  306. return ( (Login*)p )->nameTastaturEreignis( obj, te );
  307. }
  308. bool loginPasswortTastaturEreignis( void *p, void *obj, TastaturEreignis te )
  309. {
  310. if( !p )
  311. return 0;
  312. return ( (Login*)p )->passwortTastaturEreignis( obj, te );
  313. }
  314. bool loginLoginMausEreignis( void *p, void *obj, MausEreignis me )
  315. {
  316. if( !p )
  317. return 0;
  318. return ( (Login*)p )->loginMausEreignis( obj, me );
  319. }