Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Login.h"
- #include "Components/Button.h"
- #include "Components/WidgetSwitcher.h"
- #include "Components/EditableTextBox.h"
- #include "Components/TextBlock.h"
- #include "UserWidget.h"
- #include "UObject/ConstructorHelpers.h"
- #include "Windows.h"
- #include "ServerWidgets.h"
- ULogin::ULogin(const FObjectInitializer & ObjectInitializer)
- {
- ConstructorHelpers::FClassFinder<UUserWidget>ServerRowBPClass(TEXT("/Game/Assets/widgets/Menu/ServerScreen"));
- if (!ensure(ServerRowBPClass.Class != nullptr)) return;
- ServerRowClass = ServerRowBPClass.Class;
- }
- bool ULogin::Initialize() {
- bool Sucess=Super::Initialize();
- if (!Sucess) return false;
- if (!ensure(Registerbutton != nullptr)) return false;
- Registerbutton->OnClicked;
- if (!ensure(Optionsbutton != nullptr)) return false;
- Optionsbutton->OnClicked.AddDynamic(this,&ULogin::HostServer);
- if (!ensure(Loginbutton != nullptr)) return false;
- Loginbutton->OnClicked.AddDynamic(this, &ULogin::Login);
- if (!ensure(Logout != nullptr)) return false;
- Logout->OnClicked.AddDynamic(this, &ULogin::BackLogin);
- if (!ensure(Apply != nullptr)) return false;
- Apply->OnClicked.AddDynamic(this, &ULogin::JoinServer);
- if (!ensure(QuitButton != nullptr)) return false;
- QuitButton->OnClicked.AddDynamic(this, &ULogin::QuitLogin);
- return true;
- }
- void ULogin::HostServer()
- {
- if (MenuInterface != nullptr)
- {
- MenuInterface->Host();
- }
- }
- void ULogin::SetServerList(TArray<FString> ServerNames)
- {
- UWorld* World = this->GetWorld();
- if (!ensure(World != nullptr)) return;
- ServerList->ClearChildren();
- uint32 i = 0;
- for (const FString& ServerName : ServerNames) {
- UServerWidgets* Row = CreateWidget<UServerWidgets>(World, ServerRowClass);
- if (!ensure(Row != nullptr)) return;
- Row->ServerName->SetText(FText::FromString(ServerName));
- Row->Setup(this,i);
- ++i;
- ServerList->AddChild(Row);
- }
- }
- void ULogin::SelectIndex(uint32 Index)
- {
- SelectedIndex = Index;
- }
- void ULogin::JoinServer()
- {
- if (SelectedIndex.IsSet() && MenuInterface != nullptr) {
- UE_LOG(LogTemp, Warning, TEXT(" Selected Index %d"), SelectedIndex.GetValue());
- MenuInterface->Join(SelectedIndex.GetValue());
- }
- else
- {
- UE_LOG(LogTemp, Warning, TEXT(" Selected Index no set"));
- }
- }
- void ULogin::Login()
- {
- FString username = T_Username->GetText().ToString();
- FString password= T_PASSWORD->GetText().ToString();
- if (username.IsEmpty() && password.IsEmpty()) {
- MessageBoxA(NULL, "Username and Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (username.IsEmpty()) {
- MessageBoxA(NULL, "Username Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (password.IsEmpty()) {
- MessageBoxA(NULL, "Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else {
- GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
- GameSparks::Api::Requests::AuthenticationRequest authRequest(gs);
- authRequest.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
- authRequest.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
- authRequest.Send([this](GameSparks::Core::GS& gs, const GameSparks::Api::Responses::AuthenticationResponse& response) {
- if (!response.GetHasErrors()) {
- GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
- // when login is sucess a want send a idot player
- // GSRequestData scriptData;
- if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue()=="1") {
- // MessageBoxA(NULL, "Administrador", "Login", MB_OK | MB_SYSTEMMODAL);
- if (!ensure(MenuSwicther != nullptr)) return;
- if (!ensure(Server != nullptr)) return;
- MenuSwicther->SetActiveWidget(Server);
- if (MenuInterface != nullptr) {
- MenuInterface->RefreshServerList();
- }
- // return;
- }
- else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "2") {
- MessageBoxA(NULL, "Moderater", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "3") {
- MessageBoxA(NULL, "GameMaster", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "4") {
- MessageBoxA(NULL, "VIP", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "5") {
- MessageBoxA(NULL, "Player", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "6") {
- MessageBoxA(NULL, "Account Not Active", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (response.GetBaseData().GetGSDataObject("scriptData").GetValue().GetString("level").GetValue() == "7") {
- MessageBoxA(NULL, "Banned", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- }
- //scriptData.AddString("email",std::string(TCHAR_TO_UTF8(*email)));
- //scriptData.AddString("level", "3");
- //Sucesso&;
- //GameSparks::Api::Requests::LogEventRequest forceMessage(gs);
- // forceMessage.SetEventKey("AAAAMessage");
- // forceMessage.Send();
- else {
- MessageBoxA(NULL, "Username Your Password In Wrong", "Login", MB_OK | MB_SYSTEMMODAL);
- FText user;
- FText pass;
- T_Username->SetText(user);
- T_PASSWORD->SetText(pass);
- return;
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement