Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #include "Login.h"
  2. #include "Components/Button.h"
  3. #include "Components/WidgetSwitcher.h"
  4. #include "Components/EditableTextBox.h"
  5. #include "UserWidget.h"
  6. #include "Windows.h"
  7.  
  8.  
  9.  
  10.  
  11. bool ULogin::Initialize() {
  12.  
  13. bool Sucess=Super::Initialize();
  14. if (!Sucess) return false;
  15. if (!ensure(Registerbutton != nullptr)) return false;
  16. Registerbutton->OnClicked;
  17. if (!ensure(Optionsbutton != nullptr)) return false;
  18. Optionsbutton->OnClicked.AddDynamic(this,&ULogin::HostServer);
  19. if (!ensure(Loginbutton != nullptr)) return false;
  20. Loginbutton->OnClicked.AddDynamic(this, &ULogin::Login);
  21. if (!ensure(Logout != nullptr)) return false;
  22. Logout->OnClicked.AddDynamic(this, &ULogin::BackLogin);
  23. if (!ensure(Apply != nullptr)) return false;
  24. Apply->OnClicked.AddDynamic(this, &ULogin::JoinServer);
  25. if (!ensure(QuitButton != nullptr)) return false;
  26. QuitButton->OnClicked.AddDynamic(this, &ULogin::QuitLogin);
  27.  
  28. return true;
  29. }
  30.  
  31. void ULogin::HostServer()
  32. {
  33. if (MenuInterface != nullptr)
  34. {
  35.  
  36. MenuInterface->Host();
  37.  
  38. }
  39. }
  40.  
  41. void ULogin::JoinServer()
  42. {
  43. if (MenuInterface != nullptr) {
  44. if (!ensure(ip != nullptr)) return;
  45. const FString& Adress=ip->GetText().ToString();
  46. MenuInterface->Join(Adress);
  47. }
  48. }
  49.  
  50.  
  51.  
  52. void ULogin::Login()
  53. {
  54.  
  55. FString username = T_Username->GetText().ToString();
  56. FString password= T_PASSWORD->GetText().ToString();
  57.  
  58. if (username.IsEmpty() & password.IsEmpty()) {
  59. MessageBoxA(NULL, "Username and Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  60. return;
  61. }
  62. else if (username.IsEmpty()) {
  63. MessageBoxA(NULL, "Username Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  64. return;
  65. }
  66. else if (password.IsEmpty()) {
  67. MessageBoxA(NULL, "Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  68. return;
  69. }
  70. else {
  71. GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  72. GameSparks::Api::Requests::AuthenticationRequest authRequest(gs);
  73. authRequest.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
  74. authRequest.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
  75. authRequest.Send(AuthenticationRequest_Response);
  76. /* if (!ensure(MenuSwicther != nullptr)) return;
  77. if (!ensure(Server != nullptr)) return;
  78. MenuSwicther->SetActiveWidget(Server);
  79. */
  80. }
  81.  
  82.  
  83. }
  84.  
  85. void ULogin::BackLogin()
  86. {
  87. if (!ensure(MenuSwicther != nullptr)) return;
  88. if (!ensure(LoginMain != nullptr)) return;
  89. MenuSwicther->SetActiveWidget(LoginMain);
  90. FText user;
  91. FText pass;
  92. T_Username->SetText(user);
  93. T_PASSWORD->SetText(pass);
  94. }
  95.  
  96. void ULogin::QuitLogin()
  97. {
  98. UWorld* World = GetWorld();
  99. if (!ensure(World != nullptr)) return;
  100. APlayerController* PlayerController = World->GetFirstPlayerController();
  101. if (!ensure(PlayerController != nullptr)) return;
  102. PlayerController->ConsoleCommand("quit");
  103. }
  104.  
  105. void ULogin::Sucesso()
  106. {
  107. if (!ensure(MenuSwicther != nullptr)) return;
  108. if (!ensure(Server != nullptr)) return;
  109. MenuSwicther->SetActiveWidget(Server);
  110. }
  111. void ULogin::AuthenticationRequest_Response(GameSparks::Core::GS&, const GameSparks::Api::Responses::AuthenticationResponse& response)
  112. {
  113.  
  114. //Check is response has no errors
  115. if (!response.GetHasErrors()) {
  116. GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  117. GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, response.GetJSONString().c_str());
  118.  
  119.  
  120. GSRequestData scriptData;
  121.  
  122.  
  123.  
  124. //scriptData.AddString("email",std::string(TCHAR_TO_UTF8(*email)));
  125. //scriptData.AddString("level", "3");
  126. //Sucesso&;
  127. //GameSparks::Api::Requests::LogEventRequest forceMessage(gs);
  128.  
  129. // forceMessage.SetEventKey("AAAAMessage");
  130. // forceMessage.Send();
  131. }
  132. else {
  133. GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, TEXT("ERRO"));
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement