Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 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 "Components/TextBlock.h"
  6.  
  7. #include "UserWidget.h"
  8. #include "UObject/ConstructorHelpers.h"
  9. #include "Windows.h"
  10. #include "ServerWidgets.h"
  11.  
  12.  
  13. ULogin::ULogin(const FObjectInitializer & ObjectInitializer)
  14. {
  15. ConstructorHelpers::FClassFinder<UUserWidget>ServerRowBPClass(TEXT("/Game/Assets/widgets/Menu/ServerScreen"));
  16. if (!ensure(ServerRowBPClass.Class != nullptr)) return;
  17.  
  18. ServerRowClass = ServerRowBPClass.Class;
  19. }
  20.  
  21. bool ULogin::Initialize() {
  22.  
  23. bool Sucess=Super::Initialize();
  24. if (!Sucess) return false;
  25. if (!ensure(Registerbutton != nullptr)) return false;
  26. Registerbutton->OnClicked;
  27. if (!ensure(Optionsbutton != nullptr)) return false;
  28. Optionsbutton->OnClicked.AddDynamic(this,&ULogin::HostServer);
  29. if (!ensure(Loginbutton != nullptr)) return false;
  30. Loginbutton->OnClicked.AddDynamic(this, &ULogin::Login);
  31. if (!ensure(Logout != nullptr)) return false;
  32. Logout->OnClicked.AddDynamic(this, &ULogin::BackLogin);
  33. if (!ensure(Apply != nullptr)) return false;
  34. Apply->OnClicked.AddDynamic(this, &ULogin::JoinServer);
  35. if (!ensure(QuitButton != nullptr)) return false;
  36. QuitButton->OnClicked.AddDynamic(this, &ULogin::QuitLogin);
  37.  
  38. return true;
  39. }
  40.  
  41. void ULogin::HostServer()
  42. {
  43. if (MenuInterface != nullptr)
  44. {
  45.  
  46. MenuInterface->Host();
  47.  
  48. }
  49. }
  50.  
  51.  
  52. void ULogin::SetServerList(TArray<FString> ServerNames)
  53. {
  54.  
  55. UWorld* World = this->GetWorld();
  56. if (!ensure(World != nullptr)) return;
  57.  
  58. ServerList->ClearChildren();
  59. uint32 i = 0;
  60. for (const FString& ServerName : ServerNames) {
  61. UServerWidgets* Row = CreateWidget<UServerWidgets>(World, ServerRowClass);
  62. if (!ensure(Row != nullptr)) return;
  63.  
  64. Row->ServerName->SetText(FText::FromString(ServerName));
  65. Row->Setup(this,i);
  66. ++i;
  67. ServerList->AddChild(Row);
  68. }
  69.  
  70.  
  71.  
  72.  
  73. }
  74. void ULogin::SelectIndex(uint32 Index)
  75. {
  76. SelectedIndex = Index;
  77.  
  78. }
  79.  
  80.  
  81. void ULogin::JoinServer()
  82. {
  83. if (SelectedIndex.IsSet() && MenuInterface != nullptr) {
  84. UE_LOG(LogTemp, Warning, TEXT(" Selected Index %d"), SelectedIndex.GetValue());
  85. MenuInterface->Join(SelectedIndex.GetValue());
  86. }
  87. else
  88. {
  89. UE_LOG(LogTemp, Warning, TEXT(" Selected Index no set"));
  90. }
  91. }
  92.  
  93.  
  94.  
  95. void ULogin::Login()
  96. {
  97.  
  98. FString username = T_Username->GetText().ToString();
  99. FString password= T_PASSWORD->GetText().ToString();
  100.  
  101. if (username.IsEmpty() && password.IsEmpty()) {
  102. MessageBoxA(NULL, "Username and Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  103. return;
  104. }
  105. else if (username.IsEmpty()) {
  106. MessageBoxA(NULL, "Username Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  107. return;
  108. }
  109. else if (password.IsEmpty()) {
  110. MessageBoxA(NULL, "Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  111. return;
  112. }
  113. else {
  114. GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  115. GameSparks::Api::Requests::AuthenticationRequest authRequest(gs);
  116. authRequest.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
  117. authRequest.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
  118. authRequest.Send([this](GameSparks::Core::GS& gs, const GameSparks::Api::Responses::AuthenticationResponse& response) {
  119. if (!response.GetHasErrors()) {
  120. GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  121.  
  122.  
  123. // when login is sucess a want send a idot player
  124. // GSRequestData scriptData;
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue()=="1") {
  132.  
  133. // MessageBoxA(NULL, "Administrador", "Login", MB_OK | MB_SYSTEMMODAL);
  134. if (!ensure(MenuSwicther != nullptr)) return;
  135. if (!ensure(Server != nullptr)) return;
  136. MenuSwicther->SetActiveWidget(Server);
  137. if (MenuInterface != nullptr) {
  138. MenuInterface->RefreshServerList();
  139.  
  140. }
  141. // return;
  142. }
  143. else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "2") {
  144.  
  145. MessageBoxA(NULL, "Moderater", "Login", MB_OK | MB_SYSTEMMODAL);
  146. return;
  147. }
  148. else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "3") {
  149.  
  150. MessageBoxA(NULL, "GameMaster", "Login", MB_OK | MB_SYSTEMMODAL);
  151. return;
  152. }
  153. else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "4") {
  154.  
  155. MessageBoxA(NULL, "VIP", "Login", MB_OK | MB_SYSTEMMODAL);
  156. return;
  157. }
  158. else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "5") {
  159.  
  160. MessageBoxA(NULL, "Player", "Login", MB_OK | MB_SYSTEMMODAL);
  161. return;
  162. }else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "6") {
  163.  
  164. MessageBoxA(NULL, "Account Not Active", "Login", MB_OK | MB_SYSTEMMODAL);
  165. return;
  166. }
  167. else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "7") {
  168.  
  169. MessageBoxA(NULL, "Banned", "Login", MB_OK | MB_SYSTEMMODAL);
  170. return;
  171. }
  172. }
  173.  
  174. //scriptData.AddString("email",std::string(TCHAR_TO_UTF8(*email)));
  175. //scriptData.AddString("level", "3");
  176. //Sucesso&;
  177. //GameSparks::Api::Requests::LogEventRequest forceMessage(gs);
  178.  
  179. // forceMessage.SetEventKey("AAAAMessage");
  180. // forceMessage.Send();
  181.  
  182. else {
  183. MessageBoxA(NULL, "Username Your Password In Wrong", "Login", MB_OK | MB_SYSTEMMODAL);
  184. FText user;
  185. FText pass;
  186. T_Username->SetText(user);
  187. T_PASSWORD->SetText(pass);
  188. return;
  189. }
  190. });
  191.  
  192. }
  193.  
  194.  
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement