Login.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. #include "..\..\Global\Variablen.h"
  2. #include "Login.h"
  3. #include "..\..\Global\Initialisierung.h"
  4. #include <Punkt.h>
  5. #include <Text.h>
  6. // Inhalt der Login Klasse aus Login.h
  7. // Konstruktor
  8. Login::Login( Schrift *zSchrift, Fenster *vorLoginFenster )
  9. {
  10. Punkt bildschirmGröße = BildschirmGröße();
  11. login = initKnopf( 10, 50, 130, 30, zSchrift, Knopf::Style::Sichtbar, "Login" );
  12. login->setMausEreignisParameter( this );
  13. login->setMausEreignis( loginLoginME );
  14. initToolTip( login, "Einloggen.", zSchrift, hauptScreen );
  15. vorLoginFenster->addMember( login->getThis() );
  16. fenster = initFenster( bildschirmGröße.x / 2 - 125, bildschirmGröße.y / 2 - 75, 250, 150, zSchrift, Fenster::Style::Sichtbar | Fenster::Style::Erlaubt | Fenster::Style::Rahmen | Fenster::Style::Titel | Fenster::Style::TitelBuffered, "Login" );
  17. name = initTextFeld( 20, 20, 208, 20, zSchrift, TextFeld::Style::TextFeld, "Name" );
  18. name->setTastaturEreignisParameter( this );
  19. name->setTastaturEreignis( loginNameTE );
  20. initToolTip( name, "Account Name.", zSchrift, hauptScreen );
  21. fenster->addMember( name->getThis() );
  22. passwort = initTextFeld( 20, 55, 208, 20, zSchrift, TextFeld::Style::TextFeld, "Passwort" );
  23. passwort->setTastaturEreignisParameter( this );
  24. passwort->setTastaturEreignis( loginPasswortTE );
  25. initToolTip( passwort, "Account Passwort.", zSchrift, hauptScreen );
  26. fenster->addMember( passwort->getThis() );
  27. weiter = initKnopf( 75, 90, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Login" );
  28. weiter->setMausEreignisParameter( this );
  29. weiter->setMausEreignis( loginWeiterME );
  30. fenster->addMember( weiter->getThis() );
  31. nachricht = initTextFeld( 5, 5, 238, 90, zSchrift, TextFeld::Style::HCenter | TextFeld::Style::Mehrzeilig, "" );
  32. fenster->addMember( nachricht->getThis() );
  33. geheimnis = initTextFeld( 20, 55, 208, 20, zSchrift, TextFeld::Style::TextFeld, "Geheimnis" );
  34. geheimnis->removeStyle( TextFeld::Style::Sichtbar );
  35. geheimnis->setTastaturEreignisParameter( this );
  36. geheimnis->setTastaturEreignis( loginGeheimnisTE );
  37. initToolTip( geheimnis, "Account Geheimnis.", zSchrift, hauptScreen );
  38. fenster->addMember( geheimnis->getThis() );
  39. abbrechen = initKnopf( 10, 98, 100, 20, zSchrift, 0, "Abbrechen" );
  40. abbrechen->setMausEreignisParameter( this );
  41. abbrechen->setMausEreignis( loginAbbrechenME );
  42. fenster->addMember( abbrechen->getThis() );
  43. ok = initKnopf( 138, 98, 100, 20, zSchrift, 0, "Ok" );
  44. ok->setMausEreignisParameter( this );
  45. ok->setMausEreignis( loginOkME );
  46. fenster->addMember( ok->getThis() );
  47. vorLoginFenster->addMember( fenster->getThis() );
  48. MausEreignis me;
  49. me.id = ME_RLinks;
  50. loginME( 0, me );
  51. ref = 1;
  52. }
  53. // Destruktor
  54. Login::~Login()
  55. {
  56. if( fenster )
  57. fenster = (Fenster *)fenster->release();
  58. if( name )
  59. name = (TextFeld *)name->release();
  60. if( passwort )
  61. passwort = (TextFeld *)passwort->release();
  62. if( nachricht )
  63. nachricht = (TextFeld *)nachricht->release();
  64. if( geheimnis )
  65. geheimnis = (TextFeld *)geheimnis->release();
  66. if( weiter )
  67. weiter = (Knopf *)weiter->release();
  68. if( abbrechen )
  69. abbrechen = (Knopf *)abbrechen->release();
  70. if( ok )
  71. ok = (Knopf *)ok->release();
  72. if( login )
  73. login = (Knopf *)login->release();
  74. }
  75. // Knopfdruck
  76. void Login::druckFremdKnopf() // Ein anderer Bereich des Programms wurde ausgewählt
  77. {
  78. fenster->removeStyle( Fenster::Style::Sichtbar );
  79. login->setRahmenBreite( 2 );
  80. login->setAlphaFeldFarbe( 0x5500FF00 );
  81. login->setAlphaFeldStrength( -5 );
  82. }
  83. bool Login::nameTE( void *obj, TastaturEreignis te ) // Tastaturereignis im Textfeld name
  84. {
  85. if( te.id == TE_Press && te.taste == T_Enter )
  86. return 0;
  87. if( te.id == TE_Release && ( te.taste == T_Enter || te.taste == T_Tab ) )
  88. {
  89. name->removeStyle( TextFeld::Style::Fokus );
  90. passwort->addStyle( TextFeld::Style::Fokus );
  91. passwort->setAuswahl( 0, passwort->zText()->getLength() );
  92. }
  93. if( name->zText()->getLength() >= 25 && istSchreibbar( te.taste ) )
  94. return 0;
  95. return 1;
  96. }
  97. bool Login::passwortTE( void *obj, TastaturEreignis te ) // TastaturEreignis im Textfeld passwort
  98. {
  99. if( te.id == TE_Press )
  100. passwort->setSchowChar( '*' );
  101. if( te.id == TE_Press && te.taste == T_Enter )
  102. return 0;
  103. if( te.id == TE_Release && te.taste == T_Enter )
  104. {
  105. passwort->removeStyle( TextFeld::Style::Fokus );
  106. MausEreignis me;
  107. me.id = ME_RLinks;
  108. weiterME( 0, me );
  109. }
  110. if( passwort->zText()->getLength() >= 25 && istSchreibbar( te.taste ) )
  111. return 0;
  112. return 1;
  113. }
  114. bool Login::geheimnisTE( void *obj, TastaturEreignis te ) // TastaturEreignis im Textfeld geheimnis
  115. {
  116. if( te.id == TE_Press && te.taste == T_Enter )
  117. return 0;
  118. if( te.id == TE_Press )
  119. geheimnis->setSchowChar( '*' );
  120. if( te.id == TE_Release && te.taste == T_Enter )
  121. {
  122. geheimnis->removeStyle( TextFeld::Style::Fokus );
  123. MausEreignis me;
  124. me.id = ME_RLinks;
  125. okME( 0, me );
  126. }
  127. if( geheimnis->zText()->getLength() >= 50 && istSchreibbar( te.taste ) )
  128. return 0;
  129. return 1;
  130. }
  131. bool Login::weiterME( void *obj, MausEreignis me ) // MausEreignis im Knopf weiter
  132. {
  133. if( me.id == ME_RLinks )
  134. {
  135. if( name->zText()->getLength() == 0 )
  136. {
  137. name->removeStyle( TextFeld::Style::Sichtbar );
  138. passwort->removeStyle( TextFeld::Style::Sichtbar );
  139. weiter->removeStyle( Knopf::Style::Sichtbar );
  140. nachricht->setText( "Bitte trage deinen Accountnamen\nein." );
  141. nachricht->addStyle( TextFeld::Style::Sichtbar );
  142. ok->addStyle( Knopf::Style::Sichtbar );
  143. return 1;
  144. }
  145. if( passwort->zText()->getLength() == 0 )
  146. {
  147. name->removeStyle( TextFeld::Style::Sichtbar );
  148. passwort->removeStyle( TextFeld::Style::Sichtbar );
  149. weiter->removeStyle( Knopf::Style::Sichtbar );
  150. nachricht->setText( "Bitte trage dein Passwort ein." );
  151. nachricht->addStyle( TextFeld::Style::Sichtbar );
  152. ok->addStyle( Knopf::Style::Sichtbar );
  153. return 1;
  154. }
  155. new AktionsThread( 1, name->zText()->getText(), passwort->zText()->getText(), 0, 0, 0 );
  156. }
  157. return 1;
  158. }
  159. bool Login::okME( void *obj, MausEreignis me ) // MausEreignis im Knopf ok
  160. {
  161. if( me.id == ME_RLinks )
  162. {
  163. if( geheimnis->hatStyle( TextFeld::Style::Sichtbar ) )
  164. new AktionsThread( 3, name->zText()->getText(), passwort->zText()->getText(), geheimnis->zText()->getText(), 0, 0 );
  165. else
  166. {
  167. nachricht->removeStyle( TextFeld::Style::Sichtbar );
  168. geheimnis->removeStyle( TextFeld::Style::Sichtbar );
  169. ok->removeStyle( Knopf::Style::Sichtbar );
  170. abbrechen->removeStyle( Knopf::Style::Sichtbar );
  171. name->addStyle( TextFeld::Style::Sichtbar );
  172. passwort->addStyle( TextFeld::Style::Sichtbar );
  173. weiter->addStyle( TextFeld::Style::Sichtbar );
  174. name->addStyle( TextFeld::Style::Fokus );
  175. name->setAuswahl( 0, name->zText()->getLength() );
  176. }
  177. }
  178. return 1;
  179. }
  180. bool Login::abbrechenME( void *obj, MausEreignis me ) // MausEreignis im Knopf abbrechen
  181. {
  182. if( me.id == ME_RLinks )
  183. {
  184. nachricht->removeStyle( TextFeld::Style::Sichtbar );
  185. geheimnis->removeStyle( TextFeld::Style::Sichtbar );
  186. ok->removeStyle( Knopf::Style::Sichtbar );
  187. abbrechen->removeStyle( Knopf::Style::Sichtbar );
  188. name->addStyle( TextFeld::Style::Sichtbar );
  189. passwort->addStyle( TextFeld::Style::Sichtbar );
  190. weiter->addStyle( TextFeld::Style::Sichtbar );
  191. name->addStyle( TextFeld::Style::Fokus );
  192. name->setAuswahl( 0, name->zText()->getLength() );
  193. }
  194. return 1;
  195. }
  196. bool Login::loginME( void *obj, MausEreignis me ) // MausEreignis im Knopf login
  197. {
  198. if( me.id == ME_RLinks )
  199. {
  200. vorLogin->setLogin( 1 );
  201. nachricht->removeStyle( TextFeld::Style::Sichtbar );
  202. geheimnis->removeStyle( TextFeld::Style::Sichtbar );
  203. ok->removeStyle( Knopf::Style::Sichtbar );
  204. abbrechen->removeStyle( Knopf::Style::Sichtbar );
  205. fenster->addStyle( Fenster::Style::Sichtbar );
  206. name->addStyle( TextFeld::Style::Sichtbar );
  207. passwort->addStyle( TextFeld::Style::Sichtbar );
  208. weiter->addStyle( TextFeld::Style::Sichtbar );
  209. login->setRahmenBreite( 3 );
  210. login->setAlphaFeldFarbe( 0xFF000000 );
  211. login->setAlphaFeldStrength( 20 );
  212. name->addStyle( TextFeld::Style::Fokus );
  213. name->setAuswahl( 0, name->zText()->getLength() );
  214. }
  215. return 1;
  216. }
  217. void Login::setLoginReturn( int ret ) // setzt den Returnwert vom login
  218. {
  219. if( ret == 1 )
  220. new AktionsThread( 2, 0, 0, 0, 0, 0 );
  221. else if( ret == 2 )
  222. {
  223. name->removeStyle( TextFeld::Style::Sichtbar );
  224. passwort->removeStyle( TextFeld::Style::Sichtbar );
  225. weiter->removeStyle( Knopf::Style::Sichtbar );
  226. nachricht->setText( "Der Account ist bereits online.\nGebe dein Account Geheimnis ein,\num den anderen Benutzer zu kicken." );
  227. nachricht->addStyle( TextFeld::Style::Sichtbar );
  228. geheimnis->addStyle( TextFeld::Style::Sichtbar );
  229. ok->addStyle( Knopf::Style::Sichtbar );
  230. abbrechen->addStyle( Knopf::Style::Sichtbar );
  231. geheimnis->addStyle( TextFeld::Style::Fokus );
  232. geheimnis->setAuswahl( 0, geheimnis->zText()->getLength() );
  233. }
  234. else if( !ret && lastError.getLength() )
  235. {
  236. name->removeStyle( TextFeld::Style::Sichtbar );
  237. passwort->removeStyle( TextFeld::Style::Sichtbar );
  238. weiter->removeStyle( Knopf::Style::Sichtbar );
  239. nachricht->setText( lastError );
  240. if( nachricht->zText()->getLength() > 30 )
  241. {
  242. int pos = -1;
  243. bool set = 0;
  244. int lastp = 0;
  245. for( int i = 20; i < nachricht->zText()->getLength(); )
  246. {
  247. char *tmp = &nachricht->zText()->getText()[ i ];
  248. while( *tmp != ' ' && i < nachricht->zText()->getLength() )
  249. {
  250. tmp++;
  251. i++;
  252. if( i - 30 >= lastp )
  253. {
  254. if( set )
  255. {
  256. lastp = pos;
  257. set = 0;
  258. nachricht->zText()->getText()[ pos ] = '\n';
  259. }
  260. else
  261. lastp += 5;
  262. }
  263. }
  264. if( i < nachricht->zText()->getLength() )
  265. {
  266. pos = i;
  267. set = 1;
  268. tmp++;
  269. i++;
  270. }
  271. }
  272. }
  273. nachricht->addStyle( TextFeld::Style::Sichtbar );
  274. ok->addStyle( Knopf::Style::Sichtbar );
  275. }
  276. }
  277. void Login::setKickReturn( int ret ) // setzt den returnwert vom kick
  278. {
  279. if( ret == 1 )
  280. new AktionsThread( 2, 0, 0, 0, 0, 0 );
  281. else if( ret == 2 )
  282. {
  283. nachricht->setText( lastError );
  284. if( nachricht->zText()->getLength() > 30 )
  285. {
  286. int pos = -1;
  287. bool set = 0;
  288. int lastp = 0;
  289. for( int i = 20; i < nachricht->zText()->getLength(); )
  290. {
  291. char *tmp = &nachricht->zText()->getText()[ i ];
  292. while( *tmp != ' ' && i < nachricht->zText()->getLength() )
  293. {
  294. tmp++;
  295. i++;
  296. if( i - 30 >= lastp )
  297. {
  298. if( set )
  299. {
  300. lastp = pos;
  301. set = 0;
  302. nachricht->zText()->getText()[ pos ] = '\n';
  303. }
  304. else
  305. lastp += 5;
  306. }
  307. }
  308. if( i < nachricht->zText()->getLength() )
  309. {
  310. pos = i;
  311. set = 1;
  312. tmp++;
  313. i++;
  314. }
  315. }
  316. }
  317. geheimnis->removeStyle( TextFeld::Style::Sichtbar );
  318. abbrechen->removeStyle( Knopf::Style::Sichtbar );
  319. }
  320. else if( !ret )
  321. {
  322. nachricht->setText( "Das Geheimnis stimmt nicht mit dem des Accounts\nüberein. Achte auf Groß - und Kleinschreibung." );
  323. geheimnis->removeStyle( TextFeld::Style::Sichtbar );
  324. abbrechen->removeStyle( Knopf::Style::Sichtbar );
  325. }
  326. }
  327. // Reference Counting
  328. Login *Login::getThis()
  329. {
  330. ref++;
  331. return this;
  332. }
  333. Login *Login::release()
  334. {
  335. ref--;
  336. if( !ref )
  337. delete this;
  338. return 0;
  339. }
  340. // Ereignisse
  341. bool loginNameTE( void *p, void *obj, TastaturEreignis te )
  342. {
  343. if( !p )
  344. return 0;
  345. return ( (Login*)p )->nameTE( obj, te );
  346. }
  347. bool loginPasswortTE( void *p, void *obj, TastaturEreignis te )
  348. {
  349. if( !p )
  350. return 0;
  351. return ( (Login*)p )->passwortTE( obj, te );
  352. }
  353. bool loginGeheimnisTE( void *p, void *obj, TastaturEreignis te )
  354. {
  355. if( !p )
  356. return 0;
  357. return ( (Login*)p )->geheimnisTE( obj, te );
  358. }
  359. bool loginWeiterME( void *p, void *obj, MausEreignis me )
  360. {
  361. if( !p )
  362. return 0;
  363. return ( (Login*)p )->weiterME( obj, me );
  364. }
  365. bool loginAbbrechenME( void *p, void *obj, MausEreignis me )
  366. {
  367. if( !p )
  368. return 0;
  369. return ( (Login*)p )->abbrechenME( obj, me );
  370. }
  371. bool loginOkME( void *p, void *obj, MausEreignis me )
  372. {
  373. if( !p )
  374. return 0;
  375. return ( (Login*)p )->okME( obj, me );
  376. }
  377. bool loginLoginME( void *p, void *obj, MausEreignis me )
  378. {
  379. if( !p )
  380. return 0;
  381. return ( (Login*)p )->loginME( obj, me );
  382. }