Login.cpp 8.5 KB

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